Skip to content

Commit 5ecbd27

Browse files
feat(prepublish): Add prepublish command for transpiling
1 parent 3cb8a10 commit 5ecbd27

File tree

1 file changed

+27
-21
lines changed

1 file changed

+27
-21
lines changed

bin/mastarm

+27-21
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#!/usr/bin/env node
22

3-
const checkDependencies = require('check-dependencies')
43
const commander = require('commander')
54
const path = require('path')
65

@@ -9,7 +8,6 @@ const pkg = require('../lib/pkg')
98

109
commander
1110
.version(require('../package.json').version)
12-
.usage('<cmd> [options]')
1311
.option('-c, --config <path>', 'Path to configuration files.', path.join(process.cwd(), '/configurations/default'))
1412
.option('-e, --env <environment>', 'Environment to use.', process.env.NODE_ENV || 'development')
1513
.option('-m, --minify', 'Minify built files.')
@@ -23,10 +21,10 @@ commander
2321
.option('-s, --serve', 'Serve with budo. Auto-matically rebuilds on changes.')
2422
.option('-w, --watch', 'Rebuild on changes with watchify.')
2523
.action(function (entries, options) {
24+
checkDependencies()
2625
const config = loadConfig(process.cwd(), commander.config, commander.env)
2726
const get = (item) => val([options, commander, config.settings], item)
2827
const files = parseEntries(entries, get)
29-
3028
if (get('serve')) {
3129
const budo = require('../lib/budo')
3230
files.map(budo({
@@ -50,10 +48,8 @@ commander
5048
.description('Force intelligent commit messages.')
5149
.action(function () {
5250
popMastarmFromArgv()
53-
5451
const path = require('path')
5552
const bootstrap = require('commitizen/dist/cli/git-cz').bootstrap
56-
5753
bootstrap({
5854
cliPath: path.join(__dirname, '../node_modules/commitizen'),
5955
config: {
@@ -64,17 +60,15 @@ commander
6460

6561
commander
6662
.command('deploy [entries...]')
67-
.usage('[entries...] [options]')
6863
.description('Bundle & Deploy JavaScript & CSS')
6964
.option('--cloudfront', 'CloudFront Distribution ID to invalidate.')
7065
.option('--s3bucket', 'S3 Bucket to push to.')
7166
.action(function (entries, options) {
67+
checkDependencies()
7268
const pushToS3 = require('../lib/push-to-s3')
73-
7469
const config = loadConfig(process.cwd(), commander.config, commander.env)
7570
const get = (item) => val([options, commander, config.settings], item)
7671
const files = parseEntries(entries, get)
77-
7872
files.map(pushToS3({
7973
cloudfront: get('cloudfront'),
8074
config,
@@ -90,31 +84,43 @@ commander
9084
.action(function () {
9185
const engine = require('standard-engine')
9286
const standard = require('standard')
93-
9487
// get lint out of there
9588
process.argv.pop()
9689
// Force verbose
9790
process.argv.push('--verbose')
98-
9991
engine.cli(Object.assign({}, standard, {
10092
cwd: process.cwd(),
10193
homepage: 'https://github.com/conveyal/mastarm'
10294
}))
10395
})
10496

97+
const BABEL = path.join(__dirname, '../node_modules/.bin/babel')
98+
commander
99+
.command('prepublish [entries...]')
100+
.description('Transpile JavaScript down to ES5 with Babel')
101+
.action(function (entries, options) {
102+
checkDependencies()
103+
const exec = require('child_process').execSync
104+
entries.forEach((entry) =>
105+
exec(`${BABEL} ${entry} --out-dir build --source-maps`))
106+
})
107+
105108
commander.parse(process.argv)
106109

107-
if (!commander.skipCheckDependencies) {
108-
const results = checkDependencies.sync({
109-
install: true,
110-
packageDir: process.cwd()
111-
})
112-
if (results.status !== 0) {
113-
console.error(results.error)
114-
process.exit(results.status)
115-
} else if (!results.depsWereOk) {
116-
console.log('Updated out of date dependencies found in package.json. Please try running the command again.')
117-
process.exit(results.status)
110+
function checkDependencies () {
111+
if (!commander.skipCheckDependencies) {
112+
const checkDependenciesSync = require('check-dependencies').sync
113+
const results = checkDependenciesSync({
114+
install: true,
115+
packageDir: process.cwd()
116+
})
117+
if (results.status !== 0) {
118+
console.error(results.error)
119+
process.exit(results.status)
120+
} else if (!results.depsWereOk) {
121+
console.log('Updated out of date dependencies found in package.json. Please try running the command again.')
122+
process.exit(results.status)
123+
}
118124
}
119125
}
120126

0 commit comments

Comments
 (0)