Skip to content

Commit 3219cf6

Browse files
committed
remove vow from deps
1 parent 8766c36 commit 3219cf6

File tree

7 files changed

+137
-93
lines changed

7 files changed

+137
-93
lines changed

bin/html-differ

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#!/usr/bin/env node
22

3-
require('../lib/cli.js').run();
3+
require('../lib/cli.js').run(process.argv);

lib/cli.js

Lines changed: 54 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11
const path = require('path');
2-
const vow = require('vow');
3-
const vfs = require('vow-fs');
42
const chalk = require('chalk');
53
const boldGreen = chalk.green.bold;
64
const boldRed = chalk.red.bold;
75
const HtmlDiffer = require('./index').HtmlDiffer;
86
const diffLogger = require('./logger');
97
const defaults = require('./defaults');
8+
const coa = require('coa');
9+
const fs = require('fs');
10+
const util = require('util');
11+
const readAsync = util.promisify(fs.readFile);
1012

1113
module.exports = {
12-
run() {
13-
require('coa').Cmd()
14-
.name(process.argv[1])
15-
.helpful()
14+
run(argv) {
15+
const cmd = coa.Cmd()
16+
.name(argv[1])
1617
.title('Compares two HTML')
17-
.opt()
18+
.helpful();
19+
20+
cmd.opt()
1821
.name('version')
1922
.title('Shows the version number')
2023
.short('v').long('version')
@@ -23,14 +26,14 @@ module.exports = {
2326
.act(function() {
2427
const p = require('../package.json');
2528
return p.name + ' ' + p.version;
26-
})
27-
.end()
28-
.opt()
29+
});
30+
31+
cmd.opt()
2932
.name('config')
3033
.title('Path to a configuration JSON file')
31-
.long('config')
32-
.end()
33-
.opt()
34+
.long('config');
35+
36+
cmd.opt()
3437
.name('bem')
3538
.title('Uses predefined options for BEM (deprecated)')
3639
.long('bem')
@@ -40,9 +43,9 @@ module.exports = {
4043
// support legacy
4144
opts.preset = 'bem';
4245
delete opts.bem;
43-
})
44-
.end()
45-
.opt()
46+
});
47+
48+
cmd.opt()
4649
.name('preset')
4750
.title('Name of a preset')
4851
.short('p').long('preset')
@@ -55,48 +58,53 @@ module.exports = {
5558
process.exit(1);
5659
}
5760
return val;
58-
})
59-
.end()
60-
.opt()
61+
});
62+
63+
cmd.opt()
6164
.name('charsAroundDiff')
6265
.title('The number of characters around the diff (default: 40)')
6366
.long('chars-around-diff')
6467
.def(40)
6568
.val(function(val) {
6669
return parseInt(val, 10);
67-
})
68-
.end()
69-
.arg()
70+
});
71+
72+
cmd.arg()
7073
.name('path1')
7174
.title('Path to the 1-st HTML file')
72-
.req()
73-
.end()
74-
.arg()
75+
.req();
76+
77+
cmd.arg()
7578
.name('path2')
7679
.title('Path to the 2-nd HTML file')
77-
.req()
78-
.end()
79-
.act(function(opts, args) {
80-
return vow.all([
81-
vfs.read(path.resolve(args.path1), 'utf-8'),
82-
vfs.read(path.resolve(args.path2), 'utf-8'),
83-
opts.config ? vfs.read(path.resolve(opts.config)) : undefined
84-
]).spread(function(html1, html2, config) {
85-
config = config ? JSON.parse(config) : {};
80+
.req();
81+
82+
cmd.act(async function(opts, args) {
83+
const [html1, html2, configFile] = await Promise.all([
84+
readAsync(path.resolve(args.path1), 'utf8'),
85+
readAsync(path.resolve(args.path2), 'utf8'),
86+
opts.config ? readAsync(path.resolve(opts.config), 'utf8') : undefined
87+
]);
88+
89+
const config = configFile ? JSON.parse(configFile) : {};
90+
91+
if (opts.preset) {
92+
config.preset = opts.preset;
93+
}
94+
95+
const options = defaults(config);
96+
const htmlDiffer = new HtmlDiffer(options);
8697

87-
if (opts.preset) {
88-
config.preset = opts.preset;
89-
}
98+
const diff = await htmlDiffer.diffHtml(html1, html2);
9099

91-
const options = defaults(config);
92-
const loggerOptions = {
93-
charsAroundDiff: opts.charsAroundDiff
94-
};
95-
const htmlDiffer = new HtmlDiffer(options);
100+
const loggerOptions = {
101+
charsAroundDiff: opts.charsAroundDiff
102+
};
103+
if (!diffLogger.logDiffText(diff, loggerOptions)) {
104+
process.exit(1);
105+
}
106+
}).run(argv.slice(2));
96107

97-
diffLogger.logDiffText(htmlDiffer.diffHtml(html1, html2), loggerOptions);
98-
});
99-
})
100-
.run(process.argv.slice(2));
108+
return cmd;
101109
}
102110
};

lib/logger.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,10 @@ function logDiffText(diff, options) {
7171

7272
if (diffText) {
7373
console.log(inverseGreen('+ expected'), inverseRed('- actual'), '\n', diffText);
74+
return false;
7475
}
76+
77+
return true;
7578
}
7679

7780
module.exports = {

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@
3030
"chalk": "^2.4.2",
3131
"coa": "^2.0.2",
3232
"diff": "^4.0.1",
33-
"parse5-sax-parser": "^5.1.0",
34-
"vow": "^0.4.20",
35-
"vow-fs": "^0.3.6"
33+
"parse5-sax-parser": "^5.1.0"
3634
},
3735
"devDependencies": {
3836
"eslint": "^6.0.1",

test/differ/isEqual.js

Lines changed: 60 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
const fs = require('fs');
22
const path = require('path');
3+
const util = require('util');
4+
const readAsync = util.promisify(fs.readFile);
35
const fixturesPath = path.join(__dirname, 'fixtures');
46
const HtmlDiffer = require('../../lib/index').HtmlDiffer;
57

@@ -9,61 +11,67 @@ const HtmlDiffer = require('../../lib/index').HtmlDiffer;
911
*/
1012
function readFiles(basename) {
1113
const fileName = basename + '.html';
12-
13-
return {
14-
html1: fs.readFileSync(path.join(fixturesPath, 'first', fileName), 'utf-8'),
15-
html2: fs.readFileSync(path.join(fixturesPath, 'second', fileName), 'utf-8')
16-
};
14+
return Promise.all([
15+
readAsync(path.join(fixturesPath, 'first', fileName), 'utf-8'),
16+
readAsync(path.join(fixturesPath, 'second', fileName), 'utf-8')
17+
]);
1718
}
1819

1920
describe('\'isEqual\'', function() {
2021
it('must be equal', async function() {
2122
const htmlDiffer = new HtmlDiffer();
22-
const files = readFiles('equal');
23+
const files = await readFiles('equal');
24+
const isEqual = await htmlDiffer.isEqual(...files);
2325

24-
(await htmlDiffer.isEqual(files.html1, files.html2)).must.be.true();
26+
isEqual.must.be.true();
2527
});
2628

2729
it('must be not equal', async function() {
2830
const htmlDiffer = new HtmlDiffer();
29-
const files = readFiles('not-equal');
31+
const files = await readFiles('not-equal');
32+
const isEqual = await htmlDiffer.isEqual(...files);
3033

31-
(await htmlDiffer.isEqual(files.html1, files.html2)).must.be.false();
34+
isEqual.must.be.false();
3235
});
3336

3437
it('must consider uppercase and lowercase declarations in \'doctype\' to be equal', async function() {
3538
const htmlDiffer = new HtmlDiffer();
36-
const files = readFiles('doctype');
39+
const files = await readFiles('doctype');
40+
const isEqual = await htmlDiffer.isEqual(...files);
3741

38-
(await htmlDiffer.isEqual(files.html1, files.html2)).must.be.true();
42+
isEqual.must.be.true();
3943
});
4044

4145
it('must sort attributes', async function() {
4246
const htmlDiffer = new HtmlDiffer();
43-
const files = readFiles('sort-attributes');
47+
const files = await readFiles('sort-attributes');
48+
const isEqual = await htmlDiffer.isEqual(...files);
4449

45-
(await htmlDiffer.isEqual(files.html1, files.html2)).must.be.true();
50+
isEqual.must.be.true();
4651
});
4752

4853
it('must sort classes\' values', async function() {
4954
const htmlDiffer = new HtmlDiffer();
50-
const files = readFiles('sort-classes');
55+
const files = await readFiles('sort-classes');
56+
const isEqual = await htmlDiffer.isEqual(...files);
5157

52-
(await htmlDiffer.isEqual(files.html1, files.html2)).must.be.true();
58+
isEqual.must.be.true();
5359
});
5460

5561
it('must sort values of attributes as JSON when the content is not a function', async function() {
5662
const htmlDiffer = new HtmlDiffer({ compareAttributesAsJSON: ['a', { name: 'b', isFunction: false }] });
57-
const files = readFiles('sort-values-in-json-format');
63+
const files = await readFiles('sort-values-in-json-format');
64+
const isEqual = await htmlDiffer.isEqual(...files);
5865

59-
(await htmlDiffer.isEqual(files.html1, files.html2)).must.be.true();
66+
isEqual.must.be.true();
6067
});
6168

6269
it('must handle invalid JSON', async function() {
6370
const htmlDiffer = new HtmlDiffer({ compareAttributesAsJSON: ['data-bem'] });
64-
const files = readFiles('invalid-json');
71+
const files = await readFiles('invalid-json');
72+
const isEqual = await htmlDiffer.isEqual(...files);
6573

66-
(await htmlDiffer.isEqual(files.html1, files.html2)).must.be.true();
74+
isEqual.must.be.true();
6775
});
6876

6977
it('must sort values of attributes as JSON when the content is a function', async function() {
@@ -74,80 +82,91 @@ describe('\'isEqual\'', function() {
7482
]
7583
};
7684
const htmlDiffer = new HtmlDiffer(options);
77-
const files = readFiles('sort-functions-in-json-format');
85+
const files = await readFiles('sort-functions-in-json-format');
86+
const isEqual = await htmlDiffer.isEqual(...files);
7887

79-
(await htmlDiffer.isEqual(files.html1, files.html2)).must.be.true();
88+
isEqual.must.be.true();
8089
});
8190

8291
it('must handle invalid function', async function() {
8392
const options = { compareAttributesAsJSON: [{ name: 'onclick', isFunction: true }] };
8493
const htmlDiffer = new HtmlDiffer(options);
85-
const files = readFiles('invalid-function');
94+
const files = await readFiles('invalid-function');
95+
const isEqual = await htmlDiffer.isEqual(...files);
8696

87-
(await htmlDiffer.isEqual(files.html1, files.html2)).must.be.true();
97+
isEqual.must.be.true();
8898
});
8999

90100
it('must work option \'ignoreAttributes\'', async function() {
91101
const htmlDiffer = new HtmlDiffer({ ignoreAttributes: ['id', 'for'] });
92-
const files = readFiles('ignore-attributes');
102+
const files = await readFiles('ignore-attributes');
103+
const isEqual = await htmlDiffer.isEqual(...files);
93104

94-
(await htmlDiffer.isEqual(files.html1, files.html2)).must.be.true();
105+
isEqual.must.be.true();
95106
});
96107

97108
it('must work option \'ignoreWhitespaces\'', async function() {
98109
const htmlDiffer = new HtmlDiffer({ ignoreWhitespaces: true });
99-
const files = readFiles('ignore-whitespaces');
110+
const files = await readFiles('ignore-whitespaces');
111+
const isEqual = await htmlDiffer.isEqual(...files);
100112

101-
(await htmlDiffer.isEqual(files.html1, files.html2)).must.be.true();
113+
isEqual.must.be.true();
102114
});
103115

104116
it('must work option \'ignoreComments\'', async function() {
105117
const htmlDiffer = new HtmlDiffer();
106-
const files = readFiles('ignore-comments');
118+
const files = await readFiles('ignore-comments');
119+
const isEqual = await htmlDiffer.isEqual(...files);
107120

108-
(await htmlDiffer.isEqual(files.html1, files.html2)).must.be.true();
121+
isEqual.must.be.true();
109122
});
110123

111124
it('must does NOT work option \'ignoreComments\'', async function() {
112125
const htmlDiffer = new HtmlDiffer({ ignoreComments: false });
113-
const files = readFiles('ignore-comments-false');
126+
const files = await readFiles('ignore-comments-false');
127+
const isEqual = await htmlDiffer.isEqual(...files);
114128

115-
(await htmlDiffer.isEqual(files.html1, files.html2)).must.be.true();
129+
isEqual.must.be.true();
116130
});
117131

118132
it('must work option \'ignoreEndTags\'', async function() {
119133
const htmlDiffer = new HtmlDiffer({ ignoreEndTags: true });
120-
const files = readFiles('ignore-end-tags');
134+
const files = await readFiles('ignore-end-tags');
135+
const isEqual = await htmlDiffer.isEqual(...files);
121136

122-
(await htmlDiffer.isEqual(files.html1, files.html2)).must.be.true();
137+
isEqual.must.be.true();
123138
});
124139

125140
it('must work \'bem\' preset', async function() {
126141
const htmlDiffer = new HtmlDiffer('bem');
127-
const files = readFiles('bem-preset');
142+
const files = await readFiles('bem-preset');
143+
const isEqual = await htmlDiffer.isEqual(...files);
128144

129-
(await htmlDiffer.isEqual(files.html1, files.html2)).must.be.true();
145+
isEqual.must.be.true();
130146
});
131147

132148
it('must work mask {{RegExp}}', async function() {
133149
const htmlDiffer = new HtmlDiffer();
134-
const files = readFiles('mask');
150+
const files = await readFiles('mask');
151+
const isEqual = await htmlDiffer.isEqual(...files);
135152

136-
(await htmlDiffer.isEqual(files.html1, files.html2)).must.be.true();
153+
isEqual.must.be.true();
137154
});
138155

139156
it('must not be equal by mask {{RegExp}}', async function() {
140157
const htmlDiffer = new HtmlDiffer();
141-
const files = readFiles('mask-false');
158+
const files = await readFiles('mask-false');
159+
const isEqual = await htmlDiffer.isEqual(...files);
142160

143-
(await htmlDiffer.isEqual(files.html1, files.html2)).must.be.false();
161+
isEqual.must.be.false();
144162
});
145163

146164
it('must ignore self closing slash', async function() {
147165
const htmlDiffer = new HtmlDiffer({ ignoreSelfClosingSlash: true });
148-
const files = readFiles('strip-self-closing-slash');
166+
const files = await readFiles('strip-self-closing-slash');
167+
const isEqual = await htmlDiffer.isEqual(...files);
149168

150-
(await htmlDiffer.isEqual(files.html1, files.html2)).must.be.true();
169+
isEqual.must.be.true();
151170
});
152171

153172
it('must throw an error for invalid preset', function() {

0 commit comments

Comments
 (0)