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, gitIgnore,
npmIgnore, npmIgnore,
} from './templates/index.js' } from './templates/index.js'
import { WasiTargetName } from './templates/ci-template.js'
const debug = debugFactory('new') const debug = debugFactory('new')
@ -211,6 +212,9 @@ function generateGithubWorkflow(options: NewOptions): Output | null {
content: createGithubActionsCIYml( content: createGithubActionsCIYml(
options.targets, options.targets,
options.packageManager as SupportedPackageManager, 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 = ( export const YAML = (
packageManager: SupportedPackageManager, packageManager: SupportedPackageManager,
wasiTargetName?: WasiTargetName, wasiTargetName: WasiTargetName,
) => ` ) => `
name: CI name: CI
@ -100,8 +100,6 @@ jobs:
sudo apt-get install gcc-s390x-linux-gnu -y sudo apt-get install gcc-s390x-linux-gnu -y
build: ${packageManager} build --platform --target s390x-unknown-linux-gnu build: ${packageManager} build --platform --target s390x-unknown-linux-gnu
- host: ubuntu-latest - host: ubuntu-latest
target: 'wasm32-wasi-preview1-threads'
build: ${packageManager} build --platform --target wasm32-wasi-preview1-threads
target: '${wasiTargetName}' target: '${wasiTargetName}'
build: ${packageManager} build --platform --target ${wasiTargetName} build: ${packageManager} build --platform --target ${wasiTargetName}

View file

@ -22,7 +22,7 @@ const UNIVERSAL_MACOS = 'universal-macOS'
export const createGithubActionsCIYml = ( export const createGithubActionsCIYml = (
targets: string[], targets: string[],
packageManager: SupportedPackageManager, packageManager: SupportedPackageManager,
wasiTargetName?: WasiTargetName, wasiTargetName: WasiTargetName,
) => { ) => {
const allTargets = new Set( const allTargets = new Set(
targets.flatMap((t) => { targets.flatMap((t) => {
@ -129,7 +129,12 @@ export const createGithubActionsCIYml = (
fullTemplate.jobs.publish.needs = requiredSteps fullTemplate.jobs.publish.needs = requiredSteps
return dump(fullTemplate, { try {
lineWidth: 1000, 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) { if (this.interactive) {
const targetPath: string = cmdOptions.path const targetPath: string = cmdOptions.path
? cmdOptions.path ? cmdOptions.path
: await inquirer : await inquirerProjectPath()
.prompt({
type: 'input',
name: 'path',
message: 'Target path to create the project, relative to cwd',
})
.then(({ path }) => path)
cmdOptions.path = targetPath cmdOptions.path = targetPath
return { return {
...cmdOptions, ...cmdOptions,
@ -142,3 +136,18 @@ export class NewCommand extends BaseNewCommand {
return enableGithubActions 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
})
}