Skip to content

Commit

Permalink
Merge pull request #4 from flandrade/add-support-node-6
Browse files Browse the repository at this point in the history
feat: Add support for Node v.6.4+
  • Loading branch information
flandrade committed Nov 12, 2018
2 parents 04bb721 + 7a7c037 commit ff4a540
Show file tree
Hide file tree
Showing 11 changed files with 80 additions and 32 deletions.
11 changes: 8 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
15 changes: 9 additions & 6 deletions lib/harvest-overtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)}
`);
});
3 changes: 2 additions & 1 deletion lib/io.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
import * as Promise from "bluebird";
export declare function read(filePath: string): Promise<string>;
export declare function write(filePath: string): (data: string) => Promise<void>;
export declare function write(filePath: string): (data: string) => void;
13 changes: 8 additions & 5 deletions lib/io.js
Original file line number Diff line number Diff line change
@@ -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;
1 change: 1 addition & 0 deletions lib/reporter.d.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
13 changes: 12 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "harvest-overtime",
"version": "2.0.0",
"version": "2.1.0",
"description": "Track the overtime!",
"keywords": [
"harvest",
Expand All @@ -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": {
Expand All @@ -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",
Expand All @@ -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",
Expand Down
15 changes: 9 additions & 6 deletions src/harvest-overtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)}
`);
});
28 changes: 20 additions & 8 deletions src/io.ts
Original file line number Diff line number Diff line change
@@ -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<string>
= Promise.promisify<string, string, string>(fs.readFile);

const writeFileAsync: (
file: string,
data: any,
options: fs.WriteFileOptions
) => Promise<void>
= Promise.promisify<void, string, any, fs.WriteFileOptions>(fs.writeFile);

export function read(filePath: string): Promise<string> {
return readFileAsync(filePath, { encoding: "utf8" });
return readFileAsync(filePath, DEFAULT_ENCODING);
}

export function write(
filePath: string
): (data: string) => Promise<void> {
return data =>
writeFileAsync(filePath, data, { encoding: "utf8" });
): (data: string) => void {
return data => {
writeFileAsync(filePath, data, { encoding: DEFAULT_ENCODING });
};
}
2 changes: 2 additions & 0 deletions src/reporter.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"compilerOptions": {
"declaration": true,
"lib": [ "es2015" ],
"module": "commonjs",
"outDir": "lib",
"strict": true,
"target": "ES2018"
"target": "ES2015"
},
"include": [
"src/**/*"
Expand Down

0 comments on commit ff4a540

Please sign in to comment.