forked from open-rpa/openflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
265 lines (241 loc) · 10.7 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
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')
let minify = true;
let watch = false;
const OpenFlowFiles = [
"./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"];
const NodeREDHTMLFiles = ["./OpenFlowNodeRED/src/nodered/nodes/**/*.html", "./OpenFlowNodeRED/src/nodered/nodes/**/*.png", "./OpenFlowNodeRED/src/nodered/nodes/**/*.json"]
const destination = "./dist/public";
const mapfile = path.join(__dirname, destination, 'bundle.js.map')
let version = "0.0.1";
if (fs.existsSync("../VERSION")) {
version = fs.readFileSync("../VERSION", "utf8");
} else if (fs.existsSync("VERSION")) {
version = fs.readFileSync("VERSION", "utf8");
}
gulp.task("copyfiles1", function () {
console.log("copyfiles1")
const openflow = gulp.src(OpenFlowFiles).pipe(gulp.dest(destination));
const nodered = gulp.src(NodeREDHTMLFiles).pipe(gulp.dest("OpenFlowNodeRED/dist/nodered/nodes"));
const version1 = gulp.src('./VERSION').pipe(gulp.dest("./dist"));
const version2 = gulp.src('./VERSION').pipe(gulp.dest("OpenFlowNodeRED/dist"));
const copyspurce = gulp.src('./OpenFlow/src/public/**/*.ts').pipe(gulp.dest(destination + '/OpenFlow/src/public'));
return merge(openflow, nodered, version1, version2, copyspurce);
});
gulp.task("setwatch", async function () {
minify = false;
watch = true;
});
gulp.task("dowatch", function () {
console.log("watch")
return gulp.watch(NodeREDHTMLFiles.concat(OpenFlowFiles).concat('./VERSION').concat('./OpenFlow/src/public/**/*.ts'), gulp.series("browserify", "copyfiles1"));
});
let bfi = null;
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)
// .transform('browserify-shim', {
// global: true,
// shim: {
// jQuery: {
// path: './node_modules/jquery/dist/jquery.min.js',
// exports: '$'
// }
// }
// })
// .transform('exposify', { expose: { jquery: '$', three: 'THREE' } })
.plugin(tsify, { noImplicitAny: false });
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);
//
// Copying files from '../node_modules/bootstrap/' to 'dist/vendor/bootstrap/'
//
// 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.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;
// if (_.contains(['.jpg', '.png', '.gif', '.eot'], path.extname(relativeUrl))) {
// // Embed image data with data URI
// var DataUri = require('datauri');
// var dUri = new DataUri(relativeUrl);
// console.log(dUri.content);
// return dUri.content;
// }
return relativeUrl;
}
})
;
// .transform('browserify-shim', { global: true })
bfi.on('update', bundle);
bfi.on('error', function (error) {
console.error(error.message);
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);
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([
'echo "Build openiap/nodered"',
'cd OpenFlowNodeRED && docker build -t openiap/nodered:edge .',
'docker tag openiap/nodered:edge openiap/nodered:' + version,
'echo "Push openiap/nodered"',
'docker push openiap/nodered:edge', //'docker push openiap/nodered:' + version,
'docker push openiap/nodered:' + version, //'docker push openiap/nodered:' + version,
'echo "Build openiap/openflow"',
'docker build -t openiap/openflow:edge .',
'docker tag openiap/openflow:edge openiap/openflow:' + version,
'echo "Push openiap/openflow"',
'docker push openiap/openflow:edge',
'docker push openiap/openflow:' + version
]));
gulp.task("latest", shell.task([
'docker tag openiap/nodered:edge openiap/nodered:latest',
'echo "Push openiap/nodered"',
'docker push openiap/nodered:latest',
'docker tag openiap/openflow:edge openiap/openflow:latest',
'echo "Push openiap/openflow"',
'docker push openiap/openflow:latest',
]));
gulp.task("composelatest", gulp.series("compose", "latest"));
gulp.task("bumpyml1", function () {
return gulp.src(["./*.yml"]).pipe(replace(/openflow:\d+(\.\d+)+/g, 'openflow:' + version)).
pipe(gulp.dest("./"));
});
gulp.task("bumpyml2", function () {
return nodered = gulp.src(["./*.yml"]).pipe(replace(/nodered:\d+(\.\d+)+/g, 'nodered:' + version)).
pipe(gulp.dest("./"));
});
gulp.task("bumpflow", function () {
console.log('openiap/openflow:' + version);
return gulp.src(["config/**/controllers.yml"])
.pipe(replace(/openflow:\d+(\.\d+)+/g, 'openflow:' + version))
.pipe(gulp.dest("config"));
});
gulp.task("bumpnodered", function () {
console.log('openiap/nodered:' + version);
return gulp.src(["config/**/controllers.yml"])
.pipe(replace(/nodered:\d+(\.\d+)+/g, 'nodered:' + version))
.pipe(gulp.dest("config"));
});
gulp.task("bumpconfigmap", function () {
console.log('openiap/nodered:' + version);
return gulp.src(["config/**/configmap.yml"])
.pipe(replace(/nodered:\d+(\.\d+)+/g, 'nodered:' + version))
.pipe(gulp.dest("config"));
});
gulp.task("bumpaiotfrontend", function () {
let version = "0.0.1";
version = fs.readFileSync("../aiot-frontend/VERSION", "utf8");
console.log('openiap/aiot-frontend:' + version);
return gulp.src(["config/**/controllers.yml"])
.pipe(replace(/aiot-frontend:\d+(\.\d+)+/g, 'aiot-frontend:' + version))
.pipe(gulp.dest("config"));
});
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('.');
});
gulp.task("bump", gulp.series("bumpyml1", "bumpyml2", "bumpflow", "bumpnodered", "bumpconfigmap", "bumpaiotfrontend", "bumpprojectfiles", "copyfiles1"));
gulp.task("watch", gulp.series("setwatch", "browserify", "copyfiles1", "dowatch"));
gulp.task("default", gulp.series("copyfiles1", "browserify"));