This repository has been archived by the owner on Sep 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
gulpfile.js
48 lines (44 loc) · 2.03 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
const {src, dest, series} = require('gulp');
const filter = require('gulp-filter');
const zip = require('gulp-zip');
const ngPackagr = require('ng-packagr');
const fs = require('fs-extra');
const del = require('del');
const execSync = require('child_process').execSync;
const replace = require('gulp-replace');
const path = require('path');
function clean() {
return del(['dist']);
}
const compile = series(
function buildAngularLibrary() { return ngPackagr.build({project: './ng-package.json'}) },
function separateWebpackBuildSrc() { return fs.copy('./dist/widget-library/fesm5', './dist/bundle-src') },
function replaceStylePath() {
return src('./dist/widget-library/**/*')
.pipe(replace(/~styles/g, function () {
return path.relative(this.file.dirname, './dist/widget-library/styles').replace(/\\/g, '/')
}))
.pipe(dest('./dist/widget-library/'))
},
async function packLibrary() { return execSync("npm pack ./widget-library", { cwd: './dist', stdio: 'inherit' }) }
)
const bundle = series(
async function webpackBuild() { return execSync("npx webpack", {stdio: 'inherit'}) },
function copyCumulocityJson() { return fs.copy('./cumulocity.json', './dist/widget/cumulocity.json')},
function createZip() {
return src('./dist/widget/**/*')
// Filter out the webpackRuntime chunk, we only need the widget code chunks
.pipe(filter(file => !/^[a-f0-9]{20}\.js(\.map)?$/.test(file.relative)))
.pipe(zip('widget.zip'))
.pipe(dest('dist/'))
}
)
exports.clean = clean;
exports.build = compile;
exports.bundle = bundle;
exports.default = series(clean, compile, bundle, async function success() {
console.log("Build Finished Successfully!");
console.log("Runtime Widget Output (Install in the browser): dist/widget.zip");
const pkgJson = require('./dist/widget-library/package.json');
console.log(`Widget Angular Library (Install with: "npm i <filename.tgz>"): dist/${pkgJson.name}-${pkgJson.version}.tgz`);
});