-
-
Notifications
You must be signed in to change notification settings - Fork 117
/
gulpfile.js
324 lines (289 loc) · 15 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
const fs = require("fs");
const path = require("path");
const gulp = require("gulp");
const shell = require("gulp-shell");
const replace = require('gulp-replace');
const merge = require('merge-stream');
const browserify = require('browserify');
const tsify = require('tsify');
const watchify = require('watchify');
const exorcist = require('exorcist')
const ts = require('gulp-typescript');
const sass = require('gulp-sass')(require('sass'));
let minify = true;
let watch = false;
const OpenFlowPublicFiles = [
"./OpenFlow/src/public/**/*.html", "./OpenFlow/src/public/**/*.css", "./OpenFlow/src/public/**/*.js", "./OpenFlow/src/public/**/*.json",
"./OpenFlow/src/public/**/*.ico", "./OpenFlow/src/public/**/*.eot", "./OpenFlow/src/public/**/*.svg", "./OpenFlow/src/public/**/*.ttf",
"./OpenFlow/src/public/**/*.woff", "./OpenFlow/src/public/**/*.woff2", "./OpenFlow/src/public/**/*.png", "./OpenFlow/src/public/**/*.lang",
"./OpenFlow/src/public/**/*.json"];
const NodeREDHTMLFiles = ["./OpenFlowNodeRED/src/nodered/nodes/**/*.html", "./OpenFlowNodeRED/src/nodered/nodes/**/*.png", "./OpenFlowNodeRED/src/nodered/nodes/**/*.json"]
const publicdestination = "./dist/public";
const mapfile = path.join(__dirname, publicdestination, 'bundle.js.map')
let version = "0.0.1";
if (fs.existsSync("../package.json")) {
var p = require("../package.json");
version = p.version;
} else if (fs.existsSync("package.json")) {
var p = require("./package.json");
version = p.version;
}
gulp.task("copyfiles1", function () {
console.log("copyfiles1")
const openflow = gulp.src(OpenFlowPublicFiles).pipe(gulp.dest(publicdestination));
const copyspurce = gulp.src('./OpenFlow/src/public/**/*.ts').pipe(gulp.dest(publicdestination + '/OpenFlow/src/public'));
const copyproto = gulp.src('./proto/**/*.*').pipe(gulp.dest('./dist/proto/proto'));
return merge(openflow, copyspurce, copyproto);
});
gulp.task("setwatch", async function () {
minify = false;
watch = true;
});
gulp.task("dowatch", function () {
console.log("watch")
return gulp.watch(NodeREDHTMLFiles.concat(OpenFlowPublicFiles)
.concat('./OpenFlow/src/public/**/*.ts')
.concat('./OpenFlow/src/proto/**/*.*')
, gulp.series("browserify", "copyfiles1"));
});
gulp.task("filewatch", function () {
console.log("watch")
return gulp.watch(NodeREDHTMLFiles.concat(OpenFlowPublicFiles)
.concat('./OpenFlow/src/public/**/*.ts')
.concat('./OpenFlow/src/proto/**/*.*')
, gulp.series( "copyfiles1"));
});
gulp.task('dosass', function () {
return gulp
.src('./OpenFlow/src/public/**/*.scss')
.pipe(sass().on('error', sass.logError))
.pipe(gulp.dest('./OpenFlow/src/public'));
});
gulp.task("sass", gulp.series("dosass", "copyfiles1"));
let bfi = null;
gulp.task("deps", function () {
if (bfi != null) return gulp.src('.');
const config = {
entries: ['./OpenFlow/src/public/app.ts'],
cache: {},
packageCache: {},
debug: true,
basedir: '.',
plugin: []
}
bfi = browserify(config)
.plugin(tsify, { noImplicitAny: false, skipLibCheck: true });
bfi.pipeline.get('deps').push(require('through2').obj(
function (row, enc, next) {
var wasok = false;
try {
var stats = fs.statSync(row.file || row.id);
var fileSizeInBytes = stats.size
var fileSizeInMegabytes = fileSizeInBytes / (1024 * 1024);
fileSizeInMegabytes = parseFloat(fileSizeInMegabytes).toFixed(2);
console.log((row.file || row.id) + " " + fileSizeInMegabytes + "mb");
wasok = true;
} catch (error) {
console.log(error)
}
if (!wasok) {
console.log(row.file || row.id);
}
next();
}
));
function bundle() {
console.log('browserify bundle::begin()');
const result = bfi.bundle()
.on('error', function (error) {
console.log(error.message ? error.message : error);
this.emit('end');
})
.pipe(exorcist(mapfile))
.pipe(fs.createWriteStream('./dist/public/bundle.js'));
return result;
};
return bundle();
});
gulp.task("browserify", function () {
console.log("browserify")
if (bfi != null) return gulp.src('.');
const config = {
entries: ['./OpenFlow/src/public/app.ts'],
cache: {},
packageCache: {},
debug: true,
basedir: '.',
plugin: []
}
if (watch) {
console.log("Addin watchify")
config.plugin.push(watchify);
}
bfi = browserify(config)
.plugin(tsify, { noImplicitAny: false, skipLibCheck: true });
if (minify) bfi.plugin('tinyify', {})
bfi.transform('browserify-css', {
minify: minify,
output: './dist/public/bundle.css'
,
// processRelativeUrl: function (relativeUrl) {
// if (relativeUrl.indexOf('..\\..\\..\\OpenFlow') > -1) {
// relativeUrl = relativeUrl.replace('..\\..\\..\\OpenFlow\\src\\public', '.');
// }
// try {
// var stripQueryStringAndHashFromPath = function (url) {
// return url.split('?')[0].split('#')[0];
// };
// var rootDir = path.resolve(process.cwd(), 'OpenFlow/src/public');
// var relativePath = stripQueryStringAndHashFromPath(relativeUrl);
// var queryStringAndHash = relativeUrl.substring(relativePath.length);
// // var prefix = '../node_modules/';
// var prefix = '..\\..\\..\\node_modules\\';
// if (relativeUrl.startsWith(relativePath, prefix)) {
// var vendorPath = 'vendor/' + relativePath.substring(prefix.length);
// vendorPath = vendorPath.replace("@", "");
// console.log("vendorPath: " + vendorPath)
// var source = path.join(rootDir, relativePath);
// var target = path.join(rootDir, vendorPath);
// if (fs.existsSync(source)) {
// fs.mkdirSync(path.dirname(target), { recursive: true });
// fs.copyFileSync(source, target);
// } else if (source.indexOf('fontawesome-webfont') > -1) {
// // console.error(source + " WHAT?????")
// } else {
// console.error(source + " not found")
// }
// // Returns a new path string with original query string and hash fragments
// return vendorPath + queryStringAndHash;
// }
// } catch (error) {
// console.error(error);
// }
// return relativeUrl;
// }
})
;
// .transform('browserify-shim', { global: true })
bfi.on('update', bundle);
bfi.on('error', function (error) {
console.error(error.message ? error.message : error);
this.emit('end');
});
bfi.on('time', function (time) {
if (time < 1499) {
console.log('browserify bundle::end() in ' + time + ' ms');
} else {
console.log('browserify bundle::end() in ' + (time / 1000) + ' s');
}
})
function bundle() {
console.log('browserify bundle::begin()');
const result = bfi.bundle()
.on('error', function (error) {
console.log(error.message ? error.message : error);
this.emit('end');
})
.pipe(exorcist(mapfile))
.pipe(fs.createWriteStream('./dist/public/bundle.js'));
return result;
};
return bundle();
});
// 'echo "compile OpenFlowNodeRED"',
// 'cd OpenFlowNodeRED && tsc -p tsconfig.json',
// 'echo "compile OpenFlow"',
// 'tsc -p OpenFlow/tsconfig.json',
// 'echo "delete npmrc and cache"',
// 'if exist "OpenFlowNodeRED\\dist\\nodered\\.npmrc" del OpenFlowNodeRED\\dist\\nodered\\.npmrc',
// 'if exist "OpenFlowNodeRED\\dist\\.cache" rmdir OpenFlowNodeRED\\dist\\.cache /s /q ',
// 'gulp copyfiles1',
// 'gulp browserify',
// 'echo "delete npmrc and cache"',
// 'if exist "OpenFlowNodeRED\\dist\\nodered\\.npmrc" del OpenFlowNodeRED\\dist\\nodered\\.npmrc',
// 'if exist "OpenFlowNodeRED\\dist\\.cache" rmdir OpenFlowNodeRED\\dist\\.cache /s /q ',
// 'gulp copyfiles1',
// 'gulp browserify',
// gulp.task("compose", shell.task([
// // docker buildx create --name openiap --use
// // docker buildx use default
// // docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6 -t openiap/openflow:edge .
// `echo "docker buildx build -t openiap/openflow:edge -t openiap/openflow:` + version + ` --platform linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6 --push ."`,
// `echo "docker buildx build -t openiap/nodered:edge -t openiap/nodered:` + version + ` --platform linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6 --push --file ./OpenFlowNodeRED/Dockerfile ."`,
// `echo "docker buildx build -t openiap/nodered-puppeteer:edge -t openiap/nodered-puppeteer:` + version + ` --platform linux/amd64 --push -f ./OpenFlowNodeRED/Dockerfilepuppeteer ."`,
// `echo "docker buildx build -t openiap/nodered-tagui:edge -t openiap/nodered-tagui:` + version + ` --platform linux/amd64 --push -f ./OpenFlowNodeRED/Dockerfiletagui ."`,
// `docker buildx build -t openiap/openflow:edge -t openiap/openflow:` + version + ` --platform linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6 --push .`,
// `docker buildx build -t openiap/nodered:edge -t openiap/nodered:` + version + ` --platform linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6 --file ./OpenFlowNodeRED/Dockerfile --push .`,
// `docker buildx build -t openiap/nodered-puppeteer:edge -t openiap/nodered-puppeteer:` + version + ` --platform linux/amd64 --push -f ./OpenFlowNodeRED/Dockerfilepuppeteer .`,
// `docker buildx build -t openiap/nodered-tagui:edge -t openiap/nodered-tagui:` + version + ` --platform linux/amd64 --push -f ./OpenFlowNodeRED/Dockerfiletagui .`,
// ]));
gulp.task("compose", async function (done) {
var versions = ["-t openiap/openflow:edge", "-t openiap/openflow:" + version]
const dotCount = version.split('.').length - 1;
if(dotCount == 3){
majorversion = version.substring(0, version.lastIndexOf('.'));
versions.push("-t openiap/openflow:" + majorversion);
}
console.log(versions)
return shell.task([`docker buildx build ${versions.join(" ")} --platform linux/amd64 --push .`])();
});
gulp.task("latest", async function (done) {
var versions = ["-t openiap/openflow:latest", "-t openiap/openflow:edge", "-t openiap/openflow:" + version]
const dotCount = version.split('.').length - 1;
if(dotCount == 3){
majorversion = version.substring(0, version.lastIndexOf('.'));
versions.push("-t openiap/openflow:" + majorversion);
}
console.log(versions)
return shell.task([`docker buildx build ${versions.join(" ")} --platform linux/amd64 --push .`])();
});
/*
docker buildx build -t openiap/openflow:edge -t openiap/openflow:latest -t openiap/openflow:1.5.0 --platform linux/amd64 --push .
docker buildx build -t openiap/openflow:edge -t openiap/openflow:latest -t openiap/openflow:1.5.0 --platform linux/arm/v7 --push .
docker buildx build -t openiap/openflow:edge -t openiap/openflow:latest -t openiap/openflow:1.5.0 --platform linux/arm/v6 --push .
gulp.task("latest", shell.task([
`echo "docker buildx build -t openiap/openflow:edge -t openiap/openflow:latest -t openiap/openflow:` + version + ` --platform linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6 --push ."`,
// `echo "docker buildx build -t openiap/nodered:edge -t openiap/nodered:latest -t openiap/nodered:` + version + ` --platform linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6 --push --file ./OpenFlowNodeRED/Dockerfile ."`,
// `echo "docker buildx build -t openiap/nodered-puppeteer:edge -t openiap/nodered-puppeteer:latest -t openiap/nodered-puppeteer:` + version + ` --platform linux/amd64 --push -f ./OpenFlowNodeRED/Dockerfilepuppeteer ."`,
// `echo "docker buildx build -t openiap/nodered-tagui:edge -t openiap/nodered-tagui:latest -t openiap/nodered-tagui:` + version + ` --platform linux/amd64 --push -f ./OpenFlowNodeRED/Dockerfiletagui ."`,
// ,linux/arm64,linux/arm/v7,linux/arm/v6
`docker buildx build -t openiap/openflow:edge -t openiap/openflow:latest -t openiap/openflow:` + version + ` --platform linux/amd64 --push .`,
// `docker buildx build -t openiap/nodered:edge -t openiap/nodered:latest -t openiap/nodered:` + version + ` --platform linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6 --push --file ./OpenFlowNodeRED/Dockerfile .`,
// `docker buildx build -t openiap/nodered-puppeteer:edge -t openiap/nodered-puppeteer:latest -t openiap/nodered-puppeteer:` + version + ` --platform linux/amd64 --push -f ./OpenFlowNodeRED/Dockerfilepuppeteer .`,
// `docker buildx build -t openiap/nodered-tagui:edge -t openiap/nodered-tagui:latest -t openiap/nodered-tagui:` + version + ` --platform linux/amd64 --push -f ./OpenFlowNodeRED/Dockerfiletagui .`,
]));
*/
gulp.task("bumpprojectfiles", function () {
let data = require("./package.json");
console.log(data.version + " updated to " + version);
data.version = version;
let json = JSON.stringify(data, null, 2);
fs.writeFileSync("package.json", json);
// data.version = "1.1.57";
// json = JSON.stringify(data, null, 2);
// fs.writeFileSync("docker-package.json", json); // keep a project file that is not changed so we dont need to rebuild everything every time
// data = require("./OpenFlowNodeRED/package.json");
// console.log(data.version + " updated to " + version);
// data.version = version;
// json = JSON.stringify(data, null, 2);
// fs.writeFileSync("OpenFlowNodeRED/package.json", json);
// data.version = "1.1.57";
// json = JSON.stringify(data, null, 2);
// fs.writeFileSync("OpenFlowNodeRED/docker-package.json", json); // keep a project file that is not changed so we dont need to rebuild everything every time
return gulp.src('.');
});
var tsOpenFlowProject = ts.createProject('OpenFlow/tsconfig.json');
var tsNodeREDProject = ts.createProject('OpenFlowNodeRED/tsconfig.json');
gulp.task('ts-openflow', function () {
var tsResult = tsOpenFlowProject.src().pipe(tsOpenFlowProject());
return tsResult.js.pipe(gulp.dest('dist'));
});
gulp.task('ts-nodered', function () {
var tsResult = tsNodeREDProject.src().pipe(tsNodeREDProject());
return tsResult.js.pipe(gulp.dest('OpenFlowNodeRED/dist'));
});
gulp.task("ts", gulp.series("ts-openflow", "ts-nodered"));
gulp.task("build", gulp.series("copyfiles1", "sass", "ts", "browserify", "copyfiles1"));
gulp.task("bump", gulp.series("bumpprojectfiles", "copyfiles1"));
gulp.task("watch", gulp.series("setwatch", "browserify", "copyfiles1", "dowatch"));
gulp.task("default", gulp.series("copyfiles1", "browserify", "copyfiles1"));