-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
142 lines (122 loc) · 3.45 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
let gulp = require("gulp");
let PluginError = require("plugin-error");
let log = require("fancy-log");
let webpack = require("webpack");
const path = require("path");
const { spawn } = require("child_process");
const fs = require("fs");
let setProduction = done => {
process.env.NODE_ENV = "production";
done();
};
let setDev = done => {
process.env.NODE_ENV = "development";
done();
};
// function getReactLibraryLinkInfo() {
// const dependencyName = "4dn-microscopy-metadata-tool";
// let reactLibPath = path.resolve(__dirname, "node_modules/" + dependencyName);
// let isLinked = false;
// try {
// // Get exact path to dir, else leave. Used to avoid needing to webpack dependency itself.
// for (var i = 0; i < 10; i++) {
// // Incase multiple links.
// reactLibPath = fs.readlinkSync(reactLibPath);
// isLinked = true;
// }
// } catch (e) {
// // ... not linked
// }
// // eslint-disable-next-line no-console
// console.log(
// "`node_modules/" + dependencyName + "` directory is",
// isLinked ? "sym-linked to `" + reactLibPath + "`." : "NOT sym-linked."
// );
// return { isLinked, reactLibPath: isLinked ? reactLibPath : null };
// }
// function buildLinkedDependency(done) {
// const { isLinked, reactLibPath } = getReactLibraryLinkInfo();
// if (!isLinked) {
// // Exit
// done();
// return;
// }
// // Same as shared-portal-components own build method, but with "--watch"
// const subP = spawn(
// path.join(reactLibPath, "node_modules/.bin/babel"),
// [
// path.join(reactLibPath, "src"),
// "--out-dir",
// path.join(reactLibPath, "es"),
// "--env-name",
// "esm"
// ],
// { stdio: "inherit" }
// );
// subP.on("close", code => {
// done();
// });
// }
// function watchLinkedDependency(done){
// const { isLinked, reactLibPath } = getReactLibraryLinkInfo();
// if (!isLinked){ // Exit
// done();
// return;
// }
// // Same as shared-portal-components own build method, but with "--watch"
// const subP = spawn(
// path.join(reactLibPath, "node_modules/.bin/babel"),
// [
// path.join(reactLibPath, "src"),
// "--out-dir",
// path.join(reactLibPath, "es"),
// "--env-name",
// "esm",
// "--watch",
// "--skip-initial-build"
// ],
// { stdio: "inherit" }
// );
// subP.on("close", (code)=>{
// done();
// });
// }
function webpackOnBuild(done) {
let start = Date.now();
return function(err, stats) {
if (err) {
throw new PluginError("webpack", err);
}
log(
"[webpack]",
stats.toString({
colors: true
})
);
let end = Date.now();
log("Build Completed, running for " + (end - start) / 1000) + "s";
if (done) {
done(err);
}
};
}
const buildWebpack = cb => {
let webpackConfig = require("./webpack.config.js");
webpack(webpackConfig).run(webpackOnBuild(cb));
};
const watchWebpack = () => {
let webpackConfig = require("./webpack.config.js");
webpack(webpackConfig).watch(300, webpackOnBuild());
};
// TODO add step in series to build node_modules/4dn-metadata-tool-react/src to node_modules/4dn-metadata-tool-react/dist maybe
// const buildInternal = gulp.series(setProduction, buildWebpack);
// const build = gulp.series(buildInternal, done => {
// /* todo */
// done();
// });
const dev = gulp.series(setDev, buildWebpack, watchWebpack);
const buildProd = gulp.series(setProduction, buildWebpack);
const buildDev = gulp.series(setDev, buildWebpack);
gulp.task("dev", dev);
gulp.task("build-prod", buildProd);
gulp.task("build-dev", buildDev);