-
Notifications
You must be signed in to change notification settings - Fork 29
/
gulpfile.js
233 lines (187 loc) · 5.97 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
const { series, src, dest, parallel } = require("gulp");
const { task } = require("gulp-execa");
const del = require("del");
const path = require("path");
const through2 = require("through2");
/* DEV START TASKS */
const startUIForElectron = task("yarn start:desktop", {
cwd: path.join(__dirname, "ui"),
});
const startUIForBrowser = task("yarn start:browser", {
cwd: path.join(__dirname, "ui"),
});
const startBuildWatchForApp = task("yarn build:watch", {
cwd: path.join(__dirname, "app"),
});
const startBuildWatchForCLI = task("yarn build:watch", {
cwd: path.join(__dirname, "cli"),
});
const startAppsForDev = task("yarn dev", {
cwd: path.join(__dirname, "app"),
});
const startServerForBrowser = task("yarn start:server", {
cwd: path.join(__dirname, "app"),
});
exports.startUIForElectron = startUIForElectron;
exports.startUIForBrowser = startUIForBrowser;
exports.startBuildWatchForApp = startBuildWatchForApp;
exports.startAppsForDev = startAppsForDev;
/* BUILDING TASKS */
const buildUIForBrowser = task("yarn build:browser", {
cwd: path.join(__dirname, "ui"),
});
const buildUIForElectron = task("yarn build:desktop", {
cwd: path.join(__dirname, "ui"),
});
const buildServerForElectron = task("yarn build", {
cwd: path.join(__dirname, "app"),
});
const buildDesktopAppInstallers = task("yarn build:installers", {
cwd: path.join(__dirname, "app"),
});
const buildCLI = task("yarn build", {
cwd: path.join(__dirname, "cli"),
});
/* VERSIONING TASKS */
const updateVersion = (type = "patch", where = "ui") =>
task(`npm version ${type}`, {
cwd: path.join(__dirname, where),
});
/* CLEANING TASKS */
const cleanAppBuild = async () => {
return await del(["./app/build/**/*", "!./app/build"]);
};
const cleanAppDist = async () => {
return await del(["./app/dist/**/*", "!./app/dist"]);
};
const cleanDesktopFinalDist = async () => {
return await del(["./dist/desktop/**/*", "!./dist/desktop"]);
};
const cleanCLIFinalDist = async () => {
return await del(["./dist/cli/**/*", "!./dist/cli"]);
};
const cleanCLIBuild = async () => {
return await del(["./cli/build/**/*", "!./cli/build"]);
};
/* MOVE BUILD FILES TO THEIR FINAL DESTINATIONS. */
const moveUIBuilds = async () => {
// Electron-Builder runs in ./app folder, so move UI build there before building installer
return src("./ui/build/**/*").pipe(dest("./app/build/ui"));
};
const moveDesktopBuildToFinalDist = async () => {
return src("./app/dist/**/*").pipe(dest("./dist/desktop"));
};
const moveUIToCLI = async () => {
return src("./ui/build/**/*").pipe(dest("./cli/build/server/public"));
};
const moveServerToCLI = async () => {
return src("./app/build/server/**/*").pipe(dest("./cli/build/server"));
};
const moveServerConfigToCLI = async () => {
return src("./app/build/shared/**/*").pipe(dest("./cli/build/shared"));
};
const moveCLIBuildToFinalDist = async () => {
return src(["./cli/build/**/*", "./cli/README.md"]).pipe(dest("./dist/cli"));
};
const moveAppIconsToBuild = async () => {
return src("./app/images/**/*").pipe(dest("./app/build"));
};
/* Transformations */
const updateCLIPackageJson = async () => {
return src("./cli/package.json")
.pipe(
through2.obj(function (file, _, cb) {
if (file.isBuffer()) {
const currentPackageJson = JSON.parse(file.contents.toString());
const newPackageJson = Object.assign(currentPackageJson, {
main: "index.js",
scripts: {
start: "node index.js",
postinstall: "node postinstall.js",
},
bin: {
"ten-hands": "index.js",
},
files: [
"server",
"shared",
"cli.js",
"index.js",
"postinstall.js",
"server.js",
"package.json",
"README.md",
],
});
file.contents = Buffer.from(JSON.stringify(newPackageJson));
}
cb(null, file);
}),
)
.pipe(dest("./dist/cli"));
};
const delay = (time) => {
return async function wait() {
return new Promise((resolve) => {
setTimeout(resolve, time);
});
};
};
/* DEV MODE TASKS */
// Keep startAppsForDev in parallel. react-scripts/rescripts start is stopping next tasks if put in series
// Just refresh (Ctrl + R) once to get fresh content once app starts in dev mode
exports.startDesktop = series(
parallel(startUIForElectron, startBuildWatchForApp, startAppsForDev),
);
exports.startBrowser = series(
parallel(startUIForBrowser, startBuildWatchForApp, startServerForBrowser),
);
exports.startServer = series(
parallel(startBuildWatchForApp, startServerForBrowser),
);
exports.startCLI = series(startBuildWatchForCLI);
/* BUILD TASKS */
exports.buildDesktop = series(
parallel(cleanAppBuild, cleanAppDist, cleanDesktopFinalDist),
parallel(buildUIForElectron, buildServerForElectron),
moveUIBuilds,
moveAppIconsToBuild,
buildDesktopAppInstallers,
moveDesktopBuildToFinalDist,
delay(5000),
cleanAppDist,
);
exports.buildDesktopAzure = series(
parallel(cleanAppBuild, cleanAppDist, cleanDesktopFinalDist),
parallel(buildUIForElectron, buildServerForElectron),
moveUIBuilds,
moveAppIconsToBuild,
buildDesktopAppInstallers,
moveDesktopBuildToFinalDist,
);
exports.buildCLI = series(
parallel(cleanAppBuild, cleanAppDist, cleanCLIBuild, cleanCLIFinalDist),
parallel(buildUIForBrowser, buildServerForElectron),
buildCLI,
parallel(moveServerToCLI, moveServerConfigToCLI),
delay(2000),
moveUIToCLI,
delay(2000),
moveCLIBuildToFinalDist,
updateCLIPackageJson,
);
exports.updateMajorVersion = parallel(
updateVersion("major", "ui"),
updateVersion("major", "app"),
updateVersion("major", "cli"),
);
exports.updateMinorVersion = parallel(
updateVersion("minor", "ui"),
updateVersion("minor", "app"),
updateVersion("minor", "cli"),
);
exports.updatePatchVersion = parallel(
updateVersion("patch", "ui"),
updateVersion("patch", "app"),
updateVersion("patch", "cli"),
);