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/utils/discover2.js
DELETED
|
@@ -1,424 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// component resolution file borrowed from great storyblok-migrate
|
|
3
|
-
// https://github.com/maoberlehner/storyblok-migrate
|
|
4
|
-
// edit: changed a lot in here, but inspiration still is valid :)
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getFileContent = exports.getFilesContent = exports.discoverManyRoles = exports.discoverRoles = exports.discoverManyStyles = exports.discover = exports.discoverOne = exports.discoverDatasources = exports.discoverManyDatasources = exports.discoverMany = exports.discoverOneByPackageName = exports.discoverManyByPackageName = exports.compare = exports.LOOKUP_TYPE = exports.SCOPE = void 0;
|
|
7
|
-
const glob = require("glob");
|
|
8
|
-
const path = require("path");
|
|
9
|
-
const config_1 = require("../config/config");
|
|
10
|
-
var SCOPE;
|
|
11
|
-
(function (SCOPE) {
|
|
12
|
-
SCOPE["local"] = "local";
|
|
13
|
-
SCOPE["external"] = "external";
|
|
14
|
-
SCOPE["lock"] = "lock";
|
|
15
|
-
SCOPE["all"] = "all";
|
|
16
|
-
})(SCOPE = exports.SCOPE || (exports.SCOPE = {}));
|
|
17
|
-
var LOOKUP_TYPE;
|
|
18
|
-
(function (LOOKUP_TYPE) {
|
|
19
|
-
LOOKUP_TYPE["packagName"] = "packageName";
|
|
20
|
-
LOOKUP_TYPE["fileName"] = "fileName";
|
|
21
|
-
})(LOOKUP_TYPE = exports.LOOKUP_TYPE || (exports.LOOKUP_TYPE = {}));
|
|
22
|
-
// problem with glob sync is, that when there is only one folder to search for
|
|
23
|
-
// we have to omit { } and when a lot, we have to use {folder1, folder2}
|
|
24
|
-
// so this function will normalize it based on amount of folders provided
|
|
25
|
-
const normalizeDiscover = ({ segments }) => {
|
|
26
|
-
if (segments.length === 1) {
|
|
27
|
-
return segments[0];
|
|
28
|
-
}
|
|
29
|
-
return `{${segments.join(',')}}`;
|
|
30
|
-
};
|
|
31
|
-
const compare = (request) => {
|
|
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
|
|
48
|
-
.filter(externalComponent => {
|
|
49
|
-
if (splittedLocal.find(localComponent => externalComponent.name === localComponent.name)) {
|
|
50
|
-
return false;
|
|
51
|
-
}
|
|
52
|
-
return true;
|
|
53
|
-
}),
|
|
54
|
-
};
|
|
55
|
-
return result;
|
|
56
|
-
};
|
|
57
|
-
exports.compare = compare;
|
|
58
|
-
const discoverManyByPackageName = (request) => {
|
|
59
|
-
const rootDirectory = './';
|
|
60
|
-
const directory = path.resolve(process.cwd(), rootDirectory);
|
|
61
|
-
let pattern;
|
|
62
|
-
let listOfFiles = [''];
|
|
63
|
-
let listOfPackagesJsonFiles;
|
|
64
|
-
switch (request.scope) {
|
|
65
|
-
case SCOPE.local:
|
|
66
|
-
// ### MANY by PACKAGE - LOCAL - packageName
|
|
67
|
-
const onlyLocalComponentsDirectories = config_1.default.componentsDirectories.filter(path => !path.includes('node_modules'));
|
|
68
|
-
pattern = path.join(`${directory}/${normalizeDiscover({ segments: onlyLocalComponentsDirectories })}`, '**', 'package.json');
|
|
69
|
-
listOfPackagesJsonFiles = glob.sync(pattern, { follow: true });
|
|
70
|
-
listOfFiles = listOfPackagesJsonFiles
|
|
71
|
-
.filter(file => request.packageNames.includes((0, exports.getFileContent)({ 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.split('/').slice(0, -1).join('/');
|
|
75
|
-
const allStoryblokSchemaFilesWithinFolderPattern = path.join(`${fileFolderPath}`, '**', `[^_]*.${config_1.default.schemaFileExt}`);
|
|
76
|
-
return glob.sync(allStoryblokSchemaFilesWithinFolderPattern, { follow: true });
|
|
77
|
-
})
|
|
78
|
-
.flat();
|
|
79
|
-
break;
|
|
80
|
-
case SCOPE.external:
|
|
81
|
-
// ### MANY by PACKAGE - EXTERNAL - packageName
|
|
82
|
-
const onlyNodeModulesPackagesComponentsDirectories = config_1.default.componentsDirectories.filter(path => path.includes('node_modules'));
|
|
83
|
-
pattern = path.join(`${directory}/${normalizeDiscover({ segments: onlyNodeModulesPackagesComponentsDirectories })}`, '**', 'package.json');
|
|
84
|
-
listOfPackagesJsonFiles = glob.sync(pattern, { follow: true });
|
|
85
|
-
listOfFiles = listOfPackagesJsonFiles
|
|
86
|
-
.filter(file => request.packageNames.includes((0, exports.getFileContent)({ file }).name)) // filter only package.json from provided request.packageNames
|
|
87
|
-
.map(file => {
|
|
88
|
-
// get path to folder in which current package.json is
|
|
89
|
-
const fileFolderPath = file.split('/').slice(0, -1).join('/');
|
|
90
|
-
const allStoryblokSchemaFilesWithinFolderPattern = path.join(`${fileFolderPath}`, '**', `[^_]*.${config_1.default.schemaFileExt}`);
|
|
91
|
-
return glob.sync(allStoryblokSchemaFilesWithinFolderPattern, { follow: true });
|
|
92
|
-
})
|
|
93
|
-
.flat();
|
|
94
|
-
break;
|
|
95
|
-
case SCOPE.all:
|
|
96
|
-
// ### MANY by PACKAGE - ALL - packageName
|
|
97
|
-
pattern = path.join(`${directory}/${normalizeDiscover({ segments: config_1.default.componentsDirectories })}`, '**', 'package.json');
|
|
98
|
-
listOfPackagesJsonFiles = glob.sync(pattern, { follow: true });
|
|
99
|
-
listOfFiles = listOfPackagesJsonFiles
|
|
100
|
-
.filter(file => request.packageNames.includes((0, exports.getFileContent)({ file }).name)) // filter only package.json from provided request.packageNames
|
|
101
|
-
.map(file => {
|
|
102
|
-
// get path to folder in which current package.json is
|
|
103
|
-
const fileFolderPath = file.split('/').slice(0, -1).join('/');
|
|
104
|
-
const allStoryblokSchemaFilesWithinFolderPattern = path.join(`${fileFolderPath}`, '**', `[^_]*.${config_1.default.schemaFileExt}`);
|
|
105
|
-
return glob.sync(allStoryblokSchemaFilesWithinFolderPattern, { follow: true });
|
|
106
|
-
})
|
|
107
|
-
.flat();
|
|
108
|
-
break;
|
|
109
|
-
default:
|
|
110
|
-
break;
|
|
111
|
-
}
|
|
112
|
-
return listOfFiles;
|
|
113
|
-
};
|
|
114
|
-
exports.discoverManyByPackageName = discoverManyByPackageName;
|
|
115
|
-
const discoverOneByPackageName = (request) => {
|
|
116
|
-
const rootDirectory = './';
|
|
117
|
-
const directory = path.resolve(process.cwd(), rootDirectory);
|
|
118
|
-
let pattern;
|
|
119
|
-
let listOfFiles = [''];
|
|
120
|
-
let listOfPackagesJsonFiles;
|
|
121
|
-
switch (request.scope) {
|
|
122
|
-
case SCOPE.local:
|
|
123
|
-
// ### ONE by PACKAGE - LOCAL - packageName
|
|
124
|
-
const onlyLocalComponentsDirectories = config_1.default.componentsDirectories.filter(path => !path.includes('node_modules'));
|
|
125
|
-
pattern = path.join(`${directory}/${normalizeDiscover({ segments: onlyLocalComponentsDirectories })}`, '**', 'package.json');
|
|
126
|
-
listOfPackagesJsonFiles = glob.sync(pattern, { follow: true });
|
|
127
|
-
listOfFiles = listOfPackagesJsonFiles
|
|
128
|
-
.filter(file => (0, exports.getFileContent)({ file }).name === request.packageName) // filter only package.json from provided request.packageName
|
|
129
|
-
.map(file => {
|
|
130
|
-
// get path to folder in which current package.json is
|
|
131
|
-
const fileFolderPath = file.split('/').slice(0, -1).join('/');
|
|
132
|
-
const allStoryblokSchemaFilesWithinFolderPattern = path.join(`${fileFolderPath}`, '**', `[^_]*.${config_1.default.schemaFileExt}`);
|
|
133
|
-
return glob.sync(allStoryblokSchemaFilesWithinFolderPattern, { follow: true });
|
|
134
|
-
})
|
|
135
|
-
.flat();
|
|
136
|
-
break;
|
|
137
|
-
case SCOPE.external:
|
|
138
|
-
// ### ONE by PACKAGE - EXTERNAL - packageName
|
|
139
|
-
const onlyNodeModulesPackagesComponentsDirectories = config_1.default.componentsDirectories.filter(path => path.includes('node_modules'));
|
|
140
|
-
pattern = path.join(`${directory}/${normalizeDiscover({ segments: onlyNodeModulesPackagesComponentsDirectories })}`, '**', 'package.json');
|
|
141
|
-
listOfPackagesJsonFiles = glob.sync(pattern, { follow: true });
|
|
142
|
-
listOfFiles = listOfPackagesJsonFiles
|
|
143
|
-
.filter(file => (0, exports.getFileContent)({ file }).name === 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.split('/').slice(0, -1).join('/');
|
|
147
|
-
const allStoryblokSchemaFilesWithinFolderPattern = path.join(`${fileFolderPath}`, '**', `[^_]*.${config_1.default.schemaFileExt}`);
|
|
148
|
-
return glob.sync(allStoryblokSchemaFilesWithinFolderPattern, { follow: true });
|
|
149
|
-
})
|
|
150
|
-
.flat();
|
|
151
|
-
break;
|
|
152
|
-
case SCOPE.all:
|
|
153
|
-
// ### ONE by PACKAGE - ALL - packageName
|
|
154
|
-
pattern = path.join(`${directory}/${normalizeDiscover({ segments: config_1.default.componentsDirectories })}`, '**', 'package.json');
|
|
155
|
-
listOfPackagesJsonFiles = glob.sync(pattern, { follow: true });
|
|
156
|
-
listOfFiles = listOfPackagesJsonFiles
|
|
157
|
-
.filter(file => (0, exports.getFileContent)({ file }).name === request.packageName) // filter only package.json from provided request.packageName
|
|
158
|
-
.map(file => {
|
|
159
|
-
// get path to folder in which current package.json is
|
|
160
|
-
const fileFolderPath = file.split('/').slice(0, -1).join('/');
|
|
161
|
-
const allStoryblokSchemaFilesWithinFolderPattern = path.join(`${fileFolderPath}`, '**', `[^_]*.${config_1.default.schemaFileExt}`);
|
|
162
|
-
return glob.sync(allStoryblokSchemaFilesWithinFolderPattern, { follow: true });
|
|
163
|
-
})
|
|
164
|
-
.flat();
|
|
165
|
-
break;
|
|
166
|
-
default:
|
|
167
|
-
break;
|
|
168
|
-
}
|
|
169
|
-
return listOfFiles;
|
|
170
|
-
};
|
|
171
|
-
exports.discoverOneByPackageName = discoverOneByPackageName;
|
|
172
|
-
const discoverMany = (request) => {
|
|
173
|
-
const rootDirectory = './';
|
|
174
|
-
const directory = path.resolve(process.cwd(), rootDirectory);
|
|
175
|
-
let pattern;
|
|
176
|
-
let listOfFiles = [''];
|
|
177
|
-
switch (request.scope) {
|
|
178
|
-
case SCOPE.local:
|
|
179
|
-
// ### MANY - LOCAL - fileName ###
|
|
180
|
-
const onlyLocalComponentsDirectories = config_1.default.componentsDirectories.filter(path => !path.includes('node_modules'));
|
|
181
|
-
pattern = path.join(`${directory}/${normalizeDiscover({ segments: onlyLocalComponentsDirectories })}`, '**', `${normalizeDiscover({ segments: request.fileNames })}.${config_1.default.schemaFileExt}`);
|
|
182
|
-
listOfFiles = glob.sync(pattern, { follow: true });
|
|
183
|
-
break;
|
|
184
|
-
case SCOPE.external:
|
|
185
|
-
// ### MANY - EXTERNAL - fileName ###
|
|
186
|
-
const onlyNodeModulesPackagesComponentsDirectories = config_1.default.componentsDirectories.filter(path => path.includes('node_modules'));
|
|
187
|
-
pattern = path.join(`${directory}/${normalizeDiscover({ segments: onlyNodeModulesPackagesComponentsDirectories })}`, '**', `${normalizeDiscover({ segments: request.fileNames })}.${config_1.default.schemaFileExt}`);
|
|
188
|
-
listOfFiles = glob.sync(pattern, { follow: true });
|
|
189
|
-
break;
|
|
190
|
-
case SCOPE.all:
|
|
191
|
-
// ### MANY - ALL - fileName ###
|
|
192
|
-
pattern = path.join(`${directory}/${normalizeDiscover({ segments: config_1.default.componentsDirectories })}`, '**', `${normalizeDiscover({ segments: request.fileNames })}.${config_1.default.schemaFileExt}`);
|
|
193
|
-
listOfFiles = glob.sync(pattern, { follow: true });
|
|
194
|
-
break;
|
|
195
|
-
default:
|
|
196
|
-
break;
|
|
197
|
-
}
|
|
198
|
-
return listOfFiles;
|
|
199
|
-
};
|
|
200
|
-
exports.discoverMany = discoverMany;
|
|
201
|
-
const discoverManyDatasources = (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 = config_1.default.componentsDirectories.filter(path => !path.includes('node_modules'));
|
|
210
|
-
pattern = path.join(`${directory}/${normalizeDiscover({ segments: onlyLocalComponentsDirectories })}`, '**', `${normalizeDiscover({ segments: request.fileNames })}.${config_1.default.datasourceExt}`);
|
|
211
|
-
listOfFiles = glob.sync(pattern, { follow: true });
|
|
212
|
-
break;
|
|
213
|
-
case SCOPE.external:
|
|
214
|
-
// ### MANY - EXTERNAL - fileName ###
|
|
215
|
-
const onlyNodeModulesPackagesComponentsDirectories = config_1.default.componentsDirectories.filter(path => path.includes('node_modules'));
|
|
216
|
-
pattern = path.join(`${directory}/${normalizeDiscover({ segments: onlyNodeModulesPackagesComponentsDirectories })}`, '**', `${normalizeDiscover({ segments: request.fileNames })}.${config_1.default.datasourceExt}`);
|
|
217
|
-
listOfFiles = glob.sync(pattern, { follow: true });
|
|
218
|
-
break;
|
|
219
|
-
case SCOPE.all:
|
|
220
|
-
// ### MANY - ALL - fileName ###
|
|
221
|
-
pattern = path.join(`${directory}/${normalizeDiscover({ segments: config_1.default.componentsDirectories })}`, '**', `${normalizeDiscover({ segments: request.fileNames })}.${config_1.default.datasourceExt}`);
|
|
222
|
-
listOfFiles = glob.sync(pattern, { follow: true });
|
|
223
|
-
break;
|
|
224
|
-
default:
|
|
225
|
-
break;
|
|
226
|
-
}
|
|
227
|
-
return listOfFiles;
|
|
228
|
-
};
|
|
229
|
-
exports.discoverManyDatasources = discoverManyDatasources;
|
|
230
|
-
const discoverDatasources = (request) => {
|
|
231
|
-
const rootDirectory = './';
|
|
232
|
-
const directory = path.resolve(process.cwd(), rootDirectory);
|
|
233
|
-
let pattern;
|
|
234
|
-
let listOfFiles = [''];
|
|
235
|
-
switch (request.scope) {
|
|
236
|
-
case SCOPE.local:
|
|
237
|
-
// ### ALL - LOCAL - fileName ###
|
|
238
|
-
const onlyLocalComponentsDirectories = config_1.default.componentsDirectories.filter(path => !path.includes('node_modules'));
|
|
239
|
-
pattern = path.join(`${directory}/${normalizeDiscover({ segments: onlyLocalComponentsDirectories })}`, '**', `[^_]*.${config_1.default.datasourceExt}` // all files with 'ext' extension, without files beggining with _
|
|
240
|
-
);
|
|
241
|
-
listOfFiles = glob.sync(pattern, { follow: true });
|
|
242
|
-
break;
|
|
243
|
-
case SCOPE.external:
|
|
244
|
-
// ### ALL - EXTERNAL - fileName ###
|
|
245
|
-
const onlyNodeModulesPackagesComponentsDirectories = config_1.default.componentsDirectories.filter(path => path.includes('node_modules'));
|
|
246
|
-
pattern = path.join(`${directory}/${normalizeDiscover({ segments: onlyNodeModulesPackagesComponentsDirectories })}`, '**', `[^_]*.${config_1.default.datasourceExt}` // all files with 'ext' extension, without files beggining with _
|
|
247
|
-
);
|
|
248
|
-
listOfFiles = glob.sync(pattern, { follow: true });
|
|
249
|
-
break;
|
|
250
|
-
case SCOPE.all:
|
|
251
|
-
// ### ALL - LOCAL - fileName ###
|
|
252
|
-
pattern = path.join(`${directory}/${normalizeDiscover({ segments: config_1.default.componentsDirectories })}`, '**', `[^_]*.${config_1.default.datasourceExt}` // all files with 'ext' extension, without files beggining with _
|
|
253
|
-
);
|
|
254
|
-
listOfFiles = glob.sync(pattern, { follow: true });
|
|
255
|
-
break;
|
|
256
|
-
default:
|
|
257
|
-
break;
|
|
258
|
-
}
|
|
259
|
-
return listOfFiles;
|
|
260
|
-
};
|
|
261
|
-
exports.discoverDatasources = discoverDatasources;
|
|
262
|
-
const discoverOne = (request) => {
|
|
263
|
-
const rootDirectory = './';
|
|
264
|
-
const directory = path.resolve(process.cwd(), rootDirectory);
|
|
265
|
-
let pattern;
|
|
266
|
-
let listOfFiles = [''];
|
|
267
|
-
switch (request.scope) {
|
|
268
|
-
case SCOPE.local:
|
|
269
|
-
// ### ONE - LOCAL - fileName ###
|
|
270
|
-
const onlyLocalComponentsDirectories = config_1.default.componentsDirectories.filter(path => !path.includes('node_modules'));
|
|
271
|
-
pattern = path.join(`${directory}/${normalizeDiscover({ segments: onlyLocalComponentsDirectories })}`, '**', `${request.fileName}.${config_1.default.schemaFileExt}` // all files with 'ext' extension, without files beggining with _
|
|
272
|
-
);
|
|
273
|
-
listOfFiles = glob.sync(pattern, { follow: true });
|
|
274
|
-
break;
|
|
275
|
-
case SCOPE.external:
|
|
276
|
-
// ### ONE - EXTERNAL - fileName ###
|
|
277
|
-
const onlyNodeModulesPackagesComponentsDirectories = config_1.default.componentsDirectories.filter(path => path.includes('node_modules'));
|
|
278
|
-
pattern = path.join(`${directory}/${normalizeDiscover({ segments: onlyNodeModulesPackagesComponentsDirectories })}`, '**', `${request.fileName}.${config_1.default.schemaFileExt}` // all files with 'ext' extension, without files beggining with _
|
|
279
|
-
);
|
|
280
|
-
listOfFiles = glob.sync(pattern, { follow: true });
|
|
281
|
-
break;
|
|
282
|
-
case SCOPE.all:
|
|
283
|
-
// ### ONE - ALL - fileName ###
|
|
284
|
-
pattern = path.join(`${directory}/${normalizeDiscover({ segments: config_1.default.componentsDirectories })}`, '**', `${request.fileName}.${config_1.default.schemaFileExt}`);
|
|
285
|
-
listOfFiles = glob.sync(pattern, { follow: true });
|
|
286
|
-
break;
|
|
287
|
-
default:
|
|
288
|
-
break;
|
|
289
|
-
}
|
|
290
|
-
return listOfFiles;
|
|
291
|
-
};
|
|
292
|
-
exports.discoverOne = discoverOne;
|
|
293
|
-
const discover = (request) => {
|
|
294
|
-
const rootDirectory = './';
|
|
295
|
-
const directory = path.resolve(process.cwd(), rootDirectory);
|
|
296
|
-
let pattern;
|
|
297
|
-
let listOfFiles = [''];
|
|
298
|
-
const filesPattern = (componentDirectories) => {
|
|
299
|
-
return componentDirectories.length === 1 ? path.join(`${directory}/${componentDirectories[0]}`, '**', `[^_]*.${config_1.default.schemaFileExt}` // all files with 'ext' extension, without files beggining with _
|
|
300
|
-
) : path.join(`${directory}/{${componentDirectories.join(',')}}`, '**', `[^_]*.${config_1.default.schemaFileExt}` // all files with 'ext' extension, without files beggining with _
|
|
301
|
-
);
|
|
302
|
-
};
|
|
303
|
-
switch (request.scope) {
|
|
304
|
-
case SCOPE.local:
|
|
305
|
-
// ### ALL - LOCAL - fileName ###
|
|
306
|
-
const onlyLocalComponentsDirectories = config_1.default.componentsDirectories.filter(path => !path.includes('node_modules'));
|
|
307
|
-
pattern = filesPattern(onlyLocalComponentsDirectories);
|
|
308
|
-
listOfFiles = glob.sync(pattern, { follow: true });
|
|
309
|
-
break;
|
|
310
|
-
case SCOPE.external:
|
|
311
|
-
// ### ALL - EXTERNAL - fileName ###
|
|
312
|
-
const onlyNodeModulesPackagesComponentsDirectories = config_1.default.componentsDirectories.filter(path => path.includes('node_modules'));
|
|
313
|
-
pattern = filesPattern(onlyNodeModulesPackagesComponentsDirectories);
|
|
314
|
-
listOfFiles = glob.sync(pattern, { follow: true });
|
|
315
|
-
break;
|
|
316
|
-
case SCOPE.all:
|
|
317
|
-
// ### ALL - LOCAL - fileName ###
|
|
318
|
-
pattern = filesPattern(config_1.default.componentsDirectories);
|
|
319
|
-
listOfFiles = glob.sync(pattern, { follow: true });
|
|
320
|
-
break;
|
|
321
|
-
default:
|
|
322
|
-
break;
|
|
323
|
-
}
|
|
324
|
-
return listOfFiles;
|
|
325
|
-
};
|
|
326
|
-
exports.discover = discover;
|
|
327
|
-
const discoverManyStyles = (request) => {
|
|
328
|
-
const rootDirectory = './';
|
|
329
|
-
const directory = path.resolve(process.cwd(), rootDirectory);
|
|
330
|
-
let pattern;
|
|
331
|
-
let listOfFiles = [''];
|
|
332
|
-
switch (request.scope) {
|
|
333
|
-
case SCOPE.local:
|
|
334
|
-
// ### MANY - LOCAL - fileName ###
|
|
335
|
-
const onlyLocalComponentsDirectories = config_1.default.componentsDirectories.filter(path => !path.includes('node_modules'));
|
|
336
|
-
pattern = path.join(`${directory}/${normalizeDiscover({ segments: onlyLocalComponentsDirectories })}`, '**', `${normalizeDiscover({ segments: request.fileNames })}.scss`);
|
|
337
|
-
listOfFiles = glob.sync(pattern, { follow: true });
|
|
338
|
-
break;
|
|
339
|
-
case SCOPE.external:
|
|
340
|
-
// ### MANY - EXTERNAL - fileName ###
|
|
341
|
-
const onlyNodeModulesPackagesComponentsDirectories = config_1.default.componentsDirectories.filter(path => path.includes('node_modules'));
|
|
342
|
-
pattern = path.join(`${directory}/${normalizeDiscover({ segments: onlyNodeModulesPackagesComponentsDirectories })}`, '**', `${normalizeDiscover({ segments: request.fileNames })}.scss`);
|
|
343
|
-
listOfFiles = glob.sync(pattern, { follow: true });
|
|
344
|
-
break;
|
|
345
|
-
case SCOPE.all:
|
|
346
|
-
// ### MANY - ALL - fileName ###
|
|
347
|
-
pattern = path.join(`${directory}/${normalizeDiscover({ segments: config_1.default.componentsDirectories })}`, '**', `${normalizeDiscover({ segments: request.fileNames })}.scss`);
|
|
348
|
-
listOfFiles = glob.sync(pattern, { follow: true });
|
|
349
|
-
break;
|
|
350
|
-
default:
|
|
351
|
-
break;
|
|
352
|
-
}
|
|
353
|
-
return listOfFiles;
|
|
354
|
-
};
|
|
355
|
-
exports.discoverManyStyles = discoverManyStyles;
|
|
356
|
-
const discoverRoles = (request) => {
|
|
357
|
-
const rootDirectory = './';
|
|
358
|
-
const directory = path.resolve(process.cwd(), rootDirectory);
|
|
359
|
-
let pattern;
|
|
360
|
-
let listOfFiles = [''];
|
|
361
|
-
switch (request.scope) {
|
|
362
|
-
case SCOPE.local:
|
|
363
|
-
// ### ALL - LOCAL - fileName ###
|
|
364
|
-
const onlyLocalComponentsDirectories = config_1.default.componentsDirectories.filter(path => !path.includes('node_modules'));
|
|
365
|
-
pattern = path.join(`${directory}/${normalizeDiscover({ segments: onlyLocalComponentsDirectories })}`, '**', `[^_]*.${config_1.default.rolesExt}` // all files with 'ext' extension, without files beggining with _
|
|
366
|
-
);
|
|
367
|
-
listOfFiles = glob.sync(pattern, { follow: true });
|
|
368
|
-
break;
|
|
369
|
-
case SCOPE.external:
|
|
370
|
-
// ### ALL - EXTERNAL - fileName ###
|
|
371
|
-
const onlyNodeModulesPackagesComponentsDirectories = config_1.default.componentsDirectories.filter(path => path.includes('node_modules'));
|
|
372
|
-
pattern = path.join(`${directory}/${normalizeDiscover({ segments: onlyNodeModulesPackagesComponentsDirectories })}`, '**', `[^_]*.${config_1.default.rolesExt}` // all files with 'ext' extension, without files beggining with _
|
|
373
|
-
);
|
|
374
|
-
listOfFiles = glob.sync(pattern, { follow: true });
|
|
375
|
-
break;
|
|
376
|
-
case SCOPE.all:
|
|
377
|
-
// ### ALL - LOCAL - fileName ###
|
|
378
|
-
pattern = path.join(`${directory}/${normalizeDiscover({ segments: config_1.default.componentsDirectories })}`, '**', `[^_]*.${config_1.default.rolesExt}` // all files with 'ext' extension, without files beggining with _
|
|
379
|
-
);
|
|
380
|
-
listOfFiles = glob.sync(pattern, { follow: true });
|
|
381
|
-
break;
|
|
382
|
-
default:
|
|
383
|
-
break;
|
|
384
|
-
}
|
|
385
|
-
return listOfFiles;
|
|
386
|
-
};
|
|
387
|
-
exports.discoverRoles = discoverRoles;
|
|
388
|
-
const discoverManyRoles = (request) => {
|
|
389
|
-
const rootDirectory = './';
|
|
390
|
-
const directory = path.resolve(process.cwd(), rootDirectory);
|
|
391
|
-
let pattern;
|
|
392
|
-
let listOfFiles = [''];
|
|
393
|
-
switch (request.scope) {
|
|
394
|
-
case SCOPE.local:
|
|
395
|
-
// ### ALL - LOCAL - fileName ###
|
|
396
|
-
const onlyLocalComponentsDirectories = config_1.default.componentsDirectories.filter(path => !path.includes('node_modules'));
|
|
397
|
-
pattern = path.join(`${directory}/${normalizeDiscover({ segments: onlyLocalComponentsDirectories })}`, '**', `${normalizeDiscover({ segments: request.fileNames })}.${config_1.default.rolesExt}`);
|
|
398
|
-
listOfFiles = glob.sync(pattern, { follow: true });
|
|
399
|
-
break;
|
|
400
|
-
case SCOPE.external:
|
|
401
|
-
// ### ALL - EXTERNAL - fileName ###
|
|
402
|
-
const onlyNodeModulesPackagesComponentsDirectories = config_1.default.componentsDirectories.filter(path => path.includes('node_modules'));
|
|
403
|
-
pattern = path.join(`${directory}/${normalizeDiscover({ segments: onlyNodeModulesPackagesComponentsDirectories })}`, '**', `${normalizeDiscover({ segments: request.fileNames })}.${config_1.default.rolesExt}`);
|
|
404
|
-
listOfFiles = glob.sync(pattern, { follow: true });
|
|
405
|
-
break;
|
|
406
|
-
case SCOPE.all:
|
|
407
|
-
// ### ALL - LOCAL - fileName ###
|
|
408
|
-
pattern = path.join(`${directory}/${normalizeDiscover({ segments: config_1.default.componentsDirectories })}`, '**', `${normalizeDiscover({ segments: request.fileNames })}.${config_1.default.rolesExt}`);
|
|
409
|
-
listOfFiles = glob.sync(pattern, { follow: true });
|
|
410
|
-
break;
|
|
411
|
-
default:
|
|
412
|
-
break;
|
|
413
|
-
}
|
|
414
|
-
return listOfFiles;
|
|
415
|
-
};
|
|
416
|
-
exports.discoverManyRoles = discoverManyRoles;
|
|
417
|
-
const getFilesContent = (data) => {
|
|
418
|
-
return data.files.map(file => require(file));
|
|
419
|
-
};
|
|
420
|
-
exports.getFilesContent = getFilesContent;
|
|
421
|
-
const getFileContent = (data) => {
|
|
422
|
-
return require(data.file);
|
|
423
|
-
};
|
|
424
|
-
exports.getFileContent = getFileContent;
|
package/lib/utils/files.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export declare const getCurrentDirectoryBase: () => string;
|
|
2
|
-
export declare const isDirectoryExists: (path: string) => boolean;
|
|
3
|
-
export declare const createDir: (dirPath: string) => Promise<void>;
|
|
4
|
-
export declare const createJsonFile: (content: string, pathWithFilename: string) => Promise<void>;
|
|
5
|
-
export declare const copyFolder: (src: string, dest: string) => Promise<unknown>;
|
|
6
|
-
export declare const copyFile: (src: string, dest: string) => Promise<void>;
|
package/lib/utils/files.js
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.copyFile = exports.copyFolder = exports.createJsonFile = exports.createDir = exports.isDirectoryExists = exports.getCurrentDirectoryBase = void 0;
|
|
4
|
-
const fs = require("fs");
|
|
5
|
-
const ncp_1 = require("ncp");
|
|
6
|
-
const path = require("path");
|
|
7
|
-
const logger_1 = require("./logger");
|
|
8
|
-
const getCurrentDirectoryBase = () => path.basename(process.cwd());
|
|
9
|
-
exports.getCurrentDirectoryBase = getCurrentDirectoryBase;
|
|
10
|
-
const isDirectoryExists = (path) => fs.existsSync(path);
|
|
11
|
-
exports.isDirectoryExists = isDirectoryExists;
|
|
12
|
-
const createDir = async (dirPath) => {
|
|
13
|
-
await fs.promises.mkdir(`${process.cwd()}/${dirPath}`, {
|
|
14
|
-
recursive: true,
|
|
15
|
-
});
|
|
16
|
-
};
|
|
17
|
-
exports.createDir = createDir;
|
|
18
|
-
const createJsonFile = async (content, pathWithFilename) => {
|
|
19
|
-
await fs.promises.writeFile(pathWithFilename, content, { flag: 'w' });
|
|
20
|
-
};
|
|
21
|
-
exports.createJsonFile = createJsonFile;
|
|
22
|
-
const copyFolder = async (src, dest) => {
|
|
23
|
-
return new Promise((resolve, reject) => {
|
|
24
|
-
(0, ncp_1.ncp)(src, dest, function (err) {
|
|
25
|
-
if (err) {
|
|
26
|
-
reject({
|
|
27
|
-
failed: true,
|
|
28
|
-
message: `${src} copied unsuccessfully.`,
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
resolve({
|
|
32
|
-
failed: false,
|
|
33
|
-
message: `${src} copied successfully.`,
|
|
34
|
-
});
|
|
35
|
-
});
|
|
36
|
-
});
|
|
37
|
-
};
|
|
38
|
-
exports.copyFolder = copyFolder;
|
|
39
|
-
const copyFile = async (src, dest) => {
|
|
40
|
-
const directory = dest.split('/').slice(0, dest.split('/').length - 1);
|
|
41
|
-
const fileName = src.split('/')[src.split('/').length - 1];
|
|
42
|
-
if (!(0, exports.isDirectoryExists)(directory.join('/'))) {
|
|
43
|
-
await (0, exports.createDir)(directory.join('/'));
|
|
44
|
-
}
|
|
45
|
-
fs.copyFile(src, dest, err => {
|
|
46
|
-
if (err) {
|
|
47
|
-
logger_1.default.error(`There is no file to copy, named ${fileName}`);
|
|
48
|
-
console.log(err);
|
|
49
|
-
return false;
|
|
50
|
-
}
|
|
51
|
-
console.log(`${fileName} was copied to ${dest}`);
|
|
52
|
-
});
|
|
53
|
-
};
|
|
54
|
-
exports.copyFile = copyFile;
|
package/lib/utils/logger.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export default class Logger {
|
|
2
|
-
name: any;
|
|
3
|
-
constructor(name: any);
|
|
4
|
-
static bigLog(content: any): void;
|
|
5
|
-
static log(content: any): void;
|
|
6
|
-
static success(content: any): void;
|
|
7
|
-
static warning(content: any): void;
|
|
8
|
-
static error(content: any, { verbose }?: {
|
|
9
|
-
verbose: boolean;
|
|
10
|
-
}): void;
|
|
11
|
-
}
|
package/lib/utils/logger.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const chalk = require("chalk");
|
|
4
|
-
const figlet = require("figlet");
|
|
5
|
-
class Logger {
|
|
6
|
-
constructor(name) {
|
|
7
|
-
this.name = name;
|
|
8
|
-
}
|
|
9
|
-
static bigLog(content) {
|
|
10
|
-
console.log(chalk.yellow(figlet.textSync(content, { horizontalLayout: 'full' })));
|
|
11
|
-
}
|
|
12
|
-
static log(content) {
|
|
13
|
-
console.log(content);
|
|
14
|
-
}
|
|
15
|
-
static success(content) {
|
|
16
|
-
console.log(chalk.green(`✓ ${content}`));
|
|
17
|
-
}
|
|
18
|
-
static warning(content) {
|
|
19
|
-
console.log(chalk.yellow(`! ${content}`));
|
|
20
|
-
}
|
|
21
|
-
static error(content, { verbose } = { verbose: false }) {
|
|
22
|
-
if (verbose) {
|
|
23
|
-
console.log(content);
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
console.log(chalk.red(`✘ ${content}`));
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
exports.default = Logger;
|
package/lib/utils/others.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const generateDatestamp: (datestamp: Date) => string;
|
package/lib/utils/others.js
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateDatestamp = void 0;
|
|
4
|
-
const generateDatestamp = (datestamp) => `${datestamp.getFullYear()}-${datestamp.getMonth()}-${datestamp.getDay()}_${datestamp.getTime()}`;
|
|
5
|
-
exports.generateDatestamp = generateDatestamp;
|
package/oclif.manifest.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":"2.9.13","commands":{"backup":{"id":"backup","description":"Command for backing up anything related to Storyblok","pluginName":"sb-mig","pluginType":"core","aliases":[],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false},"allComponents":{"name":"allComponents","type":"boolean","char":"a","description":"Backup all components.","allowNo":false},"oneComponent":{"name":"oneComponent","type":"option","char":"o","description":"Backup one component by name."},"allComponentsGroups":{"name":"allComponentsGroups","type":"boolean","char":"g","description":"Backup all components groups.","allowNo":false},"oneComponentsGroup":{"name":"oneComponentsGroup","type":"option","char":"f","description":"Backup one components group by name."},"oneComponentPresets":{"name":"oneComponentPresets","type":"option","char":"p","description":"Backup all presets for one component"},"allPresets":{"name":"allPresets","type":"boolean","char":"l","description":"Backup all presets.","allowNo":false},"onePreset":{"name":"onePreset","type":"option","char":"i","description":"Backup one preset by id."},"allDatasources":{"name":"allDatasources","type":"boolean","char":"d","description":"Backup all datasources.","allowNo":false},"oneDatasource":{"name":"oneDatasource","type":"option","char":"x","description":"Backup one datasource by name."},"datasourceEntries":{"name":"datasourceEntries","type":"option","char":"e","description":"Backup one datasource entries by datasource name."},"allRoles":{"name":"allRoles","type":"boolean","char":"R","description":"Backup all roles and permissions.","allowNo":false},"oneRole":{"name":"oneRole","type":"option","char":"r","description":"Backup one role by name."}},"args":[]},"debug":{"id":"debug","description":"Output extra debugging","pluginName":"sb-mig","pluginType":"core","aliases":[],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false}},"args":[]},"sync":{"id":"sync","description":"Synchronize components, datasources or roles with Storyblok space.","pluginName":"sb-mig","pluginType":"core","aliases":[],"examples":["$ sb-mig sync components --all --ext","$ sb-mig sync components @storyblok-components/text-block --ext --packageName","$ sb-mig sync components @storyblok-components/text-block @storyblok-components/button --ext --packageName","$ sb-mig sync components text-block button --ext","$ sb-mig sync components text-block button","$ sb-mig sync roles"],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false},"all":{"name":"all","type":"boolean","char":"a","description":"Synchronize all components.","allowNo":false},"ext":{"name":"ext","type":"boolean","char":"e","description":"Synchronize with file extension. Default extension: '.sb.js'","allowNo":false},"packageName":{"name":"packageName","type":"boolean","char":"n","description":"Synchronize based on installed package name.","allowNo":false},"presets":{"name":"presets","type":"boolean","char":"p","description":"Synchronize components with presets.","allowNo":false},"lock":{"name":"lock","type":"boolean","char":"l","description":"Synchronize based on storyblok.components.lock.js file","allowNo":false}},"args":[{"name":"type","description":"What to synchronize","required":true,"options":["components","datasources","roles"]},{"name":"list","description":"Space separated list of component names. Example: card product-card row layout"}]}}}
|