-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
40 changed files
with
518 additions
and
1,062 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export { default as updateCommand } from './update.cmd'; | ||
export { default as createCommand } from './create.cmd'; | ||
export { default as pluginCommand } from './plugin.cmd'; | ||
export { default as pullCommand } from './pull.cmd'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { Command } from 'commander'; | ||
import { input, select } from '@inquirer/prompts'; | ||
import { join, dirname } from 'path'; | ||
import { isFileOrFolderExists } from '@compass-aiden/helpers/cjs'; | ||
import { SELECT_TEMPLATE } from '@/constants'; | ||
import { Logger, pullUtilsTemplate } from '@/utils'; | ||
|
||
export default (program: Command) => { | ||
program | ||
.command('pull') | ||
.description('通过拉取模板来创建项目') | ||
.option('-N, --name [name]', '项目路径, 如: new-project, ./temp/new-project') | ||
.option('-T, --template-type [tempType]', '需要拉取的模板类型\n\t\t\t\t\t- utils\tUtils实用程序工具库模板') | ||
.action(async (options) => { | ||
const tempType = | ||
options.templateType || | ||
(await select({ | ||
message: '请选择要拉取的模板类型', | ||
choices: SELECT_TEMPLATE, | ||
})); | ||
const tempConfig = SELECT_TEMPLATE.find((item) => item.value === tempType); | ||
if (!tempConfig) { | ||
throw new Error('Not found template'); | ||
} | ||
|
||
let projectPath = | ||
options.name || | ||
(await input({ | ||
message: '请输入项目路径', | ||
default: './new-project', | ||
})); | ||
|
||
projectPath = projectPath.startsWith('/') ? projectPath : join(process.cwd(), projectPath); | ||
const projectName = projectPath.replace(join(dirname(projectPath), './'), ''); | ||
|
||
if (isFileOrFolderExists(projectPath)) { | ||
Logger.error('❌ 目标路径已经存在'); | ||
return; | ||
} | ||
|
||
if (tempType === 'utils') { | ||
await pullUtilsTemplate({ | ||
projectPath, | ||
templateData: await tempConfig.getTemplateVars({ | ||
projectName, | ||
}), | ||
}); | ||
return; | ||
} | ||
|
||
Logger.error('❌ 暂不支持的模板类型'); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { input, confirm } from '@inquirer/prompts'; | ||
|
||
/* eslint-disable import/prefer-default-export */ | ||
export const SELECT_TEMPLATE = [ | ||
{ | ||
name: '自定义模板', | ||
value: 'custom', | ||
getTemplateVars: async (options?: any) => options || {}, | ||
}, | ||
{ | ||
name: 'Utils 实用程序工具库模板', | ||
value: 'utils', | ||
getTemplateVars: async (options?: any) => { | ||
const result = { | ||
projectName: await input({ | ||
message: '请输入项目名称', | ||
default: options.projectName, | ||
}), | ||
projectDescription: | ||
options?.projectDescription || | ||
(await input({ | ||
message: '请输入项目描述', | ||
})), | ||
enabledEslint: | ||
options?.enabledEslint || | ||
(await confirm({ | ||
message: '是否启用 eslint 代码检查插件', | ||
default: true, | ||
})), | ||
enabledPrettier: | ||
options?.enabledEslint || | ||
(await confirm({ | ||
message: '是否启用 prettier 代码格式化插件', | ||
default: true, | ||
})), | ||
enabledJest: | ||
options?.enabledJest || | ||
(await confirm({ | ||
message: '是否启用 jest 单测插件', | ||
default: true, | ||
})), | ||
enabledTypedoc: | ||
options?.enabledTypedoc || | ||
(await confirm({ | ||
message: '是否启用 typedoc 生成文档', | ||
default: true, | ||
})), | ||
enabledPrettyQuick: | ||
options?.enabledPrettyQuick || | ||
(await confirm({ | ||
message: '是否启用 pretty-quick 插件,代码提交前快速格式化变更文件.依赖enabledGithooks开启', | ||
default: true, | ||
})), | ||
enabledCommitlint: | ||
options?.enabledPrettyQuick || | ||
(await confirm({ | ||
message: '是否启用 commitlint 插件,代码提交前对提交信息进行校验.依赖enabledGithooks开启', | ||
default: true, | ||
})), | ||
enabledGithooks: false, | ||
}; | ||
|
||
return { | ||
...result, | ||
enabledGithooks: result.enabledPrettyQuick || result.enabledCommitlint || false, | ||
}; | ||
}, | ||
}, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.