UNPKG

1.17 kBJavaScriptView Raw
1/* eslint-disable import/no-extraneous-dependencies */
2
3import gulp from 'gulp';
4
5import babel from 'gulp-babel';
6import fs from 'fs';
7import path from 'path';
8
9gulp.task('transpile', () =>
10 gulp.src('./src/**/*.js')
11 .pipe(babel())
12 .pipe(gulp.dest('./dist'))
13);
14
15gulp.task('watch', ['build'], () => {
16 gulp.watch('./src/**/*.js', ['transpile']);
17});
18
19gulp.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
40gulp.task('build', ['transpile', 'link']);