Skip to content

Commit

Permalink
Merge pull request #143 from conveyal/dev
Browse files Browse the repository at this point in the history
v3.5.1
  • Loading branch information
trevorgerhardt committed Mar 3, 2017
2 parents 803ac98 + 726b3e5 commit 5f9098b
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 48 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* [Commit](#commit)
* [Deploy](#deploy)
* [Lint](#lint)
* [Prepublish](#prepublish)
* [Test](#test)
* [Lint Messages](#lint-messages)

Expand Down Expand Up @@ -157,6 +158,14 @@ $ mastarm lint "src/util/**/*.js" "test/**/*.js"

Note: by default standard will look for all files matching the patterns: `"**/*.js"`, `"**/*.jsx"`. Always quote the globs. Needed when used as an `npm` command.

### `prepublish`

Transpile a library using [Babel](http://babeljs.io/) and our custom config. Usually used as a prepublish step for libraries written in ES6+ that will be published to NPM. Pass it a directory and it will look for `.js` files to transpile.

```shell
$ mastarm prepublish lib:build
```

### `test`

Run the [Jest](http://facebook.github.io/jest/) test runner on your project. By default, mastarm will run Jest and generate coverage reports on all .js files in the `lib` folder of your project. The `patterns` argument will make Jest run only tests whose filename match the provided pattern.
Expand Down
4 changes: 2 additions & 2 deletions __tests__/test-utils/mocks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ export default class MockTestComponentUniqueName {
}

render () {
<div />
return <div />
}
}

uuid.v4()
console.log(uuid.v4())
15 changes: 11 additions & 4 deletions bin/mastarm
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ commander
log(`:rocket: ${tag} deploy finished!! :tada: :confetti_ball: :tada:`)
.then(() => process.exit(0)))
.catch((err) =>
log(`:rotating_light: *error deploying ${tag} ${err.message || err}*`)
log(`:rotating_light: *error deploying ${tag} ${err.message}*`)
.then(() => process.exit(1)))
})
})
Expand Down Expand Up @@ -163,15 +163,22 @@ commander
commander
.command('prepublish [entries...]')
.description('Transpile JavaScript down to ES5 with Babel')
.action(function (entries, options) {
.action(function (cliEntries, options) {
const prepublish = require('../lib/prepublish')
const config = loadConfig(process.cwd(), commander.config, commander.env)
const get = util.makeGetFn([options, commander, config.settings])

const outdir = get('outdir')
const entries = util.parseEntries(cliEntries && cliEntries.length > 0
? cliEntries
: get('entries') || [],
outdir
)

prepublish({
entries: util.parseEntries([...entries, ...(get('entries') || [])], get('outdir')),
entries,
env: get('env'),
outdir: get('outdir')
outdir
})
})

Expand Down
88 changes: 50 additions & 38 deletions lib/push-to-s3.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,20 @@ module.exports = function ({
tag
}) {
const upload = createUpload({bucket: s3bucket, cloudfront, log, tag})
return ([entry, outfile]) => (
path.extname(entry) === '.js'
? upload({
body: browserify({config, entry, env, minify}).bundle(),
outfile
})
: transformCss({config, entry, env, minify})
.then((results) =>
upload({body: results.css, outfile}))
)
return ([entry, outfile]) =>
log(`:hammer_and_wrench: ${tag} building ${outfile}`)
.then(() => path.extname(entry) === '.js'
? new Promise((resolve, reject) =>
browserify({config, entry, env, minify})
.bundle((err, buffer) => err
? reject(err)
: resolve(upload({body: buffer, outfile}))
)
)
: transformCss({config, entry, env, minify})
.then((results) =>
upload({body: results.css, outfile}))
)
}

const createUpload = ({bucket, cloudfront, log, tag}) =>
Expand All @@ -52,40 +56,48 @@ function upload ({
}
})

log(`:hammer_and_wrench: ${tag} building ${outfile} and pushing to ${bucket}`).then(() => {
s3object
.upload()
.send(function (err) {
if (err) return reject(`s3 upload to ${bucket} rejected with ${err.message}`)
log(`:ok_hand: ${tag} finished pushing to <${bucketUrl}/${outfile}|${bucket}/${outfile}>`).then(() => {
if (cloudfront) {
const cf = new AWS.CloudFront()
log(`:earth_asia: ${tag} creating cloudfront invalidation at ${outfile}`).then(() => {
cf.createInvalidation({
DistributionId: cloudfront,
InvalidationBatch: {
CallerReference: uuid.v4(),
Paths: {
Quantity: 1,
Items: [
'/' + outfile
]
}
const bytes = bytesToSize(body.byteLength || body.length)
const bucketLink = `<${bucketUrl}/${outfile}|${bucket}/${outfile}>`
log(`:satellite_antenna: ${tag} uploading to ${bucketLink} (${bytes})`)
s3object
.upload()
.send(function (err) {
if (err) return reject(new Error(`s3 upload to ${bucket} rejected with ${err.code} ${err.message}`))
log(`:ok_hand: ${tag} finished uploading to ${bucketLink}`).then(() => {
if (cloudfront) {
const cf = new AWS.CloudFront()
log(`:earth_asia: ${tag} creating cloudfront invalidation at ${outfile}`).then(() => {
cf.createInvalidation({
DistributionId: cloudfront,
InvalidationBatch: {
CallerReference: uuid.v4(),
Paths: {
Quantity: 1,
Items: [
'/' + outfile
]
}
}, function (err) {
if (err) return reject(`cf invalidation rejected with ${err.message}`)
done()
})
}
}, function (err) {
if (err) return reject(new Error(`cf invalidation rejected with ${err.message}`))
done()
})
} else {
done()
}
})
})
} else {
done()
}
})
})
})

function done () {
log(`:checkered_flag: ${tag} finished with ${outfile}`).then(resolve)
}
})
}

function bytesToSize (bytes) {
const sizes = ['bytes', 'kb', 'mb', 'gb', 'tb']
if (bytes === 0) return '0 byte'
const i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)))
return Math.round(bytes / Math.pow(1024, i), 2) + sizes[i]
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"envify": "^4.0.0",
"errorify": "^0.3.1",
"eslint": "^3.15.0",
"eslint-config-standard": "^6.2.1",
"eslint-config-standard": "^7.0.0",
"eslint-config-standard-jsx": "^3.3.0",
"eslint-plugin-flowtype": "^2.30.0",
"eslint-plugin-flowtype-errors": "^3.0.0",
Expand Down
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2178,9 +2178,9 @@ eslint-config-standard-jsx@^3.3.0:
version "3.3.0"
resolved "https://registry.yarnpkg.com/eslint-config-standard-jsx/-/eslint-config-standard-jsx-3.3.0.tgz#cab0801a15a360bf63facb97ab22fbdd88d8a5e0"

eslint-config-standard@^6.2.1:
version "6.2.1"
resolved "https://registry.yarnpkg.com/eslint-config-standard/-/eslint-config-standard-6.2.1.tgz#d3a68aafc7191639e7ee441e7348739026354292"
eslint-config-standard@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/eslint-config-standard/-/eslint-config-standard-7.0.0.tgz#4f161bc65695e4bc61331c55b9eeaca458cd99c6"

eslint-plugin-flowtype-errors@^3.0.0:
version "3.0.0"
Expand Down

0 comments on commit 5f9098b

Please sign in to comment.