sb-mig 2.9.0 → 2.9.13
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 +72 -20
- package/lib/api/componentPresets.d.ts +1 -1
- package/lib/api/componentPresets.js +6 -9
- package/lib/api/components.js +25 -20
- package/lib/api/datasources.js +53 -46
- package/lib/api/migrate.d.ts +2 -2
- package/lib/api/migrate.js +69 -64
- package/lib/api/mutateComponents.js +10 -8
- package/lib/api/presets.js +11 -7
- package/lib/api/resolvePresets.js +7 -7
- package/lib/api/roles.d.ts +1 -1
- package/lib/api/roles.js +39 -32
- package/lib/api/spaces.js +8 -6
- package/lib/commands/backup.d.ts +1 -1
- package/lib/commands/backup.js +75 -75
- package/lib/commands/debug.js +10 -3
- package/lib/commands/sync.js +43 -43
- package/lib/config/StoryblokComponentsConfig.js +44 -44
- package/lib/config/config.js +16 -16
- package/lib/core.js +5 -5
- package/lib/index.js +1 -0
- package/lib/utils/discover.d.ts +1 -1
- package/lib/utils/discover.js +46 -44
- package/lib/utils/discover2.js +100 -91
- package/lib/utils/files.js +21 -15
- package/lib/utils/logger.js +5 -5
- package/lib/utils/others.js +2 -1
- package/oclif.manifest.json +1 -1
- package/package.json +18 -30
- package/CHANGELOG.md +0 -968
package/README.md
CHANGED
|
@@ -302,6 +302,7 @@ COMMANDS
|
|
|
302
302
|
* [`sb-mig debug`](#sb-mig-debug)
|
|
303
303
|
* [`sb-mig help [COMMAND]`](#sb-mig-help-command)
|
|
304
304
|
* [`sb-mig plugins`](#sb-mig-plugins)
|
|
305
|
+
* [`sb-mig plugins:inspect PLUGIN...`](#sb-mig-pluginsinspect-plugin)
|
|
305
306
|
* [`sb-mig plugins:install PLUGIN...`](#sb-mig-pluginsinstall-plugin)
|
|
306
307
|
* [`sb-mig plugins:link PLUGIN`](#sb-mig-pluginslink-plugin)
|
|
307
308
|
* [`sb-mig plugins:uninstall PLUGIN...`](#sb-mig-pluginsuninstall-plugin)
|
|
@@ -313,6 +314,8 @@ COMMANDS
|
|
|
313
314
|
Command for backing up anything related to Storyblok
|
|
314
315
|
|
|
315
316
|
```
|
|
317
|
+
Command for backing up anything related to Storyblok
|
|
318
|
+
|
|
316
319
|
USAGE
|
|
317
320
|
$ sb-mig backup
|
|
318
321
|
|
|
@@ -332,13 +335,15 @@ OPTIONS
|
|
|
332
335
|
-x, --oneDatasource=oneDatasource Backup one datasource by name.
|
|
333
336
|
```
|
|
334
337
|
|
|
335
|
-
_See code: [
|
|
338
|
+
_See code: [lib/commands/backup.js](https://github.com/sb-mig/sb-mig/blob/v2.9.13/lib/commands/backup.js)_
|
|
336
339
|
|
|
337
340
|
## `sb-mig debug`
|
|
338
341
|
|
|
339
342
|
Output extra debugging
|
|
340
343
|
|
|
341
344
|
```
|
|
345
|
+
Output extra debugging
|
|
346
|
+
|
|
342
347
|
USAGE
|
|
343
348
|
$ sb-mig debug
|
|
344
349
|
|
|
@@ -346,13 +351,15 @@ OPTIONS
|
|
|
346
351
|
-h, --help show CLI help
|
|
347
352
|
```
|
|
348
353
|
|
|
349
|
-
_See code: [
|
|
354
|
+
_See code: [lib/commands/debug.js](https://github.com/sb-mig/sb-mig/blob/v2.9.13/lib/commands/debug.js)_
|
|
350
355
|
|
|
351
356
|
## `sb-mig help [COMMAND]`
|
|
352
357
|
|
|
353
358
|
display help for sb-mig
|
|
354
359
|
|
|
355
360
|
```
|
|
361
|
+
display help for <%= config.bin %>
|
|
362
|
+
|
|
356
363
|
USAGE
|
|
357
364
|
$ sb-mig help [COMMAND]
|
|
358
365
|
|
|
@@ -367,35 +374,68 @@ _See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v2.2.3
|
|
|
367
374
|
|
|
368
375
|
## `sb-mig plugins`
|
|
369
376
|
|
|
370
|
-
|
|
377
|
+
List installed plugins.
|
|
371
378
|
|
|
372
379
|
```
|
|
380
|
+
List installed plugins.
|
|
381
|
+
|
|
373
382
|
USAGE
|
|
374
383
|
$ sb-mig plugins
|
|
375
384
|
|
|
376
385
|
OPTIONS
|
|
377
|
-
--core
|
|
386
|
+
--core Show core plugins.
|
|
378
387
|
|
|
379
388
|
EXAMPLE
|
|
380
389
|
$ sb-mig plugins
|
|
381
390
|
```
|
|
382
391
|
|
|
383
|
-
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/
|
|
392
|
+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v2.0.11/src/commands/plugins/index.ts)_
|
|
393
|
+
|
|
394
|
+
## `sb-mig plugins:inspect PLUGIN...`
|
|
395
|
+
|
|
396
|
+
Displays installation properties of a plugin.
|
|
397
|
+
|
|
398
|
+
```
|
|
399
|
+
Displays installation properties of a plugin.
|
|
400
|
+
|
|
401
|
+
USAGE
|
|
402
|
+
$ sb-mig plugins:inspect PLUGIN...
|
|
403
|
+
|
|
404
|
+
ARGUMENTS
|
|
405
|
+
PLUGIN [default: .] Plugin to inspect.
|
|
406
|
+
|
|
407
|
+
OPTIONS
|
|
408
|
+
-h, --help Show CLI help.
|
|
409
|
+
-v, --verbose
|
|
410
|
+
|
|
411
|
+
EXAMPLE
|
|
412
|
+
$ sb-mig plugins:inspect myplugin
|
|
413
|
+
```
|
|
414
|
+
|
|
415
|
+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v2.0.11/src/commands/plugins/inspect.ts)_
|
|
384
416
|
|
|
385
417
|
## `sb-mig plugins:install PLUGIN...`
|
|
386
418
|
|
|
387
|
-
|
|
419
|
+
Installs a plugin into the CLI.
|
|
388
420
|
|
|
389
421
|
```
|
|
422
|
+
Installs a plugin into the CLI.
|
|
423
|
+
Can be installed from npm or a git url.
|
|
424
|
+
|
|
425
|
+
Installation of a user-installed plugin will override a core plugin.
|
|
426
|
+
|
|
427
|
+
e.g. If you have a core plugin that has a 'hello' command, installing a user-installed plugin with a 'hello' command will override the core plugin implementation. This is useful if a user needs to update core plugin functionality in the CLI without the need to patch and update the whole CLI.
|
|
428
|
+
|
|
429
|
+
|
|
390
430
|
USAGE
|
|
391
431
|
$ sb-mig plugins:install PLUGIN...
|
|
392
432
|
|
|
393
433
|
ARGUMENTS
|
|
394
|
-
PLUGIN
|
|
434
|
+
PLUGIN Plugin to install.
|
|
395
435
|
|
|
396
436
|
OPTIONS
|
|
397
|
-
-f, --force yarn install with force flag
|
|
398
|
-
-h, --help
|
|
437
|
+
-f, --force Run yarn install with force flag.
|
|
438
|
+
-h, --help Show CLI help.
|
|
399
439
|
-v, --verbose
|
|
400
440
|
|
|
401
441
|
DESCRIPTION
|
|
@@ -416,13 +456,19 @@ EXAMPLES
|
|
|
416
456
|
$ sb-mig plugins:install someuser/someplugin
|
|
417
457
|
```
|
|
418
458
|
|
|
419
|
-
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/
|
|
459
|
+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v2.0.11/src/commands/plugins/install.ts)_
|
|
420
460
|
|
|
421
461
|
## `sb-mig plugins:link PLUGIN`
|
|
422
462
|
|
|
423
|
-
|
|
463
|
+
Links a plugin into the CLI for development.
|
|
424
464
|
|
|
425
465
|
```
|
|
466
|
+
Links a plugin into the CLI for development.
|
|
467
|
+
Installation of a linked plugin will override a user-installed or core plugin.
|
|
468
|
+
|
|
469
|
+
e.g. If you have a user-installed or core plugin that has a 'hello' command, installing a linked plugin with a 'hello' command will override the user-installed or core plugin implementation. This is useful for development work.
|
|
470
|
+
|
|
471
|
+
|
|
426
472
|
USAGE
|
|
427
473
|
$ sb-mig plugins:link PLUGIN
|
|
428
474
|
|
|
@@ -430,7 +476,7 @@ ARGUMENTS
|
|
|
430
476
|
PATH [default: .] path to plugin
|
|
431
477
|
|
|
432
478
|
OPTIONS
|
|
433
|
-
-h, --help
|
|
479
|
+
-h, --help Show CLI help.
|
|
434
480
|
-v, --verbose
|
|
435
481
|
|
|
436
482
|
DESCRIPTION
|
|
@@ -443,13 +489,15 @@ EXAMPLE
|
|
|
443
489
|
$ sb-mig plugins:link myplugin
|
|
444
490
|
```
|
|
445
491
|
|
|
446
|
-
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/
|
|
492
|
+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v2.0.11/src/commands/plugins/link.ts)_
|
|
447
493
|
|
|
448
494
|
## `sb-mig plugins:uninstall PLUGIN...`
|
|
449
495
|
|
|
450
|
-
|
|
496
|
+
Removes a plugin from the CLI.
|
|
451
497
|
|
|
452
498
|
```
|
|
499
|
+
Removes a plugin from the CLI.
|
|
500
|
+
|
|
453
501
|
USAGE
|
|
454
502
|
$ sb-mig plugins:uninstall PLUGIN...
|
|
455
503
|
|
|
@@ -457,7 +505,7 @@ ARGUMENTS
|
|
|
457
505
|
PLUGIN plugin to uninstall
|
|
458
506
|
|
|
459
507
|
OPTIONS
|
|
460
|
-
-h, --help
|
|
508
|
+
-h, --help Show CLI help.
|
|
461
509
|
-v, --verbose
|
|
462
510
|
|
|
463
511
|
ALIASES
|
|
@@ -465,28 +513,32 @@ ALIASES
|
|
|
465
513
|
$ sb-mig plugins:remove
|
|
466
514
|
```
|
|
467
515
|
|
|
468
|
-
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/
|
|
516
|
+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v2.0.11/src/commands/plugins/uninstall.ts)_
|
|
469
517
|
|
|
470
518
|
## `sb-mig plugins:update`
|
|
471
519
|
|
|
472
|
-
|
|
520
|
+
Update installed plugins.
|
|
473
521
|
|
|
474
522
|
```
|
|
523
|
+
Update installed plugins.
|
|
524
|
+
|
|
475
525
|
USAGE
|
|
476
526
|
$ sb-mig plugins:update
|
|
477
527
|
|
|
478
528
|
OPTIONS
|
|
479
|
-
-h, --help
|
|
529
|
+
-h, --help Show CLI help.
|
|
480
530
|
-v, --verbose
|
|
481
531
|
```
|
|
482
532
|
|
|
483
|
-
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/
|
|
533
|
+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v2.0.11/src/commands/plugins/update.ts)_
|
|
484
534
|
|
|
485
535
|
## `sb-mig sync TYPE [LIST]`
|
|
486
536
|
|
|
487
537
|
Synchronize components, datasources or roles with Storyblok space.
|
|
488
538
|
|
|
489
539
|
```
|
|
540
|
+
Synchronize components, datasources or roles with Storyblok space.
|
|
541
|
+
|
|
490
542
|
USAGE
|
|
491
543
|
$ sb-mig sync TYPE [LIST]
|
|
492
544
|
|
|
@@ -511,7 +563,7 @@ EXAMPLES
|
|
|
511
563
|
$ sb-mig sync roles
|
|
512
564
|
```
|
|
513
565
|
|
|
514
|
-
_See code: [
|
|
566
|
+
_See code: [lib/commands/sync.js](https://github.com/sb-mig/sb-mig/blob/v2.9.13/lib/commands/sync.js)_
|
|
515
567
|
<!-- commandsstop -->
|
|
516
568
|
|
|
517
569
|
# Plugins
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const getComponentPresets: (componentName: string) => Promise<false | [
|
|
1
|
+
export declare const getComponentPresets: (componentName: string) => Promise<false | any[]>;
|
|
@@ -4,22 +4,19 @@ exports.getComponentPresets = void 0;
|
|
|
4
4
|
const logger_1 = require("../utils/logger");
|
|
5
5
|
const components_1 = require("./components");
|
|
6
6
|
const presets_1 = require("./presets");
|
|
7
|
-
|
|
7
|
+
const getComponentPresets = (componentName) => {
|
|
8
8
|
logger_1.default.log(`Trying to get all '${componentName}' presets.`);
|
|
9
|
-
return components_1.getAllComponents().then(async (res) => {
|
|
9
|
+
return (0, components_1.getAllComponents)().then(async (res) => {
|
|
10
10
|
const componentPresets = res.components.filter((component) => component.name === componentName);
|
|
11
11
|
if (componentPresets.length > 0) {
|
|
12
12
|
if (componentPresets[0].all_presets.length === 0) {
|
|
13
13
|
logger_1.default.warning(`There is no presets for: '${componentName}' component`);
|
|
14
14
|
return false;
|
|
15
15
|
}
|
|
16
|
-
|
|
17
|
-
return Promise.all(componentPresets[0].all_presets.map((preset) => presets_1.getPreset(preset.id).catch((err) => logger_1.default.error(err))));
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
else {
|
|
21
|
-
logger_1.default.warning(`There is no '${componentName}' component`);
|
|
22
|
-
return false;
|
|
16
|
+
return Promise.all(componentPresets[0].all_presets.map((preset) => (0, presets_1.getPreset)(preset.id).catch((err) => logger_1.default.error(err))));
|
|
23
17
|
}
|
|
18
|
+
logger_1.default.warning(`There is no '${componentName}' component`);
|
|
19
|
+
return false;
|
|
24
20
|
});
|
|
25
21
|
};
|
|
22
|
+
exports.getComponentPresets = getComponentPresets;
|
package/lib/api/components.js
CHANGED
|
@@ -6,49 +6,53 @@ const config_1 = require("../config/config");
|
|
|
6
6
|
const apiConfig_1 = require("./apiConfig");
|
|
7
7
|
const { spaceId } = config_1.default;
|
|
8
8
|
// GET
|
|
9
|
-
|
|
10
|
-
logger_1.default.log(
|
|
9
|
+
const getAllComponents = () => {
|
|
10
|
+
logger_1.default.log('Trying to get all components.');
|
|
11
11
|
return apiConfig_1.sbApi
|
|
12
12
|
.get(`spaces/${spaceId}/components/`)
|
|
13
13
|
.then((res) => res.data)
|
|
14
14
|
.catch((err) => logger_1.default.error(err));
|
|
15
15
|
};
|
|
16
|
-
exports.
|
|
16
|
+
exports.getAllComponents = getAllComponents;
|
|
17
|
+
const getComponent = (componentName) => {
|
|
17
18
|
logger_1.default.log(`Trying to get '${componentName}' component.`);
|
|
18
|
-
return exports.getAllComponents()
|
|
19
|
-
.then(
|
|
20
|
-
.then(
|
|
19
|
+
return (0, exports.getAllComponents)()
|
|
20
|
+
.then(res => res.components.filter((component) => component.name === componentName))
|
|
21
|
+
.then(res => {
|
|
21
22
|
if (Array.isArray(res) && res.length === 0) {
|
|
22
23
|
logger_1.default.warning(`There is no component named '${componentName}'`);
|
|
23
24
|
return false;
|
|
24
25
|
}
|
|
25
26
|
return res;
|
|
26
27
|
})
|
|
27
|
-
.catch(
|
|
28
|
+
.catch(err => logger_1.default.error(err));
|
|
28
29
|
};
|
|
29
|
-
exports.
|
|
30
|
+
exports.getComponent = getComponent;
|
|
31
|
+
const getComponentsGroup = (groupName) => {
|
|
30
32
|
logger_1.default.log(`Trying to get '${groupName}' group.`);
|
|
31
|
-
return exports.getAllComponentsGroups()
|
|
32
|
-
.then(
|
|
33
|
+
return (0, exports.getAllComponentsGroups)()
|
|
34
|
+
.then(res => {
|
|
33
35
|
return res.component_groups.filter((group) => group.name === groupName);
|
|
34
36
|
})
|
|
35
|
-
.then(
|
|
37
|
+
.then(res => {
|
|
36
38
|
if (Array.isArray(res) && res.length === 0) {
|
|
37
39
|
logger_1.default.warning(`There is no group named '${groupName}'`);
|
|
38
40
|
return false;
|
|
39
41
|
}
|
|
40
42
|
return res;
|
|
41
43
|
})
|
|
42
|
-
.catch(
|
|
44
|
+
.catch(err => logger_1.default.error(err));
|
|
43
45
|
};
|
|
44
|
-
exports.
|
|
45
|
-
|
|
46
|
+
exports.getComponentsGroup = getComponentsGroup;
|
|
47
|
+
const getAllComponentsGroups = async () => {
|
|
48
|
+
logger_1.default.log('Trying to get all groups.');
|
|
46
49
|
return apiConfig_1.sbApi
|
|
47
50
|
.get(`spaces/${spaceId}/component_groups/`)
|
|
48
|
-
.then(
|
|
49
|
-
.catch(
|
|
51
|
+
.then(response => response.data)
|
|
52
|
+
.catch(err => logger_1.default.error(err));
|
|
50
53
|
};
|
|
51
|
-
exports.
|
|
54
|
+
exports.getAllComponentsGroups = getAllComponentsGroups;
|
|
55
|
+
const createComponentsGroup = (groupName) => {
|
|
52
56
|
logger_1.default.log(`Trying to create '${groupName}' group`);
|
|
53
57
|
return apiConfig_1.sbApi
|
|
54
58
|
.post(`spaces/${spaceId}/component_groups/`, {
|
|
@@ -56,11 +60,12 @@ exports.createComponentsGroup = (groupName) => {
|
|
|
56
60
|
name: groupName,
|
|
57
61
|
},
|
|
58
62
|
})
|
|
59
|
-
.then(
|
|
63
|
+
.then(res => {
|
|
60
64
|
logger_1.default.warning(`'${groupName}' created with uuid: ${res.data.component_group.uuid}`);
|
|
61
65
|
return res.data;
|
|
62
66
|
})
|
|
63
|
-
.catch(
|
|
64
|
-
logger_1.default.error(
|
|
67
|
+
.catch(err => {
|
|
68
|
+
logger_1.default.error('Error happened :()');
|
|
65
69
|
});
|
|
66
70
|
};
|
|
71
|
+
exports.createComponentsGroup = createComponentsGroup;
|
package/lib/api/datasources.js
CHANGED
|
@@ -7,12 +7,12 @@ const apiConfig_1 = require("./apiConfig");
|
|
|
7
7
|
const discover2_1 = require("../utils/discover2");
|
|
8
8
|
const { spaceId } = config_1.default;
|
|
9
9
|
// GET
|
|
10
|
-
|
|
11
|
-
logger_1.default.log(
|
|
10
|
+
const getAllDatasources = () => {
|
|
11
|
+
logger_1.default.log('Trying to get all Datasources.');
|
|
12
12
|
return apiConfig_1.sbApi
|
|
13
13
|
.get(`spaces/${spaceId}/datasources/`)
|
|
14
14
|
.then(({ data }) => data)
|
|
15
|
-
.catch(
|
|
15
|
+
.catch(err => {
|
|
16
16
|
if (err.response.status === 404) {
|
|
17
17
|
logger_1.default.error(`There is no datasources in your Storyblok ${spaceId} space.`);
|
|
18
18
|
}
|
|
@@ -22,34 +22,37 @@ exports.getAllDatasources = () => {
|
|
|
22
22
|
}
|
|
23
23
|
});
|
|
24
24
|
};
|
|
25
|
-
exports.
|
|
25
|
+
exports.getAllDatasources = getAllDatasources;
|
|
26
|
+
const getDatasource = (datasourceName) => {
|
|
26
27
|
logger_1.default.log(`Trying to get '${datasourceName}' datasource.`);
|
|
27
|
-
return exports.getAllDatasources()
|
|
28
|
-
.then(
|
|
28
|
+
return (0, exports.getAllDatasources)()
|
|
29
|
+
.then(res => {
|
|
29
30
|
if (res) {
|
|
30
31
|
return res.datasources.filter((datasource) => datasource.name === datasourceName);
|
|
31
32
|
}
|
|
32
33
|
})
|
|
33
|
-
.then(
|
|
34
|
+
.then(res => {
|
|
34
35
|
if (Array.isArray(res) && res.length === 0) {
|
|
35
36
|
logger_1.default.warning(`There is no datasource named '${datasourceName}'`);
|
|
36
37
|
return false;
|
|
37
38
|
}
|
|
38
39
|
return res;
|
|
39
40
|
})
|
|
40
|
-
.catch(
|
|
41
|
+
.catch(err => logger_1.default.error(err));
|
|
41
42
|
};
|
|
42
|
-
exports.
|
|
43
|
+
exports.getDatasource = getDatasource;
|
|
44
|
+
const getDatasourceEntries = async (datasourceName) => {
|
|
43
45
|
logger_1.default.log(`Trying to get '${datasourceName}' datasource entries.`);
|
|
44
|
-
const data = await exports.getDatasource(datasourceName);
|
|
46
|
+
const data = await (0, exports.getDatasource)(datasourceName);
|
|
45
47
|
if (data) {
|
|
46
48
|
return apiConfig_1.sbApi
|
|
47
49
|
.get(`spaces/${spaceId}/datasource_entries/?datasource_id=${data[0].id}`)
|
|
48
50
|
.then(async ({ data }) => data)
|
|
49
|
-
.catch(
|
|
51
|
+
.catch(err => logger_1.default.error(err));
|
|
50
52
|
}
|
|
51
53
|
};
|
|
52
|
-
exports.
|
|
54
|
+
exports.getDatasourceEntries = getDatasourceEntries;
|
|
55
|
+
const createDatasource = (datasource) => apiConfig_1.sbApi
|
|
53
56
|
.post(`spaces/${spaceId}/datasources/`, {
|
|
54
57
|
datasource: {
|
|
55
58
|
name: datasource.name,
|
|
@@ -60,8 +63,9 @@ exports.createDatasource = (datasource) => apiConfig_1.sbApi
|
|
|
60
63
|
data,
|
|
61
64
|
datasource_entries: datasource.datasource_entries,
|
|
62
65
|
}))
|
|
63
|
-
.catch(
|
|
64
|
-
exports.
|
|
66
|
+
.catch(err => logger_1.default.error(err));
|
|
67
|
+
exports.createDatasource = createDatasource;
|
|
68
|
+
const createDatasourceEntry = (datasourceEntry, datasourceId) => {
|
|
65
69
|
return apiConfig_1.sbApi
|
|
66
70
|
.post(`spaces/${spaceId}/datasource_entries/`, {
|
|
67
71
|
datasource_entry: {
|
|
@@ -73,9 +77,10 @@ exports.createDatasourceEntry = (datasourceEntry, datasourceId) => {
|
|
|
73
77
|
.then(({ data }) => {
|
|
74
78
|
return data;
|
|
75
79
|
})
|
|
76
|
-
.catch(
|
|
80
|
+
.catch(err => logger_1.default.error(err));
|
|
77
81
|
};
|
|
78
|
-
exports.
|
|
82
|
+
exports.createDatasourceEntry = createDatasourceEntry;
|
|
83
|
+
const updateDatasourceEntry = (datasourceEntry, datasourceId, datasourceToBeUpdated) => {
|
|
79
84
|
return apiConfig_1.sbApi
|
|
80
85
|
.put(`spaces/${spaceId}/datasource_entries/${datasourceToBeUpdated.id}`, {
|
|
81
86
|
datasource_entry: {
|
|
@@ -88,9 +93,10 @@ exports.updateDatasourceEntry = (datasourceEntry, datasourceId, datasourceToBeUp
|
|
|
88
93
|
.then(({ data }) => {
|
|
89
94
|
return data;
|
|
90
95
|
})
|
|
91
|
-
.catch(
|
|
96
|
+
.catch(err => logger_1.default.error(err));
|
|
92
97
|
};
|
|
93
|
-
exports.
|
|
98
|
+
exports.updateDatasourceEntry = updateDatasourceEntry;
|
|
99
|
+
const updateDatasource = (datasource, temp) => apiConfig_1.sbApi
|
|
94
100
|
.put(`spaces/${spaceId}/datasources/${temp.id}`, {
|
|
95
101
|
datasource: {
|
|
96
102
|
id: temp.id,
|
|
@@ -104,83 +110,84 @@ exports.updateDatasource = (datasource, temp) => apiConfig_1.sbApi
|
|
|
104
110
|
datasource_entries: datasource.datasource_entries,
|
|
105
111
|
};
|
|
106
112
|
})
|
|
107
|
-
.catch(
|
|
108
|
-
exports.
|
|
113
|
+
.catch(err => logger_1.default.error(err));
|
|
114
|
+
exports.updateDatasource = updateDatasource;
|
|
115
|
+
const createDatasourceEntries = (datasourceId, datasource_entries, remoteDatasourceEntries) => {
|
|
109
116
|
Promise.all(datasource_entries.map((datasourceEntry) => {
|
|
110
117
|
const datasourceEntriesToBeUpdated = remoteDatasourceEntries.datasource_entries.find((remoteDatasourceEntry) => remoteDatasourceEntry.name ===
|
|
111
118
|
Object.values(datasourceEntry)[0]);
|
|
112
119
|
if (datasourceEntriesToBeUpdated) {
|
|
113
|
-
return exports.updateDatasourceEntry(datasourceEntry, datasourceId, datasourceEntriesToBeUpdated);
|
|
114
|
-
}
|
|
115
|
-
else {
|
|
116
|
-
return exports.createDatasourceEntry(datasourceEntry, datasourceId);
|
|
120
|
+
return (0, exports.updateDatasourceEntry)(datasourceEntry, datasourceId, datasourceEntriesToBeUpdated);
|
|
117
121
|
}
|
|
122
|
+
return (0, exports.createDatasourceEntry)(datasourceEntry, datasourceId);
|
|
118
123
|
}))
|
|
119
124
|
.then(({ data }) => {
|
|
120
125
|
logger_1.default.success(`Datasource entries for ${datasourceId} datasource id has been successfully synced.`);
|
|
121
126
|
return data;
|
|
122
127
|
})
|
|
123
|
-
.catch(
|
|
128
|
+
.catch(err => logger_1.default.error(err));
|
|
124
129
|
};
|
|
125
|
-
exports.
|
|
130
|
+
exports.createDatasourceEntries = createDatasourceEntries;
|
|
131
|
+
const syncDatasources = async ({ providedDatasources, }) => {
|
|
126
132
|
logger_1.default.log(`Trying to sync provided datasources: ${providedDatasources}`);
|
|
127
|
-
const providedDatasourcesContent = discover2_1.getFilesContent({
|
|
133
|
+
const providedDatasourcesContent = (0, discover2_1.getFilesContent)({
|
|
128
134
|
files: providedDatasources,
|
|
129
135
|
});
|
|
130
|
-
const remoteDatasources = await exports.getAllDatasources();
|
|
131
|
-
Promise.all(providedDatasourcesContent.map(
|
|
136
|
+
const remoteDatasources = await (0, exports.getAllDatasources)();
|
|
137
|
+
Promise.all(providedDatasourcesContent.map(datasource => {
|
|
132
138
|
const datasourceToBeUpdated = remoteDatasources.datasources.find((remoteDatasource) => datasource.name === remoteDatasource.name);
|
|
133
139
|
if (datasourceToBeUpdated) {
|
|
134
|
-
return exports.updateDatasource(datasource, datasourceToBeUpdated);
|
|
135
|
-
}
|
|
136
|
-
else {
|
|
137
|
-
return exports.createDatasource(datasource);
|
|
140
|
+
return (0, exports.updateDatasource)(datasource, datasourceToBeUpdated);
|
|
138
141
|
}
|
|
142
|
+
return (0, exports.createDatasource)(datasource);
|
|
139
143
|
}))
|
|
140
|
-
.then(
|
|
144
|
+
.then(res => {
|
|
141
145
|
res.map(async ({ data, datasource_entries }) => {
|
|
142
|
-
const remoteDatasourceEntries = await exports.getDatasourceEntries(data.datasource.name);
|
|
143
|
-
exports.createDatasourceEntries(data.datasource.id, datasource_entries, remoteDatasourceEntries);
|
|
146
|
+
const remoteDatasourceEntries = await (0, exports.getDatasourceEntries)(data.datasource.name);
|
|
147
|
+
(0, exports.createDatasourceEntries)(data.datasource.id, datasource_entries, remoteDatasourceEntries);
|
|
144
148
|
});
|
|
145
149
|
return res;
|
|
146
150
|
})
|
|
147
|
-
.catch(
|
|
151
|
+
.catch(err => {
|
|
148
152
|
console.log(err);
|
|
149
|
-
logger_1.default.warning(
|
|
153
|
+
logger_1.default.warning('There is error inside promise.all from datasource');
|
|
150
154
|
return false;
|
|
151
155
|
});
|
|
152
156
|
};
|
|
153
|
-
exports.
|
|
154
|
-
|
|
157
|
+
exports.syncDatasources = syncDatasources;
|
|
158
|
+
const syncProvidedDatasources = ({ datasources, }) => {
|
|
159
|
+
const allLocalDatasources = (0, discover2_1.discoverManyDatasources)({
|
|
155
160
|
scope: discover2_1.SCOPE.local,
|
|
156
161
|
type: discover2_1.LOOKUP_TYPE.fileName,
|
|
157
162
|
fileNames: datasources,
|
|
158
163
|
});
|
|
159
|
-
const allExternalDatasources = discover2_1.discoverManyDatasources({
|
|
164
|
+
const allExternalDatasources = (0, discover2_1.discoverManyDatasources)({
|
|
160
165
|
scope: discover2_1.SCOPE.external,
|
|
161
166
|
type: discover2_1.LOOKUP_TYPE.fileName,
|
|
162
167
|
fileNames: datasources,
|
|
163
168
|
});
|
|
164
|
-
exports.syncDatasources({
|
|
169
|
+
(0, exports.syncDatasources)({
|
|
165
170
|
providedDatasources: [
|
|
166
171
|
...allLocalDatasources,
|
|
167
172
|
...allExternalDatasources,
|
|
168
173
|
],
|
|
169
174
|
});
|
|
170
175
|
};
|
|
171
|
-
exports.
|
|
172
|
-
|
|
176
|
+
exports.syncProvidedDatasources = syncProvidedDatasources;
|
|
177
|
+
const syncAllDatasources = () => {
|
|
178
|
+
const allLocalDatasources = (0, discover2_1.discoverDatasources)({
|
|
173
179
|
scope: discover2_1.SCOPE.local,
|
|
174
180
|
type: discover2_1.LOOKUP_TYPE.fileName,
|
|
175
181
|
});
|
|
176
|
-
const allExternalDatasources = discover2_1.discoverDatasources({
|
|
182
|
+
const allExternalDatasources = (0, discover2_1.discoverDatasources)({
|
|
177
183
|
scope: discover2_1.SCOPE.external,
|
|
178
184
|
type: discover2_1.LOOKUP_TYPE.fileName,
|
|
179
185
|
});
|
|
180
|
-
exports.syncDatasources({
|
|
186
|
+
(0, exports.syncDatasources)({
|
|
181
187
|
providedDatasources: [
|
|
182
188
|
...allLocalDatasources,
|
|
183
189
|
...allExternalDatasources,
|
|
184
190
|
],
|
|
185
191
|
});
|
|
186
192
|
};
|
|
193
|
+
exports.syncAllDatasources = syncAllDatasources;
|
package/lib/api/migrate.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ interface SyncComponents {
|
|
|
4
4
|
presets: boolean;
|
|
5
5
|
}
|
|
6
6
|
export declare const sync2Components: ({ specifiedComponents, presets }: SyncComponents) => Promise<void>;
|
|
7
|
-
export declare const syncComponents: (specifiedComponents: string[], ext: string |
|
|
7
|
+
export declare const syncComponents: (specifiedComponents: string[], ext: string | boolean, presets: boolean, packageName: boolean, local?: boolean | undefined) => Promise<void>;
|
|
8
8
|
interface SyncAllComponents {
|
|
9
9
|
presets: boolean;
|
|
10
10
|
}
|
|
@@ -15,5 +15,5 @@ interface SyncProvidedComponents {
|
|
|
15
15
|
}
|
|
16
16
|
export declare const syncProvidedComponents: ({ components, presets, packageName }: SyncProvidedComponents) => void;
|
|
17
17
|
export declare const sync2AllComponents: ({ presets }: SyncAllComponents) => void;
|
|
18
|
-
export declare const syncAllComponents: (ext: string |
|
|
18
|
+
export declare const syncAllComponents: (ext: string | boolean, presets: boolean) => void;
|
|
19
19
|
export {};
|