cmyr-template-cli 1.10.2 → 1.12.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
@@ -13,7 +13,7 @@ var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
13
13
 
14
14
  const program = new commander.Command('ct')
15
15
  .description('草梅项目创建器');
16
- program.version("1.10.1" , '-v, --version');
16
+ program.version("1.11.0" , '-v, --version');
17
17
  const args = process.argv.slice(2);
18
18
  if (args.length === 0) {
19
19
  args.push('create');
package/dist/plopfile.js CHANGED
@@ -11,6 +11,7 @@ var child_process = require('child_process');
11
11
  var colors = require('colors');
12
12
  var ejs = require('ejs');
13
13
  var core = require('@lint-md/core');
14
+ var JSON5 = require('json5');
14
15
 
15
16
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
16
17
 
@@ -39,6 +40,7 @@ var download__default = /*#__PURE__*/_interopDefaultLegacy(download);
39
40
  var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
40
41
  var colors__default = /*#__PURE__*/_interopDefaultLegacy(colors);
41
42
  var ejs__default = /*#__PURE__*/_interopDefaultLegacy(ejs);
43
+ var JSON5__default = /*#__PURE__*/_interopDefaultLegacy(JSON5);
42
44
 
43
45
  process.env;
44
46
  const PACKAGE_MANAGER = 'pnpm';
@@ -50,7 +52,10 @@ if (!Promise.any) {
50
52
  });
51
53
  }
52
54
  const GITHUB_API_URL = 'https://api.github.com';
53
- const NODEJS_URL = 'https://nodejs.org/zh-cn/download/';
55
+ const NODEJS_URLS = [
56
+ 'https://nodejs.org/zh-cn/download/',
57
+ 'http://nodejs.cn/download/',
58
+ ];
54
59
  const REMOTES = [
55
60
  'https://github.com',
56
61
  'https://hub.fastgit.xyz',
@@ -159,6 +164,7 @@ async function init(projectPath, answers) {
159
164
  await sortProjectJson(projectPath);
160
165
  await initDependabot(projectPath, answers);
161
166
  await initYarn(projectPath, answers);
167
+ await initTsconfig(projectPath);
162
168
  await asyncExec('git add .', {
163
169
  cwd: projectPath,
164
170
  });
@@ -170,6 +176,7 @@ async function init(projectPath, answers) {
170
176
  loading.succeed('依赖安装成功!');
171
177
  }
172
178
  catch (error) {
179
+ console.error(error);
173
180
  loading.fail('依赖安装失败!');
174
181
  process.exit(1);
175
182
  }
@@ -228,6 +235,30 @@ async function initYarn(projectPath, answers) {
228
235
  console.error(error);
229
236
  }
230
237
  }
238
+ async function initTsconfig(projectPath) {
239
+ var _a;
240
+ try {
241
+ const tsconfigPath = path__default["default"].join(projectPath, 'tsconfig.json');
242
+ if (await fs__default["default"].pathExists(tsconfigPath)) {
243
+ const tsconfigStr = await fs__default["default"].readFile(tsconfigPath, 'utf8');
244
+ const tsconfig = JSON5__default["default"].parse(tsconfigStr);
245
+ if ((_a = tsconfig === null || tsconfig === void 0 ? void 0 : tsconfig.compilerOptions) === null || _a === void 0 ? void 0 : _a.importHelpers) {
246
+ const pkg = await getProjectJson(projectPath);
247
+ const pkgData = {
248
+ dependencies: {
249
+ ...pkg.dependencies,
250
+ tslib: `^${await getNpmPackageVersion('tslib')}`,
251
+ },
252
+ };
253
+ const newPkg = Object.assign({}, pkg, pkgData);
254
+ await saveProjectJson(projectPath, newPkg);
255
+ }
256
+ }
257
+ }
258
+ catch (error) {
259
+ console.error(error);
260
+ }
261
+ }
231
262
  async function initProjectJson(projectPath, answers) {
232
263
  const loading = ora__default["default"]('正在初始化 package.json ……').start();
233
264
  try {
@@ -663,10 +694,31 @@ async function getAuthorWebsiteFromGithubAPI(githubUsername) {
663
694
  return '';
664
695
  }
665
696
  }
697
+ async function getFastNodeUrl() {
698
+ const loading = ora__default["default"]('正在选择 Node.js 网址');
699
+ loading.start();
700
+ try {
701
+ const fast = await Promise.any(NODEJS_URLS.map((url) => axios__default["default"]({
702
+ url,
703
+ method: 'HEAD',
704
+ timeout: 15 * 1000,
705
+ })));
706
+ loading.succeed(`成功选择了 Node.js 网址 - ${fast.config.url}`);
707
+ return fast.config.url;
708
+ }
709
+ catch (error) {
710
+ console.error(error);
711
+ loading.fail('选择 Node.js 网址失败!');
712
+ }
713
+ }
666
714
  async function getLtsNodeVersion() {
667
715
  var _a, _b;
668
716
  try {
669
- const html = (await axios__default["default"].get(NODEJS_URL)).data;
717
+ const url = await getFastNodeUrl();
718
+ if (!url) {
719
+ return;
720
+ }
721
+ const html = (await axios__default["default"].get(url)).data;
670
722
  const version = (_a = html.match(/<strong>(.*)<\/strong>/)) === null || _a === void 0 ? void 0 : _a[1];
671
723
  return (_b = version.split('.')) === null || _b === void 0 ? void 0 : _b[0];
672
724
  }
@@ -756,6 +808,7 @@ module.exports = function (plop) {
756
808
  'electron-vue',
757
809
  'nuxt',
758
810
  'uni',
811
+ 'uni-vite2',
759
812
  'react',
760
813
  'react16',
761
814
  'ts',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cmyr-template-cli",
3
- "version": "1.10.2",
3
+ "version": "1.12.0",
4
4
  "description": "草梅友仁自制的项目模板创建器",
5
5
  "author": "CaoMeiYouRen",
6
6
  "license": "MIT",
@@ -32,7 +32,7 @@
32
32
  "build:prod": "npm run build && rimraf temp && cross-env NODE_ENV=production ct create"
33
33
  },
34
34
  "devDependencies": {
35
- "@rollup/plugin-commonjs": "^21.0.0",
35
+ "@rollup/plugin-commonjs": "^22.0.0",
36
36
  "@rollup/plugin-json": "^4.1.0",
37
37
  "@rollup/plugin-node-resolve": "^13.0.5",
38
38
  "@rollup/plugin-replace": "^4.0.0",
@@ -56,26 +56,27 @@
56
56
  "debug": "^4.3.1",
57
57
  "eslint": "^7.14.0",
58
58
  "eslint-config-cmyr": "^1.1.14",
59
- "husky": "^7.0.2",
59
+ "husky": "^8.0.1",
60
60
  "lint-staged": "^12.0.2",
61
61
  "rimraf": "^3.0.2",
62
62
  "rollup": "^2.33.3",
63
63
  "rollup-plugin-terser": "^7.0.2",
64
64
  "semantic-release": "^19.0.2",
65
65
  "ts-node": "^10.2.1",
66
- "ts-node-dev": "^1.0.0",
66
+ "ts-node-dev": "^2.0.0",
67
67
  "typescript": "^4.1.2",
68
68
  "validate-commit-msg": "^2.14.0"
69
69
  },
70
70
  "dependencies": {
71
71
  "@lint-md/core": "^0.2.1",
72
- "axios": "^0.26.0",
72
+ "axios": "^0.27.1",
73
73
  "colors": "^1.4.0",
74
74
  "commander": "^9.0.0",
75
75
  "dayjs": "^1.9.6",
76
76
  "download-git-repo": "^3.0.2",
77
77
  "ejs": "^3.1.6",
78
78
  "fs-extra": "^10.0.0",
79
+ "json5": "^2.2.1",
79
80
  "lodash": "^4.17.20",
80
81
  "minimist": "^1.2.5",
81
82
  "ora": "^5.4.1",