From 7a7c03772d3f43a0ae7a86ce5c3ed0d52c8df44c Mon Sep 17 00:00:00 2001 From: Fernanda Andrade Date: Sun, 11 Nov 2018 19:13:23 -0500 Subject: [PATCH] feat: Add support for Node v.6.4+ --- CHANGELOG.md | 11 ++++++++--- lib/harvest-overtime.js | 15 +++++++++------ lib/io.d.ts | 3 ++- lib/io.js | 13 ++++++++----- lib/reporter.d.ts | 1 + package-lock.json | 13 ++++++++++++- package.json | 8 +++++++- src/harvest-overtime.ts | 15 +++++++++------ src/io.ts | 28 ++++++++++++++++++++-------- src/reporter.ts | 2 ++ tsconfig.json | 3 ++- 11 files changed, 80 insertions(+), 32 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 33f16bd..1e5cea1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,13 @@ +## 0.2.1.0 + +* Feature: Add support for Node v6.4+. + ## 0.2.0.0 -* Add CLI and colors for output. -* Upgrade dependencies: TypeScript, mocha and csv-generate. -* Use ES2018. +* Breaking Change: harvest-overtime uses ES2018. Support litimed to Node v10+. +* Breaking Change: Add CLI. Commands `i` and `o` are required to define files. +* Feature: Add colors for output. +* Chore: Upgrade dependencies: TypeScript, mocha and csv-generate. ## 0.1.0.0 diff --git a/lib/harvest-overtime.js b/lib/harvest-overtime.js index a93368a..e20c697 100644 --- a/lib/harvest-overtime.js +++ b/lib/harvest-overtime.js @@ -14,12 +14,15 @@ program .parse(process.argv); const args = decorator_1.decorateArgs({ default: reporter_1.DEF_INPUT, file: program.input }, { default: reporter_1.DEF_OUTPUT, file: program.output }); reporter_1.default(args.inputPath, args.outputPath) - .finally(() => { - console.log(`Input file is ${infoColor(args.inputPath)}`); -}) .then(() => { - console.log(`Done. Output file is ${infoColor(args.outputPath)}`); + console.log(` + Input file is ${infoColor(args.inputPath)}. + Output file is ${infoColor(args.outputPath)}. + `); }) - .catch(error => { - console.error(errorColor(`There was an issue. ${error.message}`)); + .catch((error) => { + console.error(` + It was not possible to process ${infoColor(args.inputPath)}. + ${errorColor(error.message)} + `); }); diff --git a/lib/io.d.ts b/lib/io.d.ts index 07424fc..1158447 100644 --- a/lib/io.d.ts +++ b/lib/io.d.ts @@ -1,2 +1,3 @@ +import * as Promise from "bluebird"; export declare function read(filePath: string): Promise; -export declare function write(filePath: string): (data: string) => Promise; +export declare function write(filePath: string): (data: string) => void; diff --git a/lib/io.js b/lib/io.js index cb0787d..c60de39 100644 --- a/lib/io.js +++ b/lib/io.js @@ -1,14 +1,17 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); +const Promise = require("bluebird"); const fs = require("fs"); -const util = require("util"); -const readFileAsync = util.promisify(fs.readFile); -const writeFileAsync = util.promisify(fs.writeFile); +const DEFAULT_ENCODING = "utf8"; +const readFileAsync = Promise.promisify(fs.readFile); +const writeFileAsync = Promise.promisify(fs.writeFile); function read(filePath) { - return readFileAsync(filePath, { encoding: "utf8" }); + return readFileAsync(filePath, DEFAULT_ENCODING); } exports.read = read; function write(filePath) { - return data => writeFileAsync(filePath, data, { encoding: "utf8" }); + return data => { + writeFileAsync(filePath, data, { encoding: DEFAULT_ENCODING }); + }; } exports.write = write; diff --git a/lib/reporter.d.ts b/lib/reporter.d.ts index 99fdc96..ebe6ab6 100644 --- a/lib/reporter.d.ts +++ b/lib/reporter.d.ts @@ -1,3 +1,4 @@ +import * as Promise from "bluebird"; export declare const CUR_VERSION: string; export declare const DEF_INPUT: string; export declare const DEF_OUTPUT: string; diff --git a/package-lock.json b/package-lock.json index 15cbfd3..7f4989a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,9 +1,15 @@ { "name": "harvest-overtime", - "version": "2.0.0", + "version": "2.1.0", "lockfileVersion": 1, "requires": true, "dependencies": { + "@types/bluebird": { + "version": "3.5.24", + "resolved": "https://registry.npmjs.org/@types/bluebird/-/bluebird-3.5.24.tgz", + "integrity": "sha512-YeQoDpq4Lm8ppSBqAnAeF/xy1cYp/dMTif2JFcvmAbETMRlvKHT2iLcWu+WyYiJO3b3Ivokwo7EQca/xfLVJmg==", + "dev": true + }, "@types/chai": { "version": "4.1.7", "resolved": "https://registry.npmjs.org/@types/chai/-/chai-4.1.7.tgz", @@ -115,6 +121,11 @@ "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", "dev": true }, + "bluebird": { + "version": "3.5.3", + "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.5.3.tgz", + "integrity": "sha1-fQHG+WFsmlGrD4xUmnnf5uwz76c=" + }, "brace-expansion": { "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", diff --git a/package.json b/package.json index e5b5251..304509f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "harvest-overtime", - "version": "2.0.0", + "version": "2.1.0", "description": "Track the overtime!", "keywords": [ "harvest", @@ -11,6 +11,10 @@ "convert", "parse" ], + "repository": { + "type": "git", + "url": "git+https://github.com/flandrade/harvest-overtime.git" + }, "main": "lib/harvest-overtime.js", "types": "lib/harvest-overtime.d.ts", "bin": { @@ -28,6 +32,7 @@ "license": "MIT", "dependencies": { "@types/chalk": "^2.2.0", + "bluebird": "^3.5.3", "chalk": "^2.4.1", "commander": "^2.19.0", "csv": "^3.1.0", @@ -39,6 +44,7 @@ "ramda": "^0.25.0" }, "devDependencies": { + "@types/bluebird": "^3.5.24", "@types/chai": "^4.1.7", "@types/json2csv": "^4.2.0", "@types/mocha": "^5.2.5", diff --git a/src/harvest-overtime.ts b/src/harvest-overtime.ts index fd204f2..df643ff 100644 --- a/src/harvest-overtime.ts +++ b/src/harvest-overtime.ts @@ -25,12 +25,15 @@ const args: Files = decorateArgs( ); reporter(args.inputPath, args.outputPath) - .finally(() => { - console.log(`Input file is ${infoColor(args.inputPath)}`); - }) .then(() => { - console.log(`Done. Output file is ${infoColor(args.outputPath)}`); + console.log(` + Input file is ${infoColor(args.inputPath)}. + Output file is ${infoColor(args.outputPath)}. + `); }) - .catch(error => { - console.error(errorColor(`There was an issue. ${error.message}`)); + .catch((error: Error) => { + console.error(` + It was not possible to process ${infoColor(args.inputPath)}. + ${errorColor(error.message)} + `); }); diff --git a/src/io.ts b/src/io.ts index bd25c2f..7f2276e 100644 --- a/src/io.ts +++ b/src/io.ts @@ -1,16 +1,28 @@ +import * as Promise from "bluebird"; import * as fs from "fs"; -import * as util from "util"; -const readFileAsync = util.promisify(fs.readFile); -const writeFileAsync = util.promisify(fs.writeFile); +const DEFAULT_ENCODING: string = "utf8"; + +const readFileAsync: ( + file: string, + encoding: string +) => Promise + = Promise.promisify(fs.readFile); + +const writeFileAsync: ( + file: string, + data: any, + options: fs.WriteFileOptions +) => Promise + = Promise.promisify(fs.writeFile); export function read(filePath: string): Promise { - return readFileAsync(filePath, { encoding: "utf8" }); + return readFileAsync(filePath, DEFAULT_ENCODING); } - export function write( filePath: string -): (data: string) => Promise { - return data => - writeFileAsync(filePath, data, { encoding: "utf8" }); +): (data: string) => void { + return data => { + writeFileAsync(filePath, data, { encoding: DEFAULT_ENCODING }); + }; } diff --git a/src/reporter.ts b/src/reporter.ts index dd4702c..18a9608 100644 --- a/src/reporter.ts +++ b/src/reporter.ts @@ -1,3 +1,5 @@ +import * as Promise from "bluebird"; + import { read, write } from "./io"; import parseFromReport from "./parser/parser-from-csv"; import parseToReport from "./parser/parser-to-csv"; diff --git a/tsconfig.json b/tsconfig.json index e8af874..04ba982 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,10 +1,11 @@ { "compilerOptions": { "declaration": true, + "lib": [ "es2015" ], "module": "commonjs", "outDir": "lib", "strict": true, - "target": "ES2018" + "target": "ES2015" }, "include": [ "src/**/*"