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

Commit

Permalink
Merge pull request #11 from kurone-kito/refactoring/basis
Browse files Browse the repository at this point in the history
⚙ Internal Update
  • Loading branch information
kurone-kito authored Mar 15, 2019
2 parents 73fa006 + 38a1f7d commit a8c0fb5
Show file tree
Hide file tree
Showing 21 changed files with 865 additions and 438 deletions.
5 changes: 3 additions & 2 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
dist/
node_modules/
backstop_data/engine_scripts
dist
node_modules
20 changes: 0 additions & 20 deletions .storybook/create-toc.ts

This file was deleted.

14 changes: 0 additions & 14 deletions backstop_data/engine_scripts/cookies.json

This file was deleted.

Binary file removed backstop_data/engine_scripts/imageStub.jpg
Binary file not shown.
107 changes: 28 additions & 79 deletions gulpfile.ts
Original file line number Diff line number Diff line change
@@ -1,79 +1,28 @@
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'));
import { series, task } from 'gulp';
import * as tsConfigPaths from 'tsconfig-paths';
import buildElectronAsync from './src/gulp/buildElectronAsync';
import cleanAsync from './src/gulp/cleanAsync';
import * as contentBuilder from './src/gulp/contentBuilder';
import createToc from './src/gulp/createToc';
import spawnAsync from './src/gulp/spawnAsync';
import syncDummy from './src/gulp/syncDummy';
import * as testRunner from './src/gulp/testRunner';
import tsConfig from './tsconfig.json';

// XXX: Although the cause is unknown, alias can not be resolved unless paths are explicitly specified.
const { baseUrl, paths } = tsConfig.compilerOptions;
tsConfigPaths.register({ baseUrl, paths });

task('clean', end => cleanAsync().then(end));
task('clean:storybook', end => cleanAsync({ storybook: true }).then(end));
task('build:content', contentBuilder.build);
task('build:binary:inner', end => buildElectronAsync().then(end));
task('build:binary', contentBuilder.condition('build:binary:inner'));
task('run:electron', end => spawnAsync('electron ./').then(end));
task('test', end => testRunner.unitAsync().then(end));
task('test:coverage', end => testRunner.coverageAsync().then(end));
task('storybook:sync-dummy', syncDummy);
task('storybook:create-toc', createToc);
task('storybook:toc', series('storybook:create-toc', 'storybook:sync-dummy'));
task('storybook:flush', series('clean:storybook', 'storybook:toc'));
task('default', contentBuilder.condition('run:electron'));
Loading

0 comments on commit a8c0fb5

Please sign in to comment.