mirror of
https://github.com/hanzoai/gui.git
synced 2026-10-25 02:31:41 +00:00
The CommonJS pass rewrites a dynamic import into a require, which cannot take the file URL the ESM path hands it, so the load goes through here.ts and its .cjs sibling. create-gui reads its manifest from the package root at run time, names its relative imports with their extension, and imports opener instead of requiring it. Co-authored-by: Hanzo Dev <[email protected]>
49 lines
1.3 KiB
TypeScript
49 lines
1.3 KiB
TypeScript
import path from 'node:path'
|
|
|
|
import chalk from 'chalk'
|
|
import prompts from 'prompts'
|
|
|
|
import { validateNpmName } from './validateNpmPackage.ts'
|
|
import { packageJson } from '../manifest.ts'
|
|
|
|
export const getProjectName = async (projectPath?: string) => {
|
|
if (typeof projectPath === 'string') {
|
|
projectPath = projectPath.trim()
|
|
}
|
|
|
|
if (!projectPath) {
|
|
const res = await prompts({
|
|
type: 'text',
|
|
name: 'path',
|
|
message: 'Project name:',
|
|
initial: 'myapp',
|
|
validate: (name) => {
|
|
const validation = validateNpmName(path.basename(path.resolve(name)))
|
|
if (validation.valid) {
|
|
return true
|
|
}
|
|
return 'Invalid project name: ' + validation.problems![0]
|
|
},
|
|
})
|
|
|
|
if (typeof res.path === 'string') {
|
|
projectPath = res.path.trim()
|
|
}
|
|
}
|
|
|
|
if (!projectPath) {
|
|
console.info()
|
|
console.info('Please specify the project directory:')
|
|
console.info(
|
|
` ${chalk.cyan(packageJson.name)} ${chalk.green('<project-directory>')}`
|
|
)
|
|
console.info()
|
|
console.info('For example:')
|
|
console.info(` ${chalk.cyan(packageJson.name)} ${chalk.green('my-hanzogui-app')}`)
|
|
console.info()
|
|
console.info(`Run ${chalk.cyan(`${packageJson.name} --help`)} to see all options.`)
|
|
process.exit(1)
|
|
}
|
|
return projectPath
|
|
}
|