fix(cli): new project issue (#2058)

This commit is contained in:
LongYinan 2024-04-19 16:43:29 +08:00 committed by GitHub
parent 4ccbb61179
commit 10602fb76f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 30 additions and 14 deletions

View file

@ -28,6 +28,7 @@ import {
gitIgnore,
npmIgnore,
} from './templates/index.js'
import { WasiTargetName } from './templates/ci-template.js'
const debug = debugFactory('new')
@ -211,6 +212,9 @@ function generateGithubWorkflow(options: NewOptions): Output | null {
content: createGithubActionsCIYml(
options.targets,
options.packageManager as SupportedPackageManager,
(options.targets.find((t) =>
t.includes('wasm32-wasi'),
) as WasiTargetName) ?? 'wasm32-wasi-preview1-threads',
),
}
}

View file

@ -7,7 +7,7 @@ export type WasiTargetName =
export const YAML = (
packageManager: SupportedPackageManager,
wasiTargetName?: WasiTargetName,
wasiTargetName: WasiTargetName,
) => `
name: CI
@ -100,8 +100,6 @@ jobs:
sudo apt-get install gcc-s390x-linux-gnu -y
build: ${packageManager} build --platform --target s390x-unknown-linux-gnu
- host: ubuntu-latest
target: 'wasm32-wasi-preview1-threads'
build: ${packageManager} build --platform --target wasm32-wasi-preview1-threads
target: '${wasiTargetName}'
build: ${packageManager} build --platform --target ${wasiTargetName}

View file

@ -22,7 +22,7 @@ const UNIVERSAL_MACOS = 'universal-macOS'
export const createGithubActionsCIYml = (
targets: string[],
packageManager: SupportedPackageManager,
wasiTargetName?: WasiTargetName,
wasiTargetName: WasiTargetName,
) => {
const allTargets = new Set(
targets.flatMap((t) => {
@ -129,7 +129,12 @@ export const createGithubActionsCIYml = (
fullTemplate.jobs.publish.needs = requiredSteps
return dump(fullTemplate, {
lineWidth: 1000,
})
try {
return dump(fullTemplate, {
lineWidth: 1000,
})
} catch (err) {
console.info(fullTemplate)
throw err
}
}

View file

@ -39,13 +39,7 @@ export class NewCommand extends BaseNewCommand {
if (this.interactive) {
const targetPath: string = cmdOptions.path
? cmdOptions.path
: await inquirer
.prompt({
type: 'input',
name: 'path',
message: 'Target path to create the project, relative to cwd',
})
.then(({ path }) => path)
: await inquirerProjectPath()
cmdOptions.path = targetPath
return {
...cmdOptions,
@ -142,3 +136,18 @@ export class NewCommand extends BaseNewCommand {
return enableGithubActions
}
}
async function inquirerProjectPath(): Promise<string> {
return inquirer
.prompt({
type: 'input',
name: 'path',
message: 'Target path to create the project, relative to cwd.',
})
.then(({ path }) => {
if (!path) {
return inquirerProjectPath()
}
return path
})
}