Skip to content

Commit

Permalink
feat: 新增 git config user.name 作为 作者名称 默认值
Browse files Browse the repository at this point in the history
  • Loading branch information
CaoMeiYouRen committed Dec 3, 2021
1 parent e9b8392 commit 6507073
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 99 deletions.
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"release": "semantic-release",
"commit": "git add . && git cz",
"create": "ct create",
"build:dev": "npm run build && rimraf temp && cross-env NODE_ENV=development ct create"
"build:dev": "npm run build && rimraf temp && cross-env NODE_ENV=development ct create",
"build:prod": "npm run build && rimraf temp && cross-env NODE_ENV=production ct create"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^21.0.0",
Expand All @@ -48,7 +49,7 @@
"cz-conventional-changelog": "^3.3.0",
"debug": "^4.3.1",
"eslint": "^7.14.0",
"eslint-config-cmyr": "^1.0.2",
"eslint-config-cmyr": "^1.1.13",
"husky": "^7.0.2",
"lint-staged": "^11.1.2",
"lodash": "^4.17.20",
Expand Down Expand Up @@ -79,4 +80,4 @@
"changelog": {
"language": "zh"
}
}
}
10 changes: 7 additions & 3 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,15 @@ function getPlugins({ isBrowser = false, isMin = false, isDeclaration = false })
)
plugins.push(
typescript({
tsconfig: isDeclaration ? 'tsconfig.json' : 'tsconfig.build.json',
tsconfig: 'tsconfig.json',
module: 'esnext',
target: 'es2019', // node >= 12
esModuleInterop: true,
allowSyntheticDefaultImports: true,
module: 'esnext',
target: 'esnext',
declaration: isDeclaration,
sourceMap: false,
importHelpers: false,
removeComments: true,
}),
)
plugins.push(
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ program.option('-d, --debug', 'debug')

const create = new Command('create')
.description('创建项目')
.action((_source, _destination) => {
.action(() => {
Plop.launch({
cwd: argv.cwd,
configPath: path.resolve(__dirname, './plopfile.js'),
Expand Down
102 changes: 53 additions & 49 deletions src/plopfile.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import path from 'path'
import { NodePlopAPI, ActionType } from 'plop'
import { __DEV__ } from './env'
import { downloadGitRepo, init } from './utils'
import { downloadGitRepo, getGitUserName, init } from './utils'

module.exports = function (plop: NodePlopAPI) {
plop.setActionType('initProject', async (answers: any, config) => {
plop.setActionType('initProject', async (answers: any) => {
const name = answers.name as string
const author = answers.author as string
const template = answers.template as string
Expand All @@ -18,56 +18,59 @@ module.exports = function (plop: NodePlopAPI) {
})
plop.setGenerator('create', {
description: '草梅项目创建器',
prompts: [
{
type: 'input',
name: 'name',
message: '请输入项目名称',
validate(input: string, answers) {
return input.trim().length !== 0
async prompts(inquirer) {
const questions = [
{
type: 'input',
name: 'name',
message: '请输入项目名称',
validate(input: string) {
return input.trim().length !== 0
},
default: __DEV__ ? 'temp' : '',
filter: (e: string) => e.trim(),
},
default: __DEV__ ? 'temp' : '',
filter: (e: string) => e.trim(),
},
{
type: 'input',
name: 'author',
message: '请输入作者名称',
validate(input: string, answers) {
return input.trim().length !== 0
{
type: 'input',
name: 'author',
message: '请输入作者名称',
validate(input: string) {
return input.trim().length !== 0
},
default: __DEV__ ? 'CaoMeiYouRen' : await getGitUserName(),
// default: 'CaoMeiYouRen',
filter: (e: string) => e.trim(),
},
default: __DEV__ ? 'CaoMeiYouRen' : '',
// default: 'CaoMeiYouRen',
filter: (e: string) => e.trim(),
},
{
type: 'list',
name: 'template',
message: '请选择项目模板',
choices({ projectType }) {
return [
'vue',
'vue3',
'vite2',
'vite2-vue2',
'electron-vue',
'nuxt',
'uni',
'react',
'react16',
'ts',
'express',
'koa2',
'nest',
'auto-release',
'rollup',
'webpack',
'github-action',
].map((e) => `${e}-template`)
{
type: 'list',
name: 'template',
message: '请选择项目模板',
choices() {
return [
'vue',
'vue3',
'vite2',
'vite2-vue2',
'electron-vue',
'nuxt',
'uni',
'react',
'react16',
'ts',
'express',
'koa2',
'nest',
'auto-release',
'rollup',
'webpack',
'github-action',
].map((e) => `${e}-template`)
},
},
},
],
actions(answers) {
]
return inquirer.prompt(questions)
},
actions() {
const actions: ActionType[] = []
actions.push({
type: 'initProject',
Expand All @@ -76,3 +79,4 @@ module.exports = function (plop: NodePlopAPI) {
},
})
}

12 changes: 12 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,15 @@ export async function init(projectPath: string, pkgData: IPackage) {
}
}

export async function getGitUserName() {
const username = (await asyncExec('git config user.name')) as string
return username.trim()
}

export async function sleep(time: number) {
return new Promise((resolve) => setTimeout(resolve, time))
}

const forEachSetVersion = (dep: Record<string, string>) => {
const promises: Promise<unknown>[] = []
const manager = 'npm'
Expand All @@ -120,6 +129,9 @@ const forEachSetVersion = (dep: Record<string, string>) => {
if (err) {
return reject(err)
}
if (stderr) {
return reject(stderr)
}
dep[key] = `^${stdout.slice(0, stdout.length - 1)}`
resolve(0)
})
Expand Down
42 changes: 0 additions & 42 deletions tsconfig.build.json

This file was deleted.

2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"outDir": "./dist", //重定向输出目录。
"watch": false, //在监视模式下运行编译器。会监视输出文件,在它们改变时重新编译。
"declaration": true, //生成类型文件
"importHelpers": true,
"importHelpers": false,
"strictPropertyInitialization": false,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
Expand Down

0 comments on commit 6507073

Please sign in to comment.