sb-mig 2.9.13 → 3.1.3
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 +5 -5
- package/dist/index.js +52 -0
- package/package.json +42 -62
- package/bin/run +0 -5
- package/bin/run.cmd +0 -3
- package/lib/api/apiConfig.d.ts +0 -2
- package/lib/api/apiConfig.js +0 -9
- package/lib/api/componentPresets.d.ts +0 -1
- package/lib/api/componentPresets.js +0 -22
- package/lib/api/components.d.ts +0 -5
- package/lib/api/components.js +0 -71
- package/lib/api/datasources.d.ts +0 -24
- package/lib/api/datasources.js +0 -193
- package/lib/api/migrate.d.ts +0 -19
- package/lib/api/migrate.js +0 -220
- package/lib/api/mutateComponents.d.ts +0 -2
- package/lib/api/mutateComponents.js +0 -50
- package/lib/api/presets.d.ts +0 -4
- package/lib/api/presets.js +0 -59
- package/lib/api/resolvePresets.d.ts +0 -2
- package/lib/api/resolvePresets.js +0 -40
- package/lib/api/roles.d.ts +0 -14
- package/lib/api/roles.js +0 -133
- package/lib/api/spaces.d.ts +0 -2
- package/lib/api/spaces.js +0 -29
- package/lib/commands/backup.d.ts +0 -22
- package/lib/commands/backup.js +0 -217
- package/lib/commands/debug.d.ts +0 -9
- package/lib/commands/debug.js +0 -27
- package/lib/commands/sync.d.ts +0 -26
- package/lib/commands/sync.js +0 -93
- package/lib/config/StoryblokComponentsConfig.d.ts +0 -68
- package/lib/config/StoryblokComponentsConfig.js +0 -220
- package/lib/config/config.d.ts +0 -37
- package/lib/config/config.js +0 -36
- package/lib/core.d.ts +0 -16
- package/lib/core.js +0 -75
- package/lib/index.d.ts +0 -1
- package/lib/index.js +0 -5
- package/lib/types/storyblokTypes.d.ts +0 -171
- package/lib/types/storyblokTypes.js +0 -3
- package/lib/utils/discover.d.ts +0 -4
- package/lib/utils/discover.js +0 -96
- package/lib/utils/discover2.d.ts +0 -63
- package/lib/utils/discover2.js +0 -424
- package/lib/utils/files.d.ts +0 -6
- package/lib/utils/files.js +0 -54
- package/lib/utils/logger.d.ts +0 -11
- package/lib/utils/logger.js +0 -30
- package/lib/utils/others.d.ts +0 -1
- package/lib/utils/others.js +0 -5
- package/oclif.manifest.json +0 -1
package/README.md
CHANGED
|
@@ -335,14 +335,14 @@ OPTIONS
|
|
|
335
335
|
-x, --oneDatasource=oneDatasource Backup one datasource by name.
|
|
336
336
|
```
|
|
337
337
|
|
|
338
|
-
_See code: [lib/commands/backup.js](https://github.com/sb-mig/sb-mig/blob/v2.9.
|
|
338
|
+
_See code: [lib/commands/backup.js](https://github.com/sb-mig/sb-mig/blob/v2.9.11/lib/commands/backup.js)_
|
|
339
339
|
|
|
340
340
|
## `sb-mig debug`
|
|
341
341
|
|
|
342
|
-
Output extra debugging
|
|
342
|
+
Output extra debugging.
|
|
343
343
|
|
|
344
344
|
```
|
|
345
|
-
Output extra debugging
|
|
345
|
+
Output extra debugging.
|
|
346
346
|
|
|
347
347
|
USAGE
|
|
348
348
|
$ sb-mig debug
|
|
@@ -351,7 +351,7 @@ OPTIONS
|
|
|
351
351
|
-h, --help show CLI help
|
|
352
352
|
```
|
|
353
353
|
|
|
354
|
-
_See code: [lib/commands/debug.js](https://github.com/sb-mig/sb-mig/blob/v2.9.
|
|
354
|
+
_See code: [lib/commands/debug.js](https://github.com/sb-mig/sb-mig/blob/v2.9.11/lib/commands/debug.js)_
|
|
355
355
|
|
|
356
356
|
## `sb-mig help [COMMAND]`
|
|
357
357
|
|
|
@@ -563,7 +563,7 @@ EXAMPLES
|
|
|
563
563
|
$ sb-mig sync roles
|
|
564
564
|
```
|
|
565
565
|
|
|
566
|
-
_See code: [lib/commands/sync.js](https://github.com/sb-mig/sb-mig/blob/v2.9.
|
|
566
|
+
_See code: [lib/commands/sync.js](https://github.com/sb-mig/sb-mig/blob/v2.9.11/lib/commands/sync.js)_
|
|
567
567
|
<!-- commandsstop -->
|
|
568
568
|
|
|
569
569
|
# Plugins
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
#! /usr/bin/env node
|
|
2
|
+
import meow from "meow";
|
|
3
|
+
import { debug } from "./commands/debug.js";
|
|
4
|
+
import { pipe, prop } from "./utils/main.js";
|
|
5
|
+
import { sync } from "./commands/sync.js";
|
|
6
|
+
import { backup } from "./commands/backup.js";
|
|
7
|
+
import { backupDescription, debugDescription, mainDescription, syncDescription, } from "./cli-descriptions.js";
|
|
8
|
+
const app = () => ({
|
|
9
|
+
cli: meow(mainDescription, {
|
|
10
|
+
importMeta: import.meta,
|
|
11
|
+
booleanDefault: undefined,
|
|
12
|
+
}),
|
|
13
|
+
action: (cli) => cli.showHelp(),
|
|
14
|
+
});
|
|
15
|
+
app.sync = () => ({
|
|
16
|
+
cli: meow(syncDescription, {
|
|
17
|
+
importMeta: import.meta,
|
|
18
|
+
booleanDefault: undefined,
|
|
19
|
+
}),
|
|
20
|
+
action: (cli) => {
|
|
21
|
+
sync(cli);
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
app.backup = () => ({
|
|
25
|
+
cli: meow(backupDescription, {
|
|
26
|
+
importMeta: import.meta,
|
|
27
|
+
booleanDefault: undefined,
|
|
28
|
+
}),
|
|
29
|
+
action: (cli) => {
|
|
30
|
+
backup(cli);
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
app.debug = () => ({
|
|
34
|
+
cli: meow(debugDescription, {
|
|
35
|
+
importMeta: import.meta,
|
|
36
|
+
booleanDefault: undefined,
|
|
37
|
+
}),
|
|
38
|
+
action: (cli) => {
|
|
39
|
+
debug(cli);
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
const getSubcommand = (cliObject, level) => pipe(prop("input"), prop(level), (name) => prop(name)(cliObject))(prop("cli")(cliObject()));
|
|
43
|
+
const cli = (cliObject, level = 0) => {
|
|
44
|
+
const { cli: nextCli, action } = cliObject();
|
|
45
|
+
const subCommand = getSubcommand(cliObject, level);
|
|
46
|
+
return subCommand
|
|
47
|
+
? cli(subCommand, level + 1)
|
|
48
|
+
: nextCli.flags.help
|
|
49
|
+
? nextCli.showHelp()
|
|
50
|
+
: action(nextCli);
|
|
51
|
+
};
|
|
52
|
+
cli(app);
|
package/package.json
CHANGED
|
@@ -1,41 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sb-mig",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.1.3",
|
|
4
4
|
"description": "CLI to rule the world. (and handle stuff related to Storyblok CMS)",
|
|
5
5
|
"author": "Marcin Krawczyk <marckraw@icloud.com>",
|
|
6
|
-
"
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
"@oclif/command": "^1.8.0",
|
|
12
|
-
"@oclif/plugin-help": "^2",
|
|
13
|
-
"@oclif/plugin-plugins": "^2.0.11",
|
|
14
|
-
"@oclif/plugin-warn-if-update-available": "^2.0.2",
|
|
15
|
-
"@oclif/test": "^2.0.3",
|
|
16
|
-
"axios": "^0.24.0",
|
|
17
|
-
"camelcase": "^6.2.0",
|
|
18
|
-
"dotenv": "^8.2.0",
|
|
19
|
-
"glob": "^7.1.6",
|
|
20
|
-
"ncp": "^2.0.0",
|
|
21
|
-
"rimraf": "^3.0.2",
|
|
22
|
-
"storyblok-js-client": "^4.1.5"
|
|
23
|
-
},
|
|
24
|
-
"devDependencies": {
|
|
25
|
-
"@oclif/dev-cli": "^1.26.9",
|
|
26
|
-
"@oclif/test": "^1",
|
|
27
|
-
"conventional-changelog-cli": "^2.0.31",
|
|
28
|
-
"eslint-config-oclif": "^3.1"
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"bin": "./dist/index.js",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/sb-mig/sb-mig.git"
|
|
29
11
|
},
|
|
30
|
-
"
|
|
31
|
-
"
|
|
12
|
+
"publishConfig": {
|
|
13
|
+
"registry": "https://registry.npmjs.org/",
|
|
14
|
+
"access": "public"
|
|
32
15
|
},
|
|
33
|
-
"
|
|
34
|
-
"/bin",
|
|
35
|
-
"/lib",
|
|
36
|
-
"/npm-shrinkwrap.json",
|
|
37
|
-
"/oclif.manifest.json"
|
|
38
|
-
],
|
|
16
|
+
"bugs": "https://github.com/sb-mig/sb-mig/issues",
|
|
39
17
|
"homepage": "https://sb-mig.com",
|
|
40
18
|
"keywords": [
|
|
41
19
|
"cli",
|
|
@@ -43,38 +21,40 @@
|
|
|
43
21
|
"sb",
|
|
44
22
|
"migrate"
|
|
45
23
|
],
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
|
|
49
|
-
"
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
"
|
|
53
|
-
"@oclif/plugin-help",
|
|
54
|
-
"@oclif/plugin-plugins",
|
|
55
|
-
"@oclif/plugin-warn-if-update-available"
|
|
56
|
-
],
|
|
57
|
-
"warn-if-update-available": {
|
|
58
|
-
"timeoutInDays": 3,
|
|
59
|
-
"message": "<%= config.name %> update available from <%= chalk.greenBright(config.version) %> to <%= chalk.greenBright(latest) %>."
|
|
60
|
-
}
|
|
61
|
-
},
|
|
62
|
-
"repository": {
|
|
63
|
-
"type": "git",
|
|
64
|
-
"url": "git+https://github.com/sb-mig/sb-mig.git"
|
|
65
|
-
},
|
|
66
|
-
"publishConfig": {
|
|
67
|
-
"registry": "https://registry.npmjs.org/",
|
|
68
|
-
"access": "public"
|
|
24
|
+
"type": "module",
|
|
25
|
+
"exports": [
|
|
26
|
+
"./dist/index.js",
|
|
27
|
+
"./dist/**/*"
|
|
28
|
+
],
|
|
29
|
+
"engines": {
|
|
30
|
+
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
|
|
69
31
|
},
|
|
32
|
+
"files": [
|
|
33
|
+
"./dist"
|
|
34
|
+
],
|
|
70
35
|
"scripts": {
|
|
71
|
-
"
|
|
72
|
-
"
|
|
73
|
-
"
|
|
74
|
-
"
|
|
75
|
-
"test": "nyc --extension .ts mocha --forbid-only \"test/**/*.test.ts\"",
|
|
36
|
+
"build": "rm -rf dist && tsc",
|
|
37
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
38
|
+
"start": "yarn build && ./dist/index.js",
|
|
39
|
+
"debug": "yarn build && ./dist/index.js sync components accordion accordion-item",
|
|
76
40
|
"version": "conventional-changelog -p eslint -i CHANGELOG.md -s"
|
|
77
41
|
},
|
|
78
|
-
"
|
|
79
|
-
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"axios": "^0.25.0",
|
|
44
|
+
"chalk": "^5.0.0",
|
|
45
|
+
"dotenv": "^14.3.0",
|
|
46
|
+
"glob": "^7.2.0",
|
|
47
|
+
"meow": "^10.1.2",
|
|
48
|
+
"ncp": "^2.0.0",
|
|
49
|
+
"storyblok-js-client": "^4.2.0"
|
|
50
|
+
},
|
|
51
|
+
"devDependencies": {
|
|
52
|
+
"@sindresorhus/tsconfig": "^2.0.0",
|
|
53
|
+
"@types/glob": "^7.2.0",
|
|
54
|
+
"@types/ncp": "^2.0.5",
|
|
55
|
+
"@types/node": "^17.0.12",
|
|
56
|
+
"conventional-changelog-cli": "^2.0.31",
|
|
57
|
+
"typescript": "^4.5.5"
|
|
58
|
+
},
|
|
59
|
+
"gitHead": "e71c4d85954be101d27c4ece148e0bc986198266"
|
|
80
60
|
}
|
package/bin/run
DELETED
package/bin/run.cmd
DELETED
package/lib/api/apiConfig.d.ts
DELETED
package/lib/api/apiConfig.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.sbApi = void 0;
|
|
4
|
-
const StoryblokClient = require('storyblok-js-client');
|
|
5
|
-
const config_1 = require("../config/config");
|
|
6
|
-
const { accessToken, oauthToken, storyblokApiUrl } = config_1.default;
|
|
7
|
-
exports.sbApi = new StoryblokClient({ accessToken, oauthToken }, storyblokApiUrl);
|
|
8
|
-
// export const sbApi = new StoryblokClient({ accessToken, oauthToken }, storyblokApiUrl) as Storyblok // after https://github.com/storyblok/storyblok-js-client/issues/50 will be solved
|
|
9
|
-
// export const sbApi = new StoryblokClient({ accessToken, oauthToken }, storyblokApiUrl)
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const getComponentPresets: (componentName: string) => Promise<false | any[]>;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getComponentPresets = void 0;
|
|
4
|
-
const logger_1 = require("../utils/logger");
|
|
5
|
-
const components_1 = require("./components");
|
|
6
|
-
const presets_1 = require("./presets");
|
|
7
|
-
const getComponentPresets = (componentName) => {
|
|
8
|
-
logger_1.default.log(`Trying to get all '${componentName}' presets.`);
|
|
9
|
-
return (0, components_1.getAllComponents)().then(async (res) => {
|
|
10
|
-
const componentPresets = res.components.filter((component) => component.name === componentName);
|
|
11
|
-
if (componentPresets.length > 0) {
|
|
12
|
-
if (componentPresets[0].all_presets.length === 0) {
|
|
13
|
-
logger_1.default.warning(`There is no presets for: '${componentName}' component`);
|
|
14
|
-
return false;
|
|
15
|
-
}
|
|
16
|
-
return Promise.all(componentPresets[0].all_presets.map((preset) => (0, presets_1.getPreset)(preset.id).catch((err) => logger_1.default.error(err))));
|
|
17
|
-
}
|
|
18
|
-
logger_1.default.warning(`There is no '${componentName}' component`);
|
|
19
|
-
return false;
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
exports.getComponentPresets = getComponentPresets;
|
package/lib/api/components.d.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
export declare const getAllComponents: () => Promise<any>;
|
|
2
|
-
export declare const getComponent: (componentName: string) => Promise<any>;
|
|
3
|
-
export declare const getComponentsGroup: (groupName: string) => Promise<any>;
|
|
4
|
-
export declare const getAllComponentsGroups: () => Promise<any>;
|
|
5
|
-
export declare const createComponentsGroup: (groupName: string) => Promise<any>;
|
package/lib/api/components.js
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createComponentsGroup = exports.getAllComponentsGroups = exports.getComponentsGroup = exports.getComponent = exports.getAllComponents = void 0;
|
|
4
|
-
const logger_1 = require("../utils/logger");
|
|
5
|
-
const config_1 = require("../config/config");
|
|
6
|
-
const apiConfig_1 = require("./apiConfig");
|
|
7
|
-
const { spaceId } = config_1.default;
|
|
8
|
-
// GET
|
|
9
|
-
const getAllComponents = () => {
|
|
10
|
-
logger_1.default.log('Trying to get all components.');
|
|
11
|
-
return apiConfig_1.sbApi
|
|
12
|
-
.get(`spaces/${spaceId}/components/`)
|
|
13
|
-
.then((res) => res.data)
|
|
14
|
-
.catch((err) => logger_1.default.error(err));
|
|
15
|
-
};
|
|
16
|
-
exports.getAllComponents = getAllComponents;
|
|
17
|
-
const getComponent = (componentName) => {
|
|
18
|
-
logger_1.default.log(`Trying to get '${componentName}' component.`);
|
|
19
|
-
return (0, exports.getAllComponents)()
|
|
20
|
-
.then(res => res.components.filter((component) => component.name === componentName))
|
|
21
|
-
.then(res => {
|
|
22
|
-
if (Array.isArray(res) && res.length === 0) {
|
|
23
|
-
logger_1.default.warning(`There is no component named '${componentName}'`);
|
|
24
|
-
return false;
|
|
25
|
-
}
|
|
26
|
-
return res;
|
|
27
|
-
})
|
|
28
|
-
.catch(err => logger_1.default.error(err));
|
|
29
|
-
};
|
|
30
|
-
exports.getComponent = getComponent;
|
|
31
|
-
const getComponentsGroup = (groupName) => {
|
|
32
|
-
logger_1.default.log(`Trying to get '${groupName}' group.`);
|
|
33
|
-
return (0, exports.getAllComponentsGroups)()
|
|
34
|
-
.then(res => {
|
|
35
|
-
return res.component_groups.filter((group) => group.name === groupName);
|
|
36
|
-
})
|
|
37
|
-
.then(res => {
|
|
38
|
-
if (Array.isArray(res) && res.length === 0) {
|
|
39
|
-
logger_1.default.warning(`There is no group named '${groupName}'`);
|
|
40
|
-
return false;
|
|
41
|
-
}
|
|
42
|
-
return res;
|
|
43
|
-
})
|
|
44
|
-
.catch(err => logger_1.default.error(err));
|
|
45
|
-
};
|
|
46
|
-
exports.getComponentsGroup = getComponentsGroup;
|
|
47
|
-
const getAllComponentsGroups = async () => {
|
|
48
|
-
logger_1.default.log('Trying to get all groups.');
|
|
49
|
-
return apiConfig_1.sbApi
|
|
50
|
-
.get(`spaces/${spaceId}/component_groups/`)
|
|
51
|
-
.then(response => response.data)
|
|
52
|
-
.catch(err => logger_1.default.error(err));
|
|
53
|
-
};
|
|
54
|
-
exports.getAllComponentsGroups = getAllComponentsGroups;
|
|
55
|
-
const createComponentsGroup = (groupName) => {
|
|
56
|
-
logger_1.default.log(`Trying to create '${groupName}' group`);
|
|
57
|
-
return apiConfig_1.sbApi
|
|
58
|
-
.post(`spaces/${spaceId}/component_groups/`, {
|
|
59
|
-
component_group: {
|
|
60
|
-
name: groupName,
|
|
61
|
-
},
|
|
62
|
-
})
|
|
63
|
-
.then(res => {
|
|
64
|
-
logger_1.default.warning(`'${groupName}' created with uuid: ${res.data.component_group.uuid}`);
|
|
65
|
-
return res.data;
|
|
66
|
-
})
|
|
67
|
-
.catch(err => {
|
|
68
|
-
logger_1.default.error('Error happened :()');
|
|
69
|
-
});
|
|
70
|
-
};
|
|
71
|
-
exports.createComponentsGroup = createComponentsGroup;
|
package/lib/api/datasources.d.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
export declare const getAllDatasources: () => Promise<any>;
|
|
2
|
-
export declare const getDatasource: (datasourceName: string) => Promise<any>;
|
|
3
|
-
export declare const getDatasourceEntries: (datasourceName: string) => Promise<any>;
|
|
4
|
-
export declare const createDatasource: (datasource: any) => Promise<void | {
|
|
5
|
-
data: any;
|
|
6
|
-
datasource_entries: any;
|
|
7
|
-
}>;
|
|
8
|
-
export declare const createDatasourceEntry: (datasourceEntry: any, datasourceId: string) => Promise<any>;
|
|
9
|
-
export declare const updateDatasourceEntry: (datasourceEntry: any, datasourceId: string, datasourceToBeUpdated: any) => Promise<any>;
|
|
10
|
-
export declare const updateDatasource: (datasource: any, temp: any) => Promise<void | {
|
|
11
|
-
data: any;
|
|
12
|
-
datasource_entries: any;
|
|
13
|
-
}>;
|
|
14
|
-
export declare const createDatasourceEntries: (datasourceId: string, datasource_entries: any, remoteDatasourceEntries: any) => void;
|
|
15
|
-
interface SyncDatasources {
|
|
16
|
-
providedDatasources: string[];
|
|
17
|
-
}
|
|
18
|
-
export declare const syncDatasources: ({ providedDatasources, }: SyncDatasources) => Promise<void>;
|
|
19
|
-
interface SyncProvidedDatasources {
|
|
20
|
-
datasources: string[];
|
|
21
|
-
}
|
|
22
|
-
export declare const syncProvidedDatasources: ({ datasources, }: SyncProvidedDatasources) => void;
|
|
23
|
-
export declare const syncAllDatasources: () => void;
|
|
24
|
-
export {};
|
package/lib/api/datasources.js
DELETED
|
@@ -1,193 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.syncAllDatasources = exports.syncProvidedDatasources = exports.syncDatasources = exports.createDatasourceEntries = exports.updateDatasource = exports.updateDatasourceEntry = exports.createDatasourceEntry = exports.createDatasource = exports.getDatasourceEntries = exports.getDatasource = exports.getAllDatasources = void 0;
|
|
4
|
-
const logger_1 = require("../utils/logger");
|
|
5
|
-
const config_1 = require("../config/config");
|
|
6
|
-
const apiConfig_1 = require("./apiConfig");
|
|
7
|
-
const discover2_1 = require("../utils/discover2");
|
|
8
|
-
const { spaceId } = config_1.default;
|
|
9
|
-
// GET
|
|
10
|
-
const getAllDatasources = () => {
|
|
11
|
-
logger_1.default.log('Trying to get all Datasources.');
|
|
12
|
-
return apiConfig_1.sbApi
|
|
13
|
-
.get(`spaces/${spaceId}/datasources/`)
|
|
14
|
-
.then(({ data }) => data)
|
|
15
|
-
.catch(err => {
|
|
16
|
-
if (err.response.status === 404) {
|
|
17
|
-
logger_1.default.error(`There is no datasources in your Storyblok ${spaceId} space.`);
|
|
18
|
-
}
|
|
19
|
-
else {
|
|
20
|
-
logger_1.default.error(err);
|
|
21
|
-
return false;
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
};
|
|
25
|
-
exports.getAllDatasources = getAllDatasources;
|
|
26
|
-
const getDatasource = (datasourceName) => {
|
|
27
|
-
logger_1.default.log(`Trying to get '${datasourceName}' datasource.`);
|
|
28
|
-
return (0, exports.getAllDatasources)()
|
|
29
|
-
.then(res => {
|
|
30
|
-
if (res) {
|
|
31
|
-
return res.datasources.filter((datasource) => datasource.name === datasourceName);
|
|
32
|
-
}
|
|
33
|
-
})
|
|
34
|
-
.then(res => {
|
|
35
|
-
if (Array.isArray(res) && res.length === 0) {
|
|
36
|
-
logger_1.default.warning(`There is no datasource named '${datasourceName}'`);
|
|
37
|
-
return false;
|
|
38
|
-
}
|
|
39
|
-
return res;
|
|
40
|
-
})
|
|
41
|
-
.catch(err => logger_1.default.error(err));
|
|
42
|
-
};
|
|
43
|
-
exports.getDatasource = getDatasource;
|
|
44
|
-
const getDatasourceEntries = async (datasourceName) => {
|
|
45
|
-
logger_1.default.log(`Trying to get '${datasourceName}' datasource entries.`);
|
|
46
|
-
const data = await (0, exports.getDatasource)(datasourceName);
|
|
47
|
-
if (data) {
|
|
48
|
-
return apiConfig_1.sbApi
|
|
49
|
-
.get(`spaces/${spaceId}/datasource_entries/?datasource_id=${data[0].id}`)
|
|
50
|
-
.then(async ({ data }) => data)
|
|
51
|
-
.catch(err => logger_1.default.error(err));
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
exports.getDatasourceEntries = getDatasourceEntries;
|
|
55
|
-
const createDatasource = (datasource) => apiConfig_1.sbApi
|
|
56
|
-
.post(`spaces/${spaceId}/datasources/`, {
|
|
57
|
-
datasource: {
|
|
58
|
-
name: datasource.name,
|
|
59
|
-
slug: datasource.slug,
|
|
60
|
-
},
|
|
61
|
-
})
|
|
62
|
-
.then(({ data }) => ({
|
|
63
|
-
data,
|
|
64
|
-
datasource_entries: datasource.datasource_entries,
|
|
65
|
-
}))
|
|
66
|
-
.catch(err => logger_1.default.error(err));
|
|
67
|
-
exports.createDatasource = createDatasource;
|
|
68
|
-
const createDatasourceEntry = (datasourceEntry, datasourceId) => {
|
|
69
|
-
return apiConfig_1.sbApi
|
|
70
|
-
.post(`spaces/${spaceId}/datasource_entries/`, {
|
|
71
|
-
datasource_entry: {
|
|
72
|
-
name: Object.values(datasourceEntry)[0],
|
|
73
|
-
value: Object.values(datasourceEntry)[1],
|
|
74
|
-
datasource_id: datasourceId,
|
|
75
|
-
},
|
|
76
|
-
})
|
|
77
|
-
.then(({ data }) => {
|
|
78
|
-
return data;
|
|
79
|
-
})
|
|
80
|
-
.catch(err => logger_1.default.error(err));
|
|
81
|
-
};
|
|
82
|
-
exports.createDatasourceEntry = createDatasourceEntry;
|
|
83
|
-
const updateDatasourceEntry = (datasourceEntry, datasourceId, datasourceToBeUpdated) => {
|
|
84
|
-
return apiConfig_1.sbApi
|
|
85
|
-
.put(`spaces/${spaceId}/datasource_entries/${datasourceToBeUpdated.id}`, {
|
|
86
|
-
datasource_entry: {
|
|
87
|
-
name: Object.values(datasourceEntry)[0],
|
|
88
|
-
value: Object.values(datasourceEntry)[1],
|
|
89
|
-
datasource_id: datasourceId,
|
|
90
|
-
id: datasourceToBeUpdated.id,
|
|
91
|
-
},
|
|
92
|
-
})
|
|
93
|
-
.then(({ data }) => {
|
|
94
|
-
return data;
|
|
95
|
-
})
|
|
96
|
-
.catch(err => logger_1.default.error(err));
|
|
97
|
-
};
|
|
98
|
-
exports.updateDatasourceEntry = updateDatasourceEntry;
|
|
99
|
-
const updateDatasource = (datasource, temp) => apiConfig_1.sbApi
|
|
100
|
-
.put(`spaces/${spaceId}/datasources/${temp.id}`, {
|
|
101
|
-
datasource: {
|
|
102
|
-
id: temp.id,
|
|
103
|
-
name: datasource.name,
|
|
104
|
-
slug: datasource.slug,
|
|
105
|
-
},
|
|
106
|
-
})
|
|
107
|
-
.then(({ data }) => {
|
|
108
|
-
return {
|
|
109
|
-
data,
|
|
110
|
-
datasource_entries: datasource.datasource_entries,
|
|
111
|
-
};
|
|
112
|
-
})
|
|
113
|
-
.catch(err => logger_1.default.error(err));
|
|
114
|
-
exports.updateDatasource = updateDatasource;
|
|
115
|
-
const createDatasourceEntries = (datasourceId, datasource_entries, remoteDatasourceEntries) => {
|
|
116
|
-
Promise.all(datasource_entries.map((datasourceEntry) => {
|
|
117
|
-
const datasourceEntriesToBeUpdated = remoteDatasourceEntries.datasource_entries.find((remoteDatasourceEntry) => remoteDatasourceEntry.name ===
|
|
118
|
-
Object.values(datasourceEntry)[0]);
|
|
119
|
-
if (datasourceEntriesToBeUpdated) {
|
|
120
|
-
return (0, exports.updateDatasourceEntry)(datasourceEntry, datasourceId, datasourceEntriesToBeUpdated);
|
|
121
|
-
}
|
|
122
|
-
return (0, exports.createDatasourceEntry)(datasourceEntry, datasourceId);
|
|
123
|
-
}))
|
|
124
|
-
.then(({ data }) => {
|
|
125
|
-
logger_1.default.success(`Datasource entries for ${datasourceId} datasource id has been successfully synced.`);
|
|
126
|
-
return data;
|
|
127
|
-
})
|
|
128
|
-
.catch(err => logger_1.default.error(err));
|
|
129
|
-
};
|
|
130
|
-
exports.createDatasourceEntries = createDatasourceEntries;
|
|
131
|
-
const syncDatasources = async ({ providedDatasources, }) => {
|
|
132
|
-
logger_1.default.log(`Trying to sync provided datasources: ${providedDatasources}`);
|
|
133
|
-
const providedDatasourcesContent = (0, discover2_1.getFilesContent)({
|
|
134
|
-
files: providedDatasources,
|
|
135
|
-
});
|
|
136
|
-
const remoteDatasources = await (0, exports.getAllDatasources)();
|
|
137
|
-
Promise.all(providedDatasourcesContent.map(datasource => {
|
|
138
|
-
const datasourceToBeUpdated = remoteDatasources.datasources.find((remoteDatasource) => datasource.name === remoteDatasource.name);
|
|
139
|
-
if (datasourceToBeUpdated) {
|
|
140
|
-
return (0, exports.updateDatasource)(datasource, datasourceToBeUpdated);
|
|
141
|
-
}
|
|
142
|
-
return (0, exports.createDatasource)(datasource);
|
|
143
|
-
}))
|
|
144
|
-
.then(res => {
|
|
145
|
-
res.map(async ({ data, datasource_entries }) => {
|
|
146
|
-
const remoteDatasourceEntries = await (0, exports.getDatasourceEntries)(data.datasource.name);
|
|
147
|
-
(0, exports.createDatasourceEntries)(data.datasource.id, datasource_entries, remoteDatasourceEntries);
|
|
148
|
-
});
|
|
149
|
-
return res;
|
|
150
|
-
})
|
|
151
|
-
.catch(err => {
|
|
152
|
-
console.log(err);
|
|
153
|
-
logger_1.default.warning('There is error inside promise.all from datasource');
|
|
154
|
-
return false;
|
|
155
|
-
});
|
|
156
|
-
};
|
|
157
|
-
exports.syncDatasources = syncDatasources;
|
|
158
|
-
const syncProvidedDatasources = ({ datasources, }) => {
|
|
159
|
-
const allLocalDatasources = (0, discover2_1.discoverManyDatasources)({
|
|
160
|
-
scope: discover2_1.SCOPE.local,
|
|
161
|
-
type: discover2_1.LOOKUP_TYPE.fileName,
|
|
162
|
-
fileNames: datasources,
|
|
163
|
-
});
|
|
164
|
-
const allExternalDatasources = (0, discover2_1.discoverManyDatasources)({
|
|
165
|
-
scope: discover2_1.SCOPE.external,
|
|
166
|
-
type: discover2_1.LOOKUP_TYPE.fileName,
|
|
167
|
-
fileNames: datasources,
|
|
168
|
-
});
|
|
169
|
-
(0, exports.syncDatasources)({
|
|
170
|
-
providedDatasources: [
|
|
171
|
-
...allLocalDatasources,
|
|
172
|
-
...allExternalDatasources,
|
|
173
|
-
],
|
|
174
|
-
});
|
|
175
|
-
};
|
|
176
|
-
exports.syncProvidedDatasources = syncProvidedDatasources;
|
|
177
|
-
const syncAllDatasources = () => {
|
|
178
|
-
const allLocalDatasources = (0, discover2_1.discoverDatasources)({
|
|
179
|
-
scope: discover2_1.SCOPE.local,
|
|
180
|
-
type: discover2_1.LOOKUP_TYPE.fileName,
|
|
181
|
-
});
|
|
182
|
-
const allExternalDatasources = (0, discover2_1.discoverDatasources)({
|
|
183
|
-
scope: discover2_1.SCOPE.external,
|
|
184
|
-
type: discover2_1.LOOKUP_TYPE.fileName,
|
|
185
|
-
});
|
|
186
|
-
(0, exports.syncDatasources)({
|
|
187
|
-
providedDatasources: [
|
|
188
|
-
...allLocalDatasources,
|
|
189
|
-
...allExternalDatasources,
|
|
190
|
-
],
|
|
191
|
-
});
|
|
192
|
-
};
|
|
193
|
-
exports.syncAllDatasources = syncAllDatasources;
|
package/lib/api/migrate.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { OneComponent } from '../utils/discover2';
|
|
2
|
-
interface SyncComponents {
|
|
3
|
-
specifiedComponents: OneComponent[];
|
|
4
|
-
presets: boolean;
|
|
5
|
-
}
|
|
6
|
-
export declare const sync2Components: ({ specifiedComponents, presets }: SyncComponents) => Promise<void>;
|
|
7
|
-
export declare const syncComponents: (specifiedComponents: string[], ext: string | boolean, presets: boolean, packageName: boolean, local?: boolean | undefined) => Promise<void>;
|
|
8
|
-
interface SyncAllComponents {
|
|
9
|
-
presets: boolean;
|
|
10
|
-
}
|
|
11
|
-
interface SyncProvidedComponents {
|
|
12
|
-
presets: boolean;
|
|
13
|
-
components: string[];
|
|
14
|
-
packageName: boolean;
|
|
15
|
-
}
|
|
16
|
-
export declare const syncProvidedComponents: ({ components, presets, packageName }: SyncProvidedComponents) => void;
|
|
17
|
-
export declare const sync2AllComponents: ({ presets }: SyncAllComponents) => void;
|
|
18
|
-
export declare const syncAllComponents: (ext: string | boolean, presets: boolean) => void;
|
|
19
|
-
export {};
|