Skip to content

Commit

Permalink
feat: use chalk for statements printed to console
Browse files Browse the repository at this point in the history
Closes #8
  • Loading branch information
metonym committed Oct 27, 2019
1 parent 48390da commit de2e938
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 3 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import chalk from 'chalk';
import fs from 'fs';
import htmlnano from 'htmlnano';
import posthtml from 'posthtml';
Expand Down Expand Up @@ -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) {
Expand Down
5 changes: 5 additions & 0 deletions tests/hashStatic.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});

Expand All @@ -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();
});

Expand All @@ -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();
});

Expand All @@ -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();
});
});
2 changes: 1 addition & 1 deletion tslint.json
Original file line number Diff line number Diff line change
@@ -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 }
}

0 comments on commit de2e938

Please sign in to comment.