sb-mig 2.9.3 → 3.1.2
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 +51 -27
- package/dist/index.js +52 -0
- package/package.json +40 -57
- package/CHANGELOG.md +0 -996
- 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 -21
- 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/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 | [unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown]>;
|
|
@@ -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 {};
|
package/lib/api/migrate.js
DELETED
|
@@ -1,220 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.syncAllComponents = exports.sync2AllComponents = exports.syncProvidedComponents = exports.syncComponents = exports.sync2Components = void 0;
|
|
4
|
-
const logger_1 = require("../utils/logger");
|
|
5
|
-
const discover_1 = require("../utils/discover");
|
|
6
|
-
const config_1 = require("../config/config");
|
|
7
|
-
const components_1 = require("./components");
|
|
8
|
-
const mutateComponents_1 = require("./mutateComponents");
|
|
9
|
-
const discover2_1 = require("../utils/discover2");
|
|
10
|
-
const { componentDirectory } = config_1.default;
|
|
11
|
-
const _uniqueValuesFrom = (array) => [...new Set(array)];
|
|
12
|
-
const _checkAndPrepareGroups = async (groupsToCheck) => {
|
|
13
|
-
const componentsGroups = await (0, components_1.getAllComponentsGroups)();
|
|
14
|
-
const groupExist = (groupName) => componentsGroups.component_groups.find((group) => group.name === groupName);
|
|
15
|
-
groupsToCheck.forEach(async (groupName) => {
|
|
16
|
-
if (!groupExist(groupName)) {
|
|
17
|
-
await (0, components_1.createComponentsGroup)(groupName);
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
};
|
|
21
|
-
const _resolveGroups = async (component, existedGroups, remoteComponentsGroups) => {
|
|
22
|
-
if (!component.component_group_name) {
|
|
23
|
-
return { ...component, component_group_uuid: null };
|
|
24
|
-
}
|
|
25
|
-
const componentsGroup = existedGroups.find((group) => component.component_group_name === group);
|
|
26
|
-
if (componentsGroup) {
|
|
27
|
-
const component_group_uuid = remoteComponentsGroups.component_groups.find((remoteComponentsGroup) => remoteComponentsGroup.name === componentsGroup).uuid;
|
|
28
|
-
return { ...component, component_group_uuid };
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
const sync2Components = async ({ specifiedComponents, presets }) => {
|
|
32
|
-
logger_1.default.log('sync2Components: ');
|
|
33
|
-
const specifiedComponentsContent = specifiedComponents.map(component => (0, discover2_1.getFileContent)({ file: component.path }));
|
|
34
|
-
const groupsToCheck = _uniqueValuesFrom(specifiedComponentsContent
|
|
35
|
-
.filter(component => component.component_group_name)
|
|
36
|
-
.map(component => component.component_group_name));
|
|
37
|
-
await _checkAndPrepareGroups(groupsToCheck);
|
|
38
|
-
// after checkAndPrepareGroups remoteComponents will have synced groups with local groups
|
|
39
|
-
// updates of the groups had to happen before creation of them, cause creation/updates of components
|
|
40
|
-
// happens async, so if one component will have the same group, as other one
|
|
41
|
-
// it will be race of condition kinda issue - we will never now, if the group for current processed component
|
|
42
|
-
// already exist or is being created by other request
|
|
43
|
-
const remoteComponents = await (0, components_1.getAllComponents)();
|
|
44
|
-
const componentsToUpdate = [];
|
|
45
|
-
const componentsToCreate = [];
|
|
46
|
-
for (const component of specifiedComponentsContent) {
|
|
47
|
-
const shouldBeUpdated = remoteComponents.components.find((remoteComponent) => component.name === remoteComponent.name);
|
|
48
|
-
if (shouldBeUpdated) {
|
|
49
|
-
componentsToUpdate.push({ id: shouldBeUpdated.id, ...component });
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
componentsToCreate.push(component);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
const componentsGroups = await (0, components_1.getAllComponentsGroups)();
|
|
56
|
-
componentsToUpdate.length > 0 && Promise.all(componentsToUpdate
|
|
57
|
-
.map(component => _resolveGroups(component, groupsToCheck, componentsGroups))).then(res => {
|
|
58
|
-
logger_1.default.log('Components to update after check: ');
|
|
59
|
-
res.map(component => {
|
|
60
|
-
logger_1.default.warning(` ${component.name}`);
|
|
61
|
-
(0, mutateComponents_1.updateComponent)(component, presets);
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
componentsToCreate.length > 0 && Promise.all(componentsToCreate
|
|
65
|
-
.map(component => _resolveGroups(component, groupsToCheck, componentsGroups))).then(res => {
|
|
66
|
-
logger_1.default.log('Components to create after check: ');
|
|
67
|
-
res.map(component => {
|
|
68
|
-
logger_1.default.warning(` ${component.name}`);
|
|
69
|
-
(0, mutateComponents_1.createComponent)(component, presets);
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
};
|
|
73
|
-
exports.sync2Components = sync2Components;
|
|
74
|
-
const syncComponents = async (specifiedComponents, ext, presets, packageName, local) => {
|
|
75
|
-
if (packageName) {
|
|
76
|
-
specifiedComponents = (0, discover_1.findComponentsByPackageName)(ext, specifiedComponents, local);
|
|
77
|
-
}
|
|
78
|
-
logger_1.default.log(`Trying to sync specified components from '${componentDirectory}'`);
|
|
79
|
-
let localComponents;
|
|
80
|
-
if (ext) {
|
|
81
|
-
localComponents = (0, discover_1.findComponentsWithExt)(ext);
|
|
82
|
-
}
|
|
83
|
-
else {
|
|
84
|
-
localComponents = (0, discover_1.findComponents)(componentDirectory);
|
|
85
|
-
}
|
|
86
|
-
const groupsToCheck = _uniqueValuesFrom(localComponents
|
|
87
|
-
.filter(component => component.component_group_name)
|
|
88
|
-
.map(component => component.component_group_name));
|
|
89
|
-
await _checkAndPrepareGroups(groupsToCheck);
|
|
90
|
-
// after checkAndPrepareGroups remoteComponents will have synced groups with local groups
|
|
91
|
-
// updates of the groups had to happen before creation of them, cause creation/updates of components
|
|
92
|
-
// happens async, so if one component will have the same group, as other one
|
|
93
|
-
// it will be race of condition kinda issue - we will never now, if the group for current processed component
|
|
94
|
-
// already exist or is being created by other request
|
|
95
|
-
const remoteComponents = await (0, components_1.getAllComponents)();
|
|
96
|
-
const componentsToUpdate = [];
|
|
97
|
-
const componentsToCreate = [];
|
|
98
|
-
for (const component of localComponents) {
|
|
99
|
-
const shouldBeUpdated = remoteComponents.components.find((remoteComponent) => component.name === remoteComponent.name);
|
|
100
|
-
if (shouldBeUpdated) {
|
|
101
|
-
componentsToUpdate.push({ id: shouldBeUpdated.id, ...component });
|
|
102
|
-
}
|
|
103
|
-
else {
|
|
104
|
-
componentsToCreate.push(component);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
const componentsGroups = await (0, components_1.getAllComponentsGroups)();
|
|
108
|
-
Promise.all(componentsToUpdate
|
|
109
|
-
.filter(c => {
|
|
110
|
-
const temp = specifiedComponents.find((component) => component === c.name);
|
|
111
|
-
if (temp) {
|
|
112
|
-
specifiedComponents = specifiedComponents.filter((component) => component !== temp);
|
|
113
|
-
}
|
|
114
|
-
return temp;
|
|
115
|
-
})
|
|
116
|
-
.map(component => _resolveGroups(component, groupsToCheck, componentsGroups))).then(res => {
|
|
117
|
-
logger_1.default.log('Components to update after check: ');
|
|
118
|
-
res.map(component => {
|
|
119
|
-
logger_1.default.warning(` ${component.name}`);
|
|
120
|
-
(0, mutateComponents_1.updateComponent)(component, presets);
|
|
121
|
-
});
|
|
122
|
-
});
|
|
123
|
-
Promise.all(componentsToCreate
|
|
124
|
-
.filter(c => {
|
|
125
|
-
const temp = specifiedComponents.find((component) => component === c.name);
|
|
126
|
-
return temp;
|
|
127
|
-
})
|
|
128
|
-
.map(component => _resolveGroups(component, groupsToCheck, componentsGroups))).then(res => {
|
|
129
|
-
logger_1.default.log('Components to create after check: ');
|
|
130
|
-
res.map(component => {
|
|
131
|
-
logger_1.default.warning(` ${component.name}`);
|
|
132
|
-
(0, mutateComponents_1.createComponent)(component, presets);
|
|
133
|
-
});
|
|
134
|
-
});
|
|
135
|
-
};
|
|
136
|
-
exports.syncComponents = syncComponents;
|
|
137
|
-
const syncProvidedComponents = ({ components, presets, packageName }) => {
|
|
138
|
-
if (!packageName) {
|
|
139
|
-
// #1: discover all external .sb.js files
|
|
140
|
-
const allLocalSbComponentsSchemaFiles = (0, discover2_1.discoverMany)({
|
|
141
|
-
scope: discover2_1.SCOPE.local,
|
|
142
|
-
type: discover2_1.LOOKUP_TYPE.fileName,
|
|
143
|
-
fileNames: components,
|
|
144
|
-
});
|
|
145
|
-
// #2: discover all local .sb.js files
|
|
146
|
-
const allExternalSbComponentsSchemaFiles = (0, discover2_1.discoverMany)({
|
|
147
|
-
scope: discover2_1.SCOPE.external,
|
|
148
|
-
type: discover2_1.LOOKUP_TYPE.fileName,
|
|
149
|
-
fileNames: components,
|
|
150
|
-
});
|
|
151
|
-
// #3: compare results, prefer local ones (so we have to create final external paths array and local array of things to sync from where)
|
|
152
|
-
const { local, external } = (0, discover2_1.compare)({
|
|
153
|
-
local: allLocalSbComponentsSchemaFiles,
|
|
154
|
-
external: allExternalSbComponentsSchemaFiles,
|
|
155
|
-
});
|
|
156
|
-
// #4: sync - do all stuff already done (groups resolving, and so on)
|
|
157
|
-
(0, exports.sync2Components)({
|
|
158
|
-
presets,
|
|
159
|
-
specifiedComponents: [...local, ...external],
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
else {
|
|
163
|
-
// implement discovering and syncrhonizing with packageName
|
|
164
|
-
// #1: discover all external .sb.js files
|
|
165
|
-
const allLocalSbComponentsSchemaFiles = (0, discover2_1.discoverManyByPackageName)({
|
|
166
|
-
scope: discover2_1.SCOPE.local,
|
|
167
|
-
packageNames: components,
|
|
168
|
-
});
|
|
169
|
-
// #2: discover all local .sb.js files
|
|
170
|
-
const allExternalSbComponentsSchemaFiles = (0, discover2_1.discoverManyByPackageName)({
|
|
171
|
-
scope: discover2_1.SCOPE.external,
|
|
172
|
-
packageNames: components,
|
|
173
|
-
});
|
|
174
|
-
// #3: compare results, prefer local ones (so we have to create final external paths array and local array of things to sync from where)
|
|
175
|
-
const { local, external } = (0, discover2_1.compare)({
|
|
176
|
-
local: allLocalSbComponentsSchemaFiles,
|
|
177
|
-
external: allExternalSbComponentsSchemaFiles,
|
|
178
|
-
});
|
|
179
|
-
// #4: sync - do all stuff already done (groups resolving, and so on)
|
|
180
|
-
(0, exports.sync2Components)({
|
|
181
|
-
presets,
|
|
182
|
-
specifiedComponents: [...local, ...external],
|
|
183
|
-
});
|
|
184
|
-
}
|
|
185
|
-
};
|
|
186
|
-
exports.syncProvidedComponents = syncProvidedComponents;
|
|
187
|
-
const sync2AllComponents = ({ presets }) => {
|
|
188
|
-
// #1: discover all external .sb.js files
|
|
189
|
-
const allLocalSbComponentsSchemaFiles = (0, discover2_1.discover)({
|
|
190
|
-
scope: discover2_1.SCOPE.local,
|
|
191
|
-
type: discover2_1.LOOKUP_TYPE.fileName,
|
|
192
|
-
});
|
|
193
|
-
// #2: discover all local .sb.js files
|
|
194
|
-
const allExternalSbComponentsSchemaFiles = (0, discover2_1.discover)({
|
|
195
|
-
scope: discover2_1.SCOPE.external,
|
|
196
|
-
type: discover2_1.LOOKUP_TYPE.fileName,
|
|
197
|
-
});
|
|
198
|
-
// #3: compare results, prefare local ones (so we have to create final external paths array and local array of things to sync from where)
|
|
199
|
-
const { local, external } = (0, discover2_1.compare)({
|
|
200
|
-
local: allLocalSbComponentsSchemaFiles,
|
|
201
|
-
external: allExternalSbComponentsSchemaFiles,
|
|
202
|
-
});
|
|
203
|
-
// #4: sync - do all stuff already done (groups resolving, and so on)
|
|
204
|
-
(0, exports.sync2Components)({
|
|
205
|
-
presets,
|
|
206
|
-
specifiedComponents: [...local, ...external],
|
|
207
|
-
});
|
|
208
|
-
};
|
|
209
|
-
exports.sync2AllComponents = sync2AllComponents;
|
|
210
|
-
const syncAllComponents = (ext, presets) => {
|
|
211
|
-
let specifiedComponents;
|
|
212
|
-
if (ext) {
|
|
213
|
-
specifiedComponents = (0, discover_1.findComponentsWithExt)(ext).map(component => component.name);
|
|
214
|
-
}
|
|
215
|
-
else {
|
|
216
|
-
specifiedComponents = (0, discover_1.findComponents)(componentDirectory).map((component) => component.name);
|
|
217
|
-
}
|
|
218
|
-
(0, exports.syncComponents)(specifiedComponents, ext, presets, false);
|
|
219
|
-
};
|
|
220
|
-
exports.syncAllComponents = syncAllComponents;
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createComponent = exports.updateComponent = void 0;
|
|
4
|
-
const logger_1 = require("../utils/logger");
|
|
5
|
-
const config_1 = require("../config/config");
|
|
6
|
-
const apiConfig_1 = require("./apiConfig");
|
|
7
|
-
const resolvePresets_1 = require("./resolvePresets");
|
|
8
|
-
const { spaceId } = config_1.default;
|
|
9
|
-
// UPDATE
|
|
10
|
-
const updateComponent = (component, presets) => {
|
|
11
|
-
logger_1.default.log(`Trying to update '${component.name}' with id ${component.id}`);
|
|
12
|
-
const componentWithPresets = component;
|
|
13
|
-
const { all_presets, ...componentWithoutPresets } = componentWithPresets;
|
|
14
|
-
apiConfig_1.sbApi
|
|
15
|
-
.put(`spaces/${spaceId}/components/${component.id}`, {
|
|
16
|
-
component: componentWithoutPresets,
|
|
17
|
-
})
|
|
18
|
-
.then(res => {
|
|
19
|
-
logger_1.default.success(`Component '${component.name}' has been updated.`);
|
|
20
|
-
if (presets) {
|
|
21
|
-
(0, resolvePresets_1.default)(res, all_presets, component);
|
|
22
|
-
}
|
|
23
|
-
})
|
|
24
|
-
.catch(err => {
|
|
25
|
-
logger_1.default.error('error happened... :(');
|
|
26
|
-
console.log(`${err.message} in migration of ${component.name} in updateComponent function`);
|
|
27
|
-
});
|
|
28
|
-
};
|
|
29
|
-
exports.updateComponent = updateComponent;
|
|
30
|
-
// CREATE
|
|
31
|
-
const createComponent = (component, presets) => {
|
|
32
|
-
logger_1.default.log(`Trying to create '${component.name}'`);
|
|
33
|
-
const componentWithPresets = component;
|
|
34
|
-
const { all_presets, ...componentWithoutPresets } = componentWithPresets;
|
|
35
|
-
apiConfig_1.sbApi
|
|
36
|
-
.post(`spaces/${spaceId}/components/`, {
|
|
37
|
-
component: componentWithoutPresets,
|
|
38
|
-
})
|
|
39
|
-
.then(res => {
|
|
40
|
-
logger_1.default.success(`Component '${component.name}' has been created.`);
|
|
41
|
-
if (presets) {
|
|
42
|
-
(0, resolvePresets_1.default)(res, all_presets, component);
|
|
43
|
-
}
|
|
44
|
-
})
|
|
45
|
-
.catch(err => {
|
|
46
|
-
logger_1.default.error('error happened... :(');
|
|
47
|
-
console.log(`${err.message} in migration of ${component.name} in createComponent function`);
|
|
48
|
-
});
|
|
49
|
-
};
|
|
50
|
-
exports.createComponent = createComponent;
|
package/lib/api/presets.d.ts
DELETED