This repository has been archived by the owner on May 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathbuild.js
106 lines (91 loc) · 3.51 KB
/
build.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/**
* Command line helper
*
* To get the complete functional media folder please run
*
* npm install
*
* For dedicated tasks, please run:
* node build.js --buildcheck === will create the error page (for incomplete repo build)
* node build.js --installer === will create the error page (for unsupported PHP version)
* node build.js --copy-assets === will clean the media/vendor folder and then will populate the folder from node_modules
* node build.js --compile-js === will transpile ES6 files and also uglify the ES6,ES5 files
* node build.js --compile-ce === will compile all the given CE or WC with their relative css files
* node build.js --compile-css === will compile all the scss defined files and also create a minified version of the css
*
*/
// eslint-disable-next-line import/no-extraneous-dependencies
const Program = require('commander');
// eslint-disable-next-line import/no-extraneous-dependencies
// Joomla Build modules
const buildCheck = require('./build/build-modules-js/build-check');
const copyAssets = require('./build/build-modules-js/update');
const compileCSS = require('./build/build-modules-js/compilescss');
const compileJS = require('./build/build-modules-js/compilejs');
const compileWebComponents = require('./build/build-modules-js/compilecejs');
const minifyVendor = require('./build/build-modules-js/minify-vendor');
// The settings
const options = require('./package.json');
const settings = require('./build/build-modules-js/settings.json');
// Merge Joomla's specific settings to the main package.json object
if ('settings' in settings) {
options.settings = settings.settings;
}
// Initialize the CLI
Program
.version(options.version)
.option('--copy-assets', 'Moving files from node_modules to media folder')
.option('--compile-js, --compile-js path', 'Compiles ES6 to ES5 scripts')
.option('--compile-css, --compile-css path', 'Compiles all the scss files to css')
.option('--compile-ce, --compile-ce path', 'Compiles/traspiles all the custom elements files')
.option('--watch, --watch path', 'Watch file changes and re-compile (Only work for compile-css and compile-js now).')
.option('--build-check', 'Creates the error pages for unsupported PHP version & incomplete environment')
.on('--help', () => {
// eslint-disable-next-line no-console
console.log(`Version: ${options.version}`);
process.exit(0);
})
.parse(process.argv);
// Show help by default
if (!process.argv.slice(2).length) {
Program.outputHelp();
process.exit(1);
}
// Update the vendor folder
if (Program.copyAssets) {
Promise.resolve()
.then(copyAssets.copyAssets(options))
.then(minifyVendor.compile(options))
// Exit with success
.then(() => process.exit(0))
// Handle errors
.catch((err) => {
// eslint-disable-next-line no-console
console.error(err);
process.exit(-1);
});
}
// Creates the error pages for unsupported PHP version & incomplete environment
if (Program.buildCheck) {
buildCheck.buildCheck(options);
}
// Convert scss to css
if (Program.compileCss) {
if (Program.watch) {
compileCSS.watch(options, null, true);
} else {
compileCSS.compileCSS(options, Program.args[0]);
}
}
// Compress/transpile the javascript files
if (Program.compileJs) {
if (Program.watch) {
compileJS.watch(options, null, false);
} else {
compileJS.compileJS(options, Program.args[0]);
}
}
// Compress/transpile the Custom Elements files
if (Program.compileCe) {
compileWebComponents.compile(options, Program.args[0]);
}