@gct-paas/cli 0.1.4-dev.1 → 0.1.4-dev.3
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/actions/gen-api/api-manage.cjs +1 -1
- package/dist/actions/gen-api/gen-api.cjs +12 -8
- package/es/actions/gen-api/api-manage.mjs +1 -1
- package/es/actions/gen-api/gen-api.mjs +17 -13
- package/hbs-temp/api-config.ts.hbs +20 -0
- package/hbs-temp/apis/{{api}}.service.d.ts.hbs +19 -0
- package/hbs-temp/index.d.ts.hbs +9 -0
- package/package.json +4 -2
- package/hbs-temp/index.ts.hbs +0 -9
- package/hbs-temp/{{api}}.service.ts.hbs +0 -37
- /package/hbs-temp/{entities.ts.hbs → entities.d.ts.hbs} +0 -0
|
@@ -33,7 +33,7 @@ class ApiManage {
|
|
|
33
33
|
add(pathStr, cfg) {
|
|
34
34
|
const splits = pathStr.split("/");
|
|
35
35
|
const entityName = splits[3];
|
|
36
|
-
const method = splits
|
|
36
|
+
const method = splits.slice(4).join("_");
|
|
37
37
|
const requestPath = splits.slice(4).join("/");
|
|
38
38
|
if (!this.cache.has(entityName)) {
|
|
39
39
|
this.cache.set(entityName, new EntityApiManage(entityName));
|
|
@@ -35,15 +35,19 @@ class GenApiAction {
|
|
|
35
35
|
* @param {boolean} clean 是否清理输出目录后再生成
|
|
36
36
|
*/
|
|
37
37
|
async run(baseUrl, tag, template, output, clean) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
38
|
+
try {
|
|
39
|
+
const cwd = process.cwd();
|
|
40
|
+
const tempPath = _path.default.resolve(cwd, template);
|
|
41
|
+
const outPath = _path.default.resolve(cwd, output);
|
|
42
|
+
if (clean === true && _fsExtra.default.existsSync(outPath)) {
|
|
43
|
+
rm.sync(outPath);
|
|
44
|
+
}
|
|
45
|
+
await this.registerMacros(tempPath, this.engine);
|
|
46
|
+
await this.registerTempFiles(tempPath, this.engine);
|
|
47
|
+
await this.write(tag, _path.default.join(baseUrl, this.configs[tag]), outPath, this.engine);
|
|
48
|
+
} catch (error) {
|
|
49
|
+
console.error(error);
|
|
43
50
|
}
|
|
44
|
-
await this.registerMacros(tempPath, this.engine);
|
|
45
|
-
await this.registerTempFiles(tempPath, this.engine);
|
|
46
|
-
await this.write(tag, _path.default.join(baseUrl, this.configs[tag]), outPath, this.engine);
|
|
47
51
|
}
|
|
48
52
|
/**
|
|
49
53
|
* 基于模型编译输出文件
|
|
@@ -26,7 +26,7 @@ export class ApiManage {
|
|
|
26
26
|
add(pathStr, cfg) {
|
|
27
27
|
const splits = pathStr.split("/");
|
|
28
28
|
const entityName = splits[3];
|
|
29
|
-
const method = splits
|
|
29
|
+
const method = splits.slice(4).join("_");
|
|
30
30
|
const requestPath = splits.slice(4).join("/");
|
|
31
31
|
if (!this.cache.has(entityName)) {
|
|
32
32
|
this.cache.set(entityName, new EntityApiManage(entityName));
|
|
@@ -26,20 +26,24 @@ export class GenApiAction {
|
|
|
26
26
|
* @param {boolean} clean 是否清理输出目录后再生成
|
|
27
27
|
*/
|
|
28
28
|
async run(baseUrl, tag, template, output, clean) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
29
|
+
try {
|
|
30
|
+
const cwd = process.cwd();
|
|
31
|
+
const tempPath = path.resolve(cwd, template);
|
|
32
|
+
const outPath = path.resolve(cwd, output);
|
|
33
|
+
if (clean === true && fse.existsSync(outPath)) {
|
|
34
|
+
rm.sync(outPath);
|
|
35
|
+
}
|
|
36
|
+
await this.registerMacros(tempPath, this.engine);
|
|
37
|
+
await this.registerTempFiles(tempPath, this.engine);
|
|
38
|
+
await this.write(
|
|
39
|
+
tag,
|
|
40
|
+
path.join(baseUrl, this.configs[tag]),
|
|
41
|
+
outPath,
|
|
42
|
+
this.engine
|
|
43
|
+
);
|
|
44
|
+
} catch (error) {
|
|
45
|
+
console.error(error);
|
|
34
46
|
}
|
|
35
|
-
await this.registerMacros(tempPath, this.engine);
|
|
36
|
-
await this.registerTempFiles(tempPath, this.engine);
|
|
37
|
-
await this.write(
|
|
38
|
-
tag,
|
|
39
|
-
path.join(baseUrl, this.configs[tag]),
|
|
40
|
-
outPath,
|
|
41
|
-
this.engine
|
|
42
|
-
);
|
|
43
47
|
}
|
|
44
48
|
/**
|
|
45
49
|
* 基于模型编译输出文件
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2
|
+
export const apiConfig: any[] = [
|
|
3
|
+
{{#each entities as |entity|}}
|
|
4
|
+
{
|
|
5
|
+
name: '{{camelCase entity.entityName}}',
|
|
6
|
+
entityName: '{{entity.entityName}}',
|
|
7
|
+
apis: [
|
|
8
|
+
{{#each methods as |method|}}
|
|
9
|
+
{
|
|
10
|
+
mode: '{{ method.mode }}',
|
|
11
|
+
method: '{{ method.mode }}{{#if method.name}}{{pascalCase (camelCase method.name) }}{{/if}}',
|
|
12
|
+
path: '{{#eq method.name '{id}'}}{{else}}{{method.model.requestPath}}{{/eq}}',
|
|
13
|
+
hasQuery: {{#gt method.queries.length 0}}true{{else}}false{{/gt}},
|
|
14
|
+
hasData: {{#if method.requestEntity}}true{{else}}false{{/if}}
|
|
15
|
+
},
|
|
16
|
+
{{/each}}
|
|
17
|
+
]
|
|
18
|
+
},
|
|
19
|
+
{{/each}}
|
|
20
|
+
]
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{{#gt entityRefs.length 0}}
|
|
2
|
+
import type { {{formatImport entityRefs}} } from '../entities';
|
|
3
|
+
|
|
4
|
+
{{/gt}}
|
|
5
|
+
{{#each methods as |method|}}
|
|
6
|
+
{{#gt method.queries.length 0}}
|
|
7
|
+
export interface {{ method.mode }}{{#if method.name}}{{pascalCase (camelCase method.name) }}{{/if}}Query {
|
|
8
|
+
{{#each method.queries as |query|}}
|
|
9
|
+
{{camelCase query.name}}{{#if query.required}}{{else}}?{{/if}}: {{#if query.items}}{{formatJsType query.items.type}}{{else}}{{formatJsType query.type}}{{/if}}; // {{query.description}}
|
|
10
|
+
{{/each}}
|
|
11
|
+
}
|
|
12
|
+
{{/gt}}
|
|
13
|
+
{{/each}}
|
|
14
|
+
export interface {{pascalCase (camelCase entityName) }}Service {
|
|
15
|
+
{{#each methods as |method|}}
|
|
16
|
+
// {{ method.model.summary }}
|
|
17
|
+
{{ method.mode }}{{#if method.name}}{{pascalCase (camelCase method.name) }}{{/if}}({{#gt method.queries.length 0}}query: {{ method.mode }}{{#if method.name}}{{pascalCase (camelCase method.name) }}{{/if}}Query, {{/gt}}{{#if method.requestEntity}}data: {{method.requestEntity.title}}, {{/if}}config?: Record<string, string>): Promise<IHttpResponse<{{#if method.responseEntity}}{{formatImportItem method.responseEntity.title}}{{else}}unknown{{/if}}>>;
|
|
18
|
+
{{/each}}
|
|
19
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
{{#each entities as |entity|}}
|
|
2
|
+
import type { {{pascalCase (camelCase entity.entityName) }}Service } from './apis/{{entity.entityName}}.service';
|
|
3
|
+
{{/each}}
|
|
4
|
+
|
|
5
|
+
export interface ApiManage {
|
|
6
|
+
{{#each entities as |entity|}}
|
|
7
|
+
readonly {{camelCase entity.entityName}}: {{pascalCase (camelCase entity.entityName)}}Service;
|
|
8
|
+
{{/each}}
|
|
9
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gct-paas/cli",
|
|
3
|
-
"version": "0.1.4-dev.
|
|
3
|
+
"version": "0.1.4-dev.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "paas 平台核心包",
|
|
6
6
|
"bin": {
|
|
@@ -34,6 +34,7 @@
|
|
|
34
34
|
"license": "MIT",
|
|
35
35
|
"author": "gct",
|
|
36
36
|
"scripts": {
|
|
37
|
+
"run": "tsx src/bin.ts",
|
|
37
38
|
"build": "npm run lint && unbuild",
|
|
38
39
|
"lint": "eslint src/",
|
|
39
40
|
"publish:next": "npm run build && npm publish --access public --tag=next --registry=https://registry.npmjs.org/",
|
|
@@ -64,5 +65,6 @@
|
|
|
64
65
|
"tsx": "^4.20.4",
|
|
65
66
|
"typescript": "^5.8.2",
|
|
66
67
|
"unbuild": "^3.5.0"
|
|
67
|
-
}
|
|
68
|
+
},
|
|
69
|
+
"gitHead": "caa65b07a6bbfb27d41911da2f5459567db38b1d"
|
|
68
70
|
}
|
package/hbs-temp/index.ts.hbs
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
{{#each entities as |entity|}}
|
|
2
|
-
import { {{pascalCase (camelCase entity.entityName) }}Service } from './{{entity.entityName}}.service';
|
|
3
|
-
{{/each}}
|
|
4
|
-
|
|
5
|
-
export class ApiManage {
|
|
6
|
-
{{#each entities as |entity|}}
|
|
7
|
-
{{camelCase entity.entityName}}: {{pascalCase (camelCase entity.entityName)}}Service = new {{pascalCase (camelCase entity.entityName)}}Service();
|
|
8
|
-
{{/each}}
|
|
9
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import type { IHttpResponse } from '@gct-paas/base';
|
|
2
|
-
{{#eq tag 'apaas'}}
|
|
3
|
-
import { APaasBaseService } from '../base/apaas-base.service';
|
|
4
|
-
{{/eq}}
|
|
5
|
-
{{#eq tag 'ipaas'}}
|
|
6
|
-
import { IPaasBaseService } from '../base/ipaas-base.service';
|
|
7
|
-
{{/eq}}
|
|
8
|
-
{{#eq tag 'platform'}}
|
|
9
|
-
import { PlatformBaseService } from '../base/platform-base.service';
|
|
10
|
-
{{/eq}}
|
|
11
|
-
{{#eq tag 'rag'}}
|
|
12
|
-
import { RagBaseService } from '../base/rag-base.service';
|
|
13
|
-
{{/eq}}
|
|
14
|
-
{{#gt entityRefs.length 0}}
|
|
15
|
-
import type { {{formatImport entityRefs}} } from './entities';
|
|
16
|
-
|
|
17
|
-
{{/gt}}
|
|
18
|
-
{{#each methods as |method|}}
|
|
19
|
-
{{#gt method.queries.length 0}}
|
|
20
|
-
export interface {{ method.mode }}{{#if method.name}}{{pascalCase (camelCase method.name) }}{{/if}}Query {
|
|
21
|
-
{{#each method.queries as |query|}}
|
|
22
|
-
{{camelCase query.name}}{{#if query.required}}{{else}}?{{/if}}: {{#if query.items}}{{formatJsType query.items.type}}{{else}}{{formatJsType query.type}}{{/if}}; // {{query.description}}
|
|
23
|
-
{{/each}}
|
|
24
|
-
}
|
|
25
|
-
{{/gt}}
|
|
26
|
-
{{/each}}
|
|
27
|
-
export class {{pascalCase (camelCase entityName) }}Service extends {{#eq tag 'apaas'}}APaasBaseService{{/eq}}{{#eq tag 'platform'}}PlatformBaseService{{/eq}}{{#eq tag 'rag'}}RagBaseService{{/eq}}{{#eq tag 'ipaas'}}IPaasBaseService{{/eq}} {
|
|
28
|
-
constructor() {
|
|
29
|
-
super('{{ entityName }}');
|
|
30
|
-
}
|
|
31
|
-
{{#each methods as |method|}}
|
|
32
|
-
// {{ method.model.summary }}
|
|
33
|
-
async {{ method.mode }}{{#if method.name}}{{pascalCase (camelCase method.name) }}{{/if}}({{#gt method.queries.length 0}}query: {{ method.mode }}{{#if method.name}}{{pascalCase (camelCase method.name) }}{{/if}}Query, {{/gt}}{{#if method.requestEntity}}data: {{method.requestEntity.title}}, {{/if}}config: Record<string, string> = {}): Promise<IHttpResponse<{{#if method.responseEntity}}{{formatImportItem method.responseEntity.title}}{{else}}unknown{{/if}}>> {
|
|
34
|
-
return this._{{ method.mode }}('{{#eq method.name '{id}'}}{{else}}{{method.model.requestPath}}{{/eq}}'{{#if method.requestEntity}}, data{{else}}, null{{/if}}{{#gt method.queries.length 0}}, query{{else}}, null{{/gt}}, config);
|
|
35
|
-
}
|
|
36
|
-
{{/each}}
|
|
37
|
-
}
|
|
File without changes
|