Skip to content

Commit

Permalink
Handle publishing initial version of scoped package (#258)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyler Boright authored and sindresorhus committed Nov 29, 2018
1 parent 3b0ed9a commit 03871b2
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 3 deletions.
8 changes: 7 additions & 1 deletion cli.js
Expand Up @@ -4,7 +4,9 @@ const logSymbols = require('log-symbols');
const meow = require('meow');
const updateNotifier = require('update-notifier');
const hasYarn = require('has-yarn');
const npmName = require('npm-name');
const version = require('./lib/version');
const util = require('./lib/util');
const ui = require('./lib/ui');
const np = require('.');

Expand Down Expand Up @@ -69,14 +71,18 @@ process.on('SIGINT', () => {
Promise
.resolve()
.then(() => {
const pkg = util.readPkg();
return Promise.all([npmName(pkg.name), pkg]);
})
.then(([available, pkg]) => {
if (cli.input.length > 0) {
return Object.assign({}, cli.flags, {
confirm: true,
version: cli.input[0]
});
}

return ui(cli.flags);
return ui(Object.assign({}, cli.flags, {exists: !available}), pkg);
})
.then(options => {
if (!options.confirm) {
Expand Down
4 changes: 4 additions & 0 deletions index.js
Expand Up @@ -150,6 +150,10 @@ module.exports = (input, opts) => {
args.push('--tag', opts.tag);
}

if (opts.publishScoped) {
args.push('--access', 'public');
}

return exec('yarn', args);
}
},
Expand Down
4 changes: 4 additions & 0 deletions lib/publish.js
Expand Up @@ -20,6 +20,10 @@ const npmPublish = options => {
args.push('--otp', options.otp);
}

if (options.publishScoped) {
args.push('--access', 'public');
}

return execa('npm', args);
};

Expand Down
10 changes: 8 additions & 2 deletions lib/ui.js
Expand Up @@ -3,6 +3,7 @@ const execa = require('execa');
const inquirer = require('inquirer');
const chalk = require('chalk');
const githubUrlFromGit = require('github-url-from-git');
const isScoped = require('is-scoped');
const util = require('./util');
const version = require('./version');

Expand Down Expand Up @@ -58,8 +59,7 @@ function printCommitLog(repositoryUrl) {
});
}

module.exports = options => {
const pkg = util.readPkg();
module.exports = (options, pkg) => {
const oldVersion = pkg.version;
const extraBaseUrls = ['gitlab.com'];
const repositoryUrl = pkg.repository && githubUrlFromGit(pkg.repository.url, {extraBaseUrls});
Expand Down Expand Up @@ -154,6 +154,12 @@ module.exports = options => {

return `Will bump from ${chalk.cyan(oldVersion)} to ${chalk.cyan(answers.version + tagPart)}. Continue?`;
}
},
{
type: 'confirm',
name: 'publishScoped',
when: isScoped(pkg.name) && !options.exists,
message: `This scoped repo ${chalk.bold.magenta(pkg.name)} hasn't been published. Do you want to publish it publicly?`
}
];

Expand Down
2 changes: 2 additions & 0 deletions package.json
Expand Up @@ -36,11 +36,13 @@
"github-url-from-git": "^1.5.0",
"has-yarn": "^1.0.0",
"inquirer": "^5.2.0",
"is-scoped": "^1.0.0",
"issue-regex": "^2.0.0",
"listr": "^0.14.1",
"listr-input": "^0.1.1",
"log-symbols": "^2.1.0",
"meow": "^5.0.0",
"npm-name": "^5.0.0",
"p-timeout": "^2.0.1",
"read-pkg-up": "^3.0.0",
"rxjs": "^6.2.0",
Expand Down

0 comments on commit 03871b2

Please sign in to comment.