@adobe/aio-cli-plugin-api-mesh 1.3.0 → 1.5.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/oclif.manifest.json +1 -1
- package/package.json +2 -2
- package/src/commands/api-mesh/__tests__/create.test.js +21 -0
- package/src/commands/api-mesh/create.js +8 -4
- package/src/commands/api-mesh/source/__tests__/discover.test.js +9 -8
- package/src/commands/api-mesh/source/__tests__/get.test.js +21 -18
- package/src/commands/api-mesh/source/__tests__/install.test.js +16 -0
- package/src/commands/api-mesh/source/discover.js +58 -5
- package/src/commands/api-mesh/source/get.js +18 -9
- package/src/commands/api-mesh/source/install.js +30 -8
- package/src/utils.js +7 -0
package/oclif.manifest.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":"1.
|
|
1
|
+
{"version":"1.5.0","commands":{"PLUGINNAME":{"id":"PLUGINNAME","description":"Your description here","pluginName":"@adobe/aio-cli-plugin-api-mesh","pluginType":"core","aliases":[],"examples":["$ aio PLUGINNAME:some_command"],"flags":{"someflag":{"name":"someflag","type":"option","char":"f","description":"this is some flag"}},"args":[]},"api-mesh:create":{"id":"api-mesh:create","description":"Create a mesh with the given config.","pluginName":"@adobe/aio-cli-plugin-api-mesh","pluginType":"core","aliases":[],"flags":{"ignoreCache":{"name":"ignoreCache","type":"boolean","char":"i","description":"Ignore cache and force manual org -> project -> workspace selection","allowNo":false},"autoConfirmAction":{"name":"autoConfirmAction","type":"boolean","char":"c","description":"Auto confirm action prompt. CLI will not check for user approval before executing the action.","allowNo":false},"json":{"name":"json","type":"boolean","description":"Output JSON","allowNo":false}},"args":[{"name":"file"}]},"api-mesh:delete":{"id":"api-mesh:delete","description":"Delete the config of a given mesh","pluginName":"@adobe/aio-cli-plugin-api-mesh","pluginType":"core","aliases":[],"flags":{"ignoreCache":{"name":"ignoreCache","type":"boolean","char":"i","description":"Ignore cache and force manual org -> project -> workspace selection","allowNo":false},"autoConfirmAction":{"name":"autoConfirmAction","type":"boolean","char":"c","description":"Auto confirm action prompt. CLI will not check for user approval before executing the action.","allowNo":false}},"args":[]},"api-mesh:describe":{"id":"api-mesh:describe","description":"Get details of a mesh","pluginName":"@adobe/aio-cli-plugin-api-mesh","pluginType":"core","aliases":[],"flags":{"ignoreCache":{"name":"ignoreCache","type":"boolean","char":"i","description":"Ignore cache and force manual org -> project -> workspace selection","allowNo":false}},"args":[]},"api-mesh:get":{"id":"api-mesh:get","description":"Get the config of a given mesh","pluginName":"@adobe/aio-cli-plugin-api-mesh","pluginType":"core","aliases":[],"flags":{"ignoreCache":{"name":"ignoreCache","type":"boolean","char":"i","description":"Ignore cache and force manual org -> project -> workspace selection","allowNo":false}},"args":[{"name":"file"}]},"api-mesh:update":{"id":"api-mesh:update","description":"Update a mesh with the given config.","pluginName":"@adobe/aio-cli-plugin-api-mesh","pluginType":"core","aliases":[],"flags":{"ignoreCache":{"name":"ignoreCache","type":"boolean","char":"i","description":"Ignore cache and force manual org -> project -> workspace selection","allowNo":false},"autoConfirmAction":{"name":"autoConfirmAction","type":"boolean","char":"c","description":"Auto confirm action prompt. CLI will not check for user approval before executing the action.","allowNo":false}},"args":[{"name":"file"}]},"api-mesh:source:discover":{"id":"api-mesh:source:discover","description":"Return the list of avaliable sources","pluginName":"@adobe/aio-cli-plugin-api-mesh","pluginType":"core","aliases":[],"flags":{"confirm":{"name":"confirm","type":"boolean","char":"c","description":"Auto confirm install action prompt. CLI will not check ask user to install source.","allowNo":false}},"args":[]},"api-mesh:source:get":{"id":"api-mesh:source:get","description":"Command returns the content of a specific source.","pluginName":"@adobe/aio-cli-plugin-api-mesh","pluginType":"core","aliases":[],"examples":["$ aio api-mesh:source:get -s=<version>@<source_name>","$ aio api-mesh:source:get -s<source_name>","$ aio api-mesh:source:get -m"],"flags":{"confirm":{"name":"confirm","type":"boolean","char":"c","description":"Auto confirm print action prompt. CLI will not check ask user to print source.","allowNo":false},"source":{"name":"source","type":"option","char":"s","description":"Source name"},"multiple":{"name":"multiple","type":"boolean","char":"m","description":"Select multiple sources","allowNo":false}},"args":[]},"api-mesh:source:install":{"id":"api-mesh:source:install","description":"Command to install the source to your API mesh.","pluginName":"@adobe/aio-cli-plugin-api-mesh","pluginType":"core","aliases":[],"examples":["$ aio api-mesh:source:install <version>@<source_name>","$ aio api-mesh:source:install <source_name> -v <variable_name>=<variable_value>","$ aio api-mesh:source:install <source_name> -f <path_to_variables_file>"],"flags":{"source":{"name":"source","type":"option","char":"s","description":"Source name"},"confirm":{"name":"confirm","type":"boolean","char":"c","description":"Auto confirm override action prompt. CLI will not check ask user to override source.","allowNo":false},"variable":{"name":"variable","type":"option","char":"v","description":"Variables required for the source"},"variable-file":{"name":"variable-file","type":"option","char":"f","description":"Variables file path"},"ignoreCache":{"name":"ignoreCache","type":"boolean","char":"i","description":"Ignore cache and force manual org -> project -> workspace selection","allowNo":false}},"args":[{"name":"source"}]}}}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adobe/aio-cli-plugin-api-mesh",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -83,7 +83,7 @@
|
|
|
83
83
|
"format": "prettier --check \"./**/*.{ts,tsx,js,css,json,md}\"",
|
|
84
84
|
"format:fix": "prettier --write \"./**/*.{ts,tsx,js,css,json,md}\""
|
|
85
85
|
},
|
|
86
|
-
"description": "
|
|
86
|
+
"description": "Adobe I/O CLI plugin to develop and manage API mesh sources",
|
|
87
87
|
"directories": {
|
|
88
88
|
"test": "test"
|
|
89
89
|
},
|
|
@@ -117,6 +117,13 @@ describe('create command tests', () => {
|
|
|
117
117
|
"parse": [Function],
|
|
118
118
|
"type": "boolean",
|
|
119
119
|
},
|
|
120
|
+
"json": Object {
|
|
121
|
+
"allowNo": false,
|
|
122
|
+
"default": false,
|
|
123
|
+
"description": "Output JSON",
|
|
124
|
+
"parse": [Function],
|
|
125
|
+
"type": "boolean",
|
|
126
|
+
},
|
|
120
127
|
}
|
|
121
128
|
`);
|
|
122
129
|
expect(CreateCommand.aliases).toMatchInlineSnapshot(`Array []`);
|
|
@@ -485,4 +492,18 @@ describe('create command tests', () => {
|
|
|
485
492
|
`);
|
|
486
493
|
expect(errorLogSpy.mock.calls).toMatchInlineSnapshot(`Array []`);
|
|
487
494
|
});
|
|
495
|
+
|
|
496
|
+
test('must return proper object structure used by adobe/generator-app-api-mesh', async () => {
|
|
497
|
+
parseSpy.mockResolvedValueOnce({
|
|
498
|
+
args: { file: 'src/commands/__fixtures__/sample_mesh.json' },
|
|
499
|
+
flags: {
|
|
500
|
+
json: Promise.resolve(true)
|
|
501
|
+
},
|
|
502
|
+
});
|
|
503
|
+
const output = await CreateCommand.run()
|
|
504
|
+
expect(output).toHaveProperty('mesh')
|
|
505
|
+
expect(output).toHaveProperty('adobeIdIntegrationsForWorkspace')
|
|
506
|
+
expect(output.mesh).toEqual(expect.objectContaining({ meshId: 'dummy_mesh_id' }));
|
|
507
|
+
expect(output.adobeIdIntegrationsForWorkspace).toEqual(expect.objectContaining({ apiKey: 'dummy_api_key' }));
|
|
508
|
+
});
|
|
488
509
|
});
|
|
@@ -9,13 +9,13 @@ OF ANY KIND, either express or implied. See the License for the specific languag
|
|
|
9
9
|
governing permissions and limitations under the License.
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
const { Command } = require('@oclif/
|
|
12
|
+
const { Command } = require('@oclif/core');
|
|
13
13
|
const { readFile } = require('fs/promises');
|
|
14
14
|
|
|
15
15
|
const { initSdk, initRequestId, promptConfirm } = require('../../helpers');
|
|
16
16
|
const logger = require('../../classes/logger');
|
|
17
17
|
const CONSTANTS = require('../../constants');
|
|
18
|
-
const { ignoreCacheFlag, autoConfirmActionFlag } = require('../../utils');
|
|
18
|
+
const { ignoreCacheFlag, autoConfirmActionFlag, jsonFlag } = require('../../utils');
|
|
19
19
|
const {
|
|
20
20
|
createMesh,
|
|
21
21
|
createAPIMeshCredentials,
|
|
@@ -31,8 +31,11 @@ class CreateCommand extends Command {
|
|
|
31
31
|
static flags = {
|
|
32
32
|
ignoreCache: ignoreCacheFlag,
|
|
33
33
|
autoConfirmAction: autoConfirmActionFlag,
|
|
34
|
+
json: jsonFlag
|
|
34
35
|
};
|
|
35
36
|
|
|
37
|
+
static enableJsonFlag = true
|
|
38
|
+
|
|
36
39
|
async run() {
|
|
37
40
|
await initRequestId();
|
|
38
41
|
|
|
@@ -116,11 +119,12 @@ class CreateCommand extends Command {
|
|
|
116
119
|
} else {
|
|
117
120
|
this.log('Unable to create API Key');
|
|
118
121
|
}
|
|
119
|
-
|
|
122
|
+
// Do not remove or rename return values.
|
|
123
|
+
// Template adobe/generator-app-api-mesh relies on "mesh" & "adobeIdIntegrationsForWorkspace" obj structure
|
|
120
124
|
return {
|
|
121
125
|
adobeIdIntegrationsForWorkspace,
|
|
122
126
|
sdkList,
|
|
123
|
-
mesh
|
|
127
|
+
mesh
|
|
124
128
|
};
|
|
125
129
|
} else {
|
|
126
130
|
this.error(`Unable to create a mesh. Please try again. RequestId: ${global.requestId}`, {
|
|
@@ -12,10 +12,10 @@ governing permissions and limitations under the License.
|
|
|
12
12
|
|
|
13
13
|
const mockMetadataFixture = require('../__fixtures__/connectors-metadata.json');
|
|
14
14
|
const mockAdapter = require('source-registry-storage-adapter');
|
|
15
|
-
const { promptConfirm } = require('../../../../helpers');
|
|
16
|
-
const GetCommand = require('../get');
|
|
15
|
+
const { promptConfirm, promptMultiselect } = require('../../../../helpers');
|
|
17
16
|
const { CliUx } = require('@oclif/core');
|
|
18
17
|
const DiscoverCommand = require('../discover');
|
|
18
|
+
const InstallCommand = require('../install');
|
|
19
19
|
jest.mock('source-registry-storage-adapter');
|
|
20
20
|
jest.mock('../../../../helpers');
|
|
21
21
|
jest.mock('../get');
|
|
@@ -43,16 +43,17 @@ describe('source:discover command tests', () => {
|
|
|
43
43
|
await DiscoverCommand.run([]);
|
|
44
44
|
expect(CliUx.Table.table).toHaveBeenCalledTimes(1);
|
|
45
45
|
});
|
|
46
|
-
test('Check that "source:
|
|
47
|
-
|
|
46
|
+
test('Check that "source:install" command is called', async () => {
|
|
47
|
+
InstallCommand.run = jest.fn().mockImplementation(() => 'source:install');
|
|
48
48
|
promptConfirm.mockResolvedValue(true);
|
|
49
|
+
promptMultiselect.mockResolvedValue([mockMetadataFixture['test-01']])
|
|
49
50
|
await DiscoverCommand.run([]);
|
|
50
|
-
expect(
|
|
51
|
+
expect(InstallCommand.run).toHaveBeenCalledTimes(1);
|
|
51
52
|
});
|
|
52
|
-
test('Check that "source:
|
|
53
|
-
|
|
53
|
+
test('Check that "source:install" command is not called', async () => {
|
|
54
|
+
InstallCommand.run = jest.fn().mockImplementation(() => 'source:install');
|
|
54
55
|
promptConfirm.mockResolvedValue(false);
|
|
55
56
|
await DiscoverCommand.run([]);
|
|
56
|
-
expect(
|
|
57
|
+
expect(InstallCommand.run).toHaveBeenCalledTimes(0);
|
|
57
58
|
});
|
|
58
59
|
});
|
|
@@ -30,6 +30,9 @@ const expectedResultForSuccessScenarios = JSON.stringify(
|
|
|
30
30
|
null,
|
|
31
31
|
4,
|
|
32
32
|
);
|
|
33
|
+
const normalizeAssertString = str => {
|
|
34
|
+
return str.replace(/[\r\t]/gm, '').replace(/[\r\n]/gm, '').replace(/ +/g, ' ')
|
|
35
|
+
}
|
|
33
36
|
mockAdapter.mockImplementation(() => ({
|
|
34
37
|
get: jest
|
|
35
38
|
.fn()
|
|
@@ -54,6 +57,14 @@ describe('source:get command tests', () => {
|
|
|
54
57
|
);
|
|
55
58
|
expect(GetCommand.flags).toMatchInlineSnapshot(`
|
|
56
59
|
Object {
|
|
60
|
+
"confirm": Object {
|
|
61
|
+
"allowNo": false,
|
|
62
|
+
"char": "c",
|
|
63
|
+
"default": false,
|
|
64
|
+
"description": "Auto confirm print action prompt. CLI will not check ask user to print source.",
|
|
65
|
+
"parse": [Function],
|
|
66
|
+
"type": "boolean",
|
|
67
|
+
},
|
|
57
68
|
"multiple": Object {
|
|
58
69
|
"allowNo": false,
|
|
59
70
|
"char": "m",
|
|
@@ -78,15 +89,13 @@ describe('source:get command tests', () => {
|
|
|
78
89
|
});
|
|
79
90
|
test('Check executing without parameters', async () => {
|
|
80
91
|
await GetCommand.run([]).catch(err => {
|
|
81
|
-
expect(err.message).toEqual(
|
|
82
|
-
|
|
92
|
+
expect(normalizeAssertString(err.message)).toEqual(
|
|
93
|
+
normalizeAssertString(`Something went wrong with "get" command. Please try again later.` +
|
|
94
|
+
`Error: \nThe "aio api-mesh:source:get" command requires additional parameters` +
|
|
95
|
+
`Use "aio api-mesh:source:get --help" to see parameters information.`)
|
|
96
|
+
);
|
|
83
97
|
});
|
|
84
|
-
});
|
|
85
|
-
test('Check executing success with multiple, copied to clipboard and logged to console', async () => {
|
|
86
|
-
await GetCommand.run(['-m']);
|
|
87
|
-
expect(ncp.readSync()).toEqual(expectedResultForSuccessScenarios);
|
|
88
|
-
expect(logSpy.mock.calls.pop()[0]).toEqual(expectedResultForSuccessScenarios);
|
|
89
|
-
});
|
|
98
|
+
});
|
|
90
99
|
test('Check executing success with provided name and version, copied to clipboard and logged to console', async () => {
|
|
91
100
|
await GetCommand.run(['-s=test-01@0.0.1', '-s=test-02@0.0.1']);
|
|
92
101
|
expect(ncp.readSync()).toEqual(expectedResultForSuccessScenarios);
|
|
@@ -100,11 +109,8 @@ describe('source:get command tests', () => {
|
|
|
100
109
|
test('Check executing failed due to requested source does not exist', async () => {
|
|
101
110
|
const name = 'test-99';
|
|
102
111
|
await GetCommand.run([`-s=${name}`]).catch(err => {
|
|
103
|
-
expect(err.message).
|
|
104
|
-
chalk.red(
|
|
105
|
-
`The source with the name "${name}" doesn't exist.` +
|
|
106
|
-
`\nUse "aio api-mesh:source:discover" command to see avaliable sources.`,
|
|
107
|
-
),
|
|
112
|
+
expect(err.message).toContain(
|
|
113
|
+
chalk.red(`The source with the name "test-99" doesn't exist.`),
|
|
108
114
|
);
|
|
109
115
|
});
|
|
110
116
|
});
|
|
@@ -112,11 +118,8 @@ describe('source:get command tests', () => {
|
|
|
112
118
|
const name = 'test-01';
|
|
113
119
|
const version = '1.1.1';
|
|
114
120
|
await GetCommand.run([`-s=${name}@${version}`]).catch(err => {
|
|
115
|
-
expect(err.message).
|
|
116
|
-
chalk.red(
|
|
117
|
-
`The version "${version}" for source name "${name}" doesn't exist.` +
|
|
118
|
-
`\nUse "aio api-mesh:source:discover" command to see avaliable source versions.`,
|
|
119
|
-
),
|
|
121
|
+
expect(err.message).toContain(
|
|
122
|
+
chalk.red(`The version \"1.1.1\" for source name \"test-01\" doesn't exist.`),
|
|
120
123
|
);
|
|
121
124
|
});
|
|
122
125
|
});
|
|
@@ -51,6 +51,14 @@ describe('source:install command tests', () => {
|
|
|
51
51
|
);
|
|
52
52
|
expect(InstallCommand.flags).toMatchInlineSnapshot(`
|
|
53
53
|
Object {
|
|
54
|
+
"confirm": Object {
|
|
55
|
+
"allowNo": false,
|
|
56
|
+
"char": "c",
|
|
57
|
+
"default": false,
|
|
58
|
+
"description": "Auto confirm override action prompt. CLI will not check ask user to override source.",
|
|
59
|
+
"parse": [Function],
|
|
60
|
+
"type": "boolean",
|
|
61
|
+
},
|
|
54
62
|
"ignoreCache": Object {
|
|
55
63
|
"allowNo": false,
|
|
56
64
|
"char": "i",
|
|
@@ -59,6 +67,14 @@ describe('source:install command tests', () => {
|
|
|
59
67
|
"parse": [Function],
|
|
60
68
|
"type": "boolean",
|
|
61
69
|
},
|
|
70
|
+
"source": Object {
|
|
71
|
+
"char": "s",
|
|
72
|
+
"description": "Source name",
|
|
73
|
+
"input": Array [],
|
|
74
|
+
"multiple": true,
|
|
75
|
+
"parse": [Function],
|
|
76
|
+
"type": "option",
|
|
77
|
+
},
|
|
62
78
|
"variable": Object {
|
|
63
79
|
"char": "v",
|
|
64
80
|
"description": "Variables required for the source",
|
|
@@ -9,12 +9,12 @@ OF ANY KIND, either express or implied. See the License for the specific languag
|
|
|
9
9
|
governing permissions and limitations under the License.
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
const { Command, CliUx } = require('@oclif/core');
|
|
13
|
-
const { promptConfirm, initRequestId } = require('../../../helpers');
|
|
14
|
-
const GetCommand = require('./get');
|
|
12
|
+
const { Command, CliUx, Flags } = require('@oclif/core');
|
|
13
|
+
const { promptConfirm, initRequestId, promptMultiselect, promptSelect } = require('../../../helpers');
|
|
15
14
|
const SourceRegistryStorage = require('source-registry-storage-adapter');
|
|
16
15
|
const config = require('@adobe/aio-lib-core-config');
|
|
17
16
|
const logger = require('../../../classes/logger');
|
|
17
|
+
const InstallCommand = require('./install');
|
|
18
18
|
|
|
19
19
|
|
|
20
20
|
class DiscoverCommand extends Command {
|
|
@@ -23,6 +23,7 @@ class DiscoverCommand extends Command {
|
|
|
23
23
|
await initRequestId();
|
|
24
24
|
|
|
25
25
|
logger.info(`RequestId: ${global.requestId}`);
|
|
26
|
+
const { flags } = await this.parse(DiscoverCommand);
|
|
26
27
|
const srs = new SourceRegistryStorage(config.get('api-mesh.sourceRegistry.path'));
|
|
27
28
|
let list;
|
|
28
29
|
try {
|
|
@@ -33,10 +34,24 @@ class DiscoverCommand extends Command {
|
|
|
33
34
|
}
|
|
34
35
|
|
|
35
36
|
this.generateSourcesTable(list);
|
|
36
|
-
|
|
37
|
+
let needInstall = false;
|
|
38
|
+
|
|
39
|
+
if (flags.confirm) {
|
|
40
|
+
needInstall = true;
|
|
41
|
+
} else {
|
|
42
|
+
needInstall = await promptConfirm(`Do you want to install sources?`);
|
|
43
|
+
}
|
|
44
|
+
|
|
37
45
|
if (needInstall) {
|
|
38
|
-
|
|
46
|
+
const toInstall = await this.handleMultiple(list)
|
|
47
|
+
const params = [];
|
|
48
|
+
toInstall.forEach(source => {
|
|
49
|
+
params.push('-s');
|
|
50
|
+
params.push(source)
|
|
51
|
+
})
|
|
52
|
+
InstallCommand.run(params);
|
|
39
53
|
}
|
|
54
|
+
|
|
40
55
|
} catch (error) {
|
|
41
56
|
logger.error(error);
|
|
42
57
|
this.error(`
|
|
@@ -46,6 +61,36 @@ class DiscoverCommand extends Command {
|
|
|
46
61
|
}
|
|
47
62
|
}
|
|
48
63
|
|
|
64
|
+
async handleMultiple(data) {
|
|
65
|
+
const result = [];
|
|
66
|
+
let selectedList = await promptMultiselect(
|
|
67
|
+
'Select sources to install',
|
|
68
|
+
Object.values(data).map(elem => ({ name: elem.name, value: elem })),
|
|
69
|
+
) || [];
|
|
70
|
+
|
|
71
|
+
if (!selectedList.length) {
|
|
72
|
+
while (!selectedList.length) {
|
|
73
|
+
selectedList = await promptMultiselect(
|
|
74
|
+
'Please choose at least one source',
|
|
75
|
+
Object.values(data).map(elem => ({ name: elem.name, value: elem })),
|
|
76
|
+
) || []
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
for (const selected of selectedList) {
|
|
81
|
+
if (selected.versions.length > 1) {
|
|
82
|
+
const version = await promptSelect(
|
|
83
|
+
`Please choose the version of "${selected.name}" source`,
|
|
84
|
+
selected.versions.map(v => ({ name: `v${v}`, value: `${selected.name}@${v}` })),
|
|
85
|
+
);
|
|
86
|
+
result.push(version);
|
|
87
|
+
} else {
|
|
88
|
+
result.push(`${selected.name}@${selected.latest}`);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return result;
|
|
92
|
+
}
|
|
93
|
+
|
|
49
94
|
async generateSourcesTable(data) {
|
|
50
95
|
const columns = {
|
|
51
96
|
name: {
|
|
@@ -65,6 +110,14 @@ class DiscoverCommand extends Command {
|
|
|
65
110
|
}
|
|
66
111
|
}
|
|
67
112
|
|
|
113
|
+
DiscoverCommand.flags = {
|
|
114
|
+
confirm: Flags.boolean({
|
|
115
|
+
char: 'c',
|
|
116
|
+
description:'Auto confirm install action prompt. CLI will not check ask user to install source.',
|
|
117
|
+
default: false,
|
|
118
|
+
}),
|
|
119
|
+
};
|
|
120
|
+
|
|
68
121
|
DiscoverCommand.description = 'Return the list of avaliable sources';
|
|
69
122
|
|
|
70
123
|
module.exports = DiscoverCommand;
|
|
@@ -41,7 +41,7 @@ class GetCommand extends Command {
|
|
|
41
41
|
const { flags } = await this.parse(GetCommand);
|
|
42
42
|
if (!flags.source && !flags.multiple) {
|
|
43
43
|
this.error(
|
|
44
|
-
|
|
44
|
+
`\nThe "aio api-mesh:source:get" command requires additional parameters` +
|
|
45
45
|
`\nUse "aio api-mesh:source:get --help" to see parameters information.`,
|
|
46
46
|
);
|
|
47
47
|
}
|
|
@@ -77,16 +77,20 @@ class GetCommand extends Command {
|
|
|
77
77
|
'The sources are copied to the clipboard, please paste them to your API Mesh configuration',
|
|
78
78
|
),
|
|
79
79
|
);
|
|
80
|
-
|
|
81
|
-
|
|
80
|
+
if (!flags.confirm) {
|
|
81
|
+
const print = await promptConfirm(`Do you want to print Source configurations in console?`);
|
|
82
|
+
if (print) {
|
|
83
|
+
this.log(sourceConfigsString);
|
|
84
|
+
}
|
|
85
|
+
} else {
|
|
82
86
|
this.log(sourceConfigsString);
|
|
83
|
-
}
|
|
87
|
+
}
|
|
84
88
|
} catch (error) {
|
|
85
89
|
logger.error(error);
|
|
86
90
|
this.error(`
|
|
87
|
-
|
|
88
|
-
${error}
|
|
89
|
-
|
|
91
|
+
\nSomething went wrong with "get" command. Please try again later.
|
|
92
|
+
\n${error}`
|
|
93
|
+
);
|
|
90
94
|
}
|
|
91
95
|
}
|
|
92
96
|
|
|
@@ -116,6 +120,11 @@ class GetCommand extends Command {
|
|
|
116
120
|
}
|
|
117
121
|
|
|
118
122
|
GetCommand.flags = {
|
|
123
|
+
confirm: Flags.boolean({
|
|
124
|
+
char: 'c',
|
|
125
|
+
description:'Auto confirm print action prompt. CLI will not check ask user to print source.',
|
|
126
|
+
default: false,
|
|
127
|
+
}),
|
|
119
128
|
source: Flags.string({
|
|
120
129
|
char: 's',
|
|
121
130
|
description: 'Source name',
|
|
@@ -130,8 +139,8 @@ GetCommand.flags = {
|
|
|
130
139
|
|
|
131
140
|
GetCommand.description = 'Command returns the content of a specific source.';
|
|
132
141
|
GetCommand.examples = [
|
|
133
|
-
'$ aio api-mesh:source:get
|
|
134
|
-
'$ aio api-mesh:source:get <source_name>',
|
|
142
|
+
'$ aio api-mesh:source:get -s=<version>@<source_name>',
|
|
143
|
+
'$ aio api-mesh:source:get -s<source_name>',
|
|
135
144
|
'$ aio api-mesh:source:get -m',
|
|
136
145
|
];
|
|
137
146
|
|
|
@@ -45,6 +45,7 @@ class InstallCommand extends Command {
|
|
|
45
45
|
return obj;
|
|
46
46
|
}, {})
|
|
47
47
|
: {};
|
|
48
|
+
|
|
48
49
|
if (filepath) {
|
|
49
50
|
try {
|
|
50
51
|
variables = { ...variables, ...JSON.parse(await readFile(filepath, 'utf8')) };
|
|
@@ -92,16 +93,17 @@ class InstallCommand extends Command {
|
|
|
92
93
|
const jsonInterpolate = new JsonInterpolate({ variablesSchema: sourceConfig.variables });
|
|
93
94
|
const sourceProviderString = JSON.stringify(sourceConfig.provider);
|
|
94
95
|
const sourceVariables = jsonInterpolate.getJsonVariables(sourceProviderString);
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
96
|
+
const passedSourceVariables = this.getPassedSourceVariables(sourceVariables || [], variables);
|
|
97
|
+
const missedVariables = jsonInterpolate.getMissedVariables(passedSourceVariables, sourceVariables);
|
|
98
|
+
for (const missedVariable of missedVariables.map(item => item.name).filter((value, index, self) => self.indexOf(value) === index)) {
|
|
99
|
+
passedSourceVariables[missedVariable] = await promptInput(
|
|
100
|
+
`Enter the value for variable ${missedVariable}:`,
|
|
99
101
|
);
|
|
100
102
|
}
|
|
101
103
|
|
|
102
104
|
const { error, data } = jsonInterpolate.interpolate(
|
|
103
105
|
JSON.stringify(sourceConfig.provider),
|
|
104
|
-
|
|
106
|
+
passedSourceVariables,
|
|
105
107
|
);
|
|
106
108
|
if (error) {
|
|
107
109
|
this.error(chalk.red(`${error.message}\n${error.list.map(err => err.message).join('\n')}`));
|
|
@@ -141,7 +143,7 @@ class InstallCommand extends Command {
|
|
|
141
143
|
|
|
142
144
|
let override = false;
|
|
143
145
|
if (verifiedSources.installed.length) {
|
|
144
|
-
override = await promptConfirm(
|
|
146
|
+
override = flags.confirm ? true : await promptConfirm(
|
|
145
147
|
`The following sources are already installed: ${verifiedSources.installed
|
|
146
148
|
.map(source => source.name)
|
|
147
149
|
.join(', ')}.
|
|
@@ -228,6 +230,16 @@ class InstallCommand extends Command {
|
|
|
228
230
|
return result;
|
|
229
231
|
}
|
|
230
232
|
|
|
233
|
+
getPassedSourceVariables(variablesInSource, passedVariables) {
|
|
234
|
+
const res = {}
|
|
235
|
+
variablesInSource.forEach(variable => {
|
|
236
|
+
if (passedVariables[variable.name]) {
|
|
237
|
+
res[variable.name] = passedVariables[variable.name]
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
return res;
|
|
241
|
+
}
|
|
242
|
+
|
|
231
243
|
verifySourceAlreadyExists(meshSources, installSources) {
|
|
232
244
|
const alreadyInstalledSources = [];
|
|
233
245
|
const uniqueSourcesToInstall = [];
|
|
@@ -247,7 +259,17 @@ class InstallCommand extends Command {
|
|
|
247
259
|
}
|
|
248
260
|
|
|
249
261
|
InstallCommand.flags = {
|
|
250
|
-
|
|
262
|
+
source: Flags.string({
|
|
263
|
+
char: 's',
|
|
264
|
+
description: 'Source name',
|
|
265
|
+
multiple: true,
|
|
266
|
+
}),
|
|
267
|
+
confirm: Flags.boolean({
|
|
268
|
+
char: 'c',
|
|
269
|
+
description:'Auto confirm override action prompt. CLI will not check ask user to override source.',
|
|
270
|
+
default: false,
|
|
271
|
+
}),
|
|
272
|
+
variable: Flags.string({
|
|
251
273
|
char: 'v',
|
|
252
274
|
description: 'Variables required for the source',
|
|
253
275
|
multiple: true,
|
|
@@ -256,7 +278,7 @@ InstallCommand.flags = {
|
|
|
256
278
|
char: 'f',
|
|
257
279
|
description: 'Variables file path',
|
|
258
280
|
}),
|
|
259
|
-
|
|
281
|
+
ignoreCache: ignoreCacheFlag,
|
|
260
282
|
};
|
|
261
283
|
|
|
262
284
|
InstallCommand.description = 'Command to install the source to your API mesh.';
|
package/src/utils.js
CHANGED
|
@@ -49,8 +49,15 @@ const autoConfirmActionFlag = Flags.boolean({
|
|
|
49
49
|
default: false,
|
|
50
50
|
});
|
|
51
51
|
|
|
52
|
+
const jsonFlag = Flags.boolean({
|
|
53
|
+
description:
|
|
54
|
+
'Output JSON',
|
|
55
|
+
default: false,
|
|
56
|
+
});
|
|
57
|
+
|
|
52
58
|
module.exports = {
|
|
53
59
|
objToString,
|
|
54
60
|
ignoreCacheFlag,
|
|
55
61
|
autoConfirmActionFlag,
|
|
62
|
+
jsonFlag,
|
|
56
63
|
};
|