Skip to content
This repository has been archived by the owner on Feb 17, 2021. It is now read-only.

Commit

Permalink
Merge pull request #91 from trunkclub/remove-lint-from-build
Browse files Browse the repository at this point in the history
Remove lint from build-module
  • Loading branch information
Zach Perrault authored Jul 24, 2017
2 parents 3b2bbf4 + f32259d commit 2a27f63
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 59 deletions.
2 changes: 1 addition & 1 deletion packages/react-scripts/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@trunkclub/build",
"version": "7.3.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",
Expand Down
117 changes: 59 additions & 58 deletions packages/react-scripts/scripts/build-module.js
Original file line number Diff line number Diff line change
@@ -1,108 +1,109 @@
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 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])
}

// 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));
});
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([
'**/*.*'
], {
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);
processFile(filePath)
}
})

0 comments on commit 2a27f63

Please sign in to comment.