-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgulpfile.js
77 lines (67 loc) · 2.53 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
77
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", async () => {
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}`,
);
shell.exec(
`webpack --mode=development --devtool=eval-source-map\
--output-path=${customComponentLocation}`,
{ fatal: true },
);
} else {
throw new Error(
"Env var CLIENT_DIR is not defined in the .env file. It should be set to the weblicent directory.",
);
}
});
gulp.task("dev:spm", () => {
if (!process.env.CLIENT_DIR) {
throw new Error(
"Env var CLIENT_DIR is not defined in the .env file. It should be set to the weblicent directory.",
);
}
const cdejLocation =
process.env.RELATIVE_PATH_TO_BUNDLE || "CDEJ/jscript/SPMUIComponents";
const output =
`${process.env.CLIENT_DIR}/WebContent/${cdejLocation}` ||
path.resolve(__dirname, "/dist");
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\
`,
{ fatal: true },
);
shell.echo(
`\n\n[INFO] Bundle Generated into ${output} \n[INFO] Watching for file changes`,
);
});
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();
});