1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00

[WIP] Migrate from Gulp to Fly (#965)

* install fly & plugins

* start flyfile conversion

* install node-notifier directly

* send task notifications

* upgrade to fly@2.0.1

* fix watch rebuilds

* compile in parallel

* remove gulp-related deps

* enable start|stop-chromedriver

* run build before watching

* extract webpack config

* fix webpack build

* use serial chain within 'build' -- faster

* update to fly-watch@1.1.0

* generate new yarn.lock after rebase

* rename tasks; use fly-esnext (async/await)

* bump fly deps (node4 supp)

* remove destructured assignment

* import latest package.json changes
This commit is contained in:
Luke Edwards 2017-02-09 11:33:08 -08:00 committed by Tim Neutkens
parent 97714e8b2a
commit 839fb1c05c
4 changed files with 338 additions and 939 deletions

109
flyfile.js Normal file
View file

@ -0,0 +1,109 @@
const webpack = require('webpack')
const notifier = require('node-notifier')
const childProcess = require('child_process')
const webpackConfig = require('./webpack.config')
const isWindows = /^win/.test(process.platform)
export async function compile(fly) {
await fly.parallel(['bin', 'server', 'lib', 'client'])
await fly.start('unrestrict')
}
export async function bin(fly, opts) {
await fly.source(opts.src || 'bin/*').babel().target('dist/bin')
notify('Compiled binaries')
}
export async function lib(fly, opts) {
await fly.source(opts.src || 'lib/**/*.js').babel().target('dist/lib')
notify('Compiled lib files')
}
export async function server(fly, opts) {
await fly.source(opts.src || 'server/**/*.js').babel().target('dist/server')
notify('Compiled server files')
}
export async function client(fly, opts) {
await fly.source(opts.src || 'client/**/*.js').babel().target('dist/client')
notify('Compiled client files')
}
export async function unrestrict(fly) {
await fly.source('dist/lib/eval-script.js').babel({
babelrc: false,
plugins: ['babel-plugin-transform-remove-strict-mode']
}).target('dist/lib')
notify('Completed removing strict mode for eval script')
}
export async function copy(fly) {
await fly.source('pages/**/*.js').target('dist/pages')
}
export async function build(fly) {
await fly.serial(['copy', 'compile', 'prefetcher'])
}
const compiler = webpack(webpackConfig)
export async function prefetcher(fly) {
compiler.run((err, stats) => {
if (err) throw err
notify('Built release prefetcher')
})
}
export async function bench(fly) {
await fly.parallel(['compile', 'copy'])
// copy bench fixtures
await fly.source('bench/fixtures/**/*').target('dist/bench/fixtures')
// compile bench
await fly.source('bench/*.js').babel().target('dist/bench')
notify('Compiled bench files')
// yield fly.source('dist/bench/*.js').benchmark({
// benchmark.reporters.etalon('RegExp#test')
// })
}
export default async function (fly) {
await fly.start('build')
await fly.watch('bin/*', 'bin')
await fly.watch('pages/**/*.js', 'copy')
await fly.watch('server/**/*.js', 'server')
await fly.watch('client/**/*.js', ['client', 'prefetcher'])
await fly.watch('lib/**/*.js', ['lib', 'prefetcher'])
}
export async function release(fly) {
await fly.clear('dist').start('build')
}
// We run following task inside a NPM script chain and it runs chromedriver
// inside a child process tree.
// Even though we kill this task's process, chromedriver exists throughout
// the lifetime of the original npm script.
export async function pretest(fly) {
const processName = isWindows ? 'chromedriver.cmd' : 'chromedriver'
const chromedriver = childProcess.spawn(processName, { stdio: 'inherit' })
// We need to do this, otherwise this task's process will keep waiting.
setTimeout(() => process.exit(0), 2000)
}
export async function posttest(fly) {
try {
const cmd = isWindows ? 'taskkill /im chromedriver* /t /f' : 'pkill chromedriver'
childProcess.execSync(cmd, { stdio: 'ignore' })
} catch(err) {
// Do nothing
}
}
// notification helper
function notify(msg) {
return notifier.notify({
title: '▲ Next',
message: msg,
icon: false
})
}

View file

@ -23,11 +23,11 @@
"next": "./dist/bin/next" "next": "./dist/bin/next"
}, },
"scripts": { "scripts": {
"build": "gulp", "build": "fly",
"release": "gulp release", "release": "fly release",
"pretestonly": "gulp start-chromedriver", "pretestonly": "fly pretest",
"testonly": "cross-env NODE_PATH=test/lib jest \\.test.js", "testonly": "cross-env NODE_PATH=test/lib jest \\.test.js",
"posttestonly": "gulp stop-chromedriver", "posttestonly": "fly posttest",
"pretest": "npm run lint && cross-env NODE_ENV=test npm run release", "pretest": "npm run lint && cross-env NODE_ENV=test npm run release",
"test": "npm run testonly -- --coverage --forceExit", "test": "npm run testonly -- --coverage --forceExit",
"coveralls": "nyc --instrument=false --source-map=false report --temp-directory=./coverage --reporter=text-lcov | coveralls", "coveralls": "nyc --instrument=false --source-map=false report --temp-directory=./coverage --reporter=text-lcov | coveralls",
@ -95,21 +95,20 @@
"chromedriver": "^2.26.1", "chromedriver": "^2.26.1",
"coveralls": "2.11.16", "coveralls": "2.11.16",
"cross-env": "^3.1.4", "cross-env": "^3.1.4",
"gulp": "3.9.1", "fly": "^2.0.3",
"gulp-babel": "6.1.2", "fly-babel": "^2.1.1",
"gulp-benchmark": "1.1.1", "fly-clear": "^1.0.1",
"gulp-cached": "1.1.1", "fly-esnext": "^2.0.0",
"gulp-notify": "3.0.0", "fly-watch": "^1.1.1",
"husky": "0.13.1", "husky": "0.13.1",
"jest-cli": "^18.0.0", "jest-cli": "^18.0.0",
"node-fetch": "^1.6.3", "node-fetch": "^1.6.3",
"node-notifier": "^5.0.2",
"nyc": "^10.0.0", "nyc": "^10.0.0",
"react": "15.4.2", "react": "15.4.2",
"react-dom": "15.4.2", "react-dom": "15.4.2",
"run-sequence": "1.2.2",
"standard": "8.6.0", "standard": "8.6.0",
"wd": "^1.1.3", "wd": "^1.1.3"
"webpack-stream": "3.2.0"
}, },
"peerDependencies": { "peerDependencies": {
"react": "^15.4.2", "react": "^15.4.2",

35
webpack.config.js Normal file
View file

@ -0,0 +1,35 @@
const resolve = require('path').resolve
const webpack = require('webpack')
module.exports = {
entry: './client/next-prefetcher.js',
output: {
filename: 'next-prefetcher-bundle.js',
path: resolve(__dirname, 'dist/client')
},
plugins: [
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify('production')
}
})
],
module: {
rules: [{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader',
options: {
babelrc: false,
presets: [
['env', {
targets: {
// All browsers which supports service workers
browsers: ['chrome 49', 'firefox 49', 'opera 41']
}
}]
]
}
}]
}
}

1110
yarn.lock

File diff suppressed because it is too large Load diff