-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
/
compilejs.es6.js
64 lines (59 loc) · 1.96 KB
/
compilejs.es6.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
const Fs = require('fs');
const Recurs = require('recursive-readdir');
const HandleFile = require('./javascript/handle-file.es6.js');
const RootPath = require('./utils/rootpath.es6.js')._();
/**
* Method that will crawl the media_source folder and
* compile ES6 to ES5 and ES6
* copy any ES5 files to the appropriate destination and
* minify them in place
* compile any custom elements/webcomponents
*
* Expects ES6 files to have ext: .es6.js
* ES5 files to have ext: .es5.js
* WC/CE files to have ext: .w-c.es6.js
*
* @param { object } options The options from settings.json
* @param { string } path The folder that needs to be compiled, optional
*/
module.exports.compileJS = (options, path) => {
Promise.resolve(options, path)
// Compile the scss files
.then((options, path) => {
let folders = [];
if (path) {
const stats = Fs.lstatSync(`${RootPath}/${path}`);
if (!stats.isDirectory()) {
// @todo: allow to compile single file
throw new Error(`Path should be a directory: ${path}`);
}
folders.push(`${RootPath}/${path}`);
} else {
folders = [
`${RootPath}/build/media_source`,
`${RootPath}/administrator/templates/atum/js`,
`${RootPath}/templates/cassiopeia/js`,
];
}
// Loop to get some text for the packgage.json
folders.forEach((folder) => {
Recurs(folder, ['*.min.js', '*.map', '*.scss', '*.css', '*.svg', '*.png', '*.swf', '*.gif', '*.json']).then(
(files) => {
files.forEach(
(file) => {
HandleFile.run(file);
},
(error) => {
// eslint-disable-next-line no-console
console.error(`something exploded ${error}`);
},
);
},
);
});
})
// Handle errors
.catch((error) => {
throw new Error(`${error}`);
});
};