forked from merative/spm-ui-addon-devenv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
77 lines (64 loc) · 2.67 KB
/
gulpfile.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
/* eslint-disable no-console */
const path = require('path');
const gulp = require('gulp');
const shell = require('shelljs');
// Load env vars from the .env file.
require('dotenv').config();
/*
* This task generates a development bundle to the specified output folder.
* Also the bundle is generated, it watches the projects folder for changes.
* Any changes in the project kicks off a Delta bundle generator only for
* the file that was changed.
*
* - The output folder is defined in the .env file
* through the variable: CLIENT_DIR
* If not variable is defined, it defaults to /dist
*
* - The development bundle uses the source maps strategy "eval-source-map"
* It is the slowest build option but it enables the developer to debug
* on the browser exactly the same code he sees in the code editor
* before it is transpiled by Babel.
*/
gulp.task('deploy:spm', () => {
if (process.env.CLIENT_DIR) {
const customComponentName = process.env.CUSTOM_COMPONENT_NAME || "custom";
const customComponentLocation = process.env.CLIENT_DIR + "/components/" + customComponentName + "/WebContent/CDEJ/jscript/SPMUIComponents";
shell.echo(`\n[INFO] Copying the generated files to custom component: ${customComponentLocation}
[INFO] Any changes to the files will automatically trigger a new bundle generation.`);
shell.exec(
`webpack --mode=development --devtool=eval-source-map\
--output-path=${customComponentLocation} --watch=true --hide-modules=true\
--build-delimiter="\n\n[INFO] Bundle Generated into ${customComponentLocation} \n[INFO] Watching for file changes."`,
{ fatal: true }
);
}
});
gulp.task('dev:spm', () => {
const cdejLocation = process.env.RELATIVE_PATH_TO_BUNDLE || "CDEJ/jscript/SPMUIComponents";
const output =
process.env.CLIENT_DIR + "/WebContent/" + cdejLocation ||
path.resolve(__dirname, '/dist');
if (!process.env.CLIENT_DIR) {
shell.echo(
`\n[WARNING] Env var CLIENT_DIR not defined in the .env file.
Using Default Output: ${output}`
);
}
shell.echo(`\n[INFO] Generating the dev bundle to path: ${output}
[INFO] Any changes to the files will automatically trigger a new bundle generation.`);
shell.exec(
`webpack --mode=development --devtool=eval-source-map\
--output-path=${output} --watch=true --hide-modules=true\
--build-delimiter="\n\n[INFO] Bundle Generated into ${output} \n[INFO] Watching for file changes."`,
{ fatal: true }
);
});
gulp.task('prod:spm', (done) => {
const output = path.resolve(__dirname, '/dist');
shell.echo(`\n[INFO] Generating the dev bundle to path: ${output}.`);
shell.exec(
`webpack --mode production`,
{ fatal: true}
);
done();
});