forked from input-output-hk/daedalus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
executable file
·224 lines (193 loc) · 6.14 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
const gulp = require('gulp');
const webpack = require('webpack');
const webpackStream = require('webpack-stream');
const shell = require('gulp-shell');
const electronConnect = require('electron-connect');
const flowRemoveTypes = require('gulp-flow-remove-types');
const mainWebpackConfig = require('./source/main/webpack.config');
const rendererWebpackConfig = require('./source/renderer/webpack.config');
// Setup electron-connect server to start the app in development mode
let electronServer;
// Gulp input sources for main and renderer compilation
const mainInputSource = () => gulp.src('source/main/index.js');
const rendererInputSource = () => gulp.src('source/renderer/index.js');
// Webpack watch configs
const mainWebpackWatchConfig = Object.assign({}, mainWebpackConfig, {
watch: true,
});
const rendererWebpackWatchConfig = Object.assign({}, rendererWebpackConfig, {
watch: true,
});
// Gulp output destinations for main and renderer compilation
const mainOutputDestination = () => gulp.dest('dist/main');
const rendererOutputDestination = () => gulp.dest('dist/renderer');
/**
* Creates an electron-connect server instance that enables
* us to control our app (restarting / reloading)
* @param env - electron app environment
* @param args - additional spawn options
*/
const createElectronServer = (env, args = []) => {
electronServer = electronConnect.server.create({
spawnOpt: {
env: Object.assign({}, process.env, env),
args,
},
});
};
const buildMain = () => () =>
mainInputSource()
.pipe(webpackStream(mainWebpackConfig, webpack))
.pipe(mainOutputDestination());
const buildMainWatch = () => (done) =>
mainInputSource()
.pipe(
webpackStream(mainWebpackWatchConfig, webpack, () => {
// Restart app every time after main script has been re-compiled
electronServer.restart();
done();
})
)
.pipe(mainOutputDestination());
const buildRenderer = () => () =>
rendererInputSource()
.pipe(webpackStream(rendererWebpackConfig, webpack))
.pipe(rendererOutputDestination());
const buildRendererWatch = () => (done) =>
rendererInputSource()
.pipe(
webpackStream(rendererWebpackWatchConfig, webpack, () => {
if (electronServer) {
// Reload app every time after renderer script has been re-compiled
electronServer.reload();
}
done();
})
)
.pipe(rendererOutputDestination());
gulp.task(
'clear:cache',
shell.task('rimraf ./node_modules/.cache && rimraf .cache-loader')
);
gulp.task('clean:dist', shell.task('rimraf ./dist'));
gulp.task('server:start', (done) => {
electronServer.start();
done();
});
gulp.task('server:create:dev', (done) => {
createElectronServer({
NODE_ENV: process.env.NODE_ENV,
XCURSOR_PATH: '/usr/share/icons' || 'development',
});
done();
});
gulp.task('server:create:debug', (done) => {
createElectronServer(
{
NODE_ENV: process.env.NODE_ENV,
XCURSOR_PATH: '/usr/share/icons' || 'development',
},
['--inspect', '--inspect-brk']
);
done();
});
gulp.task('build:main', buildMain());
gulp.task('build:main:watch', buildMainWatch());
gulp.task('build:renderer:html', () =>
gulp.src('source/renderer/index.html').pipe(gulp.dest('dist/renderer/'))
);
gulp.task('build:renderer:assets', buildRenderer());
gulp.task(
'build:renderer',
gulp.series('build:renderer:html', 'build:renderer:assets')
);
gulp.task('build:renderer:watch', buildRendererWatch());
gulp.task('build', gulp.series('clean:dist', 'build:main', 'build:renderer'));
gulp.task('prepare:themes:utils', () =>
gulp
.src([
'source/renderer/app/themes/utils/checkCreateTheme.js',
'source/renderer/app/themes/utils/constants.js',
'source/renderer/app/themes/utils/createShades.js',
'source/renderer/app/themes/utils/createTheme.js',
'source/renderer/app/themes/utils/findUpdates.js',
'source/renderer/app/themes/utils/updateThemes.js',
'source/renderer/app/themes/utils/updateThemesCLI.js',
'source/renderer/app/themes/utils/writeThemeUpdate.js',
])
.pipe(flowRemoveTypes())
.pipe(gulp.dest('dist/utils'))
);
gulp.task('prepare:themes:daedalus', () =>
gulp
.src([
'source/renderer/app/themes/daedalus/cardano.js',
'source/renderer/app/themes/daedalus/dark-blue.js',
'source/renderer/app/themes/daedalus/dark-cardano.js',
'source/renderer/app/themes/daedalus/flight-candidate.js',
'source/renderer/app/themes/daedalus/incentivized-testnet.js',
'source/renderer/app/themes/daedalus/index.js',
'source/renderer/app/themes/daedalus/light-blue.js',
'source/renderer/app/themes/daedalus/shelley-testnet.js',
'source/renderer/app/themes/daedalus/white.js',
'source/renderer/app/themes/daedalus/yellow.js',
])
.pipe(flowRemoveTypes())
.pipe(gulp.dest('dist/daedalus'))
);
gulp.task('prepare:themes:scripts', () =>
gulp
.src([
'source/renderer/app/themes/scripts/check.js',
'source/renderer/app/themes/scripts/update.js',
])
.pipe(flowRemoveTypes())
.pipe(gulp.dest('dist/scripts'))
);
gulp.task(
'prepare:themes',
gulp.series(
'prepare:themes:utils',
'prepare:themes:daedalus',
'prepare:themes:scripts'
)
);
gulp.task(
'build:watch',
gulp.series(
'clean:dist',
'server:create:dev',
'build:renderer:html',
'build:main:watch',
'build:renderer:watch'
)
);
gulp.task('build:themes', gulp.series('clean:dist', 'prepare:themes'));
gulp.task(
'test:e2e:nodemon',
shell.task(
'nodemon --watch dist --watch tests --exec "yarn test:e2e --tags \'@e2e and @watch\'"'
)
);
gulp.task('test:e2e:watch', gulp.series('build:watch', 'test:e2e:nodemon'));
gulp.task('purge:translations', shell.task('rimraf ./translations/messages'));
gulp.task('electron:inspector', shell.task('yarn electron:inspector'));
gulp.task(
'start',
shell.task(
`cross-env NODE_ENV=${process.env.NODE_ENV || 'production'} electron ./`
)
);
gulp.task(
'dev',
gulp.series('server:create:dev', 'build:watch', 'server:start')
);
gulp.task(
'debug',
gulp.series(
'server:create:debug',
'build:watch',
'server:start',
'electron:inspector'
)
);