UNPKG

create-node-template

Version:

Create node.js or express boilerplate with one command

79 lines 2.47 kB
import prompts from 'prompts'; import path from 'path'; import { validateNpmName } from './validate-pkg.js'; import { onPromptState } from './misc.js'; import { bold, red } from '../../../utils/index.js'; import { supportedPMs, supportedTemplates } from '../../../config/index.js'; /* * */ export const getProjectName = async (arg1) => { let projectName = arg1; if (!projectName) { const res = await prompts({ onState: onPromptState, type: 'text', name: 'name', message: 'What is your project named?', initial: 'my-app', validate: (name) => { const validation = validateNpmName(path.basename(path.resolve(name))); if (validation.valid) { return true; } console.error('Invalid project name. Issue(s): '); validation.problems.forEach(p => console.error(`- ${p}\n`)); validation.problems.forEach(p => console.error(` ${red(bold('*'))} ${p}`)); process.exit(1); }, }); if (typeof res.name === 'string') { projectName = res.name.trim(); } } return projectName; }; /* * */ export const getPackageManager = async (pm) => { if (supportedPMs.includes(pm)) { return pm; } const { packageManager } = await prompts({ onState: onPromptState, type: 'select', name: 'packageManager', message: 'Which package manager do you want to use?', choices: [ { title: 'npm', value: 'npm' }, { title: 'yarn', value: 'yarn' }, { title: 'pnpm', value: 'pnpm' }, { title: 'bun', value: 'bun' }, ], /* No need for validation */ }); return packageManager; }; /* * */ export const getTemplate = async (temp) => { if (supportedTemplates.includes(temp)) { return temp; } const { template } = await prompts({ onState: onPromptState, type: 'select', name: 'template', message: 'Which template do you want to use?', choices: [ { title: 'node-basic', value: 'node-basic' }, { title: 'express-basic', value: 'express-basic' }, { title: 'express-advanced', value: 'express-advanced' }, ], /* No need for validation */ }); return template; }; //# sourceMappingURL=prompts.js.map