sb-mig 5.5.4-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.d.ts +6 -2
- package/dist/api/data-migration/component-data-migration.js +35 -11
- 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 +5 -13
- 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/cli-descriptions.d.ts +1 -1
- package/dist/cli/cli-descriptions.js +4 -0
- package/dist/cli/commands/backup.js +7 -3
- package/dist/cli/commands/copy.js +2 -2
- package/dist/cli/commands/migrate.js +13 -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 +8 -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,23 @@
|
|
|
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.createClient = createClient;
|
|
7
|
+
const storyblok_js_client_1 = __importDefault(require("storyblok-js-client"));
|
|
8
|
+
function createClient(options) {
|
|
9
|
+
const sbApi = new storyblok_js_client_1.default({
|
|
10
|
+
oauthToken: options.oauthToken,
|
|
11
|
+
accessToken: options.accessToken,
|
|
12
|
+
rateLimit: options.rateLimit ?? 3,
|
|
13
|
+
cache: {
|
|
14
|
+
clear: "auto",
|
|
15
|
+
type: "none",
|
|
16
|
+
},
|
|
17
|
+
}, "https://mapi.storyblok.com/v1");
|
|
18
|
+
return {
|
|
19
|
+
config: options,
|
|
20
|
+
sbApi,
|
|
21
|
+
spaceId: options.spaceId,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getAllComponents = getAllComponents;
|
|
4
|
+
exports.getComponent = getComponent;
|
|
5
|
+
exports.getAllComponentsGroups = getAllComponentsGroups;
|
|
6
|
+
exports.getComponentsGroup = getComponentsGroup;
|
|
7
|
+
exports.createComponentsGroup = createComponentsGroup;
|
|
8
|
+
exports.removeComponentGroup = removeComponentGroup;
|
|
9
|
+
exports.removeComponent = removeComponent;
|
|
10
|
+
exports.createComponent = createComponent;
|
|
11
|
+
exports.updateComponent = updateComponent;
|
|
12
|
+
const components_js_1 = require("../../api/components/components.js");
|
|
13
|
+
const requestConfig_js_1 = require("../requestConfig.js");
|
|
14
|
+
async function getAllComponents(client) {
|
|
15
|
+
return await (0, components_js_1.getAllComponents)((0, requestConfig_js_1.toRequestConfig)(client));
|
|
16
|
+
}
|
|
17
|
+
async function getComponent(client, componentName) {
|
|
18
|
+
return await (0, components_js_1.getComponent)(componentName, (0, requestConfig_js_1.toRequestConfig)(client));
|
|
19
|
+
}
|
|
20
|
+
async function getAllComponentsGroups(client) {
|
|
21
|
+
return await (0, components_js_1.getAllComponentsGroups)((0, requestConfig_js_1.toRequestConfig)(client));
|
|
22
|
+
}
|
|
23
|
+
async function getComponentsGroup(client, groupName) {
|
|
24
|
+
return await (0, components_js_1.getComponentsGroup)(groupName, (0, requestConfig_js_1.toRequestConfig)(client));
|
|
25
|
+
}
|
|
26
|
+
async function createComponentsGroup(client, groupName) {
|
|
27
|
+
return await (0, components_js_1.createComponentsGroup)(groupName, (0, requestConfig_js_1.toRequestConfig)(client));
|
|
28
|
+
}
|
|
29
|
+
async function removeComponentGroup(client, componentGroup) {
|
|
30
|
+
return await (0, components_js_1.removeComponentGroup)(componentGroup, (0, requestConfig_js_1.toRequestConfig)(client));
|
|
31
|
+
}
|
|
32
|
+
async function removeComponent(client, component) {
|
|
33
|
+
return await (0, components_js_1.removeComponent)(component, (0, requestConfig_js_1.toRequestConfig)(client));
|
|
34
|
+
}
|
|
35
|
+
async function createComponent(client, component, presets = false) {
|
|
36
|
+
return await (0, components_js_1.createComponent)(component, presets, (0, requestConfig_js_1.toRequestConfig)(client));
|
|
37
|
+
}
|
|
38
|
+
async function updateComponent(client, component, presets = false) {
|
|
39
|
+
return await (0, components_js_1.updateComponent)(component, presets, (0, requestConfig_js_1.toRequestConfig)(client));
|
|
40
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getAllDatasources = getAllDatasources;
|
|
4
|
+
exports.getDatasource = getDatasource;
|
|
5
|
+
exports.createDatasource = createDatasource;
|
|
6
|
+
exports.updateDatasource = updateDatasource;
|
|
7
|
+
const request_js_1 = require("../../api/utils/request.js");
|
|
8
|
+
async function getAllDatasources(client) {
|
|
9
|
+
const spaceId = client.spaceId;
|
|
10
|
+
return (0, request_js_1.getAllItemsWithPagination)({
|
|
11
|
+
apiFn: ({ per_page, page }) => client.sbApi.get(`spaces/${spaceId}/datasources/`, {
|
|
12
|
+
per_page,
|
|
13
|
+
page,
|
|
14
|
+
}),
|
|
15
|
+
params: { spaceId },
|
|
16
|
+
itemsKey: "datasources",
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
async function getDatasource(client, datasourceName) {
|
|
20
|
+
const datasources = await getAllDatasources(client);
|
|
21
|
+
const match = datasources.filter((d) => d.name === datasourceName);
|
|
22
|
+
if (Array.isArray(match) && match.length === 0)
|
|
23
|
+
return false;
|
|
24
|
+
return match;
|
|
25
|
+
}
|
|
26
|
+
async function createDatasource(client, datasource) {
|
|
27
|
+
const spaceId = client.spaceId;
|
|
28
|
+
const finalDatasource = {
|
|
29
|
+
name: datasource.name,
|
|
30
|
+
slug: datasource.slug,
|
|
31
|
+
dimensions: [...(datasource.dimensions ?? [])],
|
|
32
|
+
dimensions_attributes: [...(datasource.dimensions ?? [])],
|
|
33
|
+
};
|
|
34
|
+
return client.sbApi
|
|
35
|
+
.post(`spaces/${spaceId}/datasources/`, {
|
|
36
|
+
datasource: finalDatasource,
|
|
37
|
+
})
|
|
38
|
+
.then((res) => res.data);
|
|
39
|
+
}
|
|
40
|
+
async function updateDatasource(client, args) {
|
|
41
|
+
const spaceId = client.spaceId;
|
|
42
|
+
const { datasource, datasourceToBeUpdated } = args;
|
|
43
|
+
const dimensionsToCreate = (datasource.dimensions ?? []).filter((dimension) => {
|
|
44
|
+
const isDimensionInRemoteDatasource = datasourceToBeUpdated.dimensions?.find((d) => dimension.name === d.name);
|
|
45
|
+
return !isDimensionInRemoteDatasource;
|
|
46
|
+
});
|
|
47
|
+
return client.sbApi
|
|
48
|
+
.put(`spaces/${spaceId}/datasources/${datasourceToBeUpdated.id}`, {
|
|
49
|
+
datasource: {
|
|
50
|
+
id: datasourceToBeUpdated.id,
|
|
51
|
+
name: datasource.name,
|
|
52
|
+
slug: datasource.slug,
|
|
53
|
+
dimensions: [
|
|
54
|
+
...(datasourceToBeUpdated.dimensions ?? []),
|
|
55
|
+
...dimensionsToCreate,
|
|
56
|
+
],
|
|
57
|
+
dimensions_attributes: [
|
|
58
|
+
...(datasourceToBeUpdated.dimensions ?? []),
|
|
59
|
+
...dimensionsToCreate,
|
|
60
|
+
],
|
|
61
|
+
},
|
|
62
|
+
})
|
|
63
|
+
.then((res) => res.data);
|
|
64
|
+
}
|
|
@@ -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; } });
|