From 05c93c9fcad579b8a56bf70b05804ecf1711dcaf Mon Sep 17 00:00:00 2001 From: Zach Perrault Date: Mon, 24 Jul 2017 13:20:54 -0400 Subject: [PATCH 1/4] Run prettier on build-module.js --- .../react-scripts/scripts/build-module.js | 119 +++++++++--------- 1 file changed, 63 insertions(+), 56 deletions(-) diff --git a/packages/react-scripts/scripts/build-module.js b/packages/react-scripts/scripts/build-module.js index 5726bdccd6d..34a03d34dd4 100644 --- a/packages/react-scripts/scripts/build-module.js +++ b/packages/react-scripts/scripts/build-module.js @@ -1,79 +1,88 @@ -require('../utils/loadEnv'); - -var path = require('path'); -var fs = require('fs-extra'); -var chokidar = require('chokidar'); -var transformFileSync = require('babel-core').transformFileSync; -var spawn = require('cross-spawn'); -var paths = require('../config/paths'); +require('../utils/loadEnv') + +var path = require('path') +var fs = require('fs-extra') +var chokidar = require('chokidar') +var transformFileSync = require('babel-core').transformFileSync +var spawn = require('cross-spawn') +var paths = require('../config/paths') const chalk = require('chalk') -function lint () { - return spawn.sync('node', [require.resolve('./lint')], {stdio: 'inherit'}); +function lint() { + return spawn.sync('node', [require.resolve('./lint')], { stdio: 'inherit' }) } -function fancyLog (color, label, fileName, src, dest) { +function fancyLog(color, label, fileName, src, dest) { console.log( color.bgBlack(label), '[' + chalk.green(fileName) + ']', chalk.gray(src + ' -> ' + dest) - ); + ) } -function transformWithBabel (filePath) { - const srcFile = path.join(paths.appSrc, filePath); +function transformWithBabel(filePath) { + const srcFile = path.join(paths.appSrc, filePath) const { code } = transformFileSync(srcFile, { ast: false, sourceMaps: 'inline', - presets: [ - require.resolve('babel-preset-trunkclub') - ], + presets: [require.resolve('babel-preset-trunkclub')], plugins: [ - [require.resolve('babel-plugin-module-resolver'), { - root: [paths.appSrc] - }] - ] - }); - const outputFilePath = - path.join(paths.appBuild, - path.join(path.dirname(filePath), - path.basename(filePath, path.extname(filePath)) + '.js')) + [ + require.resolve('babel-plugin-module-resolver'), + { + root: [paths.appSrc], + }, + ], + ], + }) + const outputFilePath = path.join( + paths.appBuild, + path.join( + path.dirname(filePath), + path.basename(filePath, path.extname(filePath)) + '.js' + ) + ) // Write the transpiled file - fs.writeFileSync(outputFilePath, code); + fs.writeFileSync(outputFilePath, code) fancyLog(chalk.cyan, 'BABEL', filePath, srcFile, outputFilePath) // Copy the source file as a Flow declaration file - const outputFlowFilePath = outputFilePath + '.flow' + const outputFlowFilePath = outputFilePath + '.flow' fs.copySync(srcFile, outputFlowFilePath) - fancyLog(chalk.yellow, 'FLOW', filePath + '.flow', srcFile, outputFlowFilePath) + fancyLog( + chalk.yellow, + 'FLOW', + filePath + '.flow', + srcFile, + outputFlowFilePath + ) return outputFilePath } -function copyAsset (filePath) { +function copyAsset(filePath) { const srcFile = path.join(paths.appSrc, filePath) const destFile = path.join(paths.appBuild, filePath) fs.copySync(srcFile, destFile) fancyLog(chalk.magenta, 'COPY', filePath, srcFile, destFile) } -function processFile (filePath) { +function processFile(filePath) { if (/\.(es6|jsx?)$/.test(filePath)) { - - fs.mkdirpSync(path.parse(path.join(paths.appBuild, filePath)).dir); - const outputPath = transformWithBabel(filePath); - - } else if (/\.(s?css|svg|json|ico|jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$/.test(filePath)) { - - fs.mkdirpSync(path.parse(path.join(paths.appBuild, filePath)).dir); + fs.mkdirpSync(path.parse(path.join(paths.appBuild, filePath)).dir) + const outputPath = transformWithBabel(filePath) + } else if ( + /\.(s?css|svg|json|ico|jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$/.test( + filePath + ) + ) { + fs.mkdirpSync(path.parse(path.join(paths.appBuild, filePath)).dir) copyAsset(filePath) } } +var args = process.argv.slice(2) -var args = process.argv.slice(2); - -var outDirIdx = args.indexOf('-d') !== -1 - ? args.indexOf('-d') - : args.indexOf('--out-dir') +var outDirIdx = + args.indexOf('-d') !== -1 ? args.indexOf('-d') : args.indexOf('--out-dir') if (outDirIdx !== -1) { paths.appBuild = path.resolve(paths.appBuild, '..', args[outDirIdx + 1]) } @@ -81,28 +90,26 @@ if (outDirIdx !== -1) { // Clear previous build artifacts before we start var shouldClean = args.indexOf('--clean') !== -1 if (shouldClean) { - fs.removeSync(paths.appBuild); + fs.removeSync(paths.appBuild) } -var result = lint(); -fs.walkSync(paths.appSrc).forEach(function (filePath) { - processFile(path.relative(paths.appSrc, filePath)); -}); +var result = lint() +fs.walkSync(paths.appSrc).forEach(function(filePath) { + processFile(path.relative(paths.appSrc, filePath)) +}) var isWatch = args.indexOf('-w') !== -1 || args.indexOf('--watch') !== -1 -if (!isWatch) process.exit(result.status); +if (!isWatch) process.exit(result.status) -var watcher = chokidar.watch([ - '**/*.*' -], { +var watcher = chokidar.watch(['**/*.*'], { cwd: paths.appSrc, persistent: true, - ignoreInitial: true + ignoreInitial: true, }) -watcher.on('all', function (event, filePath) { +watcher.on('all', function(event, filePath) { if (event === 'add' || event === 'change') { - lint(); - processFile(filePath); + lint() + processFile(filePath) } }) From 0a5fe66b6153361777a0e02238dcad020cd7d221 Mon Sep 17 00:00:00 2001 From: Zach Perrault Date: Mon, 24 Jul 2017 13:22:06 -0400 Subject: [PATCH 2/4] Remove `lint` from `build-module` script --- packages/react-scripts/scripts/build-module.js | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/packages/react-scripts/scripts/build-module.js b/packages/react-scripts/scripts/build-module.js index 34a03d34dd4..92356bac8f4 100644 --- a/packages/react-scripts/scripts/build-module.js +++ b/packages/react-scripts/scripts/build-module.js @@ -8,10 +8,6 @@ var spawn = require('cross-spawn') var paths = require('../config/paths') const chalk = require('chalk') -function lint() { - return spawn.sync('node', [require.resolve('./lint')], { stdio: 'inherit' }) -} - function fancyLog(color, label, fileName, src, dest) { console.log( color.bgBlack(label), @@ -93,13 +89,12 @@ if (shouldClean) { fs.removeSync(paths.appBuild) } -var result = lint() fs.walkSync(paths.appSrc).forEach(function(filePath) { processFile(path.relative(paths.appSrc, filePath)) }) var isWatch = args.indexOf('-w') !== -1 || args.indexOf('--watch') !== -1 -if (!isWatch) process.exit(result.status) +if (!isWatch) process.exit(0) var watcher = chokidar.watch(['**/*.*'], { cwd: paths.appSrc, @@ -109,7 +104,6 @@ var watcher = chokidar.watch(['**/*.*'], { watcher.on('all', function(event, filePath) { if (event === 'add' || event === 'change') { - lint() processFile(filePath) } }) From 822a8aeb172688d4b18c332958ff3165776ad4de Mon Sep 17 00:00:00 2001 From: Zach Perrault Date: Mon, 24 Jul 2017 13:27:30 -0400 Subject: [PATCH 3/4] v7.4.0-beta.0 --- packages/react-scripts/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react-scripts/package.json b/packages/react-scripts/package.json index da18ffa29cf..a3c2ebb1389 100644 --- a/packages/react-scripts/package.json +++ b/packages/react-scripts/package.json @@ -1,6 +1,6 @@ { "name": "@trunkclub/build", - "version": "7.3.0", + "version": "7.4.0-beta.0", "upstream-version": "0.9.5", "description": "Configuration and scripts for Create React App. Fork maintained by Trunk Club", "repository": "trunkclub/create-react-app", From f32259db151567814bca7ec194b93a43c5edb2b2 Mon Sep 17 00:00:00 2001 From: Zach Perrault Date: Mon, 24 Jul 2017 14:05:40 -0400 Subject: [PATCH 4/4] v8.0.0 --- packages/react-scripts/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react-scripts/package.json b/packages/react-scripts/package.json index a3c2ebb1389..3c7905e6fd1 100644 --- a/packages/react-scripts/package.json +++ b/packages/react-scripts/package.json @@ -1,6 +1,6 @@ { "name": "@trunkclub/build", - "version": "7.4.0-beta.0", + "version": "8.0.0", "upstream-version": "0.9.5", "description": "Configuration and scripts for Create React App. Fork maintained by Trunk Club", "repository": "trunkclub/create-react-app",