endpoints-sdk-cli 2.7.0 → 2.8.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/README.md +4 -4
- package/lib/classes/Repository.d.ts +3 -1
- package/lib/classes/Repository.js +7 -4
- package/lib/commands/add.js +2 -2
- package/lib/commands/install.js +6 -6
- package/lib/commands/update.js +4 -4
- package/lib/makeFiles.d.ts +5 -5
- package/lib/makeFiles.js +5 -5
- package/lib/templates/files/endpoints.d.ts +1 -1
- package/lib/templates/files/endpoints.js +3 -3
- package/lib/templates/functions/endpoint.d.ts +1 -1
- package/lib/templates/functions/endpoint.js +10 -4
- package/oclif.manifest.json +1 -1
- package/package.json +3 -1
package/README.md
CHANGED
|
@@ -18,7 +18,7 @@ $ npm install -g endpoints-sdk-cli
|
|
|
18
18
|
$ mes COMMAND
|
|
19
19
|
running command...
|
|
20
20
|
$ mes (-v|--version|version)
|
|
21
|
-
endpoints-sdk-cli/2.
|
|
21
|
+
endpoints-sdk-cli/2.8.0 darwin-arm64 node-v18.19.0
|
|
22
22
|
$ mes --help [COMMAND]
|
|
23
23
|
USAGE
|
|
24
24
|
$ mes COMMAND
|
|
@@ -82,7 +82,7 @@ EXAMPLES
|
|
|
82
82
|
$ mes add https://github.com/[username/repository].git
|
|
83
83
|
```
|
|
84
84
|
|
|
85
|
-
_See code: [src/commands/add.ts](https://github.com/matsuri-tech/endpoints-sdk-cli/blob/v2.
|
|
85
|
+
_See code: [src/commands/add.ts](https://github.com/matsuri-tech/endpoints-sdk-cli/blob/v2.8.0/src/commands/add.ts)_
|
|
86
86
|
|
|
87
87
|
## `mes help [COMMAND]`
|
|
88
88
|
|
|
@@ -110,7 +110,7 @@ USAGE
|
|
|
110
110
|
$ mes install
|
|
111
111
|
```
|
|
112
112
|
|
|
113
|
-
_See code: [src/commands/install.ts](https://github.com/matsuri-tech/endpoints-sdk-cli/blob/v2.
|
|
113
|
+
_See code: [src/commands/install.ts](https://github.com/matsuri-tech/endpoints-sdk-cli/blob/v2.8.0/src/commands/install.ts)_
|
|
114
114
|
|
|
115
115
|
## `mes update [SERVICE]`
|
|
116
116
|
|
|
@@ -121,7 +121,7 @@ USAGE
|
|
|
121
121
|
$ mes update [SERVICE]
|
|
122
122
|
```
|
|
123
123
|
|
|
124
|
-
_See code: [src/commands/update.ts](https://github.com/matsuri-tech/endpoints-sdk-cli/blob/v2.
|
|
124
|
+
_See code: [src/commands/update.ts](https://github.com/matsuri-tech/endpoints-sdk-cli/blob/v2.8.0/src/commands/update.ts)_
|
|
125
125
|
<!-- commandsstop -->
|
|
126
126
|
|
|
127
127
|
|
|
@@ -16,6 +16,8 @@ export interface Endpoint {
|
|
|
16
16
|
desc: string;
|
|
17
17
|
method?: string;
|
|
18
18
|
authSchema?: AuthSchema;
|
|
19
|
+
request?: null | Record<string, unknown>;
|
|
20
|
+
response?: null | Record<string, unknown>;
|
|
19
21
|
}
|
|
20
22
|
export interface Api {
|
|
21
23
|
[endpoint: string]: Endpoint;
|
|
@@ -38,7 +40,7 @@ export declare class Repository {
|
|
|
38
40
|
version?: string;
|
|
39
41
|
workspace?: string;
|
|
40
42
|
branch: string | undefined;
|
|
41
|
-
}): void
|
|
43
|
+
}): Promise<void>;
|
|
42
44
|
private checkout;
|
|
43
45
|
private revParse;
|
|
44
46
|
private reset;
|
|
@@ -6,6 +6,7 @@ const path = tslib_1.__importStar(require("node:path"));
|
|
|
6
6
|
const node_child_process_1 = require("node:child_process");
|
|
7
7
|
const fs = tslib_1.__importStar(require("node:fs"));
|
|
8
8
|
const rimraf_1 = tslib_1.__importDefault(require("rimraf"));
|
|
9
|
+
const json_schema_ref_parser_1 = tslib_1.__importDefault(require("@apidevtools/json-schema-ref-parser"));
|
|
9
10
|
class Repository {
|
|
10
11
|
constructor(str) {
|
|
11
12
|
this.hash = 'latest';
|
|
@@ -14,19 +15,21 @@ class Repository {
|
|
|
14
15
|
this.name = this.getName();
|
|
15
16
|
this.cache = path.resolve(`./node_modules/.endpoints-tmp/${Math.random().toString(36).slice(-8)}`);
|
|
16
17
|
}
|
|
17
|
-
clone({ version, workspace = '', branch }) {
|
|
18
|
+
async clone({ version, workspace = '', branch }) {
|
|
18
19
|
(0, node_child_process_1.execSync)(`git clone --no-checkout --quiet ${this.path} ${this.cache}`);
|
|
19
20
|
this.reset(version);
|
|
20
21
|
this.hash = this.revParse();
|
|
21
|
-
this.data = this.checkout(workspace, branch);
|
|
22
|
+
this.data = await this.checkout(workspace, branch);
|
|
22
23
|
}
|
|
23
|
-
checkout(workspace, branch) {
|
|
24
|
+
async checkout(workspace, branch) {
|
|
24
25
|
const file = path.resolve(this.cache, workspace, '.endpoints.json');
|
|
25
26
|
const targetBranch = branch ? `origin/${branch}` : (0, node_child_process_1.execSync)(`cd ${this.cache}; git rev-parse --abbrev-ref origin/HEAD`)
|
|
26
27
|
.toString()
|
|
27
28
|
.trim();
|
|
28
29
|
(0, node_child_process_1.execSync)(`cd ${this.cache}; git checkout ${targetBranch} -- ${file}`);
|
|
29
|
-
|
|
30
|
+
const schema = (await json_schema_ref_parser_1.default.dereference(JSON.parse(fs.readFileSync(file).toString())));
|
|
31
|
+
delete schema.$defs;
|
|
32
|
+
return schema;
|
|
30
33
|
}
|
|
31
34
|
revParse() {
|
|
32
35
|
const hash = (0, node_child_process_1.execSync)(`cd ${this.cache}; git rev-parse HEAD`)
|
package/lib/commands/add.js
CHANGED
|
@@ -10,9 +10,9 @@ class Add extends command_1.Command {
|
|
|
10
10
|
const { flags: { version, workspace, branch, excludes }, args } = this.parse(Add);
|
|
11
11
|
const repository = new Repository_1.Repository(args.repository);
|
|
12
12
|
try {
|
|
13
|
-
repository.clone({ version, workspace, branch });
|
|
13
|
+
await repository.clone({ version, workspace, branch });
|
|
14
14
|
const config = new Config_1.Config();
|
|
15
|
-
(0, makeFiles_1.makeFiles)({ repository, config, workspace, exclude_periods: excludes });
|
|
15
|
+
await (0, makeFiles_1.makeFiles)({ repository, config, workspace, exclude_periods: excludes });
|
|
16
16
|
config.push({
|
|
17
17
|
name: repository.name,
|
|
18
18
|
path: repository.path,
|
package/lib/commands/install.js
CHANGED
|
@@ -13,14 +13,14 @@ class Install extends command_1.Command {
|
|
|
13
13
|
if (!config.dependencies) {
|
|
14
14
|
throw new Error('Dependencies property of the endpoints.config.json does not exist. Use the add command to add dependencies before installing');
|
|
15
15
|
}
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
await Promise.all(Object.entries(config.dependencies).map(async ([_name, { repository: path, version, workspaces = [''], roots, branch, exclude_periods }]) => {
|
|
17
|
+
return Promise.all(workspaces.map(async (workspace) => {
|
|
18
18
|
const repository = new Repository_1.Repository(path);
|
|
19
19
|
repositories.push(repository);
|
|
20
|
-
repository.clone({ version, workspace, branch });
|
|
21
|
-
(0, makeFiles_1.makeFiles)({ repository, workspace, config, roots, exclude_periods });
|
|
22
|
-
}
|
|
23
|
-
}
|
|
20
|
+
await repository.clone({ version, workspace, branch });
|
|
21
|
+
await (0, makeFiles_1.makeFiles)({ repository, workspace, config, roots, exclude_periods });
|
|
22
|
+
}));
|
|
23
|
+
}));
|
|
24
24
|
}
|
|
25
25
|
catch (error) {
|
|
26
26
|
// @ts-expect-error
|
package/lib/commands/update.js
CHANGED
|
@@ -18,10 +18,10 @@ class Update extends command_1.Command {
|
|
|
18
18
|
throw new Error('The service does not exist in the dependency. Check dependencies property of the endpoints.config.json. Or use the add command to add dependencies before installing');
|
|
19
19
|
}
|
|
20
20
|
const { repository: path, version, workspaces = [''], roots, branch, exclude_periods } = config.dependencies[args.service];
|
|
21
|
-
|
|
21
|
+
await Promise.all(workspaces.map(async (workspace) => {
|
|
22
22
|
const repository = new Repository_1.Repository(path);
|
|
23
|
-
repository.clone({ version, workspace, branch });
|
|
24
|
-
(0, makeFiles_1.makeFiles)({ repository, config, workspace, roots, exclude_periods });
|
|
23
|
+
await repository.clone({ version, workspace, branch });
|
|
24
|
+
await (0, makeFiles_1.makeFiles)({ repository, config, workspace, roots, exclude_periods });
|
|
25
25
|
config.push({
|
|
26
26
|
name: repository.name,
|
|
27
27
|
path: repository.path,
|
|
@@ -31,7 +31,7 @@ class Update extends command_1.Command {
|
|
|
31
31
|
exclude_periods,
|
|
32
32
|
});
|
|
33
33
|
repositories.push(repository);
|
|
34
|
-
}
|
|
34
|
+
}));
|
|
35
35
|
config.publish();
|
|
36
36
|
}
|
|
37
37
|
catch (error) {
|
package/lib/makeFiles.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { Config, Roots } from './classes/Config';
|
|
2
2
|
import type { Repository } from './classes/Repository';
|
|
3
|
-
export declare const makeFiles: (
|
|
3
|
+
export declare const makeFiles: ({ repository, workspace, config, roots, exclude_periods }: {
|
|
4
4
|
repository: Repository;
|
|
5
|
-
workspace?: string;
|
|
5
|
+
workspace?: string | undefined;
|
|
6
6
|
config: Config;
|
|
7
|
-
roots?: Roots;
|
|
8
|
-
exclude_periods?: string[];
|
|
9
|
-
}) => void
|
|
7
|
+
roots?: Roots | undefined;
|
|
8
|
+
exclude_periods?: string[] | undefined;
|
|
9
|
+
}) => Promise<void>;
|
package/lib/makeFiles.js
CHANGED
|
@@ -9,17 +9,17 @@ const format_1 = require("./utils/format");
|
|
|
9
9
|
const makeName = (...args) => {
|
|
10
10
|
return args.filter(e => Boolean(e)).join('.');
|
|
11
11
|
};
|
|
12
|
-
const makeFiles = ({ repository, workspace, config, roots, exclude_periods }) => {
|
|
12
|
+
const makeFiles = async ({ repository, workspace, config, roots, exclude_periods }) => {
|
|
13
13
|
const files = [];
|
|
14
|
-
|
|
14
|
+
await Promise.all(Object.entries(repository.data).map(async ([version, period]) => {
|
|
15
15
|
if (exclude_periods === null || exclude_periods === void 0 ? void 0 : exclude_periods.includes(version)) {
|
|
16
|
-
|
|
16
|
+
return;
|
|
17
17
|
}
|
|
18
|
-
const content = templates.files.endpoints({ repository, version, period, config, roots });
|
|
18
|
+
const content = await templates.files.endpoints({ repository, version, period, config, roots });
|
|
19
19
|
const basename = makeName(repository.name, workspace, version);
|
|
20
20
|
files.push({ version, basename });
|
|
21
21
|
fs.writeFileSync(path.resolve(config.output, `${basename}.ts`), (0, format_1.format)(content));
|
|
22
|
-
}
|
|
22
|
+
}));
|
|
23
23
|
fs.writeFileSync(path.resolve(config.output, `${makeName(repository.name, workspace)}.ts`), (0, format_1.format)(templates.files.index({ files, repository })));
|
|
24
24
|
};
|
|
25
25
|
exports.makeFiles = makeFiles;
|
|
@@ -4,13 +4,13 @@ exports.endpoints = void 0;
|
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const templates = tslib_1.__importStar(require("../functions"));
|
|
6
6
|
const camelCase_1 = require("../../utils/camelCase");
|
|
7
|
-
const endpoints = ({ repository, version, period, config, roots, }) => {
|
|
7
|
+
const endpoints = async ({ repository, version, period, config, roots, }) => {
|
|
8
8
|
const names = [];
|
|
9
|
-
const fns = Object.entries(period.api).map(([_name, endpoint]) => {
|
|
9
|
+
const fns = await Promise.all(Object.entries(period.api).map(([_name, endpoint]) => {
|
|
10
10
|
const name = (0, camelCase_1.camelCase)(_name);
|
|
11
11
|
names.push(name);
|
|
12
12
|
return templates.endpoint(name, endpoint);
|
|
13
|
-
});
|
|
13
|
+
}));
|
|
14
14
|
const exportFns = `export const ${(0, camelCase_1.camelCase)(repository.name)}_${(0, camelCase_1.camelCase)(version)} = {${names.join(',')}}`;
|
|
15
15
|
const env = Object.assign(Object.assign({}, period.env), roots);
|
|
16
16
|
return [
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { Endpoint } from '../../classes/Repository';
|
|
2
|
-
export declare const endpoint: (name: string, e: Endpoint) => string
|
|
2
|
+
export declare const endpoint: (name: string, e: Endpoint) => Promise<string>;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.endpoint = void 0;
|
|
4
4
|
const unique_1 = require("../../utils/unique");
|
|
5
|
+
const json_schema_to_typescript_1 = require("json-schema-to-typescript");
|
|
5
6
|
const isNumberLiteral = (str) => {
|
|
6
7
|
return str && Number.isFinite(Number(str));
|
|
7
8
|
};
|
|
@@ -56,7 +57,7 @@ const makePathTemplate = (p) => {
|
|
|
56
57
|
.join('/');
|
|
57
58
|
return t.startsWith('/') ? t.slice(1) : t;
|
|
58
59
|
};
|
|
59
|
-
const endpoint = (name, e) => {
|
|
60
|
+
const endpoint = async (name, e) => {
|
|
60
61
|
const [path, queryParamsStr] = e.path.split('?');
|
|
61
62
|
const queryParams = makeQueryParams(queryParamsStr);
|
|
62
63
|
const pathParams = makePathParams(path);
|
|
@@ -68,8 +69,12 @@ const endpoint = (name, e) => {
|
|
|
68
69
|
const QUERY_PARAMS_OBJECT = `{${queryParamNames.join(',')}}`;
|
|
69
70
|
const ARGUMENTS = makeArguments(params, paramNames, pathParamNames);
|
|
70
71
|
const PATH_TEMPLATE = makePathTemplate(path);
|
|
71
|
-
|
|
72
|
-
|
|
72
|
+
const request = e.request ? await (0, json_schema_to_typescript_1.compile)(e.request, `${name}Request`) : undefined;
|
|
73
|
+
const response = e.response ? await (0, json_schema_to_typescript_1.compile)(e.response, `${name}Response`) : undefined;
|
|
74
|
+
return [
|
|
75
|
+
request,
|
|
76
|
+
response,
|
|
77
|
+
`/**
|
|
73
78
|
* ${e.desc}
|
|
74
79
|
${QUERY_PARAMS_COMMENTS}
|
|
75
80
|
*/
|
|
@@ -87,6 +92,7 @@ const endpoint = (name, e) => {
|
|
|
87
92
|
};
|
|
88
93
|
`,
|
|
89
94
|
e.method ? `${name}.method='${e.method}' as const;` : null,
|
|
90
|
-
e.authSchema ? `${name}.authSchema=${JSON.stringify(e.authSchema)} as const;` : null
|
|
95
|
+
e.authSchema ? `${name}.authSchema=${JSON.stringify(e.authSchema)} as const;` : null,
|
|
96
|
+
].filter(Boolean).join('\n');
|
|
91
97
|
};
|
|
92
98
|
exports.endpoint = endpoint;
|
package/oclif.manifest.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":"2.
|
|
1
|
+
{"version":"2.8.0","commands":{"add":{"id":"add","description":"\nadd service to dependencies & make endpoints files.\n\n1. make endpoints.config.json for version control.\n\n{\n \"dependencies\": {\n \"service-name\": {\n \"version\": \"26177ed7e673daf0cc5a69e9793dd863424d272f\",\n \"repository\": \"git@github.com:[username/repository].git\"\n }\n }\n}\n\n> service name is inferred from Repository name.\n\n2. make src/endpoints/[service-name].ts\n","pluginName":"endpoints-sdk-cli","pluginType":"core","aliases":[],"examples":["$ mes add [username/repository]","$ mes add [username/repository] --version [commmit hash]","$ mes add [username/repository] -v [commmit hash]","$ mes add [username/repository] -v latest","$ mes add [username/repository] --workspace [workspace directory]","$ mes add [username/repository] -w [workspace directory]","$ mes add [username/repository] --branch [branch name]","$ mes add [username/repository] -b [branch name]","$ mes add [username/repository] --excludes [period name]","$ mes add [username/repository] -e [period name]","$ mes add [username/repository] -e [period name] [period name]","$ mes add /Users/.../local-repository/","$ mes add ./local-repository","$ mes add git@github.com:[username/repository].git","$ mes add https://github.com/[username/repository].git"],"flags":{"version":{"name":"version","type":"option","char":"v","description":"latest or commit hash"},"workspace":{"name":"workspace","type":"option","char":"w","description":"a path to workspace containing .endpoints.json"},"branch":{"name":"branch","type":"option","char":"b","description":"branch name to clone"},"excludes":{"name":"excludes","type":"option","char":"e","description":"exclude periods"}},"args":[{"name":"repository"}]},"install":{"id":"install","description":"generate endpoints files based on endpoints.config.json","pluginName":"endpoints-sdk-cli","pluginType":"core","aliases":[],"flags":{},"args":[]},"update":{"id":"update","description":"update service version & regenerate endpoints files","pluginName":"endpoints-sdk-cli","pluginType":"core","aliases":[],"flags":{},"args":[{"name":"service"}]}}}
|
package/package.json
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "endpoints-sdk-cli",
|
|
3
3
|
"description": "endpoints sdk cli",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.8.0",
|
|
5
5
|
"author": "hrdtbs",
|
|
6
6
|
"bin": {
|
|
7
7
|
"mes": "./bin/run"
|
|
8
8
|
},
|
|
9
9
|
"bugs": "https://github.com/matsuri-tech/endpoints-sdk-cli/issues",
|
|
10
10
|
"dependencies": {
|
|
11
|
+
"@apidevtools/json-schema-ref-parser": "^11.1.0",
|
|
11
12
|
"@oclif/color": "^0.1.2",
|
|
12
13
|
"@oclif/command": "^1.8.0",
|
|
13
14
|
"@oclif/config": "^1.17.0",
|
|
14
15
|
"@oclif/plugin-help": "^3.2.0",
|
|
15
16
|
"cli-ux": "^5.4.10",
|
|
17
|
+
"json-schema-to-typescript": "^13.1.1",
|
|
16
18
|
"prettier": "^2.1.1",
|
|
17
19
|
"rimraf": "^3.0.2",
|
|
18
20
|
"tslib": "^2.0.1"
|