1
1
#!/usr/bin/env node
2
2
3
- const checkDependencies = require ( 'check-dependencies' )
4
3
const commander = require ( 'commander' )
5
4
const path = require ( 'path' )
6
5
@@ -9,7 +8,6 @@ const pkg = require('../lib/pkg')
9
8
10
9
commander
11
10
. version ( require ( '../package.json' ) . version )
12
- . usage ( '<cmd> [options]' )
13
11
. option ( '-c, --config <path>' , 'Path to configuration files.' , path . join ( process . cwd ( ) , '/configurations/default' ) )
14
12
. option ( '-e, --env <environment>' , 'Environment to use.' , process . env . NODE_ENV || 'development' )
15
13
. option ( '-m, --minify' , 'Minify built files.' )
@@ -23,10 +21,10 @@ commander
23
21
. option ( '-s, --serve' , 'Serve with budo. Auto-matically rebuilds on changes.' )
24
22
. option ( '-w, --watch' , 'Rebuild on changes with watchify.' )
25
23
. action ( function ( entries , options ) {
24
+ checkDependencies ( )
26
25
const config = loadConfig ( process . cwd ( ) , commander . config , commander . env )
27
26
const get = ( item ) => val ( [ options , commander , config . settings ] , item )
28
27
const files = parseEntries ( entries , get )
29
-
30
28
if ( get ( 'serve' ) ) {
31
29
const budo = require ( '../lib/budo' )
32
30
files . map ( budo ( {
@@ -50,10 +48,8 @@ commander
50
48
. description ( 'Force intelligent commit messages.' )
51
49
. action ( function ( ) {
52
50
popMastarmFromArgv ( )
53
-
54
51
const path = require ( 'path' )
55
52
const bootstrap = require ( 'commitizen/dist/cli/git-cz' ) . bootstrap
56
-
57
53
bootstrap ( {
58
54
cliPath : path . join ( __dirname , '../node_modules/commitizen' ) ,
59
55
config : {
@@ -64,17 +60,15 @@ commander
64
60
65
61
commander
66
62
. command ( 'deploy [entries...]' )
67
- . usage ( '[entries...] [options]' )
68
63
. description ( 'Bundle & Deploy JavaScript & CSS' )
69
64
. option ( '--cloudfront' , 'CloudFront Distribution ID to invalidate.' )
70
65
. option ( '--s3bucket' , 'S3 Bucket to push to.' )
71
66
. action ( function ( entries , options ) {
67
+ checkDependencies ( )
72
68
const pushToS3 = require ( '../lib/push-to-s3' )
73
-
74
69
const config = loadConfig ( process . cwd ( ) , commander . config , commander . env )
75
70
const get = ( item ) => val ( [ options , commander , config . settings ] , item )
76
71
const files = parseEntries ( entries , get )
77
-
78
72
files . map ( pushToS3 ( {
79
73
cloudfront : get ( 'cloudfront' ) ,
80
74
config,
@@ -90,31 +84,43 @@ commander
90
84
. action ( function ( ) {
91
85
const engine = require ( 'standard-engine' )
92
86
const standard = require ( 'standard' )
93
-
94
87
// get lint out of there
95
88
process . argv . pop ( )
96
89
// Force verbose
97
90
process . argv . push ( '--verbose' )
98
-
99
91
engine . cli ( Object . assign ( { } , standard , {
100
92
cwd : process . cwd ( ) ,
101
93
homepage : 'https://github.com/conveyal/mastarm'
102
94
} ) )
103
95
} )
104
96
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
+
105
108
commander . parse ( process . argv )
106
109
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
+ }
118
124
}
119
125
}
120
126
0 commit comments