From de2e93818a57a3ebf1fdf67f1a126258f1b771f5 Mon Sep 17 00:00:00 2001 From: Eric Liu Date: Sun, 27 Oct 2019 04:53:19 -0700 Subject: [PATCH] feat: use chalk for statements printed to console Closes #8 --- package.json | 3 ++- src/index.ts | 4 +++- tests/hashStatic.spec.ts | 5 +++++ tslint.json | 2 +- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 8fefaeb..11c1c47 100644 --- a/package.json +++ b/package.json @@ -8,12 +8,13 @@ "types": "lib/index.d.ts", "scripts": { "build": "tsc", - "lint": "tslint --fix -p . -c tslint.json", + "lint": "tslint --fix -p .", "test": "jest --coverage", "test:tdd": "jest --watch", "prepublishOnly": "yarn build" }, "dependencies": { + "chalk": "^2.4.2", "htmlnano": "^0.2.4", "posthtml": "^0.12.0", "posthtml-hash": "^0.2.1" diff --git a/src/index.ts b/src/index.ts index c13fa25..26951ab 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,3 +1,4 @@ +import chalk from 'chalk'; import fs from 'fs'; import htmlnano from 'htmlnano'; import posthtml from 'posthtml'; @@ -33,7 +34,8 @@ async function hashStatic(options: IHashStaticOptions) { const result = await posthtml(plugins).process(html); fs.writeFileSync(entry, result.html); - process.stdout.write(`Successfully hashed static assets.\n`); + + console.log(chalk.green('Successfully hashed static assets.')); } async function hashStaticCli(process: NodeJS.Process) { diff --git a/tests/hashStatic.spec.ts b/tests/hashStatic.spec.ts index 01ffd11..af22587 100644 --- a/tests/hashStatic.spec.ts +++ b/tests/hashStatic.spec.ts @@ -5,10 +5,12 @@ import { hashStatic, hashStaticCli } from '../src'; describe('hashStatic', () => { beforeEach(() => { + jest.spyOn(global.console, 'log'); process.argv = process.argv.slice(0, 2); }); afterEach(() => { + jest.clearAllMocks(); sh.rm('-rf', 'tests/fixtures/basic/processed'); }); @@ -30,6 +32,7 @@ describe('hashStatic', () => { const entry = 'tests/fixtures/basic/processed/index.html'; await hashStatic({ entry }); const html = fs.readFileSync(entry).toString(); + expect(console.log).toBeCalledTimes(1); expect(html).toMatchSnapshot(); }); @@ -43,6 +46,7 @@ describe('hashStatic', () => { const entry = 'tests/fixtures/basic/processed/index.html'; await hashStatic({ entry, minify: false }); const html = fs.readFileSync(entry).toString(); + expect(console.log).toBeCalledTimes(1); expect(html).toMatchSnapshot(); }); @@ -57,6 +61,7 @@ describe('hashStatic', () => { process.argv.push(entry); await hashStaticCli(process); const html = fs.readFileSync(entry).toString(); + expect(console.log).toBeCalledTimes(1); expect(html).toMatchSnapshot(); }); }); diff --git a/tslint.json b/tslint.json index fbbc3a8..eeb3330 100644 --- a/tslint.json +++ b/tslint.json @@ -1,4 +1,4 @@ { "extends": ["tslint:latest", "tslint-config-prettier"], - "rules": { "object-literal-sort-keys": false } + "rules": { "no-console": false, "object-literal-sort-keys": false } }