create-palladium
Version:
A modern CLI tool to create Vite + React + TypeScript projects with various configurations
47 lines (46 loc) • 1.67 kB
JavaScript
export function validateProjectName(name) {
const errors = [];
if (!name || name.trim().length === 0) {
errors.push('프로젝트 이름은 필수입니다.');
}
if (name.length > 50) {
errors.push('프로젝트 이름은 50자 이하여야 합니다.');
}
// npm 패키지 이름 규칙 검증
const npmNameRegex = /^[a-z0-9][a-z0-9-]*[a-z0-9]$/;
if (!npmNameRegex.test(name)) {
errors.push('프로젝트 이름은 소문자, 숫자, 하이픈만 사용 가능하며, 하이픈으로 시작하거나 끝날 수 없습니다.');
}
// 예약어 검증
const reservedWords = ['node_modules', 'package', 'package.json', 'npm', 'yarn', 'pnpm'];
if (reservedWords.includes(name.toLowerCase())) {
errors.push(`${name}은 예약어이므로 사용할 수 없습니다.`);
}
return {
isValid: errors.length === 0,
errors
};
}
export function validateAnswers(answers) {
const errors = [];
// 프로젝트 이름 검증
const nameValidation = validateProjectName(answers.projectName);
if (!nameValidation.isValid) {
errors.push(...nameValidation.errors);
}
// 상태 관리 라이브러리 검증
if (answers.stateLibrary === 'redux' && !answers.useRouter) {
errors.push('Redux를 사용할 때는 React Router를 함께 사용하는 것을 권장합니다.');
}
return {
isValid: errors.length === 0,
errors
};
}
export function sanitizeProjectName(name) {
return name
.toLowerCase()
.replace(/[^a-z0-9-]/g, '-')
.replace(/-+/g, '-')
.replace(/^-|-$/g, '');
}