Skip to content

Commit

Permalink
Merge pull request react-bootstrap#843 from taion/no-babel-cache
Browse files Browse the repository at this point in the history
[fixed] Do not use Babel cache for release build
  • Loading branch information
taion committed Jun 15, 2015
2 parents 737a672 + 01c547f commit 64276ae
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 27 deletions.
7 changes: 5 additions & 2 deletions docs/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,19 @@ function generateHTML(fileName) {
});
}

export default function BuildDocs({ dev }) {
export default function BuildDocs({useCache, dev}) {
console.log('Building: '.cyan + 'docs'.green + (dev ? ' [DEV]'.grey : ''));

const useCacheOption = `--use-cache=${Boolean(useCache)}`;
const devOption = dev ? '' : '-p';

return exec(`rimraf ${docsBuilt}`)
.then(() => fsp.mkdir(docsBuilt))
.then(() => {
let pagesGenerators = Root.getPages().map(generateHTML);

return Promise.all(pagesGenerators.concat([
exec(`webpack --config webpack.docs.js ${dev ? '' : '-p '}--bail`),
exec(`webpack --config webpack.docs.js ${useCacheOption} --bail ${devOption}`),
copy(license, docsBuilt),
copy(readmeSrc, readmeDest)
]));
Expand Down
9 changes: 8 additions & 1 deletion tools/build-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,17 @@ import { setExecOptions } from './exec';
import yargs from 'yargs';

const argv = yargs
.help('h')
.option('docs-only', {
demand: false,
default: false
})
.option('use-cache', {
type: 'boolean',
demand: false,
default: true,
describe: 'Use Babel cache when running webpack'
})
.option('verbose', {
demand: false,
default: false,
Expand All @@ -26,7 +33,7 @@ const argv = yargs

setExecOptions(argv);

let buildProcess = argv.docsOnly ? docs(argv) : build();
let buildProcess = argv.docsOnly ? docs(argv) : build(argv);

buildProcess
.catch(err => {
Expand Down
13 changes: 7 additions & 6 deletions tools/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,22 @@ import { copy } from './fs-utils';
import { distRoot, bowerRoot } from './constants';
import { exec } from './exec';

function forkAndBuildDocs(verbose) {
function forkAndBuildDocs({verbose, useCache}) {
console.log('Building: '.cyan + 'docs'.green);

let options = verbose ? ' -- --verbose' : '';
const verboseOption = verbose ? '--verbose' : '';
const useCacheOption = `--use-cache=${Boolean(useCache)}`;

return exec(`npm run docs-build${options}`)
return exec(`npm run docs-build -- ${verboseOption} ${useCacheOption}`)
.then(() => console.log('Built: '.cyan + 'docs'.green));
}

export default function Build(verbose) {
export default function Build({verbose, useCache} = {}) {
return Promise.all([
lib(),
bower(),
dist(),
forkAndBuildDocs(verbose)
dist({useCache}),
forkAndBuildDocs({verbose, useCache})
])
.then(() => copy(distRoot, bowerRoot));
}
8 changes: 5 additions & 3 deletions tools/dist/build.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { exec } from '../exec';
import { distRoot } from '../constants';

export default function BuildDistributable() {
export default function BuildDistributable({useCache}) {
console.log('Building: '.cyan + 'distributable'.green);

const useCacheOption = `--use-cache=${Boolean(useCache)}`;

return exec(`rimraf ${distRoot}`)
.then(() => Promise.all([
exec('webpack --bail'),
exec('webpack --bail -p')
exec(`webpack ${useCacheOption} --bail`),
exec(`webpack ${useCacheOption} --bail -p`)
]))
.then(() => console.log('Built: '.cyan + 'distributable'.green));
}
6 changes: 4 additions & 2 deletions tools/release-scripts/release.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { bowerRepo, bowerRoot, tmpBowerRepo, docsRoot, docsRepo, tmpDocsRepo } f

const yargsConf = yargs
.usage('Usage: $0 <version> [--preid <identifier>]')
.help('h')
.example('$0 minor --preid beta', 'Release with minor version bump with pre-release tag')
.example('$0 major', 'Release with major version bump')
.example('$0 major --dry-run', 'Release dry run with patch version bump')
Expand All @@ -32,7 +33,7 @@ const yargsConf = yargs
alias: 'n',
demand: false,
default: false,
describe: 'Execute command in dry run mode. Will not commit, tag, push, or publish anything. Userful for testing.'
describe: 'Execute command in dry run mode. Will not commit, tag, push, or publish anything. Useful for testing.'
})
.option('verbose', {
demand: false,
Expand Down Expand Up @@ -66,7 +67,8 @@ preConditions()
.then(v => { version = v; })
.then(() => addChangelog(version))
.then(() => {
return build(argv.verbose)
// useCache implicitly defaults to false here.
return build(argv)
.catch(err => {
console.log('Build failed, reverting version bump'.red);

Expand Down
33 changes: 20 additions & 13 deletions webpack/base.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,35 @@ import path from 'path';
import webpack from 'webpack';
import yargs from 'yargs';

const babelCache = path.resolve(path.join(__dirname, '../.babel-cache'));

if (!fs.existsSync(babelCache)) {
try {
fs.mkdirSync(babelCache);
} catch (err) {
if (err.code !== 'EEXIST') {
console.error(err.stack);
}
}
}

export const options = yargs
.alias('p', 'optimize-minimize')
.alias('d', 'debug')
.option('use-cache', {
type: 'boolean',
default: true
})
.option('port', {
default: '8080',
type: 'string'
})
.argv;

export const jsLoader = `babel?cacheDirectory=${babelCache}`;
export let jsLoader = 'babel';
if (options.useCache) {
const babelCache = path.resolve(path.join(__dirname, '../.babel-cache'));

if (!fs.existsSync(babelCache)) {
try {
fs.mkdirSync(babelCache);
} catch (err) {
if (err.code !== 'EEXIST') {
console.error(err.stack);
}
}
}

jsLoader += `?cacheDirectory=${babelCache}`;
}

const baseConfig = {
entry: undefined,
Expand Down

0 comments on commit 64276ae

Please sign in to comment.