forked from ancoopa/static-pages-bundler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·60 lines (54 loc) · 2.31 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
#!/usr/bin/env node
const { ArgumentParser } = require('argparse');
const { version } = require('./package.json');
const Bundler = require('./bundler');
const PATH_CONFIG = {
HTML: 'index.html',
DIST: 'dist',
ASSETS: 'assets',
CSS: 'css',
JS: 'js',
FOLDER: '',
};
const TAG_CONFIG = {
CSS: {
START: 'css',
END: '/css'
},
JS: {
START: 'js',
END: '/js'
}
};
const parser = new ArgumentParser({
description: 'Static Pages Bundler'
});
parser.add_argument('-v', '--version', { action: 'version', version });
parser.add_argument('-i', '--html', { help: 'The index html file path', default: PATH_CONFIG.HTML });
parser.add_argument('-d', '--dist', { help: 'The final dist/build folder path', default: PATH_CONFIG.DIST });
parser.add_argument('-a', '--assets', { help: 'The assets folder path', default: PATH_CONFIG.ASSETS });
parser.add_argument('-c', '--css', { help: 'The css folder path', default: PATH_CONFIG.CSS });
parser.add_argument('-j', '--js', { help: 'The js folder path', default: PATH_CONFIG.JS });
parser.add_argument('-tsc', '--tag-start-css', { help: 'The css start tag', default: TAG_CONFIG.CSS.START });
parser.add_argument('-tec', '--tag-end-css', { help: 'The css end tag', default: TAG_CONFIG.CSS.END });
parser.add_argument('-tsj', '--tag-start-js', { help: 'The js start tag', default: TAG_CONFIG.JS.START });
parser.add_argument('-tej', '--tag-end-js', { help: 'The js end tag', default: TAG_CONFIG.JS.END });
parser.add_argument('-f', '--folder', { help: 'The folder', default: PATH_CONFIG.FOLDER});
const args = parser.parse_args();
if (args.html) PATH_CONFIG.HTML = args.html;
if (args.dist) PATH_CONFIG.DIST = args.dist;
if (args.assets) PATH_CONFIG.ASSETS = args.assets;
if (args.css) PATH_CONFIG.CSS = args.css;
if (args.js) PATH_CONFIG.JS = args.js;
if (args.tag_start_css) TAG_CONFIG.CSS.START = args.tag_start_css;
if (args.tag_end_css) TAG_CONFIG.CSS.END = args.tag_end_css;
if (args.tag_start_js) TAG_CONFIG.JS.START = args.tag_start_js;
if (args.tag_end_js) TAG_CONFIG.JS.END = args.tag_end_js;
if (args.folder) {
const folder = `${args.folder}/`;
for (const property in PATH_CONFIG) {
if (property !== 'DIST' && property !== 'FOLDER') PATH_CONFIG[property] = `${folder}${PATH_CONFIG[property]}`;
}
PATH_CONFIG.FOLDER = folder;
}
new Bundler(PATH_CONFIG, TAG_CONFIG).create();