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
|
@@ -2,12 +2,11 @@ import { managementApi } from "../../api/managementApi.js";
|
|
|
2
2
|
import { removeAllComponents, syncAllComponents, syncContent, syncProvidedComponents, setComponentDefaultPreset, } from "../../api/migrate.js";
|
|
3
3
|
import storyblokConfig from "../../config/config.js";
|
|
4
4
|
import Logger from "../../utils/logger.js";
|
|
5
|
-
import { isItFactory, unpackElements } from "../../utils/main.js";
|
|
6
|
-
import { getFrom, getTo } from "../../utils/others.js";
|
|
7
5
|
import { apiConfig } from "../api-config.js";
|
|
8
6
|
import { syncAllDatasources, syncProvidedDatasources, } from "../datasources/sync.js";
|
|
9
7
|
import { askForConfirmation } from "../helpers.js";
|
|
10
8
|
import { syncAllRoles, syncProvidedRoles } from "../roles/sync.js";
|
|
9
|
+
import { getFrom, getTo, isItFactory, unpackElements, } from "../utils/cli-utils.js";
|
|
11
10
|
const SYNC_COMMANDS = {
|
|
12
11
|
content: "content",
|
|
13
12
|
components: "components",
|
package/dist/cli/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
#! /usr/bin/env node
|
|
2
2
|
import meow from "meow";
|
|
3
|
-
import { pipe, prop } from "../utils/main.js";
|
|
4
3
|
import { backupDescription, debugDescription, mainDescription, syncDescription, removeDescription, initDescription, discoverDescription, migrateDescription, revertDescription, migrationsDescription, copyDescription, } from "./cli-descriptions.js";
|
|
5
4
|
import { backup } from "./commands/backup.js";
|
|
6
5
|
import { copyCommand } from "./commands/copy.js";
|
|
@@ -13,6 +12,7 @@ import { remove } from "./commands/remove.js";
|
|
|
13
12
|
import { revert } from "./commands/revert.js";
|
|
14
13
|
import { sync } from "./commands/sync.js";
|
|
15
14
|
import { testCommand } from "./commands/test.js";
|
|
15
|
+
import { pipe, prop } from "./utils/cli-utils.js";
|
|
16
16
|
const app = () => ({
|
|
17
17
|
cli: meow(mainDescription, {
|
|
18
18
|
importMeta: import.meta,
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CLI-specific utility functions for building and parsing CLI commands
|
|
3
|
+
*/
|
|
4
|
+
import type { RequestBaseConfig } from "../../api/utils/request.js";
|
|
5
|
+
/**
|
|
6
|
+
* Property accessor - curried function to get a property from an object
|
|
7
|
+
* @example prop('name')({ name: 'hero' }) // => 'hero'
|
|
8
|
+
*/
|
|
9
|
+
export declare const prop: (k: any) => (o: any) => any;
|
|
10
|
+
/**
|
|
11
|
+
* Pipe functions left to right (function composition)
|
|
12
|
+
* @example pipe(addOne, double)(5) // => 12
|
|
13
|
+
*/
|
|
14
|
+
export declare const pipe: (...fns: any[]) => (x: any) => any;
|
|
15
|
+
/**
|
|
16
|
+
* Extract elements after the first two from CLI input array
|
|
17
|
+
* Used for parsing component names from commands like: sync components hero card
|
|
18
|
+
* @example unpackElements(['sync', 'components', 'hero', 'card']) // => ['hero', 'card']
|
|
19
|
+
*/
|
|
20
|
+
export declare const unpackElements: (input: string[]) => string[];
|
|
21
|
+
/**
|
|
22
|
+
* Extract the third element from CLI input array
|
|
23
|
+
* Used for parsing single component name from commands
|
|
24
|
+
* @example unpackOne(['sync', 'components', 'hero']) // => 'hero'
|
|
25
|
+
*/
|
|
26
|
+
export declare const unpackOne: (input: string[]) => string | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* Factory for creating flag matchers
|
|
29
|
+
* Used to determine which CLI action to take based on provided flags
|
|
30
|
+
*
|
|
31
|
+
* @param flags - The flags object from CLI parser
|
|
32
|
+
* @param rules - Object mapping action names to required flag combinations
|
|
33
|
+
* @param whitelist - Flags to ignore when matching (e.g., 'from', 'to')
|
|
34
|
+
* @returns A function that checks if a given action type matches the flags
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* const rules = { all: ['all'], allWithPresets: ['all', 'presets'] };
|
|
38
|
+
* const isIt = isItFactory({ all: true, presets: true }, rules, []);
|
|
39
|
+
* isIt('allWithPresets') // => true
|
|
40
|
+
*/
|
|
41
|
+
export declare const isItFactory: <T>(flags: any, rules: any, whitelist: string[]) => (type: T) => boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Extract 'from' space ID from flags, falling back to config spaceId
|
|
44
|
+
*/
|
|
45
|
+
export declare const getFrom: (flags: any, config: RequestBaseConfig) => string;
|
|
46
|
+
/**
|
|
47
|
+
* Extract 'to' space ID from flags, falling back to config spaceId
|
|
48
|
+
*/
|
|
49
|
+
export declare const getTo: (flags: any, config: RequestBaseConfig) => string;
|
|
50
|
+
/**
|
|
51
|
+
* Extract 'sourceSpace' from flags, falling back to config spaceId
|
|
52
|
+
*/
|
|
53
|
+
export declare const getSourceSpace: (flags: any, config: RequestBaseConfig) => string;
|
|
54
|
+
/**
|
|
55
|
+
* Extract 'targetSpace' from flags, falling back to config spaceId
|
|
56
|
+
*/
|
|
57
|
+
export declare const getTargetSpace: (flags: any, config: RequestBaseConfig) => string;
|
|
58
|
+
/**
|
|
59
|
+
* Extract 'what' flag, defaulting to 'all'
|
|
60
|
+
*/
|
|
61
|
+
export declare const getWhat: (flags: any) => string;
|
|
62
|
+
/**
|
|
63
|
+
* Extract 'where' flag, defaulting to 'all'
|
|
64
|
+
*/
|
|
65
|
+
export declare const getWhere: (flags: any) => string;
|
|
66
|
+
/**
|
|
67
|
+
* Extract 'recursive' flag, defaulting to false
|
|
68
|
+
*/
|
|
69
|
+
export declare const getRecursive: (flags: any) => boolean;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CLI-specific utility functions for building and parsing CLI commands
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Property accessor - curried function to get a property from an object
|
|
6
|
+
* @example prop('name')({ name: 'hero' }) // => 'hero'
|
|
7
|
+
*/
|
|
8
|
+
export const prop = (k) => (o) => o[k];
|
|
9
|
+
/**
|
|
10
|
+
* Pipe functions left to right (function composition)
|
|
11
|
+
* @example pipe(addOne, double)(5) // => 12
|
|
12
|
+
*/
|
|
13
|
+
export const pipe = (...fns) => (x) => [...fns].reduce((acc, f) => f(acc), x);
|
|
14
|
+
/**
|
|
15
|
+
* Extract elements after the first two from CLI input array
|
|
16
|
+
* Used for parsing component names from commands like: sync components hero card
|
|
17
|
+
* @example unpackElements(['sync', 'components', 'hero', 'card']) // => ['hero', 'card']
|
|
18
|
+
*/
|
|
19
|
+
export const unpackElements = (input) => {
|
|
20
|
+
const [_1, _2, ...elementsForUse] = input;
|
|
21
|
+
return elementsForUse;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Extract the third element from CLI input array
|
|
25
|
+
* Used for parsing single component name from commands
|
|
26
|
+
* @example unpackOne(['sync', 'components', 'hero']) // => 'hero'
|
|
27
|
+
*/
|
|
28
|
+
export const unpackOne = (input) => {
|
|
29
|
+
const [_1, _2, elementForUse] = input;
|
|
30
|
+
return elementForUse;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Factory for creating flag matchers
|
|
34
|
+
* Used to determine which CLI action to take based on provided flags
|
|
35
|
+
*
|
|
36
|
+
* @param flags - The flags object from CLI parser
|
|
37
|
+
* @param rules - Object mapping action names to required flag combinations
|
|
38
|
+
* @param whitelist - Flags to ignore when matching (e.g., 'from', 'to')
|
|
39
|
+
* @returns A function that checks if a given action type matches the flags
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* const rules = { all: ['all'], allWithPresets: ['all', 'presets'] };
|
|
43
|
+
* const isIt = isItFactory({ all: true, presets: true }, rules, []);
|
|
44
|
+
* isIt('allWithPresets') // => true
|
|
45
|
+
*/
|
|
46
|
+
export const isItFactory = (flags, rules, whitelist) => {
|
|
47
|
+
return (type) => {
|
|
48
|
+
const rulesCopy = [...rules[type]];
|
|
49
|
+
const flagsKeys = Object.keys(flags);
|
|
50
|
+
const temp = flagsKeys.map((flag) => {
|
|
51
|
+
if (whitelist.includes(flag)) {
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
if (rulesCopy.includes(flag)) {
|
|
55
|
+
rulesCopy.splice(rulesCopy.indexOf(flag), 1);
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
if (rulesCopy.length > 0) {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
return temp.every((el) => el === true);
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
// ============================================================================
|
|
71
|
+
// CLI Flag Extractors
|
|
72
|
+
// ============================================================================
|
|
73
|
+
/**
|
|
74
|
+
* Extract 'from' space ID from flags, falling back to config spaceId
|
|
75
|
+
*/
|
|
76
|
+
export const getFrom = (flags, config) => (flags["from"] ? flags["from"] : config.spaceId).toString();
|
|
77
|
+
/**
|
|
78
|
+
* Extract 'to' space ID from flags, falling back to config spaceId
|
|
79
|
+
*/
|
|
80
|
+
export const getTo = (flags, config) => (flags["to"] ? flags["to"] : config.spaceId).toString();
|
|
81
|
+
/**
|
|
82
|
+
* Extract 'sourceSpace' from flags, falling back to config spaceId
|
|
83
|
+
*/
|
|
84
|
+
export const getSourceSpace = (flags, config) => (flags["sourceSpace"] ? flags["sourceSpace"] : config.spaceId).toString();
|
|
85
|
+
/**
|
|
86
|
+
* Extract 'targetSpace' from flags, falling back to config spaceId
|
|
87
|
+
*/
|
|
88
|
+
export const getTargetSpace = (flags, config) => (flags["targetSpace"] ? flags["targetSpace"] : config.spaceId).toString();
|
|
89
|
+
/**
|
|
90
|
+
* Extract 'what' flag, defaulting to 'all'
|
|
91
|
+
*/
|
|
92
|
+
export const getWhat = (flags) => (flags["what"] ? flags["what"] : "all").toString();
|
|
93
|
+
/**
|
|
94
|
+
* Extract 'where' flag, defaulting to 'all'
|
|
95
|
+
*/
|
|
96
|
+
export const getWhere = (flags) => (flags["where"] ? flags["where"] : "all").toString();
|
|
97
|
+
/**
|
|
98
|
+
* Extract 'recursive' flag, defaulting to false
|
|
99
|
+
*/
|
|
100
|
+
export const getRecursive = (flags) => flags["recursive"] ? flags["recursive"] : false;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type CompareResult, type OneFileElement } from "../../utils/path-utils.js";
|
|
1
2
|
export declare enum SCOPE {
|
|
2
3
|
local = "local",
|
|
3
4
|
external = "external",
|
|
@@ -25,23 +26,9 @@ interface DiscoverManyByPackageNameRequest {
|
|
|
25
26
|
packageNames: string[];
|
|
26
27
|
scope: SCOPE;
|
|
27
28
|
}
|
|
28
|
-
interface CompareRequest {
|
|
29
|
-
local: string[];
|
|
30
|
-
external: string[];
|
|
31
|
-
}
|
|
32
|
-
export interface OneFileElement {
|
|
33
|
-
name: string;
|
|
34
|
-
p: string;
|
|
35
|
-
}
|
|
36
|
-
export interface CompareResult {
|
|
37
|
-
local: OneFileElement[];
|
|
38
|
-
external: OneFileElement[];
|
|
39
|
-
}
|
|
40
29
|
type DiscoverResult = string[];
|
|
41
|
-
export
|
|
42
|
-
|
|
43
|
-
}) => string | undefined;
|
|
44
|
-
export declare const compare: (request: CompareRequest) => CompareResult;
|
|
30
|
+
export type { CompareResult, OneFileElement };
|
|
31
|
+
export { normalizeDiscover, compare, filesPattern, } from "../../utils/path-utils.js";
|
|
45
32
|
export declare const discoverManyByPackageName: (request: DiscoverManyByPackageNameRequest) => DiscoverResult;
|
|
46
33
|
export declare const discoverOneByPackageName: (request: DiscoverOneByPackageNameRequest) => DiscoverResult;
|
|
47
34
|
export declare const discoverMany: (request: DiscoverManyRequest) => Promise<DiscoverResult>;
|
|
@@ -50,11 +37,6 @@ export declare const discoverStories: (request: DiscoverManyRequest) => Discover
|
|
|
50
37
|
export declare const discoverMigrationConfig: (request: DiscoverManyRequest) => DiscoverResult;
|
|
51
38
|
export declare const discoverVersionMapping: (request: DiscoverManyRequest) => DiscoverResult;
|
|
52
39
|
export declare const discoverDatasources: (request: DiscoverRequest) => Promise<DiscoverResult>;
|
|
53
|
-
export declare const filesPattern: ({ mainDirectory, componentDirectories, ext, }: {
|
|
54
|
-
mainDirectory: string;
|
|
55
|
-
componentDirectories: string[];
|
|
56
|
-
ext: string;
|
|
57
|
-
}) => string;
|
|
58
40
|
export declare const discover: (request: DiscoverRequest) => Promise<DiscoverResult>;
|
|
59
41
|
export declare const discoverResolvers: (request: DiscoverRequest) => Promise<DiscoverResult>;
|
|
60
42
|
export declare const discoverRoles: (request: DiscoverRequest) => Promise<DiscoverResult>;
|
|
@@ -63,4 +45,3 @@ export declare const discoverAllComponents: () => Promise<{
|
|
|
63
45
|
local: OneFileElement[];
|
|
64
46
|
external: OneFileElement[];
|
|
65
47
|
}>;
|
|
66
|
-
export {};
|
|
@@ -5,7 +5,8 @@ import path from "path";
|
|
|
5
5
|
import glob from "glob";
|
|
6
6
|
import storyblokConfig, { SCHEMA } from "../../config/config.js";
|
|
7
7
|
import { buildOnTheFly } from "../../rollup/build-on-the-fly.js";
|
|
8
|
-
import { getFileContentWithRequire } from "../../utils/
|
|
8
|
+
import { getFileContentWithRequire } from "../../utils/files.js";
|
|
9
|
+
import { normalizeDiscover, filesPattern, compare, } from "../../utils/path-utils.js";
|
|
9
10
|
export var SCOPE;
|
|
10
11
|
(function (SCOPE) {
|
|
11
12
|
SCOPE["local"] = "local";
|
|
@@ -18,51 +19,8 @@ export var LOOKUP_TYPE;
|
|
|
18
19
|
LOOKUP_TYPE["packagName"] = "packageName";
|
|
19
20
|
LOOKUP_TYPE["fileName"] = "fileName";
|
|
20
21
|
})(LOOKUP_TYPE || (LOOKUP_TYPE = {}));
|
|
21
|
-
//
|
|
22
|
-
|
|
23
|
-
// so this function will normalize it based on amount of folders provided
|
|
24
|
-
export const normalizeDiscover = ({ segments }) => {
|
|
25
|
-
if (segments.length === 0) {
|
|
26
|
-
return "";
|
|
27
|
-
}
|
|
28
|
-
if (segments.length === 1) {
|
|
29
|
-
return segments[0];
|
|
30
|
-
}
|
|
31
|
-
return `{${segments.join(",")}}`;
|
|
32
|
-
};
|
|
33
|
-
export const compare = (request) => {
|
|
34
|
-
const { local, external } = request;
|
|
35
|
-
const splittedLocal = local.map((p) => {
|
|
36
|
-
return {
|
|
37
|
-
name: p.split(path.sep)[p.split(path.sep).length - 1],
|
|
38
|
-
p,
|
|
39
|
-
};
|
|
40
|
-
});
|
|
41
|
-
const splittedExternal = external
|
|
42
|
-
.map((p) => {
|
|
43
|
-
return {
|
|
44
|
-
name: p.split(path.sep)[p.split(path.sep).length - 1],
|
|
45
|
-
p,
|
|
46
|
-
};
|
|
47
|
-
})
|
|
48
|
-
.filter((file) => {
|
|
49
|
-
// 1. check if the file has node_modules > 1
|
|
50
|
-
const nodeModulesCount = (file.p.match(/node_modules/g) || [])
|
|
51
|
-
.length;
|
|
52
|
-
return nodeModulesCount <= 1;
|
|
53
|
-
});
|
|
54
|
-
// we only want to modify external array, because we want sometimes remove stuff which are already on local (overwrite node_modules ones)
|
|
55
|
-
const result = {
|
|
56
|
-
local: splittedLocal,
|
|
57
|
-
external: splittedExternal.filter((externalComponent) => {
|
|
58
|
-
if (splittedLocal.find((localComponent) => externalComponent.name === localComponent.name)) {
|
|
59
|
-
return false;
|
|
60
|
-
}
|
|
61
|
-
return true;
|
|
62
|
-
}),
|
|
63
|
-
};
|
|
64
|
-
return result;
|
|
65
|
-
};
|
|
22
|
+
// Re-export functions for backwards compatibility
|
|
23
|
+
export { normalizeDiscover, compare, filesPattern, } from "../../utils/path-utils.js";
|
|
66
24
|
export const discoverManyByPackageName = (request) => {
|
|
67
25
|
const rootDirectory = "./";
|
|
68
26
|
const directory = path.resolve(process.cwd(), rootDirectory);
|
|
@@ -464,11 +422,6 @@ export const discoverDatasources = async (request) => {
|
|
|
464
422
|
}
|
|
465
423
|
return listOfFiles;
|
|
466
424
|
};
|
|
467
|
-
export const filesPattern = ({ mainDirectory, componentDirectories, ext, }) => {
|
|
468
|
-
return componentDirectories.length === 1
|
|
469
|
-
? path.join(`${mainDirectory}`, `${componentDirectories[0]}`, "**", `[^_]*.${ext}`)
|
|
470
|
-
: path.join(`${mainDirectory}`, `{${componentDirectories.join(",")}}`, "**", `[^_]*.${ext}`);
|
|
471
|
-
};
|
|
472
425
|
export const discover = async (request) => {
|
|
473
426
|
const rootDirectory = ".";
|
|
474
427
|
const directory = path.resolve(process.cwd(), rootDirectory);
|
package/dist/config/config.d.ts
CHANGED
|
@@ -1,43 +1,6 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type StoryblokClient from "storyblok-js-client";
|
|
1
|
+
import type { IStoryblokConfig } from "./config.types.js";
|
|
3
2
|
import { SCHEMA } from "./helper.js";
|
|
4
|
-
type SchemaType = (typeof SCHEMA)[keyof typeof SCHEMA];
|
|
5
3
|
export { SCHEMA };
|
|
6
|
-
export
|
|
7
|
-
storyblokComponentsLocalDirectory: string;
|
|
8
|
-
sbmigWorkingDirectory: string;
|
|
9
|
-
presetsBackupDirectory: string;
|
|
10
|
-
storiesBackupDirectory: string;
|
|
11
|
-
componentsDirectories: string[];
|
|
12
|
-
awsBucketData: {
|
|
13
|
-
bucketName: string;
|
|
14
|
-
s3Url: `s3://${string}`;
|
|
15
|
-
httpUrl: `https://${string}`;
|
|
16
|
-
};
|
|
17
|
-
metadataSelection: Record<string, any>;
|
|
18
|
-
contentHubOriginUrl: string;
|
|
19
|
-
contentHubAuthorizationToken: string;
|
|
20
|
-
schemaFileExt: "sb.cjs" | "sb.js";
|
|
21
|
-
datasourceExt: string;
|
|
22
|
-
rolesExt: string;
|
|
23
|
-
storiesExt: string;
|
|
24
|
-
migrationConfigExt: string;
|
|
25
|
-
storyblokApiUrl: string;
|
|
26
|
-
storyblokDeliveryApiUrl: string;
|
|
27
|
-
storyblokGraphqlApiUrl: string;
|
|
28
|
-
oauthToken: string;
|
|
29
|
-
openaiToken: string;
|
|
30
|
-
spaceId: string;
|
|
31
|
-
accessToken: string;
|
|
32
|
-
boilerplateSpaceId: string;
|
|
33
|
-
schemaType: SchemaType;
|
|
34
|
-
flushCache: boolean;
|
|
35
|
-
cacheDir: string;
|
|
36
|
-
debug: boolean;
|
|
37
|
-
rateLimit: number;
|
|
38
|
-
sbApi?: () => StoryblokClient;
|
|
39
|
-
resolvers?: SimpleResolver[];
|
|
40
|
-
advancedResolvers?: SchemaGlobalResolvers;
|
|
41
|
-
}
|
|
4
|
+
export type { IStoryblokConfig };
|
|
42
5
|
declare const _default: IStoryblokConfig;
|
|
43
6
|
export default _default;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { SCHEMA } from "./constants.js";
|
|
2
|
+
import type { SchemaGlobalResolvers, SimpleResolver } from "../api/utils/resolvers.types.js";
|
|
3
|
+
import type StoryblokClient from "storyblok-js-client";
|
|
4
|
+
export type SchemaType = (typeof SCHEMA)[keyof typeof SCHEMA];
|
|
5
|
+
export interface IStoryblokConfig {
|
|
6
|
+
storyblokComponentsLocalDirectory: string;
|
|
7
|
+
sbmigWorkingDirectory: string;
|
|
8
|
+
presetsBackupDirectory: string;
|
|
9
|
+
storiesBackupDirectory: string;
|
|
10
|
+
componentsDirectories: string[];
|
|
11
|
+
awsBucketData: {
|
|
12
|
+
bucketName: string;
|
|
13
|
+
s3Url: `s3://${string}`;
|
|
14
|
+
httpUrl: `https://${string}`;
|
|
15
|
+
};
|
|
16
|
+
metadataSelection: Record<string, any>;
|
|
17
|
+
contentHubOriginUrl: string;
|
|
18
|
+
contentHubAuthorizationToken: string;
|
|
19
|
+
schemaFileExt: "sb.cjs" | "sb.js";
|
|
20
|
+
datasourceExt: string;
|
|
21
|
+
rolesExt: string;
|
|
22
|
+
storiesExt: string;
|
|
23
|
+
migrationConfigExt: string;
|
|
24
|
+
storyblokApiUrl: string;
|
|
25
|
+
storyblokDeliveryApiUrl: string;
|
|
26
|
+
storyblokGraphqlApiUrl: string;
|
|
27
|
+
oauthToken: string;
|
|
28
|
+
openaiToken: string;
|
|
29
|
+
spaceId: string;
|
|
30
|
+
accessToken: string;
|
|
31
|
+
boilerplateSpaceId: string;
|
|
32
|
+
schemaType: SchemaType;
|
|
33
|
+
flushCache: boolean;
|
|
34
|
+
cacheDir: string;
|
|
35
|
+
debug: boolean;
|
|
36
|
+
rateLimit: number;
|
|
37
|
+
sbApi?: () => StoryblokClient;
|
|
38
|
+
resolvers?: SimpleResolver[];
|
|
39
|
+
advancedResolvers?: SchemaGlobalResolvers;
|
|
40
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { IStoryblokConfig } from "./config.js";
|
|
1
|
+
import type { IStoryblokConfig } from "./config.types.js";
|
|
2
2
|
export declare const defaultConfig: (pkg: any, path: string, env: any) => IStoryblokConfig;
|
|
@@ -35,7 +35,7 @@ export const defaultConfig = (pkg, path, env) => {
|
|
|
35
35
|
// : "sb.stories.cjs",
|
|
36
36
|
storiesExt: "sb.stories.json",
|
|
37
37
|
storyblokApiUrl: env["NEXT_PUBLIC_STORYBLOK_MANAGEMENT_API_URL"] ||
|
|
38
|
-
"https://mapi.storyblok.com/v1",
|
|
38
|
+
"https://mapi.storyblok.com/v1", // should be mapi.storyblok.com ?
|
|
39
39
|
storyblokDeliveryApiUrl: env["NEXT_PUBLIC_STORYBLOK_DELIVERY_API_URL"] ||
|
|
40
40
|
"https://api.storyblok.com/v2",
|
|
41
41
|
storyblokGraphqlApiUrl: env["NEXT_PUBLIC_STORYBLOK_GRAPHQL_API_URL"] ||
|
|
@@ -46,7 +46,7 @@ export const defaultConfig = (pkg, path, env) => {
|
|
|
46
46
|
accessToken: env["GATSBY_STORYBLOK_ACCESS_TOKEN"] ||
|
|
47
47
|
env["NEXT_PUBLIC_STORYBLOK_ACCESS_TOKEN"] ||
|
|
48
48
|
"",
|
|
49
|
-
boilerplateSpaceId: "172677",
|
|
49
|
+
boilerplateSpaceId: "172677", // this is id of Content seed for nextjs boilerplate space
|
|
50
50
|
schemaType: SCHEMA.JS,
|
|
51
51
|
flushCache: true,
|
|
52
52
|
cacheDir: ".next/cache",
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Array utility functions
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Get unique values from an array
|
|
6
|
+
* Uses Set for O(n) deduplication
|
|
7
|
+
*
|
|
8
|
+
* @param array - The array to deduplicate
|
|
9
|
+
* @returns A new array with only unique values
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* uniqueValuesFrom([1, 2, 2, 3, 3, 3]) // => [1, 2, 3]
|
|
13
|
+
* uniqueValuesFrom(['a', 'b', 'a']) // => ['a', 'b']
|
|
14
|
+
*/
|
|
15
|
+
export declare const uniqueValuesFrom: <T>(array: T[]) => T[];
|
|
16
|
+
/**
|
|
17
|
+
* @deprecated Use uniqueValuesFrom instead
|
|
18
|
+
* Alias for backwards compatibility
|
|
19
|
+
*/
|
|
20
|
+
export declare const _uniqueValuesFrom: <T>(array: T[]) => T[];
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Array utility functions
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Get unique values from an array
|
|
6
|
+
* Uses Set for O(n) deduplication
|
|
7
|
+
*
|
|
8
|
+
* @param array - The array to deduplicate
|
|
9
|
+
* @returns A new array with only unique values
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* uniqueValuesFrom([1, 2, 2, 3, 3, 3]) // => [1, 2, 3]
|
|
13
|
+
* uniqueValuesFrom(['a', 'b', 'a']) // => ['a', 'b']
|
|
14
|
+
*/
|
|
15
|
+
export const uniqueValuesFrom = (array) => [...new Set(array)];
|
|
16
|
+
/**
|
|
17
|
+
* @deprecated Use uniqueValuesFrom instead
|
|
18
|
+
* Alias for backwards compatibility
|
|
19
|
+
*/
|
|
20
|
+
export const _uniqueValuesFrom = uniqueValuesFrom;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Async utility functions
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Delay execution for a specified time
|
|
6
|
+
*
|
|
7
|
+
* @param time - Time to delay in milliseconds
|
|
8
|
+
* @returns Promise that resolves after the delay
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* await delay(1000); // Wait 1 second
|
|
12
|
+
*/
|
|
13
|
+
export declare const delay: (time: number) => Promise<void>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Async utility functions
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Delay execution for a specified time
|
|
6
|
+
*
|
|
7
|
+
* @param time - Time to delay in milliseconds
|
|
8
|
+
* @returns Promise that resolves after the delay
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* await delay(1000); // Wait 1 second
|
|
12
|
+
*/
|
|
13
|
+
export const delay = (time) => new Promise((resolve) => setTimeout(resolve, time));
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Date utility functions
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Generate a datestamp string from a Date object
|
|
6
|
+
* Format: YYYY-M-D_H-M (no zero-padding)
|
|
7
|
+
*
|
|
8
|
+
* @param datestamp - The Date object to format
|
|
9
|
+
* @returns Formatted date string
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* generateDatestamp(new Date('2024-03-15T10:30:00')) // => '2024-3-15_10-30'
|
|
13
|
+
*/
|
|
14
|
+
export declare const generateDatestamp: (datestamp: Date) => string;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Date utility functions
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Generate a datestamp string from a Date object
|
|
6
|
+
* Format: YYYY-M-D_H-M (no zero-padding)
|
|
7
|
+
*
|
|
8
|
+
* @param datestamp - The Date object to format
|
|
9
|
+
* @returns Formatted date string
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* generateDatestamp(new Date('2024-03-15T10:30:00')) // => '2024-3-15_10-30'
|
|
13
|
+
*/
|
|
14
|
+
export const generateDatestamp = (datestamp) => {
|
|
15
|
+
const year = datestamp.getFullYear();
|
|
16
|
+
const month = datestamp.getMonth() + 1;
|
|
17
|
+
const day = datestamp.getDate();
|
|
18
|
+
const hours = datestamp.getHours();
|
|
19
|
+
const minutes = datestamp.getMinutes();
|
|
20
|
+
return `${year}-${month}-${day}_${hours}-${minutes}`;
|
|
21
|
+
};
|
package/dist/utils/files.d.ts
CHANGED
|
@@ -1,4 +1,39 @@
|
|
|
1
1
|
import type { RequestBaseConfig } from "../api/utils/request.js";
|
|
2
|
+
/**
|
|
3
|
+
* Asynchronously load a file using dynamic import
|
|
4
|
+
* Returns the default export of the module
|
|
5
|
+
*
|
|
6
|
+
* @param data - Object containing the file path
|
|
7
|
+
* @returns The default export of the imported module
|
|
8
|
+
*/
|
|
9
|
+
export declare const getFileContent: (data: {
|
|
10
|
+
file: string;
|
|
11
|
+
}) => any;
|
|
12
|
+
/**
|
|
13
|
+
* Synchronously load a file using require
|
|
14
|
+
* Handles both CommonJS and ES modules with default exports
|
|
15
|
+
*
|
|
16
|
+
* @param data - Object containing the file path
|
|
17
|
+
* @returns The file content (default export if available)
|
|
18
|
+
*/
|
|
19
|
+
export declare const getFileContentWithRequire: (data: {
|
|
20
|
+
file: string;
|
|
21
|
+
}) => any;
|
|
22
|
+
/**
|
|
23
|
+
* Load multiple files using require
|
|
24
|
+
*
|
|
25
|
+
* @param data - Object containing array of file paths
|
|
26
|
+
* @returns Array of file contents
|
|
27
|
+
*/
|
|
28
|
+
export declare const getFilesContentWithRequire: (data: {
|
|
29
|
+
files: string[];
|
|
30
|
+
}) => any[];
|
|
31
|
+
/**
|
|
32
|
+
* Read and parse the package.json from current working directory
|
|
33
|
+
*
|
|
34
|
+
* @returns Parsed package.json object
|
|
35
|
+
*/
|
|
36
|
+
export declare const getPackageJson: () => any;
|
|
2
37
|
export declare const isDirectoryExists: (path: string) => boolean;
|
|
3
38
|
export declare const createDir: (dirPath: string) => Promise<void>;
|
|
4
39
|
export declare const createJsonFile: (content: string, pathWithFilename: string) => Promise<void>;
|
package/dist/utils/files.js
CHANGED
|
@@ -1,11 +1,66 @@
|
|
|
1
1
|
import * as fs from "fs";
|
|
2
2
|
import { writeFile } from "fs";
|
|
3
|
+
import { createRequire } from "module";
|
|
3
4
|
import path from "path";
|
|
4
5
|
import pkg from "ncp";
|
|
6
|
+
import { generateDatestamp } from "./date-utils.js";
|
|
5
7
|
import Logger from "./logger.js";
|
|
6
|
-
import { getFileContentWithRequire } from "./main.js";
|
|
7
|
-
import { generateDatestamp } from "./others.js";
|
|
8
8
|
const { ncp } = pkg;
|
|
9
|
+
// ============================================================================
|
|
10
|
+
// File Content Loading
|
|
11
|
+
// ============================================================================
|
|
12
|
+
/**
|
|
13
|
+
* Asynchronously load a file using dynamic import
|
|
14
|
+
* Returns the default export of the module
|
|
15
|
+
*
|
|
16
|
+
* @param data - Object containing the file path
|
|
17
|
+
* @returns The default export of the imported module
|
|
18
|
+
*/
|
|
19
|
+
export const getFileContent = (data) => {
|
|
20
|
+
return import(data.file)
|
|
21
|
+
.then((res) => {
|
|
22
|
+
return res.default;
|
|
23
|
+
})
|
|
24
|
+
.catch((err) => {
|
|
25
|
+
console.log(err);
|
|
26
|
+
console.log("Cannot find requested file.");
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Synchronously load a file using require
|
|
31
|
+
* Handles both CommonJS and ES modules with default exports
|
|
32
|
+
*
|
|
33
|
+
* @param data - Object containing the file path
|
|
34
|
+
* @returns The file content (default export if available)
|
|
35
|
+
*/
|
|
36
|
+
export const getFileContentWithRequire = (data) => {
|
|
37
|
+
const require = createRequire(import.meta.url);
|
|
38
|
+
const fileContent = require(data.file);
|
|
39
|
+
if (fileContent.default) {
|
|
40
|
+
return fileContent.default;
|
|
41
|
+
}
|
|
42
|
+
return fileContent;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Load multiple files using require
|
|
46
|
+
*
|
|
47
|
+
* @param data - Object containing array of file paths
|
|
48
|
+
* @returns Array of file contents
|
|
49
|
+
*/
|
|
50
|
+
export const getFilesContentWithRequire = (data) => {
|
|
51
|
+
return data.files.map((file) => getFileContentWithRequire({ file }));
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Read and parse the package.json from current working directory
|
|
55
|
+
*
|
|
56
|
+
* @returns Parsed package.json object
|
|
57
|
+
*/
|
|
58
|
+
export const getPackageJson = () => {
|
|
59
|
+
const packageJsonPath = path.join(process.cwd(), "package.json");
|
|
60
|
+
const packageJsonContent = fs.readFileSync(packageJsonPath, "utf-8");
|
|
61
|
+
const packageJson = JSON.parse(packageJsonContent);
|
|
62
|
+
return packageJson;
|
|
63
|
+
};
|
|
9
64
|
export const isDirectoryExists = (path) => fs.existsSync(path);
|
|
10
65
|
export const createDir = async (dirPath) => {
|
|
11
66
|
await fs.promises.mkdir(`${process.cwd()}/${dirPath}`, {
|