endpoints-sdk-cli 2.1.0 → 2.2.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 +28 -0
- package/README.md +5 -5
- package/lib/classes/Config.d.ts +20 -0
- package/lib/classes/Config.js +52 -0
- package/lib/classes/Repository.d.ts +38 -0
- package/lib/classes/Repository.js +60 -0
- package/lib/commands/add.js +17 -28
- package/lib/commands/install.js +14 -12
- package/lib/commands/update.js +19 -16
- package/lib/endpoints/m2m-core.d.ts +4 -0
- package/lib/endpoints/m2m-core.js +7 -0
- package/lib/endpoints/m2m-core.v1.d.ts +527 -0
- package/lib/endpoints/m2m-core.v1.js +1084 -0
- package/lib/endpoints/m2m-notifications.d.ts +4 -0
- package/lib/endpoints/m2m-notifications.js +7 -0
- package/lib/endpoints/m2m-notifications.v1.d.ts +50 -0
- package/lib/endpoints/m2m-notifications.v1.js +133 -0
- package/lib/endpoints/m2m-users.d.ts +4 -0
- package/lib/endpoints/m2m-users.js +7 -0
- package/lib/endpoints/m2m-users.v1.d.ts +210 -0
- package/lib/endpoints/m2m-users.v1.js +529 -0
- package/lib/index.js +1 -0
- package/lib/makeFiles.d.ts +7 -0
- package/lib/makeFiles.js +21 -0
- package/lib/templates/files/endpoints.d.ts +8 -0
- package/lib/templates/files/endpoints.js +21 -0
- package/lib/templates/files/index.d.ts +2 -0
- package/lib/templates/files/index.js +7 -0
- package/lib/templates/files/indexFile.d.ts +8 -0
- package/lib/templates/files/indexFile.js +16 -0
- package/lib/templates/functions/endpoint.d.ts +2 -0
- package/lib/templates/functions/endpoint.js +89 -0
- package/lib/templates/functions/index.d.ts +2 -0
- package/lib/templates/functions/index.js +5 -0
- package/lib/templates/functions/root.d.ts +6 -0
- package/lib/templates/functions/root.js +30 -0
- package/lib/templates/index.d.ts +2 -0
- package/lib/templates/index.js +6 -0
- package/lib/utils/format.d.ts +1 -0
- package/lib/utils/format.js +8 -0
- package/lib/utils/unique.d.ts +1 -0
- package/lib/utils/unique.js +14 -0
- package/oclif.manifest.json +1 -1
- package/package.json +17 -17
- package/lib/constants.d.ts +0 -1
- package/lib/constants.js +0 -4
- package/lib/parts/makeEndpointsFiles.d.ts +0 -6
- package/lib/parts/makeEndpointsFiles.js +0 -41
- package/lib/parts/makeEndpointsSourceFromRepository.d.ts +0 -11
- package/lib/parts/makeEndpointsSourceFromRepository.js +0 -37
- package/lib/types.d.ts +0 -30
- package/lib/types.js +0 -1
- package/lib/utils/extractServiceNameFromPath.d.ts +0 -1
- package/lib/utils/extractServiceNameFromPath.js +0 -8
- package/lib/utils/getConfig.d.ts +0 -1
- package/lib/utils/getConfig.js +0 -12
- package/lib/utils/inferRepository.d.ts +0 -1
- package/lib/utils/inferRepository.js +0 -20
- package/lib/utils/parseEndpoints.d.ts +0 -23
- package/lib/utils/parseEndpoints.js +0 -74
- package/lib/utils/parseUrl.d.ts +0 -17
- package/lib/utils/parseUrl.js +0 -43
- package/lib/utils/updateConfigFile.d.ts +0 -6
- package/lib/utils/updateConfigFile.js +0 -20
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.endpoint = void 0;
|
|
4
|
+
const unique_1 = require("../../utils/unique");
|
|
5
|
+
const isNumberLiteral = (str) => {
|
|
6
|
+
return str && isFinite(Number(str));
|
|
7
|
+
};
|
|
8
|
+
const detectType = (str) => {
|
|
9
|
+
return isNumberLiteral(str) ? 'number' : 'string';
|
|
10
|
+
};
|
|
11
|
+
const makeQueryParams = (s) => {
|
|
12
|
+
return s ? s.split('&').map(f => {
|
|
13
|
+
const [name, example] = f.split('=');
|
|
14
|
+
const type = detectType(example);
|
|
15
|
+
return {
|
|
16
|
+
name,
|
|
17
|
+
example,
|
|
18
|
+
type,
|
|
19
|
+
};
|
|
20
|
+
}) : [];
|
|
21
|
+
};
|
|
22
|
+
const makePathParams = (s) => {
|
|
23
|
+
return s.split('/').map(f => {
|
|
24
|
+
return f.startsWith(':') ? {
|
|
25
|
+
name: f.slice(1),
|
|
26
|
+
type: 'string',
|
|
27
|
+
} : undefined;
|
|
28
|
+
}).filter((p) => Boolean(p));
|
|
29
|
+
};
|
|
30
|
+
const pickNames = (ps) => {
|
|
31
|
+
return ps.map(p => p.name);
|
|
32
|
+
};
|
|
33
|
+
const makeQueryParamsComments = (qs) => {
|
|
34
|
+
return qs.length > 0 ?
|
|
35
|
+
qs
|
|
36
|
+
.map(q => {
|
|
37
|
+
return `* @param {${q.type}} ${q.name} ${q.example}`;
|
|
38
|
+
})
|
|
39
|
+
.join('\n') :
|
|
40
|
+
'*';
|
|
41
|
+
};
|
|
42
|
+
const makeArguments = (params, paramNames, pathParamNames) => {
|
|
43
|
+
if (paramNames.length === 0)
|
|
44
|
+
return '';
|
|
45
|
+
return `{${paramNames.join(',')}} : {${params
|
|
46
|
+
.map(p => {
|
|
47
|
+
const op = pathParamNames.includes(p.name) ? '' : '?';
|
|
48
|
+
return `${p.name}${op}:${p.type};`;
|
|
49
|
+
})
|
|
50
|
+
.join('')}}`;
|
|
51
|
+
};
|
|
52
|
+
const makePathTemplate = (p) => {
|
|
53
|
+
const t = p
|
|
54
|
+
.split('/')
|
|
55
|
+
.map(f => (f.startsWith(':') ? `\${${f.slice(1)}}` : f))
|
|
56
|
+
.join('/');
|
|
57
|
+
return t.startsWith('/') ? t.slice(1) : t;
|
|
58
|
+
};
|
|
59
|
+
exports.endpoint = (name, e) => {
|
|
60
|
+
const [path, queryParamsStr] = e.path.split('?');
|
|
61
|
+
const queryParams = makeQueryParams(queryParamsStr);
|
|
62
|
+
const pathParams = makePathParams(path);
|
|
63
|
+
const queryParamNames = pickNames(queryParams);
|
|
64
|
+
const pathParamNames = pickNames(pathParams);
|
|
65
|
+
const paramNames = unique_1.unique([...queryParamNames, ...pathParamNames]);
|
|
66
|
+
const params = unique_1.unique([...queryParams, ...pathParams]);
|
|
67
|
+
const QUERY_PARAMS_COMMENTS = makeQueryParamsComments(queryParams);
|
|
68
|
+
const QUERY_PARAMS_OBJECT = `{${queryParamNames.join(',')}}`;
|
|
69
|
+
const ARGUMENTS = makeArguments(params, paramNames, pathParamNames);
|
|
70
|
+
const PATH_TEMPLATE = makePathTemplate(path);
|
|
71
|
+
return `
|
|
72
|
+
/**
|
|
73
|
+
* ${e.desc}
|
|
74
|
+
${QUERY_PARAMS_COMMENTS}
|
|
75
|
+
*/
|
|
76
|
+
export const ${name}=(${ARGUMENTS})=>{
|
|
77
|
+
const __root = root();
|
|
78
|
+
const __queries = Object.entries(${QUERY_PARAMS_OBJECT})
|
|
79
|
+
.filter(([_, value])=> {
|
|
80
|
+
return value !== undefined
|
|
81
|
+
})
|
|
82
|
+
.map(([key, value])=> {
|
|
83
|
+
return \`\${key}=\${value}\`
|
|
84
|
+
}).join("&");
|
|
85
|
+
const __path = \`\${__root}/\${\`${PATH_TEMPLATE}\`}\`;
|
|
86
|
+
return __queries ? \`\${__path}?\${__queries}\` : __path;
|
|
87
|
+
}
|
|
88
|
+
`;
|
|
89
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.root = void 0;
|
|
4
|
+
const normalizeName = (n) => {
|
|
5
|
+
return n === 'dev' ?
|
|
6
|
+
'development' :
|
|
7
|
+
n === 'prod' ?
|
|
8
|
+
'production' : n;
|
|
9
|
+
};
|
|
10
|
+
const normalizeUrl = (u) => {
|
|
11
|
+
return u.endsWith('/') ? u.slice(0, -1) : u;
|
|
12
|
+
};
|
|
13
|
+
exports.root = ({ period, config }) => {
|
|
14
|
+
const content = Object.entries(period.env).map(([n, u]) => {
|
|
15
|
+
return `
|
|
16
|
+
if(${config.environment_identifier}==="${normalizeName(n)}"){
|
|
17
|
+
__root = '${normalizeUrl(u)}'
|
|
18
|
+
}
|
|
19
|
+
`;
|
|
20
|
+
}).join('');
|
|
21
|
+
return `
|
|
22
|
+
/**
|
|
23
|
+
* A function that returns the URL part common to the endpoints.
|
|
24
|
+
*/
|
|
25
|
+
export const root = () => {
|
|
26
|
+
let __root = "";
|
|
27
|
+
${content}
|
|
28
|
+
return __root
|
|
29
|
+
}`;
|
|
30
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.functions = exports.files = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
exports.files = tslib_1.__importStar(require("./files"));
|
|
6
|
+
exports.functions = tslib_1.__importStar(require("./functions"));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const format: (content: string) => string;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.format = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const prettier = tslib_1.__importStar(require("prettier"));
|
|
6
|
+
exports.format = (content) => {
|
|
7
|
+
return prettier.format(content, { parser: 'typescript' });
|
|
8
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const unique: <T>(arr: T[]) => T[];
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.unique = void 0;
|
|
4
|
+
exports.unique = (arr) => {
|
|
5
|
+
const a = arr.concat();
|
|
6
|
+
for (let i = 0; i < a.length; ++i) {
|
|
7
|
+
for (let j = i + 1; j < a.length; ++j) {
|
|
8
|
+
if (a[i] === a[j]) {
|
|
9
|
+
a.splice(j--, 1);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
return a;
|
|
14
|
+
};
|
package/oclif.manifest.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":"2.
|
|
1
|
+
{"version":"2.2.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 /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"}},"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,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "endpoints-sdk-cli",
|
|
3
3
|
"description": "endpoints sdk cli",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.2.0",
|
|
5
5
|
"author": "hrdtbs",
|
|
6
6
|
"bin": {
|
|
7
7
|
"mes": "./bin/run"
|
|
@@ -9,33 +9,33 @@
|
|
|
9
9
|
"bugs": "https://github.com/matsuri-tech/endpoints-sdk-cli/issues",
|
|
10
10
|
"dependencies": {
|
|
11
11
|
"@oclif/color": "^0.1.2",
|
|
12
|
-
"@oclif/command": "^1.
|
|
13
|
-
"@oclif/config": "^1.
|
|
14
|
-
"@oclif/plugin-help": "^3.
|
|
15
|
-
"cli-ux": "^5.4.
|
|
16
|
-
"prettier": "^2.
|
|
12
|
+
"@oclif/command": "^1.8.0",
|
|
13
|
+
"@oclif/config": "^1.17.0",
|
|
14
|
+
"@oclif/plugin-help": "^3.2.0",
|
|
15
|
+
"cli-ux": "^5.4.10",
|
|
16
|
+
"prettier": "^2.1.1",
|
|
17
17
|
"rimraf": "^3.0.2",
|
|
18
|
-
"tslib": "^2.0.
|
|
18
|
+
"tslib": "^2.0.1"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
21
|
"@oclif/dev-cli": "^1",
|
|
22
22
|
"@oclif/test": "^1.2.6",
|
|
23
|
-
"@types/chai": "^4.2.
|
|
24
|
-
"@types/mocha": "^8.0.
|
|
25
|
-
"@types/node": "^14.
|
|
26
|
-
"@types/prettier": "^2.0
|
|
23
|
+
"@types/chai": "^4.2.12",
|
|
24
|
+
"@types/mocha": "^8.0.3",
|
|
25
|
+
"@types/node": "^14.6.1",
|
|
26
|
+
"@types/prettier": "^2.1.0",
|
|
27
27
|
"@types/rimraf": "^3.0.0",
|
|
28
28
|
"@types/supports-color": "^5.3.0",
|
|
29
29
|
"chai": "^4",
|
|
30
|
-
"eslint": "^7.
|
|
30
|
+
"eslint": "^7.7.0",
|
|
31
31
|
"eslint-config-oclif": "^3.1",
|
|
32
32
|
"eslint-config-oclif-typescript": "^0.2.0",
|
|
33
33
|
"globby": "^11.0.1",
|
|
34
|
-
"mocha": "^8.
|
|
34
|
+
"mocha": "^8.1.2",
|
|
35
35
|
"nyc": "^15.1.0",
|
|
36
|
-
"standard-version": "^
|
|
37
|
-
"ts-node": "^
|
|
38
|
-
"typescript": "^
|
|
36
|
+
"standard-version": "^9.0.0",
|
|
37
|
+
"ts-node": "^9.0.0",
|
|
38
|
+
"typescript": "^4.0.2"
|
|
39
39
|
},
|
|
40
40
|
"engines": {
|
|
41
41
|
"node": ">=8.0.0"
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
"posttest": "eslint . --ext .ts --config .eslintrc",
|
|
68
68
|
"prepack": "rm -rf lib && tsc -b && oclif-dev manifest && oclif-dev readme",
|
|
69
69
|
"test": "nyc --extension .ts mocha --forbid-only \"test/**/*.test.ts\"",
|
|
70
|
-
"release": "yarn dev && yarn prepack &&
|
|
70
|
+
"release": "yarn dev && standard-version && yarn prepack && git add README.md && git commit --amend --no-edit && git push --follow-tags origin master"
|
|
71
71
|
},
|
|
72
72
|
"types": "lib/index.d.ts"
|
|
73
73
|
}
|
package/lib/constants.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const CONFIG_FILE: "endpoints.config.json";
|
package/lib/constants.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.makeEndpointsFiles = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const path = tslib_1.__importStar(require("path"));
|
|
6
|
-
const fs = tslib_1.__importStar(require("fs"));
|
|
7
|
-
const parseEndpoints_1 = require("../utils/parseEndpoints");
|
|
8
|
-
const camelCase_1 = require("../utils/camelCase");
|
|
9
|
-
const prettier = tslib_1.__importStar(require("prettier"));
|
|
10
|
-
const cli_ux_1 = tslib_1.__importDefault(require("cli-ux"));
|
|
11
|
-
const getWorkspaceName = (dir) => {
|
|
12
|
-
return path.basename(dir, path.extname(dir));
|
|
13
|
-
};
|
|
14
|
-
const DEFAULT_OUTPUT_DIR = fs.existsSync(path.resolve('./src')) ? path.resolve('./src/endpoints/') : path.resolve('./endpoints/');
|
|
15
|
-
const resolveFileBasename = (...args) => {
|
|
16
|
-
return args.filter(e => Boolean(e)).join('.');
|
|
17
|
-
};
|
|
18
|
-
exports.makeEndpointsFiles = ({ workspace, repository_name, data, config, }) => {
|
|
19
|
-
const outputDir = (config === null || config === void 0 ? void 0 : config.output) ? path.resolve(config === null || config === void 0 ? void 0 : config.output) : DEFAULT_OUTPUT_DIR;
|
|
20
|
-
cli_ux_1.default.action.start(`generating ${repository_name} endpoints files.`);
|
|
21
|
-
if (!fs.existsSync(outputDir)) {
|
|
22
|
-
fs.mkdirSync(outputDir);
|
|
23
|
-
}
|
|
24
|
-
const workspaceName = workspace ? getWorkspaceName(workspace) : '';
|
|
25
|
-
const repositoryName = camelCase_1.camelCase(repository_name);
|
|
26
|
-
const files = [];
|
|
27
|
-
parseEndpoints_1.parseEndpoints(data, config === null || config === void 0 ? void 0 : config.environment_identifier).map(
|
|
28
|
-
// eslint-disable-next-line array-callback-return
|
|
29
|
-
({ version, endpoints }) => {
|
|
30
|
-
const main = `export const ${repositoryName}_${camelCase_1.camelCase(version)} = {${Object.keys(endpoints).join(',')}}`;
|
|
31
|
-
const basename = resolveFileBasename(repository_name, workspaceName, version);
|
|
32
|
-
files.push({
|
|
33
|
-
basename,
|
|
34
|
-
version: camelCase_1.camelCase(version),
|
|
35
|
-
});
|
|
36
|
-
fs.writeFileSync(path.relative(outputDir, `${basename}.ts`), prettier.format(['/* eslint-disable */', ...Object.values(endpoints), main].join(''), { parser: 'typescript' }));
|
|
37
|
-
});
|
|
38
|
-
fs.writeFileSync(path.resolve(outputDir, `${resolveFileBasename(repository_name, workspaceName)}.ts`), prettier.format(`/* eslint-disable */ \n ${files.map(({ basename, version }) => `import * as ${version} from './${basename}'`).join('\n')}
|
|
39
|
-
export const ${repositoryName} = {${files.map(({ version }) => version).join(',')}}`, { parser: 'typescript' }));
|
|
40
|
-
cli_ux_1.default.action.stop();
|
|
41
|
-
};
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export declare const makeEndpointsSourceFromRepository: (cacheDirectory?: string) => {
|
|
2
|
-
getEndpointsSourceFromRepository: ({ repository, version, workspace }: {
|
|
3
|
-
repository: string;
|
|
4
|
-
version?: string | undefined;
|
|
5
|
-
workspace?: string | undefined;
|
|
6
|
-
}) => {
|
|
7
|
-
hash: string;
|
|
8
|
-
data: Endpoints;
|
|
9
|
-
};
|
|
10
|
-
cleanEndpointsSourceFromRepository: () => void;
|
|
11
|
-
};
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.makeEndpointsSourceFromRepository = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const child_process_1 = require("child_process");
|
|
6
|
-
const fs_1 = require("fs");
|
|
7
|
-
const rimraf_1 = tslib_1.__importDefault(require("rimraf"));
|
|
8
|
-
const cli_ux_1 = tslib_1.__importDefault(require("cli-ux"));
|
|
9
|
-
const path_1 = tslib_1.__importDefault(require("path"));
|
|
10
|
-
exports.makeEndpointsSourceFromRepository = (cacheDirectory = './node_modules/.endpoints-tmp/') => {
|
|
11
|
-
const getEndpointsSourceFromRepository = ({ repository, version, workspace = '' }) => {
|
|
12
|
-
const id = Math.random().toString(36).slice(-8);
|
|
13
|
-
const tmp = `${cacheDirectory}${id}`;
|
|
14
|
-
cli_ux_1.default.action.start(`cloning ${repository}`);
|
|
15
|
-
child_process_1.execSync(`git clone --no-checkout --quiet ${repository} ${tmp}`);
|
|
16
|
-
if (version && version !== 'latest') {
|
|
17
|
-
child_process_1.execSync(`cd ${tmp}; git reset --hard ${version}`);
|
|
18
|
-
}
|
|
19
|
-
const hash = child_process_1.execSync(`cd ${tmp}; git rev-parse HEAD`).toString().trim();
|
|
20
|
-
const file = path_1.default.resolve(tmp, workspace, '.endpoints.json');
|
|
21
|
-
child_process_1.execSync(`cd ${tmp} && git checkout origin/master -- ${file}`);
|
|
22
|
-
const data = JSON.parse(fs_1.readFileSync(file).toString());
|
|
23
|
-
cli_ux_1.default.action.stop();
|
|
24
|
-
return {
|
|
25
|
-
hash, data,
|
|
26
|
-
};
|
|
27
|
-
};
|
|
28
|
-
const cleanEndpointsSourceFromRepository = () => {
|
|
29
|
-
cli_ux_1.default.action.start('cleaning temporary directory');
|
|
30
|
-
rimraf_1.default.sync(cacheDirectory);
|
|
31
|
-
cli_ux_1.default.action.stop();
|
|
32
|
-
};
|
|
33
|
-
return {
|
|
34
|
-
getEndpointsSourceFromRepository,
|
|
35
|
-
cleanEndpointsSourceFromRepository,
|
|
36
|
-
};
|
|
37
|
-
};
|
package/lib/types.d.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
interface Config {
|
|
2
|
-
output?: string;
|
|
3
|
-
environment_identifier?: string;
|
|
4
|
-
dependencies?: {
|
|
5
|
-
[service: string]: {
|
|
6
|
-
version: string;
|
|
7
|
-
repository: string;
|
|
8
|
-
workspaces?: string[];
|
|
9
|
-
};
|
|
10
|
-
};
|
|
11
|
-
}
|
|
12
|
-
interface Endpoints {
|
|
13
|
-
[prefixName: string]: {
|
|
14
|
-
env: {
|
|
15
|
-
local: string;
|
|
16
|
-
dev: string;
|
|
17
|
-
prod: string;
|
|
18
|
-
[envName: string]: string;
|
|
19
|
-
};
|
|
20
|
-
api: {
|
|
21
|
-
[endpointName: string]: {
|
|
22
|
-
path: string;
|
|
23
|
-
desc?: string;
|
|
24
|
-
};
|
|
25
|
-
};
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
declare type UnPartial<T> = {
|
|
29
|
-
[K in keyof T]: Exclude<T[K], undefined>;
|
|
30
|
-
};
|
package/lib/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const extractServiceNameFromPath: (path: string) => string;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.extractServiceNameFromPath = void 0;
|
|
4
|
-
exports.extractServiceNameFromPath = (path) => {
|
|
5
|
-
const splits = path.split('/');
|
|
6
|
-
const name = splits[splits.length - 1].split(/\./)[0];
|
|
7
|
-
return name;
|
|
8
|
-
};
|
package/lib/utils/getConfig.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const getConfig: () => Config;
|
package/lib/utils/getConfig.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getConfig = void 0;
|
|
4
|
-
const fs_1 = require("fs");
|
|
5
|
-
exports.getConfig = () => {
|
|
6
|
-
const path = 'endpoints.config.json';
|
|
7
|
-
if (!fs_1.existsSync(path)) {
|
|
8
|
-
throw new Error('The endpoints.config.json is not found. Use the add command to add dependencies before installing');
|
|
9
|
-
}
|
|
10
|
-
const config = JSON.parse(fs_1.readFileSync(path).toString());
|
|
11
|
-
return config;
|
|
12
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const inferRepository: (str: string) => string;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.inferRepository = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const path = tslib_1.__importStar(require("path"));
|
|
6
|
-
exports.inferRepository = (str) => {
|
|
7
|
-
if (str.startsWith('https://')) {
|
|
8
|
-
return str;
|
|
9
|
-
}
|
|
10
|
-
if (str.startsWith('git@')) {
|
|
11
|
-
return str;
|
|
12
|
-
}
|
|
13
|
-
if (str.startsWith('./')) {
|
|
14
|
-
return path.resolve(str);
|
|
15
|
-
}
|
|
16
|
-
if (str.startsWith('/')) {
|
|
17
|
-
return str;
|
|
18
|
-
}
|
|
19
|
-
return `git@github.com:${str}.git`;
|
|
20
|
-
};
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
interface Service {
|
|
2
|
-
[prefixName: string]: {
|
|
3
|
-
env: {
|
|
4
|
-
local: string;
|
|
5
|
-
dev: string;
|
|
6
|
-
prod: string;
|
|
7
|
-
[envName: string]: string;
|
|
8
|
-
};
|
|
9
|
-
api: {
|
|
10
|
-
[endpointName: string]: {
|
|
11
|
-
path: string;
|
|
12
|
-
desc?: string;
|
|
13
|
-
};
|
|
14
|
-
};
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
export declare const parseEndpoints: (service: Service, environment_identifier?: string) => {
|
|
18
|
-
version: string;
|
|
19
|
-
endpoints: {
|
|
20
|
-
[endpoint: string]: string;
|
|
21
|
-
};
|
|
22
|
-
}[];
|
|
23
|
-
export {};
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseEndpoints = void 0;
|
|
4
|
-
const camelCase_1 = require("./camelCase");
|
|
5
|
-
const parseUrl_1 = require("./parseUrl");
|
|
6
|
-
const isNumberLiteral = (str) => {
|
|
7
|
-
return str !== '' && isFinite(Number(str));
|
|
8
|
-
};
|
|
9
|
-
exports.parseEndpoints = (service, environment_identifier = 'process.env.NODE_ENV') => {
|
|
10
|
-
return Object.entries(service).map(([version, { env, api }]) => {
|
|
11
|
-
const root = `
|
|
12
|
-
/**
|
|
13
|
-
* A function that returns the URL part common to the endpoints.
|
|
14
|
-
*/
|
|
15
|
-
export const root = ()=>{let __root = "";${Object.entries(env)
|
|
16
|
-
.map(([envName, url]) => `if(${environment_identifier}==='${envName === 'dev' ?
|
|
17
|
-
'development' :
|
|
18
|
-
envName === 'prod' ?
|
|
19
|
-
'production' :
|
|
20
|
-
envName}'){__root = '${url.endsWith('/') ? url.slice(0, -1) : url}'}`)
|
|
21
|
-
.join('')}return __root}`;
|
|
22
|
-
let endpoints = { root };
|
|
23
|
-
// eslint-disable-next-line array-callback-return
|
|
24
|
-
Object.entries(api).map(([_endpointName, { path: _path, desc }]) => {
|
|
25
|
-
const endpointName = camelCase_1.camelCase(_endpointName);
|
|
26
|
-
if (endpointName === 'root')
|
|
27
|
-
return null;
|
|
28
|
-
const { path, queryParams, paramNames, queryParamNames, pathParamNames, params, } = parseUrl_1.parseUrl(_path);
|
|
29
|
-
const QUERY_PARAMS_COMMENTS = queryParams
|
|
30
|
-
.map(({ name, example }) => {
|
|
31
|
-
return `* @param {${isNumberLiteral(example) ? 'number' : 'string'}} ${name} ${example}`;
|
|
32
|
-
})
|
|
33
|
-
.join('\n');
|
|
34
|
-
const QUERY_PARAMS_OBJECT = `{${queryParamNames.join(',')}}`;
|
|
35
|
-
const ARGUMENTS = paramNames.length === 0 ? '' : `{${paramNames.join(',')}}`;
|
|
36
|
-
const ARGUMENTS_TYPE = params.length === 0 ?
|
|
37
|
-
'' :
|
|
38
|
-
`{${params
|
|
39
|
-
.map(({ name, example }) => {
|
|
40
|
-
const type = example !== undefined && isNumberLiteral(example) ?
|
|
41
|
-
'number' :
|
|
42
|
-
'string';
|
|
43
|
-
return pathParamNames.includes(name) ?
|
|
44
|
-
`${name}:${type};` :
|
|
45
|
-
`${name}?:${type};`;
|
|
46
|
-
})
|
|
47
|
-
.join('')}}`;
|
|
48
|
-
const FIXED_PATH = path
|
|
49
|
-
.split('/')
|
|
50
|
-
.map(pathFrag => pathFrag.startsWith(':') ? `\${${pathFrag.slice(1)}}` : pathFrag)
|
|
51
|
-
.join('/');
|
|
52
|
-
const NORMALIZED_FIXED_PATH = FIXED_PATH.startsWith('/') ? FIXED_PATH.slice(1) : FIXED_PATH;
|
|
53
|
-
const endpoint = `
|
|
54
|
-
/**
|
|
55
|
-
* ${desc}
|
|
56
|
-
* @version ${version}
|
|
57
|
-
${QUERY_PARAMS_COMMENTS || '*'}
|
|
58
|
-
*/
|
|
59
|
-
export const ${endpointName}=(${ARGUMENTS &&
|
|
60
|
-
`${ARGUMENTS}:${ARGUMENTS_TYPE}`})=>{
|
|
61
|
-
const __root = root();
|
|
62
|
-
const __queries = Object.entries(${QUERY_PARAMS_OBJECT}).filter(([_, value])=> value !== undefined).map(([key, value])=> \`\${key}=\${value}\`).join("&");
|
|
63
|
-
const __path = \`\${__root}/\${\`${NORMALIZED_FIXED_PATH}\`}\`;
|
|
64
|
-
return __queries ? \`\${__path}?\${__queries}\` : __path;
|
|
65
|
-
}
|
|
66
|
-
`;
|
|
67
|
-
endpoints = Object.assign(Object.assign({}, endpoints), { [endpointName]: endpoint });
|
|
68
|
-
});
|
|
69
|
-
return {
|
|
70
|
-
version,
|
|
71
|
-
endpoints,
|
|
72
|
-
};
|
|
73
|
-
});
|
|
74
|
-
};
|
package/lib/utils/parseUrl.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export declare const parseUrl: (url: string) => {
|
|
2
|
-
path: string;
|
|
3
|
-
queryParams: {
|
|
4
|
-
name: string;
|
|
5
|
-
example: string;
|
|
6
|
-
}[];
|
|
7
|
-
queryParamNames: string[];
|
|
8
|
-
pathParams: {
|
|
9
|
-
name: string;
|
|
10
|
-
}[];
|
|
11
|
-
pathParamNames: string[];
|
|
12
|
-
params: {
|
|
13
|
-
name: string;
|
|
14
|
-
example?: string | undefined;
|
|
15
|
-
}[];
|
|
16
|
-
paramNames: string[];
|
|
17
|
-
};
|
package/lib/utils/parseUrl.js
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseUrl = void 0;
|
|
4
|
-
exports.parseUrl = (url) => {
|
|
5
|
-
const [path, queryParamsStr] = url.split('?');
|
|
6
|
-
const queryParams = queryParamsStr ? queryParamsStr.split('&').map(frags => {
|
|
7
|
-
const [name, example] = frags.split('=');
|
|
8
|
-
return {
|
|
9
|
-
name,
|
|
10
|
-
example,
|
|
11
|
-
};
|
|
12
|
-
}) : [];
|
|
13
|
-
const pathParams = path.split('/').map(pathFrag => {
|
|
14
|
-
if (pathFrag.startsWith(':')) {
|
|
15
|
-
return {
|
|
16
|
-
name: pathFrag.slice(1),
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
return undefined;
|
|
20
|
-
}).filter((query) => {
|
|
21
|
-
return Boolean(query);
|
|
22
|
-
});
|
|
23
|
-
const queryParamNames = queryParams.map(queryParam => queryParam.name);
|
|
24
|
-
const pathParamNames = pathParams.map(pathParam => pathParam.name);
|
|
25
|
-
const paramNames = [...new Set([...queryParamNames, ...pathParamNames])];
|
|
26
|
-
const flags = {};
|
|
27
|
-
const params = [...queryParams, ...pathParams].filter(entry => {
|
|
28
|
-
if (flags[entry.name]) {
|
|
29
|
-
return false;
|
|
30
|
-
}
|
|
31
|
-
flags[entry.name] = true;
|
|
32
|
-
return true;
|
|
33
|
-
});
|
|
34
|
-
return {
|
|
35
|
-
path,
|
|
36
|
-
queryParams,
|
|
37
|
-
queryParamNames,
|
|
38
|
-
pathParams,
|
|
39
|
-
pathParamNames,
|
|
40
|
-
params,
|
|
41
|
-
paramNames,
|
|
42
|
-
};
|
|
43
|
-
};
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.updateConfigFile = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const fs_1 = require("fs");
|
|
6
|
-
const prettier = tslib_1.__importStar(require("prettier"));
|
|
7
|
-
const constants_1 = require("../constants");
|
|
8
|
-
exports.updateConfigFile = (config, { repository, service, version, workspace }) => {
|
|
9
|
-
var _a, _b;
|
|
10
|
-
const configWorkspace = (_b = (_a = config.dependencies) === null || _a === void 0 ? void 0 : _a[service]) === null || _b === void 0 ? void 0 : _b.workspaces;
|
|
11
|
-
const data = Object.assign(Object.assign({}, config), { dependencies: Object.assign(Object.assign({}, config.dependencies), { [service]: {
|
|
12
|
-
version,
|
|
13
|
-
repository,
|
|
14
|
-
workspaces: workspace ? configWorkspace ? [...new Set([
|
|
15
|
-
...configWorkspace,
|
|
16
|
-
workspace,
|
|
17
|
-
])] : [...new Set([workspace])] : undefined,
|
|
18
|
-
} }) });
|
|
19
|
-
return fs_1.writeFileSync(constants_1.CONFIG_FILE, prettier.format(JSON.stringify(data, null, 2), { parser: 'json' }));
|
|
20
|
-
};
|