sb-mig 5.6.0-beta.1 → 5.6.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -19
- package/dist/api/assets/assets.js +1 -14
- package/dist/api/components/components.js +2 -1
- package/dist/api/components/components.sync.d.ts +8 -0
- package/dist/api/components/components.sync.js +193 -0
- package/dist/api/data-migration/component-data-migration.js +2 -2
- package/dist/api/datasources/datasource-entries.js +4 -5
- package/dist/api/datasources/datasources.d.ts +5 -2
- package/dist/api/datasources/datasources.js +42 -35
- package/dist/api/datasources/datasources.sync.d.ts +2 -0
- package/dist/api/datasources/datasources.sync.js +11 -0
- package/dist/api/datasources/datasources.types.d.ts +1 -1
- package/dist/api/datasources/index.d.ts +2 -1
- package/dist/api/datasources/index.js +2 -1
- package/dist/api/managementApi.d.ts +2 -2
- package/dist/api/migrate.d.ts +1 -1
- package/dist/api/migrate.js +3 -48
- package/dist/api/plugins/index.d.ts +2 -1
- package/dist/api/plugins/index.js +2 -1
- package/dist/api/plugins/plugins.d.ts +7 -2
- package/dist/api/plugins/plugins.js +28 -15
- package/dist/api/plugins/plugins.sync.d.ts +2 -0
- package/dist/api/plugins/plugins.sync.js +11 -0
- package/dist/api/roles/index.d.ts +2 -1
- package/dist/api/roles/index.js +2 -1
- package/dist/api/roles/roles.d.ts +5 -2
- package/dist/api/roles/roles.js +34 -11
- package/dist/api/roles/roles.sync.d.ts +2 -0
- package/dist/api/roles/roles.sync.js +6 -0
- package/dist/api/roles/roles.types.d.ts +1 -1
- package/dist/api/stories/stories.js +3 -11
- package/dist/api/sync/sync.types.d.ts +30 -0
- package/dist/api/sync/sync.types.js +1 -0
- package/dist/api/testApi.d.ts +2 -2
- package/dist/api/utils/helper-functions.d.ts +5 -1
- package/dist/api/utils/helper-functions.js +6 -1
- package/dist/api/utils/request.d.ts +1 -1
- package/dist/api/utils/request.js +11 -2
- package/dist/api/utils/resolverTransformations.js +2 -57
- package/dist/api-v2/assets/index.d.ts +13 -0
- package/dist/api-v2/assets/index.js +25 -0
- package/dist/api-v2/auth/index.d.ts +3 -0
- package/dist/api-v2/auth/index.js +8 -0
- package/dist/api-v2/client.d.ts +13 -0
- package/dist/api-v2/client.js +17 -0
- package/dist/api-v2/components/index.d.ts +10 -0
- package/dist/api-v2/components/index.js +29 -0
- package/dist/api-v2/datasources/index.d.ts +8 -0
- package/dist/api-v2/datasources/index.js +58 -0
- package/dist/api-v2/discover/discover.d.ts +36 -0
- package/dist/api-v2/discover/discover.js +281 -0
- package/dist/api-v2/discover/index.d.ts +2 -0
- package/dist/api-v2/discover/index.js +1 -0
- package/dist/api-v2/index.d.ts +19 -0
- package/dist/api-v2/index.js +21 -0
- package/dist/api-v2/plugins/index.d.ts +9 -0
- package/dist/api-v2/plugins/index.js +42 -0
- package/dist/api-v2/precompile/index.d.ts +2 -0
- package/dist/api-v2/precompile/index.js +1 -0
- package/dist/api-v2/precompile/precompile.d.ts +65 -0
- package/dist/api-v2/precompile/precompile.js +127 -0
- package/dist/api-v2/presets/index.d.ts +13 -0
- package/dist/api-v2/presets/index.js +25 -0
- package/dist/api-v2/requestConfig.d.ts +5 -0
- package/dist/api-v2/requestConfig.js +34 -0
- package/dist/api-v2/roles/index.d.ts +5 -0
- package/dist/api-v2/roles/index.js +35 -0
- package/dist/api-v2/spaces/index.d.ts +7 -0
- package/dist/api-v2/spaces/index.js +11 -0
- package/dist/api-v2/stories/index.d.ts +34 -0
- package/dist/api-v2/stories/index.js +172 -0
- package/dist/api-v2/stories/types.d.ts +28 -0
- package/dist/api-v2/stories/types.js +1 -0
- package/dist/api-v2/sync/index.d.ts +24 -0
- package/dist/api-v2/sync/index.js +109 -0
- package/dist/api-v2/sync/types.d.ts +1 -0
- package/dist/api-v2/sync/types.js +1 -0
- package/dist/api-v2/test.d.ts +15 -0
- package/dist/api-v2/test.js +21 -0
- package/dist/cli/commands/backup.js +7 -3
- package/dist/cli/commands/copy.js +2 -2
- package/dist/cli/commands/migrate.js +1 -2
- package/dist/cli/commands/migrations.js +2 -2
- package/dist/cli/commands/remove.js +1 -1
- package/dist/cli/commands/revert.js +2 -2
- package/dist/cli/commands/sync.js +1 -2
- package/dist/cli/index.js +1 -1
- package/dist/cli/utils/cli-utils.d.ts +69 -0
- package/dist/cli/utils/cli-utils.js +100 -0
- package/dist/cli/utils/discover.d.ts +3 -22
- package/dist/cli/utils/discover.js +4 -51
- package/dist/config/config.d.ts +2 -39
- package/dist/config/config.types.d.ts +40 -0
- package/dist/config/config.types.js +1 -0
- package/dist/config/defaultConfig.d.ts +1 -1
- package/dist/config/defaultConfig.js +2 -2
- package/dist/utils/array-utils.d.ts +20 -0
- package/dist/utils/array-utils.js +20 -0
- package/dist/utils/async-utils.d.ts +13 -0
- package/dist/utils/async-utils.js +13 -0
- package/dist/utils/date-utils.d.ts +14 -0
- package/dist/utils/date-utils.js +21 -0
- package/dist/utils/files.d.ts +35 -0
- package/dist/utils/files.js +57 -2
- package/dist/utils/main.d.ts +8 -18
- package/dist/utils/main.js +12 -104
- package/dist/utils/migrations.d.ts +9 -3
- package/dist/utils/object-utils.d.ts +46 -0
- package/dist/utils/object-utils.js +71 -0
- package/dist/utils/others.d.ts +6 -9
- package/dist/utils/others.js +8 -15
- package/dist/utils/path-utils.d.ts +89 -0
- package/dist/utils/path-utils.js +106 -0
- package/dist/utils/pkg.d.ts +16 -2
- package/dist/utils/pkg.js +16 -3
- package/dist/utils/string-utils.d.ts +33 -0
- package/dist/utils/string-utils.js +45 -0
- package/dist/utils/transform-utils.d.ts +62 -0
- package/dist/utils/transform-utils.js +113 -0
- package/dist-cjs/api/auth/auth.js +28 -0
- package/dist-cjs/api/auth/auth.types.js +2 -0
- package/dist-cjs/api/components/components.js +202 -0
- package/dist-cjs/api/components/components.sync.js +199 -0
- package/dist-cjs/api/components/components.types.js +2 -0
- package/dist-cjs/api/datasources/datasource-entries.js +166 -0
- package/dist-cjs/api/datasources/datasources.js +166 -0
- package/dist-cjs/api/datasources/datasources.types.js +2 -0
- package/dist-cjs/api/plugins/plugins.js +132 -0
- package/dist-cjs/api/plugins/plugins.types.js +2 -0
- package/dist-cjs/api/presets/componentPresets.js +25 -0
- package/dist-cjs/api/presets/presets.js +92 -0
- package/dist-cjs/api/presets/presets.types.js +2 -0
- package/dist-cjs/api/presets/resolvePresets.js +49 -0
- package/dist-cjs/api/roles/roles.js +131 -0
- package/dist-cjs/api/roles/roles.types.js +2 -0
- package/dist-cjs/api/spaces/spaces.js +34 -0
- package/dist-cjs/api/spaces/spaces.types.js +2 -0
- package/dist-cjs/api/stories/stories.js +214 -0
- package/dist-cjs/api/stories/stories.types.js +2 -0
- package/dist-cjs/api/sync/sync.types.js +2 -0
- package/dist-cjs/api/utils/request.js +48 -0
- package/dist-cjs/api/utils/resolvers.types.js +2 -0
- package/dist-cjs/api-v2/assets/index.js +30 -0
- package/dist-cjs/api-v2/auth/index.js +12 -0
- package/dist-cjs/api-v2/client.js +23 -0
- package/dist-cjs/api-v2/components/index.js +40 -0
- package/dist-cjs/api-v2/datasources/index.js +64 -0
- package/dist-cjs/api-v2/discover/discover.js +321 -0
- package/dist-cjs/api-v2/discover/index.js +9 -0
- package/dist-cjs/api-v2/index.js +60 -0
- package/dist-cjs/api-v2/plugins/index.js +49 -0
- package/dist-cjs/api-v2/precompile/index.js +7 -0
- package/dist-cjs/api-v2/precompile/precompile.js +136 -0
- package/dist-cjs/api-v2/presets/index.js +33 -0
- package/dist-cjs/api-v2/requestConfig.js +37 -0
- package/dist-cjs/api-v2/roles/index.js +41 -0
- package/dist-cjs/api-v2/spaces/index.js +16 -0
- package/dist-cjs/api-v2/stories/index.js +180 -0
- package/dist-cjs/api-v2/stories/types.js +2 -0
- package/dist-cjs/api-v2/sync/index.js +115 -0
- package/dist-cjs/api-v2/sync/types.js +2 -0
- package/dist-cjs/api-v2/test.js +25 -0
- package/dist-cjs/config/config.types.js +2 -0
- package/dist-cjs/config/constants.js +29 -0
- package/dist-cjs/package.json +3 -0
- package/dist-cjs/utils/array-utils.js +24 -0
- package/dist-cjs/utils/logger.js +32 -0
- package/dist-cjs/utils/object-utils.js +77 -0
- package/dist-cjs/utils/path-utils.js +115 -0
- package/package.json +37 -20
- package/dist/utils/pkg-require.d.ts +0 -2
- package/dist/utils/pkg-require.js +0 -4
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.loadResourceContent = loadResourceContent;
|
|
37
|
+
exports.loadResources = loadResources;
|
|
38
|
+
exports.discoverComponents = discoverComponents;
|
|
39
|
+
exports.discoverDatasources = discoverDatasources;
|
|
40
|
+
exports.discoverRoles = discoverRoles;
|
|
41
|
+
const promises_1 = require("fs/promises");
|
|
42
|
+
const path_1 = require("path");
|
|
43
|
+
const url_1 = require("url");
|
|
44
|
+
/**
|
|
45
|
+
* Load the content of a resource file (.sb.js, .datasource.js, etc.)
|
|
46
|
+
* Uses dynamic import to load ES modules and CommonJS
|
|
47
|
+
*/
|
|
48
|
+
async function loadResourceContent(filePath) {
|
|
49
|
+
try {
|
|
50
|
+
// Use dynamic import which works for both ESM and CJS
|
|
51
|
+
const fileUrl = (0, url_1.pathToFileURL)(filePath).href;
|
|
52
|
+
const module = await Promise.resolve(`${fileUrl}`).then(s => __importStar(require(s)));
|
|
53
|
+
return module.default || module;
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
throw new Error(`Failed to load ${filePath}: ${error instanceof Error ? error.message : String(error)}`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Load multiple resources by file path
|
|
61
|
+
*/
|
|
62
|
+
async function loadResources(filePaths) {
|
|
63
|
+
const results = [];
|
|
64
|
+
for (const filePath of filePaths) {
|
|
65
|
+
const name = filePath
|
|
66
|
+
.split("/")
|
|
67
|
+
.pop()
|
|
68
|
+
?.replace(/\.sb\.(js|cjs|mjs|ts)$/, "")
|
|
69
|
+
.replace(/\.(datasource|roles)\.(js|cjs|ts)$/, "")
|
|
70
|
+
.replace(/\.sb\.(datasource|roles)\.(js|cjs|ts)$/, "") ||
|
|
71
|
+
"unknown";
|
|
72
|
+
try {
|
|
73
|
+
const data = await loadResourceContent(filePath);
|
|
74
|
+
results.push({ name, filePath, data });
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
results.push({
|
|
78
|
+
name,
|
|
79
|
+
filePath,
|
|
80
|
+
data: null,
|
|
81
|
+
error: error instanceof Error ? error.message : String(error),
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return results;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Read componentsDirectories from storyblok.config.js if it exists
|
|
89
|
+
*/
|
|
90
|
+
async function readComponentDirectories(workingDir) {
|
|
91
|
+
const configFiles = [
|
|
92
|
+
"storyblok.config.js",
|
|
93
|
+
"storyblok.config.cjs",
|
|
94
|
+
"storyblok.config.mjs",
|
|
95
|
+
];
|
|
96
|
+
for (const configFile of configFiles) {
|
|
97
|
+
try {
|
|
98
|
+
const configPath = (0, path_1.join)(workingDir, configFile);
|
|
99
|
+
const configContent = await (0, promises_1.readFile)(configPath, "utf-8");
|
|
100
|
+
const match = configContent.match(/componentsDirectories\s*:\s*\[([\s\S]*?)\]/);
|
|
101
|
+
if (match && match[1]) {
|
|
102
|
+
const dirsMatch = match[1].match(/['"]([^'"]+)['"]/g);
|
|
103
|
+
if (dirsMatch) {
|
|
104
|
+
return dirsMatch.map((d) => d.replace(/['"]/g, ""));
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
break;
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
// Config file doesn't exist, continue
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return ["src", "components", "storyblok"];
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Discover components in the working directory
|
|
117
|
+
* Prefers .ts for local files and .cjs for external (node_modules) files
|
|
118
|
+
* to avoid duplicates when both ESM and CJS versions exist
|
|
119
|
+
*/
|
|
120
|
+
async function discoverComponents(workingDir, options) {
|
|
121
|
+
const components = [];
|
|
122
|
+
// Priority order: .ts first (local), then .cjs (for node_modules)
|
|
123
|
+
// Skip .js and .mjs to avoid duplicates
|
|
124
|
+
const extensions = options?.extensions ?? [".sb.ts", ".sb.cjs"];
|
|
125
|
+
const componentDirs = await readComponentDirectories(workingDir);
|
|
126
|
+
const scanDir = async (dir, isExternal) => {
|
|
127
|
+
try {
|
|
128
|
+
const entries = await (0, promises_1.readdir)(dir, { withFileTypes: true });
|
|
129
|
+
for (const entry of entries) {
|
|
130
|
+
const fullPath = (0, path_1.join)(dir, entry.name);
|
|
131
|
+
if (entry.isDirectory()) {
|
|
132
|
+
if (entry.name === ".git" ||
|
|
133
|
+
entry.name === ".next" ||
|
|
134
|
+
entry.name === "dist") {
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
const isNowExternal = isExternal || entry.name === "node_modules";
|
|
138
|
+
await scanDir(fullPath, isNowExternal);
|
|
139
|
+
}
|
|
140
|
+
else if (entry.isFile()) {
|
|
141
|
+
for (const ext of extensions) {
|
|
142
|
+
if (entry.name.endsWith(ext) &&
|
|
143
|
+
!entry.name.startsWith("_")) {
|
|
144
|
+
const componentName = entry.name.replace(ext, "");
|
|
145
|
+
components.push({
|
|
146
|
+
name: componentName,
|
|
147
|
+
filePath: fullPath,
|
|
148
|
+
type: isExternal ? "external" : "local",
|
|
149
|
+
});
|
|
150
|
+
break;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
catch {
|
|
157
|
+
// Directory doesn't exist or can't be read
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
for (const dir of componentDirs) {
|
|
161
|
+
const fullDir = (0, path_1.join)(workingDir, dir);
|
|
162
|
+
try {
|
|
163
|
+
const dirStat = await (0, promises_1.stat)(fullDir);
|
|
164
|
+
if (dirStat.isDirectory()) {
|
|
165
|
+
await scanDir(fullDir, dir.includes("node_modules"));
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
catch {
|
|
169
|
+
// Directory doesn't exist
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
// Also scan root
|
|
173
|
+
try {
|
|
174
|
+
const rootEntries = await (0, promises_1.readdir)(workingDir, { withFileTypes: true });
|
|
175
|
+
for (const entry of rootEntries) {
|
|
176
|
+
if (entry.isFile()) {
|
|
177
|
+
for (const ext of extensions) {
|
|
178
|
+
if (entry.name.endsWith(ext) &&
|
|
179
|
+
!entry.name.startsWith("_")) {
|
|
180
|
+
const componentName = entry.name.replace(ext, "");
|
|
181
|
+
if (!components.find((c) => c.name === componentName)) {
|
|
182
|
+
components.push({
|
|
183
|
+
name: componentName,
|
|
184
|
+
filePath: (0, path_1.join)(workingDir, entry.name),
|
|
185
|
+
type: "local",
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
break;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
catch {
|
|
195
|
+
// Ignore
|
|
196
|
+
}
|
|
197
|
+
// Deduplicate: prefer .ts over .cjs for same component name
|
|
198
|
+
const seen = new Map();
|
|
199
|
+
for (const component of components) {
|
|
200
|
+
const existing = seen.get(component.name);
|
|
201
|
+
if (!existing) {
|
|
202
|
+
seen.set(component.name, component);
|
|
203
|
+
}
|
|
204
|
+
else {
|
|
205
|
+
// Prefer .ts files over .cjs
|
|
206
|
+
if (component.filePath.endsWith(".ts") &&
|
|
207
|
+
!existing.filePath.endsWith(".ts")) {
|
|
208
|
+
seen.set(component.name, component);
|
|
209
|
+
}
|
|
210
|
+
// Prefer local over external
|
|
211
|
+
else if (component.type === "local" &&
|
|
212
|
+
existing.type === "external") {
|
|
213
|
+
seen.set(component.name, component);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
const deduplicated = Array.from(seen.values());
|
|
218
|
+
// Sort: local first, then by name
|
|
219
|
+
deduplicated.sort((a, b) => {
|
|
220
|
+
if (a.type !== b.type) {
|
|
221
|
+
return a.type === "local" ? -1 : 1;
|
|
222
|
+
}
|
|
223
|
+
return a.name.localeCompare(b.name);
|
|
224
|
+
});
|
|
225
|
+
return deduplicated;
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Discover datasources in the working directory
|
|
229
|
+
*/
|
|
230
|
+
async function discoverDatasources(workingDir) {
|
|
231
|
+
const datasources = [];
|
|
232
|
+
const extensions = [
|
|
233
|
+
".datasource.js",
|
|
234
|
+
".datasource.cjs",
|
|
235
|
+
".sb.datasource.js",
|
|
236
|
+
".sb.datasource.cjs",
|
|
237
|
+
];
|
|
238
|
+
const scanDir = async (dir) => {
|
|
239
|
+
try {
|
|
240
|
+
const entries = await (0, promises_1.readdir)(dir, { withFileTypes: true });
|
|
241
|
+
for (const entry of entries) {
|
|
242
|
+
const fullPath = (0, path_1.join)(dir, entry.name);
|
|
243
|
+
if (entry.isDirectory()) {
|
|
244
|
+
if (entry.name === ".git" ||
|
|
245
|
+
entry.name === ".next" ||
|
|
246
|
+
entry.name === "dist" ||
|
|
247
|
+
entry.name === "node_modules") {
|
|
248
|
+
continue;
|
|
249
|
+
}
|
|
250
|
+
await scanDir(fullPath);
|
|
251
|
+
}
|
|
252
|
+
else if (entry.isFile()) {
|
|
253
|
+
for (const ext of extensions) {
|
|
254
|
+
if (entry.name.endsWith(ext) &&
|
|
255
|
+
!entry.name.startsWith("_")) {
|
|
256
|
+
const name = entry.name
|
|
257
|
+
.replace(ext, "")
|
|
258
|
+
.replace(".sb", "");
|
|
259
|
+
datasources.push({
|
|
260
|
+
name,
|
|
261
|
+
filePath: fullPath,
|
|
262
|
+
type: "local",
|
|
263
|
+
});
|
|
264
|
+
break;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
catch {
|
|
271
|
+
// Skip
|
|
272
|
+
}
|
|
273
|
+
};
|
|
274
|
+
await scanDir(workingDir);
|
|
275
|
+
datasources.sort((a, b) => a.name.localeCompare(b.name));
|
|
276
|
+
return datasources;
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Discover roles in the working directory
|
|
280
|
+
*/
|
|
281
|
+
async function discoverRoles(workingDir) {
|
|
282
|
+
const roles = [];
|
|
283
|
+
const extensions = [".sb.roles.js", ".sb.roles.cjs", ".sb.roles.ts"];
|
|
284
|
+
const scanDir = async (dir) => {
|
|
285
|
+
try {
|
|
286
|
+
const entries = await (0, promises_1.readdir)(dir, { withFileTypes: true });
|
|
287
|
+
for (const entry of entries) {
|
|
288
|
+
const fullPath = (0, path_1.join)(dir, entry.name);
|
|
289
|
+
if (entry.isDirectory()) {
|
|
290
|
+
if (entry.name === ".git" ||
|
|
291
|
+
entry.name === ".next" ||
|
|
292
|
+
entry.name === "dist" ||
|
|
293
|
+
entry.name === "node_modules") {
|
|
294
|
+
continue;
|
|
295
|
+
}
|
|
296
|
+
await scanDir(fullPath);
|
|
297
|
+
}
|
|
298
|
+
else if (entry.isFile()) {
|
|
299
|
+
for (const ext of extensions) {
|
|
300
|
+
if (entry.name.endsWith(ext) &&
|
|
301
|
+
!entry.name.startsWith("_")) {
|
|
302
|
+
const name = entry.name.replace(ext, "");
|
|
303
|
+
roles.push({
|
|
304
|
+
name,
|
|
305
|
+
filePath: fullPath,
|
|
306
|
+
type: "local",
|
|
307
|
+
});
|
|
308
|
+
break;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
catch {
|
|
315
|
+
// Skip
|
|
316
|
+
}
|
|
317
|
+
};
|
|
318
|
+
await scanDir(workingDir);
|
|
319
|
+
roles.sort((a, b) => a.name.localeCompare(b.name));
|
|
320
|
+
return roles;
|
|
321
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.loadResources = exports.loadResourceContent = exports.discoverRoles = exports.discoverDatasources = exports.discoverComponents = void 0;
|
|
4
|
+
var discover_js_1 = require("./discover.js");
|
|
5
|
+
Object.defineProperty(exports, "discoverComponents", { enumerable: true, get: function () { return discover_js_1.discoverComponents; } });
|
|
6
|
+
Object.defineProperty(exports, "discoverDatasources", { enumerable: true, get: function () { return discover_js_1.discoverDatasources; } });
|
|
7
|
+
Object.defineProperty(exports, "discoverRoles", { enumerable: true, get: function () { return discover_js_1.discoverRoles; } });
|
|
8
|
+
Object.defineProperty(exports, "loadResourceContent", { enumerable: true, get: function () { return discover_js_1.loadResourceContent; } });
|
|
9
|
+
Object.defineProperty(exports, "loadResources", { enumerable: true, get: function () { return discover_js_1.loadResources; } });
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.precompile = exports.discover = exports.sync = exports.spaces = exports.roles = exports.presets = exports.plugins = exports.datasources = exports.components = exports.auth = exports.assets = exports.stories = exports.createClient = exports.testAsyncConnection = exports.testConnection = void 0;
|
|
37
|
+
// Test functions for ESM/CJS interop testing
|
|
38
|
+
var test_js_1 = require("./test.js");
|
|
39
|
+
Object.defineProperty(exports, "testConnection", { enumerable: true, get: function () { return test_js_1.testConnection; } });
|
|
40
|
+
Object.defineProperty(exports, "testAsyncConnection", { enumerable: true, get: function () { return test_js_1.testAsyncConnection; } });
|
|
41
|
+
// Client
|
|
42
|
+
var client_js_1 = require("./client.js");
|
|
43
|
+
Object.defineProperty(exports, "createClient", { enumerable: true, get: function () { return client_js_1.createClient; } });
|
|
44
|
+
// Stories
|
|
45
|
+
exports.stories = __importStar(require("./stories/index.js"));
|
|
46
|
+
// Resources (thin wrappers)
|
|
47
|
+
exports.assets = __importStar(require("./assets/index.js"));
|
|
48
|
+
exports.auth = __importStar(require("./auth/index.js"));
|
|
49
|
+
exports.components = __importStar(require("./components/index.js"));
|
|
50
|
+
exports.datasources = __importStar(require("./datasources/index.js"));
|
|
51
|
+
exports.plugins = __importStar(require("./plugins/index.js"));
|
|
52
|
+
exports.presets = __importStar(require("./presets/index.js"));
|
|
53
|
+
exports.roles = __importStar(require("./roles/index.js"));
|
|
54
|
+
exports.spaces = __importStar(require("./spaces/index.js"));
|
|
55
|
+
// Sync (data-only)
|
|
56
|
+
exports.sync = __importStar(require("./sync/index.js"));
|
|
57
|
+
// Discovery
|
|
58
|
+
exports.discover = __importStar(require("./discover/index.js"));
|
|
59
|
+
// Precompile (TypeScript to JS using Rollup + SWC)
|
|
60
|
+
exports.precompile = __importStar(require("./precompile/index.js"));
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getAllPlugins = getAllPlugins;
|
|
4
|
+
exports.getPlugin = getPlugin;
|
|
5
|
+
exports.getPluginDetails = getPluginDetails;
|
|
6
|
+
exports.updatePlugin = updatePlugin;
|
|
7
|
+
exports.createPlugin = createPlugin;
|
|
8
|
+
const request_js_1 = require("../../api/utils/request.js");
|
|
9
|
+
async function getAllPlugins(client) {
|
|
10
|
+
return (0, request_js_1.getAllItemsWithPagination)({
|
|
11
|
+
apiFn: ({ per_page, page }) => client.sbApi.get("field_types", { per_page, page }),
|
|
12
|
+
params: {},
|
|
13
|
+
itemsKey: "field_types",
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
async function getPlugin(client, pluginName) {
|
|
17
|
+
const plugins = await getAllPlugins(client);
|
|
18
|
+
const plugin = plugins.find((p) => p.name === pluginName);
|
|
19
|
+
if (!plugin)
|
|
20
|
+
return false;
|
|
21
|
+
return await getPluginDetails(client, plugin);
|
|
22
|
+
}
|
|
23
|
+
async function getPluginDetails(client, plugin) {
|
|
24
|
+
return client.sbApi
|
|
25
|
+
.get(`field_types/${plugin.id}`)
|
|
26
|
+
.then((res) => res.data);
|
|
27
|
+
}
|
|
28
|
+
async function updatePlugin(client, args) {
|
|
29
|
+
const { plugin, body } = args;
|
|
30
|
+
return client.sbApi
|
|
31
|
+
.put(`field_types/${plugin.id}`, {
|
|
32
|
+
publish: true,
|
|
33
|
+
field_type: {
|
|
34
|
+
body,
|
|
35
|
+
compiled_body: "",
|
|
36
|
+
},
|
|
37
|
+
})
|
|
38
|
+
.then((res) => res.data);
|
|
39
|
+
}
|
|
40
|
+
async function createPlugin(client, pluginName) {
|
|
41
|
+
return client.sbApi
|
|
42
|
+
.post("field_types", {
|
|
43
|
+
publish: true,
|
|
44
|
+
field_type: {
|
|
45
|
+
name: pluginName,
|
|
46
|
+
},
|
|
47
|
+
})
|
|
48
|
+
.then((res) => res.data);
|
|
49
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getCompiledPath = exports.extractComponentName = exports.precompile = void 0;
|
|
4
|
+
var precompile_js_1 = require("./precompile.js");
|
|
5
|
+
Object.defineProperty(exports, "precompile", { enumerable: true, get: function () { return precompile_js_1.precompile; } });
|
|
6
|
+
Object.defineProperty(exports, "extractComponentName", { enumerable: true, get: function () { return precompile_js_1.extractComponentName; } });
|
|
7
|
+
Object.defineProperty(exports, "getCompiledPath", { enumerable: true, get: function () { return precompile_js_1.getCompiledPath; } });
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.extractComponentName = void 0;
|
|
7
|
+
exports.precompile = precompile;
|
|
8
|
+
exports.getCompiledPath = getCompiledPath;
|
|
9
|
+
const promises_1 = require("fs/promises");
|
|
10
|
+
const path_1 = __importDefault(require("path"));
|
|
11
|
+
const rollup_1 = require("rollup");
|
|
12
|
+
const rollup_plugin_ts_1 = __importDefault(require("rollup-plugin-ts"));
|
|
13
|
+
/**
|
|
14
|
+
* Extract the component name from a file path
|
|
15
|
+
* e.g., "/path/to/my-component.sb.ts" -> "my-component.sb"
|
|
16
|
+
*/
|
|
17
|
+
const extractComponentName = (filePath) => {
|
|
18
|
+
const separator = "/";
|
|
19
|
+
const parts = filePath.split(separator);
|
|
20
|
+
const lastElement = parts[parts.length - 1];
|
|
21
|
+
return lastElement.replace(/\.ts$/, "");
|
|
22
|
+
};
|
|
23
|
+
exports.extractComponentName = extractComponentName;
|
|
24
|
+
/**
|
|
25
|
+
* Build a single file using Rollup
|
|
26
|
+
*/
|
|
27
|
+
async function buildFile(inputPath, outputCjs, outputEsm) {
|
|
28
|
+
const inputOptions = {
|
|
29
|
+
input: inputPath,
|
|
30
|
+
plugins: [
|
|
31
|
+
(0, rollup_plugin_ts_1.default)({
|
|
32
|
+
transpileOnly: true,
|
|
33
|
+
transpiler: "swc",
|
|
34
|
+
}),
|
|
35
|
+
],
|
|
36
|
+
};
|
|
37
|
+
const outputOptionsList = [
|
|
38
|
+
{ file: outputCjs, format: "cjs" },
|
|
39
|
+
{ file: outputEsm, format: "es" },
|
|
40
|
+
];
|
|
41
|
+
let bundle;
|
|
42
|
+
try {
|
|
43
|
+
bundle = await (0, rollup_1.rollup)(inputOptions);
|
|
44
|
+
for (const outputOptions of outputOptionsList) {
|
|
45
|
+
await bundle.write(outputOptions);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
finally {
|
|
49
|
+
if (bundle) {
|
|
50
|
+
await bundle.close();
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Precompile TypeScript schema files to JavaScript
|
|
56
|
+
*
|
|
57
|
+
* This uses Rollup with SWC for fast transpilation, producing
|
|
58
|
+
* both CommonJS (.cjs) and ESM (.js) outputs.
|
|
59
|
+
*
|
|
60
|
+
* @param files - Array of TypeScript file paths to compile
|
|
61
|
+
* @param options - Precompile options
|
|
62
|
+
* @returns Result with compiled files and any errors
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```ts
|
|
66
|
+
* const result = await precompile([
|
|
67
|
+
* '/path/to/hero.sb.ts',
|
|
68
|
+
* '/path/to/card.sb.ts',
|
|
69
|
+
* ], { cacheDir: '.cache/sb-mig' });
|
|
70
|
+
*
|
|
71
|
+
* // Use compiled CJS files
|
|
72
|
+
* for (const compiled of result.compiled) {
|
|
73
|
+
* const content = require(compiled.outputCjs);
|
|
74
|
+
* }
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
async function precompile(files, options = {}) {
|
|
78
|
+
const { cacheDir = ".sb-mig-cache", flushCache = true, projectDir = process.cwd(), } = options;
|
|
79
|
+
const fullCacheDir = path_1.default.join(projectDir, cacheDir, "sb-mig");
|
|
80
|
+
// Optionally clear cache
|
|
81
|
+
if (flushCache) {
|
|
82
|
+
try {
|
|
83
|
+
await (0, promises_1.rm)(fullCacheDir, { recursive: true, force: true });
|
|
84
|
+
}
|
|
85
|
+
catch {
|
|
86
|
+
// Ignore if doesn't exist
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
// Ensure cache directory exists
|
|
90
|
+
await (0, promises_1.mkdir)(fullCacheDir, { recursive: true });
|
|
91
|
+
const result = {
|
|
92
|
+
compiled: [],
|
|
93
|
+
errors: [],
|
|
94
|
+
};
|
|
95
|
+
// Filter to only TypeScript files
|
|
96
|
+
const tsFiles = files.filter((f) => f.endsWith(".ts"));
|
|
97
|
+
if (tsFiles.length === 0) {
|
|
98
|
+
return result;
|
|
99
|
+
}
|
|
100
|
+
// Compile all files in parallel
|
|
101
|
+
await Promise.all(tsFiles.map(async (inputPath) => {
|
|
102
|
+
const componentName = (0, exports.extractComponentName)(inputPath);
|
|
103
|
+
const outputCjs = path_1.default.join(fullCacheDir, `${componentName}.cjs`);
|
|
104
|
+
const outputEsm = path_1.default.join(fullCacheDir, `${componentName}.js`);
|
|
105
|
+
try {
|
|
106
|
+
await buildFile(inputPath, outputCjs, outputEsm);
|
|
107
|
+
result.compiled.push({
|
|
108
|
+
input: inputPath,
|
|
109
|
+
outputCjs,
|
|
110
|
+
outputEsm,
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
catch (error) {
|
|
114
|
+
result.errors.push({
|
|
115
|
+
input: inputPath,
|
|
116
|
+
error: error instanceof Error ? error.message : String(error),
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
}));
|
|
120
|
+
return result;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Get the compiled file path for a TypeScript source file
|
|
124
|
+
*
|
|
125
|
+
* @param tsFilePath - Original .ts file path
|
|
126
|
+
* @param options - Options with cacheDir and projectDir
|
|
127
|
+
* @param format - Output format ('cjs' or 'esm')
|
|
128
|
+
* @returns Path to the compiled file
|
|
129
|
+
*/
|
|
130
|
+
function getCompiledPath(tsFilePath, options = {}, format = "cjs") {
|
|
131
|
+
const { cacheDir = ".sb-mig-cache", projectDir = process.cwd() } = options;
|
|
132
|
+
const fullCacheDir = path_1.default.join(projectDir, cacheDir, "sb-mig");
|
|
133
|
+
const componentName = (0, exports.extractComponentName)(tsFilePath);
|
|
134
|
+
const ext = format === "cjs" ? ".cjs" : ".js";
|
|
135
|
+
return path_1.default.join(fullCacheDir, `${componentName}${ext}`);
|
|
136
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getAllPresets = getAllPresets;
|
|
4
|
+
exports.getPreset = getPreset;
|
|
5
|
+
exports.createPreset = createPreset;
|
|
6
|
+
exports.updatePreset = updatePreset;
|
|
7
|
+
exports.updatePresets = updatePresets;
|
|
8
|
+
exports.getComponentPresets = getComponentPresets;
|
|
9
|
+
const componentPresets_js_1 = require("../../api/presets/componentPresets.js");
|
|
10
|
+
const presets_js_1 = require("../../api/presets/presets.js");
|
|
11
|
+
const requestConfig_js_1 = require("../requestConfig.js");
|
|
12
|
+
async function getAllPresets(client) {
|
|
13
|
+
return await (0, presets_js_1.getAllPresets)((0, requestConfig_js_1.toRequestConfig)(client));
|
|
14
|
+
}
|
|
15
|
+
async function getPreset(client, presetId) {
|
|
16
|
+
return await (0, presets_js_1.getPreset)({ presetId }, (0, requestConfig_js_1.toRequestConfig)(client));
|
|
17
|
+
}
|
|
18
|
+
async function createPreset(client, preset) {
|
|
19
|
+
return await (0, presets_js_1.createPreset)(preset, (0, requestConfig_js_1.toRequestConfig)(client));
|
|
20
|
+
}
|
|
21
|
+
async function updatePreset(client, preset) {
|
|
22
|
+
return await (0, presets_js_1.updatePreset)({ p: preset }, (0, requestConfig_js_1.toRequestConfig)(client));
|
|
23
|
+
}
|
|
24
|
+
async function updatePresets(client, args) {
|
|
25
|
+
return await (0, presets_js_1.updatePresets)({
|
|
26
|
+
presets: args.presets,
|
|
27
|
+
spaceId: args.spaceId,
|
|
28
|
+
options: args.options ?? {},
|
|
29
|
+
}, (0, requestConfig_js_1.toRequestConfig)(client));
|
|
30
|
+
}
|
|
31
|
+
async function getComponentPresets(client, componentName) {
|
|
32
|
+
return await (0, componentPresets_js_1.getComponentPresets)(componentName, (0, requestConfig_js_1.toRequestConfig)(client));
|
|
33
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toRequestConfig = toRequestConfig;
|
|
4
|
+
function toRequestConfig(client, overrides) {
|
|
5
|
+
return {
|
|
6
|
+
spaceId: overrides?.spaceId ?? client.spaceId,
|
|
7
|
+
sbApi: client.sbApi,
|
|
8
|
+
oauthToken: overrides?.oauthToken ?? client.config.oauthToken,
|
|
9
|
+
accessToken: overrides?.accessToken ?? client.config.accessToken,
|
|
10
|
+
storyblokApiUrl: overrides?.storyblokApiUrl,
|
|
11
|
+
storyblokDeliveryApiUrl: overrides?.storyblokDeliveryApiUrl,
|
|
12
|
+
storyblokGraphqlApiUrl: overrides?.storyblokGraphqlApiUrl,
|
|
13
|
+
schemaFileExt: overrides?.schemaFileExt,
|
|
14
|
+
datasourceExt: overrides?.datasourceExt,
|
|
15
|
+
rolesExt: overrides?.rolesExt,
|
|
16
|
+
storiesExt: overrides?.storiesExt,
|
|
17
|
+
migrationConfigExt: overrides?.migrationConfigExt,
|
|
18
|
+
sbmigWorkingDirectory: overrides?.sbmigWorkingDirectory,
|
|
19
|
+
presetsBackupDirectory: overrides?.presetsBackupDirectory,
|
|
20
|
+
storiesBackupDirectory: overrides?.storiesBackupDirectory,
|
|
21
|
+
componentsDirectories: overrides?.componentsDirectories,
|
|
22
|
+
flushCache: overrides?.flushCache,
|
|
23
|
+
cacheDir: overrides?.cacheDir,
|
|
24
|
+
debug: overrides?.debug,
|
|
25
|
+
rateLimit: overrides?.rateLimit,
|
|
26
|
+
openaiToken: overrides?.openaiToken,
|
|
27
|
+
boilerplateSpaceId: overrides?.boilerplateSpaceId,
|
|
28
|
+
schemaType: overrides?.schemaType,
|
|
29
|
+
awsBucketData: overrides?.awsBucketData,
|
|
30
|
+
metadataSelection: overrides?.metadataSelection,
|
|
31
|
+
contentHubOriginUrl: overrides?.contentHubOriginUrl,
|
|
32
|
+
contentHubAuthorizationToken: overrides?.contentHubAuthorizationToken,
|
|
33
|
+
resolvers: overrides?.resolvers,
|
|
34
|
+
advancedResolvers: overrides?.advancedResolvers,
|
|
35
|
+
storyblokComponentsLocalDirectory: overrides?.storyblokComponentsLocalDirectory,
|
|
36
|
+
};
|
|
37
|
+
}
|