Skip to content
This repository has been archived by the owner on Jun 6, 2024. It is now read-only.

Commit

Permalink
Migrated from npm-script to Gulp
Browse files Browse the repository at this point in the history
  • Loading branch information
kurone-kito committed Mar 11, 2019
1 parent 9cb3793 commit 1cf9ec8
Show file tree
Hide file tree
Showing 4 changed files with 1,652 additions and 185 deletions.
9 changes: 5 additions & 4 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ env:
es6: true
jest/globals: true
extends:
- 'eslint:recommended'
- "eslint:recommended"
- airbnb
- 'plugin:prettier/recommended'
parser: '@typescript-eslint/parser'
- "plugin:prettier/recommended"
parser: "@typescript-eslint/parser"
parserOptions:
ecmaFeatures:
jsx: true
ecmaVersion: 2018
sourceType: module
plugins:
- '@typescript-eslint'
- "@typescript-eslint"
- jest
- react
rules:
Expand All @@ -29,6 +29,7 @@ rules:
- ./backstop_data/**/*.?s*
- ./src/__tests__/*.?s*
- ./*.config.?s
- ./gulpfile.?s
- ./main.?s
- ./stories/*.?s
settings:
Expand Down
79 changes: 79 additions & 0 deletions gulpfile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import childProcess from 'child_process';
import fs from 'fs';
import { dest, series, src, task } from 'gulp';
import minimist from 'minimist';
import rmfr from 'rmfr';
import webpack from 'webpack-stream';
import webpackConfig from './webpack.config';

const BUILD_CONTENT_OPTIONS = { mode: 'development' };
const BUILD_BINARY_OPTIONS = { linux: true, macos: false, windows: true };
const CLEAN_OPTIONS = { logs: false, dist: false, storybook: false };

const args = minimist(process.argv, {
default: {
...BUILD_BINARY_OPTIONS,
...BUILD_CONTENT_OPTIONS,
...CLEAN_OPTIONS
}
});

const clean = async (
options: Partial<typeof CLEAN_OPTIONS> = CLEAN_OPTIONS
) => {
type KEYS = keyof typeof CLEAN_OPTIONS;
const all = (Object.keys(CLEAN_OPTIONS) as KEYS[])
.map<boolean>(k => args[k] || options[k])
.every(v => !v);
const remove = (key: KEYS, targets: string[]) =>
all || args[key] || options[key]
? Promise.all(targets.map(target => rmfr(target)))
: undefined;
await remove('logs', ['converage', 'logs']);
await remove('dist', ['dist']);
await remove('storybook', ['storybook-static']);
};

const spawn = (command: string, ...options: string[]) =>
new Promise<void>((resolve, reject) => {
const p = childProcess.spawn(command, options, { stdio: 'inherit' });
p.on('close', resolve);
p.on('error', err => {
console.error(err);
reject(err);
});
});

const tasksBeforeBuildContent = (...tasks: string[]) => {
const production = args.mode === 'production';
return series(
...(production ? ['clean'] : []),
...(production || !fs.existsSync('dist') ? ['build:content'] : []),
...tasks
);
};

const buildWebPack = async () => {
await clean({ dist: true });
const config = webpackConfig({}, args);

return src(config!.entry as string)
.pipe(webpack(config))
.pipe(dest(config!.output!.path as string));
};

const buildElectron = () => {
type KEYS = keyof typeof BUILD_BINARY_OPTIONS;
const keys = Object.keys(BUILD_BINARY_OPTIONS) as KEYS[];

return spawn('electron-builder', ...keys.map(k => (args[k] ? `--${k}` : '')));
};

task('clean', async end => clean().then(end));
task('build:content', buildWebPack);
task('build:binary:inner', end => buildElectron().then(end));
task('build:binary', tasksBeforeBuildContent('build:binary:inner'));
task('run:electron', end => spawn('electron', './').then(end));
task('test', end => spawn('jest', '--coverage').then(end));

task('default', tasksBeforeBuildContent('run:electron'));

0 comments on commit 1cf9ec8

Please sign in to comment.