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
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import Logger from "../utils/logger.js";
|
|
2
|
+
import storyblokConfig from "../config/config.js";
|
|
3
|
+
import { sbApi } from "./config.js";
|
|
4
|
+
import { LOOKUP_TYPE, SCOPE, compare, discoverRoles, discoverManyRoles, } from "../utils/discover.js";
|
|
5
|
+
import { getFileContent } from "../utils/main.js";
|
|
6
|
+
const { spaceId } = storyblokConfig;
|
|
7
|
+
// POST
|
|
8
|
+
export const createRole = (role) => {
|
|
9
|
+
sbApi
|
|
10
|
+
.post(`spaces/${spaceId}/space_roles/`, {
|
|
11
|
+
space_role: role,
|
|
12
|
+
})
|
|
13
|
+
.then(() => {
|
|
14
|
+
Logger.success(`Role '${role.role}' has been created.`);
|
|
15
|
+
})
|
|
16
|
+
.catch((err) => {
|
|
17
|
+
Logger.error("error happened... :(");
|
|
18
|
+
console.log(`${err.message} in migration of ${role.role} in createRole function`);
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
// PUT
|
|
22
|
+
export const updateRole = (role) => {
|
|
23
|
+
sbApi
|
|
24
|
+
.put(`spaces/${spaceId}/space_roles/${role.id}`, {
|
|
25
|
+
space_role: role,
|
|
26
|
+
})
|
|
27
|
+
.then(() => {
|
|
28
|
+
Logger.success(`Role '${role.role}' has been updated.`);
|
|
29
|
+
})
|
|
30
|
+
.catch((err) => {
|
|
31
|
+
Logger.error("error happened... :(");
|
|
32
|
+
console.log(`${err.message} in migration of ${role.role} in updateRole function`);
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
// GET
|
|
36
|
+
export const getAllRoles = async () => {
|
|
37
|
+
return sbApi
|
|
38
|
+
.get(`spaces/${spaceId}/space_roles/`)
|
|
39
|
+
.then(({ data }) => data)
|
|
40
|
+
.catch((err) => {
|
|
41
|
+
if (err.response.status === 404) {
|
|
42
|
+
Logger.error(`There is no roles in your Storyblok ${spaceId} space.`);
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
Logger.error(err);
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
// GET
|
|
52
|
+
export const getRole = async (roleName) => {
|
|
53
|
+
Logger.log(`Trying to get '${roleName}' role.`);
|
|
54
|
+
return getAllRoles()
|
|
55
|
+
.then((res) => res.space_roles.filter((role) => role.role === roleName))
|
|
56
|
+
.then((res) => {
|
|
57
|
+
if (Array.isArray(res) && res.length === 0) {
|
|
58
|
+
Logger.warning(`There is no role named '${roleName}'`);
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
return res;
|
|
62
|
+
})
|
|
63
|
+
.catch((err) => Logger.error(err));
|
|
64
|
+
};
|
|
65
|
+
export const syncRoles = async ({ specifiedRoles }) => {
|
|
66
|
+
const specifiedRolesContent = await Promise.all(specifiedRoles.map((roles) => getFileContent({ file: roles.path })));
|
|
67
|
+
const { space_roles } = await getAllRoles();
|
|
68
|
+
const rolesToUpdate = [];
|
|
69
|
+
const rolesToCreate = [];
|
|
70
|
+
for (const role of specifiedRolesContent) {
|
|
71
|
+
const shouldBeUpdated = space_roles.find((remoteRole) => role.role === remoteRole.role);
|
|
72
|
+
if (shouldBeUpdated) {
|
|
73
|
+
rolesToUpdate.push({ id: shouldBeUpdated.id, ...role });
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
rolesToCreate.push(role);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
rolesToUpdate.map(async (role) => {
|
|
80
|
+
await updateRole(role);
|
|
81
|
+
});
|
|
82
|
+
rolesToCreate.map(async (role) => {
|
|
83
|
+
await createRole(role);
|
|
84
|
+
});
|
|
85
|
+
};
|
|
86
|
+
export const syncAllRoles = async () => {
|
|
87
|
+
// #1: discover all external .roles.sb.js files
|
|
88
|
+
const allLocalSbComponentsSchemaFiles = discoverRoles({
|
|
89
|
+
scope: SCOPE.local,
|
|
90
|
+
type: LOOKUP_TYPE.fileName,
|
|
91
|
+
});
|
|
92
|
+
// #2: discover all local .roles.sb.js files
|
|
93
|
+
const allExternalSbComponentsSchemaFiles = discoverRoles({
|
|
94
|
+
scope: SCOPE.external,
|
|
95
|
+
type: LOOKUP_TYPE.fileName,
|
|
96
|
+
});
|
|
97
|
+
// #3: compare results, prefare local ones (so we have to create final external paths array and local array of things to sync from where)
|
|
98
|
+
const { local, external } = compare({
|
|
99
|
+
local: allLocalSbComponentsSchemaFiles,
|
|
100
|
+
external: allExternalSbComponentsSchemaFiles,
|
|
101
|
+
});
|
|
102
|
+
// #4: sync - do all stuff already done (groups resolving, and so on)
|
|
103
|
+
syncRoles({ specifiedRoles: [...local, ...external] });
|
|
104
|
+
};
|
|
105
|
+
export const syncProvidedRoles = ({ roles }) => {
|
|
106
|
+
// #1: discover all external .sb.js files
|
|
107
|
+
const allLocalSbComponentsSchemaFiles = discoverManyRoles({
|
|
108
|
+
scope: SCOPE.local,
|
|
109
|
+
type: LOOKUP_TYPE.fileName,
|
|
110
|
+
fileNames: roles,
|
|
111
|
+
});
|
|
112
|
+
// #2: discover all local .sb.js files
|
|
113
|
+
const allExternalSbComponentsSchemaFiles = discoverManyRoles({
|
|
114
|
+
scope: SCOPE.external,
|
|
115
|
+
type: LOOKUP_TYPE.fileName,
|
|
116
|
+
fileNames: roles,
|
|
117
|
+
});
|
|
118
|
+
// #3: compare results, prefer local ones (so we have to create final external paths array and local array of things to sync from where)
|
|
119
|
+
const { local, external } = compare({
|
|
120
|
+
local: allLocalSbComponentsSchemaFiles,
|
|
121
|
+
external: allExternalSbComponentsSchemaFiles,
|
|
122
|
+
});
|
|
123
|
+
// #4: sync - do all stuff already done (groups resolving, and so on)
|
|
124
|
+
syncRoles({ specifiedRoles: [...local, ...external] });
|
|
125
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare const mainDescription = "\n CLI to rule the world. (and handle stuff related to Storyblok CMS)\n \n USAGE\n $ sb-mig [command]\n \n COMMANDS\n sync Synchronize components, datasources or roles with Storyblok space.\n backup Command for backing up anything related to Storyblok\n debug Output extra debugging information\n help This screen\n \n Examples\n $ sb-migv-3 sync\n $ sb-mig-v3 debug \n";
|
|
2
|
+
export declare const syncDescription = "\n Usage\n $ sb-mig-v3 sync [components|roles|datasources] [space separated file names] or --all --packageName\n \n Description\n Synchronize components or roles with Storyblok space.\n \n COMMANDS\n components - sync components\n roles - sync roles\n datasources - sync datasources\n \n FLAGS\n --all - Sync all components\n --packageName - Sync based on package name, instead of file name (package can have multiple schema files to sync)\n --presets - Pass it, if u want to sync also with presets (will take longer) \n \n EXAMPLES\n $ sb-mig sync components --all\n $ sb-mig sync components accordion accordion-item\n $ sb-mig sync components @storyblok-components/accordion --packageName\n \n";
|
|
3
|
+
export declare const backupDescription = "\n Usage\n $ sb-mig-v3 backup [components|component-groups|roles|datasources|presets|component-presets] [space separated file names ] or --all\n Description\n Command for backing up anything related to Storyblok\n \n COMMANDS\n components - backup components\n component-groups - backuo component-groups\n roles - backup components\n datasources - backup components\n presets - backup presets\n component-presets - backup component presets\n \n FLAGS\n --all - Backup all \n --one - Backup one \n \n EXAMPLES\n $ sb-mig backup components --all\n $ sb-mig backup components accordion accordion-item carousel text-block\n $ sb-mig backup datasources --all\n $ sb-mig backup roles admin normal-user\n";
|
|
4
|
+
export declare const debugDescription = "\n Usage\n $ sb-mig-v3 debug\n Description\n Output extra debugging information\n";
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
export const mainDescription = `
|
|
2
|
+
CLI to rule the world. (and handle stuff related to Storyblok CMS)
|
|
3
|
+
|
|
4
|
+
USAGE
|
|
5
|
+
$ sb-mig [command]
|
|
6
|
+
|
|
7
|
+
COMMANDS
|
|
8
|
+
sync Synchronize components, datasources or roles with Storyblok space.
|
|
9
|
+
backup Command for backing up anything related to Storyblok
|
|
10
|
+
debug Output extra debugging information
|
|
11
|
+
help This screen
|
|
12
|
+
|
|
13
|
+
Examples
|
|
14
|
+
$ sb-migv-3 sync
|
|
15
|
+
$ sb-mig-v3 debug
|
|
16
|
+
`;
|
|
17
|
+
export const syncDescription = `
|
|
18
|
+
Usage
|
|
19
|
+
$ sb-mig-v3 sync [components|roles|datasources] [space separated file names] or --all --packageName
|
|
20
|
+
|
|
21
|
+
Description
|
|
22
|
+
Synchronize components or roles with Storyblok space.
|
|
23
|
+
|
|
24
|
+
COMMANDS
|
|
25
|
+
components - sync components
|
|
26
|
+
roles - sync roles
|
|
27
|
+
datasources - sync datasources
|
|
28
|
+
|
|
29
|
+
FLAGS
|
|
30
|
+
--all - Sync all components
|
|
31
|
+
--packageName - Sync based on package name, instead of file name (package can have multiple schema files to sync)
|
|
32
|
+
--presets - Pass it, if u want to sync also with presets (will take longer)
|
|
33
|
+
|
|
34
|
+
EXAMPLES
|
|
35
|
+
$ sb-mig sync components --all
|
|
36
|
+
$ sb-mig sync components accordion accordion-item
|
|
37
|
+
$ sb-mig sync components @storyblok-components/accordion --packageName
|
|
38
|
+
|
|
39
|
+
`;
|
|
40
|
+
export const backupDescription = `
|
|
41
|
+
Usage
|
|
42
|
+
$ sb-mig-v3 backup [components|component-groups|roles|datasources|presets|component-presets] [space separated file names ] or --all
|
|
43
|
+
Description
|
|
44
|
+
Command for backing up anything related to Storyblok
|
|
45
|
+
|
|
46
|
+
COMMANDS
|
|
47
|
+
components - backup components
|
|
48
|
+
component-groups - backuo component-groups
|
|
49
|
+
roles - backup components
|
|
50
|
+
datasources - backup components
|
|
51
|
+
presets - backup presets
|
|
52
|
+
component-presets - backup component presets
|
|
53
|
+
|
|
54
|
+
FLAGS
|
|
55
|
+
--all - Backup all
|
|
56
|
+
--one - Backup one
|
|
57
|
+
|
|
58
|
+
EXAMPLES
|
|
59
|
+
$ sb-mig backup components --all
|
|
60
|
+
$ sb-mig backup components accordion accordion-item carousel text-block
|
|
61
|
+
$ sb-mig backup datasources --all
|
|
62
|
+
$ sb-mig backup roles admin normal-user
|
|
63
|
+
`;
|
|
64
|
+
export const debugDescription = `
|
|
65
|
+
Usage
|
|
66
|
+
$ sb-mig-v3 debug
|
|
67
|
+
Description
|
|
68
|
+
Output extra debugging information
|
|
69
|
+
`;
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { getAllComponents, getAllComponentsGroups, getComponent, getComponentsGroup, } from "../api/components.js";
|
|
2
|
+
import { createAndSaveToFile } from "../utils/files.js";
|
|
3
|
+
import Logger from "../utils/logger.js";
|
|
4
|
+
import { unpackOne } from "../utils/main.js";
|
|
5
|
+
import { getAllDatasources, getDatasource } from "../api/datasources.js";
|
|
6
|
+
import { getAllRoles, getRole } from "../api/roles.js";
|
|
7
|
+
import { getComponentPresets } from "../api/componentPresets.js";
|
|
8
|
+
import { getAllPresets, getPreset } from "../api/presets.js";
|
|
9
|
+
const BACKUP_COMMANDS = {
|
|
10
|
+
components: "components",
|
|
11
|
+
componentGroups: "component-groups",
|
|
12
|
+
datasources: "datasources",
|
|
13
|
+
presets: "presets",
|
|
14
|
+
componentPresets: "component-presets",
|
|
15
|
+
roles: "roles",
|
|
16
|
+
};
|
|
17
|
+
export const backup = (props) => {
|
|
18
|
+
const { input, flags } = props;
|
|
19
|
+
const command = input[1];
|
|
20
|
+
switch (command) {
|
|
21
|
+
case BACKUP_COMMANDS.components:
|
|
22
|
+
Logger.warning(`back up components... with command: ${command}`);
|
|
23
|
+
if (flags["all"]) {
|
|
24
|
+
getAllComponents()
|
|
25
|
+
.then(async (res) => {
|
|
26
|
+
await createAndSaveToFile({
|
|
27
|
+
prefix: "all-components-",
|
|
28
|
+
folder: "components",
|
|
29
|
+
res,
|
|
30
|
+
});
|
|
31
|
+
})
|
|
32
|
+
.catch((err) => {
|
|
33
|
+
console.log(err);
|
|
34
|
+
console.error("error happened... :(");
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
if (flags["one"]) {
|
|
38
|
+
const componentToBackup = unpackOne(input);
|
|
39
|
+
getComponent(componentToBackup)
|
|
40
|
+
.then(async (res) => {
|
|
41
|
+
await createAndSaveToFile({
|
|
42
|
+
prefix: "component-",
|
|
43
|
+
folder: "components",
|
|
44
|
+
res,
|
|
45
|
+
});
|
|
46
|
+
})
|
|
47
|
+
.catch((err) => {
|
|
48
|
+
console.log(err);
|
|
49
|
+
Logger.error("error happened... :(");
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
break;
|
|
53
|
+
case BACKUP_COMMANDS.componentGroups:
|
|
54
|
+
if (flags["all"]) {
|
|
55
|
+
getAllComponentsGroups()
|
|
56
|
+
.then(async (res) => {
|
|
57
|
+
await createAndSaveToFile({
|
|
58
|
+
prefix: "all-component_groups-",
|
|
59
|
+
folder: "component_groups",
|
|
60
|
+
res,
|
|
61
|
+
});
|
|
62
|
+
})
|
|
63
|
+
.catch((err) => {
|
|
64
|
+
console.log(err);
|
|
65
|
+
Logger.error("error happened... :(");
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
if (flags["one"]) {
|
|
69
|
+
const componentGroupToBackup = unpackOne(input);
|
|
70
|
+
getComponentsGroup(componentGroupToBackup)
|
|
71
|
+
.then(async (res) => {
|
|
72
|
+
await createAndSaveToFile({
|
|
73
|
+
prefix: "components_group-",
|
|
74
|
+
folder: "component_groups",
|
|
75
|
+
res,
|
|
76
|
+
});
|
|
77
|
+
})
|
|
78
|
+
.catch((err) => {
|
|
79
|
+
console.log(err);
|
|
80
|
+
Logger.error("error happened... :(");
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
break;
|
|
84
|
+
case BACKUP_COMMANDS.datasources:
|
|
85
|
+
if (flags["all"]) {
|
|
86
|
+
getAllDatasources()
|
|
87
|
+
.then(async (res) => {
|
|
88
|
+
await createAndSaveToFile({
|
|
89
|
+
prefix: "all-datasources-",
|
|
90
|
+
folder: "datasources",
|
|
91
|
+
res,
|
|
92
|
+
});
|
|
93
|
+
})
|
|
94
|
+
.catch((err) => {
|
|
95
|
+
console.log(err);
|
|
96
|
+
Logger.error("error happened... :(");
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
if (flags["one"]) {
|
|
100
|
+
const datasourceToBackup = unpackOne(input);
|
|
101
|
+
getDatasource(datasourceToBackup)
|
|
102
|
+
.then(async (res) => {
|
|
103
|
+
if (res) {
|
|
104
|
+
await createAndSaveToFile({
|
|
105
|
+
prefix: `datasource-${datasourceToBackup}-`,
|
|
106
|
+
folder: "datasources",
|
|
107
|
+
res,
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
})
|
|
111
|
+
.catch((err) => {
|
|
112
|
+
console.log(err);
|
|
113
|
+
Logger.error("error happened... :(");
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
break;
|
|
117
|
+
case BACKUP_COMMANDS.roles:
|
|
118
|
+
if (flags["all"]) {
|
|
119
|
+
getAllRoles()
|
|
120
|
+
.then(async (res) => {
|
|
121
|
+
await createAndSaveToFile({
|
|
122
|
+
prefix: "all-roles-",
|
|
123
|
+
folder: "roles",
|
|
124
|
+
res,
|
|
125
|
+
});
|
|
126
|
+
})
|
|
127
|
+
.catch((err) => {
|
|
128
|
+
console.log(err);
|
|
129
|
+
Logger.error("error happened... :(");
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
if (flags["one"]) {
|
|
133
|
+
const roleToBackup = unpackOne(input);
|
|
134
|
+
getRole(roleToBackup)
|
|
135
|
+
.then(async (res) => {
|
|
136
|
+
if (res) {
|
|
137
|
+
await createAndSaveToFile({
|
|
138
|
+
prefix: `role-${roleToBackup}`,
|
|
139
|
+
folder: "roles",
|
|
140
|
+
res,
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
})
|
|
144
|
+
.catch((err) => {
|
|
145
|
+
console.log(err);
|
|
146
|
+
Logger.error("error happened... :(");
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
break;
|
|
150
|
+
case BACKUP_COMMANDS.presets:
|
|
151
|
+
if (flags["all"]) {
|
|
152
|
+
getAllPresets()
|
|
153
|
+
.then(async (res) => {
|
|
154
|
+
await createAndSaveToFile({
|
|
155
|
+
prefix: "all-presets-",
|
|
156
|
+
folder: "presets",
|
|
157
|
+
res,
|
|
158
|
+
});
|
|
159
|
+
})
|
|
160
|
+
.catch((err) => {
|
|
161
|
+
console.log(err);
|
|
162
|
+
Logger.error("error happened... :(");
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
if (flags["one"]) {
|
|
166
|
+
const presetToBackup = unpackOne(input);
|
|
167
|
+
getPreset(presetToBackup)
|
|
168
|
+
.then(async (res) => {
|
|
169
|
+
await createAndSaveToFile({
|
|
170
|
+
prefix: `preset-${presetToBackup}-`,
|
|
171
|
+
folder: "presets",
|
|
172
|
+
res,
|
|
173
|
+
});
|
|
174
|
+
})
|
|
175
|
+
.catch((err) => {
|
|
176
|
+
console.log(err);
|
|
177
|
+
Logger.error("error happened... :(");
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
break;
|
|
181
|
+
case BACKUP_COMMANDS.componentPresets:
|
|
182
|
+
if (flags["one"]) {
|
|
183
|
+
const componentPresetToBackup = unpackOne(input);
|
|
184
|
+
getComponentPresets(componentPresetToBackup)
|
|
185
|
+
.then(async (res) => {
|
|
186
|
+
await createAndSaveToFile({
|
|
187
|
+
prefix: `component-preset-${componentPresetToBackup}-`,
|
|
188
|
+
folder: "component-presets",
|
|
189
|
+
res,
|
|
190
|
+
});
|
|
191
|
+
})
|
|
192
|
+
.catch((err) => {
|
|
193
|
+
console.log(err);
|
|
194
|
+
Logger.error("error happened... :(");
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
break;
|
|
198
|
+
default:
|
|
199
|
+
console.log(`no command like that: ${command}`);
|
|
200
|
+
}
|
|
201
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const debug: () => Promise<void>;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import Logger from "../utils/logger.js";
|
|
2
|
+
import { unpackElements } from "../utils/main.js";
|
|
3
|
+
import storyblokConfig from "../config/config.js";
|
|
4
|
+
import { syncAllComponents, syncProvidedComponents } from "../api/migrate.js";
|
|
5
|
+
import { syncAllRoles, syncProvidedRoles } from "../api/roles.js";
|
|
6
|
+
import { syncAllDatasources, syncProvidedDatasources, } from "../api/datasources.js";
|
|
7
|
+
const SYNC_COMMANDS = {
|
|
8
|
+
components: "components",
|
|
9
|
+
roles: "roles",
|
|
10
|
+
datasources: "datasources",
|
|
11
|
+
};
|
|
12
|
+
export const sync = async (props) => {
|
|
13
|
+
const { input, flags } = props;
|
|
14
|
+
const command = input[1];
|
|
15
|
+
switch (command) {
|
|
16
|
+
case SYNC_COMMANDS.components:
|
|
17
|
+
Logger.warning(`sync components... with command: ${command}`);
|
|
18
|
+
if (flags["all"]) {
|
|
19
|
+
Logger.log(`Syncing ALL components with ${storyblokConfig.schemaFileExt} extension...`);
|
|
20
|
+
const presets = flags["presets"] || false;
|
|
21
|
+
syncAllComponents({ presets });
|
|
22
|
+
}
|
|
23
|
+
if (!flags["all"]) {
|
|
24
|
+
Logger.warning("Synchronizing PROVIDED componensdt...");
|
|
25
|
+
const componentsToSync = unpackElements(input);
|
|
26
|
+
syncProvidedComponents({
|
|
27
|
+
components: componentsToSync,
|
|
28
|
+
presets: Boolean(flags.presets),
|
|
29
|
+
packageName: flags.packageName,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
break;
|
|
33
|
+
case SYNC_COMMANDS.roles:
|
|
34
|
+
if (flags["all"]) {
|
|
35
|
+
Logger.log("Syncing all roles...");
|
|
36
|
+
syncAllRoles();
|
|
37
|
+
}
|
|
38
|
+
if (!flags["all"]) {
|
|
39
|
+
Logger.log("Syncing provided roles...");
|
|
40
|
+
const rolesToSync = unpackElements(input);
|
|
41
|
+
syncProvidedRoles({ roles: rolesToSync });
|
|
42
|
+
}
|
|
43
|
+
break;
|
|
44
|
+
case SYNC_COMMANDS.datasources:
|
|
45
|
+
if (flags["all"]) {
|
|
46
|
+
Logger.log("Syncing all datasources with extension...");
|
|
47
|
+
syncAllDatasources();
|
|
48
|
+
}
|
|
49
|
+
if (!flags["all"]) {
|
|
50
|
+
Logger.log("Syncing provided datasources with extension...");
|
|
51
|
+
const datasourcesToSync = unpackElements(input);
|
|
52
|
+
syncProvidedDatasources({ datasources: datasourcesToSync });
|
|
53
|
+
}
|
|
54
|
+
break;
|
|
55
|
+
default:
|
|
56
|
+
console.log(`no command like that: ${command}`);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface IStoryblokConfig {
|
|
2
|
+
storyblokComponentsLocalDirectory: string;
|
|
3
|
+
sbmigWorkingDirectory: string;
|
|
4
|
+
componentsDirectories: string[];
|
|
5
|
+
schemaFileExt: string;
|
|
6
|
+
datasourceExt: string;
|
|
7
|
+
rolesExt: string;
|
|
8
|
+
storyblokApiUrl: string;
|
|
9
|
+
oauthToken: string;
|
|
10
|
+
spaceId: string;
|
|
11
|
+
accessToken: string;
|
|
12
|
+
}
|
|
13
|
+
declare const _default: any;
|
|
14
|
+
export default _default;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
var _a, _b;
|
|
2
|
+
import path from "path";
|
|
3
|
+
import dotenv from "dotenv";
|
|
4
|
+
import Logger from "../utils/logger.js";
|
|
5
|
+
const getStoryblokConfigContent = (data) => {
|
|
6
|
+
return import(`${data.filePath}${data.ext}`)
|
|
7
|
+
.then((res) => {
|
|
8
|
+
Logger.success("Found storyblok.config.js!");
|
|
9
|
+
return res.default;
|
|
10
|
+
})
|
|
11
|
+
.catch(() => {
|
|
12
|
+
Logger.warning("Cannot find requested file with .js extension.");
|
|
13
|
+
Logger.log("Trying .mjs extension\n");
|
|
14
|
+
return import(`${data.filePath}.mjs`)
|
|
15
|
+
.then((res) => {
|
|
16
|
+
Logger.success("Found storyblok.config.mjs!");
|
|
17
|
+
return res.default;
|
|
18
|
+
})
|
|
19
|
+
.catch(() => {
|
|
20
|
+
Logger.error("Cannot find requested file with .mjs extension.");
|
|
21
|
+
Logger.log("Create storyblok.config.js or storyblok.config.mjs in your project. If u want to have custom configuration");
|
|
22
|
+
Logger.log("Using default configruration.");
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
dotenv.config();
|
|
27
|
+
const defaultConfig = {
|
|
28
|
+
storyblokComponentsLocalDirectory: "src/@storyblok-components",
|
|
29
|
+
sbmigWorkingDirectory: "sbmig",
|
|
30
|
+
componentsDirectories: ["src", "storyblok"],
|
|
31
|
+
schemaFileExt: "sb.js",
|
|
32
|
+
datasourceExt: "sb.datasource.js",
|
|
33
|
+
rolesExt: "sb.roles.js",
|
|
34
|
+
storyblokApiUrl: "https://api.storyblok.com/v1",
|
|
35
|
+
oauthToken: (_a = process.env["STORYBLOK_OAUTH_TOKEN"]) !== null && _a !== void 0 ? _a : "",
|
|
36
|
+
spaceId: (_b = process.env["STORYBLOK_SPACE_ID"]) !== null && _b !== void 0 ? _b : "",
|
|
37
|
+
accessToken: process.env["GATSBY_STORYBLOK_ACCESS_TOKEN"] ||
|
|
38
|
+
process.env["NEXT_PUBLIC_STORYBLOK_ACCESS_TOKEN"] ||
|
|
39
|
+
"",
|
|
40
|
+
};
|
|
41
|
+
const filePath = path.resolve(process.cwd(), "storyblok.config");
|
|
42
|
+
const customConfig = await getStoryblokConfigContent({
|
|
43
|
+
filePath,
|
|
44
|
+
ext: ".js",
|
|
45
|
+
});
|
|
46
|
+
export default {
|
|
47
|
+
...defaultConfig,
|
|
48
|
+
...customConfig,
|
|
49
|
+
};
|
package/dist/index.d.ts
ADDED
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: () => {
|
|
39
|
+
debug();
|
|
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);
|
|
@@ -43,7 +43,7 @@ export interface CompareResult {
|
|
|
43
43
|
external: OneComponent[];
|
|
44
44
|
}
|
|
45
45
|
declare type DiscoverResult = string[];
|
|
46
|
-
export declare const compare: (request: CompareRequest) =>
|
|
46
|
+
export declare const compare: (request: CompareRequest) => any;
|
|
47
47
|
export declare const discoverManyByPackageName: (request: DiscoverManyByPackageNameRequest) => DiscoverResult;
|
|
48
48
|
export declare const discoverOneByPackageName: (request: DiscoverOneByPackageNameRequest) => DiscoverResult;
|
|
49
49
|
export declare const discoverMany: (request: DiscoverManyRequest) => DiscoverResult;
|
|
@@ -54,10 +54,4 @@ export declare const discover: (request: DiscoverRequest) => DiscoverResult;
|
|
|
54
54
|
export declare const discoverManyStyles: (request: DiscoverManyRequest) => DiscoverResult;
|
|
55
55
|
export declare const discoverRoles: (request: DiscoverRequest) => DiscoverResult;
|
|
56
56
|
export declare const discoverManyRoles: (request: DiscoverManyRequest) => DiscoverResult;
|
|
57
|
-
export declare const getFilesContent: (data: {
|
|
58
|
-
files: string[];
|
|
59
|
-
}) => any[];
|
|
60
|
-
export declare const getFileContent: (data: {
|
|
61
|
-
file: string;
|
|
62
|
-
}) => any;
|
|
63
57
|
export {};
|