Skip to content

Commit d055640

Browse files
Merge pull request #148 from conveyal/dev
v3.6.0
2 parents 5f9098b + 1a4b016 commit d055640

10 files changed

+61
-25
lines changed

README.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ $ npm install -g mastarm
3030

3131
## Configuration
3232

33-
Mastarm can be pointed to a directory containing configuration files using the `--config` flag. By default, Mastarm looks in the `configurations/default` path of the current working directory. Mastarm looks for four different files: `env.yml`, `settings.yml`, `store.yml`, and `messages.yml`.
33+
Mastarm can be pointed to a directory containing configuration files using the `--config` flag. It will fall back to files in the `configurations/default` path of the current working directory if one of the files below does not exist in config folder specified.
3434

3535
### `env.yml`
3636

@@ -56,6 +56,10 @@ Settings contain both Mastarm configuration settings and per environment setting
5656

5757
Auto-populate your redux store with this configuration data instead of setting defaults directly in code.
5858

59+
### `style.css`
60+
61+
Add a stylesheet that gets `@import`ed at the beginning of your entry stylesheet. This allows you to override styles for specific deployments and use [custom CSS properties](http://cssnext.io/features/#custom-properties-var). Useful for configuration specific images and colors.
62+
5963
## CLI Usage
6064

6165
Not all options pertain to all commands. Entries are in the format `input/file.js:output/file.js`.

__tests__/lib/__snapshots__/load-config.js.snap

+1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ Object {
77
"messages": Object {},
88
"settings": Object {},
99
"store": Object {},
10+
"stylePath": null,
1011
}
1112
`;

lib/budo.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ module.exports = function ({
4646

4747
files.map((file) => {
4848
if (path.extname(file[0]) === '.css') {
49-
transformCss({entry: file[0], outfile: file[1], watch: true})
49+
transformCss({config, entry: file[0], outfile: file[1], watch: true})
5050
} else {
5151
budoFiles.push(file.join(':'))
5252
}

lib/build.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ module.exports = function ({
2121
}) {
2222
return files.map(([entry, outfile]) =>
2323
path.extname(entry) === '.css'
24-
? buildCss({entry, outfile, watch})
24+
? buildCss({config, entry, outfile, watch})
2525
: buildJs({config, entry, env, minify, outfile, watch}))
2626
}
2727

lib/css-transform.js

+8-3
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,14 @@ const postcssReporter = require('postcss-reporter')
1010
const postcssSafeParser = require('postcss-safe-parser')
1111

1212
module.exports = function ({
13+
config,
1314
entry,
1415
outfile,
1516
watch
1617
}) {
18+
const configImport = config.stylePath
19+
? `@import url(${config.stylePath});`
20+
: ''
1721
let watcher
1822
const transform = () =>
1923
postcss([
@@ -27,10 +31,11 @@ module.exports = function ({
2731
}
2832
}
2933
}),
34+
base64ify(process.cwd()),
3035
postcssNext(),
3136
postcssReporter({clearMessages: true})
3237
])
33-
.process(fs.readFileSync(entry, 'utf8'), {
38+
.process(`${configImport}${fs.readFileSync(entry, 'utf8')}`, {
3439
parser: postcssSafeParser,
3540
map: true,
3641
to: outfile
@@ -59,8 +64,6 @@ module.exports = function ({
5964

6065
const base64ify = postcss.plugin('postcss-base64ify', function () {
6166
return function (css, result) {
62-
const source = css.source.input.file
63-
const dir = path.dirname(source)
6467
css.replaceValues(/url\((\s*)(['"]?)(.+?)\2(\s*)\)/g, function (string) {
6568
const filename = getUrl(string)
6669
.split('?')[0]
@@ -71,6 +74,8 @@ const base64ify = postcss.plugin('postcss-base64ify', function () {
7174
} else if (filename[0] === '/') {
7275
file = path.join(process.cwd(), filename)
7376
} else {
77+
const source = css.source.input.file
78+
const dir = path.dirname(source)
7479
file = path.resolve(dir, filename)
7580
}
7681
if (!fs.existsSync(file)) {

lib/load-config.js

+20-12
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,34 @@ const path = require('path')
33
const YAML = require('yamljs')
44

55
module.exports = function load (cwd, config, environment) {
6+
const configDirectory = path.resolve(cwd, config || 'configurations/default')
67
const defaultDirectory = path.resolve(cwd, 'configurations/default')
7-
const directory = path.resolve(cwd, config || 'configurations/default')
8-
const env = loadYml('env')
9-
const settings = loadYml('settings')
8+
const env = loadYaml('env')
9+
const settings = loadYaml('settings')
1010

1111
return {
1212
env: overrideWithEnvironment(env, environment),
1313
environment,
14-
messages: loadYml('messages'),
15-
path: directory,
14+
messages: loadYaml('messages'),
15+
path: configDirectory,
1616
settings: overrideWithEnvironment(settings, environment),
17-
store: loadYml('store')
17+
store: loadYaml('store'),
18+
stylePath: findFile('style.css')
1819
}
1920

20-
function loadYml (filename) {
21-
const defaultFile = defaultDirectory + '/' + filename + '.yml'
22-
const file = directory + '/' + filename + '.yml'
23-
if (fs.existsSync(file)) return YAML.load(file) || {}
24-
else if (fs.existsSync(defaultFile)) return YAML.load(defaultFile) || {}
25-
else return {}
21+
function findFile (filename) {
22+
const file = configDirectory + '/' + filename
23+
if (fs.existsSync(file)) return file
24+
const defaultFile = defaultDirectory + '/' + filename
25+
if (fs.existsSync(defaultFile)) return defaultFile
26+
return null
27+
}
28+
29+
function loadYaml (filename) {
30+
const file = findFile(`${filename}.yml`)
31+
return file
32+
? YAML.parse(fs.readFileSync(file, 'utf8'))
33+
: {}
2634
}
2735
}
2836

lib/logger.js

+12-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
1+
const nodeEmoji = require('node-emoji')
12
const slack = require('./notify-slack')
23

34
module.exports = function ({channel, webhook} = {}) {
4-
if (webhook) console.log(`see slack@${channel} for notifications`)
5-
return function (text) {
6-
if (webhook) {
5+
if (webhook) {
6+
return function (text) {
7+
emojifyLog(text)
78
return slack({channel, text, webhook})
8-
} else {
9-
return Promise.resolve(console.log(text))
109
}
1110
}
11+
return function (text) {
12+
return Promise.resolve(emojifyLog(text))
13+
}
14+
}
15+
16+
function emojifyLog (text) {
17+
const strippedLinks = text.replace(/<[^|>]+\|([^>]+)>/g, '$1')
18+
console.log(nodeEmoji.emojify(strippedLinks))
1219
}

lib/push-to-s3.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ function upload ({
5858

5959
const bytes = bytesToSize(body.byteLength || body.length)
6060
const bucketLink = `<${bucketUrl}/${outfile}|${bucket}/${outfile}>`
61-
log(`:satellite_antenna: ${tag} uploading to ${bucketLink} (${bytes})`)
61+
log(`:airplane_departure: ${tag} uploading to ${bucketLink} (${bytes})`)
6262
s3object
6363
.upload()
6464
.send(function (err) {
@@ -99,5 +99,5 @@ function bytesToSize (bytes) {
9999
const sizes = ['bytes', 'kb', 'mb', 'gb', 'tb']
100100
if (bytes === 0) return '0 byte'
101101
const i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)))
102-
return Math.round(bytes / Math.pow(1024, i), 2) + sizes[i]
102+
return (bytes / Math.pow(1024, i)).toFixed(2) + sizes[i]
103103
}

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
"middleware-proxy": "^2.0.2",
7272
"mime": "^1.3.4",
7373
"mkdirp": "^0.5.1",
74+
"node-emoji": "^1.5.1",
7475
"postcss": "^5.0.21",
7576
"postcss-cssnext": "^2.6.0",
7677
"postcss-import": "^9.0.0",

yarn.lock

+10
Original file line numberDiff line numberDiff line change
@@ -4075,6 +4075,12 @@ netrc@^0.1.4:
40754075
version "0.1.4"
40764076
resolved "https://registry.yarnpkg.com/netrc/-/netrc-0.1.4.tgz#6be94fcaca8d77ade0a9670dc460914c94472444"
40774077

4078+
node-emoji@^1.5.1:
4079+
version "1.5.1"
4080+
resolved "https://registry.yarnpkg.com/node-emoji/-/node-emoji-1.5.1.tgz#fd918e412769bf8c448051238233840b2aff16a1"
4081+
dependencies:
4082+
string.prototype.codepointat "^0.2.0"
4083+
40784084
node-fetch@^1.0.1:
40794085
version "1.6.3"
40804086
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-1.6.3.tgz#dc234edd6489982d58e8f0db4f695029abcd8c04"
@@ -5644,6 +5650,10 @@ string-width@^2.0.0:
56445650
is-fullwidth-code-point "^2.0.0"
56455651
strip-ansi "^3.0.0"
56465652

5653+
string.prototype.codepointat@^0.2.0:
5654+
version "0.2.0"
5655+
resolved "https://registry.yarnpkg.com/string.prototype.codepointat/-/string.prototype.codepointat-0.2.0.tgz#6b26e9bd3afcaa7be3b4269b526de1b82000ac78"
5656+
56475657
string_decoder@~0.10.0, string_decoder@~0.10.x:
56485658
version "0.10.31"
56495659
resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-0.10.31.tgz#62e203bc41766c6c28c9fc84301dab1c5310fa94"

0 commit comments

Comments
 (0)