@@ -7,6 +7,7 @@ import path from 'path';
7
7
import semver from 'semver' ;
8
8
import yargs from 'yargs' ;
9
9
import request from 'request' ;
10
+ import gh from 'github-url-to-object' ;
10
11
11
12
// do not die on errors
12
13
config . fatal = false ;
@@ -15,8 +16,10 @@ config.fatal = false;
15
16
// constants
16
17
const repoRoot = pwd ( ) ;
17
18
const packagePath = path . join ( repoRoot , 'package.json' ) ;
19
+ const bowerjsonPath = path . join ( repoRoot , 'bower.json' ) ;
18
20
19
21
const npmjson = JSON . parse ( cat ( packagePath ) ) ;
22
+ const bowerjson = test ( '-f' , bowerjsonPath ) ? JSON . parse ( cat ( bowerjsonPath ) ) : null ;
20
23
const isPrivate = npmjson . private ;
21
24
const devDepsNode = npmjson . devDependencies ;
22
25
@@ -140,17 +143,17 @@ function printErrorAndExit(error) {
140
143
exit ( 1 ) ;
141
144
}
142
145
143
- function run ( command ) {
146
+ function run ( command , skipError ) {
144
147
const { code, output } = exec ( command ) ;
145
- if ( code !== 0 ) printErrorAndExit ( output ) ;
148
+ if ( code !== 0 && ! skipError ) printErrorAndExit ( output ) ;
146
149
return output ;
147
150
}
148
151
149
- function safeRun ( command ) {
152
+ function safeRun ( command , skipError ) {
150
153
if ( dryRunMode ) {
151
154
console . log ( `[${ command } ]` . grey , 'DRY RUN' . magenta ) ;
152
155
} else {
153
- return run ( command ) ;
156
+ return run ( command , skipError ) ;
154
157
}
155
158
}
156
159
@@ -320,6 +323,8 @@ function release({ type, preid, npmTagName }) {
320
323
console . log ( 'Tagged: ' . cyan + vVersion . green ) ;
321
324
322
325
if ( ! argv . onlyDocs ) {
326
+ const repo = npmjson . repository . url || npmjson . repository ;
327
+
323
328
// publish to GitHub
324
329
if ( githubToken ) {
325
330
console . log ( `GitHub token found ${ githubToken } ` . green ) ;
@@ -328,7 +333,7 @@ function release({ type, preid, npmTagName }) {
328
333
if ( dryRunMode ) {
329
334
console . log ( `[publishing to GitHub]` . grey , 'DRY RUN' . magenta ) ;
330
335
} else {
331
- const [ githubOwner , githubRepo ] = getOwnerAndRepo ( npmjson . repository . url || npmjson . repository ) ;
336
+ const [ githubOwner , githubRepo ] = getOwnerAndRepo ( repo ) ;
332
337
333
338
request ( {
334
339
uri : `https://api.github.com/repos/${ githubOwner } /${ githubRepo } /releases` ,
@@ -389,8 +394,7 @@ function release({ type, preid, npmTagName }) {
389
394
390
395
console . log ( 'Released: ' . cyan + 'npm package' . green ) ;
391
396
}
392
-
393
- // bower
397
+ // bower (separate repo)
394
398
if ( isPrivate ) {
395
399
console . log ( 'Package is private, skipping bower release' . yellow ) ;
396
400
} else if ( bowerRepo ) {
@@ -400,6 +404,31 @@ function release({ type, preid, npmTagName }) {
400
404
} else {
401
405
console . log ( 'The "bowerRepo" is not set in package.json. Skipping Bower package publishing.' . yellow ) ;
402
406
}
407
+ // bower (register package if bower.json is located in this repo)
408
+ if ( bowerjson ) {
409
+ if ( bowerjson . private ) {
410
+ console . log ( 'Package is private, skipping bower registration' . yellow ) ;
411
+ }
412
+ else if ( ! which ( 'bower' ) ) {
413
+ console . log ( 'Bower is not installed globally, skipping bower registration' . yellow ) ;
414
+ }
415
+ else {
416
+ console . log ( 'Registering: ' . cyan + 'bower package' . green ) ;
417
+
418
+ const output = safeRun ( `bower register ${ bowerjson . name } ${ gh ( repo ) . clone_url } ` , true ) ;
419
+
420
+ if ( output . indexOf ( 'EDUPLICATE' ) > - 1 ) {
421
+ console . log ( 'Package already registered' . yellow ) ;
422
+ }
423
+ else if ( output . indexOf ( 'registered successfully' ) < 0 ) {
424
+ console . log ( 'Error registering package, details:' . red ) ;
425
+ console . log ( output . red ) ;
426
+ }
427
+ else {
428
+ console . log ( 'Registered: ' . cyan + 'bower package' . green ) ;
429
+ }
430
+ }
431
+ }
403
432
}
404
433
405
434
// documents site
0 commit comments