Skip to content
This repository has been archived by the owner on Sep 10, 2022. It is now read-only.

Commit

Permalink
Build UMD bundle on release (#154)
Browse files Browse the repository at this point in the history
  • Loading branch information
acdlite committed May 10, 2016
1 parent 0611648 commit da24809
Show file tree
Hide file tree
Showing 16 changed files with 230 additions and 137 deletions.
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@
"babel-cli": "^6.5.1",
"babel-core": "^6.5.2",
"babel-eslint": "^5.0.0-beta9",
"babel-loader": "^6.2.4",
"babel-polyfill": "^6.5.0",
"babel-preset-es2015": "^6.5.0",
"babel-preset-react": "^6.5.0",
"babel-preset-stage-0": "^6.5.0",
"chai": "^3.3.0",
"chalk": "^1.1.1",
"change-case": "^2.3.1",
"codecov": "^1.0.1",
"enzyme": "^2.2.0",
"eslint": "^1.5.1",
Expand All @@ -34,14 +36,16 @@
"gzip-size-cli": "^1.0.0",
"jsdom": "^8.4.0",
"lodash": "^4.0.0",
"lodash-webpack-plugin": "^0.2.1",
"nyc": "^6.4.0",
"react": "^15.0.0",
"react-addons-test-utils": "^15.0.0",
"react-dom": "^15.0.0",
"readline-sync": "^1.2.21",
"rimraf": "^2.4.3",
"shelljs": "^0.6.0",
"sinon": "^1.17.1"
"sinon": "^1.17.1",
"webpack": "^1.12.0"
},
"devEngines": {
"node": "5.x",
Expand Down
280 changes: 171 additions & 109 deletions scripts/release.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import { flowRight as compose } from 'lodash'
import readline from 'readline-sync'
import semver from 'semver'
import glob from 'glob'
import { pascalCase } from 'change-case'
import webpack from 'webpack'
import webpackBaseConfig from '../webpack.config'

const BIN = './node_modules/.bin'

Expand All @@ -26,123 +29,182 @@ const writeFile = (filepath, string) => (
fs.writeFileSync(filepath, string, 'utf8')
)

if (exec('git diff-files --quiet').code !== 0) {
logError(
'You have unsaved changes in the working tree. Commit or stash changes ' +
'before releasing.'
)
exit(1)
}
const run = async () => {
if (exec('git diff-files --quiet').code !== 0) {
logError(
'You have unsaved changes in the working tree. Commit or stash changes ' +
'before releasing.'
)
exit(1)
}

const packageNames = getPackageNames()
const packageNames = getPackageNames()

let packageName = readline.question('Name of package to release: ')

while (!packageNames.includes(packageName)) {
packageName = readline.question(
`The package "${packageName}" does not exist in this project. ` +
`Choose again: `
)
}
let packageName = readline.question('Name of package to release: ')

const versionLoc = path.resolve(PACKAGES_SRC_DIR, packageName, 'VERSION')
const version = fs.readFileSync(versionLoc, 'utf8').trim()
while (!packageNames.includes(packageName)) {
packageName = readline.question(
`The package "${packageName}" does not exist in this project. ` +
`Choose again: `
)
}

let nextVersion = readline.question(
`Next version of ${packageName} (current version is ${version}): `
)
const versionLoc = path.resolve(PACKAGES_SRC_DIR, packageName, 'VERSION')
const version = fs.readFileSync(versionLoc, 'utf8').trim()

while (!(
!nextVersion ||
(semver.valid(nextVersion) && semver.gt(nextVersion, version))
)) {
nextVersion = readline.question(
`Must provide a valid version that is greater than ${version}, `
+ `or leave blank to skip: `
let nextVersion = readline.question(
`Next version of ${packageName} (current version is ${version}): `
)
}

log('Running tests...')

if (exec('npm run lint && npm test -- --single-run').code !== 0) {
logError(
'The test command did not exit cleanly. Aborting release.'
while (!(
!nextVersion ||
(semver.valid(nextVersion) && semver.gt(nextVersion, version))
)) {
nextVersion = readline.question(
`Must provide a valid version that is greater than ${version}, `
+ `or leave blank to skip: `
)
}

log('Running tests...')

if (exec('npm run lint && npm test').code !== 0) {
logError(
'The test command did not exit cleanly. Aborting release.'
)
exit(1)
}

logSuccess('Tests were successful.')

const sourceDir = path.resolve(PACKAGES_SRC_DIR, packageName)
const outDir = path.resolve(PACKAGES_OUT_DIR, packageName)

log('Cleaning destination directory...')
rm('-rf', outDir)

log('Compiling source files...')

const sourceFiles = glob.sync(`${sourceDir}/**/*.js`, {
ignore: `${sourceDir}/node_modules/**/*.js`
}).map(to => path.relative(sourceDir, to))

exec(`cd ${sourceDir} && ${path.resolve(BIN)}/babel ${sourceFiles.join(' ')} --out-dir ${path.resolve(outDir)}`)

log('Copying additional project files...')
const additionalProjectFiles = [
'README.md',
'.npmignore'
]
additionalProjectFiles.forEach(filename => {
const src = path.resolve(sourceDir, filename)

if (!test('-e', src)) return

cp('-Rf', src, outDir)
})

log('Generating package.json...')
const packageConfig = {
name: packageName,
version: nextVersion,
...require(BASE_PACKAGE_LOC),
...require(path.resolve(sourceDir, 'package.json')),
private: undefined,
}

writeFile(
path.resolve(outDir, 'package.json'),
JSON.stringify(packageConfig, null, 2)
)
exit(1)
}

logSuccess('Tests were successful.')

const sourceDir = path.resolve(PACKAGES_SRC_DIR, packageName)
const outDir = path.resolve(PACKAGES_OUT_DIR, packageName)

log('Cleaning destination directory...')
rm('-rf', outDir)

log('Compiling source files...')

const sourceFiles = glob.sync(`${sourceDir}/**/*.js`, {
ignore: `${sourceDir}/node_modules/**/*.js`
}).map(to => path.relative(sourceDir, to))

exec(`cd ${sourceDir} && ${path.resolve(BIN)}/babel ${sourceFiles.join(' ')} --out-dir ${path.resolve(outDir)}`)

log('Copying additional project files...')
const additionalProjectFiles = [
'README.md',
'.npmignore'
]
additionalProjectFiles.forEach(filename => {
const src = path.resolve(sourceDir, filename)

if (!test('-e', src)) return

cp('-Rf', src, outDir)
})

log('Generating package.json...')
const packageConfig = {
name: packageName,
version: nextVersion,
...require(BASE_PACKAGE_LOC),
...require(path.resolve(sourceDir, 'package.json')),
private: undefined,
}

writeFile(
path.resolve(outDir, 'package.json'),
JSON.stringify(packageConfig, null, 2)
)

log(`About to publish ${packageName}@${nextVersion} to npm.`)
if (!readline.keyInYN('Sound good? ')) {
log('OK. Stopping release.')
exit(0)
}

log('Publishing...')
if (exec(`cd ${outDir} && npm publish`).code !== 0) {
logError('Publish failed. Aborting release.')
exit(1)
}

logSuccess(`${packageName}@${nextVersion} was successfully published.`)

log('Updating VERSION file...')
writeFile(versionLoc, `${nextVersion}\n`)

log('Committing changes...')
const newTagName = `v${nextVersion}`
exec(`git add ${versionLoc}`)
exec(`git commit -m "${packageName} ${newTagName}"`)

if (packageName === 'recompose') {
log(`Tagging release... (${newTagName})`)
exec(`git tag ${newTagName}`)
const buildWebpack = config => {
return new Promise((resolve, reject) => {
log(`Building ${config.output.filename}...`)
webpack(config, (err, stats) => {
if (err) {
return reject(err)
}
// log(`${config.output.filename} is ${stats.chunks[0].size}`)
writeFile(
path.resolve(outDir, `build/${config.output.filename}.stats.json`),
JSON.stringify(stats.toJson())
)
resolve()
})
})
}

const libraryName = pascalCase(packageName)
const webpackConfig = {
...webpackBaseConfig,
entry: [path.resolve(sourceDir, 'index.js')],
output: {
...webpackBaseConfig.output,
library: libraryName,
path: `${outDir}/build`,
filename: `${libraryName}.js`
}
}
const webpackMinConfig = {
...webpackConfig,
output: {
...webpackConfig.output,
filename: `${libraryName}.min.js`
},
plugins: [
...webpackConfig.plugins,
new webpack.optimize.UglifyJsPlugin({
compressor: {
pure_getters: true,
unsafe: true,
unsafe_comps: true,
screw_ie8: true,
warnings: false
}
})
]
}

await Promise.all([
buildWebpack(webpackConfig),
buildWebpack(webpackMinConfig),
])

log(`About to publish ${packageName}@${nextVersion} to npm.`)
if (!readline.keyInYN('Sound good? ')) {
log('OK. Stopping release.')
exit(0)
}

log('Publishing...')
if (exec(`cd ${outDir} && npm publish`).code !== 0) {
logError('Publish failed. Aborting release.')
exit(1)
}

logSuccess(`${packageName}@${nextVersion} was successfully published.`)

log('Updating VERSION file...')
writeFile(versionLoc, `${nextVersion}\n`)

log('Committing changes...')
const newTagName = `v${nextVersion}`
exec(`git add ${versionLoc}`)
exec(`git commit -m "${packageName} ${newTagName}"`)

if (packageName === 'recompose') {
log(`Tagging release... (${newTagName})`)
exec(`git tag ${newTagName}`)
}

log('Pushing to GitHub...')
exec('git push')
exec('git push --tags')

logSuccess('Done.')
}

log('Pushing to GitHub...')
exec('git push')
exec('git push --tags')

logSuccess('Done.')
run().catch(error => {
logError('Release failed due to an error', error)
})
4 changes: 2 additions & 2 deletions src/packages/recompose/componentFromProp.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import omit from 'lodash/omit'
import omit from './utils/omit'
import createElement from './createElement'

const componentFromProp = propName => {
const Component = props =>
createElement(props[propName], omit(props, propName))
createElement(props[propName], omit(props, [propName]))
Component.displayName = `componentFromProp(${propName})`
return Component
}
Expand Down
4 changes: 2 additions & 2 deletions src/packages/recompose/flattenProp.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import omit from 'lodash/omit'
import omit from './utils/omit'
import createHelper from './createHelper'
import { internalCreateElement } from './createElement'

const flattenProp = propName => BaseComponent => {
const createElement = internalCreateElement(BaseComponent)
return props => (
createElement({
...omit(props, propName),
...omit(props, [propName]),
...props[propName]
})
)
Expand Down
2 changes: 1 addition & 1 deletion src/packages/recompose/onlyUpdateForKeys.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pick from 'lodash/pick'
import shouldUpdate from './shouldUpdate'
import shallowEqual from './shallowEqual'
import createHelper from './createHelper'
import pick from './utils/pick'

const onlyUpdateForKeys = propKeys =>
shouldUpdate(
Expand Down
4 changes: 2 additions & 2 deletions src/packages/recompose/renameProp.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import omit from 'lodash/omit'
import omit from './utils/omit'
import mapProps from './mapProps'
import createHelper from './createHelper'

const renameProp = (oldName, newName) =>
mapProps(props => ({
...omit(props, oldName),
...omit(props, [oldName]),
[newName]: props[oldName]
}))

Expand Down
Loading

0 comments on commit da24809

Please sign in to comment.