@@ -7,6 +7,7 @@ import path from 'path';
77import semver from 'semver' ;
88import yargs from 'yargs' ;
99import request from 'request' ;
10+ import gh from 'github-url-to-object' ;
1011
1112// do not die on errors
1213config . fatal = false ;
@@ -15,8 +16,10 @@ config.fatal = false;
1516// constants
1617const repoRoot = pwd ( ) ;
1718const packagePath = path . join ( repoRoot , 'package.json' ) ;
19+ const bowerjsonPath = path . join ( repoRoot , 'bower.json' ) ;
1820
1921const npmjson = JSON . parse ( cat ( packagePath ) ) ;
22+ const bowerjson = test ( '-f' , bowerjsonPath ) ? JSON . parse ( cat ( bowerjsonPath ) ) : null ;
2023const isPrivate = npmjson . private ;
2124const devDepsNode = npmjson . devDependencies ;
2225
@@ -140,17 +143,17 @@ function printErrorAndExit(error) {
140143 exit ( 1 ) ;
141144}
142145
143- function run ( command ) {
146+ function run ( command , skipError ) {
144147 const { code, output } = exec ( command ) ;
145- if ( code !== 0 ) printErrorAndExit ( output ) ;
148+ if ( code !== 0 && ! skipError ) printErrorAndExit ( output ) ;
146149 return output ;
147150}
148151
149- function safeRun ( command ) {
152+ function safeRun ( command , skipError ) {
150153 if ( dryRunMode ) {
151154 console . log ( `[${ command } ]` . grey , 'DRY RUN' . magenta ) ;
152155 } else {
153- return run ( command ) ;
156+ return run ( command , skipError ) ;
154157 }
155158}
156159
@@ -320,6 +323,8 @@ function release({ type, preid, npmTagName }) {
320323 console . log ( 'Tagged: ' . cyan + vVersion . green ) ;
321324
322325 if ( ! argv . onlyDocs ) {
326+ const repo = npmjson . repository . url || npmjson . repository ;
327+
323328 // publish to GitHub
324329 if ( githubToken ) {
325330 console . log ( `GitHub token found ${ githubToken } ` . green ) ;
@@ -328,7 +333,7 @@ function release({ type, preid, npmTagName }) {
328333 if ( dryRunMode ) {
329334 console . log ( `[publishing to GitHub]` . grey , 'DRY RUN' . magenta ) ;
330335 } else {
331- const [ githubOwner , githubRepo ] = getOwnerAndRepo ( npmjson . repository . url || npmjson . repository ) ;
336+ const [ githubOwner , githubRepo ] = getOwnerAndRepo ( repo ) ;
332337
333338 request ( {
334339 uri : `https://api.github.com/repos/${ githubOwner } /${ githubRepo } /releases` ,
@@ -389,8 +394,7 @@ function release({ type, preid, npmTagName }) {
389394
390395 console . log ( 'Released: ' . cyan + 'npm package' . green ) ;
391396 }
392-
393- // bower
397+ // bower (separate repo)
394398 if ( isPrivate ) {
395399 console . log ( 'Package is private, skipping bower release' . yellow ) ;
396400 } else if ( bowerRepo ) {
@@ -400,6 +404,27 @@ function release({ type, preid, npmTagName }) {
400404 } else {
401405 console . log ( 'The "bowerRepo" is not set in package.json. Skipping Bower package publishing.' . yellow ) ;
402406 }
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+ } else if ( ! which ( 'bower' ) ) {
412+ console . log ( 'Bower is not installed globally, skipping bower registration' . yellow ) ;
413+ } else {
414+ console . log ( 'Registering: ' . cyan + 'bower package' . green ) ;
415+
416+ const output = safeRun ( `bower register ${ bowerjson . name } ${ gh ( repo ) . clone_url } ` , true ) ;
417+
418+ if ( output . indexOf ( 'EDUPLICATE' ) > - 1 ) {
419+ console . log ( 'Package already registered' . yellow ) ;
420+ } else if ( output . indexOf ( 'registered successfully' ) < 0 ) {
421+ console . log ( 'Error registering package, details:' . red ) ;
422+ console . log ( output . red ) ;
423+ } else {
424+ console . log ( 'Registered: ' . cyan + 'bower package' . green ) ;
425+ }
426+ }
427+ }
403428 }
404429
405430 // documents site
0 commit comments