Skip to content

Commit

Permalink
Merge pull request #194 from conveyal/dev
Browse files Browse the repository at this point in the history
v3.9.0
  • Loading branch information
trevorgerhardt authored Apr 29, 2017
2 parents 9e554ad + fd62a2b commit 0b35cc1
Show file tree
Hide file tree
Showing 42 changed files with 918 additions and 562 deletions.
60 changes: 41 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
* [Build](#build)
* [Commit](#commit)
* [Deploy](#deploy)
* [Flow](#flow)
* [Format](#format)
* [Lint](#lint)
* [Prepublish](#prepublish)
* [Test](#test)
Expand Down Expand Up @@ -67,44 +69,47 @@ Not all options pertain to all commands. Entries are in the format `input/file.
```shell
$ mastarm --help

Usage: mastarm <cmd> [options]
Usage: mastarm [options] [command]


Commands:

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

Options:

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

### `build`

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/).

```shell
$ mastarm build [options] [entries...]
$ mastarm build --help

Usage: mastarm-build [options]

Options:

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

Expand Down Expand Up @@ -134,7 +139,6 @@ Options:
-h, --help output usage information
--cloudfront CloudFront Distribution ID to invalidate.
--s3bucket S3 Bucket to push to.

```

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

### `flow`

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.

### `format`

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.

```shell
$ mastarm format
```

To format one file:

```shell
$ mastarm format index.js
```

### `lint`

Lint using [Standard](http://standardjs.com/). Everything is passed directly to [`standard-engine`](https://github.com/Flet/standard-engine).
Expand Down
4 changes: 2 additions & 2 deletions __mocks__/aws-sdk.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global jest */

const AWS = module.exports = jest.genMockFromModule('aws-sdk')
AWS.S3.prototype.upload = () => ({send: (fn) => fn()})
const AWS = (module.exports = jest.genMockFromModule('aws-sdk'))
AWS.S3.prototype.upload = () => ({send: fn => fn()})
22 changes: 12 additions & 10 deletions __tests__/bin/mastarm.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('mastarm cli', () => {
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout
})

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

beforeEach((done) => mkdirp(buildDir, done))
afterEach((done) => rimraf(buildDir, done))
beforeEach(done => mkdirp(buildDir, done))
afterEach(done => rimraf(buildDir, done))

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

beforeEach((done) => mkdirp(buildDir, done))
afterEach((done) => rimraf(buildDir, done))
beforeEach(done => mkdirp(buildDir, done))
afterEach(done => rimraf(buildDir, done))

it('should prepublish a project', (done) => {
exec(`node ${mastarm} prepublish ${mockDir}:${buildDir}`,
it('should prepublish a project', done => {
exec(
`node ${mastarm} prepublish ${mockDir}:${buildDir}`,
(err, stdout, stderr) => {
expect(err).toBeNull()
expect(stdout).toBe('')
Expand All @@ -70,7 +72,7 @@ describe('mastarm cli', () => {
})
})

it('should run lint on a project', (done) => {
it('should run lint on a project', done => {
exec(`node ${mastarm} lint`, (err, stdout, stderr) => {
expect(err).toBeNull()
expect(stdout).toBe('')
Expand Down
4 changes: 2 additions & 2 deletions __tests__/lib/__snapshots__/build.js.snap
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`build development should transform css 1`] = `345`;
exports[`build development should transform css 1`] = `86`;

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

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

exports[`build production should transform and minify js and css 2`] = `345`;
exports[`build production should transform and minify js and css 2`] = `86`;
8 changes: 8 additions & 0 deletions __tests__/lib/__snapshots__/format.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`format can format a file 1`] = `
"function a () {
return 1
}
"
`;
13 changes: 7 additions & 6 deletions __tests__/lib/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ describe('build', () => {
})

const transpiledString = result.toString()
expect(transpiledString.indexOf('MockTestComponentUniqueName')).not.toBe(-1)
expect(transpiledString.indexOf('MockTestComponentUniqueName')).not.toBe(
-1
)
expect(transpiledString.length).toMatchSnapshot()
})

Expand All @@ -45,14 +47,13 @@ describe('build', () => {
const [jsResult, cssResult] = await build({
config: loadConfig(process.cwd(), null, 'production'),
env: 'production',
files: [
[`${mockDir}/index.js`],
[`${mockDir}/index.css`]
],
files: [[`${mockDir}/index.js`], [`${mockDir}/index.css`]],
minify: true
})
const transpiledString = jsResult.toString()
expect(transpiledString.indexOf('MockTestComponentUniqueName')).not.toBe(-1)
expect(transpiledString.indexOf('MockTestComponentUniqueName')).not.toBe(
-1
)
expect(cssResult.css.indexOf('criticalClass')).not.toBe(-1)
expect(transpiledString.length).toMatchSnapshot()
expect(cssResult.css.length).toMatchSnapshot()
Expand Down
19 changes: 19 additions & 0 deletions __tests__/lib/format.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* globals afterEach, beforeEach, describe, expect, it */

const fs = require('fs')

const rimraf = require('rimraf')

const format = require('../../lib/format')

describe('format', () => {
beforeEach(done => fs.writeFile('test.js', 'function a(){return 1;}', done))
afterEach(done => rimraf('test.js', done))

it('can format a file', done => {
format(['test.js']).then(() => {
expect(fs.readFileSync('test.js', {encoding: 'utf-8'})).toMatchSnapshot()
done()
})
})
})
4 changes: 3 additions & 1 deletion __tests__/lib/jest.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ describe('test.js', () => {
updateSnapshots: true
})
cfg[JEST_CONFIG_INDEX] = JSON.parse(cfg[JEST_CONFIG_INDEX])
expect(cfg[JEST_CONFIG_INDEX].transform['.*']).toContain('lib/jest-preprocessor.js')
expect(cfg[JEST_CONFIG_INDEX].transform['.*']).toContain(
'lib/jest-preprocessor.js'
)
delete cfg[JEST_CONFIG_INDEX].transform
expect(cfg).toMatchSnapshot()
})
Expand Down
43 changes: 32 additions & 11 deletions __tests__/lib/lint-messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,28 +30,49 @@ const testMessages = {
}

describe('lint-messages', () => {
const { lintFileContents, parseImportLine } = require('../../lib/lint-messages')
const {lintFileContents, parseImportLine} = require('../../lib/lint-messages')
it('should parse root import correctly', () => {
expect(parseImportLine("import msgs from '../utils/messages'"))
.toMatchSnapshot("import msgs from '../utils/messages'")
expect(
parseImportLine("import msgs from '../utils/messages'")
).toMatchSnapshot("import msgs from '../utils/messages'")
})

it('should parse named imports correctly', () => {
expect(parseImportLine("import { analysis, project as proj } from '../utils/messages'"))
.toMatchSnapshot("import { analysis, project as proj } from '../utils/messages'")
expect(
parseImportLine(
"import { analysis, project as proj } from '../utils/messages'"
)
).toMatchSnapshot(
"import { analysis, project as proj } from '../utils/messages'"
)

// make sure it works when spacing is smaller
expect(parseImportLine("import {analysis, project as proj} from '../utils/messages'"))
.toMatchSnapshot("import {analysis, project as proj} from '../utils/messages'")
expect(
parseImportLine(
"import {analysis, project as proj} from '../utils/messages'"
)
).toMatchSnapshot(
"import {analysis, project as proj} from '../utils/messages'"
)
})

it('should parse named and default imports together correctly', () => {
expect(parseImportLine("import messages, { analysis, project as proj } from '../utils/messages'"))
.toMatchSnapshot("import messages, { analysis, project as proj } from '../utils/messages'")
expect(
parseImportLine(
"import messages, { analysis, project as proj } from '../utils/messages'"
)
).toMatchSnapshot(
"import messages, { analysis, project as proj } from '../utils/messages'"
)

// try it with the default import after the named imports
expect(parseImportLine("import { analysis, project as proj }, messages from '../utils/messages'"))
.toMatchSnapshot("import { analysis, project as proj }, messages from '../utils/messages'")
expect(
parseImportLine(
"import { analysis, project as proj }, messages from '../utils/messages'"
)
).toMatchSnapshot(
"import { analysis, project as proj }, messages from '../utils/messages'"
)
})

it('should lint file', () => {
Expand Down
4 changes: 2 additions & 2 deletions __tests__/lib/prepublish.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ const util = require('../../lib/util')
const {buildDir, mockDir} = require('../test-utils/util.js')

describe('prepublish', () => {
beforeEach((done) => mkdirp(buildDir, done))
afterEach((done) => rimraf(buildDir, done))
beforeEach(done => mkdirp(buildDir, done))
afterEach(done => rimraf(buildDir, done))

it('should transpile a directory of files', () => {
const results = prepublish({
Expand Down
12 changes: 9 additions & 3 deletions __tests__/lib/push-to-s3.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ describe('lib > push to s3', () => {
const loadConfig = require('../../lib/load-config')

it('should compile JavaScript and CSS and send to s3 via aws-sdk', () => {
const config = loadConfig(process.cwd(), 'configurations/default', 'development')
const config = loadConfig(
process.cwd(),
'configurations/default',
'development'
)
const push = createPushToS3({
env: 'development',
config,
Expand All @@ -28,7 +32,9 @@ describe('lib > push to s3', () => {
env: 'development',
files
}).then(() =>
Promise.all(files.map((f) =>
push({body: fs.readFileSync(f[0]), outfile: f[0]}))))
Promise.all(
files.map(f => push({body: fs.readFileSync(f[0]), outfile: f[0]}))
)
)
})
})
13 changes: 8 additions & 5 deletions __tests__/lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ const mockDir = testUtils.mockDir
describe('util.js', () => {
it('configureEnvironment should set process.env vars', () => {
const env2 = 'mock-env2'
const messages = { hi: 'there' }
const settings = { someSetting: true }
const messages = {hi: 'there'}
const settings = {someSetting: true}
const store = {}
const config = {
env: 'mock-env',
Expand All @@ -17,15 +17,15 @@ describe('util.js', () => {
settings,
store
}
util.configureEnvironment({ config, env: env2 })
util.configureEnvironment({config, env: env2})
expect(process.env.NODE_ENV).toEqual(env2)
expect(JSON.parse(process.env.MESSAGES)).toEqual(messages)
expect(JSON.parse(process.env.SETTINGS)).toEqual(settings)
expect(JSON.parse(process.env.STORE)).toEqual(store)
})

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

describe('parseEntries', () => {
Expand All @@ -37,7 +37,10 @@ describe('util.js', () => {
})

it('should return inputted file paths', () => {
const result = util.parseEntries([`${mockDir}/index.css:blah`, `${mockDir}/index.js:blah`], get)
const result = util.parseEntries(
[`${mockDir}/index.css:blah`, `${mockDir}/index.js:blah`],
get
)
expect(result.length).toBe(2)
expect(result).toMatchSnapshot()
})
Expand Down
Loading

0 comments on commit 0b35cc1

Please sign in to comment.