@adobe/aio-cli-plugin-api-mesh 3.0.0 → 3.1.0-beta.1
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 +13 -5
- package/src/commands/api-mesh/__tests__/create.test.js +9 -1
- package/src/commands/api-mesh/__tests__/describe.test.js +9 -9
- package/src/commands/api-mesh/__tests__/get.test.js +1 -0
- package/src/commands/api-mesh/__tests__/run.test.js +783 -0
- package/src/commands/api-mesh/create.js +19 -11
- package/src/commands/api-mesh/describe.js +15 -14
- package/src/commands/api-mesh/get.js +3 -3
- package/src/commands/api-mesh/init.js +8 -0
- package/src/commands/api-mesh/run.js +156 -0
- package/src/commands/api-mesh/source/__tests__/install.test.js +2 -0
- package/src/commands/api-mesh/source/install.js +4 -4
- package/src/commands/api-mesh/status.js +3 -3
- package/src/constants.js +2 -6
- package/src/helpers.js +59 -5
- package/src/lib/devConsole.js +7 -5
- package/src/server.js +168 -0
- package/src/serverUtils.js +323 -0
- package/src/templates/package.json +29 -19
- package/src/utils.js +12 -0
- package/src/uuid.js +21 -0
|
@@ -25,7 +25,7 @@ const {
|
|
|
25
25
|
} = require('../../utils');
|
|
26
26
|
const { getMesh, createMesh } = require('../../lib/devConsole');
|
|
27
27
|
|
|
28
|
-
const { MULTITENANT_GRAPHQL_SERVER_BASE_URL
|
|
28
|
+
const { MULTITENANT_GRAPHQL_SERVER_BASE_URL } = CONSTANTS;
|
|
29
29
|
|
|
30
30
|
class CreateCommand extends Command {
|
|
31
31
|
static args = [{ name: 'file' }];
|
|
@@ -54,7 +54,7 @@ class CreateCommand extends Command {
|
|
|
54
54
|
const ignoreCache = await flags.ignoreCache;
|
|
55
55
|
const autoConfirmAction = await flags.autoConfirmAction;
|
|
56
56
|
const envFilePath = await flags.env;
|
|
57
|
-
const { imsOrgId, projectId, workspaceId } = await initSdk({
|
|
57
|
+
const { imsOrgId, projectId, workspaceId, workspaceName } = await initSdk({
|
|
58
58
|
ignoreCache,
|
|
59
59
|
});
|
|
60
60
|
|
|
@@ -104,7 +104,13 @@ class CreateCommand extends Command {
|
|
|
104
104
|
|
|
105
105
|
if (shouldContinue) {
|
|
106
106
|
try {
|
|
107
|
-
const { mesh, apiKey, sdkList } = await createMesh(
|
|
107
|
+
const { mesh, apiKey, sdkList } = await createMesh(
|
|
108
|
+
imsOrgId,
|
|
109
|
+
projectId,
|
|
110
|
+
workspaceId,
|
|
111
|
+
workspaceName,
|
|
112
|
+
data,
|
|
113
|
+
);
|
|
108
114
|
|
|
109
115
|
if (mesh) {
|
|
110
116
|
this.log(
|
|
@@ -126,23 +132,25 @@ class CreateCommand extends Command {
|
|
|
126
132
|
if (sdkList) {
|
|
127
133
|
this.log('Successfully subscribed API Key %s to API Mesh service', apiKey);
|
|
128
134
|
|
|
129
|
-
const { meshURL } = await getMesh(
|
|
135
|
+
const { meshURL } = await getMesh(
|
|
136
|
+
imsOrgId,
|
|
137
|
+
projectId,
|
|
138
|
+
workspaceId,
|
|
139
|
+
workspaceName,
|
|
140
|
+
mesh.meshId,
|
|
141
|
+
);
|
|
130
142
|
const meshUrl =
|
|
131
143
|
meshURL === '' || meshURL === undefined
|
|
132
144
|
? MULTITENANT_GRAPHQL_SERVER_BASE_URL
|
|
133
145
|
: meshURL;
|
|
134
146
|
|
|
135
|
-
if (
|
|
136
|
-
meshUrl === TMOConstants.TMO_STAGE_URL ||
|
|
137
|
-
meshUrl === TMOConstants.TMO_SANDBOX_URL ||
|
|
138
|
-
meshUrl === TMOConstants.TMO_PROD_URL
|
|
139
|
-
) {
|
|
140
|
-
this.log('Mesh Endpoint: %s\n', `${meshUrl}/${mesh.meshId}/graphql`);
|
|
141
|
-
} else {
|
|
147
|
+
if (apiKey && MULTITENANT_GRAPHQL_SERVER_BASE_URL.includes(meshUrl)) {
|
|
142
148
|
this.log(
|
|
143
149
|
'Mesh Endpoint: %s\n',
|
|
144
150
|
`${meshUrl}/${mesh.meshId}/graphql?api_key=${apiKey}`,
|
|
145
151
|
);
|
|
152
|
+
} else {
|
|
153
|
+
this.log('Mesh Endpoint: %s\n', `${meshUrl}/${mesh.meshId}/graphql`);
|
|
146
154
|
}
|
|
147
155
|
} else {
|
|
148
156
|
this.log('Unable to subscribe API Key %s to API Mesh service', apiKey);
|
|
@@ -19,7 +19,7 @@ const { describeMesh, getMesh } = require('../../lib/devConsole');
|
|
|
19
19
|
|
|
20
20
|
require('dotenv').config();
|
|
21
21
|
|
|
22
|
-
const { MULTITENANT_GRAPHQL_SERVER_BASE_URL
|
|
22
|
+
const { MULTITENANT_GRAPHQL_SERVER_BASE_URL } = CONSTANTS;
|
|
23
23
|
|
|
24
24
|
class DescribeCommand extends Command {
|
|
25
25
|
static flags = {
|
|
@@ -35,12 +35,12 @@ class DescribeCommand extends Command {
|
|
|
35
35
|
|
|
36
36
|
const ignoreCache = await flags.ignoreCache;
|
|
37
37
|
|
|
38
|
-
const { imsOrgId, projectId, workspaceId } = await initSdk({
|
|
38
|
+
const { imsOrgId, projectId, workspaceId, workspaceName } = await initSdk({
|
|
39
39
|
ignoreCache,
|
|
40
40
|
});
|
|
41
41
|
|
|
42
42
|
try {
|
|
43
|
-
const meshDetails = await describeMesh(imsOrgId, projectId, workspaceId);
|
|
43
|
+
const meshDetails = await describeMesh(imsOrgId, projectId, workspaceId, workspaceName);
|
|
44
44
|
|
|
45
45
|
if (meshDetails) {
|
|
46
46
|
const { meshId, apiKey } = meshDetails;
|
|
@@ -52,19 +52,20 @@ class DescribeCommand extends Command {
|
|
|
52
52
|
this.log('Workspace ID: %s', workspaceId);
|
|
53
53
|
this.log('Mesh ID: %s', meshId);
|
|
54
54
|
|
|
55
|
-
const { meshURL } = await getMesh(
|
|
56
|
-
|
|
55
|
+
const { meshURL } = await getMesh(
|
|
56
|
+
imsOrgId,
|
|
57
|
+
projectId,
|
|
58
|
+
workspaceId,
|
|
59
|
+
workspaceName,
|
|
60
|
+
meshId,
|
|
61
|
+
);
|
|
62
|
+
const meshUrl =
|
|
63
|
+
meshURL === '' || meshURL === undefined ? MULTITENANT_GRAPHQL_SERVER_BASE_URL : meshURL;
|
|
57
64
|
|
|
58
|
-
if (
|
|
59
|
-
apiKey &&
|
|
60
|
-
(meshUrl === TMOConstants.TMO_STAGE_URL ||
|
|
61
|
-
meshUrl === TMOConstants.TMO_SANDBOX_URL ||
|
|
62
|
-
meshUrl === TMOConstants.TMO_PROD_URL)
|
|
63
|
-
) {
|
|
64
|
-
this.log('Mesh Endpoint: %s\n', `${meshUrl}/${meshId}/graphql`);
|
|
65
|
-
} else if (apiKey) {
|
|
66
|
-
this.log('API Key: %s', apiKey);
|
|
65
|
+
if (apiKey && MULTITENANT_GRAPHQL_SERVER_BASE_URL.includes(meshUrl)) {
|
|
67
66
|
this.log('Mesh Endpoint: %s\n', `${meshUrl}/${meshId}/graphql?api_key=${apiKey}`);
|
|
67
|
+
} else {
|
|
68
|
+
this.log('Mesh Endpoint: %s\n', `${meshUrl}/${meshId}/graphql`);
|
|
68
69
|
}
|
|
69
70
|
return meshDetails;
|
|
70
71
|
} else {
|
|
@@ -38,7 +38,7 @@ class GetCommand extends Command {
|
|
|
38
38
|
const ignoreCache = await flags.ignoreCache;
|
|
39
39
|
const json = await flags.json;
|
|
40
40
|
|
|
41
|
-
const { imsOrgId, projectId, workspaceId } = await initSdk({
|
|
41
|
+
const { imsOrgId, projectId, workspaceId, workspaceName } = await initSdk({
|
|
42
42
|
ignoreCache,
|
|
43
43
|
verbose: !json,
|
|
44
44
|
});
|
|
@@ -46,7 +46,7 @@ class GetCommand extends Command {
|
|
|
46
46
|
let meshId = null;
|
|
47
47
|
|
|
48
48
|
try {
|
|
49
|
-
meshId = await getMeshId(imsOrgId, projectId, workspaceId);
|
|
49
|
+
meshId = await getMeshId(imsOrgId, projectId, workspaceId, workspaceName);
|
|
50
50
|
} catch (err) {
|
|
51
51
|
this.error(
|
|
52
52
|
`Unable to get mesh ID. Please check the details and try again. RequestId: ${global.requestId}`,
|
|
@@ -55,7 +55,7 @@ class GetCommand extends Command {
|
|
|
55
55
|
|
|
56
56
|
if (meshId) {
|
|
57
57
|
try {
|
|
58
|
-
const mesh = await getMesh(imsOrgId, projectId, workspaceId, meshId);
|
|
58
|
+
const mesh = await getMesh(imsOrgId, projectId, workspaceId, workspaceName, meshId);
|
|
59
59
|
|
|
60
60
|
if (mesh) {
|
|
61
61
|
this.log('Successfully retrieved mesh %s', JSON.stringify(mesh, null, 2));
|
|
@@ -70,6 +70,11 @@ class InitCommand extends Command {
|
|
|
70
70
|
await fs.writeFile(filePath, JSON.stringify(pkgJSON, null, 2), 'utf8', { mode: 'w' });
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
+
async createDotNpmrcFile(templatePath, filePath) {
|
|
74
|
+
const dotNpmrcFile = await fs.readFile(templatePath, 'utf8');
|
|
75
|
+
await fs.writeFile(filePath, dotNpmrcFile, 'utf8', { mode: 'w' });
|
|
76
|
+
}
|
|
77
|
+
|
|
73
78
|
async run() {
|
|
74
79
|
const { args, flags } = await this.parse(InitCommand);
|
|
75
80
|
const gitFlagOptions = {
|
|
@@ -81,6 +86,7 @@ class InitCommand extends Command {
|
|
|
81
86
|
let shouldCreateGit = gitFlagOptions[flags.git];
|
|
82
87
|
let packageManagerChoice = flags.packageManager;
|
|
83
88
|
const packageJsonTemplate = `${getAppRootDir()}/src/templates/package.json`;
|
|
89
|
+
const dotNpmrcPath = `${getAppRootDir()}/src/templates/.npmrc`;
|
|
84
90
|
const shouldCreateWorkspace = await promptConfirm(
|
|
85
91
|
`Do you want to create the workspace in ${absolutePath}`,
|
|
86
92
|
);
|
|
@@ -144,6 +150,8 @@ class InitCommand extends Command {
|
|
|
144
150
|
args.projectName,
|
|
145
151
|
);
|
|
146
152
|
|
|
153
|
+
await this.createDotNpmrcFile(dotNpmrcPath, `${absolutePath}/.npmrc`);
|
|
154
|
+
|
|
147
155
|
if (packageManagerChoice === 'npm') {
|
|
148
156
|
try {
|
|
149
157
|
await runCliCommand(`npm install`, absolutePath);
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2021 Adobe. All rights reserved.
|
|
3
|
+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
Unless required by applicable law or agreed to in writing, software distributed under
|
|
7
|
+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
8
|
+
OF ANY KIND, either express or implied. See the License for the specific language
|
|
9
|
+
governing permissions and limitations under the License.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
const { Command } = require('@oclif/core');
|
|
13
|
+
const {
|
|
14
|
+
portNoFlag,
|
|
15
|
+
debugFlag,
|
|
16
|
+
envFileFlag,
|
|
17
|
+
autoConfirmActionFlag,
|
|
18
|
+
readFileContents,
|
|
19
|
+
validateAndInterpolateMesh,
|
|
20
|
+
checkPlaceholders,
|
|
21
|
+
getFilesInMeshConfig,
|
|
22
|
+
} = require('../../utils');
|
|
23
|
+
const meshBuilder = require('@adobe-apimesh/mesh-builder');
|
|
24
|
+
const fs = require('fs');
|
|
25
|
+
const UUID = require('../../uuid');
|
|
26
|
+
const path = require('path');
|
|
27
|
+
const { initRequestId, startGraphqlServer, importFiles } = require('../../helpers');
|
|
28
|
+
const logger = require('../../classes/logger');
|
|
29
|
+
require('dotenv').config();
|
|
30
|
+
|
|
31
|
+
const { validateMesh, buildMesh, compileMesh } = meshBuilder.default;
|
|
32
|
+
|
|
33
|
+
class RunCommand extends Command {
|
|
34
|
+
static summary = 'Run local development server';
|
|
35
|
+
static description = 'Run a local development server that builds and compiles a mesh locally';
|
|
36
|
+
|
|
37
|
+
static args = [
|
|
38
|
+
{
|
|
39
|
+
name: 'file',
|
|
40
|
+
description: 'Mesh File',
|
|
41
|
+
},
|
|
42
|
+
];
|
|
43
|
+
|
|
44
|
+
static flags = {
|
|
45
|
+
port: portNoFlag,
|
|
46
|
+
debug: debugFlag,
|
|
47
|
+
env: envFileFlag,
|
|
48
|
+
autoConfirmAction: autoConfirmActionFlag,
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
static enableJsonFlag = true;
|
|
52
|
+
|
|
53
|
+
static examples = [];
|
|
54
|
+
|
|
55
|
+
async run() {
|
|
56
|
+
await initRequestId();
|
|
57
|
+
|
|
58
|
+
logger.info(`RequestId: ${global.requestId}`);
|
|
59
|
+
|
|
60
|
+
const { args, flags } = await this.parse(RunCommand);
|
|
61
|
+
|
|
62
|
+
if (!args.file) {
|
|
63
|
+
throw new Error('Missing file path. Run aio api-mesh run --help for more info.');
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
let portNo;
|
|
67
|
+
|
|
68
|
+
//To set the port number using the environment file
|
|
69
|
+
if (process.env.PORT !== undefined) {
|
|
70
|
+
if (isNaN(process.env.PORT) || !Number.isInteger(parseInt(process.env.PORT))) {
|
|
71
|
+
throw new Error('PORT value in the .env file is not a valid integer');
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
portNo = process.env.PORT;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
//To set the port number as the provided value in the command
|
|
78
|
+
if (flags.port !== undefined) {
|
|
79
|
+
portNo = flags.port;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
//To set the default port to 5000
|
|
83
|
+
if (!portNo) {
|
|
84
|
+
portNo = 5000;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const envFilePath = await flags.env;
|
|
88
|
+
|
|
89
|
+
try {
|
|
90
|
+
//Ensure that current directory includes package.json
|
|
91
|
+
if (fs.existsSync(path.join(process.cwd(), 'package.json'))) {
|
|
92
|
+
//Read the mesh input file
|
|
93
|
+
let inputMeshData = await readFileContents(args.file, this, 'mesh');
|
|
94
|
+
let data;
|
|
95
|
+
|
|
96
|
+
if (checkPlaceholders(inputMeshData)) {
|
|
97
|
+
this.log('The provided mesh contains placeholders. Starting mesh interpolation process.');
|
|
98
|
+
data = await validateAndInterpolateMesh(inputMeshData, envFilePath, this);
|
|
99
|
+
} else {
|
|
100
|
+
try {
|
|
101
|
+
data = JSON.parse(inputMeshData);
|
|
102
|
+
} catch (err) {
|
|
103
|
+
this.log(err.message);
|
|
104
|
+
throw new Error('Input mesh file is not a valid JSON. Please check the file provided.');
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
let filesList = [];
|
|
109
|
+
|
|
110
|
+
try {
|
|
111
|
+
filesList = getFilesInMeshConfig(data, args.file);
|
|
112
|
+
} catch (err) {
|
|
113
|
+
this.log(err.message);
|
|
114
|
+
throw new Error('Input mesh config is not valid.');
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// if local files are present, import them in files array in meshConfig
|
|
118
|
+
if (filesList.length) {
|
|
119
|
+
try {
|
|
120
|
+
// minification of js will not be done for run command if debugging is enabled
|
|
121
|
+
data = await importFiles(
|
|
122
|
+
data,
|
|
123
|
+
filesList,
|
|
124
|
+
args.file,
|
|
125
|
+
flags.autoConfirmAction,
|
|
126
|
+
!flags.debug,
|
|
127
|
+
);
|
|
128
|
+
} catch (err) {
|
|
129
|
+
this.log(err.message);
|
|
130
|
+
throw new Error(
|
|
131
|
+
'Unable to import the files in the mesh config. Please check the file and try again.',
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
//Generating unique mesh id
|
|
137
|
+
let meshId = UUID.newUuid().toString();
|
|
138
|
+
|
|
139
|
+
await validateMesh(data.meshConfig);
|
|
140
|
+
await buildMesh(meshId, data.meshConfig);
|
|
141
|
+
await compileMesh(meshId);
|
|
142
|
+
|
|
143
|
+
this.log(`Starting server on port : ${portNo}`);
|
|
144
|
+
await startGraphqlServer(meshId, portNo, flags.debug);
|
|
145
|
+
} else {
|
|
146
|
+
throw new Error(
|
|
147
|
+
'`aio api-mesh run` cannot be executed because there is no package.json file in the current directory. Use `aio api-mesh init` to set up a package.',
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
} catch (error) {
|
|
151
|
+
this.error(error.message);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
module.exports = RunCommand;
|
|
@@ -39,6 +39,7 @@ initSdk.mockResolvedValue({
|
|
|
39
39
|
imsOrgId: selectedOrg.id,
|
|
40
40
|
projectId: selectedProject.id,
|
|
41
41
|
workspaceId: selectedWorkspace.id,
|
|
42
|
+
workspaceName: selectedWorkspace.title,
|
|
42
43
|
});
|
|
43
44
|
initRequestId.mockResolvedValue({});
|
|
44
45
|
promptInput.mockResolvedValueOnce('test-03');
|
|
@@ -146,6 +147,7 @@ describe('source:install command tests', () => {
|
|
|
146
147
|
selectedOrg.id,
|
|
147
148
|
selectedProject.id,
|
|
148
149
|
selectedWorkspace.id,
|
|
150
|
+
selectedWorkspace.title,
|
|
149
151
|
'dummy_meshId',
|
|
150
152
|
res,
|
|
151
153
|
);
|
|
@@ -36,7 +36,7 @@ class InstallCommand extends Command {
|
|
|
36
36
|
await initRequestId();
|
|
37
37
|
logger.info(`RequestId: ${global.requestId}`);
|
|
38
38
|
const ignoreCache = await flags.ignoreCache;
|
|
39
|
-
const { imsOrgId, projectId, workspaceId } = await initSdk({ ignoreCache });
|
|
39
|
+
const { imsOrgId, projectId, workspaceId, workspaceName } = await initSdk({ ignoreCache });
|
|
40
40
|
const filepath = flags['variable-file'];
|
|
41
41
|
let variables = flags.variable
|
|
42
42
|
? flags.variable.reduce((obj, val) => {
|
|
@@ -119,7 +119,7 @@ class InstallCommand extends Command {
|
|
|
119
119
|
}
|
|
120
120
|
|
|
121
121
|
try {
|
|
122
|
-
meshId = await getMeshId(imsOrgId, projectId, workspaceId);
|
|
122
|
+
meshId = await getMeshId(imsOrgId, projectId, workspaceId, workspaceName);
|
|
123
123
|
} catch (err) {
|
|
124
124
|
this.error(
|
|
125
125
|
`Unable to get mesh ID. Please check the details and try again. RequestId: ${global.requestId}`,
|
|
@@ -133,7 +133,7 @@ class InstallCommand extends Command {
|
|
|
133
133
|
}
|
|
134
134
|
|
|
135
135
|
try {
|
|
136
|
-
const mesh = await getMesh(imsOrgId, projectId, workspaceId, meshId);
|
|
136
|
+
const mesh = await getMesh(imsOrgId, projectId, workspaceId, meshId, workspaceName);
|
|
137
137
|
|
|
138
138
|
if (!mesh) {
|
|
139
139
|
this.error(
|
|
@@ -199,7 +199,7 @@ class InstallCommand extends Command {
|
|
|
199
199
|
}
|
|
200
200
|
|
|
201
201
|
try {
|
|
202
|
-
const response = await updateMesh(imsOrgId, projectId, workspaceId, meshId, {
|
|
202
|
+
const response = await updateMesh(imsOrgId, projectId, workspaceId, workspaceName, meshId, {
|
|
203
203
|
meshConfig: mesh.meshConfig,
|
|
204
204
|
});
|
|
205
205
|
|
|
@@ -18,14 +18,14 @@ class StatusCommand extends Command {
|
|
|
18
18
|
const { flags } = await this.parse(StatusCommand);
|
|
19
19
|
const ignoreCache = await flags.ignoreCache;
|
|
20
20
|
|
|
21
|
-
const { imsOrgId, projectId, workspaceId } = await initSdk({
|
|
21
|
+
const { imsOrgId, projectId, workspaceId, workspaceName } = await initSdk({
|
|
22
22
|
ignoreCache,
|
|
23
23
|
});
|
|
24
24
|
|
|
25
25
|
let meshId = null;
|
|
26
26
|
|
|
27
27
|
try {
|
|
28
|
-
meshId = await getMeshId(imsOrgId, projectId, workspaceId);
|
|
28
|
+
meshId = await getMeshId(imsOrgId, projectId, workspaceId, workspaceName);
|
|
29
29
|
} catch (err) {
|
|
30
30
|
this.log(err.message);
|
|
31
31
|
this.error(
|
|
@@ -35,7 +35,7 @@ class StatusCommand extends Command {
|
|
|
35
35
|
|
|
36
36
|
if (meshId) {
|
|
37
37
|
try {
|
|
38
|
-
const mesh = await getMesh(imsOrgId, projectId, workspaceId, meshId);
|
|
38
|
+
const mesh = await getMesh(imsOrgId, projectId, workspaceId, workspaceName, meshId);
|
|
39
39
|
switch (mesh.meshStatus) {
|
|
40
40
|
case 'success':
|
|
41
41
|
this.log(
|
package/src/constants.js
CHANGED
|
@@ -19,10 +19,6 @@ const ProdConstants = {
|
|
|
19
19
|
AIO_CLI_API_KEY: 'aio-cli-console-auth',
|
|
20
20
|
SMS_BASE_URL: 'https://graph.adobe.io/api-admin',
|
|
21
21
|
};
|
|
22
|
-
|
|
23
|
-
TMO_STAGE_URL: 'https://tigraph-dev.adobe.io/api',
|
|
24
|
-
TMO_SANDBOX_URL: 'https://tigraph-sandbox.adobe.io/api',
|
|
25
|
-
TMO_PROD_URL: 'https://tigraph.adobe.io/api',
|
|
26
|
-
};
|
|
22
|
+
|
|
27
23
|
const envConstants = clientEnv === 'stage' ? StageConstants : ProdConstants;
|
|
28
|
-
module.exports = { ...envConstants
|
|
24
|
+
module.exports = { ...envConstants };
|
package/src/helpers.js
CHANGED
|
@@ -424,6 +424,7 @@ async function initSdk(options) {
|
|
|
424
424
|
imsOrgId: org.id,
|
|
425
425
|
projectId: project.id,
|
|
426
426
|
workspaceId: workspace.id,
|
|
427
|
+
workspaceName: workspace.title,
|
|
427
428
|
};
|
|
428
429
|
}
|
|
429
430
|
|
|
@@ -521,7 +522,13 @@ async function promptInput(message) {
|
|
|
521
522
|
* @param meshConfigName MeshConfigName
|
|
522
523
|
* @param autoConfirmActionFlag The user won't be prompted any questions, if this flag is set
|
|
523
524
|
*/
|
|
524
|
-
async function importFiles(
|
|
525
|
+
async function importFiles(
|
|
526
|
+
data,
|
|
527
|
+
filesListArray,
|
|
528
|
+
meshConfigName,
|
|
529
|
+
autoConfirmActionFlag,
|
|
530
|
+
shouldMinifyJS = true,
|
|
531
|
+
) {
|
|
525
532
|
//if autoConfirmActionFlag is passed in the command, it should override by default
|
|
526
533
|
let shouldOverride = true;
|
|
527
534
|
let filesNotFound = [];
|
|
@@ -557,7 +564,7 @@ async function importFiles(data, filesListArray, meshConfigName, autoConfirmActi
|
|
|
557
564
|
} else {
|
|
558
565
|
//if file does not exist in files array, but exists in filesystem, we append
|
|
559
566
|
if (fs.existsSync(path.resolve(path.dirname(meshConfigName), file))) {
|
|
560
|
-
resultData = updateFilesArray(resultData, file, meshConfigName, -1);
|
|
567
|
+
resultData = updateFilesArray(resultData, file, meshConfigName, -1, shouldMinifyJS);
|
|
561
568
|
} else {
|
|
562
569
|
filesNotFound.push(file);
|
|
563
570
|
}
|
|
@@ -587,6 +594,7 @@ async function importFiles(data, filesListArray, meshConfigName, autoConfirmActi
|
|
|
587
594
|
overrideArr[i].fileName,
|
|
588
595
|
meshConfigName,
|
|
589
596
|
overrideArr[i].index,
|
|
597
|
+
shouldMinifyJS,
|
|
590
598
|
);
|
|
591
599
|
}
|
|
592
600
|
}
|
|
@@ -672,7 +680,7 @@ function runCliCommand(command, workingDirectory = '.') {
|
|
|
672
680
|
* @param meshConfigName MeshConfig name
|
|
673
681
|
* @param index Append operation if index is -1, else override, it is the index where the override takes place
|
|
674
682
|
*/
|
|
675
|
-
function updateFilesArray(data, file, meshConfigName, index) {
|
|
683
|
+
function updateFilesArray(data, file, meshConfigName, index, shouldMinifyJS = true) {
|
|
676
684
|
try {
|
|
677
685
|
let readFileData = fs.readFileSync(
|
|
678
686
|
path.resolve(path.dirname(meshConfigName), file),
|
|
@@ -694,8 +702,17 @@ function updateFilesArray(data, file, meshConfigName, index) {
|
|
|
694
702
|
throw new Error(`Invalid JSON content in ${path.basename(file)}`);
|
|
695
703
|
}
|
|
696
704
|
|
|
697
|
-
//
|
|
698
|
-
|
|
705
|
+
// shouldMinifyJS would be always true for create and update commands
|
|
706
|
+
// if run command run on debug mode it will be false and js files wont be minified
|
|
707
|
+
if (shouldMinifyJS) {
|
|
708
|
+
readFileData = jsmin(readFileData);
|
|
709
|
+
} else {
|
|
710
|
+
if (path.extname(file) !== '.js') {
|
|
711
|
+
readFileData = jsmin(readFileData);
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
const dataInFilesArray = readFileData;
|
|
699
716
|
|
|
700
717
|
if (index >= 0) {
|
|
701
718
|
data.meshConfig.files[index] = {
|
|
@@ -722,6 +739,42 @@ function updateFilesArray(data, file, meshConfigName, index) {
|
|
|
722
739
|
}
|
|
723
740
|
}
|
|
724
741
|
|
|
742
|
+
/**
|
|
743
|
+
* Start GraphQL server for a particular mesh on a particular port
|
|
744
|
+
*
|
|
745
|
+
* @param meshId MeshId of the mesh
|
|
746
|
+
* @param port Port number at which the server is to be started
|
|
747
|
+
* @param debug Boolean flag to set the debug mode
|
|
748
|
+
*/
|
|
749
|
+
function startGraphqlServer(meshId, port, debug) {
|
|
750
|
+
const serverPath = `${__dirname}/server.js ${meshId} ${port}`;
|
|
751
|
+
const command = debug
|
|
752
|
+
? `node --inspect-brk --trace-warnings ${serverPath}`
|
|
753
|
+
: `node ${serverPath}`;
|
|
754
|
+
|
|
755
|
+
const server = exec(command);
|
|
756
|
+
|
|
757
|
+
server.stdout.on('data', data => {
|
|
758
|
+
console.log(data);
|
|
759
|
+
});
|
|
760
|
+
|
|
761
|
+
server.stderr.on('data', data => {
|
|
762
|
+
console.error(data);
|
|
763
|
+
});
|
|
764
|
+
|
|
765
|
+
server.on('close', code => {
|
|
766
|
+
console.log(`Server closed with code ${code}`);
|
|
767
|
+
});
|
|
768
|
+
|
|
769
|
+
server.on('exit', code => {
|
|
770
|
+
console.log(`Server exited with code ${code}`);
|
|
771
|
+
});
|
|
772
|
+
|
|
773
|
+
server.on('error', err => {
|
|
774
|
+
console.error(`Server exited with error ${err}`);
|
|
775
|
+
});
|
|
776
|
+
}
|
|
777
|
+
|
|
725
778
|
module.exports = {
|
|
726
779
|
objToString,
|
|
727
780
|
promptInput,
|
|
@@ -736,4 +789,5 @@ module.exports = {
|
|
|
736
789
|
interpolateMesh,
|
|
737
790
|
runCliCommand,
|
|
738
791
|
updateFilesArray,
|
|
792
|
+
startGraphqlServer,
|
|
739
793
|
};
|
package/src/lib/devConsole.js
CHANGED
|
@@ -76,11 +76,11 @@ const getApiKeyCredential = async (organizationId, projectId, workspaceId) => {
|
|
|
76
76
|
}
|
|
77
77
|
};
|
|
78
78
|
|
|
79
|
-
const describeMesh = async (organizationId, projectId, workspaceId) => {
|
|
79
|
+
const describeMesh = async (organizationId, projectId, workspaceId, workspaceName) => {
|
|
80
80
|
logger.info('Initiating Describe Mesh');
|
|
81
81
|
|
|
82
82
|
try {
|
|
83
|
-
const meshId = await getMeshId(organizationId, projectId, workspaceId);
|
|
83
|
+
const meshId = await getMeshId(organizationId, projectId, workspaceId, workspaceName);
|
|
84
84
|
|
|
85
85
|
logger.info('Response from getMeshId %s', meshId);
|
|
86
86
|
|
|
@@ -106,7 +106,7 @@ const describeMesh = async (organizationId, projectId, workspaceId) => {
|
|
|
106
106
|
}
|
|
107
107
|
};
|
|
108
108
|
|
|
109
|
-
const getMesh = async (organizationId, projectId, workspaceId, meshId) => {
|
|
109
|
+
const getMesh = async (organizationId, projectId, workspaceId, workspaceName, meshId) => {
|
|
110
110
|
const { baseUrl: devConsoleUrl, accessToken, apiKey } = await getDevConsoleConfig();
|
|
111
111
|
const config = {
|
|
112
112
|
method: 'get',
|
|
@@ -114,6 +114,7 @@ const getMesh = async (organizationId, projectId, workspaceId, meshId) => {
|
|
|
114
114
|
headers: {
|
|
115
115
|
'Authorization': `Bearer ${accessToken}`,
|
|
116
116
|
'x-request-id': global.requestId,
|
|
117
|
+
'workspaceName': workspaceName,
|
|
117
118
|
},
|
|
118
119
|
};
|
|
119
120
|
|
|
@@ -187,7 +188,7 @@ const getMesh = async (organizationId, projectId, workspaceId, meshId) => {
|
|
|
187
188
|
}
|
|
188
189
|
};
|
|
189
190
|
|
|
190
|
-
const createMesh = async (organizationId, projectId, workspaceId, data) => {
|
|
191
|
+
const createMesh = async (organizationId, projectId, workspaceId, workspaceName, data) => {
|
|
191
192
|
const { baseUrl: devConsoleUrl, accessToken, apiKey } = await getDevConsoleConfig();
|
|
192
193
|
const config = {
|
|
193
194
|
method: 'post',
|
|
@@ -480,7 +481,7 @@ const deleteMesh = async (organizationId, projectId, workspaceId, meshId) => {
|
|
|
480
481
|
}
|
|
481
482
|
};
|
|
482
483
|
|
|
483
|
-
const getMeshId = async (organizationId, projectId, workspaceId) => {
|
|
484
|
+
const getMeshId = async (organizationId, projectId, workspaceId, workspaceName) => {
|
|
484
485
|
const { baseUrl: devConsoleUrl, accessToken, apiKey } = await getDevConsoleConfig();
|
|
485
486
|
logger.info('Initiating Mesh ID request');
|
|
486
487
|
|
|
@@ -490,6 +491,7 @@ const getMeshId = async (organizationId, projectId, workspaceId) => {
|
|
|
490
491
|
headers: {
|
|
491
492
|
'Authorization': `Bearer ${accessToken}`,
|
|
492
493
|
'x-request-id': global.requestId,
|
|
494
|
+
'workspaceName': workspaceName,
|
|
493
495
|
},
|
|
494
496
|
};
|
|
495
497
|
|