fix(cli): new command without npm scope

This commit is contained in:
LongYinan 2021-02-06 14:10:17 +08:00
parent 237fda55aa
commit 5ef1887ea9
No known key found for this signature in database
GPG key ID: C3666B7FC82ADAD7

View file

@ -71,7 +71,8 @@ export class NewProjectCommand extends Command {
async execute() { async execute() {
await this.getName() await this.getName()
if (!this.dirname) { if (!this.dirname) {
const [, defaultProjectDir] = this.name?.split('/') ?? [] const [scope, name] = this.name?.split('/') ?? []
const defaultProjectDir = name ?? scope
const dirAnswer = await prompt({ const dirAnswer = await prompt({
type: 'input', type: 'input',
name: DIR_PROMOTE_NAME, name: DIR_PROMOTE_NAME,
@ -118,7 +119,8 @@ export class NewProjectCommand extends Command {
mkdirSync(join(process.cwd(), this.dirname!, 'src')) mkdirSync(join(process.cwd(), this.dirname!, 'src'))
} }
const [, binaryName] = this.name!.split('/') const [s, pkgName] = this.name!.split('/')
const binaryName = pkgName ?? s
this.writeFile('Cargo.toml', createCargoContent(this.name!)) this.writeFile('Cargo.toml', createCargoContent(this.name!))
this.writeFile('.npmignore', NPMIgnoreFiles) this.writeFile('.npmignore', NPMIgnoreFiles)