@mimik/local 6.0.12 → 7.0.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 +23 -23
- package/configuration/config.js +32 -28
- package/dotFiles/eslint.config.js +63 -0
- package/eslint.config.js +65 -0
- package/index.js +97 -93
- package/lib/common.js +3 -1
- package/lib/commonExt.js +12 -9
- package/lib/helpers.js +49 -30
- package/lib/rp-axios-wrapper.js +4 -5
- package/lib/tasks.js +113 -100
- package/manual-test/getAPI.js +1 -1
- package/manual-test/retrieve.js +1 -1
- package/manual-test/testMerge.js +27 -13
- package/manual-test/testString.js +4 -3
- package/package.json +34 -27
- package/scripts.json +3 -4
- package/.eslintrc +0 -43
- package/dotFiles/eslintrc.json +0 -102
package/index.js
CHANGED
|
@@ -1,43 +1,42 @@
|
|
|
1
1
|
/* eslint-disable prefer-template, no-console */
|
|
2
|
-
|
|
3
|
-
const path = require('path');
|
|
4
|
-
const _ = require('lodash');
|
|
5
|
-
|
|
6
|
-
const { commitCheckMsg } = require('@mimik/git-hooks');
|
|
7
|
-
|
|
8
|
-
const {
|
|
9
|
-
colors,
|
|
10
|
-
exitError,
|
|
11
|
-
start2env,
|
|
12
|
-
start2shell,
|
|
13
|
-
start2process,
|
|
14
|
-
baseUrl,
|
|
15
|
-
read,
|
|
16
|
-
write,
|
|
17
|
-
parse,
|
|
18
|
-
} = require('./lib/helpers');
|
|
19
|
-
const {
|
|
2
|
+
import {
|
|
20
3
|
DEFAULT_DIRECTORY,
|
|
21
|
-
testJsonFile,
|
|
22
|
-
shellFile,
|
|
23
4
|
DUMMY_CUSTOMER_CODE,
|
|
5
|
+
IGNORE,
|
|
24
6
|
LITERAL,
|
|
25
7
|
SYSTEM_NAME,
|
|
26
8
|
TEST,
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
9
|
+
shellFile,
|
|
10
|
+
testJsonFile,
|
|
11
|
+
} from './lib/common.js';
|
|
12
|
+
import {
|
|
13
|
+
baseUrl,
|
|
14
|
+
colors,
|
|
15
|
+
exitError,
|
|
16
|
+
parse,
|
|
17
|
+
read,
|
|
18
|
+
start2env,
|
|
19
|
+
start2process,
|
|
20
|
+
start2shell,
|
|
21
|
+
write,
|
|
22
|
+
} from './lib/helpers.js';
|
|
23
|
+
import { dirname, join } from 'path';
|
|
24
|
+
import {
|
|
33
25
|
getAPI,
|
|
34
26
|
getAdminToken,
|
|
35
|
-
|
|
27
|
+
getStartParams,
|
|
36
28
|
gettingSystemCustomer,
|
|
37
|
-
|
|
38
|
-
settingUpCustomer,
|
|
29
|
+
init,
|
|
39
30
|
settingUpAdminClient,
|
|
40
|
-
|
|
31
|
+
settingUpCustomer,
|
|
32
|
+
settingUpDummyServer,
|
|
33
|
+
settingUpServer,
|
|
34
|
+
startSetup,
|
|
35
|
+
} from './lib/tasks.js';
|
|
36
|
+
import { commitCheckMsg } from '@mimik/git-hooks';
|
|
37
|
+
import { fileURLToPath } from 'url';
|
|
38
|
+
import find from 'lodash.find';
|
|
39
|
+
import fs from 'fs';
|
|
41
40
|
|
|
42
41
|
colors.setTheme({
|
|
43
42
|
success: 'green',
|
|
@@ -47,15 +46,20 @@ colors.setTheme({
|
|
|
47
46
|
});
|
|
48
47
|
|
|
49
48
|
const INSTALL = 'install';
|
|
49
|
+
const TAB = 2;
|
|
50
|
+
const FIRST = 0;
|
|
51
|
+
const localDirname = dirname(fileURLToPath(import.meta.url));
|
|
50
52
|
|
|
51
|
-
const getBasePath =
|
|
53
|
+
const getBasePath = apiDef => apiDef.basePath || apiDef.servers[FIRST].url;
|
|
52
54
|
|
|
53
55
|
/**
|
|
54
56
|
* @module local
|
|
55
57
|
* @example
|
|
56
|
-
*
|
|
58
|
+
* import local from '@mimik/local';
|
|
59
|
+
* or
|
|
60
|
+
* import { mSTTestSetup, mSTSetup, mITTestSetup, mITSetup, testSetup, setup, dotFiles, scripts, unScripts, commitCheckMsg, start2process, testJsonFile} from '@mimik/local';
|
|
57
61
|
*
|
|
58
|
-
* @description Set of
|
|
62
|
+
* @description Set of functions for local deployment.
|
|
59
63
|
*
|
|
60
64
|
* The following files are expected to exist:
|
|
61
65
|
* In the directory above the server root directory: `mSTConfig.json`, `mIDConfig.json`, `mITConfig.json`,`sumoLog.json`, `kinesisLog.json`, `s3Log.json`, `customerConfig.json`, `key.json`, `locationConfig.json` are being set. If they don't exist at the launch of the script, default will be setup.
|
|
@@ -117,9 +121,9 @@ const getBasePath = (apiDef) => apiDef.basePath || apiDef.servers[0].url;
|
|
|
117
121
|
* "region": "region of the Kinesis implementation",
|
|
118
122
|
* "accessKeyId": "access key id of Kinesis",
|
|
119
123
|
* "secretAccessKey": "secret access key for Kinesis",
|
|
120
|
-
* "streamNameInfo": "name of the
|
|
121
|
-
* "streamNameError": "name of the
|
|
122
|
-
* "streamNameOther": "name of the
|
|
124
|
+
* "streamNameInfo": "name of the Kinesis stream for info",
|
|
125
|
+
* "streamNameError": "name of the Kinesis stream for error",
|
|
126
|
+
* "streamNameOther": "name of the Kinesis stream for all the other levels"
|
|
123
127
|
* }
|
|
124
128
|
* ```
|
|
125
129
|
* - for `s3Log.json`:
|
|
@@ -157,7 +161,7 @@ const getBasePath = (apiDef) => apiDef.basePath || apiDef.servers[0].url;
|
|
|
157
161
|
* - in the `local` directory of the server root directory: two files `start.json` and `testStart.json` may exit. `start.json` is used when `npm start` is executed, `testStart.json` is used when `npm test` is executed.
|
|
158
162
|
* If the files don't exist `exampe-start.json` is used to create `start.json` and `testStart.json`.
|
|
159
163
|
* Additionally `example-testStart.json` is used when to create `testStart.json`. The values in `example-testStart.json` take precedence over the values in `example-start.json`.
|
|
160
|
-
* The configuration of these files depends on the configuration parameters of the server.
|
|
164
|
+
* The configuration of these files depends on the configuration parameters of the server.
|
|
161
165
|
* The following is an example of start.json file for `mIT`:
|
|
162
166
|
* ``` javascript
|
|
163
167
|
* {
|
|
@@ -173,11 +177,11 @@ const getBasePath = (apiDef) => apiDef.basePath || apiDef.servers[0].url;
|
|
|
173
177
|
* }
|
|
174
178
|
* ```
|
|
175
179
|
* While all the files use the `.json` extension it is still possible to add comments `//` in the file to make the file more explicit or to remove some parameters.
|
|
176
|
-
* There are reserved environement
|
|
180
|
+
* There are reserved environement variables used by the library for configuration:
|
|
177
181
|
* - `oauthImplicitNeeded`: if the service handles user token the implicit configuration is needed
|
|
178
182
|
* - `mIDNeeded`: if the service has mID as a target
|
|
179
183
|
* - `locationNeeded`: if location translation is needed
|
|
180
|
-
* - `standAlone`: if the service
|
|
184
|
+
* - `standAlone`: if the service needs to be operated without other service. If the service has targets most likely 500 errors will be generated
|
|
181
185
|
*
|
|
182
186
|
* If SERVER_ID is not set in the start.json or testStart.json file, SERVER_ID will be assigned with a uuid.v4.
|
|
183
187
|
*
|
|
@@ -185,7 +189,7 @@ const getBasePath = (apiDef) => apiDef.basePath || apiDef.servers[0].url;
|
|
|
185
189
|
* This file contains informations needed to start the test:
|
|
186
190
|
* ``` javascript
|
|
187
191
|
* {
|
|
188
|
-
* "start": "information needed to setup the environement
|
|
192
|
+
* "start": "information needed to setup the environement variables for the test",
|
|
189
193
|
* "CUSTOMER_NAME": "name of the customer to setup customer config",
|
|
190
194
|
* "CUSTOMER_CODE": "code of the customer to setup coustomer config, `not available for MST`",
|
|
191
195
|
* "BASE_PATH": "base path of the API",
|
|
@@ -207,11 +211,11 @@ const mSTInit = (confType) => {
|
|
|
207
211
|
.then((apiDefinition) => {
|
|
208
212
|
console.log('- mST base url: ' + config.mSTBaseUrl.info);
|
|
209
213
|
console.log('- mIT base url: ' + config.MITBaseUrl.info);
|
|
210
|
-
console.log('- mST config: ' + JSON.stringify(config.mST, null,
|
|
214
|
+
console.log('- mST config: ' + JSON.stringify(config.mST, null, TAB).info);
|
|
211
215
|
if (confType === TEST) {
|
|
212
216
|
start.CUSTOMER_NAME = SYSTEM_NAME;
|
|
213
217
|
start.BASE_PATH = getBasePath(apiDefinition);
|
|
214
|
-
return { file: testJsonFile, content: JSON.stringify(start2env(start), null,
|
|
218
|
+
return { file: testJsonFile, content: JSON.stringify(start2env(start), null, TAB), type: 'JSON file' };
|
|
215
219
|
}
|
|
216
220
|
return { file: shellFile, content: start2shell(start), type: 'shell script' };
|
|
217
221
|
})
|
|
@@ -219,7 +223,7 @@ const mSTInit = (confType) => {
|
|
|
219
223
|
fs.writeFileSync(response.file, response.content);
|
|
220
224
|
console.log(`${regType}status: ` + 'completed'.success + ', ' + response.type.info + ' created at (' + response.file.info + ')');
|
|
221
225
|
})
|
|
222
|
-
.catch(
|
|
226
|
+
.catch(err => exitError(regType, err));
|
|
223
227
|
};
|
|
224
228
|
|
|
225
229
|
const mITInit = (confType) => {
|
|
@@ -241,7 +245,7 @@ const mITInit = (confType) => {
|
|
|
241
245
|
start.CUSTOMER_NAME = SYSTEM_NAME;
|
|
242
246
|
start.CUSTOMER_CODE = DUMMY_CUSTOMER_CODE;
|
|
243
247
|
start.BASE_PATH = getBasePath(apiDefinition);
|
|
244
|
-
return { file: testJsonFile, content: JSON.stringify(start2env(start), null,
|
|
248
|
+
return { file: testJsonFile, content: JSON.stringify(start2env(start), null, TAB), type: 'JSON file' };
|
|
245
249
|
}
|
|
246
250
|
return { file: shellFile, content: start2shell(start), type: 'shell script' };
|
|
247
251
|
}
|
|
@@ -254,12 +258,12 @@ const mITInit = (confType) => {
|
|
|
254
258
|
authorization = mSTAdminToken;
|
|
255
259
|
return gettingSystemCustomer(authorization, mSTBaseUrl);
|
|
256
260
|
})
|
|
257
|
-
.then(
|
|
261
|
+
.then(customer => settingUpServer(type, start.SERVER_ID, customer, authorization, mSTBaseUrl, start)
|
|
258
262
|
.then((updatedStart) => {
|
|
259
263
|
start = updatedStart;
|
|
260
264
|
return settingUpAdminClient(type, `admin_${customer.name}_${start.NODE_ENV}_${type}`, customer, authorization, mSTBaseUrl)
|
|
261
265
|
.then((adminType) => {
|
|
262
|
-
const adminAudience =
|
|
266
|
+
const adminAudience = find(adminType.audiences, audienceItem => audienceItem.type === type);
|
|
263
267
|
if (adminAudience) return getAdminToken(adminAudience, adminType.data, mSTBaseUrl);
|
|
264
268
|
return undefined;
|
|
265
269
|
})
|
|
@@ -270,7 +274,7 @@ const mITInit = (confType) => {
|
|
|
270
274
|
start.BASE_PATH = getBasePath(apiDefinition);
|
|
271
275
|
start.MST_TOKEN = authorization;
|
|
272
276
|
start.ADMIN_TOKEN = adminToken;
|
|
273
|
-
return { file: testJsonFile, content: JSON.stringify(start2env(start), null,
|
|
277
|
+
return { file: testJsonFile, content: JSON.stringify(start2env(start), null, TAB), type: 'JSON file' };
|
|
274
278
|
}
|
|
275
279
|
if (adminToken) console.log('- admin token for the service: ' + adminToken.info);
|
|
276
280
|
console.log('- mST token: ' + authorization.info);
|
|
@@ -282,7 +286,7 @@ const mITInit = (confType) => {
|
|
|
282
286
|
fs.writeFileSync(response.file, response.content);
|
|
283
287
|
console.log(`${regType}status: ` + 'completed'.success + ', ' + response.type.info + ' created at (' + response.file.info + ')');
|
|
284
288
|
})
|
|
285
|
-
.catch(
|
|
289
|
+
.catch(err => exitError(regType, err));
|
|
286
290
|
};
|
|
287
291
|
|
|
288
292
|
const serverInit = (confType) => {
|
|
@@ -308,7 +312,7 @@ const serverInit = (confType) => {
|
|
|
308
312
|
start.CUSTOMER_NAME = customer.name;
|
|
309
313
|
start.CUSTOMER_CODE = DUMMY_CUSTOMER_CODE;
|
|
310
314
|
start.BASE_PATH = getBasePath(apiDefinition);
|
|
311
|
-
return { file: testJsonFile, content: JSON.stringify(start2env(start), null,
|
|
315
|
+
return { file: testJsonFile, content: JSON.stringify(start2env(start), null, TAB), type: 'JSON file' };
|
|
312
316
|
}
|
|
313
317
|
return { file: shellFile, content: start2shell(start), type: 'shell script' };
|
|
314
318
|
}
|
|
@@ -330,7 +334,7 @@ const serverInit = (confType) => {
|
|
|
330
334
|
start = updatedStart;
|
|
331
335
|
return settingUpAdminClient(type, `admin_${customer.name}_${start.NODE_ENV}_${type}`, customer, authorization, mSTBaseUrl)
|
|
332
336
|
.then((adminType) => {
|
|
333
|
-
const adminAudience =
|
|
337
|
+
const adminAudience = find(adminType.audiences, audienceItem => audienceItem.type === type);
|
|
334
338
|
if (adminAudience) return getAdminToken(adminAudience, adminType.data, mSTBaseUrl);
|
|
335
339
|
return undefined;
|
|
336
340
|
})
|
|
@@ -341,14 +345,14 @@ const serverInit = (confType) => {
|
|
|
341
345
|
start.BASE_PATH = getBasePath(apiDefinition);
|
|
342
346
|
start.MST_TOKEN = authorization;
|
|
343
347
|
start.ADMIN_TOKEN = adminToken;
|
|
344
|
-
const testResponse = { file: testJsonFile, content: JSON.stringify(start2env(start), null,
|
|
348
|
+
const testResponse = { file: testJsonFile, content: JSON.stringify(start2env(start), null, TAB), type: 'JSON file' };
|
|
345
349
|
|
|
346
350
|
if (startConfig.oauthImplicitNeeded === 'yes') {
|
|
347
351
|
return settingUpAdminClient('mID', `admin_${customer.name}_${start.NODE_ENV}_mID`, customer, start.MST_TOKEN, mSTBaseUrl)
|
|
348
|
-
.then(
|
|
352
|
+
.then(mIDAdminType => getAdminToken(find(mIDAdminType.audiences, audienceItem => audienceItem.type === 'mID'), mIDAdminType.data, mSTBaseUrl))
|
|
349
353
|
.then((mIDAdminToken) => {
|
|
350
354
|
start.MID_TOKEN = mIDAdminToken;
|
|
351
|
-
testResponse.content = JSON.stringify(start2env(start), null,
|
|
355
|
+
testResponse.content = JSON.stringify(start2env(start), null, TAB);
|
|
352
356
|
return testResponse;
|
|
353
357
|
});
|
|
354
358
|
}
|
|
@@ -364,7 +368,7 @@ const serverInit = (confType) => {
|
|
|
364
368
|
fs.writeFileSync(response.file, response.content);
|
|
365
369
|
console.log(`${regType}status: ` + 'completed'.success + ', ' + response.type.info + ' created at (' + response.file.info + ')');
|
|
366
370
|
})
|
|
367
|
-
.catch(
|
|
371
|
+
.catch(err => exitError(regType, err));
|
|
368
372
|
};
|
|
369
373
|
|
|
370
374
|
/**
|
|
@@ -392,9 +396,9 @@ const serverInit = (confType) => {
|
|
|
392
396
|
* | `../s3Log.json` | The S3 information
|
|
393
397
|
* | `../mSTConfig.json` | The config for mST
|
|
394
398
|
* | `../mITConfig.json` | The config for mIT
|
|
395
|
-
* | `./local/testStart.json` | The local configuration. If it does not exist start.json and if sart.json does not exist start-example.json will be used to create start.json
|
|
399
|
+
* | `./local/testStart.json` | The local configuration. If it does not exist start.json will be used and if sart.json does not exist start-example.json will be used to create start.json
|
|
396
400
|
*/
|
|
397
|
-
const mSTTestSetup = () => mSTInit(TEST);
|
|
401
|
+
export const mSTTestSetup = () => mSTInit(TEST);
|
|
398
402
|
|
|
399
403
|
/**
|
|
400
404
|
*
|
|
@@ -423,7 +427,7 @@ const mSTTestSetup = () => mSTInit(TEST);
|
|
|
423
427
|
* | `../mITConfig.json` | The config for mIT
|
|
424
428
|
* | `./local/start.json` | The local configuration. If it does not exist start-example.json will be used to create start.json
|
|
425
429
|
*/
|
|
426
|
-
const mSTSetup = () => mSTInit();
|
|
430
|
+
export const mSTSetup = () => mSTInit();
|
|
427
431
|
|
|
428
432
|
/**
|
|
429
433
|
*
|
|
@@ -445,9 +449,9 @@ const mSTSetup = () => mSTInit();
|
|
|
445
449
|
*
|
|
446
450
|
* 1. retrieve the API from [swaggerhub](https://app.swaggerhub.com/search?type=API&owner=mimik)
|
|
447
451
|
* 2. get an admin token for that service
|
|
448
|
-
* 3. generate a
|
|
452
|
+
* 3. generate a JSON object store in a file under .
|
|
449
453
|
*
|
|
450
|
-
* In standAlone the dependencies will not be reachable and the operation that implies reaching dependencies will most likely generate a 500 error
|
|
454
|
+
* In standAlone the dependencies will not be reachable and the operation that implies reaching dependencies will most likely generate a 500 error.
|
|
451
455
|
*
|
|
452
456
|
* When mST and other servers are present, the following actions are being performed:
|
|
453
457
|
*
|
|
@@ -457,7 +461,7 @@ const mSTSetup = () => mSTInit();
|
|
|
457
461
|
* 4. register an admin client for that service in mST
|
|
458
462
|
* 5. get an admin token for that service
|
|
459
463
|
* 6. get an admin token for mID if needed
|
|
460
|
-
* 7. generate a
|
|
464
|
+
* 7. generate a JSON object store in a file under .
|
|
461
465
|
*
|
|
462
466
|
* The following files are needed to perform these actions:
|
|
463
467
|
*
|
|
@@ -468,9 +472,9 @@ const mSTSetup = () => mSTInit();
|
|
|
468
472
|
* | `../s3Log.json` | The S3 information
|
|
469
473
|
* | `../mSTConfig.json` | The config for mST
|
|
470
474
|
* | `../mITConfig.json` | The config for mIT
|
|
471
|
-
* | `./local/testStart.json` | The local configuration. If it does not exist start.json and if sart.json does not exist start-example.json will be used to create start.json
|
|
475
|
+
* | `./local/testStart.json` | The local configuration. If it does not exist start.json will be used and if sart.json does not exist start-example.json will be used to create start.json
|
|
472
476
|
*/
|
|
473
|
-
const mITTestSetup = () => mITInit(TEST);
|
|
477
|
+
export const mITTestSetup = () => mITInit(TEST);
|
|
474
478
|
|
|
475
479
|
/**
|
|
476
480
|
*
|
|
@@ -494,13 +498,12 @@ const mITTestSetup = () => mITInit(TEST);
|
|
|
494
498
|
* 2. get an admin token for that service
|
|
495
499
|
* 3. generate a shell script to start the server
|
|
496
500
|
*
|
|
497
|
-
* In standAlone the dependencies will not be reachable and the operation that implies reaching dependencies will most likely generate a 500 error
|
|
501
|
+
* In standAlone the dependencies will not be reachable and the operation that implies reaching dependencies will most likely generate a 500 error.
|
|
498
502
|
*
|
|
499
503
|
* When mST is present, the following actions are being performed:
|
|
500
504
|
*
|
|
501
|
-
*
|
|
502
505
|
* 1. retrieve the API from [swaggerhub](https://app.swaggerhub.com/search?type=API&owner=mimik)
|
|
503
|
-
* 2. get an
|
|
506
|
+
* 2. get an admin token for mST
|
|
504
507
|
* 3. register the service in mST
|
|
505
508
|
* 4. generate a shell script to start the server
|
|
506
509
|
*
|
|
@@ -537,9 +540,9 @@ const mITSetup = () => mITInit();
|
|
|
537
540
|
*
|
|
538
541
|
* 1. retrieve the API from [swaggerhub](https://app.swaggerhub.com/search?type=API&owner=mimik)
|
|
539
542
|
* 2. get an admin token for that service
|
|
540
|
-
* 3. generate a
|
|
543
|
+
* 3. generate a JSON object store in a file under .
|
|
541
544
|
*
|
|
542
|
-
* In standAlone the dependencies will not be reachable and the operation that implies reaching dependencies will most likely generate a 500 error
|
|
545
|
+
* In standAlone the dependencies will not be reachable and the operation that implies reaching dependencies will most likely generate a 500 error.
|
|
543
546
|
*
|
|
544
547
|
* When mST and other servers are present, the following actions are being performed:
|
|
545
548
|
*
|
|
@@ -563,9 +566,9 @@ const mITSetup = () => mITInit();
|
|
|
563
566
|
* | `../mITConfig.json` | The config for mIT
|
|
564
567
|
* | `../mIDConfig.json` | The config for mID
|
|
565
568
|
* | `../customerConfig.json` | The mST customer config
|
|
566
|
-
* | `./local/testStart.json` | The local configuration. If it does not exist start.json and if sart.json does not exist start-example.json will be used to create start.json
|
|
569
|
+
* | `./local/testStart.json` | The local configuration. If it does not exist start.json will be used and if sart.json does not exist start-example.json will be used to create start.json
|
|
567
570
|
*/
|
|
568
|
-
const testSetup = () => serverInit(TEST);
|
|
571
|
+
export const testSetup = () => serverInit(TEST);
|
|
569
572
|
|
|
570
573
|
/**
|
|
571
574
|
*
|
|
@@ -589,13 +592,12 @@ const testSetup = () => serverInit(TEST);
|
|
|
589
592
|
* 2. get an admin token for that service
|
|
590
593
|
* 3. generate a shell script to start the server
|
|
591
594
|
*
|
|
592
|
-
* In standAlone the dependencies will not be reachable and the operation that implies reaching dependencies will most likely generate a 500 error
|
|
595
|
+
* In standAlone the dependencies will not be reachable and the operation that implies reaching dependencies will most likely generate a 500 error.
|
|
593
596
|
*
|
|
594
597
|
* When mST and other servers are present, the following actions are being performed:
|
|
595
598
|
*
|
|
596
|
-
*
|
|
597
599
|
* 1. retrieve the API from [swaggerhub](https://app.swaggerhub.com/search?type=API&owner=mimik)
|
|
598
|
-
* 2. get an
|
|
600
|
+
* 2. get an admin token for mST
|
|
599
601
|
* 3. setup the customer in mST
|
|
600
602
|
* 4. register the service in mST
|
|
601
603
|
* 5. generate a shell script to start the server
|
|
@@ -613,28 +615,28 @@ const testSetup = () => serverInit(TEST);
|
|
|
613
615
|
* | `../customerConfig.json` | The mST customer config
|
|
614
616
|
* | `./local/start.json` | The local configuration. If it does not exist start-example.json will be used to create start.json
|
|
615
617
|
*/
|
|
616
|
-
const setup = () => serverInit();
|
|
618
|
+
export const setup = () => serverInit();
|
|
617
619
|
|
|
618
620
|
const rootPath = (pathName, ignore) => {
|
|
619
|
-
const rootDir =
|
|
621
|
+
const rootDir = join(localDirname, '..', '..', '..');
|
|
620
622
|
|
|
621
623
|
if (pathName) {
|
|
622
|
-
if (ignore) return `${IGNORE}${
|
|
623
|
-
return
|
|
624
|
+
if (ignore) return `${IGNORE}${join(rootDir, pathName)}`;
|
|
625
|
+
return join(rootDir, pathName);
|
|
624
626
|
}
|
|
625
627
|
if (ignore) return `${IGNORE}${rootDir}`;
|
|
626
628
|
return rootDir;
|
|
627
629
|
};
|
|
628
630
|
|
|
629
|
-
const dotFiles = () => {
|
|
630
|
-
write(rootPath('.
|
|
631
|
-
write(rootPath('.nycrc'), parse(read(
|
|
632
|
-
write(rootPath('.gitignore'), read(
|
|
631
|
+
export const dotFiles = () => {
|
|
632
|
+
write(rootPath('eslint.config.js'), parse(read(join(localDirname, 'dotFiles', 'eslint.config.js'), INSTALL)), 'eslint.config.js', INSTALL, true);
|
|
633
|
+
write(rootPath('.nycrc'), parse(read(join(localDirname, 'dotFiles', 'nycrc.json'), 'nycrc.json', INSTALL)), INSTALL, true);
|
|
634
|
+
write(rootPath('.gitignore'), read(join(localDirname, 'dotFiles', 'gitIgnore.txt'), INSTALL), INSTALL);
|
|
633
635
|
};
|
|
634
636
|
|
|
635
|
-
const scripts = () => {
|
|
637
|
+
export const scripts = () => {
|
|
636
638
|
const packageFilename = rootPath('package.json');
|
|
637
|
-
const scriptsFile = parse(read(
|
|
639
|
+
const scriptsFile = parse(read(join(localDirname, 'scripts.json'), INSTALL), 'scripts.json', INSTALL);
|
|
638
640
|
const packageFile = parse(read(packageFilename, INSTALL), 'package.json', INSTALL);
|
|
639
641
|
|
|
640
642
|
Object.keys(scriptsFile.scripts).forEach((script) => {
|
|
@@ -644,9 +646,9 @@ const scripts = () => {
|
|
|
644
646
|
write(packageFilename, packageFile, 'package.json', INSTALL, true);
|
|
645
647
|
};
|
|
646
648
|
|
|
647
|
-
const unScripts = () => {
|
|
649
|
+
export const unScripts = () => {
|
|
648
650
|
const packageFilename = rootPath('package.json');
|
|
649
|
-
const scriptsFile = parse(read(
|
|
651
|
+
const scriptsFile = parse(read(join(localDirname, 'scripts.json'), INSTALL), 'scripts.json', INSTALL);
|
|
650
652
|
const packageFile = parse(read(packageFilename, INSTALL), 'package.json', INSTALL);
|
|
651
653
|
|
|
652
654
|
Object.keys(scriptsFile.scripts).forEach((script) => {
|
|
@@ -656,17 +658,19 @@ const unScripts = () => {
|
|
|
656
658
|
write(packageFilename, packageFile, 'package.json', INSTALL, true);
|
|
657
659
|
};
|
|
658
660
|
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
mITSetup,
|
|
664
|
-
testSetup,
|
|
665
|
-
setup,
|
|
661
|
+
export { testJsonFile };
|
|
662
|
+
|
|
663
|
+
export default {
|
|
664
|
+
commitCheckMsg,
|
|
666
665
|
dotFiles,
|
|
666
|
+
mITSetup,
|
|
667
|
+
mITTestSetup,
|
|
668
|
+
mSTSetup,
|
|
669
|
+
mSTTestSetup,
|
|
667
670
|
scripts,
|
|
668
|
-
|
|
669
|
-
commitCheckMsg,
|
|
671
|
+
setup,
|
|
670
672
|
start2process,
|
|
671
673
|
testJsonFile,
|
|
674
|
+
testSetup,
|
|
675
|
+
unScripts,
|
|
672
676
|
};
|
package/lib/common.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import process from 'process';
|
|
2
|
+
|
|
1
3
|
const packageFile = './package.json';
|
|
2
4
|
const mSTConfigFile = '../mSTConfig.json';
|
|
3
5
|
const mITConfigFile = '../mITConfig.json';
|
|
@@ -143,7 +145,7 @@ const DEFAULT_LOCATION = {
|
|
|
143
145
|
const ERR_CHECK = '✘';
|
|
144
146
|
const SUCCESS_CHECK = '✔︎';
|
|
145
147
|
|
|
146
|
-
|
|
148
|
+
export {
|
|
147
149
|
packageFile,
|
|
148
150
|
mSTConfigFile,
|
|
149
151
|
mITConfigFile,
|
package/lib/commonExt.js
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
import findIndex from 'lodash.findindex';
|
|
2
|
+
import union from 'lodash.union';
|
|
2
3
|
|
|
3
4
|
// duplicate of functions in mST lib/common.js
|
|
4
5
|
const ALL_TYPE = 'all';
|
|
5
6
|
const CLUSTER_TYPE = 'cluster';
|
|
7
|
+
const NOT_FOUND = -1;
|
|
8
|
+
const FIRST = 0;
|
|
6
9
|
|
|
7
|
-
const inList = (type, list) =>
|
|
10
|
+
const inList = (type, list) => findIndex(list, listItem => listItem.type === type);
|
|
8
11
|
|
|
9
12
|
const setServiceInfo = (sharedWith, type, scopes, customer) => {
|
|
10
13
|
const result = { type };
|
|
@@ -16,24 +19,24 @@ const setServiceInfo = (sharedWith, type, scopes, customer) => {
|
|
|
16
19
|
};
|
|
17
20
|
|
|
18
21
|
const getAllTargets = (serviceType, custConfig, serviceIndex) => {
|
|
19
|
-
const index = serviceIndex || serviceIndex ===
|
|
22
|
+
const index = serviceIndex || serviceIndex === FIRST ? serviceIndex : inList(serviceType, custConfig);
|
|
20
23
|
const targets = [];
|
|
21
24
|
const serviceInfo = (target, st) => {
|
|
22
25
|
if (target.type !== CLUSTER_TYPE) return setServiceInfo(null, target.type, target.scopes, target.customer);
|
|
23
26
|
return setServiceInfo(null, st, target.scopes);
|
|
24
27
|
};
|
|
25
28
|
|
|
26
|
-
if (index !==
|
|
27
|
-
custConfig[index].targets.forEach(
|
|
29
|
+
if (index !== NOT_FOUND) {
|
|
30
|
+
custConfig[index].targets.forEach(target => targets.push(serviceInfo(target, serviceType)));
|
|
28
31
|
const allIndex = inList(ALL_TYPE, custConfig);
|
|
29
32
|
|
|
30
|
-
if (allIndex !==
|
|
33
|
+
if (allIndex !== NOT_FOUND) {
|
|
31
34
|
custConfig[allIndex].targets.forEach((allTarget) => {
|
|
32
35
|
if (!allTarget.except || !allTarget.except.includes(serviceType)) {
|
|
33
36
|
const allTargetIndex = inList(allTarget.type === CLUSTER_TYPE ? serviceType : allTarget.type, targets);
|
|
34
37
|
|
|
35
|
-
if (allTargetIndex ===
|
|
36
|
-
else targets[allTargetIndex].scopes =
|
|
38
|
+
if (allTargetIndex === NOT_FOUND) targets.push(serviceInfo(allTarget, serviceType));
|
|
39
|
+
else targets[allTargetIndex].scopes = union(targets[allTargetIndex].scopes, allTarget.scopes);
|
|
37
40
|
}
|
|
38
41
|
});
|
|
39
42
|
}
|
|
@@ -41,6 +44,6 @@ const getAllTargets = (serviceType, custConfig, serviceIndex) => {
|
|
|
41
44
|
return targets;
|
|
42
45
|
};
|
|
43
46
|
|
|
44
|
-
|
|
47
|
+
export {
|
|
45
48
|
getAllTargets,
|
|
46
49
|
};
|