Skip to content

Commit 0b35cc1

Browse files
Merge pull request #194 from conveyal/dev
v3.9.0
2 parents 9e554ad + fd62a2b commit 0b35cc1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+918
-562
lines changed

README.md

+41-19
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
* [Build](#build)
1616
* [Commit](#commit)
1717
* [Deploy](#deploy)
18+
* [Flow](#flow)
19+
* [Format](#format)
1820
* [Lint](#lint)
1921
* [Prepublish](#prepublish)
2022
* [Test](#test)
@@ -67,44 +69,47 @@ Not all options pertain to all commands. Entries are in the format `input/file.
6769
```shell
6870
$ mastarm --help
6971

70-
Usage: mastarm <cmd> [options]
72+
Usage: mastarm [options] [command]
7173

7274

7375
Commands:
7476

75-
build [entries...] [options] Bundle JavaScript & CSS
76-
commit Force intelligent commit messages.
77-
deploy [entries...] [options] Bundle & Deploy JavaScript & CSS
78-
lint [paths...] Lint JavaScript [& CSS coming soon!]
79-
test [options] Run tests using Jest test runner
80-
lint-messages [paths...] Lint message strings, making sure all messages used in source files are present in messages.yml
77+
build [entries...] Bundle JavaScript & CSS
78+
commit Force intelligent commit messages.
79+
deploy Bundle & Deploy JavaScript & CSS
80+
flow [command] Run flow on the current directory.
81+
format [entries...] Format JavaScript
82+
lint Lint JavaScript
83+
lint-messages [paths...] Check existence of messages used in source code.
84+
prepublish [entries...] Transpile JavaScript down to ES5 with Babel
85+
test [patterns...] Run tests using Jest
86+
help [cmd] display help for [cmd]
8187

8288
Options:
8389

84-
-h, --help output usage information
85-
-V, --version output the version number
86-
-c, --config <path> Path to configuration files.
87-
-e, --env <environment> Environment to use.
88-
-m, --minify Minify built files.
89-
-p, --proxy <address> Proxy calls through to target address.
90-
-s, --serve Serve with budo. Auto-matically rebuilds on changes.
91-
-u, --update-snapshots Force update of jest snapshots. USE WITH CAUTION.
92-
-w, --watch Rebuild on changes with watchify.
90+
-h, --help output usage information
91+
-V, --version output the version number
92+
-c, --config <path> Path to configuration files.
93+
-e, --env <environment> Environment to use.
94+
-m, --minify Minify built files.
95+
-O, --outdir <dir> Publish directory
9396
```
9497

9598
### `build`
9699

97100
Compile JS, HTML, CSS, YAML, Markdown into a single `.js`. Utilizes [babel](https://babeljs.io/), [browserify](https://github.com/substack/node-browserify), [budo](https://github.com/mattdesl/budo), and [postcss](http://postcss.org/).
98101

99102
```shell
100-
$ mastarm build [options] [entries...]
103+
$ mastarm build --help
104+
105+
Usage: mastarm-build [options]
101106

102107
Options:
103108

104109
-h, --help output usage information
105110
-F, --flyle Cache and serve tiles.
106111
-p, --proxy <address> Proxy calls through to target address.
107-
-s, --serve Serve with budo. Auto-matically rebuilds on changes.
112+
-s, --serve Serve with budo. Automatically rebuilds on changes.
108113
-w, --watch Automatically rebuild on changes.
109114
```
110115

@@ -134,7 +139,6 @@ Options:
134139
-h, --help output usage information
135140
--cloudfront CloudFront Distribution ID to invalidate.
136141
--s3bucket S3 Bucket to push to.
137-
138142
```
139143

140144
#### Slack Notifications
@@ -146,6 +150,24 @@ SLACK_CHANNEL: '#devops'
146150
SLACK_WEBHOOK: https://hooks.slack.com/services/fake-code
147151
```
148152

153+
### `flow`
154+
155+
Run [Flow](https://flow.org/). Must have a `.flowconfig` in the current working directory and a `// @flow` annotation at the top of each file you want to check. See the Flow website for documentation.
156+
157+
### `format`
158+
159+
Format JavaScript code using [Prettier](https://github.com/prettier/prettier). By default it globs all JavaScript files from the current directory and `__mocks__`, `__tests__`, `bin`, `lib`, and `src`. If you pass files in it directly it will just use those.
160+
161+
```shell
162+
$ mastarm format
163+
```
164+
165+
To format one file:
166+
167+
```shell
168+
$ mastarm format index.js
169+
```
170+
149171
### `lint`
150172

151173
Lint using [Standard](http://standardjs.com/). Everything is passed directly to [`standard-engine`](https://github.com/Flet/standard-engine).

__mocks__/aws-sdk.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
/* global jest */
22

3-
const AWS = module.exports = jest.genMockFromModule('aws-sdk')
4-
AWS.S3.prototype.upload = () => ({send: (fn) => fn()})
3+
const AWS = (module.exports = jest.genMockFromModule('aws-sdk'))
4+
AWS.S3.prototype.upload = () => ({send: fn => fn()})

__tests__/bin/mastarm.js

+12-10
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ describe('mastarm cli', () => {
2020
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout
2121
})
2222

23-
it('should display usage with no args', (done) => {
23+
it('should display usage with no args', done => {
2424
exec(`node ${mastarm} --help`, (err, stdout, stderr) => {
2525
expect(err).toBeNull()
2626
expect(stdout).toContain('Usage: mastarm [options] [command]')
@@ -33,11 +33,12 @@ describe('mastarm cli', () => {
3333
const buildDir = util.buildDir
3434
const mockDir = util.mockDir
3535

36-
beforeEach((done) => mkdirp(buildDir, done))
37-
afterEach((done) => rimraf(buildDir, done))
36+
beforeEach(done => mkdirp(buildDir, done))
37+
afterEach(done => rimraf(buildDir, done))
3838

39-
it('should build a project', (done) => {
40-
exec(`node ${mastarm} build ${mockDir}/index.js:${buildDir}/index.js ${mockDir}/index.css:${buildDir}/index.css`,
39+
it('should build a project', done => {
40+
exec(
41+
`node ${mastarm} build ${mockDir}/index.js:${buildDir}/index.js ${mockDir}/index.css:${buildDir}/index.css`,
4142
(err, stdout, stderr) => {
4243
expect(err).toBeNull()
4344
expect(stdout).toContain('done building')
@@ -54,11 +55,12 @@ describe('mastarm cli', () => {
5455
const buildDir = util.buildDir
5556
const mockDir = util.mockDir
5657

57-
beforeEach((done) => mkdirp(buildDir, done))
58-
afterEach((done) => rimraf(buildDir, done))
58+
beforeEach(done => mkdirp(buildDir, done))
59+
afterEach(done => rimraf(buildDir, done))
5960

60-
it('should prepublish a project', (done) => {
61-
exec(`node ${mastarm} prepublish ${mockDir}:${buildDir}`,
61+
it('should prepublish a project', done => {
62+
exec(
63+
`node ${mastarm} prepublish ${mockDir}:${buildDir}`,
6264
(err, stdout, stderr) => {
6365
expect(err).toBeNull()
6466
expect(stdout).toBe('')
@@ -70,7 +72,7 @@ describe('mastarm cli', () => {
7072
})
7173
})
7274

73-
it('should run lint on a project', (done) => {
75+
it('should run lint on a project', done => {
7476
exec(`node ${mastarm} lint`, (err, stdout, stderr) => {
7577
expect(err).toBeNull()
7678
expect(stdout).toBe('')
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`build development should transform css 1`] = `345`;
3+
exports[`build development should transform css 1`] = `86`;
44

55
exports[`build development should transform js 1`] = `157929`;
66

77
exports[`build production should transform and minify js and css 1`] = `156127`;
88

9-
exports[`build production should transform and minify js and css 2`] = `345`;
9+
exports[`build production should transform and minify js and css 2`] = `86`;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`format can format a file 1`] = `
4+
"function a () {
5+
return 1
6+
}
7+
"
8+
`;

__tests__/lib/build.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ describe('build', () => {
2424
})
2525

2626
const transpiledString = result.toString()
27-
expect(transpiledString.indexOf('MockTestComponentUniqueName')).not.toBe(-1)
27+
expect(transpiledString.indexOf('MockTestComponentUniqueName')).not.toBe(
28+
-1
29+
)
2830
expect(transpiledString.length).toMatchSnapshot()
2931
})
3032

@@ -45,14 +47,13 @@ describe('build', () => {
4547
const [jsResult, cssResult] = await build({
4648
config: loadConfig(process.cwd(), null, 'production'),
4749
env: 'production',
48-
files: [
49-
[`${mockDir}/index.js`],
50-
[`${mockDir}/index.css`]
51-
],
50+
files: [[`${mockDir}/index.js`], [`${mockDir}/index.css`]],
5251
minify: true
5352
})
5453
const transpiledString = jsResult.toString()
55-
expect(transpiledString.indexOf('MockTestComponentUniqueName')).not.toBe(-1)
54+
expect(transpiledString.indexOf('MockTestComponentUniqueName')).not.toBe(
55+
-1
56+
)
5657
expect(cssResult.css.indexOf('criticalClass')).not.toBe(-1)
5758
expect(transpiledString.length).toMatchSnapshot()
5859
expect(cssResult.css.length).toMatchSnapshot()

__tests__/lib/format.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/* globals afterEach, beforeEach, describe, expect, it */
2+
3+
const fs = require('fs')
4+
5+
const rimraf = require('rimraf')
6+
7+
const format = require('../../lib/format')
8+
9+
describe('format', () => {
10+
beforeEach(done => fs.writeFile('test.js', 'function a(){return 1;}', done))
11+
afterEach(done => rimraf('test.js', done))
12+
13+
it('can format a file', done => {
14+
format(['test.js']).then(() => {
15+
expect(fs.readFileSync('test.js', {encoding: 'utf-8'})).toMatchSnapshot()
16+
done()
17+
})
18+
})
19+
})

__tests__/lib/jest.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ describe('test.js', () => {
1515
updateSnapshots: true
1616
})
1717
cfg[JEST_CONFIG_INDEX] = JSON.parse(cfg[JEST_CONFIG_INDEX])
18-
expect(cfg[JEST_CONFIG_INDEX].transform['.*']).toContain('lib/jest-preprocessor.js')
18+
expect(cfg[JEST_CONFIG_INDEX].transform['.*']).toContain(
19+
'lib/jest-preprocessor.js'
20+
)
1921
delete cfg[JEST_CONFIG_INDEX].transform
2022
expect(cfg).toMatchSnapshot()
2123
})

__tests__/lib/lint-messages.js

+32-11
Original file line numberDiff line numberDiff line change
@@ -30,28 +30,49 @@ const testMessages = {
3030
}
3131

3232
describe('lint-messages', () => {
33-
const { lintFileContents, parseImportLine } = require('../../lib/lint-messages')
33+
const {lintFileContents, parseImportLine} = require('../../lib/lint-messages')
3434
it('should parse root import correctly', () => {
35-
expect(parseImportLine("import msgs from '../utils/messages'"))
36-
.toMatchSnapshot("import msgs from '../utils/messages'")
35+
expect(
36+
parseImportLine("import msgs from '../utils/messages'")
37+
).toMatchSnapshot("import msgs from '../utils/messages'")
3738
})
3839

3940
it('should parse named imports correctly', () => {
40-
expect(parseImportLine("import { analysis, project as proj } from '../utils/messages'"))
41-
.toMatchSnapshot("import { analysis, project as proj } from '../utils/messages'")
41+
expect(
42+
parseImportLine(
43+
"import { analysis, project as proj } from '../utils/messages'"
44+
)
45+
).toMatchSnapshot(
46+
"import { analysis, project as proj } from '../utils/messages'"
47+
)
4248

4349
// make sure it works when spacing is smaller
44-
expect(parseImportLine("import {analysis, project as proj} from '../utils/messages'"))
45-
.toMatchSnapshot("import {analysis, project as proj} from '../utils/messages'")
50+
expect(
51+
parseImportLine(
52+
"import {analysis, project as proj} from '../utils/messages'"
53+
)
54+
).toMatchSnapshot(
55+
"import {analysis, project as proj} from '../utils/messages'"
56+
)
4657
})
4758

4859
it('should parse named and default imports together correctly', () => {
49-
expect(parseImportLine("import messages, { analysis, project as proj } from '../utils/messages'"))
50-
.toMatchSnapshot("import messages, { analysis, project as proj } from '../utils/messages'")
60+
expect(
61+
parseImportLine(
62+
"import messages, { analysis, project as proj } from '../utils/messages'"
63+
)
64+
).toMatchSnapshot(
65+
"import messages, { analysis, project as proj } from '../utils/messages'"
66+
)
5167

5268
// try it with the default import after the named imports
53-
expect(parseImportLine("import { analysis, project as proj }, messages from '../utils/messages'"))
54-
.toMatchSnapshot("import { analysis, project as proj }, messages from '../utils/messages'")
69+
expect(
70+
parseImportLine(
71+
"import { analysis, project as proj }, messages from '../utils/messages'"
72+
)
73+
).toMatchSnapshot(
74+
"import { analysis, project as proj }, messages from '../utils/messages'"
75+
)
5576
})
5677

5778
it('should lint file', () => {

__tests__/lib/prepublish.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ const util = require('../../lib/util')
88
const {buildDir, mockDir} = require('../test-utils/util.js')
99

1010
describe('prepublish', () => {
11-
beforeEach((done) => mkdirp(buildDir, done))
12-
afterEach((done) => rimraf(buildDir, done))
11+
beforeEach(done => mkdirp(buildDir, done))
12+
afterEach(done => rimraf(buildDir, done))
1313

1414
it('should transpile a directory of files', () => {
1515
const results = prepublish({

__tests__/lib/push-to-s3.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ describe('lib > push to s3', () => {
1616
const loadConfig = require('../../lib/load-config')
1717

1818
it('should compile JavaScript and CSS and send to s3 via aws-sdk', () => {
19-
const config = loadConfig(process.cwd(), 'configurations/default', 'development')
19+
const config = loadConfig(
20+
process.cwd(),
21+
'configurations/default',
22+
'development'
23+
)
2024
const push = createPushToS3({
2125
env: 'development',
2226
config,
@@ -28,7 +32,9 @@ describe('lib > push to s3', () => {
2832
env: 'development',
2933
files
3034
}).then(() =>
31-
Promise.all(files.map((f) =>
32-
push({body: fs.readFileSync(f[0]), outfile: f[0]}))))
35+
Promise.all(
36+
files.map(f => push({body: fs.readFileSync(f[0]), outfile: f[0]}))
37+
)
38+
)
3339
})
3440
})

__tests__/lib/util.js

+8-5
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ const mockDir = testUtils.mockDir
77
describe('util.js', () => {
88
it('configureEnvironment should set process.env vars', () => {
99
const env2 = 'mock-env2'
10-
const messages = { hi: 'there' }
11-
const settings = { someSetting: true }
10+
const messages = {hi: 'there'}
11+
const settings = {someSetting: true}
1212
const store = {}
1313
const config = {
1414
env: 'mock-env',
@@ -17,15 +17,15 @@ describe('util.js', () => {
1717
settings,
1818
store
1919
}
20-
util.configureEnvironment({ config, env: env2 })
20+
util.configureEnvironment({config, env: env2})
2121
expect(process.env.NODE_ENV).toEqual(env2)
2222
expect(JSON.parse(process.env.MESSAGES)).toEqual(messages)
2323
expect(JSON.parse(process.env.SETTINGS)).toEqual(settings)
2424
expect(JSON.parse(process.env.STORE)).toEqual(store)
2525
})
2626

2727
it('makeGetFn should find the right value', () => {
28-
expect(util.makeGetFn([{ a: 1 }, { a: 2 }])('a')).toEqual(1)
28+
expect(util.makeGetFn([{a: 1}, {a: 2}])('a')).toEqual(1)
2929
})
3030

3131
describe('parseEntries', () => {
@@ -37,7 +37,10 @@ describe('util.js', () => {
3737
})
3838

3939
it('should return inputted file paths', () => {
40-
const result = util.parseEntries([`${mockDir}/index.css:blah`, `${mockDir}/index.js:blah`], get)
40+
const result = util.parseEntries(
41+
[`${mockDir}/index.css:blah`, `${mockDir}/index.js:blah`],
42+
get
43+
)
4144
expect(result.length).toBe(2)
4245
expect(result).toMatchSnapshot()
4346
})

0 commit comments

Comments
 (0)