This repository has been archived by the owner on Jul 28, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
/
build.js
105 lines (90 loc) · 3.22 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
/**
* Command line helper
*
* To get the complete functional media folder please run
*
* npm install
*
* For dedicated tasks, please run:
* node build.js --build-pages === will create the error pages (for incomplete repo build PHP+NPM)
* 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-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 errorPages = require('./build/build-modules-js/error-pages.es6.js');
const init = require('./build/build-modules-js/init.es6.js');
const compileCSS = require('./build/build-modules-js/compilecss.es6.js');
const compileJS = require('./build/build-modules-js/compilejs.es6.js');
const minifyVendor = require('./build/build-modules-js/javascript/minify-vendor.es6.js');
const watch = require('./build/build-modules-js/watch.es6.js');
// 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('--build-pages', 'Creates the error pages for unsupported PHP version & incomplete environment')
.option('--compile-js, --compile-js path', 'Handles ES6, ES5 and web component scripts')
.option('--compile-css, --compile-css path', 'Compiles all the scss files to css')
.option('--watch', 'Watch file changes and re-compile (ATM only works for the js in the media_source).')
.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(init.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.buildPages) {
Promise.resolve()
.then(() => {
errorPages.run(options);
})
// Handle errors
.catch((err) => {
// eslint-disable-next-line no-console
console.error(err);
process.exit(-1);
});
}
// Convert scss to css
if (Program.compileCss) {
compileCSS.compile(options, Program.args[0]);
}
// Compress/transpile the javascript files
if (Program.compileJs) {
compileJS.compileJS(options, Program.args[0]);
}
// Compress/transpile the javascript files
if (Program.watch) {
watch.run();
watch.runScss();
}