@lakutata/cli 2.9.0 → 2.11.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 +22 -0
- package/dist/CLIApp.js +16 -1
- package/dist/controllers/CommandLineController.d.ts +8 -0
- package/dist/controllers/CommandLineController.d.ts.map +1 -1
- package/dist/controllers/CommandLineController.js +21 -2
- package/dist/lib/providers/Creator.d.ts.map +1 -1
- package/dist/lib/providers/Creator.js +1 -1
- package/dist/lib/providers/TemplateManager.d.ts +41 -0
- package/dist/lib/providers/TemplateManager.d.ts.map +1 -0
- package/dist/lib/providers/TemplateManager.js +169 -0
- package/dist/options/CreateProjectOptions.d.ts.map +1 -1
- package/dist/options/ListTemplatesOptions.d.ts +5 -0
- package/dist/options/ListTemplatesOptions.d.ts.map +1 -0
- package/dist/options/ListTemplatesOptions.js +26 -0
- package/package.json +4 -2
- package/dist/lib/ProjectTypeConfig.d.ts +0 -8
- package/dist/lib/ProjectTypeConfig.d.ts.map +0 -1
- package/dist/lib/ProjectTypeConfig.js +0 -17
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,28 @@
|
|
|
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.11.0](https://github.com/lakutata/lakutata-packages/compare/@lakutata/cli@2.10.0...@lakutata/cli@2.11.0) (2024-08-03)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* **cli:** add 'templates' command to list available project templates ([c04ba99](https://github.com/lakutata/lakutata-packages/commit/c04ba9923d78623418aeb519c952ed5e0ec7d969))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
# [2.10.0](https://github.com/lakutata/lakutata-packages/compare/@lakutata/cli@2.9.0...@lakutata/cli@2.10.0) (2024-08-03)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Features
|
|
21
|
+
|
|
22
|
+
* **cli:** add 'templates' command to list available project templates ([8e05895](https://github.com/lakutata/lakutata-packages/commit/8e05895a6e44ea471484b1f7d10a74d267e2f8d7))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
6
28
|
# [2.9.0](https://github.com/lakutata/lakutata-packages/compare/@lakutata/cli@2.8.0...@lakutata/cli@2.9.0) (2024-08-03)
|
|
7
29
|
|
|
8
30
|
|
package/dist/CLIApp.js
CHANGED
|
@@ -23,6 +23,9 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
__setModuleDefault(result, mod);
|
|
24
24
|
return result;
|
|
25
25
|
};
|
|
26
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
27
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
28
|
+
};
|
|
26
29
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
30
|
const commander_1 = require("commander");
|
|
28
31
|
const CommandLineController_1 = require("./controllers/CommandLineController");
|
|
@@ -36,7 +39,14 @@ const lakutata_1 = require("lakutata");
|
|
|
36
39
|
const entrypoint_1 = require("lakutata/com/entrypoint");
|
|
37
40
|
const console = __importStar(require("node:console"));
|
|
38
41
|
const OnlineLatestVersion_1 = require("./lib/providers/OnlineLatestVersion");
|
|
39
|
-
|
|
42
|
+
const TemplateManager_1 = require("./lib/providers/TemplateManager");
|
|
43
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
44
|
+
lakutata_1.Application
|
|
45
|
+
.alias({
|
|
46
|
+
'@packageJson': node_path_1.default.resolve(__dirname, '../package.json'),
|
|
47
|
+
'@data': node_path_1.default.resolve(__dirname, '../node_modules/.data')
|
|
48
|
+
}, true)
|
|
49
|
+
.run(async () => ({
|
|
40
50
|
id: 'cli.lakutata.app',
|
|
41
51
|
name: 'Lakutata-CLI',
|
|
42
52
|
components: {
|
|
@@ -95,6 +105,11 @@ lakutata_1.Application.run(async () => ({
|
|
|
95
105
|
class: OnlineLatestVersion_1.OnlineLatestVersion,
|
|
96
106
|
name: package_json_1.name,
|
|
97
107
|
version: package_json_1.version
|
|
108
|
+
},
|
|
109
|
+
templateManager: {
|
|
110
|
+
class: TemplateManager_1.TemplateManager,
|
|
111
|
+
apiHost: 'https://api.github.com',
|
|
112
|
+
repoPrefix: 'lakutata-template'
|
|
98
113
|
}
|
|
99
114
|
},
|
|
100
115
|
bootstrap: ['entrypoint']
|
|
@@ -4,14 +4,22 @@ import { Information } from '../lib/providers/Information';
|
|
|
4
4
|
import { Creator } from '../lib/providers/Creator';
|
|
5
5
|
import { type ActionPattern } from 'lakutata';
|
|
6
6
|
import { Controller } from 'lakutata/com/entrypoint';
|
|
7
|
+
import { ListTemplatesOptions } from '../options/ListTemplatesOptions';
|
|
8
|
+
import { TemplateManager } from '../lib/providers/TemplateManager';
|
|
7
9
|
export declare class CommandLineController extends Controller {
|
|
8
10
|
protected readonly projectCreator: Creator;
|
|
9
11
|
protected readonly frameworkInfo: Information;
|
|
12
|
+
protected readonly templateManager: TemplateManager;
|
|
10
13
|
/**
|
|
11
14
|
* Create project
|
|
12
15
|
* @param inp
|
|
13
16
|
*/
|
|
14
17
|
create(inp: ActionPattern<CreateProjectOptions>): Promise<void>;
|
|
18
|
+
/**
|
|
19
|
+
* List templates
|
|
20
|
+
* @param inp
|
|
21
|
+
*/
|
|
22
|
+
templates(inp: ActionPattern<ListTemplatesOptions>): Promise<void>;
|
|
15
23
|
/**
|
|
16
24
|
* Show framework info
|
|
17
25
|
* @param inp
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CommandLineController.d.ts","sourceRoot":"","sources":["../../src/controllers/CommandLineController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,oBAAoB,EAAC,MAAM,iCAAiC,CAAA;AACpE,OAAO,EAAC,mBAAmB,EAAC,MAAM,gCAAgC,CAAA;AAClE,OAAO,EAAC,WAAW,EAAC,MAAM,8BAA8B,CAAA;AACxD,OAAO,EAAC,OAAO,EAAC,MAAM,0BAA0B,CAAA;AAChD,OAAO,EAAC,KAAK,aAAa,EAAC,MAAM,UAAU,CAAA;AAG3C,OAAO,EAAC,UAAU,EAAC,MAAM,yBAAyB,CAAA;
|
|
1
|
+
{"version":3,"file":"CommandLineController.d.ts","sourceRoot":"","sources":["../../src/controllers/CommandLineController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,oBAAoB,EAAC,MAAM,iCAAiC,CAAA;AACpE,OAAO,EAAC,mBAAmB,EAAC,MAAM,gCAAgC,CAAA;AAClE,OAAO,EAAC,WAAW,EAAC,MAAM,8BAA8B,CAAA;AACxD,OAAO,EAAC,OAAO,EAAC,MAAM,0BAA0B,CAAA;AAChD,OAAO,EAAC,KAAK,aAAa,EAAC,MAAM,UAAU,CAAA;AAG3C,OAAO,EAAC,UAAU,EAAC,MAAM,yBAAyB,CAAA;AAClD,OAAO,EAAC,oBAAoB,EAAC,MAAM,iCAAiC,CAAA;AACpE,OAAO,EAAC,eAAe,EAAC,MAAM,kCAAkC,CAAA;AAEhE,qBAAa,qBAAsB,SAAQ,UAAU;IAGjD,SAAS,CAAC,QAAQ,CAAC,cAAc,EAAE,OAAO,CAAA;IAG1C,SAAS,CAAC,QAAQ,CAAC,aAAa,EAAE,WAAW,CAAA;IAG7C,SAAS,CAAC,QAAQ,CAAC,eAAe,EAAE,eAAe,CAAA;IAEnD;;;OAGG;IAEU,MAAM,CAAC,GAAG,EAAE,aAAa,CAAC,oBAAoB,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAI5E;;;OAGG;IAEU,SAAS,CAAC,GAAG,EAAE,aAAa,CAAC,oBAAoB,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAI/E;;;OAGG;IAEU,IAAI,CAAC,GAAG,EAAE,aAAa,CAAC,mBAAmB,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;CAG5E"}
|
|
@@ -17,6 +17,8 @@ const Creator_1 = require("../lib/providers/Creator");
|
|
|
17
17
|
const di_1 = require("lakutata/decorator/di");
|
|
18
18
|
const ctrl_1 = require("lakutata/decorator/ctrl");
|
|
19
19
|
const entrypoint_1 = require("lakutata/com/entrypoint");
|
|
20
|
+
const ListTemplatesOptions_1 = require("../options/ListTemplatesOptions");
|
|
21
|
+
const TemplateManager_1 = require("../lib/providers/TemplateManager");
|
|
20
22
|
class CommandLineController extends entrypoint_1.Controller {
|
|
21
23
|
/**
|
|
22
24
|
* Create project
|
|
@@ -25,6 +27,13 @@ class CommandLineController extends entrypoint_1.Controller {
|
|
|
25
27
|
async create(inp) {
|
|
26
28
|
await this.projectCreator.create(inp);
|
|
27
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* List templates
|
|
32
|
+
* @param inp
|
|
33
|
+
*/
|
|
34
|
+
async templates(inp) {
|
|
35
|
+
await this.templateManager.list(inp);
|
|
36
|
+
}
|
|
28
37
|
/**
|
|
29
38
|
* Show framework info
|
|
30
39
|
* @param inp
|
|
@@ -40,19 +49,29 @@ __decorate([
|
|
|
40
49
|
], CommandLineController.prototype, "projectCreator", void 0);
|
|
41
50
|
__decorate([
|
|
42
51
|
(0, di_1.Inject)('info'),
|
|
43
|
-
__metadata("design:type", Information_1.Information
|
|
52
|
+
__metadata("design:type", Information_1.Information)
|
|
53
|
+
], CommandLineController.prototype, "frameworkInfo", void 0);
|
|
54
|
+
__decorate([
|
|
55
|
+
(0, di_1.Inject)('templateManager'),
|
|
56
|
+
__metadata("design:type", TemplateManager_1.TemplateManager
|
|
44
57
|
/**
|
|
45
58
|
* Create project
|
|
46
59
|
* @param inp
|
|
47
60
|
*/
|
|
48
61
|
)
|
|
49
|
-
], CommandLineController.prototype, "
|
|
62
|
+
], CommandLineController.prototype, "templateManager", void 0);
|
|
50
63
|
__decorate([
|
|
51
64
|
(0, ctrl_1.CLIAction)('create', CreateProjectOptions_1.CreateProjectOptions.description('create a Lakutata project')),
|
|
52
65
|
__metadata("design:type", Function),
|
|
53
66
|
__metadata("design:paramtypes", [Object]),
|
|
54
67
|
__metadata("design:returntype", Promise)
|
|
55
68
|
], CommandLineController.prototype, "create", null);
|
|
69
|
+
__decorate([
|
|
70
|
+
(0, ctrl_1.CLIAction)('templates', ListTemplatesOptions_1.ListTemplatesOptions.description('list available project templates')),
|
|
71
|
+
__metadata("design:type", Function),
|
|
72
|
+
__metadata("design:paramtypes", [Object]),
|
|
73
|
+
__metadata("design:returntype", Promise)
|
|
74
|
+
], CommandLineController.prototype, "templates", null);
|
|
56
75
|
__decorate([
|
|
57
76
|
(0, ctrl_1.CLIAction)('info', LakutataInfoOptions_1.LakutataInfoOptions.description('show Lakutata framework info')),
|
|
58
77
|
__metadata("design:type", Function),
|
|
@@ -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;
|
|
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;AAK1E,OAAO,EAAC,WAAW,EAAE,QAAQ,EAAC,MAAM,UAAU,CAAA;AAE9C,OAAO,EAAC,MAAM,EAAC,MAAM,qBAAqB,CAAA;AAK1C,OAAO,EAAC,mBAAmB,EAAC,MAAM,uBAAuB,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"}
|
|
@@ -99,7 +99,7 @@ class Creator extends lakutata_1.Provider {
|
|
|
99
99
|
const appTemplate = options.template;
|
|
100
100
|
const targetPath = options.overwrite ? node_path_1.default.resolve(options.path) : node_path_1.default.resolve(options.path, options.name);
|
|
101
101
|
const table = new cli_table3_1.default();
|
|
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
|
|
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 Repository'), this.puller.getGitSource(appTemplate)]);
|
|
103
103
|
console.log(table.toString());
|
|
104
104
|
await new Promise(resolve => {
|
|
105
105
|
let timeLeft = 15;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Application, Provider } from 'lakutata';
|
|
2
|
+
import { ListTemplatesOptions } from '../../options/ListTemplatesOptions';
|
|
3
|
+
import { Logger } from 'lakutata/com/logger';
|
|
4
|
+
import { Spinner } from '../components/Spinner';
|
|
5
|
+
type TemplateInfo = {
|
|
6
|
+
name: string;
|
|
7
|
+
description: string;
|
|
8
|
+
repository: string;
|
|
9
|
+
};
|
|
10
|
+
export declare class TemplateManager extends Provider {
|
|
11
|
+
protected readonly app: Application;
|
|
12
|
+
protected readonly log: Logger;
|
|
13
|
+
protected readonly spinner: Spinner;
|
|
14
|
+
protected readonly apiHost: string;
|
|
15
|
+
protected readonly repoPrefix: string;
|
|
16
|
+
protected readonly localDataFilename: string;
|
|
17
|
+
/**
|
|
18
|
+
* Initializer
|
|
19
|
+
* @protected
|
|
20
|
+
*/
|
|
21
|
+
protected init(): Promise<void>;
|
|
22
|
+
/**
|
|
23
|
+
* Fetch template repository list from remote
|
|
24
|
+
* @protected
|
|
25
|
+
*/
|
|
26
|
+
protected fetchTemplateRepos(): Promise<TemplateInfo[]>;
|
|
27
|
+
/**
|
|
28
|
+
* List templates
|
|
29
|
+
* @param options
|
|
30
|
+
*/
|
|
31
|
+
list(options: ListTemplatesOptions): Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* Print template information to console
|
|
34
|
+
* @param templateInfos
|
|
35
|
+
* @param updatedAt
|
|
36
|
+
* @protected
|
|
37
|
+
*/
|
|
38
|
+
protected printTemplates(templateInfos: TemplateInfo[], updatedAt: number): void;
|
|
39
|
+
}
|
|
40
|
+
export {};
|
|
41
|
+
//# sourceMappingURL=TemplateManager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TemplateManager.d.ts","sourceRoot":"","sources":["../../../src/lib/providers/TemplateManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,WAAW,EAAO,QAAQ,EAAO,MAAM,UAAU,CAAA;AACzD,OAAO,EAAC,oBAAoB,EAAC,MAAM,oCAAoC,CAAA;AAQvE,OAAO,EAAC,MAAM,EAAC,MAAM,qBAAqB,CAAA;AAE1C,OAAO,EAAC,OAAO,EAAC,MAAM,uBAAuB,CAAA;AAG7C,KAAK,YAAY,GAAG;IAChB,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,EAAE,MAAM,CAAA;IACnB,UAAU,EAAE,MAAM,CAAA;CACrB,CAAA;AAQD,qBAAa,eAAgB,SAAQ,QAAQ;IAGzC,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,OAAO,EAAE,MAAM,CAAA;IAGlC,SAAS,CAAC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;IAErC,SAAS,CAAC,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAwC;IAEpF;;;OAGG;cACa,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAIrC;;;OAGG;cACa,kBAAkB,IAAI,OAAO,CAAC,YAAY,EAAE,CAAC;IA0B7D;;;OAGG;IAEU,IAAI,CAAC,OAAO,EAAE,oBAAoB;IAyB/C;;;;;OAKG;IACH,SAAS,CAAC,cAAc,CAAC,aAAa,EAAE,YAAY,EAAE,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI;CAmBnF"}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
19
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
20
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
21
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
22
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
23
|
+
};
|
|
24
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
25
|
+
if (mod && mod.__esModule) return mod;
|
|
26
|
+
var result = {};
|
|
27
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
28
|
+
__setModuleDefault(result, mod);
|
|
29
|
+
return result;
|
|
30
|
+
};
|
|
31
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
32
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
33
|
+
};
|
|
34
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
|
+
};
|
|
37
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
exports.TemplateManager = void 0;
|
|
39
|
+
const lakutata_1 = require("lakutata");
|
|
40
|
+
const ListTemplatesOptions_1 = require("../../options/ListTemplatesOptions");
|
|
41
|
+
const dto_1 = require("lakutata/decorator/dto");
|
|
42
|
+
const cli_table3_1 = __importDefault(require("cli-table3"));
|
|
43
|
+
const ansis_1 = __importDefault(require("ansis"));
|
|
44
|
+
const console = __importStar(require("node:console"));
|
|
45
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
46
|
+
const di_1 = require("lakutata/decorator/di");
|
|
47
|
+
const node_fetch_native_1 = __importDefault(require("node-fetch-native"));
|
|
48
|
+
const logger_1 = require("lakutata/com/logger");
|
|
49
|
+
const helper_1 = require("lakutata/helper");
|
|
50
|
+
const Spinner_1 = require("../components/Spinner");
|
|
51
|
+
const promises_1 = require("node:fs/promises");
|
|
52
|
+
class TemplateManager extends lakutata_1.Provider {
|
|
53
|
+
constructor() {
|
|
54
|
+
super(...arguments);
|
|
55
|
+
this.localDataFilename = node_path_1.default.resolve('@data', 'templates.db');
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Initializer
|
|
59
|
+
* @protected
|
|
60
|
+
*/
|
|
61
|
+
async init() {
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Fetch template repository list from remote
|
|
65
|
+
* @protected
|
|
66
|
+
*/
|
|
67
|
+
async fetchTemplateRepos() {
|
|
68
|
+
this.spinner.start('Fetching');
|
|
69
|
+
const url = new URL(this.apiHost);
|
|
70
|
+
url.pathname = '/users/lakutata/repos';
|
|
71
|
+
const fetchResponse = await (0, node_fetch_native_1.default)(url.toString(), { method: 'get' });
|
|
72
|
+
if (fetchResponse.status >= 400) {
|
|
73
|
+
this.spinner.stop();
|
|
74
|
+
this.log.error('Failed to obtain template repository list: (%s) %s', fetchResponse.status, fetchResponse.statusText);
|
|
75
|
+
this.app.exit(1);
|
|
76
|
+
}
|
|
77
|
+
const rawRepos = (0, helper_1.As)(await fetchResponse.json());
|
|
78
|
+
const templateRepos = rawRepos.filter((rawRepo) => {
|
|
79
|
+
const repoName = rawRepo.name;
|
|
80
|
+
return repoName.startsWith(this.repoPrefix) && repoName !== this.repoPrefix;
|
|
81
|
+
});
|
|
82
|
+
this.spinner.stop();
|
|
83
|
+
return templateRepos.map((templateRepo) => {
|
|
84
|
+
const repoName = templateRepo.name;
|
|
85
|
+
return {
|
|
86
|
+
name: repoName.replace(`${this.repoPrefix}-`, ''),
|
|
87
|
+
description: templateRepo.description,
|
|
88
|
+
repository: templateRepo.full_name
|
|
89
|
+
};
|
|
90
|
+
}).sort((a, b) => b.name === 'default' ? 1 : 0);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* List templates
|
|
94
|
+
* @param options
|
|
95
|
+
*/
|
|
96
|
+
async list(options) {
|
|
97
|
+
const { version } = JSON.parse(await (0, promises_1.readFile)(node_path_1.default.resolve('@packageJson'), { encoding: 'utf-8' }));
|
|
98
|
+
const isLocalDataExists = await (0, helper_1.IsExists)(this.localDataFilename);
|
|
99
|
+
let isLocalDataVersionMatched = false;
|
|
100
|
+
let cache = {
|
|
101
|
+
templates: [],
|
|
102
|
+
version: version,
|
|
103
|
+
updatedAt: lakutata_1.Time.now()
|
|
104
|
+
};
|
|
105
|
+
if (isLocalDataExists) {
|
|
106
|
+
cache = JSON.parse(await (0, promises_1.readFile)(this.localDataFilename, { encoding: 'utf-8' }));
|
|
107
|
+
isLocalDataVersionMatched = cache.version === version;
|
|
108
|
+
}
|
|
109
|
+
if (!isLocalDataExists || !isLocalDataVersionMatched || options.refresh) {
|
|
110
|
+
const templates = await this.fetchTemplateRepos();
|
|
111
|
+
cache = {
|
|
112
|
+
templates: templates,
|
|
113
|
+
version: version,
|
|
114
|
+
updatedAt: lakutata_1.Time.now()
|
|
115
|
+
};
|
|
116
|
+
await (0, promises_1.writeFile)(this.localDataFilename, JSON.stringify(cache), { flag: 'w' });
|
|
117
|
+
}
|
|
118
|
+
this.printTemplates(cache.templates, cache.updatedAt);
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Print template information to console
|
|
122
|
+
* @param templateInfos
|
|
123
|
+
* @param updatedAt
|
|
124
|
+
* @protected
|
|
125
|
+
*/
|
|
126
|
+
printTemplates(templateInfos, updatedAt) {
|
|
127
|
+
const table = new cli_table3_1.default();
|
|
128
|
+
table.push([
|
|
129
|
+
{ content: ansis_1.default.bold.cyan('Name'), hAlign: 'center' },
|
|
130
|
+
{ content: ansis_1.default.bold.cyan('Description'), hAlign: 'center' },
|
|
131
|
+
{ content: ansis_1.default.bold.cyan('Repository'), hAlign: 'center' }
|
|
132
|
+
], ...templateInfos.map((templateInfo) => {
|
|
133
|
+
return [
|
|
134
|
+
templateInfo.name,
|
|
135
|
+
templateInfo.description,
|
|
136
|
+
templateInfo.repository
|
|
137
|
+
];
|
|
138
|
+
}));
|
|
139
|
+
console.log(table.toString());
|
|
140
|
+
console.log(`Template list last updated on: ${ansis_1.default.bold(new lakutata_1.Time(updatedAt).format('YYYY-MM-DD HH:mm:ss'))}`);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
exports.TemplateManager = TemplateManager;
|
|
144
|
+
__decorate([
|
|
145
|
+
(0, di_1.Inject)(lakutata_1.Application),
|
|
146
|
+
__metadata("design:type", lakutata_1.Application)
|
|
147
|
+
], TemplateManager.prototype, "app", void 0);
|
|
148
|
+
__decorate([
|
|
149
|
+
(0, di_1.Inject)('log'),
|
|
150
|
+
__metadata("design:type", logger_1.Logger)
|
|
151
|
+
], TemplateManager.prototype, "log", void 0);
|
|
152
|
+
__decorate([
|
|
153
|
+
(0, di_1.Inject)('spinner'),
|
|
154
|
+
__metadata("design:type", Spinner_1.Spinner)
|
|
155
|
+
], TemplateManager.prototype, "spinner", void 0);
|
|
156
|
+
__decorate([
|
|
157
|
+
(0, di_1.Configurable)(lakutata_1.DTO.String().required()),
|
|
158
|
+
__metadata("design:type", String)
|
|
159
|
+
], TemplateManager.prototype, "apiHost", void 0);
|
|
160
|
+
__decorate([
|
|
161
|
+
(0, di_1.Configurable)(lakutata_1.DTO.String().required()),
|
|
162
|
+
__metadata("design:type", String)
|
|
163
|
+
], TemplateManager.prototype, "repoPrefix", void 0);
|
|
164
|
+
__decorate([
|
|
165
|
+
(0, dto_1.Accept)(ListTemplatesOptions_1.ListTemplatesOptions.required()),
|
|
166
|
+
__metadata("design:type", Function),
|
|
167
|
+
__metadata("design:paramtypes", [ListTemplatesOptions_1.ListTemplatesOptions]),
|
|
168
|
+
__metadata("design:returntype", Promise)
|
|
169
|
+
], TemplateManager.prototype, "list", null);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CreateProjectOptions.d.ts","sourceRoot":"","sources":["../../src/options/CreateProjectOptions.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"CreateProjectOptions.d.ts","sourceRoot":"","sources":["../../src/options/CreateProjectOptions.ts"],"names":[],"mappings":"AAAA,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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ListTemplatesOptions.d.ts","sourceRoot":"","sources":["../../src/options/ListTemplatesOptions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAC,MAAM,UAAU,CAAA;AAG5B,qBAAa,oBAAqB,SAAQ,GAAG;IAUlC,OAAO,EAAE,OAAO,CAAA;CAC1B"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.ListTemplatesOptions = void 0;
|
|
13
|
+
const lakutata_1 = require("lakutata");
|
|
14
|
+
const dto_1 = require("lakutata/decorator/dto");
|
|
15
|
+
class ListTemplatesOptions extends lakutata_1.DTO {
|
|
16
|
+
}
|
|
17
|
+
exports.ListTemplatesOptions = ListTemplatesOptions;
|
|
18
|
+
__decorate([
|
|
19
|
+
(0, dto_1.Expect)(lakutata_1.DTO
|
|
20
|
+
.Boolean()
|
|
21
|
+
.strict(false)
|
|
22
|
+
.optional()
|
|
23
|
+
.default(false)
|
|
24
|
+
.description('update the local list from the remote synchronized template repository list (default: false)')),
|
|
25
|
+
__metadata("design:type", Boolean)
|
|
26
|
+
], ListTemplatesOptions.prototype, "refresh", void 0);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lakutata/cli",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.11.0",
|
|
4
4
|
"description": "Lakutata CLI tool",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"lakutata",
|
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
"build": "tsc",
|
|
26
26
|
"rebuild": "npm run clean && npm run build",
|
|
27
27
|
"test:info": "tsx src/CLIApp.ts info",
|
|
28
|
+
"test:templates": "tsx src/CLIApp.ts templates",
|
|
28
29
|
"test:create": "tsx src/CLIApp.ts create --help"
|
|
29
30
|
},
|
|
30
31
|
"bugs": {
|
|
@@ -40,11 +41,12 @@
|
|
|
40
41
|
"lakutata": "^2.0.11",
|
|
41
42
|
"latest-version": "^9.0.0",
|
|
42
43
|
"log-update": "^6.1.0",
|
|
44
|
+
"node-fetch-native": "^1.6.4",
|
|
43
45
|
"pkg-dir": "^8.0.0",
|
|
44
46
|
"semver": "^7.6.0"
|
|
45
47
|
},
|
|
46
48
|
"devDependencies": {
|
|
47
49
|
"@types/degit": "^2.8.6"
|
|
48
50
|
},
|
|
49
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "df188f5c96607c9da9bcd0258a4079fa3f36951e"
|
|
50
52
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ProjectTypeConfig.d.ts","sourceRoot":"","sources":["../../src/lib/ProjectTypeConfig.ts"],"names":[],"mappings":"AAAA,UAAU,iBAAiB;IACvB,CAAC,IAAI,EAAE,MAAM,GAAG;QACZ,MAAM,EAAE,MAAM,CAAA;KACjB,CAAA;CACJ;AAED,eAAO,MAAM,iBAAiB,EAAE,iBAa/B,CAAA"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ProjectTypeConfig = void 0;
|
|
4
|
-
exports.ProjectTypeConfig = {
|
|
5
|
-
plain: {
|
|
6
|
-
branch: 'main'
|
|
7
|
-
},
|
|
8
|
-
cli: {
|
|
9
|
-
branch: 'cli'
|
|
10
|
-
},
|
|
11
|
-
api: {
|
|
12
|
-
branch: 'api'
|
|
13
|
-
},
|
|
14
|
-
electron: {
|
|
15
|
-
branch: 'electron'
|
|
16
|
-
}
|
|
17
|
-
};
|