Skip to content

Commit 5f9098b

Browse files
Merge pull request #143 from conveyal/dev
v3.5.1
2 parents 803ac98 + 726b3e5 commit 5f9098b

File tree

6 files changed

+76
-48
lines changed

6 files changed

+76
-48
lines changed

README.md

+9
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* [Commit](#commit)
1717
* [Deploy](#deploy)
1818
* [Lint](#lint)
19+
* [Prepublish](#prepublish)
1920
* [Test](#test)
2021
* [Lint Messages](#lint-messages)
2122

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

158159
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.
159160

161+
### `prepublish`
162+
163+
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.
164+
165+
```shell
166+
$ mastarm prepublish lib:build
167+
```
168+
160169
### `test`
161170

162171
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.

__tests__/test-utils/mocks/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ export default class MockTestComponentUniqueName {
66
}
77

88
render () {
9-
<div />
9+
return <div />
1010
}
1111
}
1212

13-
uuid.v4()
13+
console.log(uuid.v4())

bin/mastarm

+11-4
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ commander
109109
log(`:rocket: ${tag} deploy finished!! :tada: :confetti_ball: :tada:`)
110110
.then(() => process.exit(0)))
111111
.catch((err) =>
112-
log(`:rotating_light: *error deploying ${tag} ${err.message || err}*`)
112+
log(`:rotating_light: *error deploying ${tag} ${err.message}*`)
113113
.then(() => process.exit(1)))
114114
})
115115
})
@@ -163,15 +163,22 @@ commander
163163
commander
164164
.command('prepublish [entries...]')
165165
.description('Transpile JavaScript down to ES5 with Babel')
166-
.action(function (entries, options) {
166+
.action(function (cliEntries, options) {
167167
const prepublish = require('../lib/prepublish')
168168
const config = loadConfig(process.cwd(), commander.config, commander.env)
169169
const get = util.makeGetFn([options, commander, config.settings])
170170

171+
const outdir = get('outdir')
172+
const entries = util.parseEntries(cliEntries && cliEntries.length > 0
173+
? cliEntries
174+
: get('entries') || [],
175+
outdir
176+
)
177+
171178
prepublish({
172-
entries: util.parseEntries([...entries, ...(get('entries') || [])], get('outdir')),
179+
entries,
173180
env: get('env'),
174-
outdir: get('outdir')
181+
outdir
175182
})
176183
})
177184

lib/push-to-s3.js

+50-38
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,20 @@ module.exports = function ({
1616
tag
1717
}) {
1818
const upload = createUpload({bucket: s3bucket, cloudfront, log, tag})
19-
return ([entry, outfile]) => (
20-
path.extname(entry) === '.js'
21-
? upload({
22-
body: browserify({config, entry, env, minify}).bundle(),
23-
outfile
24-
})
25-
: transformCss({config, entry, env, minify})
26-
.then((results) =>
27-
upload({body: results.css, outfile}))
28-
)
19+
return ([entry, outfile]) =>
20+
log(`:hammer_and_wrench: ${tag} building ${outfile}`)
21+
.then(() => path.extname(entry) === '.js'
22+
? new Promise((resolve, reject) =>
23+
browserify({config, entry, env, minify})
24+
.bundle((err, buffer) => err
25+
? reject(err)
26+
: resolve(upload({body: buffer, outfile}))
27+
)
28+
)
29+
: transformCss({config, entry, env, minify})
30+
.then((results) =>
31+
upload({body: results.css, outfile}))
32+
)
2933
}
3034

3135
const createUpload = ({bucket, cloudfront, log, tag}) =>
@@ -52,40 +56,48 @@ function upload ({
5256
}
5357
})
5458

55-
log(`:hammer_and_wrench: ${tag} building ${outfile} and pushing to ${bucket}`).then(() => {
56-
s3object
57-
.upload()
58-
.send(function (err) {
59-
if (err) return reject(`s3 upload to ${bucket} rejected with ${err.message}`)
60-
log(`:ok_hand: ${tag} finished pushing to <${bucketUrl}/${outfile}|${bucket}/${outfile}>`).then(() => {
61-
if (cloudfront) {
62-
const cf = new AWS.CloudFront()
63-
log(`:earth_asia: ${tag} creating cloudfront invalidation at ${outfile}`).then(() => {
64-
cf.createInvalidation({
65-
DistributionId: cloudfront,
66-
InvalidationBatch: {
67-
CallerReference: uuid.v4(),
68-
Paths: {
69-
Quantity: 1,
70-
Items: [
71-
'/' + outfile
72-
]
73-
}
59+
const bytes = bytesToSize(body.byteLength || body.length)
60+
const bucketLink = `<${bucketUrl}/${outfile}|${bucket}/${outfile}>`
61+
log(`:satellite_antenna: ${tag} uploading to ${bucketLink} (${bytes})`)
62+
s3object
63+
.upload()
64+
.send(function (err) {
65+
if (err) return reject(new Error(`s3 upload to ${bucket} rejected with ${err.code} ${err.message}`))
66+
log(`:ok_hand: ${tag} finished uploading to ${bucketLink}`).then(() => {
67+
if (cloudfront) {
68+
const cf = new AWS.CloudFront()
69+
log(`:earth_asia: ${tag} creating cloudfront invalidation at ${outfile}`).then(() => {
70+
cf.createInvalidation({
71+
DistributionId: cloudfront,
72+
InvalidationBatch: {
73+
CallerReference: uuid.v4(),
74+
Paths: {
75+
Quantity: 1,
76+
Items: [
77+
'/' + outfile
78+
]
7479
}
75-
}, function (err) {
76-
if (err) return reject(`cf invalidation rejected with ${err.message}`)
77-
done()
78-
})
80+
}
81+
}, function (err) {
82+
if (err) return reject(new Error(`cf invalidation rejected with ${err.message}`))
83+
done()
7984
})
80-
} else {
81-
done()
82-
}
83-
})
85+
})
86+
} else {
87+
done()
88+
}
8489
})
85-
})
90+
})
8691

8792
function done () {
8893
log(`:checkered_flag: ${tag} finished with ${outfile}`).then(resolve)
8994
}
9095
})
9196
}
97+
98+
function bytesToSize (bytes) {
99+
const sizes = ['bytes', 'kb', 'mb', 'gb', 'tb']
100+
if (bytes === 0) return '0 byte'
101+
const i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)))
102+
return Math.round(bytes / Math.pow(1024, i), 2) + sizes[i]
103+
}

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
"envify": "^4.0.0",
5656
"errorify": "^0.3.1",
5757
"eslint": "^3.15.0",
58-
"eslint-config-standard": "^6.2.1",
58+
"eslint-config-standard": "^7.0.0",
5959
"eslint-config-standard-jsx": "^3.3.0",
6060
"eslint-plugin-flowtype": "^2.30.0",
6161
"eslint-plugin-flowtype-errors": "^3.0.0",

yarn.lock

+3-3
Original file line numberDiff line numberDiff line change
@@ -2178,9 +2178,9 @@ eslint-config-standard-jsx@^3.3.0:
21782178
version "3.3.0"
21792179
resolved "https://registry.yarnpkg.com/eslint-config-standard-jsx/-/eslint-config-standard-jsx-3.3.0.tgz#cab0801a15a360bf63facb97ab22fbdd88d8a5e0"
21802180

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

21852185
eslint-plugin-flowtype-errors@^3.0.0:
21862186
version "3.0.0"

0 commit comments

Comments
 (0)