-
Notifications
You must be signed in to change notification settings - Fork 12
/
index.js
executable file
·63 lines (48 loc) · 1.47 KB
/
index.js
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
#!/usr/bin/env node
'use strict';
const colors = require('colors/safe');
const analyser = require('./lib/analyser');
const args = require('./lib/arguments');
const utils = require('./lib/utils');
/**
* MAIN FUNCTION
*
* Entry function for `ember-unused-components`
*/
function main() {
const commandOptions = args.init();
let config;
// Read config
try {
config = utils.getConfig(commandOptions);
} catch (e) {
console.log(e);
console.log(
colors.red("Can't find Ember config. Are you sure you are running this in root directory?")
);
if (commandOptions.debug) {
console.log(e);
}
return;
}
// Main sequence
console.log(colors.dim('[1/3]'), '🗺️ Mapping the project...');
analyser.mapComponents(config);
if (commandOptions.debug) {
console.log(colors.blue('indexed components:'));
console.log(analyser.components);
}
console.log(colors.dim('[2/3]'), '🔍 Looking for components usage...');
analyser.scanProject(config);
if (commandOptions.debug) {
console.log(colors.blue('scanned for occurrences in:'));
console.log(config.sourcePaths);
}
analyser.respectWhitelist(config.whitelist);
console.log(colors.dim('[3/3]'), '✔️ Done');
analyser.logResults(commandOptions.stats, commandOptions.occurrences, config.whitelist);
if (config.failOnUnused && analyser.unusedComponents.length) {
throw new Error(`You have ${analyser.unusedComponents.length} unused components.`);
}
}
main();