1 |
|
2 |
|
3 | import gulp from 'gulp';
|
4 |
|
5 | import babel from 'gulp-babel';
|
6 | import fs from 'fs';
|
7 | import path from 'path';
|
8 |
|
9 | gulp.task('transpile', () =>
|
10 | gulp.src('./src/**/*.js')
|
11 | .pipe(babel())
|
12 | .pipe(gulp.dest('./dist'))
|
13 | );
|
14 |
|
15 | gulp.task('watch', ['build'], () => {
|
16 | gulp.watch('./src/**/*.js', ['transpile']);
|
17 | });
|
18 |
|
19 | gulp.task('link', () => {
|
20 | const files = fs.readdirSync(path.resolve(__dirname, './src'))
|
21 | .filter(f => f.endsWith('.js'));
|
22 | const packageJSON = require('./package.json');
|
23 |
|
24 | if (!fs.existsSync(path.resolve(__dirname, './dist'))) fs.mkdirSync(path.resolve(__dirname, './dist'));
|
25 |
|
26 | Object.keys(packageJSON.bin).forEach((binName) => {
|
27 | if (binName === 'electron-forge') return;
|
28 |
|
29 | if (packageJSON.bin[binName] === packageJSON.bin['electron-forge']) {
|
30 | files.forEach((fileName) => {
|
31 | fs.writeFileSync(
|
32 | path.resolve(__dirname, `./dist/${fileName.replace('electron-forge', binName)}`),
|
33 | `/* Auto-generated bin alias file */\nglobal.__LINKED_FORGE__ = true;\nrequire('./${fileName}');\n`
|
34 | );
|
35 | });
|
36 | }
|
37 | });
|
38 | });
|
39 |
|
40 | gulp.task('build', ['transpile', 'link']);
|