-
Notifications
You must be signed in to change notification settings - Fork 16
/
index.ts
57 lines (49 loc) · 1.12 KB
/
index.ts
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
#! /usr/bin/env node
/*
Find unused css inside Angular components
*/
import fs from 'fs';
import meow from 'meow';
import path from 'path';
import { Config } from './src/config';
import init from './src/init';
const defaultConfigPath = '.ngx-unused-css.json';
const cli = meow(
`
Usage
$ ngx-unused-css
Options
--config, -c override default config path
Examples
$ ngx-unused-css --config ngx-custom-unused-css.json
`,
{
flags: {
config: {
type: 'string',
alias: 'c'
}
}
}
);
let config: Config;
if (cli.flags.init) {
init();
} else {
if (cli.flags.config) {
config = require(path.join(__dirname, cli.flags.config));
} else if (fs.existsSync(path.resolve(defaultConfigPath))) {
config = require(path.resolve(defaultConfigPath));
} else {
throw new Error(
'Config not found, did you forgot to run ngx-unused-css --init?'
);
}
// Use dynamic import so config is initialized on every import
const mainPromise = import('./src/main');
mainPromise.then((res) => {
// Bootstrap library
// eslint-disable-next-line
new res.default(config);
});
}