cmyr-template-cli 1.0.1 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -19,7 +19,7 @@ const argv = minimist__default["default"](args);
19
19
  program.option('-d, --debug', 'debug');
20
20
  const create = new commander.Command('create')
21
21
  .description('创建项目')
22
- .action((_source, _destination) => {
22
+ .action(() => {
23
23
  plop.Plop.launch({
24
24
  cwd: argv.cwd,
25
25
  configPath: path__default["default"].resolve(__dirname, './plopfile.js'),
package/dist/plopfile.js CHANGED
@@ -15,8 +15,8 @@ var ora__default = /*#__PURE__*/_interopDefaultLegacy(ora);
15
15
  var download__default = /*#__PURE__*/_interopDefaultLegacy(download);
16
16
 
17
17
  const env = process.env;
18
- env.NODE_ENV;
19
18
  const __DEV__ = env.NODE_ENV === 'development';
19
+ const PACKAGE_MANAGER = 'pnpm';
20
20
 
21
21
  async function downloadGitRepo(repository, destination, options = {}) {
22
22
  const loading = ora__default["default"](`download - ${repository}`);
@@ -46,12 +46,11 @@ async function asyncExec(cmd, options) {
46
46
  }
47
47
  async function init(projectPath, pkgData) {
48
48
  const loading = ora__default["default"]('正在安装依赖……');
49
- loading.start();
50
49
  try {
51
50
  await asyncExec('git --version', {
52
51
  cwd: projectPath,
53
52
  });
54
- await asyncExec('npm -v', {
53
+ await asyncExec(`${PACKAGE_MANAGER} -v`, {
55
54
  cwd: projectPath,
56
55
  });
57
56
  await asyncExec('git init', {
@@ -67,7 +66,8 @@ async function init(projectPath, pkgData) {
67
66
  await asyncExec('git commit -m "chore: init"', {
68
67
  cwd: projectPath,
69
68
  });
70
- await asyncExec('npm i', {
69
+ loading.start();
70
+ await asyncExec(`${PACKAGE_MANAGER} i`, {
71
71
  cwd: projectPath,
72
72
  });
73
73
  await asyncExec('git add .', {
@@ -81,9 +81,13 @@ async function init(projectPath, pkgData) {
81
81
  loading.stop();
82
82
  }
83
83
  }
84
+ async function getGitUserName() {
85
+ const username = (await asyncExec('git config user.name'));
86
+ return username.trim();
87
+ }
84
88
 
85
89
  module.exports = function (plop) {
86
- plop.setActionType('initProject', async (answers, config) => {
90
+ plop.setActionType('initProject', async (answers) => {
87
91
  const name = answers.name;
88
92
  const author = answers.author;
89
93
  const template = answers.template;
@@ -97,55 +101,58 @@ module.exports = function (plop) {
97
101
  });
98
102
  plop.setGenerator('create', {
99
103
  description: '草梅项目创建器',
100
- prompts: [
101
- {
102
- type: 'input',
103
- name: 'name',
104
- message: '请输入项目名称',
105
- validate(input, answers) {
106
- return input.trim().length !== 0;
104
+ async prompts(inquirer) {
105
+ const questions = [
106
+ {
107
+ type: 'input',
108
+ name: 'name',
109
+ message: '请输入项目名称',
110
+ validate(input) {
111
+ return input.trim().length !== 0;
112
+ },
113
+ default: __DEV__ ? 'temp' : '',
114
+ filter: (e) => e.trim(),
107
115
  },
108
- default: __DEV__ ? 'temp' : '',
109
- filter: (e) => e.trim(),
110
- },
111
- {
112
- type: 'input',
113
- name: 'author',
114
- message: '请输入作者名称',
115
- validate(input, answers) {
116
- return input.trim().length !== 0;
116
+ {
117
+ type: 'input',
118
+ name: 'author',
119
+ message: '请输入作者名称',
120
+ validate(input) {
121
+ return input.trim().length !== 0;
122
+ },
123
+ default: __DEV__ ? 'CaoMeiYouRen' : await getGitUserName(),
124
+ filter: (e) => e.trim(),
117
125
  },
118
- default: __DEV__ ? 'CaoMeiYouRen' : '',
119
- filter: (e) => e.trim(),
120
- },
121
- {
122
- type: 'list',
123
- name: 'template',
124
- message: '请选择项目模板',
125
- choices({ projectType }) {
126
- return [
127
- 'vue',
128
- 'vue3',
129
- 'vite2',
130
- 'vite2-vue2',
131
- 'electron-vue',
132
- 'nuxt',
133
- 'uni',
134
- 'react',
135
- 'react16',
136
- 'ts',
137
- 'express',
138
- 'koa2',
139
- 'nest',
140
- 'auto-release',
141
- 'rollup',
142
- 'webpack',
143
- 'github-action',
144
- ].map((e) => `${e}-template`);
126
+ {
127
+ type: 'list',
128
+ name: 'template',
129
+ message: '请选择项目模板',
130
+ choices() {
131
+ return [
132
+ 'vue',
133
+ 'vue3',
134
+ 'vite2',
135
+ 'vite2-vue2',
136
+ 'electron-vue',
137
+ 'nuxt',
138
+ 'uni',
139
+ 'react',
140
+ 'react16',
141
+ 'ts',
142
+ 'express',
143
+ 'koa2',
144
+ 'nest',
145
+ 'auto-release',
146
+ 'rollup',
147
+ 'webpack',
148
+ 'github-action',
149
+ ].map((e) => `${e}-template`);
150
+ },
145
151
  },
146
- },
147
- ],
148
- actions(answers) {
152
+ ];
153
+ return inquirer.prompt(questions);
154
+ },
155
+ actions() {
149
156
  const actions = [];
150
157
  actions.push({
151
158
  type: 'initProject',
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "cmyr-template-cli",
3
- "version": "1.0.1",
3
+ "version": "1.2.0",
4
4
  "description": "草梅友仁自制的项目模板创建器",
5
5
  "author": "CaoMeiYouRen",
6
6
  "license": "MIT",
7
7
  "main": "dist/index.js",
8
+ "type": "commonjs",
8
9
  "files": [
9
10
  "dist"
10
11
  ],
@@ -26,7 +27,8 @@
26
27
  "release": "semantic-release",
27
28
  "commit": "git add . && git cz",
28
29
  "create": "ct create",
29
- "build:dev": "npm run build && rimraf temp && cross-env NODE_ENV=development ct create"
30
+ "build:dev": "npm run build && rimraf temp && cross-env NODE_ENV=development ct create",
31
+ "build:prod": "npm run build && rimraf temp && cross-env NODE_ENV=production ct create"
30
32
  },
31
33
  "devDependencies": {
32
34
  "@rollup/plugin-commonjs": "^21.0.0",
@@ -48,9 +50,9 @@
48
50
  "cz-conventional-changelog": "^3.3.0",
49
51
  "debug": "^4.3.1",
50
52
  "eslint": "^7.14.0",
51
- "eslint-config-cmyr": "^1.0.2",
53
+ "eslint-config-cmyr": "^1.1.13",
52
54
  "husky": "^7.0.2",
53
- "lint-staged": "^11.1.2",
55
+ "lint-staged": "^12.0.2",
54
56
  "lodash": "^4.17.20",
55
57
  "rimraf": "^3.0.2",
56
58
  "rollup": "^2.33.3",
@@ -68,8 +70,8 @@
68
70
  "download-git-repo": "^3.0.2",
69
71
  "fs-extra": "^10.0.0",
70
72
  "minimist": "^1.2.5",
71
- "ora": "^6.0.1",
72
- "plop": "^2.7.4"
73
+ "ora": "^5.4.1",
74
+ "plop": "^2.7.6"
73
75
  },
74
76
  "config": {
75
77
  "commitizen": {