sb-mig 2.9.13 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -5
- package/dist/index.js +52 -0
- package/package.json +39 -62
- package/bin/run +0 -5
- package/bin/run.cmd +0 -3
- package/lib/api/apiConfig.d.ts +0 -2
- package/lib/api/apiConfig.js +0 -9
- package/lib/api/componentPresets.d.ts +0 -1
- package/lib/api/componentPresets.js +0 -22
- package/lib/api/components.d.ts +0 -5
- package/lib/api/components.js +0 -71
- package/lib/api/datasources.d.ts +0 -24
- package/lib/api/datasources.js +0 -193
- package/lib/api/migrate.d.ts +0 -19
- package/lib/api/migrate.js +0 -220
- package/lib/api/mutateComponents.d.ts +0 -2
- package/lib/api/mutateComponents.js +0 -50
- package/lib/api/presets.d.ts +0 -4
- package/lib/api/presets.js +0 -59
- package/lib/api/resolvePresets.d.ts +0 -2
- package/lib/api/resolvePresets.js +0 -40
- package/lib/api/roles.d.ts +0 -14
- package/lib/api/roles.js +0 -133
- package/lib/api/spaces.d.ts +0 -2
- package/lib/api/spaces.js +0 -29
- package/lib/commands/backup.d.ts +0 -22
- package/lib/commands/backup.js +0 -217
- package/lib/commands/debug.d.ts +0 -9
- package/lib/commands/debug.js +0 -27
- package/lib/commands/sync.d.ts +0 -26
- package/lib/commands/sync.js +0 -93
- package/lib/config/StoryblokComponentsConfig.d.ts +0 -68
- package/lib/config/StoryblokComponentsConfig.js +0 -220
- package/lib/config/config.d.ts +0 -37
- package/lib/config/config.js +0 -36
- package/lib/core.d.ts +0 -16
- package/lib/core.js +0 -75
- package/lib/index.d.ts +0 -1
- package/lib/index.js +0 -5
- package/lib/types/storyblokTypes.d.ts +0 -171
- package/lib/types/storyblokTypes.js +0 -3
- package/lib/utils/discover.d.ts +0 -4
- package/lib/utils/discover.js +0 -96
- package/lib/utils/discover2.d.ts +0 -63
- package/lib/utils/discover2.js +0 -424
- package/lib/utils/files.d.ts +0 -6
- package/lib/utils/files.js +0 -54
- package/lib/utils/logger.d.ts +0 -11
- package/lib/utils/logger.js +0 -30
- package/lib/utils/others.d.ts +0 -1
- package/lib/utils/others.js +0 -5
- package/oclif.manifest.json +0 -1
package/lib/commands/backup.js
DELETED
|
@@ -1,217 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const command_1 = require("@oclif/command");
|
|
4
|
-
const core_1 = require("../core");
|
|
5
|
-
const config_1 = require("../config/config");
|
|
6
|
-
const components_1 = require("../api/components");
|
|
7
|
-
const datasources_1 = require("../api/datasources");
|
|
8
|
-
const componentPresets_1 = require("../api/componentPresets");
|
|
9
|
-
const presets_1 = require("../api/presets");
|
|
10
|
-
const logger_1 = require("../utils/logger");
|
|
11
|
-
const files_1 = require("../utils/files");
|
|
12
|
-
const others_1 = require("../utils/others");
|
|
13
|
-
const roles_1 = require("../api/roles");
|
|
14
|
-
class Backup extends core_1.default {
|
|
15
|
-
// static strict = false;
|
|
16
|
-
async run() {
|
|
17
|
-
const { args, flags, argv } = this.parse(Backup);
|
|
18
|
-
// Backup one role as json file
|
|
19
|
-
if (flags.oneRole) {
|
|
20
|
-
console.log('oneRole argument: ', flags.oneRole);
|
|
21
|
-
return (0, roles_1.getRole)(flags.oneRole).then(async (res) => {
|
|
22
|
-
if (res) {
|
|
23
|
-
const datestamp = new Date();
|
|
24
|
-
const filename = `role-${flags.oneRole}-${(0, others_1.generateDatestamp)(datestamp)}`;
|
|
25
|
-
await (0, files_1.createDir)(`${config_1.default.sbmigWorkingDirectory}/roles/`);
|
|
26
|
-
await (0, files_1.createJsonFile)(JSON.stringify(res, undefined, 2), `${config_1.default.sbmigWorkingDirectory}/roles/${filename}.json`);
|
|
27
|
-
logger_1.default.success(`Role for ${flags.oneRole} written to a file: ${filename}`);
|
|
28
|
-
}
|
|
29
|
-
})
|
|
30
|
-
.catch((err) => {
|
|
31
|
-
console.log(err);
|
|
32
|
-
this.error('error happened... :(');
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
// Backup all roles and permission as json file
|
|
36
|
-
if (flags.allRoles) {
|
|
37
|
-
return (0, roles_1.getAllRoles)()
|
|
38
|
-
.then(async (res) => {
|
|
39
|
-
const datestamp = new Date();
|
|
40
|
-
const filename = `all-roles-${(0, others_1.generateDatestamp)(datestamp)}`;
|
|
41
|
-
await (0, files_1.createDir)(`${config_1.default.sbmigWorkingDirectory}/roles/`);
|
|
42
|
-
await (0, files_1.createJsonFile)(JSON.stringify(res, undefined, 2), `${config_1.default.sbmigWorkingDirectory}/roles/${filename}.json`);
|
|
43
|
-
logger_1.default.success(`All roles written to a file: ${filename}`);
|
|
44
|
-
return true;
|
|
45
|
-
})
|
|
46
|
-
.catch((err) => {
|
|
47
|
-
console.log(err);
|
|
48
|
-
this.error('error happened... :(');
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
// Backup all components as json file
|
|
52
|
-
if (flags.allComponents) {
|
|
53
|
-
return (0, components_1.getAllComponents)()
|
|
54
|
-
.then(async (res) => {
|
|
55
|
-
const datestamp = new Date();
|
|
56
|
-
const filename = `all-components-${(0, others_1.generateDatestamp)(datestamp)}`;
|
|
57
|
-
await (0, files_1.createDir)(`${config_1.default.sbmigWorkingDirectory}/components/`);
|
|
58
|
-
await (0, files_1.createJsonFile)(JSON.stringify(res, undefined, 2), `${config_1.default.sbmigWorkingDirectory}/components/${filename}.json`);
|
|
59
|
-
logger_1.default.success(`All components written to a file: ${filename}`);
|
|
60
|
-
return true;
|
|
61
|
-
})
|
|
62
|
-
.catch((err) => {
|
|
63
|
-
console.log(err);
|
|
64
|
-
this.error('error happened... :(');
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
// Backup one component as json file
|
|
68
|
-
if (flags.oneComponent) {
|
|
69
|
-
return (0, components_1.getComponent)(flags.oneComponent).then(async (res) => {
|
|
70
|
-
if (res) {
|
|
71
|
-
const datestamp = new Date();
|
|
72
|
-
const filename = `component-${flags.oneComponent}-${(0, others_1.generateDatestamp)(datestamp)}`;
|
|
73
|
-
await (0, files_1.createDir)(`${config_1.default.sbmigWorkingDirectory}/components/`);
|
|
74
|
-
await (0, files_1.createJsonFile)(JSON.stringify(res, undefined, 2), `${config_1.default.sbmigWorkingDirectory}/components/${filename}.json`);
|
|
75
|
-
logger_1.default.success(`Component for ${flags.oneComponent} written to a file: ${filename}`);
|
|
76
|
-
}
|
|
77
|
-
})
|
|
78
|
-
.catch((err) => {
|
|
79
|
-
console.log(err);
|
|
80
|
-
this.error('error happened... :(');
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
if (flags.allComponentsGroups) {
|
|
84
|
-
return (0, components_1.getAllComponentsGroups)().then(async (res) => {
|
|
85
|
-
const datestamp = new Date();
|
|
86
|
-
const filename = `all-component_groups-${(0, others_1.generateDatestamp)(datestamp)}`;
|
|
87
|
-
await (0, files_1.createDir)(`${config_1.default.sbmigWorkingDirectory}/component_groups/`);
|
|
88
|
-
await (0, files_1.createJsonFile)(JSON.stringify(res, undefined, 2), `${config_1.default.sbmigWorkingDirectory}/component_groups/${filename}.json`);
|
|
89
|
-
logger_1.default.success(`All groups written to a file: ${filename}`);
|
|
90
|
-
})
|
|
91
|
-
.catch((err) => {
|
|
92
|
-
console.log(err);
|
|
93
|
-
this.error('error happened... :(');
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
if (flags.oneComponentsGroup) {
|
|
97
|
-
return (0, components_1.getComponentsGroup)(flags.oneComponentsGroup).then(async (res) => {
|
|
98
|
-
if (res) {
|
|
99
|
-
const datestamp = new Date();
|
|
100
|
-
const filename = `components_group-${flags.oneComponentsGroup}-${(0, others_1.generateDatestamp)(datestamp)}`;
|
|
101
|
-
await (0, files_1.createDir)(`${config_1.default.sbmigWorkingDirectory}/component_groups/`);
|
|
102
|
-
await (0, files_1.createJsonFile)(JSON.stringify(res, undefined, 2), `${config_1.default.sbmigWorkingDirectory}/component_groups/${filename}.json`);
|
|
103
|
-
logger_1.default.success(`Components group for ${flags.oneComponentsGroup} written to a file: ${filename}`);
|
|
104
|
-
}
|
|
105
|
-
})
|
|
106
|
-
.catch((err) => {
|
|
107
|
-
console.log(err);
|
|
108
|
-
this.error('error happened... :(');
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
if (flags.allDatasources) {
|
|
112
|
-
return (0, datasources_1.getAllDatasources)().then(async (res) => {
|
|
113
|
-
const datestamp = new Date();
|
|
114
|
-
const filename = `all-datasources-${(0, others_1.generateDatestamp)(datestamp)}`;
|
|
115
|
-
await (0, files_1.createDir)(`${config_1.default.sbmigWorkingDirectory}/datasources/`);
|
|
116
|
-
await (0, files_1.createJsonFile)(JSON.stringify(res, undefined, 2), `${config_1.default.sbmigWorkingDirectory}/datasources/${filename}.json`);
|
|
117
|
-
logger_1.default.success(`All datasources written to a file: ${filename}`);
|
|
118
|
-
})
|
|
119
|
-
.catch((err) => {
|
|
120
|
-
console.log(err);
|
|
121
|
-
this.error('error happened... :(');
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
if (flags.oneDatasource) {
|
|
125
|
-
return (0, datasources_1.getDatasource)(flags.oneDatasource).then(async (res) => {
|
|
126
|
-
if (res) {
|
|
127
|
-
const datestamp = new Date();
|
|
128
|
-
const filename = `datasource-${flags.oneDatasource}-${(0, others_1.generateDatestamp)(datestamp)}`;
|
|
129
|
-
await (0, files_1.createDir)(`${config_1.default.sbmigWorkingDirectory}/datasources/`);
|
|
130
|
-
await (0, files_1.createJsonFile)(JSON.stringify(res, undefined, 2), `${config_1.default.sbmigWorkingDirectory}/datasources/${filename}.json`);
|
|
131
|
-
logger_1.default.success(`Datasource for ${flags.oneDatasource} written to a file: ${filename}`);
|
|
132
|
-
}
|
|
133
|
-
})
|
|
134
|
-
.catch((err) => {
|
|
135
|
-
console.log(err);
|
|
136
|
-
this.error('error happened... :(');
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
if (flags.datasourceEntries) {
|
|
140
|
-
return (0, datasources_1.getDatasourceEntries)(flags.datasourceEntries).then(async (res) => {
|
|
141
|
-
if (res) {
|
|
142
|
-
const datestamp = new Date();
|
|
143
|
-
const filename = `datasource-entries-${flags.datasourceEntries}-${(0, others_1.generateDatestamp)(datestamp)}`;
|
|
144
|
-
await (0, files_1.createDir)(`${config_1.default.sbmigWorkingDirectory}/datasources/`);
|
|
145
|
-
await (0, files_1.createJsonFile)(JSON.stringify(res, undefined, 2), `${config_1.default.sbmigWorkingDirectory}/datasources/${filename}.json`);
|
|
146
|
-
logger_1.default.success(`Datasource entries for ${flags.datasourceEntries} written to a file: ${filename}`);
|
|
147
|
-
}
|
|
148
|
-
})
|
|
149
|
-
.catch((err) => {
|
|
150
|
-
console.log(err);
|
|
151
|
-
this.error('error happened... :(');
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
if (flags.oneComponentPresets) {
|
|
155
|
-
return (0, componentPresets_1.getComponentPresets)(flags.oneComponentPresets).then(async (res) => {
|
|
156
|
-
if (res) {
|
|
157
|
-
const datestamp = new Date();
|
|
158
|
-
const filename = `component-${flags.oneComponentPresets}-${(0, others_1.generateDatestamp)(datestamp)}`;
|
|
159
|
-
await (0, files_1.createDir)(`${config_1.default.sbmigWorkingDirectory}/component-presets/`);
|
|
160
|
-
await (0, files_1.createJsonFile)(JSON.stringify(res, undefined, 2), `${config_1.default.sbmigWorkingDirectory}/component-presets/${filename}.json`);
|
|
161
|
-
logger_1.default.success(`Presets for ${flags.oneComponentPresets} written to a file: ${filename}`);
|
|
162
|
-
}
|
|
163
|
-
})
|
|
164
|
-
.catch((err) => {
|
|
165
|
-
console.log(err);
|
|
166
|
-
this.error('error happened... :(');
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
if (flags.allPresets) {
|
|
170
|
-
return (0, presets_1.getAllPresets)().then(async (res) => {
|
|
171
|
-
const datestamp = new Date();
|
|
172
|
-
const filename = `all-presets-${(0, others_1.generateDatestamp)(datestamp)}`;
|
|
173
|
-
await (0, files_1.createDir)(`${config_1.default.sbmigWorkingDirectory}/presets/`);
|
|
174
|
-
await (0, files_1.createJsonFile)(JSON.stringify(res, undefined, 2), `${config_1.default.sbmigWorkingDirectory}/presets/${filename}.json`);
|
|
175
|
-
logger_1.default.success(`All presets written to a file: ${filename}`);
|
|
176
|
-
})
|
|
177
|
-
.catch((err) => {
|
|
178
|
-
console.log(err);
|
|
179
|
-
this.error('error happened... :(');
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
if (flags.onePreset) {
|
|
183
|
-
return (0, presets_1.getPreset)(flags.onePreset).then(async (res) => {
|
|
184
|
-
if (res) {
|
|
185
|
-
const datestamp = new Date();
|
|
186
|
-
const filename = `preset-${flags.onePreset}-${(0, others_1.generateDatestamp)(datestamp)}`;
|
|
187
|
-
await (0, files_1.createDir)(`${config_1.default.sbmigWorkingDirectory}/presets/`);
|
|
188
|
-
await (0, files_1.createJsonFile)(JSON.stringify(res, undefined, 2), `${config_1.default.sbmigWorkingDirectory}/presets/${filename}.json`);
|
|
189
|
-
logger_1.default.success(`Preset for '${flags.onePreset}' have been written to a file: ${filename}`);
|
|
190
|
-
}
|
|
191
|
-
})
|
|
192
|
-
.catch((err) => {
|
|
193
|
-
console.log(err);
|
|
194
|
-
this.error('error happened... :(');
|
|
195
|
-
});
|
|
196
|
-
}
|
|
197
|
-
this.exit();
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
exports.default = Backup;
|
|
201
|
-
Backup.description = 'Command for backing up anything related to Storyblok';
|
|
202
|
-
Backup.flags = {
|
|
203
|
-
help: command_1.flags.help({ char: 'h' }),
|
|
204
|
-
allComponents: command_1.flags.boolean({ char: 'a', description: 'Backup all components.' }),
|
|
205
|
-
oneComponent: command_1.flags.string({ char: 'o', description: 'Backup one component by name.' }),
|
|
206
|
-
allComponentsGroups: command_1.flags.boolean({ char: 'g', description: 'Backup all components groups.' }),
|
|
207
|
-
oneComponentsGroup: command_1.flags.string({ char: 'f', description: 'Backup one components group by name.' }),
|
|
208
|
-
oneComponentPresets: command_1.flags.string({ char: 'p', description: 'Backup all presets for one component' }),
|
|
209
|
-
allPresets: command_1.flags.boolean({ char: 'l', description: 'Backup all presets.' }),
|
|
210
|
-
onePreset: command_1.flags.string({ char: 'i', description: 'Backup one preset by id.' }),
|
|
211
|
-
allDatasources: command_1.flags.boolean({ char: 'd', description: 'Backup all datasources.' }),
|
|
212
|
-
oneDatasource: command_1.flags.string({ char: 'x', description: 'Backup one datasource by name.' }),
|
|
213
|
-
datasourceEntries: command_1.flags.string({ char: 'e', description: 'Backup one datasource entries by datasource name.' }),
|
|
214
|
-
allRoles: command_1.flags.boolean({ char: 'R', description: 'Backup all roles and permissions.' }),
|
|
215
|
-
oneRole: command_1.flags.string({ char: 'r', description: 'Backup one role by name.' }),
|
|
216
|
-
};
|
|
217
|
-
Backup.args = [];
|
package/lib/commands/debug.d.ts
DELETED
package/lib/commands/debug.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const command_1 = require("@oclif/command");
|
|
4
|
-
const core_1 = require("../core");
|
|
5
|
-
// TODO: implement --verbose flag to be available in every command
|
|
6
|
-
class Debug extends core_1.default {
|
|
7
|
-
async run() {
|
|
8
|
-
// const {} = this.parse(Debug)
|
|
9
|
-
const config = this.storyblokConfig();
|
|
10
|
-
const componentsConfig = this.storyblokComponentsConfig().getAllData();
|
|
11
|
-
// eslint-disable-next-line no-console
|
|
12
|
-
console.log('Thius are changes!');
|
|
13
|
-
// eslint-disable-next-line no-console
|
|
14
|
-
console.log('storyblok.config.js: ', config, '\n');
|
|
15
|
-
// eslint-disable-next-line no-console
|
|
16
|
-
console.log('storyblok.components.lock.js: ', componentsConfig);
|
|
17
|
-
const test = '2';
|
|
18
|
-
// eslint-disable-next-line no-console
|
|
19
|
-
console.log(test);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
exports.default = Debug;
|
|
23
|
-
Debug.description = 'Output extra debugging';
|
|
24
|
-
Debug.flags = {
|
|
25
|
-
help: command_1.flags.help({ char: 'h' }),
|
|
26
|
-
};
|
|
27
|
-
Debug.args = [];
|
package/lib/commands/sync.d.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import Command from '../core';
|
|
2
|
-
export default class Sync extends Command {
|
|
3
|
-
static description: string;
|
|
4
|
-
static examples: string[];
|
|
5
|
-
static flags: {
|
|
6
|
-
help: import("@oclif/parser/lib/flags").IBooleanFlag<void>;
|
|
7
|
-
all: import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
|
|
8
|
-
ext: import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
|
|
9
|
-
packageName: import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
|
|
10
|
-
presets: import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
|
|
11
|
-
lock: import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
|
|
12
|
-
};
|
|
13
|
-
static strict: boolean;
|
|
14
|
-
static args: ({
|
|
15
|
-
name: string;
|
|
16
|
-
description: string;
|
|
17
|
-
options: string[];
|
|
18
|
-
required: boolean;
|
|
19
|
-
} | {
|
|
20
|
-
name: string;
|
|
21
|
-
description: string;
|
|
22
|
-
options?: undefined;
|
|
23
|
-
required?: undefined;
|
|
24
|
-
})[];
|
|
25
|
-
run(): Promise<void>;
|
|
26
|
-
}
|
package/lib/commands/sync.js
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const command_1 = require("@oclif/command");
|
|
4
|
-
const core_1 = require("../core");
|
|
5
|
-
const config_1 = require("../config/config");
|
|
6
|
-
const logger_1 = require("../utils/logger");
|
|
7
|
-
const migrate_1 = require("../api/migrate");
|
|
8
|
-
const datasources_1 = require("../api/datasources");
|
|
9
|
-
const roles_1 = require("../api/roles");
|
|
10
|
-
class Sync extends core_1.default {
|
|
11
|
-
async run() {
|
|
12
|
-
const { argv, args, flags } = this.parse(Sync);
|
|
13
|
-
const components = argv.splice(1, argv.length);
|
|
14
|
-
if (args.type === 'roles' && flags.all && flags.ext) {
|
|
15
|
-
logger_1.default.log('Syncing all roles...');
|
|
16
|
-
(0, roles_1.syncAllRoles)();
|
|
17
|
-
}
|
|
18
|
-
if (args.type === 'roles' && !flags.all && flags.ext) {
|
|
19
|
-
const roles = components;
|
|
20
|
-
logger_1.default.log('Syncing provided roles...');
|
|
21
|
-
(0, roles_1.syncProvidedRoles)({ roles });
|
|
22
|
-
}
|
|
23
|
-
if (args.type === 'components' && flags.all && flags.ext) {
|
|
24
|
-
logger_1.default.log(`Syncing all components with ${config_1.default.schemaFileExt} extension...`);
|
|
25
|
-
(0, migrate_1.sync2AllComponents)({ presets: flags.presets });
|
|
26
|
-
}
|
|
27
|
-
if (args.type === 'components' && flags.all && !flags.ext) {
|
|
28
|
-
logger_1.default.warning('### DEPRECATED method. Method of syncing files without .sb.js extension, will be removed in version 4.0.0 ###');
|
|
29
|
-
logger_1.default.warning('Use sb-mig sync components --all --ext instead (you need to update your schema files to be named with .sb.js extension)');
|
|
30
|
-
logger_1.default.log(`Syncing all components from ${config_1.default.componentDirectory} directory...`);
|
|
31
|
-
(0, migrate_1.syncAllComponents)(Boolean(flags.ext), Boolean(flags.presets));
|
|
32
|
-
}
|
|
33
|
-
if (args.type === 'components' && !flags.all && flags.ext) {
|
|
34
|
-
logger_1.default.log(`Syncing provided components with ${config_1.default.schemaFileExt} extension...`);
|
|
35
|
-
if (components.length === 0) {
|
|
36
|
-
logger_1.default.warning('You have to provide some components separated with empty space. For exmaple: \'row column card\'');
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
(0, migrate_1.syncProvidedComponents)({ components, presets: Boolean(flags.presets), packageName: flags.packageName });
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
if (args.type === 'components' && !flags.all && !flags.ext && !flags.lock) {
|
|
43
|
-
logger_1.default.warning('### DEPRECATED method. Method of syncing files without .sb.js extension, will be removed in version 4.0.0 ###');
|
|
44
|
-
logger_1.default.warning('Use sb-mig sync components --ext instead (you need to update your schema files to be named with .sb.js extension)');
|
|
45
|
-
logger_1.default.log('Syncing provided components...');
|
|
46
|
-
if (components.length === 0) {
|
|
47
|
-
logger_1.default.warning('You have to provide some components separated with empty space. For exmaple: \'row column card\'');
|
|
48
|
-
}
|
|
49
|
-
else {
|
|
50
|
-
(0, migrate_1.syncComponents)(components, Boolean(flags.ext), Boolean(flags.presets), flags.packageName);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
if (args.type === 'datasources' && flags.all && !flags.ext) {
|
|
54
|
-
this.error('Datasources are only synced while using --ext optioon. use sb-mig sync datasources --all --ext to sync all datasources with extension (default: .sb.datasources.js)');
|
|
55
|
-
}
|
|
56
|
-
if (args.type === 'datasources' && !flags.all && !flags.ext) {
|
|
57
|
-
const datasources = components;
|
|
58
|
-
this.error(`Datasources are only synced while using --ext optioon. use sb-mig sync datasources ${datasources.join(' ')} --ext to sync provided datasources with extension (default: .sb.datasources.js)`);
|
|
59
|
-
}
|
|
60
|
-
if (args.type === 'datasources' && flags.all && flags.ext) {
|
|
61
|
-
logger_1.default.log('Syncing all datasources with extension...');
|
|
62
|
-
(0, datasources_1.syncAllDatasources)();
|
|
63
|
-
}
|
|
64
|
-
if (args.type === 'datasources' && !flags.all && flags.ext) {
|
|
65
|
-
const datasources = components;
|
|
66
|
-
logger_1.default.log('Syncing provided datasources with extension...');
|
|
67
|
-
(0, datasources_1.syncProvidedDatasources)({ datasources });
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
exports.default = Sync;
|
|
72
|
-
Sync.description = 'Synchronize components, datasources or roles with Storyblok space.';
|
|
73
|
-
Sync.examples = [
|
|
74
|
-
'$ sb-mig sync components --all --ext',
|
|
75
|
-
'$ sb-mig sync components @storyblok-components/text-block --ext --packageName',
|
|
76
|
-
'$ sb-mig sync components @storyblok-components/text-block @storyblok-components/button --ext --packageName',
|
|
77
|
-
'$ sb-mig sync components text-block button --ext',
|
|
78
|
-
'$ sb-mig sync components text-block button',
|
|
79
|
-
'$ sb-mig sync roles',
|
|
80
|
-
];
|
|
81
|
-
Sync.flags = {
|
|
82
|
-
help: command_1.flags.help({ char: 'h' }),
|
|
83
|
-
all: command_1.flags.boolean({ char: 'a', description: 'Synchronize all components.' }),
|
|
84
|
-
ext: command_1.flags.boolean({ char: 'e', description: "Synchronize with file extension. Default extension: '.sb.js'" }),
|
|
85
|
-
packageName: command_1.flags.boolean({ char: 'n', description: 'Synchronize based on installed package name.' }),
|
|
86
|
-
presets: command_1.flags.boolean({ char: 'p', description: 'Synchronize components with presets.' }),
|
|
87
|
-
lock: command_1.flags.boolean({ char: 'l', description: 'Synchronize based on storyblok.components.lock.js file' }),
|
|
88
|
-
};
|
|
89
|
-
Sync.strict = false;
|
|
90
|
-
Sync.args = [
|
|
91
|
-
{ name: 'type', description: 'What to synchronize', options: ['components', 'datasources', 'roles'], required: true },
|
|
92
|
-
{ name: 'list', description: 'Space separated list of component names. Example: card product-card row layout' },
|
|
93
|
-
];
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
export interface IStoryblokComponentConfig {
|
|
2
|
-
name: string;
|
|
3
|
-
version: string;
|
|
4
|
-
modified: boolean;
|
|
5
|
-
location: string;
|
|
6
|
-
locationPath: string;
|
|
7
|
-
scope: string;
|
|
8
|
-
isLinkedInComponentFile: boolean;
|
|
9
|
-
isComponentStyleImported: boolean;
|
|
10
|
-
links: {
|
|
11
|
-
[name: string]: {
|
|
12
|
-
[name: string]: string;
|
|
13
|
-
};
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
export interface IStoryblokComponentsConfig {
|
|
17
|
-
[name: string]: IStoryblokComponentConfig;
|
|
18
|
-
}
|
|
19
|
-
export interface IInstalledComponents {
|
|
20
|
-
scope: string | undefined;
|
|
21
|
-
name: string | undefined;
|
|
22
|
-
}
|
|
23
|
-
export declare enum SWAP_TOKEN {
|
|
24
|
-
componentImports = "componentImports",
|
|
25
|
-
componentLists = "componentLists",
|
|
26
|
-
styleImports = "styleImports"
|
|
27
|
-
}
|
|
28
|
-
interface CreateCrumb {
|
|
29
|
-
to: string;
|
|
30
|
-
token: SWAP_TOKEN;
|
|
31
|
-
}
|
|
32
|
-
export declare class StoryblokComponentsConfig {
|
|
33
|
-
private componentImportsToken;
|
|
34
|
-
private componentComponentsListToken;
|
|
35
|
-
private componentStylesImportsToken;
|
|
36
|
-
private data;
|
|
37
|
-
private storyblokComponentsConfigUrl;
|
|
38
|
-
constructor(data: IStoryblokComponentsConfig);
|
|
39
|
-
updateComponentsConfigFile(): boolean;
|
|
40
|
-
addComponentsToComponentsConfigFile({ installedComponents, local, }: {
|
|
41
|
-
installedComponents: IInstalledComponents[];
|
|
42
|
-
local: boolean;
|
|
43
|
-
}): IStoryblokComponentsConfig;
|
|
44
|
-
getAllData(): IStoryblokComponentsConfig;
|
|
45
|
-
getSingleData(componentName: string): IStoryblokComponentConfig;
|
|
46
|
-
setAllData(data: IStoryblokComponentsConfig): void;
|
|
47
|
-
setSingleData(singleComponentData: IStoryblokComponentConfig): void;
|
|
48
|
-
/**
|
|
49
|
-
*
|
|
50
|
-
* Based on storyblok.componnets.lock.js file,
|
|
51
|
-
* return proper content of specific files
|
|
52
|
-
* (storyblok-components.componentList.js and storyblok-componnets-styles.scss)
|
|
53
|
-
*/
|
|
54
|
-
createCrumb({ to, token }: CreateCrumb): any;
|
|
55
|
-
/**
|
|
56
|
-
* This updates storyblok components file with imports and
|
|
57
|
-
* exports of componentList part of the component, based on
|
|
58
|
-
* storyblok.components.lock file links property
|
|
59
|
-
*/
|
|
60
|
-
updateStoryblokComponentsFile(): void;
|
|
61
|
-
/**
|
|
62
|
-
* This updates storyblok components styles file with style imports
|
|
63
|
-
* based on storyblok.components.lock file links property
|
|
64
|
-
*/
|
|
65
|
-
updateStoryblokComponentStylesFile(): void;
|
|
66
|
-
}
|
|
67
|
-
declare const _default: StoryblokComponentsConfig;
|
|
68
|
-
export default _default;
|
|
@@ -1,220 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.StoryblokComponentsConfig = exports.SWAP_TOKEN = void 0;
|
|
4
|
-
const path = require("path");
|
|
5
|
-
const dotenv = require("dotenv");
|
|
6
|
-
const fs_1 = require("fs");
|
|
7
|
-
const camelcase = require("camelcase");
|
|
8
|
-
const config_1 = require("./config");
|
|
9
|
-
const discover2_1 = require("../utils/discover2");
|
|
10
|
-
dotenv.config();
|
|
11
|
-
var SWAP_TOKEN;
|
|
12
|
-
(function (SWAP_TOKEN) {
|
|
13
|
-
SWAP_TOKEN["componentImports"] = "componentImports";
|
|
14
|
-
SWAP_TOKEN["componentLists"] = "componentLists";
|
|
15
|
-
SWAP_TOKEN["styleImports"] = "styleImports";
|
|
16
|
-
})(SWAP_TOKEN = exports.SWAP_TOKEN || (exports.SWAP_TOKEN = {}));
|
|
17
|
-
class StoryblokComponentsConfig {
|
|
18
|
-
constructor(data) {
|
|
19
|
-
this.componentImportsToken = '// --- sb-mig scoped component imports ---';
|
|
20
|
-
this.componentComponentsListToken = '// --- sb-mig scoped component list ---';
|
|
21
|
-
this.componentStylesImportsToken = '// --- sb-mig scoped component styles imports ---';
|
|
22
|
-
this.storyblokComponentsConfigUrl = path.resolve(process.cwd(), 'storyblok.components.lock.js');
|
|
23
|
-
this.data = data;
|
|
24
|
-
}
|
|
25
|
-
updateComponentsConfigFile() {
|
|
26
|
-
const content = `module.exports = ${JSON.stringify(this.data, undefined, 2)}`;
|
|
27
|
-
fs_1.promises.writeFile(this.storyblokComponentsConfigUrl, content, {
|
|
28
|
-
encoding: 'utf-8',
|
|
29
|
-
})
|
|
30
|
-
.then(result => {
|
|
31
|
-
console.log('Done');
|
|
32
|
-
console.log(result);
|
|
33
|
-
return true;
|
|
34
|
-
})
|
|
35
|
-
.catch((err) => {
|
|
36
|
-
console.log('error, wtf ?');
|
|
37
|
-
console.log(err.message);
|
|
38
|
-
return false;
|
|
39
|
-
});
|
|
40
|
-
return true;
|
|
41
|
-
}
|
|
42
|
-
addComponentsToComponentsConfigFile({ installedComponents, local, }) {
|
|
43
|
-
return {
|
|
44
|
-
...this.data,
|
|
45
|
-
...installedComponents.reduce((prev, curr) => {
|
|
46
|
-
if (!this.getSingleData(`${curr.scope}/${curr.name}`)) {
|
|
47
|
-
const stylesFileAvailable = (0, discover2_1.discoverManyStyles)({
|
|
48
|
-
fileNames: [curr.name],
|
|
49
|
-
scope: discover2_1.SCOPE.all,
|
|
50
|
-
type: discover2_1.LOOKUP_TYPE.fileName,
|
|
51
|
-
}).length > 0;
|
|
52
|
-
return {
|
|
53
|
-
...prev,
|
|
54
|
-
[`${curr.scope}/${curr.name}`]: {
|
|
55
|
-
name: `${curr.scope}/${curr.name}`,
|
|
56
|
-
scope: curr.scope,
|
|
57
|
-
location: local ? 'local' : 'node_modules',
|
|
58
|
-
locationPath: local ?
|
|
59
|
-
`${config_1.default.storyblokComponentsLocalDirectory}/${curr.name}` :
|
|
60
|
-
`node_modules/${curr.scope}/${curr.name}`,
|
|
61
|
-
links: {
|
|
62
|
-
[config_1.default.storyblokComponentsListfile]: {
|
|
63
|
-
'// --- sb-mig scoped component imports ---': local ?
|
|
64
|
-
`import * as Scoped${camelcase(curr.name, { pascalCase: true })} from "./${curr.name}";` :
|
|
65
|
-
`import * as Scoped${camelcase(curr.name, { pascalCase: true })} from "${curr.scope}/${curr.name}";`,
|
|
66
|
-
'// --- sb-mig scoped component list ---': `Scoped${camelcase(curr.name, { pascalCase: true })}.ComponentList`,
|
|
67
|
-
},
|
|
68
|
-
[config_1.default.componentsStylesMatchFile]: {
|
|
69
|
-
'// --- sb-mig scoped component styles imports ---': stylesFileAvailable ?
|
|
70
|
-
local ?
|
|
71
|
-
`@import './${curr.name}/${curr.name}.scss';` :
|
|
72
|
-
`@import '${curr.scope}/${curr.name}/src/${curr.name}.scss';` :
|
|
73
|
-
'',
|
|
74
|
-
},
|
|
75
|
-
},
|
|
76
|
-
},
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
}, {}),
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
getAllData() {
|
|
83
|
-
return this.data;
|
|
84
|
-
}
|
|
85
|
-
getSingleData(componentName) {
|
|
86
|
-
return this.data[componentName];
|
|
87
|
-
}
|
|
88
|
-
setAllData(data) {
|
|
89
|
-
this.data = {
|
|
90
|
-
...data,
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
setSingleData(singleComponentData) {
|
|
94
|
-
this.data[singleComponentData.name] = singleComponentData;
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
*
|
|
98
|
-
* Based on storyblok.componnets.lock.js file,
|
|
99
|
-
* return proper content of specific files
|
|
100
|
-
* (storyblok-components.componentList.js and storyblok-componnets-styles.scss)
|
|
101
|
-
*/
|
|
102
|
-
createCrumb({ to, token }) {
|
|
103
|
-
const dataEntries = Object.entries(this.data);
|
|
104
|
-
let temp;
|
|
105
|
-
switch (token) {
|
|
106
|
-
case SWAP_TOKEN.componentImports:
|
|
107
|
-
temp = dataEntries
|
|
108
|
-
.map(component => component[1].links)
|
|
109
|
-
.map(component => component[to] !== undefined && component[to])
|
|
110
|
-
.filter(elements => elements !== false)
|
|
111
|
-
.reduce(
|
|
112
|
-
// @ts-ignore
|
|
113
|
-
(acc, curr) => {
|
|
114
|
-
return [...acc, curr[this.componentImportsToken]];
|
|
115
|
-
}, [this.componentImportsToken]);
|
|
116
|
-
break;
|
|
117
|
-
case SWAP_TOKEN.componentLists:
|
|
118
|
-
temp = dataEntries
|
|
119
|
-
.map(component => component[1].links)
|
|
120
|
-
.map(component => component[to] !== undefined && component[to])
|
|
121
|
-
.filter(elements => elements !== false)
|
|
122
|
-
.reduce(
|
|
123
|
-
// @ts-ignore
|
|
124
|
-
(acc, curr) => {
|
|
125
|
-
return [
|
|
126
|
-
...acc,
|
|
127
|
-
curr[this.componentComponentsListToken],
|
|
128
|
-
];
|
|
129
|
-
}, [this.componentComponentsListToken]);
|
|
130
|
-
break;
|
|
131
|
-
case SWAP_TOKEN.styleImports:
|
|
132
|
-
temp = dataEntries
|
|
133
|
-
.map(component => component[1].links)
|
|
134
|
-
.map(component => component[to] !== undefined && component[to])
|
|
135
|
-
.filter(elements => elements !== false)
|
|
136
|
-
.reduce(
|
|
137
|
-
// @ts-ignore
|
|
138
|
-
(acc, curr) => {
|
|
139
|
-
return [
|
|
140
|
-
...acc,
|
|
141
|
-
curr[this.componentStylesImportsToken],
|
|
142
|
-
];
|
|
143
|
-
}, [this.componentStylesImportsToken]);
|
|
144
|
-
break;
|
|
145
|
-
default:
|
|
146
|
-
break;
|
|
147
|
-
}
|
|
148
|
-
return temp === null || temp === void 0 ? void 0 : temp.filter((element) => element);
|
|
149
|
-
}
|
|
150
|
-
/**
|
|
151
|
-
* This updates storyblok components file with imports and
|
|
152
|
-
* exports of componentList part of the component, based on
|
|
153
|
-
* storyblok.components.lock file links property
|
|
154
|
-
*/
|
|
155
|
-
updateStoryblokComponentsFile() {
|
|
156
|
-
// one file
|
|
157
|
-
const crumb1 = this.createCrumb({
|
|
158
|
-
to: config_1.default.storyblokComponentsListfile,
|
|
159
|
-
token: SWAP_TOKEN.componentImports,
|
|
160
|
-
});
|
|
161
|
-
const crumb2 = this.createCrumb({
|
|
162
|
-
to: config_1.default.storyblokComponentsListfile,
|
|
163
|
-
token: SWAP_TOKEN.componentLists,
|
|
164
|
-
});
|
|
165
|
-
let content = `${crumb1.join('\n')}\n`;
|
|
166
|
-
content = `${content}\nexport default [
|
|
167
|
-
${crumb2.shift()}
|
|
168
|
-
${crumb2.map((partial) => `${partial},`).join('\n')}
|
|
169
|
-
]\n`;
|
|
170
|
-
// update actual file
|
|
171
|
-
fs_1.promises.writeFile(config_1.default.storyblokComponentsListfile, content, {
|
|
172
|
-
encoding: 'utf-8',
|
|
173
|
-
})
|
|
174
|
-
.then(result => {
|
|
175
|
-
console.log('Done');
|
|
176
|
-
console.log(result);
|
|
177
|
-
return true;
|
|
178
|
-
})
|
|
179
|
-
.catch((err) => {
|
|
180
|
-
console.log('error, wtf ?');
|
|
181
|
-
console.log(err.message);
|
|
182
|
-
return false;
|
|
183
|
-
});
|
|
184
|
-
}
|
|
185
|
-
/**
|
|
186
|
-
* This updates storyblok components styles file with style imports
|
|
187
|
-
* based on storyblok.components.lock file links property
|
|
188
|
-
*/
|
|
189
|
-
updateStoryblokComponentStylesFile() {
|
|
190
|
-
// one file
|
|
191
|
-
const crumb1 = this.createCrumb({
|
|
192
|
-
to: config_1.default.componentsStylesMatchFile,
|
|
193
|
-
token: SWAP_TOKEN.styleImports,
|
|
194
|
-
});
|
|
195
|
-
const content = `${crumb1.join('\n')}\n`;
|
|
196
|
-
// update actual file
|
|
197
|
-
fs_1.promises.writeFile(config_1.default.componentsStylesMatchFile, content, {
|
|
198
|
-
encoding: 'utf-8',
|
|
199
|
-
})
|
|
200
|
-
.then(result => {
|
|
201
|
-
console.log('Done');
|
|
202
|
-
console.log(result);
|
|
203
|
-
return true;
|
|
204
|
-
})
|
|
205
|
-
.catch((err) => {
|
|
206
|
-
console.log('error, wtf ?');
|
|
207
|
-
console.log(err.message);
|
|
208
|
-
return false;
|
|
209
|
-
});
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
exports.StoryblokComponentsConfig = StoryblokComponentsConfig;
|
|
213
|
-
let fileContent;
|
|
214
|
-
try {
|
|
215
|
-
fileContent = require(path.resolve(process.cwd(), 'storyblok.components.lock.js'));
|
|
216
|
-
}
|
|
217
|
-
catch (err) {
|
|
218
|
-
fileContent = {};
|
|
219
|
-
}
|
|
220
|
-
exports.default = new StoryblokComponentsConfig(fileContent);
|