in src/commands/init/index.ts [38:100]
describe: t('init_config_file').d(
'Generate a config file for your project'
),
type: 'boolean'
});
},
handler: async (argv: ArgumentsCamelCase) => {
await handleInit(argv);
}
};
export default init;
export async function handleInit(argv: ArgumentsCamelCase) {
const { config } = argv;
// // 更新npm包
// const __dirname = getDirName(import.meta.url);
// const projectPath = path.join(__dirname, '../../..');
// execSync('npm install', { stdio: 'ignore', cwd: projectPath });
if (config !== undefined) {
await generateConfigFile(String(config));
return;
}
const name = await descriptionInput(
`🖊️ ${t('init_input_name').d('Enter the name of edgeRoutine:')}`,
true
);
const regex = /^[a-z0-9-]{2,}$/;
if (!regex.test(name)) {
logger.error(
t('init_name_error').d(
'Error: The project name must be at least 2 characters long and can only contain lowercase letters, numbers, and hyphens.'
)
);
return;
}
const templatePaths = fs.readdirSync(templateHubPath).filter((item) => {
const itemPath = path.join(templateHubPath, item);
const stats = fs.statSync(itemPath);
return (
stats.isDirectory() &&
item !== '.git' &&
item !== 'node_modules' &&
item !== 'lib'
);
});
const templateList = templatePaths.map((item) => {
const projectPath = templateHubPath + '/' + item;
const projectConfig = getProjectConfig(projectPath);
const templateName = projectConfig?.name ?? '';
return new Template(projectPath, templateName);
});
const templateConfig = getTemplatesConfig();
const firstSetOfItems = templateConfig
.map((template) => {
const name = template.Title_EN;
const templatePath = templateList.find((item) => {