@lakutata/cli 2.7.0 → 2.9.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/CHANGELOG.md CHANGED
@@ -3,6 +3,33 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [2.9.0](https://github.com/lakutata/lakutata-packages/compare/@lakutata/cli@2.8.0...@lakutata/cli@2.9.0) (2024-08-03)
7
+
8
+
9
+ ### Features
10
+
11
+ * **cli:** add template selection for project creation ([4835107](https://github.com/lakutata/lakutata-packages/commit/4835107d86bd70738a6508529e9d60efa807c356))
12
+
13
+
14
+
15
+
16
+
17
+ # [2.8.0](https://github.com/lakutata/lakutata-packages/compare/@lakutata/cli@2.7.0...@lakutata/cli@2.8.0) (2024-08-02)
18
+
19
+
20
+ ### Bug Fixes
21
+
22
+ * **cli:** remove commented code in OnlineLatestVersion.ts ([8820c2b](https://github.com/lakutata/lakutata-packages/commit/8820c2bb9fb501f5139b1a8ad0e05d8bdc2ee02c))
23
+
24
+
25
+ ### Features
26
+
27
+ * **creator:** add project information filling ([b230861](https://github.com/lakutata/lakutata-packages/commit/b23086112dce8a5992f3e337c9f96dae8d69d5ec))
28
+
29
+
30
+
31
+
32
+
6
33
  # [2.7.0](https://github.com/lakutata/lakutata-packages/compare/@lakutata/cli@2.6.1...@lakutata/cli@2.7.0) (2024-08-02)
7
34
 
8
35
 
package/dist/CLIApp.js CHANGED
@@ -45,7 +45,7 @@ lakutata_1.Application.run(async () => ({
45
45
  cache: false,
46
46
  verbose: true,
47
47
  force: true,
48
- repo: 'lakutata/lakutata-template'
48
+ baseRepo: 'lakutata/lakutata-template'
49
49
  },
50
50
  spinner: {
51
51
  class: Spinner_1.Spinner,
@@ -3,12 +3,12 @@ export declare class DeGitPuller extends Component {
3
3
  protected readonly cache: boolean;
4
4
  protected readonly verbose: boolean;
5
5
  protected readonly force: boolean;
6
- protected readonly repo: string;
6
+ protected readonly baseRepo: string;
7
7
  /**
8
8
  * get git source
9
- * @param branch
9
+ * @param template
10
10
  */
11
- getGitSource(branch: string): string;
11
+ getGitSource(template: string): string;
12
12
  /**
13
13
  * Exec pull
14
14
  * @param branch
@@ -1 +1 @@
1
- {"version":3,"file":"DeGitPuller.d.ts","sourceRoot":"","sources":["../../../src/lib/components/DeGitPuller.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,SAAS,EAAM,MAAM,UAAU,CAAA;AAGvC,qBACa,WAAY,SAAQ,SAAS;IAGtC,SAAS,CAAC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAQ;IAGzC,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAO;IAG1C,SAAS,CAAC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAO;IAGxC,SAAS,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IAE/B;;;OAGG;IACI,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM;IAI3C;;;;OAIG;IACU,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAOxE"}
1
+ {"version":3,"file":"DeGitPuller.d.ts","sourceRoot":"","sources":["../../../src/lib/components/DeGitPuller.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,SAAS,EAAM,MAAM,UAAU,CAAA;AAGvC,qBACa,WAAY,SAAQ,SAAS;IAGtC,SAAS,CAAC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAQ;IAGzC,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAO;IAG1C,SAAS,CAAC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAO;IAGxC,SAAS,CAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IAEnC;;;OAGG;IACI,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM;IAI7C;;;;OAIG;IACU,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAOxE"}
@@ -25,10 +25,10 @@ let DeGitPuller = class DeGitPuller extends lakutata_1.Component {
25
25
  }
26
26
  /**
27
27
  * get git source
28
- * @param branch
28
+ * @param template
29
29
  */
30
- getGitSource(branch) {
31
- return `${this.repo}#${branch}`;
30
+ getGitSource(template) {
31
+ return `${this.baseRepo}-${template}`;
32
32
  }
33
33
  /**
34
34
  * Exec pull
@@ -59,7 +59,7 @@ __decorate([
59
59
  __decorate([
60
60
  (0, di_1.Configurable)(lakutata_1.DTO.String().required()),
61
61
  __metadata("design:type", String)
62
- ], DeGitPuller.prototype, "repo", void 0);
62
+ ], DeGitPuller.prototype, "baseRepo", void 0);
63
63
  exports.DeGitPuller = DeGitPuller = __decorate([
64
64
  (0, di_1.Singleton)()
65
65
  ], DeGitPuller);
@@ -31,6 +31,11 @@ export declare class Creator extends Provider {
31
31
  * @protected
32
32
  */
33
33
  protected checkTargetDirectoryIsEmpty(targetDirectory: string): Promise<void>;
34
+ /**
35
+ * project information filling
36
+ * @protected
37
+ */
38
+ protected projectInformationFilling(targetPath: string, fields: Record<string, string>): Promise<void>;
34
39
  /**
35
40
  * Exec create
36
41
  * @param options
@@ -1 +1 @@
1
- {"version":3,"file":"Creator.d.ts","sourceRoot":"","sources":["../../../src/lib/providers/Creator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,WAAW,EAAC,MAAM,kBAAkB,CAAA;AAC5C,OAAO,EAAC,WAAW,EAAC,MAAM,8BAA8B,CAAA;AACxD,OAAO,EAAC,OAAO,EAAC,MAAM,0BAA0B,CAAA;AAChD,OAAO,EAAC,oBAAoB,EAAC,MAAM,uCAAuC,CAAA;AAM1E,OAAO,EAAC,WAAW,EAAE,QAAQ,EAAC,MAAM,UAAU,CAAA;AAE9C,OAAO,EAAC,MAAM,EAAC,MAAM,qBAAqB,CAAA;AAK1C,OAAO,EAA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,CAAA;AAEzD,qBAAa,OAAQ,SAAQ,QAAQ;IAGjC,SAAS,CAAC,QAAQ,CAAC,GAAG,EAAE,WAAW,CAAA;IAGnC,SAAS,CAAC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;IAG9B,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAA;IAGnC,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAA;IAGtC,SAAS,CAAC,QAAQ,CAAC,aAAa,EAAE,WAAW,CAAA;IAG7C,SAAS,CAAC,QAAQ,CAAC,aAAa,EAAE,mBAAmB,CAAA;IAErD;;;;;OAKG;cACa,wBAAwB,CAAC,eAAe,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAUnG;;;;OAIG;cACa,0BAA0B,CAAC,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IASlF;;;;OAIG;cACa,2BAA2B,CAAC,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IASnF;;;OAGG;cACa,yBAAyB,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAW5G;;;OAGG;IAEU,MAAM,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC;CAyDpE"}
@@ -17,7 +17,6 @@ const Information_js_1 = require("./Information.js");
17
17
  const DeGitPuller_js_1 = require("../components/DeGitPuller.js");
18
18
  const Spinner_js_1 = require("../components/Spinner.js");
19
19
  const CreateProjectOptions_js_1 = require("../../options/CreateProjectOptions.js");
20
- const ProjectTypeConfig_js_1 = require("../ProjectTypeConfig.js");
21
20
  const node_path_1 = __importDefault(require("node:path"));
22
21
  const promises_1 = require("node:fs/promises");
23
22
  const SpecialChar_js_1 = require("../SpecialChar.js");
@@ -71,6 +70,22 @@ class Creator extends lakutata_1.Provider {
71
70
  }
72
71
  this.log.info(`${SpecialChar_js_1.charCheck} The target directory is empty.`);
73
72
  }
73
+ /**
74
+ * project information filling
75
+ * @protected
76
+ */
77
+ async projectInformationFilling(targetPath, fields) {
78
+ const items = await (0, helper_1.Glob)(node_path_1.default.resolve(targetPath, '**/*'));
79
+ for (const item of items) {
80
+ const stats = await (0, promises_1.stat)(item);
81
+ if (!stats.isFile())
82
+ continue;
83
+ const rawContent = await (0, promises_1.readFile)(item, { encoding: 'utf-8' });
84
+ const filledContent = (0, helper_1.Templating)(rawContent, fields, { ignoreMissing: true });
85
+ if (rawContent !== filledContent)
86
+ await (0, promises_1.writeFile)(item, filledContent, { flag: 'w' });
87
+ }
88
+ }
74
89
  /**
75
90
  * Exec create
76
91
  * @param options
@@ -79,14 +94,12 @@ class Creator extends lakutata_1.Provider {
79
94
  const appName = options.name;
80
95
  const appId = options.id;
81
96
  const appDescription = options.description;
82
- // const packageName: string = appId
83
97
  const authorName = options.author;
84
98
  const licenseName = options.license;
85
- const appType = options.type;
99
+ const appTemplate = options.template;
86
100
  const targetPath = options.overwrite ? node_path_1.default.resolve(options.path) : node_path_1.default.resolve(options.path, options.name);
87
- const { branch } = ProjectTypeConfig_js_1.ProjectTypeConfig[appType];
88
101
  const table = new cli_table3_1.default();
89
- table.push([{ content: ansis_1.default.bold.cyan('Project Creation Information'), colSpan: 2, hAlign: 'center' }], [ansis_1.default.blue('APP ID & Project Name'), appId], [ansis_1.default.blue('APP Name'), appName], [ansis_1.default.blue('APP Description'), appDescription], [ansis_1.default.blue('Project Create Target Path'), targetPath], [ansis_1.default.blue('Project Create Mode'), options.overwrite ? ansis_1.default.yellow('Initialize project in an existing directory') : ansis_1.default.green('Create a new folder for the project')], [ansis_1.default.blue('Project Author Name'), authorName], [ansis_1.default.blue('Project License'), licenseName], [ansis_1.default.blue('Project Template Branch'), this.puller.getGitSource(branch)]);
102
+ table.push([{ content: ansis_1.default.bold.cyan('Project Creation Information'), colSpan: 2, hAlign: 'center' }], [ansis_1.default.blue('APP ID & Project Name'), appId], [ansis_1.default.blue('APP Name'), appName], [ansis_1.default.blue('APP Description'), appDescription], [ansis_1.default.blue('Project Create Target Path'), targetPath], [ansis_1.default.blue('Project Create Mode'), options.overwrite ? ansis_1.default.yellow('Initialize project in an existing directory') : ansis_1.default.green('Create a new folder for the project')], [ansis_1.default.blue('Project Author Name'), authorName], [ansis_1.default.blue('Project License'), licenseName], [ansis_1.default.blue('Project Template Branch'), this.puller.getGitSource(appTemplate)]);
90
103
  console.log(table.toString());
91
104
  await new Promise(resolve => {
92
105
  let timeLeft = 15;
@@ -104,11 +117,20 @@ class Creator extends lakutata_1.Provider {
104
117
  await this.checkTargetPathIsDirectory(targetPath);
105
118
  await this.checkTargetDirectoryIsEmpty(targetPath);
106
119
  this.spinner.start('Pulling');
107
- await this.puller.pull(branch, targetPath);
120
+ await this.puller.pull(appTemplate, targetPath);
108
121
  this.spinner.stop();
109
122
  this.log.info(`${SpecialChar_js_1.charCheck} Template pulled.`);
123
+ this.spinner.start('Filling information');
124
+ await this.projectInformationFilling(targetPath, {
125
+ $APP_NAME: appName,
126
+ $APP_ID: appId,
127
+ $APP_DESC: appDescription,
128
+ $APP_AUTHOR: authorName,
129
+ $APP_LICENSE: licenseName
130
+ });
131
+ this.spinner.stop();
132
+ this.log.info(`${SpecialChar_js_1.charCheck} Project information filling completed.`);
110
133
  this.spinner.start('Installing');
111
- //TODO 将项目内的内容进行初始化
112
134
  const { execa } = await import('execa');
113
135
  await execa('npm', ['install'], { cwd: targetPath });
114
136
  await execa('npm', ['install', `${this.onlineVersion.getName()}@${await this.onlineVersion.getVersion()}`], { cwd: targetPath });
@@ -1 +1 @@
1
- {"version":3,"file":"OnlineLatestVersion.d.ts","sourceRoot":"","sources":["../../../src/lib/providers/OnlineLatestVersion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,UAAU,CAAA;AAIjC,qBAAa,mBAAoB,SAAQ,QAAQ;IAG7C,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IAGlC,SAAS,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IAE/B;;OAEG;IACI,OAAO,IAAI,MAAM;IAIxB;;OAEG;IACU,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC;CAc7C"}
1
+ {"version":3,"file":"OnlineLatestVersion.d.ts","sourceRoot":"","sources":["../../../src/lib/providers/OnlineLatestVersion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,UAAU,CAAA;AAIjC,qBAAa,mBAAoB,SAAQ,QAAQ;IAG7C,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IAGlC,SAAS,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IAE/B;;OAEG;IACI,OAAO,IAAI,MAAM;IAIxB;;OAEG;IACU,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC;CAY7C"}
@@ -28,11 +28,9 @@ class OnlineLatestVersion extends lakutata_1.Provider {
28
28
  const prereleaseInfo = (0, semver_1.prerelease)(this.version);
29
29
  const latestVersionPackage = await import('latest-version');
30
30
  if (prereleaseInfo && prereleaseInfo[0]) {
31
- // onlineLatestVersion = await require('latest-version').default(this.name, {version: prereleaseInfo[0].toString()})
32
31
  onlineLatestVersion = await latestVersionPackage.default(this.name, { version: prereleaseInfo[0].toString() });
33
32
  }
34
33
  else {
35
- // onlineLatestVersion = await require('latest-version').default(this.name)
36
34
  onlineLatestVersion = await latestVersionPackage.default(this.name);
37
35
  }
38
36
  return (0, semver_1.gt)(onlineLatestVersion, this.version) ? onlineLatestVersion : this.version;
@@ -5,7 +5,7 @@ import { DTO } from 'lakutata';
5
5
  export declare class CreateProjectOptions extends DTO {
6
6
  name: string;
7
7
  id: string;
8
- type: string;
8
+ template: string;
9
9
  path: string;
10
10
  overwrite: boolean;
11
11
  description: string;
@@ -1 +1 @@
1
- {"version":3,"file":"CreateProjectOptions.d.ts","sourceRoot":"","sources":["../../src/options/CreateProjectOptions.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,GAAG,EAAC,MAAM,UAAU,CAAA;AAG5B;;GAEG;AACH,qBAAa,oBAAqB,SAAQ,GAAG;IASlC,IAAI,EAAE,MAAM,CAAA;IASZ,EAAE,EAAE,MAAM,CAAA;IASV,IAAI,EAAE,MAAM,CAAA;IASZ,IAAI,EAAE,MAAM,CAAA;IAUZ,SAAS,EAAE,OAAO,CAAA;IASlB,WAAW,EAAE,MAAM,CAAA;IASnB,MAAM,EAAE,MAAM,CAAA;IASd,OAAO,EAAE,MAAM,CAAA;CACzB"}
1
+ {"version":3,"file":"CreateProjectOptions.d.ts","sourceRoot":"","sources":["../../src/options/CreateProjectOptions.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,GAAG,EAAC,MAAM,UAAU,CAAA;AAG5B;;GAEG;AACH,qBAAa,oBAAqB,SAAQ,GAAG;IASlC,IAAI,EAAE,MAAM,CAAA;IASZ,EAAE,EAAE,MAAM,CAAA;IAQV,QAAQ,EAAE,MAAM,CAAA;IAShB,IAAI,EAAE,MAAM,CAAA;IAUZ,SAAS,EAAE,OAAO,CAAA;IASlB,WAAW,EAAE,MAAM,CAAA;IASnB,MAAM,EAAE,MAAM,CAAA;IASd,OAAO,EAAE,MAAM,CAAA;CACzB"}
@@ -10,7 +10,6 @@ var __metadata = (this && this.__metadata) || function (k, v) {
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.CreateProjectOptions = void 0;
13
- const ProjectTypeConfig_1 = require("../lib/ProjectTypeConfig");
14
13
  const lakutata_1 = require("lakutata");
15
14
  const dto_1 = require("lakutata/decorator/dto");
16
15
  /**
@@ -39,10 +38,9 @@ __decorate([
39
38
  (0, dto_1.Expect)(lakutata_1.DTO
40
39
  .String()
41
40
  .required()
42
- .valid(...Object.keys(ProjectTypeConfig_1.ProjectTypeConfig))
43
- .description(`select the type of the project (choices: ${Object.keys(ProjectTypeConfig_1.ProjectTypeConfig).map((type) => `"${type}"`).join(',')})`)),
41
+ .description('choose a template for this project')),
44
42
  __metadata("design:type", String)
45
- ], CreateProjectOptions.prototype, "type", void 0);
43
+ ], CreateProjectOptions.prototype, "template", void 0);
46
44
  __decorate([
47
45
  (0, dto_1.Expect)(lakutata_1.DTO
48
46
  .String()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lakutata/cli",
3
- "version": "2.7.0",
3
+ "version": "2.9.0",
4
4
  "description": "Lakutata CLI tool",
5
5
  "keywords": [
6
6
  "lakutata",
@@ -46,5 +46,5 @@
46
46
  "devDependencies": {
47
47
  "@types/degit": "^2.8.6"
48
48
  },
49
- "gitHead": "ae8c48953f4a2f7387bd52122a982e3dd417fe3e"
49
+ "gitHead": "3b365ebc61075aa8983aa47365b95ff72d8442be"
50
50
  }