1 | const { readFile } = require('fs-extra');
|
2 |
|
3 | const getJsPathsExceptTests = require('./helpers/getJsPathsExceptTests');
|
4 | const bundleJsImports = require('./helpers/bundleJsImports');
|
5 | const transformImportToCjs = require('./helpers/transformImportToCjs');
|
6 | const transformEs6ToEs5 = require('./helpers/transformEs6ToEs5');
|
7 | const safeWriteFile = require('./helpers/safeWriteFile');
|
8 |
|
9 | console.log('Building');
|
10 |
|
11 | (async () => {
|
12 | console.log('Started');
|
13 |
|
14 | let context;
|
15 |
|
16 |
|
17 |
|
18 | context = await getJsPathsExceptTests('./src');
|
19 |
|
20 | await Promise.all(context.map((filePath) => {
|
21 | const es6Path = filePath.replace('/src/', '/dist/es/es6/');
|
22 | const es5Path = filePath.replace('/src/', '/dist/es/es5/');
|
23 |
|
24 | return readFile(filePath, 'utf8')
|
25 | .then(safeWriteFile(es6Path))
|
26 | .then(transformEs6ToEs5)
|
27 | .then(safeWriteFile(es5Path));
|
28 | }));
|
29 |
|
30 |
|
31 |
|
32 | context = await getJsPathsExceptTests('./dist/es/es6');
|
33 |
|
34 | await Promise.all(context.map((filePath) => {
|
35 | const es6Path = filePath.replace('/dist/es/es6/', '/dist/cjs/es6/');
|
36 | const es5Path = filePath.replace('/dist/es/es6/', '/dist/cjs/es5/');
|
37 |
|
38 | return readFile(filePath, 'utf8')
|
39 | .then(transformImportToCjs)
|
40 | .then(safeWriteFile(es6Path))
|
41 | .then(transformEs6ToEs5)
|
42 | .then(safeWriteFile(es5Path));
|
43 | }));
|
44 |
|
45 |
|
46 |
|
47 | context = ['./dist/es/es6/index.js'];
|
48 |
|
49 | await Promise.all(context.map((filePath) => {
|
50 | const es6Path = filePath.replace('/dist/es/es6/', '/dist/iife/es6/');
|
51 | const es5Path = filePath.replace('/dist/es/es6/', '/dist/iife/es5/');
|
52 |
|
53 | return Promise.resolve(filePath)
|
54 | .then(bundleJsImports('SlingSdk'))
|
55 | .then(safeWriteFile(es6Path))
|
56 | .then(transformEs6ToEs5)
|
57 | .then(safeWriteFile(es5Path));
|
58 | }));
|
59 |
|
60 | console.log('Finished');
|
61 | })();
|