Skip to content

Commit fcd462c

Browse files
committed
Add automatic registration of package if bower.json is located in the repository. Closes AlexKVal#33
1 parent 6eb67a8 commit fcd462c

File tree

2 files changed

+37
-7
lines changed

2 files changed

+37
-7
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
},
4949
"dependencies": {
5050
"colors": "^1.1.2",
51+
"github-url-to-object": "^2.1.0",
5152
"request": "^2.60.0",
5253
"semver": "^5.0.0",
5354
"shelljs": "^0.5.1",

src/release.js

+36-7
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import path from 'path';
77
import semver from 'semver';
88
import yargs from 'yargs';
99
import request from 'request';
10+
import gh from 'github-url-to-object';
1011

1112
// do not die on errors
1213
config.fatal = false;
@@ -15,8 +16,10 @@ config.fatal = false;
1516
// constants
1617
const repoRoot = pwd();
1718
const packagePath = path.join(repoRoot, 'package.json');
19+
const bowerjsonPath = path.join(repoRoot, 'bower.json');
1820

1921
const npmjson = JSON.parse(cat(packagePath));
22+
const bowerjson = test('-f', bowerjsonPath) ? JSON.parse(cat(bowerjsonPath)) : null;
2023
const isPrivate = npmjson.private;
2124
const 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,31 @@ 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+
}
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+
}
403432
}
404433

405434
// documents site

0 commit comments

Comments
 (0)