sb-mig 2.9.13 → 3.0.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/README.md +107 -495
- package/{lib → dist}/api/componentPresets.d.ts +1 -1
- package/dist/api/componentPresets.js +18 -0
- package/{lib → dist}/api/components.d.ts +2 -2
- package/dist/api/components.js +63 -0
- package/dist/api/config.d.ts +2 -0
- package/dist/api/config.js +4 -0
- package/{lib → dist}/api/datasources.d.ts +1 -1
- package/dist/api/datasources.js +181 -0
- package/dist/api/migrate.d.ts +17 -0
- package/dist/api/migrate.js +139 -0
- package/{lib → dist}/api/mutateComponents.d.ts +0 -0
- package/dist/api/mutateComponents.js +45 -0
- package/{lib → dist}/api/presets.d.ts +1 -1
- package/dist/api/presets.js +52 -0
- package/{lib → dist}/api/resolvePresets.d.ts +0 -0
- package/{lib → dist}/api/resolvePresets.js +15 -14
- package/{lib → dist}/api/roles.d.ts +2 -2
- package/dist/api/roles.js +125 -0
- package/dist/cli-descriptions.d.ts +4 -0
- package/dist/cli-descriptions.js +69 -0
- package/dist/commands/backup.d.ts +2 -0
- package/dist/commands/backup.js +201 -0
- package/dist/commands/debug.d.ts +1 -0
- package/dist/commands/debug.js +5 -0
- package/dist/commands/sync.d.ts +2 -0
- package/dist/commands/sync.js +58 -0
- package/dist/config/config.d.ts +14 -0
- package/dist/config/config.js +49 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +52 -0
- package/{lib/utils/discover2.d.ts → dist/utils/discover.d.ts} +1 -7
- package/{lib/utils/discover2.js → dist/utils/discover.js} +200 -143
- package/{lib → dist}/utils/files.d.ts +7 -1
- package/dist/utils/files.js +54 -0
- package/dist/utils/interfaces.d.ts +4 -0
- package/dist/utils/interfaces.js +1 -0
- package/{lib → dist}/utils/logger.d.ts +0 -3
- package/{lib → dist}/utils/logger.js +2 -12
- package/dist/utils/main.d.ts +13 -0
- package/dist/utils/main.js +28 -0
- package/{lib → dist}/utils/others.d.ts +0 -0
- package/dist/utils/others.js +1 -0
- package/package.json +63 -63
- 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.js +0 -22
- package/lib/api/components.js +0 -71
- 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.js +0 -50
- package/lib/api/presets.js +0 -59
- 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/files.js +0 -54
- package/lib/utils/others.js +0 -5
- package/oclif.manifest.json +0 -1
|
@@ -1,6 +1,12 @@
|
|
|
1
|
-
export declare const getCurrentDirectoryBase: () => string;
|
|
2
1
|
export declare const isDirectoryExists: (path: string) => boolean;
|
|
3
2
|
export declare const createDir: (dirPath: string) => Promise<void>;
|
|
4
3
|
export declare const createJsonFile: (content: string, pathWithFilename: string) => Promise<void>;
|
|
5
4
|
export declare const copyFolder: (src: string, dest: string) => Promise<unknown>;
|
|
6
5
|
export declare const copyFile: (src: string, dest: string) => Promise<void>;
|
|
6
|
+
interface CreateAndSaveToFile {
|
|
7
|
+
prefix: string;
|
|
8
|
+
folder: string;
|
|
9
|
+
res: any;
|
|
10
|
+
}
|
|
11
|
+
export declare const createAndSaveToFile: ({ prefix, folder, res, }: CreateAndSaveToFile) => Promise<void>;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import * as fs from "fs";
|
|
2
|
+
import pkg from "ncp";
|
|
3
|
+
import { generateDatestamp } from "./others.js";
|
|
4
|
+
import storyblokConfig from "../config/config.js";
|
|
5
|
+
import Logger from "./logger.js";
|
|
6
|
+
const { ncp } = pkg;
|
|
7
|
+
export const isDirectoryExists = (path) => fs.existsSync(path);
|
|
8
|
+
export const createDir = async (dirPath) => {
|
|
9
|
+
await fs.promises.mkdir(`${process.cwd()}/${dirPath}`, {
|
|
10
|
+
recursive: true,
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
export const createJsonFile = async (content, pathWithFilename) => {
|
|
14
|
+
await fs.promises.writeFile(pathWithFilename, content, { flag: "w" });
|
|
15
|
+
};
|
|
16
|
+
export const copyFolder = async (src, dest) => {
|
|
17
|
+
return new Promise((resolve, reject) => {
|
|
18
|
+
ncp(src, dest, function (err) {
|
|
19
|
+
if (err) {
|
|
20
|
+
reject({
|
|
21
|
+
failed: true,
|
|
22
|
+
message: `${src} copied unsuccessfully.`,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
resolve({
|
|
26
|
+
failed: false,
|
|
27
|
+
message: `${src} copied successfully.`,
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
export const copyFile = async (src, dest) => {
|
|
33
|
+
const directory = dest.split("/").slice(0, dest.split("/").length - 1);
|
|
34
|
+
const fileName = src.split("/")[src.split("/").length - 1];
|
|
35
|
+
if (!isDirectoryExists(directory.join("/"))) {
|
|
36
|
+
await createDir(directory.join("/"));
|
|
37
|
+
}
|
|
38
|
+
fs.copyFile(src, dest, (err) => {
|
|
39
|
+
if (err) {
|
|
40
|
+
console.error(`There is no file to copy, named ${fileName}`);
|
|
41
|
+
console.log(err);
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
console.log(`${fileName} was copied to ${dest}`);
|
|
45
|
+
return true;
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
export const createAndSaveToFile = async ({ prefix, folder, res, }) => {
|
|
49
|
+
const datestamp = new Date();
|
|
50
|
+
const filename = `${prefix}${generateDatestamp(datestamp)}`;
|
|
51
|
+
await createDir(`${storyblokConfig.sbmigWorkingDirectory}/${folder}/`);
|
|
52
|
+
await createJsonFile(JSON.stringify(res, undefined, 2), `${storyblokConfig.sbmigWorkingDirectory}/${folder}/${filename}.json`);
|
|
53
|
+
Logger.success(`All groups written to a file: ${filename}`);
|
|
54
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,14 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const chalk = require("chalk");
|
|
4
|
-
const figlet = require("figlet");
|
|
5
|
-
class Logger {
|
|
6
|
-
constructor(name) {
|
|
7
|
-
this.name = name;
|
|
8
|
-
}
|
|
9
|
-
static bigLog(content) {
|
|
10
|
-
console.log(chalk.yellow(figlet.textSync(content, { horizontalLayout: 'full' })));
|
|
11
|
-
}
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
export default class Logger {
|
|
12
3
|
static log(content) {
|
|
13
4
|
console.log(content);
|
|
14
5
|
}
|
|
@@ -27,4 +18,3 @@ class Logger {
|
|
|
27
18
|
}
|
|
28
19
|
}
|
|
29
20
|
}
|
|
30
|
-
exports.default = Logger;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare const prop: (k: any) => (o: any) => any;
|
|
2
|
+
export declare const pipe: (...fns: any[]) => (x: any) => any;
|
|
3
|
+
export declare const unpackElements: (input: string[]) => string[];
|
|
4
|
+
export declare const unpackOne: (input: string[]) => string | undefined;
|
|
5
|
+
export declare const getFileContent: (data: {
|
|
6
|
+
file: string;
|
|
7
|
+
}) => any;
|
|
8
|
+
export declare const getFileContentWithRequire: (data: {
|
|
9
|
+
file: string;
|
|
10
|
+
}) => any;
|
|
11
|
+
export declare const getFilesContentWithRequire: (data: {
|
|
12
|
+
files: string[];
|
|
13
|
+
}) => any[];
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { createRequire } from "module";
|
|
2
|
+
export const prop = (k) => (o) => o[k];
|
|
3
|
+
export const pipe = (...fns) => (x) => [...fns].reduce((acc, f) => f(acc), x);
|
|
4
|
+
export const unpackElements = (input) => {
|
|
5
|
+
const [_1, _2, ...elementsForUse] = input;
|
|
6
|
+
return elementsForUse;
|
|
7
|
+
};
|
|
8
|
+
export const unpackOne = (input) => {
|
|
9
|
+
const [_1, _2, elementForUse] = input;
|
|
10
|
+
return elementForUse;
|
|
11
|
+
};
|
|
12
|
+
export const getFileContent = (data) => {
|
|
13
|
+
return import(data.file)
|
|
14
|
+
.then((res) => {
|
|
15
|
+
return res.default;
|
|
16
|
+
})
|
|
17
|
+
.catch(() => {
|
|
18
|
+
console.log("Cannot find requested file.");
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
export const getFileContentWithRequire = (data) => {
|
|
22
|
+
const require = createRequire(import.meta.url);
|
|
23
|
+
return require(data.file);
|
|
24
|
+
};
|
|
25
|
+
export const getFilesContentWithRequire = (data) => {
|
|
26
|
+
const require = createRequire(import.meta.url);
|
|
27
|
+
return data.files.map((file) => require(file));
|
|
28
|
+
};
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const generateDatestamp = (datestamp) => `${datestamp.getFullYear()}-${datestamp.getMonth()}-${datestamp.getDay()}_${datestamp.getTime()}`;
|
package/package.json
CHANGED
|
@@ -1,80 +1,80 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sb-mig",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0-beta.1",
|
|
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
|
-
"
|
|
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
|
+
"main": "./dist/index.js",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/sb-mig/sb-mig.git"
|
|
29
12
|
},
|
|
30
|
-
"
|
|
31
|
-
"
|
|
13
|
+
"publishConfig": {
|
|
14
|
+
"registry": "https://registry.npmjs.org/",
|
|
15
|
+
"access": "public"
|
|
32
16
|
},
|
|
33
|
-
"
|
|
34
|
-
|
|
35
|
-
"/lib",
|
|
36
|
-
"/npm-shrinkwrap.json",
|
|
37
|
-
"/oclif.manifest.json"
|
|
38
|
-
],
|
|
39
|
-
"homepage": "https://sb-mig.com",
|
|
17
|
+
"bugs": "https://github.com/sb-mig/sb-mig/issues",
|
|
18
|
+
"homepage": "https://github.com/sb-mig/sb-mig",
|
|
40
19
|
"keywords": [
|
|
41
20
|
"cli",
|
|
42
21
|
"storyblok",
|
|
43
22
|
"sb",
|
|
44
23
|
"migrate"
|
|
45
24
|
],
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
|
|
49
|
-
"
|
|
50
|
-
"bin": "sb-mig",
|
|
51
|
-
"scope": "sb-mig",
|
|
52
|
-
"plugins": [
|
|
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"
|
|
25
|
+
"type": "module",
|
|
26
|
+
"exports": {
|
|
27
|
+
".": "./dist/index.js",
|
|
28
|
+
"./dist/*": "./dist/*"
|
|
65
29
|
},
|
|
66
|
-
"
|
|
67
|
-
"
|
|
68
|
-
"access": "public"
|
|
30
|
+
"engines": {
|
|
31
|
+
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
|
|
69
32
|
},
|
|
33
|
+
"files": [
|
|
34
|
+
"/dist"
|
|
35
|
+
],
|
|
70
36
|
"scripts": {
|
|
71
|
-
"
|
|
72
|
-
"
|
|
73
|
-
"build": "rm -rf
|
|
74
|
-
"
|
|
75
|
-
"
|
|
76
|
-
"
|
|
37
|
+
"lint-staged": "lint-staged",
|
|
38
|
+
"build": "rm -rf dist && tsc",
|
|
39
|
+
"build:dev": "rm -rf dist && tsc && chmod +x ./dist/index.js",
|
|
40
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
41
|
+
"start": "yarn build && ./dist/index.js",
|
|
42
|
+
"debug": "yarn build && ./dist/index.js sync components accordion accordion-item",
|
|
43
|
+
"version": "conventional-changelog -p eslint -i CHANGELOG.md -s",
|
|
44
|
+
"semantic-release": "semantic-release",
|
|
45
|
+
"prepare": "husky install"
|
|
46
|
+
},
|
|
47
|
+
"dependencies": {
|
|
48
|
+
"axios": "^0.27.2",
|
|
49
|
+
"chalk": "^5.0.0",
|
|
50
|
+
"dotenv": "^14.3.1",
|
|
51
|
+
"glob": "^7.2.0",
|
|
52
|
+
"meow": "^10.1.2",
|
|
53
|
+
"ncp": "^2.0.0",
|
|
54
|
+
"storyblok-js-client": "^4.2.0"
|
|
77
55
|
},
|
|
78
|
-
"
|
|
79
|
-
|
|
56
|
+
"devDependencies": {
|
|
57
|
+
"@commitlint/cli": "^17.0.0",
|
|
58
|
+
"@commitlint/config-conventional": "^17.0.0",
|
|
59
|
+
"@semantic-release/changelog": "^6.0.1",
|
|
60
|
+
"@semantic-release/git": "^10.0.1",
|
|
61
|
+
"@sindresorhus/tsconfig": "^2.0.0",
|
|
62
|
+
"@types/glob": "^7.2.0",
|
|
63
|
+
"@types/ncp": "^2.0.5",
|
|
64
|
+
"@types/node": "^17.0.35",
|
|
65
|
+
"commitizen": "^4.0.4",
|
|
66
|
+
"conventional-changelog-cli": "^2.0.31",
|
|
67
|
+
"eslint": "^8.16.0",
|
|
68
|
+
"eslint-config-prettier": "^8.5.0",
|
|
69
|
+
"husky": "^8.0.1",
|
|
70
|
+
"lint-staged": "^12.4.1",
|
|
71
|
+
"prettier": "^2.6.2",
|
|
72
|
+
"semantic-release": "^19.0.2",
|
|
73
|
+
"typescript": "^4.6.4"
|
|
74
|
+
},
|
|
75
|
+
"config": {
|
|
76
|
+
"commitizen": {
|
|
77
|
+
"path": "./node_modules/cz-conventional-changelog"
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
80
|
}
|
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,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.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.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 {};
|