|
| 1 | +const webpack = require('webpack') |
| 2 | +const notifier = require('node-notifier') |
| 3 | +const childProcess = require('child_process') |
| 4 | +const webpackConfig = require('./webpack.config') |
| 5 | +const isWindows = /^win/.test(process.platform) |
| 6 | + |
| 7 | +export async function compile(fly) { |
| 8 | + await fly.parallel(['bin', 'server', 'lib', 'client']) |
| 9 | + await fly.start('unrestrict') |
| 10 | +} |
| 11 | + |
| 12 | +export async function bin(fly, opts) { |
| 13 | + await fly.source(opts.src || 'bin/*').babel().target('dist/bin') |
| 14 | + notify('Compiled binaries') |
| 15 | +} |
| 16 | + |
| 17 | +export async function lib(fly, opts) { |
| 18 | + await fly.source(opts.src || 'lib/**/*.js').babel().target('dist/lib') |
| 19 | + notify('Compiled lib files') |
| 20 | +} |
| 21 | + |
| 22 | +export async function server(fly, opts) { |
| 23 | + await fly.source(opts.src || 'server/**/*.js').babel().target('dist/server') |
| 24 | + notify('Compiled server files') |
| 25 | +} |
| 26 | + |
| 27 | +export async function client(fly, opts) { |
| 28 | + await fly.source(opts.src || 'client/**/*.js').babel().target('dist/client') |
| 29 | + notify('Compiled client files') |
| 30 | +} |
| 31 | + |
| 32 | +export async function unrestrict(fly) { |
| 33 | + await fly.source('dist/lib/eval-script.js').babel({ |
| 34 | + babelrc: false, |
| 35 | + plugins: ['babel-plugin-transform-remove-strict-mode'] |
| 36 | + }).target('dist/lib') |
| 37 | + notify('Completed removing strict mode for eval script') |
| 38 | +} |
| 39 | + |
| 40 | +export async function copy(fly) { |
| 41 | + await fly.source('pages/**/*.js').target('dist/pages') |
| 42 | +} |
| 43 | + |
| 44 | +export async function build(fly) { |
| 45 | + await fly.serial(['copy', 'compile', 'prefetcher']) |
| 46 | +} |
| 47 | + |
| 48 | +const compiler = webpack(webpackConfig) |
| 49 | +export async function prefetcher(fly) { |
| 50 | + compiler.run((err, stats) => { |
| 51 | + if (err) throw err |
| 52 | + notify('Built release prefetcher') |
| 53 | + }) |
| 54 | +} |
| 55 | + |
| 56 | +export async function bench(fly) { |
| 57 | + await fly.parallel(['compile', 'copy']) |
| 58 | + // copy bench fixtures |
| 59 | + await fly.source('bench/fixtures/**/*').target('dist/bench/fixtures') |
| 60 | + // compile bench |
| 61 | + await fly.source('bench/*.js').babel().target('dist/bench') |
| 62 | + notify('Compiled bench files') |
| 63 | + // yield fly.source('dist/bench/*.js').benchmark({ |
| 64 | + // benchmark.reporters.etalon('RegExp#test') |
| 65 | + // }) |
| 66 | +} |
| 67 | + |
| 68 | +export default async function (fly) { |
| 69 | + await fly.start('build') |
| 70 | + await fly.watch('bin/*', 'bin') |
| 71 | + await fly.watch('pages/**/*.js', 'copy') |
| 72 | + await fly.watch('server/**/*.js', 'server') |
| 73 | + await fly.watch('client/**/*.js', ['client', 'prefetcher']) |
| 74 | + await fly.watch('lib/**/*.js', ['lib', 'prefetcher']) |
| 75 | +} |
| 76 | + |
| 77 | +export async function release(fly) { |
| 78 | + await fly.clear('dist').start('build') |
| 79 | +} |
| 80 | + |
| 81 | +// We run following task inside a NPM script chain and it runs chromedriver |
| 82 | +// inside a child process tree. |
| 83 | +// Even though we kill this task's process, chromedriver exists throughout |
| 84 | +// the lifetime of the original npm script. |
| 85 | + |
| 86 | +export async function pretest(fly) { |
| 87 | + const processName = isWindows ? 'chromedriver.cmd' : 'chromedriver' |
| 88 | + const chromedriver = childProcess.spawn(processName, { stdio: 'inherit' }) |
| 89 | + // We need to do this, otherwise this task's process will keep waiting. |
| 90 | + setTimeout(() => process.exit(0), 2000) |
| 91 | +} |
| 92 | + |
| 93 | +export async function posttest(fly) { |
| 94 | + try { |
| 95 | + const cmd = isWindows ? 'taskkill /im chromedriver* /t /f' : 'pkill chromedriver' |
| 96 | + childProcess.execSync(cmd, { stdio: 'ignore' }) |
| 97 | + } catch(err) { |
| 98 | + // Do nothing |
| 99 | + } |
| 100 | +} |
| 101 | + |
| 102 | +// notification helper |
| 103 | +function notify(msg) { |
| 104 | + return notifier.notify({ |
| 105 | + title: '▲ Next', |
| 106 | + message: msg, |
| 107 | + icon: false |
| 108 | + }) |
| 109 | +} |
0 commit comments