sb-mig 3.1.2 → 3.1.6
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/dist/api/componentPresets.d.ts +1 -0
- package/dist/api/componentPresets.js +18 -0
- package/dist/api/components.d.ts +5 -0
- package/dist/api/components.js +63 -0
- package/dist/api/config.d.ts +2 -0
- package/dist/api/config.js +4 -0
- package/dist/api/datasources.d.ts +24 -0
- package/dist/api/datasources.js +181 -0
- package/dist/api/migrate.d.ts +17 -0
- package/dist/api/migrate.js +139 -0
- package/dist/api/mutateComponents.d.ts +2 -0
- package/dist/api/mutateComponents.js +45 -0
- package/dist/api/presets.d.ts +4 -0
- package/dist/api/presets.js +52 -0
- package/dist/api/resolvePresets.d.ts +2 -0
- package/dist/api/resolvePresets.js +41 -0
- package/dist/api/roles.d.ts +14 -0
- package/dist/api/roles.js +125 -0
- package/dist/cli-descriptions.d.ts +4 -0
- package/dist/cli-descriptions.js +72 -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 +20 -0
- package/dist/config/config.js +32 -0
- package/dist/index.d.ts +2 -0
- package/dist/utils/discover.d.ts +57 -0
- package/dist/utils/discover.js +481 -0
- package/dist/utils/files.d.ts +12 -0
- package/dist/utils/files.js +54 -0
- package/dist/utils/interfaces.d.ts +4 -0
- package/dist/utils/interfaces.js +1 -0
- package/dist/utils/logger.d.ts +8 -0
- package/dist/utils/logger.js +20 -0
- package/dist/utils/main.d.ts +13 -0
- package/dist/utils/main.js +28 -0
- package/dist/utils/others.d.ts +1 -0
- package/dist/utils/others.js +1 -0
- package/package.json +8 -4
|
@@ -0,0 +1,481 @@
|
|
|
1
|
+
// component resolution file borrowed from great storyblok-migrate
|
|
2
|
+
// https://github.com/maoberlehner/storyblok-migrate
|
|
3
|
+
// edit: changed a lot in here, but inspiration still is valid :)
|
|
4
|
+
import glob from "glob";
|
|
5
|
+
import path from "path";
|
|
6
|
+
import storyblokConfig from "../config/config.js";
|
|
7
|
+
import { getFileContentWithRequire } from "./main.js";
|
|
8
|
+
export var SCOPE;
|
|
9
|
+
(function (SCOPE) {
|
|
10
|
+
SCOPE["local"] = "local";
|
|
11
|
+
SCOPE["external"] = "external";
|
|
12
|
+
SCOPE["lock"] = "lock";
|
|
13
|
+
SCOPE["all"] = "all";
|
|
14
|
+
})(SCOPE || (SCOPE = {}));
|
|
15
|
+
export var LOOKUP_TYPE;
|
|
16
|
+
(function (LOOKUP_TYPE) {
|
|
17
|
+
LOOKUP_TYPE["packagName"] = "packageName";
|
|
18
|
+
LOOKUP_TYPE["fileName"] = "fileName";
|
|
19
|
+
})(LOOKUP_TYPE || (LOOKUP_TYPE = {}));
|
|
20
|
+
// problem with glob sync is, that when there is only one folder to search for
|
|
21
|
+
// we have to omit { } and when a lot, we have to use {folder1, folder2}
|
|
22
|
+
// so this function will normalize it based on amount of folders provided
|
|
23
|
+
const normalizeDiscover = ({ segments }) => {
|
|
24
|
+
if (segments.length === 1) {
|
|
25
|
+
return segments[0];
|
|
26
|
+
}
|
|
27
|
+
return `{${segments.join(",")}}`;
|
|
28
|
+
};
|
|
29
|
+
// export const compare = (request: CompareRequest): CompareResult => {
|
|
30
|
+
export const compare = (request) => {
|
|
31
|
+
// TODO: figure out types
|
|
32
|
+
const splittedLocal = request.local.map((path) => {
|
|
33
|
+
return {
|
|
34
|
+
name: path.split("/")[path.split("/").length - 1],
|
|
35
|
+
path,
|
|
36
|
+
};
|
|
37
|
+
});
|
|
38
|
+
const splittedExternal = request.external.map((path) => {
|
|
39
|
+
return {
|
|
40
|
+
name: path.split("/")[path.split("/").length - 1],
|
|
41
|
+
path,
|
|
42
|
+
};
|
|
43
|
+
});
|
|
44
|
+
// we only want to modify external array, because we want sometimes remove stuff which are already on local (overwrite node_modules ones)
|
|
45
|
+
const result = {
|
|
46
|
+
local: splittedLocal,
|
|
47
|
+
external: splittedExternal.filter((externalComponent) => {
|
|
48
|
+
if (splittedLocal.find((localComponent) => externalComponent.name === localComponent.name)) {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
return true;
|
|
52
|
+
}),
|
|
53
|
+
};
|
|
54
|
+
return result;
|
|
55
|
+
};
|
|
56
|
+
export const discoverManyByPackageName = (request) => {
|
|
57
|
+
const rootDirectory = "./";
|
|
58
|
+
const directory = path.resolve(process.cwd(), rootDirectory);
|
|
59
|
+
let pattern;
|
|
60
|
+
let listOfFiles = [""];
|
|
61
|
+
let listOfPackagesJsonFiles;
|
|
62
|
+
switch (request.scope) {
|
|
63
|
+
case SCOPE.local:
|
|
64
|
+
// ### MANY by PACKAGE - LOCAL - packageName
|
|
65
|
+
const onlyLocalComponentsDirectories = storyblokConfig.componentsDirectories.filter((path) => !path.includes("node_modules"));
|
|
66
|
+
pattern = path.join(`${directory}/${normalizeDiscover({
|
|
67
|
+
segments: onlyLocalComponentsDirectories,
|
|
68
|
+
})}`, "**", "package.json");
|
|
69
|
+
listOfPackagesJsonFiles = glob.sync(pattern, { follow: true });
|
|
70
|
+
listOfFiles = listOfPackagesJsonFiles
|
|
71
|
+
.filter(async (file) => request.packageNames.includes(await getFileContentWithRequire({ file }).name)) // filter only package.json from provided request.packageNames
|
|
72
|
+
.map((file) => {
|
|
73
|
+
// get path to folder in which current package.json is
|
|
74
|
+
const fileFolderPath = file
|
|
75
|
+
.split("/")
|
|
76
|
+
.slice(0, -1)
|
|
77
|
+
.join("/");
|
|
78
|
+
const allStoryblokSchemaFilesWithinFolderPattern = path.join(`${fileFolderPath}`, "**", `[^_]*.${storyblokConfig.schemaFileExt}`);
|
|
79
|
+
return glob.sync(allStoryblokSchemaFilesWithinFolderPattern, { follow: true });
|
|
80
|
+
})
|
|
81
|
+
.flat();
|
|
82
|
+
break;
|
|
83
|
+
case SCOPE.external:
|
|
84
|
+
// ### MANY by PACKAGE - EXTERNAL - packageName
|
|
85
|
+
const onlyNodeModulesPackagesComponentsDirectories = storyblokConfig.componentsDirectories.filter((path) => path.includes("node_modules"));
|
|
86
|
+
pattern = path.join(`${directory}/${normalizeDiscover({
|
|
87
|
+
segments: onlyNodeModulesPackagesComponentsDirectories,
|
|
88
|
+
})}`, "**", "package.json");
|
|
89
|
+
listOfPackagesJsonFiles = glob.sync(pattern, { follow: true });
|
|
90
|
+
listOfFiles = listOfPackagesJsonFiles
|
|
91
|
+
.filter((file) => request.packageNames.includes(getFileContentWithRequire({ file }).name)) // filter only package.json from provided request.packageNames
|
|
92
|
+
.map((file) => {
|
|
93
|
+
// get path to folder in which current package.json is
|
|
94
|
+
const fileFolderPath = file
|
|
95
|
+
.split("/")
|
|
96
|
+
.slice(0, -1)
|
|
97
|
+
.join("/");
|
|
98
|
+
const allStoryblokSchemaFilesWithinFolderPattern = path.join(`${fileFolderPath}`, "**", `[^_]*.${storyblokConfig.schemaFileExt}`);
|
|
99
|
+
return glob.sync(allStoryblokSchemaFilesWithinFolderPattern, { follow: true });
|
|
100
|
+
})
|
|
101
|
+
.flat();
|
|
102
|
+
break;
|
|
103
|
+
case SCOPE.all:
|
|
104
|
+
// ### MANY by PACKAGE - ALL - packageName
|
|
105
|
+
pattern = path.join(`${directory}/${normalizeDiscover({
|
|
106
|
+
segments: storyblokConfig.componentsDirectories,
|
|
107
|
+
})}`, "**", "package.json");
|
|
108
|
+
listOfPackagesJsonFiles = glob.sync(pattern, { follow: true });
|
|
109
|
+
listOfFiles = listOfPackagesJsonFiles
|
|
110
|
+
.filter((file) => request.packageNames.includes(getFileContentWithRequire({ file }).name)) // filter only package.json from provided request.packageNames
|
|
111
|
+
.map((file) => {
|
|
112
|
+
// get path to folder in which current package.json is
|
|
113
|
+
const fileFolderPath = file
|
|
114
|
+
.split("/")
|
|
115
|
+
.slice(0, -1)
|
|
116
|
+
.join("/");
|
|
117
|
+
const allStoryblokSchemaFilesWithinFolderPattern = path.join(`${fileFolderPath}`, "**", `[^_]*.${storyblokConfig.schemaFileExt}`);
|
|
118
|
+
return glob.sync(allStoryblokSchemaFilesWithinFolderPattern, { follow: true });
|
|
119
|
+
})
|
|
120
|
+
.flat();
|
|
121
|
+
break;
|
|
122
|
+
default:
|
|
123
|
+
break;
|
|
124
|
+
}
|
|
125
|
+
return listOfFiles;
|
|
126
|
+
};
|
|
127
|
+
export const discoverOneByPackageName = (request) => {
|
|
128
|
+
const rootDirectory = "./";
|
|
129
|
+
const directory = path.resolve(process.cwd(), rootDirectory);
|
|
130
|
+
let pattern;
|
|
131
|
+
let listOfFiles = [""];
|
|
132
|
+
let listOfPackagesJsonFiles;
|
|
133
|
+
switch (request.scope) {
|
|
134
|
+
case SCOPE.local:
|
|
135
|
+
// ### ONE by PACKAGE - LOCAL - packageName
|
|
136
|
+
const onlyLocalComponentsDirectories = storyblokConfig.componentsDirectories.filter((path) => !path.includes("node_modules"));
|
|
137
|
+
pattern = path.join(`${directory}/${normalizeDiscover({
|
|
138
|
+
segments: onlyLocalComponentsDirectories,
|
|
139
|
+
})}`, "**", "package.json");
|
|
140
|
+
listOfPackagesJsonFiles = glob.sync(pattern, { follow: true });
|
|
141
|
+
listOfFiles = listOfPackagesJsonFiles
|
|
142
|
+
.filter((file) => getFileContentWithRequire({ file }).name ===
|
|
143
|
+
request.packageName) // filter only package.json from provided request.packageName
|
|
144
|
+
.map((file) => {
|
|
145
|
+
// get path to folder in which current package.json is
|
|
146
|
+
const fileFolderPath = file
|
|
147
|
+
.split("/")
|
|
148
|
+
.slice(0, -1)
|
|
149
|
+
.join("/");
|
|
150
|
+
const allStoryblokSchemaFilesWithinFolderPattern = path.join(`${fileFolderPath}`, "**", `[^_]*.${storyblokConfig.schemaFileExt}`);
|
|
151
|
+
return glob.sync(allStoryblokSchemaFilesWithinFolderPattern, { follow: true });
|
|
152
|
+
})
|
|
153
|
+
.flat();
|
|
154
|
+
break;
|
|
155
|
+
case SCOPE.external:
|
|
156
|
+
// ### ONE by PACKAGE - EXTERNAL - packageName
|
|
157
|
+
const onlyNodeModulesPackagesComponentsDirectories = storyblokConfig.componentsDirectories.filter((path) => path.includes("node_modules"));
|
|
158
|
+
pattern = path.join(`${directory}/${normalizeDiscover({
|
|
159
|
+
segments: onlyNodeModulesPackagesComponentsDirectories,
|
|
160
|
+
})}`, "**", "package.json");
|
|
161
|
+
listOfPackagesJsonFiles = glob.sync(pattern, { follow: true });
|
|
162
|
+
listOfFiles = listOfPackagesJsonFiles
|
|
163
|
+
.filter((file) => getFileContentWithRequire({ file }).name ===
|
|
164
|
+
request.packageName) // filter only package.json from provided request.packageName
|
|
165
|
+
.map((file) => {
|
|
166
|
+
// get path to folder in which current package.json is
|
|
167
|
+
const fileFolderPath = file
|
|
168
|
+
.split("/")
|
|
169
|
+
.slice(0, -1)
|
|
170
|
+
.join("/");
|
|
171
|
+
const allStoryblokSchemaFilesWithinFolderPattern = path.join(`${fileFolderPath}`, "**", `[^_]*.${storyblokConfig.schemaFileExt}`);
|
|
172
|
+
return glob.sync(allStoryblokSchemaFilesWithinFolderPattern, { follow: true });
|
|
173
|
+
})
|
|
174
|
+
.flat();
|
|
175
|
+
break;
|
|
176
|
+
case SCOPE.all:
|
|
177
|
+
// ### ONE by PACKAGE - ALL - packageName
|
|
178
|
+
pattern = path.join(`${directory}/${normalizeDiscover({
|
|
179
|
+
segments: storyblokConfig.componentsDirectories,
|
|
180
|
+
})}`, "**", "package.json");
|
|
181
|
+
listOfPackagesJsonFiles = glob.sync(pattern, { follow: true });
|
|
182
|
+
listOfFiles = listOfPackagesJsonFiles
|
|
183
|
+
.filter((file) => getFileContentWithRequire({ file }).name ===
|
|
184
|
+
request.packageName) // filter only package.json from provided request.packageName
|
|
185
|
+
.map((file) => {
|
|
186
|
+
// get path to folder in which current package.json is
|
|
187
|
+
const fileFolderPath = file
|
|
188
|
+
.split("/")
|
|
189
|
+
.slice(0, -1)
|
|
190
|
+
.join("/");
|
|
191
|
+
const allStoryblokSchemaFilesWithinFolderPattern = path.join(`${fileFolderPath}`, "**", `[^_]*.${storyblokConfig.schemaFileExt}`);
|
|
192
|
+
return glob.sync(allStoryblokSchemaFilesWithinFolderPattern, { follow: true });
|
|
193
|
+
})
|
|
194
|
+
.flat();
|
|
195
|
+
break;
|
|
196
|
+
default:
|
|
197
|
+
break;
|
|
198
|
+
}
|
|
199
|
+
return listOfFiles;
|
|
200
|
+
};
|
|
201
|
+
export const discoverMany = (request) => {
|
|
202
|
+
const rootDirectory = "./";
|
|
203
|
+
const directory = path.resolve(process.cwd(), rootDirectory);
|
|
204
|
+
let pattern;
|
|
205
|
+
let listOfFiles = [""];
|
|
206
|
+
switch (request.scope) {
|
|
207
|
+
case SCOPE.local:
|
|
208
|
+
// ### MANY - LOCAL - fileName ###
|
|
209
|
+
const onlyLocalComponentsDirectories = storyblokConfig.componentsDirectories.filter((path) => !path.includes("node_modules"));
|
|
210
|
+
pattern = path.join(`${directory}/${normalizeDiscover({
|
|
211
|
+
segments: onlyLocalComponentsDirectories,
|
|
212
|
+
})}`, "**", `${normalizeDiscover({ segments: request.fileNames })}.${storyblokConfig.schemaFileExt}`);
|
|
213
|
+
listOfFiles = glob.sync(pattern, { follow: true });
|
|
214
|
+
break;
|
|
215
|
+
case SCOPE.external:
|
|
216
|
+
// ### MANY - EXTERNAL - fileName ###
|
|
217
|
+
const onlyNodeModulesPackagesComponentsDirectories = storyblokConfig.componentsDirectories.filter((path) => path.includes("node_modules"));
|
|
218
|
+
pattern = path.join(`${directory}/${normalizeDiscover({
|
|
219
|
+
segments: onlyNodeModulesPackagesComponentsDirectories,
|
|
220
|
+
})}`, "**", `${normalizeDiscover({ segments: request.fileNames })}.${storyblokConfig.schemaFileExt}`);
|
|
221
|
+
listOfFiles = glob.sync(pattern, { follow: true });
|
|
222
|
+
break;
|
|
223
|
+
case SCOPE.all:
|
|
224
|
+
// ### MANY - ALL - fileName ###
|
|
225
|
+
pattern = path.join(`${directory}/${normalizeDiscover({
|
|
226
|
+
segments: storyblokConfig.componentsDirectories,
|
|
227
|
+
})}`, "**", `${normalizeDiscover({ segments: request.fileNames })}.${storyblokConfig.schemaFileExt}`);
|
|
228
|
+
listOfFiles = glob.sync(pattern, { follow: true });
|
|
229
|
+
break;
|
|
230
|
+
default:
|
|
231
|
+
break;
|
|
232
|
+
}
|
|
233
|
+
return listOfFiles;
|
|
234
|
+
};
|
|
235
|
+
export const discoverManyDatasources = (request) => {
|
|
236
|
+
const rootDirectory = "./";
|
|
237
|
+
const directory = path.resolve(process.cwd(), rootDirectory);
|
|
238
|
+
let pattern;
|
|
239
|
+
let listOfFiles = [""];
|
|
240
|
+
switch (request.scope) {
|
|
241
|
+
case SCOPE.local:
|
|
242
|
+
// ### MANY - LOCAL - fileName ###
|
|
243
|
+
const onlyLocalComponentsDirectories = storyblokConfig.componentsDirectories.filter((path) => !path.includes("node_modules"));
|
|
244
|
+
pattern = path.join(`${directory}/${normalizeDiscover({
|
|
245
|
+
segments: onlyLocalComponentsDirectories,
|
|
246
|
+
})}`, "**", `${normalizeDiscover({ segments: request.fileNames })}.${storyblokConfig.datasourceExt}`);
|
|
247
|
+
listOfFiles = glob.sync(pattern, { follow: true });
|
|
248
|
+
break;
|
|
249
|
+
case SCOPE.external:
|
|
250
|
+
// ### MANY - EXTERNAL - fileName ###
|
|
251
|
+
const onlyNodeModulesPackagesComponentsDirectories = storyblokConfig.componentsDirectories.filter((path) => path.includes("node_modules"));
|
|
252
|
+
pattern = path.join(`${directory}/${normalizeDiscover({
|
|
253
|
+
segments: onlyNodeModulesPackagesComponentsDirectories,
|
|
254
|
+
})}`, "**", `${normalizeDiscover({ segments: request.fileNames })}.${storyblokConfig.datasourceExt}`);
|
|
255
|
+
listOfFiles = glob.sync(pattern, { follow: true });
|
|
256
|
+
break;
|
|
257
|
+
case SCOPE.all:
|
|
258
|
+
// ### MANY - ALL - fileName ###
|
|
259
|
+
pattern = path.join(`${directory}/${normalizeDiscover({
|
|
260
|
+
segments: storyblokConfig.componentsDirectories,
|
|
261
|
+
})}`, "**", `${normalizeDiscover({ segments: request.fileNames })}.${storyblokConfig.datasourceExt}`);
|
|
262
|
+
listOfFiles = glob.sync(pattern, { follow: true });
|
|
263
|
+
break;
|
|
264
|
+
default:
|
|
265
|
+
break;
|
|
266
|
+
}
|
|
267
|
+
return listOfFiles;
|
|
268
|
+
};
|
|
269
|
+
export const discoverDatasources = (request) => {
|
|
270
|
+
const rootDirectory = "./";
|
|
271
|
+
const directory = path.resolve(process.cwd(), rootDirectory);
|
|
272
|
+
let pattern;
|
|
273
|
+
let listOfFiles = [""];
|
|
274
|
+
switch (request.scope) {
|
|
275
|
+
case SCOPE.local:
|
|
276
|
+
// ### ALL - LOCAL - fileName ###
|
|
277
|
+
const onlyLocalComponentsDirectories = storyblokConfig.componentsDirectories.filter((path) => !path.includes("node_modules"));
|
|
278
|
+
pattern = path.join(`${directory}/${normalizeDiscover({
|
|
279
|
+
segments: onlyLocalComponentsDirectories,
|
|
280
|
+
})}`, "**", `[^_]*.${storyblokConfig.datasourceExt}` // all files with 'ext' extension, without files beggining with _
|
|
281
|
+
);
|
|
282
|
+
listOfFiles = glob.sync(pattern, { follow: true });
|
|
283
|
+
break;
|
|
284
|
+
case SCOPE.external:
|
|
285
|
+
// ### ALL - EXTERNAL - fileName ###
|
|
286
|
+
const onlyNodeModulesPackagesComponentsDirectories = storyblokConfig.componentsDirectories.filter((path) => path.includes("node_modules"));
|
|
287
|
+
pattern = path.join(`${directory}/${normalizeDiscover({
|
|
288
|
+
segments: onlyNodeModulesPackagesComponentsDirectories,
|
|
289
|
+
})}`, "**", `[^_]*.${storyblokConfig.datasourceExt}` // all files with 'ext' extension, without files beggining with _
|
|
290
|
+
);
|
|
291
|
+
listOfFiles = glob.sync(pattern, { follow: true });
|
|
292
|
+
break;
|
|
293
|
+
case SCOPE.all:
|
|
294
|
+
// ### ALL - LOCAL - fileName ###
|
|
295
|
+
pattern = path.join(`${directory}/${normalizeDiscover({
|
|
296
|
+
segments: storyblokConfig.componentsDirectories,
|
|
297
|
+
})}`, "**", `[^_]*.${storyblokConfig.datasourceExt}` // all files with 'ext' extension, without files beggining with _
|
|
298
|
+
);
|
|
299
|
+
listOfFiles = glob.sync(pattern, { follow: true });
|
|
300
|
+
break;
|
|
301
|
+
default:
|
|
302
|
+
break;
|
|
303
|
+
}
|
|
304
|
+
return listOfFiles;
|
|
305
|
+
};
|
|
306
|
+
export const discoverOne = (request) => {
|
|
307
|
+
const rootDirectory = "./";
|
|
308
|
+
const directory = path.resolve(process.cwd(), rootDirectory);
|
|
309
|
+
let pattern;
|
|
310
|
+
let listOfFiles = [""];
|
|
311
|
+
switch (request.scope) {
|
|
312
|
+
case SCOPE.local:
|
|
313
|
+
// ### ONE - LOCAL - fileName ###
|
|
314
|
+
const onlyLocalComponentsDirectories = storyblokConfig.componentsDirectories.filter((path) => !path.includes("node_modules"));
|
|
315
|
+
pattern = path.join(`${directory}/${normalizeDiscover({
|
|
316
|
+
segments: onlyLocalComponentsDirectories,
|
|
317
|
+
})}`, "**", `${request.fileName}.${storyblokConfig.schemaFileExt}` // all files with 'ext' extension, without files beggining with _
|
|
318
|
+
);
|
|
319
|
+
listOfFiles = glob.sync(pattern, { follow: true });
|
|
320
|
+
break;
|
|
321
|
+
case SCOPE.external:
|
|
322
|
+
// ### ONE - EXTERNAL - fileName ###
|
|
323
|
+
const onlyNodeModulesPackagesComponentsDirectories = storyblokConfig.componentsDirectories.filter((path) => path.includes("node_modules"));
|
|
324
|
+
pattern = path.join(`${directory}/${normalizeDiscover({
|
|
325
|
+
segments: onlyNodeModulesPackagesComponentsDirectories,
|
|
326
|
+
})}`, "**", `${request.fileName}.${storyblokConfig.schemaFileExt}` // all files with 'ext' extension, without files beggining with _
|
|
327
|
+
);
|
|
328
|
+
listOfFiles = glob.sync(pattern, { follow: true });
|
|
329
|
+
break;
|
|
330
|
+
case SCOPE.all:
|
|
331
|
+
// ### ONE - ALL - fileName ###
|
|
332
|
+
pattern = path.join(`${directory}/${normalizeDiscover({
|
|
333
|
+
segments: storyblokConfig.componentsDirectories,
|
|
334
|
+
})}`, "**", `${request.fileName}.${storyblokConfig.schemaFileExt}`);
|
|
335
|
+
listOfFiles = glob.sync(pattern, { follow: true });
|
|
336
|
+
break;
|
|
337
|
+
default:
|
|
338
|
+
break;
|
|
339
|
+
}
|
|
340
|
+
return listOfFiles;
|
|
341
|
+
};
|
|
342
|
+
export const discover = (request) => {
|
|
343
|
+
const rootDirectory = "./";
|
|
344
|
+
const directory = path.resolve(process.cwd(), rootDirectory);
|
|
345
|
+
let pattern;
|
|
346
|
+
let listOfFiles = [""];
|
|
347
|
+
const filesPattern = (componentDirectories) => {
|
|
348
|
+
return componentDirectories.length === 1
|
|
349
|
+
? path.join(`${directory}/${componentDirectories[0]}`, "**", `[^_]*.${storyblokConfig.schemaFileExt}` // all files with 'ext' extension, without files beggining with _
|
|
350
|
+
)
|
|
351
|
+
: path.join(`${directory}/{${componentDirectories.join(",")}}`, "**", `[^_]*.${storyblokConfig.schemaFileExt}` // all files with 'ext' extension, without files beggining with _
|
|
352
|
+
);
|
|
353
|
+
};
|
|
354
|
+
switch (request.scope) {
|
|
355
|
+
case SCOPE.local:
|
|
356
|
+
// ### ALL - LOCAL - fileName ###
|
|
357
|
+
const onlyLocalComponentsDirectories = storyblokConfig.componentsDirectories.filter((path) => !path.includes("node_modules"));
|
|
358
|
+
pattern = filesPattern(onlyLocalComponentsDirectories);
|
|
359
|
+
listOfFiles = glob.sync(pattern, { follow: true });
|
|
360
|
+
break;
|
|
361
|
+
case SCOPE.external:
|
|
362
|
+
// ### ALL - EXTERNAL - fileName ###
|
|
363
|
+
const onlyNodeModulesPackagesComponentsDirectories = storyblokConfig.componentsDirectories.filter((path) => path.includes("node_modules"));
|
|
364
|
+
pattern = filesPattern(onlyNodeModulesPackagesComponentsDirectories);
|
|
365
|
+
listOfFiles = glob.sync(pattern, { follow: true });
|
|
366
|
+
break;
|
|
367
|
+
case SCOPE.all:
|
|
368
|
+
// ### ALL - LOCAL - fileName ###
|
|
369
|
+
pattern = filesPattern(storyblokConfig.componentsDirectories);
|
|
370
|
+
listOfFiles = glob.sync(pattern, { follow: true });
|
|
371
|
+
break;
|
|
372
|
+
default:
|
|
373
|
+
break;
|
|
374
|
+
}
|
|
375
|
+
return listOfFiles;
|
|
376
|
+
};
|
|
377
|
+
export const discoverManyStyles = (request) => {
|
|
378
|
+
const rootDirectory = "./";
|
|
379
|
+
const directory = path.resolve(process.cwd(), rootDirectory);
|
|
380
|
+
let pattern;
|
|
381
|
+
let listOfFiles = [""];
|
|
382
|
+
switch (request.scope) {
|
|
383
|
+
case SCOPE.local:
|
|
384
|
+
// ### MANY - LOCAL - fileName ###
|
|
385
|
+
const onlyLocalComponentsDirectories = storyblokConfig.componentsDirectories.filter((path) => !path.includes("node_modules"));
|
|
386
|
+
pattern = path.join(`${directory}/${normalizeDiscover({
|
|
387
|
+
segments: onlyLocalComponentsDirectories,
|
|
388
|
+
})}`, "**", `${normalizeDiscover({ segments: request.fileNames })}.scss`);
|
|
389
|
+
listOfFiles = glob.sync(pattern, { follow: true });
|
|
390
|
+
break;
|
|
391
|
+
case SCOPE.external:
|
|
392
|
+
// ### MANY - EXTERNAL - fileName ###
|
|
393
|
+
const onlyNodeModulesPackagesComponentsDirectories = storyblokConfig.componentsDirectories.filter((path) => path.includes("node_modules"));
|
|
394
|
+
pattern = path.join(`${directory}/${normalizeDiscover({
|
|
395
|
+
segments: onlyNodeModulesPackagesComponentsDirectories,
|
|
396
|
+
})}`, "**", `${normalizeDiscover({ segments: request.fileNames })}.scss`);
|
|
397
|
+
listOfFiles = glob.sync(pattern, { follow: true });
|
|
398
|
+
break;
|
|
399
|
+
case SCOPE.all:
|
|
400
|
+
// ### MANY - ALL - fileName ###
|
|
401
|
+
pattern = path.join(`${directory}/${normalizeDiscover({
|
|
402
|
+
segments: storyblokConfig.componentsDirectories,
|
|
403
|
+
})}`, "**", `${normalizeDiscover({ segments: request.fileNames })}.scss`);
|
|
404
|
+
listOfFiles = glob.sync(pattern, { follow: true });
|
|
405
|
+
break;
|
|
406
|
+
default:
|
|
407
|
+
break;
|
|
408
|
+
}
|
|
409
|
+
return listOfFiles;
|
|
410
|
+
};
|
|
411
|
+
export const discoverRoles = (request) => {
|
|
412
|
+
const rootDirectory = "./";
|
|
413
|
+
const directory = path.resolve(process.cwd(), rootDirectory);
|
|
414
|
+
let pattern;
|
|
415
|
+
let listOfFiles = [""];
|
|
416
|
+
switch (request.scope) {
|
|
417
|
+
case SCOPE.local:
|
|
418
|
+
// ### ALL - LOCAL - fileName ###
|
|
419
|
+
const onlyLocalComponentsDirectories = storyblokConfig.componentsDirectories.filter((path) => !path.includes("node_modules"));
|
|
420
|
+
pattern = path.join(`${directory}/${normalizeDiscover({
|
|
421
|
+
segments: onlyLocalComponentsDirectories,
|
|
422
|
+
})}`, "**", `[^_]*.${storyblokConfig.rolesExt}` // all files with 'ext' extension, without files beggining with _
|
|
423
|
+
);
|
|
424
|
+
listOfFiles = glob.sync(pattern, { follow: true });
|
|
425
|
+
break;
|
|
426
|
+
case SCOPE.external:
|
|
427
|
+
// ### ALL - EXTERNAL - fileName ###
|
|
428
|
+
const onlyNodeModulesPackagesComponentsDirectories = storyblokConfig.componentsDirectories.filter((path) => path.includes("node_modules"));
|
|
429
|
+
pattern = path.join(`${directory}/${normalizeDiscover({
|
|
430
|
+
segments: onlyNodeModulesPackagesComponentsDirectories,
|
|
431
|
+
})}`, "**", `[^_]*.${storyblokConfig.rolesExt}` // all files with 'ext' extension, without files beggining with _
|
|
432
|
+
);
|
|
433
|
+
listOfFiles = glob.sync(pattern, { follow: true });
|
|
434
|
+
break;
|
|
435
|
+
case SCOPE.all:
|
|
436
|
+
// ### ALL - LOCAL - fileName ###
|
|
437
|
+
pattern = path.join(`${directory}/${normalizeDiscover({
|
|
438
|
+
segments: storyblokConfig.componentsDirectories,
|
|
439
|
+
})}`, "**", `[^_]*.${storyblokConfig.rolesExt}` // all files with 'ext' extension, without files beggining with _
|
|
440
|
+
);
|
|
441
|
+
listOfFiles = glob.sync(pattern, { follow: true });
|
|
442
|
+
break;
|
|
443
|
+
default:
|
|
444
|
+
break;
|
|
445
|
+
}
|
|
446
|
+
return listOfFiles;
|
|
447
|
+
};
|
|
448
|
+
export const discoverManyRoles = (request) => {
|
|
449
|
+
const rootDirectory = "./";
|
|
450
|
+
const directory = path.resolve(process.cwd(), rootDirectory);
|
|
451
|
+
let pattern;
|
|
452
|
+
let listOfFiles = [""];
|
|
453
|
+
switch (request.scope) {
|
|
454
|
+
case SCOPE.local:
|
|
455
|
+
// ### ALL - LOCAL - fileName ###
|
|
456
|
+
const onlyLocalComponentsDirectories = storyblokConfig.componentsDirectories.filter((path) => !path.includes("node_modules"));
|
|
457
|
+
pattern = path.join(`${directory}/${normalizeDiscover({
|
|
458
|
+
segments: onlyLocalComponentsDirectories,
|
|
459
|
+
})}`, "**", `${normalizeDiscover({ segments: request.fileNames })}.${storyblokConfig.rolesExt}`);
|
|
460
|
+
listOfFiles = glob.sync(pattern, { follow: true });
|
|
461
|
+
break;
|
|
462
|
+
case SCOPE.external:
|
|
463
|
+
// ### ALL - EXTERNAL - fileName ###
|
|
464
|
+
const onlyNodeModulesPackagesComponentsDirectories = storyblokConfig.componentsDirectories.filter((path) => path.includes("node_modules"));
|
|
465
|
+
pattern = path.join(`${directory}/${normalizeDiscover({
|
|
466
|
+
segments: onlyNodeModulesPackagesComponentsDirectories,
|
|
467
|
+
})}`, "**", `${normalizeDiscover({ segments: request.fileNames })}.${storyblokConfig.rolesExt}`);
|
|
468
|
+
listOfFiles = glob.sync(pattern, { follow: true });
|
|
469
|
+
break;
|
|
470
|
+
case SCOPE.all:
|
|
471
|
+
// ### ALL - LOCAL - fileName ###
|
|
472
|
+
pattern = path.join(`${directory}/${normalizeDiscover({
|
|
473
|
+
segments: storyblokConfig.componentsDirectories,
|
|
474
|
+
})}`, "**", `${normalizeDiscover({ segments: request.fileNames })}.${storyblokConfig.rolesExt}`);
|
|
475
|
+
listOfFiles = glob.sync(pattern, { follow: true });
|
|
476
|
+
break;
|
|
477
|
+
default:
|
|
478
|
+
break;
|
|
479
|
+
}
|
|
480
|
+
return listOfFiles;
|
|
481
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare const isDirectoryExists: (path: string) => boolean;
|
|
2
|
+
export declare const createDir: (dirPath: string) => Promise<void>;
|
|
3
|
+
export declare const createJsonFile: (content: string, pathWithFilename: string) => Promise<void>;
|
|
4
|
+
export declare const copyFolder: (src: string, dest: string) => Promise<unknown>;
|
|
5
|
+
export declare const copyFile: (src: string, dest: string) => Promise<void>;
|
|
6
|
+
interface CreateAndSaveToFile {
|
|
7
|
+
prefix: string;
|
|
8
|
+
folder: string;
|
|
9
|
+
res: any;
|
|
10
|
+
}
|
|
11
|
+
export declare const createAndSaveToFile: ({ prefix, folder, res, }: CreateAndSaveToFile) => Promise<void>;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import * as fs from "fs";
|
|
2
|
+
import pkg from "ncp";
|
|
3
|
+
import { generateDatestamp } from "./others.js";
|
|
4
|
+
import storyblokConfig from "../config/config.js";
|
|
5
|
+
import Logger from "./logger.js";
|
|
6
|
+
const { ncp } = pkg;
|
|
7
|
+
export const isDirectoryExists = (path) => fs.existsSync(path);
|
|
8
|
+
export const createDir = async (dirPath) => {
|
|
9
|
+
await fs.promises.mkdir(`${process.cwd()}/${dirPath}`, {
|
|
10
|
+
recursive: true,
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
export const createJsonFile = async (content, pathWithFilename) => {
|
|
14
|
+
await fs.promises.writeFile(pathWithFilename, content, { flag: "w" });
|
|
15
|
+
};
|
|
16
|
+
export const copyFolder = async (src, dest) => {
|
|
17
|
+
return new Promise((resolve, reject) => {
|
|
18
|
+
ncp(src, dest, function (err) {
|
|
19
|
+
if (err) {
|
|
20
|
+
reject({
|
|
21
|
+
failed: true,
|
|
22
|
+
message: `${src} copied unsuccessfully.`,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
resolve({
|
|
26
|
+
failed: false,
|
|
27
|
+
message: `${src} copied successfully.`,
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
export const copyFile = async (src, dest) => {
|
|
33
|
+
const directory = dest.split("/").slice(0, dest.split("/").length - 1);
|
|
34
|
+
const fileName = src.split("/")[src.split("/").length - 1];
|
|
35
|
+
if (!isDirectoryExists(directory.join("/"))) {
|
|
36
|
+
await createDir(directory.join("/"));
|
|
37
|
+
}
|
|
38
|
+
fs.copyFile(src, dest, (err) => {
|
|
39
|
+
if (err) {
|
|
40
|
+
console.error(`There is no file to copy, named ${fileName}`);
|
|
41
|
+
console.log(err);
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
console.log(`${fileName} was copied to ${dest}`);
|
|
45
|
+
return true;
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
export const createAndSaveToFile = async ({ prefix, folder, res, }) => {
|
|
49
|
+
const datestamp = new Date();
|
|
50
|
+
const filename = `${prefix}${generateDatestamp(datestamp)}`;
|
|
51
|
+
await createDir(`${storyblokConfig.sbmigWorkingDirectory}/${folder}/`);
|
|
52
|
+
await createJsonFile(JSON.stringify(res, undefined, 2), `${storyblokConfig.sbmigWorkingDirectory}/${folder}/${filename}.json`);
|
|
53
|
+
Logger.success(`All groups written to a file: ${filename}`);
|
|
54
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
export default class Logger {
|
|
3
|
+
static log(content) {
|
|
4
|
+
console.log(content);
|
|
5
|
+
}
|
|
6
|
+
static success(content) {
|
|
7
|
+
console.log(chalk.green(`✓ ${content}`));
|
|
8
|
+
}
|
|
9
|
+
static warning(content) {
|
|
10
|
+
console.log(chalk.yellow(`! ${content}`));
|
|
11
|
+
}
|
|
12
|
+
static error(content, { verbose } = { verbose: false }) {
|
|
13
|
+
if (verbose) {
|
|
14
|
+
console.log(content);
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
console.log(chalk.red(`✘ ${content}`));
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare const prop: (k: any) => (o: any) => any;
|
|
2
|
+
export declare const pipe: (...fns: any[]) => (x: any) => any;
|
|
3
|
+
export declare const unpackElements: (input: string[]) => string[];
|
|
4
|
+
export declare const unpackOne: (input: string[]) => string | undefined;
|
|
5
|
+
export declare const getFileContent: (data: {
|
|
6
|
+
file: string;
|
|
7
|
+
}) => any;
|
|
8
|
+
export declare const getFileContentWithRequire: (data: {
|
|
9
|
+
file: string;
|
|
10
|
+
}) => any;
|
|
11
|
+
export declare const getFilesContentWithRequire: (data: {
|
|
12
|
+
files: string[];
|
|
13
|
+
}) => any[];
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { createRequire } from "module";
|
|
2
|
+
export const prop = (k) => (o) => o[k];
|
|
3
|
+
export const pipe = (...fns) => (x) => [...fns].reduce((acc, f) => f(acc), x);
|
|
4
|
+
export const unpackElements = (input) => {
|
|
5
|
+
const [_1, _2, ...elementsForUse] = input;
|
|
6
|
+
return elementsForUse;
|
|
7
|
+
};
|
|
8
|
+
export const unpackOne = (input) => {
|
|
9
|
+
const [_1, _2, elementForUse] = input;
|
|
10
|
+
return elementForUse;
|
|
11
|
+
};
|
|
12
|
+
export const getFileContent = (data) => {
|
|
13
|
+
return import(data.file)
|
|
14
|
+
.then((res) => {
|
|
15
|
+
return res.default;
|
|
16
|
+
})
|
|
17
|
+
.catch(() => {
|
|
18
|
+
console.log("Cannot find requested file. (in terms of storyblok.config.js, using default values. ");
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
export const getFileContentWithRequire = (data) => {
|
|
22
|
+
const require = createRequire(import.meta.url);
|
|
23
|
+
return require(data.file);
|
|
24
|
+
};
|
|
25
|
+
export const getFilesContentWithRequire = (data) => {
|
|
26
|
+
const require = createRequire(import.meta.url);
|
|
27
|
+
return data.files.map((file) => require(file));
|
|
28
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const generateDatestamp: (datestamp: Date) => string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const generateDatestamp = (datestamp) => `${datestamp.getFullYear()}-${datestamp.getMonth()}-${datestamp.getDay()}_${datestamp.getTime()}`;
|