-
Notifications
You must be signed in to change notification settings - Fork 29
/
gulpfile.js
176 lines (139 loc) · 4.47 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
const { series, src, dest, parallel } = require("gulp");
const { task, exec, stream } = require("gulp-execa");
const del = require("del");
const path = require("path");
const through2 = require("through2");
/* DEV START TASKS */
const startUIForElectron = task("yarn start:electron", {
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:electron", {
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")
});
/* 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 moveCLIBuildToFinalDist = async () => {
return src(["./cli/build/**/*"]).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"
},
bin: {
"ten-hands": "index.js"
}
});
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.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(cleanCLIBuild, cleanCLIFinalDist),
buildCLI,
moveCLIBuildToFinalDist,
updateCLIPackageJson
);