This repository has been archived by the owner on Jun 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from kurone-kito/refactoring/basis
⚙ Internal Update
- Loading branch information
Showing
21 changed files
with
865 additions
and
438 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
dist/ | ||
node_modules/ | ||
backstop_data/engine_scripts | ||
dist | ||
node_modules |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')); |
Oops, something went wrong.