-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(publish): don't go publish flow when private in package.json is true
- Loading branch information
Showing
2 changed files
with
36 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,40 @@ | ||
const execa = require('execa') | ||
const inquirer = require('inquirer') | ||
const { pkgExist, readPkg } = require('./pkg') | ||
|
||
const root = process.cwd() | ||
|
||
async function publish () { | ||
if (await pkgExist()) { | ||
const answer = await inquirer.prompt({ | ||
type: 'confirm', | ||
name: 'npmPublish', | ||
message: 'Publish to npmjs.com ?', | ||
default: false | ||
}) | ||
|
||
if (answer && answer.npmPublish) { | ||
const pkg = readPkg() | ||
let cmd = 'npm publish' | ||
if (pkg.name && pkg.name.startsWith('@')) { | ||
const answerPub = await inquirer.prompt({ | ||
type: 'confirm', | ||
name: 'public', | ||
message: 'This is a scoped package, publish as public ?', | ||
default: true | ||
}) | ||
async function publish (pkg) { | ||
if (!pkg || !pkg.name) { | ||
ctx.logger.error('Invalid package.json') | ||
process.exit() | ||
} | ||
|
||
if (answerPub && answerPub.public) { | ||
cmd += ' --access=public' | ||
} | ||
} | ||
const answer = await inquirer.prompt({ | ||
type: 'confirm', | ||
name: 'npmPublish', | ||
message: 'Publish to npmjs.com ?', | ||
default: false | ||
}) | ||
|
||
await execa.shell(cmd, { | ||
cwd: root | ||
if (answer && answer.npmPublish) { | ||
let cmd = 'npm publish' | ||
if (pkg.name.startsWith('@')) { | ||
const answerPub = await inquirer.prompt({ | ||
type: 'confirm', | ||
name: 'public', | ||
message: 'This is a scoped package, publish as public ?', | ||
default: true | ||
}) | ||
ctx.logger.success('Publish successfully\n') | ||
|
||
if (answerPub && answerPub.public) { | ||
cmd += ' --access=public' | ||
} | ||
} | ||
|
||
await execa.shell(cmd, { | ||
cwd: root | ||
}) | ||
ctx.logger.success('Publish successfully\n') | ||
} | ||
} | ||
module.exports = publish |