endpoints-sdk-cli 2.3.3 → 2.4.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 CHANGED
@@ -9,6 +9,7 @@ Endpoints SDK for JavaScript
9
9
  * [Usage](#usage)
10
10
  * [Commands](#commands)
11
11
  * [Support of `create-react-app`](#support-of-create-react-app)
12
+ * [Override root url](#override-root-url)
12
13
  <!-- tocstop -->
13
14
  # Usage
14
15
  <!-- usage -->
@@ -17,7 +18,7 @@ $ npm install -g endpoints-sdk-cli
17
18
  $ mes COMMAND
18
19
  running command...
19
20
  $ mes (-v|--version|version)
20
- endpoints-sdk-cli/2.3.3 darwin-x64 node-v16.16.0
21
+ endpoints-sdk-cli/2.4.0 darwin-arm64 node-v16.17.0
21
22
  $ mes --help [COMMAND]
22
23
  USAGE
23
24
  $ mes COMMAND
@@ -74,7 +75,7 @@ EXAMPLES
74
75
  $ mes add https://github.com/[username/repository].git
75
76
  ```
76
77
 
77
- _See code: [src/commands/add.ts](https://github.com/matsuri-tech/endpoints-sdk-cli/blob/v2.3.3/src/commands/add.ts)_
78
+ _See code: [src/commands/add.ts](https://github.com/matsuri-tech/endpoints-sdk-cli/blob/v2.4.0/src/commands/add.ts)_
78
79
 
79
80
  ## `mes help [COMMAND]`
80
81
 
@@ -102,7 +103,7 @@ USAGE
102
103
  $ mes install
103
104
  ```
104
105
 
105
- _See code: [src/commands/install.ts](https://github.com/matsuri-tech/endpoints-sdk-cli/blob/v2.3.3/src/commands/install.ts)_
106
+ _See code: [src/commands/install.ts](https://github.com/matsuri-tech/endpoints-sdk-cli/blob/v2.4.0/src/commands/install.ts)_
106
107
 
107
108
  ## `mes update [SERVICE]`
108
109
 
@@ -113,7 +114,7 @@ USAGE
113
114
  $ mes update [SERVICE]
114
115
  ```
115
116
 
116
- _See code: [src/commands/update.ts](https://github.com/matsuri-tech/endpoints-sdk-cli/blob/v2.3.3/src/commands/update.ts)_
117
+ _See code: [src/commands/update.ts](https://github.com/matsuri-tech/endpoints-sdk-cli/blob/v2.4.0/src/commands/update.ts)_
117
118
  <!-- commandsstop -->
118
119
 
119
120
 
@@ -124,3 +125,21 @@ _See code: [src/commands/update.ts](https://github.com/matsuri-tech/endpoints-sd
124
125
  "environment_identifier": "process.env.REACT_APP_ENV",
125
126
  }
126
127
  ```
128
+
129
+ # Override root url
130
+
131
+ ```json
132
+ {
133
+ "dependencies": {
134
+ "my-service": {
135
+ "version": "ba832b61d0319f42b3cbb30c815cbdecfece959a",
136
+ "repository": "git@github.com:hoge/my-service.git",
137
+ "roots":{
138
+ "dev": "https://dev.hoge.com",
139
+ "prod": "https://hoge.com",
140
+ "local": "http://localhost:3000"
141
+ }
142
+ },
143
+ }
144
+ }
145
+ ```
@@ -1,8 +1,12 @@
1
+ export interface Roots {
2
+ [env: string]: string;
3
+ }
1
4
  export declare class Config {
2
5
  dependencies: {
3
6
  [service: string]: {
4
7
  version: string;
5
8
  repository: string;
9
+ roots?: Roots;
6
10
  workspaces?: string[];
7
11
  };
8
12
  };
@@ -29,16 +29,12 @@ class Config {
29
29
  }
30
30
  }
31
31
  push({ name, path, version, workspace }) {
32
- var _a, _b;
32
+ var _a, _b, _c;
33
33
  const workspaces = (0, unique_1.unique)([
34
34
  ...(((_b = (_a = this.dependencies) === null || _a === void 0 ? void 0 : _a[name]) === null || _b === void 0 ? void 0 : _b.workspaces) || []),
35
35
  workspace,
36
36
  ]).filter((w) => Boolean(w));
37
- this.dependencies = Object.assign(Object.assign({}, this.dependencies), { [name]: {
38
- version,
39
- repository: path,
40
- workspaces: workspaces.length > 0 ? workspaces : undefined,
41
- } });
37
+ this.dependencies = Object.assign(Object.assign({}, this.dependencies), { [name]: Object.assign(Object.assign({}, (_c = this.dependencies) === null || _c === void 0 ? void 0 : _c[name]), { version, repository: path, workspaces: workspaces.length > 0 ? workspaces : undefined }) });
42
38
  }
43
39
  publish() {
44
40
  const data = {
@@ -13,12 +13,12 @@ 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
- for (const { repository: path, version, workspaces = [''] } of Object.values(config.dependencies)) {
16
+ for (const { repository: path, version, workspaces = [''], roots } of Object.values(config.dependencies)) {
17
17
  for (const workspace of workspaces) {
18
18
  const repository = new Repository_1.Repository(path);
19
19
  repositories.push(repository);
20
20
  repository.clone({ version, workspace });
21
- (0, makeFiles_1.makeFiles)({ repository, workspace, config });
21
+ (0, makeFiles_1.makeFiles)({ repository, workspace, config, roots });
22
22
  }
23
23
  }
24
24
  }
@@ -1,7 +1,8 @@
1
- import type { Config } from './classes/Config';
1
+ import type { Config, Roots } from './classes/Config';
2
2
  import type { Repository } from './classes/Repository';
3
3
  export declare const makeFiles: (args: {
4
4
  repository: Repository;
5
5
  workspace?: string;
6
6
  config: Config;
7
+ roots?: Roots;
7
8
  }) => void;
package/lib/makeFiles.js CHANGED
@@ -9,10 +9,10 @@ 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 }) => {
12
+ const makeFiles = ({ repository, workspace, config, roots }) => {
13
13
  const files = [];
14
14
  for (const [version, period] of Object.entries(repository.data)) {
15
- const content = templates.files.endpoints({ repository, version, period, config });
15
+ const content = templates.files.endpoints({ repository, version, period, config, roots });
16
16
  const basename = makeName(repository.name, workspace, version);
17
17
  files.push({ version, basename });
18
18
  fs.writeFileSync(path.resolve(config.output, `${basename}.ts`), (0, format_1.format)(content));
@@ -1,8 +1,9 @@
1
- import type { Config } from '../../classes/Config';
1
+ import type { Config, Roots } from '../../classes/Config';
2
2
  import type { Repository, Period } from '../../classes/Repository';
3
- export declare const endpoints: ({ repository, version, period, config, }: {
3
+ export declare const endpoints: ({ repository, version, period, config, roots, }: {
4
4
  repository: Repository;
5
5
  version: string;
6
6
  period: Period;
7
7
  config: Config;
8
+ roots?: Roots | undefined;
8
9
  }) => string;
@@ -4,7 +4,7 @@ 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, }) => {
7
+ const endpoints = ({ repository, version, period, config, roots, }) => {
8
8
  const names = [];
9
9
  const fns = Object.entries(period.api).map(([_name, endpoint]) => {
10
10
  const name = (0, camelCase_1.camelCase)(_name);
@@ -12,9 +12,10 @@ const endpoints = ({ repository, version, period, config, }) => {
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
+ const env = Object.assign(Object.assign({}, period.env), roots);
15
16
  return [
16
17
  '/* eslint-disable */',
17
- templates.root({ period, config }),
18
+ templates.root({ env, config }),
18
19
  ...fns,
19
20
  exportFns,
20
21
  ].join('');
@@ -1,6 +1,6 @@
1
1
  import type { Config } from '../../classes/Config';
2
2
  import type { Period } from '../../classes/Repository';
3
- export declare const root: (args: {
4
- period: Period;
3
+ export declare const root: ({ env, config }: {
4
+ env: Period['env'];
5
5
  config: Config;
6
- }) => void;
6
+ }) => string;
@@ -10,8 +10,8 @@ const normalizeName = (n) => {
10
10
  const normalizeUrl = (u) => {
11
11
  return u.endsWith('/') ? u.slice(0, -1) : u;
12
12
  };
13
- const root = ({ period, config }) => {
14
- const content = Object.entries(period.env).map(([n, u]) => {
13
+ const root = ({ env, config }) => {
14
+ const content = Object.entries(env).map(([n, u]) => {
15
15
  return `
16
16
  if(${config.environment_identifier}==="${normalizeName(n)}"){
17
17
  __root = '${normalizeUrl(u)}'
@@ -1 +1 @@
1
- {"version":"2.3.3","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"}]}}}
1
+ {"version":"2.4.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.3.3",
4
+ "version": "2.4.0",
5
5
  "author": "hrdtbs",
6
6
  "bin": {
7
7
  "mes": "./bin/run"
@@ -44,7 +44,8 @@
44
44
  "/bin",
45
45
  "/lib",
46
46
  "/npm-shrinkwrap.json",
47
- "/oclif.manifest.json"
47
+ "/oclif.manifest.json",
48
+ "/schema.json"
48
49
  ],
49
50
  "homepage": "https://github.com/matsuri-tech/endpoints-sdk-cli",
50
51
  "keywords": [
package/schema.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "definitions": {},
3
+ "$schema": "http://json-schema.org/draft-07/schema#",
4
+ "required": ["output", "environment_identifier", "dependencies"],
5
+ "properties": {
6
+ "output": {
7
+ "$id": "#/properties/output",
8
+ "type": "string",
9
+ "title": "Output directory",
10
+ "default": "./src/endpoints/"
11
+ },
12
+ "environment_identifier": {
13
+ "$id": "#/properties/environment_identifier",
14
+ "type": "string",
15
+ "title": "Environment identifier",
16
+ "default": "process.env.NODE_ENV",
17
+ "examples": ["process.env.NODE_ENV", "process.env.RUNTIME_ENV"]
18
+ },
19
+ "dependencies": {
20
+ "$id": "#/properties/dependencies",
21
+ "type": "object",
22
+ "title": "Dependencies",
23
+ "default": {},
24
+ "additionalProperties": {
25
+ "type": "object",
26
+ "required": ["version", "repository"],
27
+ "properties": {
28
+ "version": {
29
+ "type": "string"
30
+ },
31
+ "repository": {
32
+ "type": "string"
33
+ },
34
+ "roots": {
35
+ "type": "object",
36
+ "title": "Override roots",
37
+ "additionalProperties": {
38
+ "type": "string"
39
+ }
40
+ },
41
+ "workspaces": {
42
+ "type": "array",
43
+ "title": "Set workspaces",
44
+ "items": {
45
+ "type": "string"
46
+ }
47
+ }
48
+ }
49
+ }
50
+ }
51
+ }
52
+ }