-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.js
More file actions
67 lines (57 loc) · 1.89 KB
/
utils.js
File metadata and controls
67 lines (57 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
const chalk = require('chalk');
const FIRST_COL_WIDTH = 60;
const Formatting = {
ARROW: '\u27F6',
CHECKMARK: '\u2714',
}
class PrintHelper {
printOK() {
console.log(chalk.greenBright(`Nothing to cache bust: ${Formatting.CHECKMARK}`))
}
printNeedCacheBust(isWebpack) {
if (isWebpack) {
console.log(chalk.underline.red(`You need to cache bust the following webpack entry points:\n`));
} else {
console.log(chalk.underline.red(`You need to cache bust the following javascript files:\n`));
}
}
printShouldFetchLatest(missingImport) {
console.log(chalk.underline.yellow('Note: '), `If you're seeing things you didn't change, try pulling the latest from master \n`);
}
printMissingImport(importsFound, key) {
let output = chalk.magenta(key);
for (var i = key.length + 2; i < FIRST_COL_WIDTH; i ++) {
output = `${output} `;
}
output = `${output}${Formatting.ARROW} `
const importSet = new Set(importsFound[key])
const setIterator = importSet.entries();
let entry = setIterator.next();
while(!entry.done) {
output = `${output} ${entry.value[0]}`
entry = setIterator.next();
if (!entry.done) output = `${output}, `;
}
console.log(output)
}
printImportResults(imports, isWebpack) {
if (Object.keys(imports).length !== 0) {
this.printNeedCacheBust(isWebpack);
Object.keys(imports).forEach((key) => {
this.printMissingImport(imports, key)
});
}
console.log('\n');
}
printResults(importsFound, nonWebpackImportsFound) {
console.log('\n')
if (Object.keys(importsFound).length === 0 && Object.keys(nonWebpackImportsFound).length === 0) {
this.printOK();
} else {
this.printImportResults(importsFound, true)
this.printImportResults(nonWebpackImportsFound, false);
this.printShouldFetchLatest();
}
}
}
module.exports = {PrintHelper};