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
package/dist/utils/main.d.ts
CHANGED
|
@@ -1,18 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
export
|
|
9
|
-
file: string;
|
|
10
|
-
}) => any;
|
|
11
|
-
export declare const getFilesContentWithRequire: (data: {
|
|
12
|
-
files: string[];
|
|
13
|
-
}) => any[];
|
|
14
|
-
export declare const isObjectEmpty: (obj: any) => boolean;
|
|
15
|
-
export declare const delay: (time: number) => Promise<unknown>;
|
|
16
|
-
export declare const isItFactory: <T>(flags: any, rules: any, whitelist: string[]) => (type: T) => boolean;
|
|
17
|
-
export declare const getPackageJson: () => any;
|
|
18
|
-
export declare const extractFields: (data: any, filter: any) => any;
|
|
1
|
+
/**
|
|
2
|
+
* Re-exports for backwards compatibility
|
|
3
|
+
* Functions have been moved to their proper modules
|
|
4
|
+
*/
|
|
5
|
+
export { prop, pipe, unpackElements, unpackOne, isItFactory, } from "../cli/utils/cli-utils.js";
|
|
6
|
+
export { isObjectEmpty, extractFields } from "./object-utils.js";
|
|
7
|
+
export { getFileContent, getFileContentWithRequire, getFilesContentWithRequire, getPackageJson, } from "./files.js";
|
|
8
|
+
export { delay } from "./async-utils.js";
|
package/dist/utils/main.js
CHANGED
|
@@ -1,104 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
export
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
};
|
|
14
|
-
export const getFileContent = (data) => {
|
|
15
|
-
return import(data.file)
|
|
16
|
-
.then((res) => {
|
|
17
|
-
return res.default;
|
|
18
|
-
})
|
|
19
|
-
.catch((err) => {
|
|
20
|
-
console.log(err);
|
|
21
|
-
console.log("Cannot find requested file.");
|
|
22
|
-
});
|
|
23
|
-
};
|
|
24
|
-
export const getFileContentWithRequire = (data) => {
|
|
25
|
-
const require = createRequire(import.meta.url);
|
|
26
|
-
const fileContent = require(data.file);
|
|
27
|
-
if (fileContent.default) {
|
|
28
|
-
return fileContent.default;
|
|
29
|
-
}
|
|
30
|
-
return fileContent;
|
|
31
|
-
};
|
|
32
|
-
export const getFilesContentWithRequire = (data) => {
|
|
33
|
-
return data.files.map((file) => getFileContentWithRequire({ file }));
|
|
34
|
-
};
|
|
35
|
-
export const isObjectEmpty = (obj) => {
|
|
36
|
-
if (obj) {
|
|
37
|
-
return Object.keys(obj).length === 0 && obj.constructor === Object;
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
return true;
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
export const delay = (time) => new Promise((resolve) => setTimeout(resolve, time));
|
|
44
|
-
export const isItFactory = (flags, rules, whitelist) => {
|
|
45
|
-
return (type) => {
|
|
46
|
-
const rulesCopy = [...rules[type]];
|
|
47
|
-
const flagsKeys = Object.keys(flags);
|
|
48
|
-
const temp = flagsKeys.map((flag) => {
|
|
49
|
-
if (whitelist.includes(flag)) {
|
|
50
|
-
return true;
|
|
51
|
-
}
|
|
52
|
-
if (rulesCopy.includes(flag)) {
|
|
53
|
-
rulesCopy.splice(rulesCopy.indexOf(flag), 1);
|
|
54
|
-
return true;
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
return false;
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
if (rulesCopy.length > 0) {
|
|
61
|
-
return false;
|
|
62
|
-
}
|
|
63
|
-
else {
|
|
64
|
-
return temp.every((el) => el === true);
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
};
|
|
68
|
-
export const getPackageJson = () => {
|
|
69
|
-
const packageJsonPath = path.join(process.cwd(), "package.json");
|
|
70
|
-
// Read the file content as a string
|
|
71
|
-
const packageJsonContent = fs.readFileSync(packageJsonPath, "utf-8");
|
|
72
|
-
// Parse the file content as a JSON object
|
|
73
|
-
const packageJson = JSON.parse(packageJsonContent);
|
|
74
|
-
return packageJson;
|
|
75
|
-
};
|
|
76
|
-
export const extractFields = (data, filter) => {
|
|
77
|
-
const result = {};
|
|
78
|
-
for (const key in filter) {
|
|
79
|
-
if (filter[key] === true) {
|
|
80
|
-
result[key] = data[key];
|
|
81
|
-
}
|
|
82
|
-
else if (typeof filter[key] === "object") {
|
|
83
|
-
result[key] = extractFields(data[key], filter[key]);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
return result;
|
|
87
|
-
};
|
|
88
|
-
// export const generateMetadata = (args: any) => {
|
|
89
|
-
// const packageJson = getPackageJson();
|
|
90
|
-
//
|
|
91
|
-
// const contentHubName = packageJson.name;
|
|
92
|
-
// const contentHubLatestVersion = packageJson.version;
|
|
93
|
-
//
|
|
94
|
-
// const backpackVersionInContentHub =
|
|
95
|
-
// packageJson.dependencies['@ef-global/backpack'];
|
|
96
|
-
//
|
|
97
|
-
// return {
|
|
98
|
-
// metadata: {
|
|
99
|
-
// contentHubName,
|
|
100
|
-
// contentHubLatestVersion,
|
|
101
|
-
// backpackVersionInContentHub,
|
|
102
|
-
// },
|
|
103
|
-
// };
|
|
104
|
-
// };
|
|
1
|
+
/**
|
|
2
|
+
* Re-exports for backwards compatibility
|
|
3
|
+
* Functions have been moved to their proper modules
|
|
4
|
+
*/
|
|
5
|
+
// CLI utils - now in src/cli/utils/cli-utils.ts
|
|
6
|
+
export { prop, pipe, unpackElements, unpackOne, isItFactory, } from "../cli/utils/cli-utils.js";
|
|
7
|
+
// Object utils - now in src/utils/object-utils.ts
|
|
8
|
+
export { isObjectEmpty, extractFields } from "./object-utils.js";
|
|
9
|
+
// File loading utils - now in src/utils/files.ts
|
|
10
|
+
export { getFileContent, getFileContentWithRequire, getFilesContentWithRequire, getPackageJson, } from "./files.js";
|
|
11
|
+
// Async utils - now in src/utils/async-utils.ts
|
|
12
|
+
export { delay } from "./async-utils.js";
|
|
@@ -1,5 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Known migration names (can be extended as new migrations are added)
|
|
3
|
+
*/
|
|
4
|
+
export type MigrationNames = "transitionsOnEnter" | "otherMigration" | "cardsMigration" | "hideToVisibility";
|
|
5
|
+
/**
|
|
6
|
+
* Version mapping - maps semver versions to arrays of migration names
|
|
7
|
+
* Uses string[] to allow flexibility for new migrations
|
|
8
|
+
*/
|
|
9
|
+
export type VersionMapping = Record<string, string[]>;
|
|
3
10
|
export declare const preselectMigrations: (currentVersion: string, installedVersion: string, versionMapping: VersionMapping, alreadyApplied?: {
|
|
4
11
|
story: string[];
|
|
5
12
|
preset: string[];
|
|
@@ -8,4 +15,3 @@ export declare const preselectMigrations: (currentVersion: string, installedVers
|
|
|
8
15
|
preset: never[];
|
|
9
16
|
};
|
|
10
17
|
export declare const modifyOrCreateAppliedMigrationsFile: (migrationApplied: string, itemType: "story" | "preset") => Promise<void>;
|
|
11
|
-
export {};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* General object utility functions
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Filter out null and undefined values from an object
|
|
6
|
+
* Keeps all properties that have defined values (including falsy values like 0, '', false)
|
|
7
|
+
*
|
|
8
|
+
* @param params - The object to filter
|
|
9
|
+
* @returns A new object with only non-nullish values
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* notNullish({ a: 1, b: null, c: undefined, d: 0 }) // => { a: 1, d: 0 }
|
|
13
|
+
*/
|
|
14
|
+
export declare const notNullish: <T extends Record<string, any>>(params: T) => T;
|
|
15
|
+
/**
|
|
16
|
+
* Check if an object is empty (has no own properties)
|
|
17
|
+
* Returns true for null, undefined, and empty objects {}
|
|
18
|
+
* Returns false for arrays (even empty ones) and objects with properties
|
|
19
|
+
*
|
|
20
|
+
* @param obj - The object to check
|
|
21
|
+
* @returns true if the object is empty, null, or undefined
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* isObjectEmpty({}) // => true
|
|
25
|
+
* isObjectEmpty(null) // => true
|
|
26
|
+
* isObjectEmpty({ name: 'test' }) // => false
|
|
27
|
+
* isObjectEmpty([]) // => false (arrays are not plain objects)
|
|
28
|
+
*/
|
|
29
|
+
export declare const isObjectEmpty: (obj: any) => boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Extract specific fields from an object based on a filter object
|
|
32
|
+
* Supports nested object extraction
|
|
33
|
+
*
|
|
34
|
+
* @param data - The source object to extract fields from
|
|
35
|
+
* @param filter - An object where true means include the field, nested objects for nested extraction
|
|
36
|
+
* @returns A new object containing only the specified fields
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* const data = { name: 'hero', id: 123, schema: { title: 'text' } };
|
|
40
|
+
* extractFields(data, { name: true, id: true }) // => { name: 'hero', id: 123 }
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* // Nested extraction
|
|
44
|
+
* extractFields(data, { schema: { title: true } }) // => { schema: { title: 'text' } }
|
|
45
|
+
*/
|
|
46
|
+
export declare const extractFields: (data: any, filter: any) => any;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* General object utility functions
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Filter out null and undefined values from an object
|
|
6
|
+
* Keeps all properties that have defined values (including falsy values like 0, '', false)
|
|
7
|
+
*
|
|
8
|
+
* @param params - The object to filter
|
|
9
|
+
* @returns A new object with only non-nullish values
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* notNullish({ a: 1, b: null, c: undefined, d: 0 }) // => { a: 1, d: 0 }
|
|
13
|
+
*/
|
|
14
|
+
export const notNullish = (params) => {
|
|
15
|
+
return Object.keys(params).reduce((acc, key) => {
|
|
16
|
+
if (params[key] !== null && params[key] !== undefined) {
|
|
17
|
+
acc[key] = params[key];
|
|
18
|
+
}
|
|
19
|
+
return acc;
|
|
20
|
+
}, {});
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Check if an object is empty (has no own properties)
|
|
24
|
+
* Returns true for null, undefined, and empty objects {}
|
|
25
|
+
* Returns false for arrays (even empty ones) and objects with properties
|
|
26
|
+
*
|
|
27
|
+
* @param obj - The object to check
|
|
28
|
+
* @returns true if the object is empty, null, or undefined
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* isObjectEmpty({}) // => true
|
|
32
|
+
* isObjectEmpty(null) // => true
|
|
33
|
+
* isObjectEmpty({ name: 'test' }) // => false
|
|
34
|
+
* isObjectEmpty([]) // => false (arrays are not plain objects)
|
|
35
|
+
*/
|
|
36
|
+
export const isObjectEmpty = (obj) => {
|
|
37
|
+
if (obj) {
|
|
38
|
+
return Object.keys(obj).length === 0 && obj.constructor === Object;
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Extract specific fields from an object based on a filter object
|
|
46
|
+
* Supports nested object extraction
|
|
47
|
+
*
|
|
48
|
+
* @param data - The source object to extract fields from
|
|
49
|
+
* @param filter - An object where true means include the field, nested objects for nested extraction
|
|
50
|
+
* @returns A new object containing only the specified fields
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* const data = { name: 'hero', id: 123, schema: { title: 'text' } };
|
|
54
|
+
* extractFields(data, { name: true, id: true }) // => { name: 'hero', id: 123 }
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* // Nested extraction
|
|
58
|
+
* extractFields(data, { schema: { title: true } }) // => { schema: { title: 'text' } }
|
|
59
|
+
*/
|
|
60
|
+
export const extractFields = (data, filter) => {
|
|
61
|
+
const result = {};
|
|
62
|
+
for (const key in filter) {
|
|
63
|
+
if (filter[key] === true) {
|
|
64
|
+
result[key] = data[key];
|
|
65
|
+
}
|
|
66
|
+
else if (typeof filter[key] === "object") {
|
|
67
|
+
result[key] = extractFields(data[key], filter[key]);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return result;
|
|
71
|
+
};
|
package/dist/utils/others.d.ts
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export
|
|
6
|
-
export
|
|
7
|
-
export declare const getWhat: (flags: any) => string;
|
|
8
|
-
export declare const getWhere: (flags: any) => string;
|
|
9
|
-
export declare const getRecursive: (flags: any) => boolean;
|
|
1
|
+
/**
|
|
2
|
+
* Re-exports for backwards compatibility
|
|
3
|
+
* Functions have been moved to their proper modules
|
|
4
|
+
*/
|
|
5
|
+
export { generateDatestamp } from "./date-utils.js";
|
|
6
|
+
export { getFrom, getTo, getSourceSpace, getTargetSpace, getWhat, getWhere, getRecursive, } from "../cli/utils/cli-utils.js";
|
package/dist/utils/others.js
CHANGED
|
@@ -1,15 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
};
|
|
9
|
-
export const getFrom = (flags, config) => (flags["from"] ? flags["from"] : config.spaceId).toString();
|
|
10
|
-
export const getTo = (flags, config) => (flags["to"] ? flags["to"] : config.spaceId).toString();
|
|
11
|
-
export const getSourceSpace = (flags, config) => (flags["sourceSpace"] ? flags["sourceSpace"] : config.spaceId).toString();
|
|
12
|
-
export const getTargetSpace = (flags, config) => (flags["targetSpace"] ? flags["targetSpace"] : config.spaceId).toString();
|
|
13
|
-
export const getWhat = (flags) => (flags["what"] ? flags["what"] : "all").toString();
|
|
14
|
-
export const getWhere = (flags) => (flags["where"] ? flags["where"] : "all").toString();
|
|
15
|
-
export const getRecursive = (flags) => flags["recursive"] ? flags["recursive"] : false;
|
|
1
|
+
/**
|
|
2
|
+
* Re-exports for backwards compatibility
|
|
3
|
+
* Functions have been moved to their proper modules
|
|
4
|
+
*/
|
|
5
|
+
// Date utilities - now in date-utils.ts
|
|
6
|
+
export { generateDatestamp } from "./date-utils.js";
|
|
7
|
+
// CLI flag extractors - now in cli/utils/cli-utils.ts
|
|
8
|
+
export { getFrom, getTo, getSourceSpace, getTargetSpace, getWhat, getWhere, getRecursive, } from "../cli/utils/cli-utils.js";
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Path and glob pattern utilities for file discovery
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Represents a file element with its name and path
|
|
6
|
+
*/
|
|
7
|
+
export interface OneFileElement {
|
|
8
|
+
name: string;
|
|
9
|
+
p: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Result of comparing local and external file arrays
|
|
13
|
+
*/
|
|
14
|
+
export interface CompareResult {
|
|
15
|
+
local: OneFileElement[];
|
|
16
|
+
external: OneFileElement[];
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Request for comparing local and external file paths
|
|
20
|
+
*/
|
|
21
|
+
interface CompareRequest {
|
|
22
|
+
local: string[];
|
|
23
|
+
external: string[];
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Normalizes an array of directory segments for glob pattern usage.
|
|
27
|
+
* Handles the glob.sync quirk where single segments don't need braces,
|
|
28
|
+
* but multiple segments need {segment1,segment2} format.
|
|
29
|
+
*
|
|
30
|
+
* @param segments - Array of directory path segments
|
|
31
|
+
* @returns Normalized string for glob pattern
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* normalizeDiscover({ segments: [] }) // => ""
|
|
35
|
+
* normalizeDiscover({ segments: ["src"] }) // => "src"
|
|
36
|
+
* normalizeDiscover({ segments: ["src", "lib"] }) // => "{src,lib}"
|
|
37
|
+
*/
|
|
38
|
+
export declare const normalizeDiscover: ({ segments, }: {
|
|
39
|
+
segments: string[];
|
|
40
|
+
}) => string;
|
|
41
|
+
/**
|
|
42
|
+
* Builds a glob file pattern for discovering files with a specific extension.
|
|
43
|
+
* Automatically handles single vs multiple directory paths.
|
|
44
|
+
*
|
|
45
|
+
* @param mainDirectory - The root directory to search from
|
|
46
|
+
* @param componentDirectories - Array of subdirectories to search in
|
|
47
|
+
* @param ext - File extension to match (without leading dot)
|
|
48
|
+
* @returns A glob pattern string
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* filesPattern({
|
|
52
|
+
* mainDirectory: "/project",
|
|
53
|
+
* componentDirectories: ["src"],
|
|
54
|
+
* ext: "sb.js"
|
|
55
|
+
* })
|
|
56
|
+
* // => "/project/src/**\/[^_]*.sb.js"
|
|
57
|
+
*
|
|
58
|
+
* filesPattern({
|
|
59
|
+
* mainDirectory: "/project",
|
|
60
|
+
* componentDirectories: ["src", "lib"],
|
|
61
|
+
* ext: "sb.js"
|
|
62
|
+
* })
|
|
63
|
+
* // => "/project/{src,lib}/**\/[^_]*.sb.js"
|
|
64
|
+
*/
|
|
65
|
+
export declare const filesPattern: ({ mainDirectory, componentDirectories, ext, }: {
|
|
66
|
+
mainDirectory: string;
|
|
67
|
+
componentDirectories: string[];
|
|
68
|
+
ext: string;
|
|
69
|
+
}) => string;
|
|
70
|
+
/**
|
|
71
|
+
* Compares local and external file path arrays.
|
|
72
|
+
* Splits paths to extract file names, filters out duplicates from external
|
|
73
|
+
* (preferring local files), and filters out nested node_modules.
|
|
74
|
+
*
|
|
75
|
+
* @param request - Object containing local and external path arrays
|
|
76
|
+
* @returns CompareResult with processed local and external file elements
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* compare({
|
|
80
|
+
* local: ["/project/src/hero.sb.js"],
|
|
81
|
+
* external: ["/project/node_modules/pkg/hero.sb.js", "/project/node_modules/pkg/card.sb.js"]
|
|
82
|
+
* })
|
|
83
|
+
* // => {
|
|
84
|
+
* // local: [{ name: "hero.sb.js", p: "/project/src/hero.sb.js" }],
|
|
85
|
+
* // external: [{ name: "card.sb.js", p: "/project/node_modules/pkg/card.sb.js" }]
|
|
86
|
+
* // }
|
|
87
|
+
*/
|
|
88
|
+
export declare const compare: (request: CompareRequest) => CompareResult;
|
|
89
|
+
export {};
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Path and glob pattern utilities for file discovery
|
|
3
|
+
*/
|
|
4
|
+
import path from "path";
|
|
5
|
+
/**
|
|
6
|
+
* Normalizes an array of directory segments for glob pattern usage.
|
|
7
|
+
* Handles the glob.sync quirk where single segments don't need braces,
|
|
8
|
+
* but multiple segments need {segment1,segment2} format.
|
|
9
|
+
*
|
|
10
|
+
* @param segments - Array of directory path segments
|
|
11
|
+
* @returns Normalized string for glob pattern
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* normalizeDiscover({ segments: [] }) // => ""
|
|
15
|
+
* normalizeDiscover({ segments: ["src"] }) // => "src"
|
|
16
|
+
* normalizeDiscover({ segments: ["src", "lib"] }) // => "{src,lib}"
|
|
17
|
+
*/
|
|
18
|
+
export const normalizeDiscover = ({ segments, }) => {
|
|
19
|
+
if (segments.length === 0) {
|
|
20
|
+
return "";
|
|
21
|
+
}
|
|
22
|
+
if (segments.length === 1) {
|
|
23
|
+
return segments[0];
|
|
24
|
+
}
|
|
25
|
+
return `{${segments.join(",")}}`;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Builds a glob file pattern for discovering files with a specific extension.
|
|
29
|
+
* Automatically handles single vs multiple directory paths.
|
|
30
|
+
*
|
|
31
|
+
* @param mainDirectory - The root directory to search from
|
|
32
|
+
* @param componentDirectories - Array of subdirectories to search in
|
|
33
|
+
* @param ext - File extension to match (without leading dot)
|
|
34
|
+
* @returns A glob pattern string
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* filesPattern({
|
|
38
|
+
* mainDirectory: "/project",
|
|
39
|
+
* componentDirectories: ["src"],
|
|
40
|
+
* ext: "sb.js"
|
|
41
|
+
* })
|
|
42
|
+
* // => "/project/src/**\/[^_]*.sb.js"
|
|
43
|
+
*
|
|
44
|
+
* filesPattern({
|
|
45
|
+
* mainDirectory: "/project",
|
|
46
|
+
* componentDirectories: ["src", "lib"],
|
|
47
|
+
* ext: "sb.js"
|
|
48
|
+
* })
|
|
49
|
+
* // => "/project/{src,lib}/**\/[^_]*.sb.js"
|
|
50
|
+
*/
|
|
51
|
+
export const filesPattern = ({ mainDirectory, componentDirectories, ext, }) => {
|
|
52
|
+
return componentDirectories.length === 1
|
|
53
|
+
? path.join(`${mainDirectory}`, `${componentDirectories[0]}`, "**", `[^_]*.${ext}`)
|
|
54
|
+
: path.join(`${mainDirectory}`, `{${componentDirectories.join(",")}}`, "**", `[^_]*.${ext}`);
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Compares local and external file path arrays.
|
|
58
|
+
* Splits paths to extract file names, filters out duplicates from external
|
|
59
|
+
* (preferring local files), and filters out nested node_modules.
|
|
60
|
+
*
|
|
61
|
+
* @param request - Object containing local and external path arrays
|
|
62
|
+
* @returns CompareResult with processed local and external file elements
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* compare({
|
|
66
|
+
* local: ["/project/src/hero.sb.js"],
|
|
67
|
+
* external: ["/project/node_modules/pkg/hero.sb.js", "/project/node_modules/pkg/card.sb.js"]
|
|
68
|
+
* })
|
|
69
|
+
* // => {
|
|
70
|
+
* // local: [{ name: "hero.sb.js", p: "/project/src/hero.sb.js" }],
|
|
71
|
+
* // external: [{ name: "card.sb.js", p: "/project/node_modules/pkg/card.sb.js" }]
|
|
72
|
+
* // }
|
|
73
|
+
*/
|
|
74
|
+
export const compare = (request) => {
|
|
75
|
+
const { local, external } = request;
|
|
76
|
+
const splittedLocal = local.map((p) => {
|
|
77
|
+
return {
|
|
78
|
+
name: p.split(path.sep)[p.split(path.sep).length - 1], // last element of split array - file name
|
|
79
|
+
p,
|
|
80
|
+
};
|
|
81
|
+
});
|
|
82
|
+
const splittedExternal = external
|
|
83
|
+
.map((p) => {
|
|
84
|
+
return {
|
|
85
|
+
name: p.split(path.sep)[p.split(path.sep).length - 1], // last element of split array - file name
|
|
86
|
+
p,
|
|
87
|
+
};
|
|
88
|
+
})
|
|
89
|
+
.filter((file) => {
|
|
90
|
+
// Filter out files from nested node_modules (node_modules within node_modules)
|
|
91
|
+
const nodeModulesCount = (file.p.match(/node_modules/g) || [])
|
|
92
|
+
.length;
|
|
93
|
+
return nodeModulesCount <= 1;
|
|
94
|
+
});
|
|
95
|
+
// Filter external array to remove items that exist locally (local takes priority)
|
|
96
|
+
const result = {
|
|
97
|
+
local: splittedLocal,
|
|
98
|
+
external: splittedExternal.filter((externalComponent) => {
|
|
99
|
+
if (splittedLocal.find((localComponent) => externalComponent.name === localComponent.name)) {
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
return true;
|
|
103
|
+
}),
|
|
104
|
+
};
|
|
105
|
+
return result;
|
|
106
|
+
};
|
package/dist/utils/pkg.d.ts
CHANGED
|
@@ -1,2 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Package loading utilities
|
|
3
|
+
* ESM-compatible require wrapper for loading JSON/JS files dynamically
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Load a package/module from the given path using require
|
|
7
|
+
* Works in ESM context by using createRequire
|
|
8
|
+
*
|
|
9
|
+
* @param path - Path to the package/module to load
|
|
10
|
+
* @returns The loaded module content
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* const packageJson = pkg('./package.json');
|
|
14
|
+
* const config = pkg('some-config-file');
|
|
15
|
+
*/
|
|
16
|
+
export declare const pkg: (path: string) => any;
|
package/dist/utils/pkg.js
CHANGED
|
@@ -1,7 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Package loading utilities
|
|
3
|
+
* ESM-compatible require wrapper for loading JSON/JS files dynamically
|
|
4
|
+
*/
|
|
1
5
|
import { createRequire } from "module";
|
|
2
6
|
const require = createRequire(import.meta.url);
|
|
3
|
-
|
|
4
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Load a package/module from the given path using require
|
|
9
|
+
* Works in ESM context by using createRequire
|
|
10
|
+
*
|
|
11
|
+
* @param path - Path to the package/module to load
|
|
12
|
+
* @returns The loaded module content
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* const packageJson = pkg('./package.json');
|
|
16
|
+
* const config = pkg('some-config-file');
|
|
17
|
+
*/
|
|
18
|
+
export const pkg = (path) => {
|
|
5
19
|
return require(path);
|
|
6
20
|
};
|
|
7
|
-
export { pkg };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* String manipulation utilities
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Extracts the filename from a file URL or path.
|
|
6
|
+
* Returns the last segment after splitting by "/".
|
|
7
|
+
*
|
|
8
|
+
* @param fileUrl - The URL or path string to extract filename from
|
|
9
|
+
* @returns The extracted filename
|
|
10
|
+
* @throws Error if filename cannot be extracted (empty string or no segments)
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* getFileName("https://example.com/assets/image.png") // => "image.png"
|
|
14
|
+
* getFileName("/path/to/file.txt") // => "file.txt"
|
|
15
|
+
* getFileName("simple.js") // => "simple.js"
|
|
16
|
+
*/
|
|
17
|
+
export declare const getFileName: (fileUrl: string) => string;
|
|
18
|
+
/**
|
|
19
|
+
* Extracts the size segment from a Storyblok asset URL.
|
|
20
|
+
* Storyblok asset URLs have the format: .../size/hash/filename
|
|
21
|
+
* This function extracts the size segment (3 positions before the end).
|
|
22
|
+
*
|
|
23
|
+
* @param fileUrl - The Storyblok asset URL
|
|
24
|
+
* @returns The size segment from the URL
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* getSizeFromURL("https://a.storyblok.com/f/12345/1920x1080/abc123/image.png")
|
|
28
|
+
* // => "1920x1080"
|
|
29
|
+
*
|
|
30
|
+
* getSizeFromURL("https://a.storyblok.com/f/12345/100x100/xyz789/thumb.jpg")
|
|
31
|
+
* // => "100x100"
|
|
32
|
+
*/
|
|
33
|
+
export declare const getSizeFromURL: (fileUrl: string) => string;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* String manipulation utilities
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Extracts the filename from a file URL or path.
|
|
6
|
+
* Returns the last segment after splitting by "/".
|
|
7
|
+
*
|
|
8
|
+
* @param fileUrl - The URL or path string to extract filename from
|
|
9
|
+
* @returns The extracted filename
|
|
10
|
+
* @throws Error if filename cannot be extracted (empty string or no segments)
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* getFileName("https://example.com/assets/image.png") // => "image.png"
|
|
14
|
+
* getFileName("/path/to/file.txt") // => "file.txt"
|
|
15
|
+
* getFileName("simple.js") // => "simple.js"
|
|
16
|
+
*/
|
|
17
|
+
export const getFileName = (fileUrl) => {
|
|
18
|
+
const fileName = fileUrl.split("/").pop();
|
|
19
|
+
if (fileName) {
|
|
20
|
+
return fileName;
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
throw Error("File name couldn't be extracted from URL.");
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Extracts the size segment from a Storyblok asset URL.
|
|
28
|
+
* Storyblok asset URLs have the format: .../size/hash/filename
|
|
29
|
+
* This function extracts the size segment (3 positions before the end).
|
|
30
|
+
*
|
|
31
|
+
* @param fileUrl - The Storyblok asset URL
|
|
32
|
+
* @returns The size segment from the URL
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* getSizeFromURL("https://a.storyblok.com/f/12345/1920x1080/abc123/image.png")
|
|
36
|
+
* // => "1920x1080"
|
|
37
|
+
*
|
|
38
|
+
* getSizeFromURL("https://a.storyblok.com/f/12345/100x100/xyz789/thumb.jpg")
|
|
39
|
+
* // => "100x100"
|
|
40
|
+
*/
|
|
41
|
+
export const getSizeFromURL = (fileUrl) => {
|
|
42
|
+
const data = fileUrl.split("/");
|
|
43
|
+
const sizePos = data.length - 3;
|
|
44
|
+
return data[sizePos];
|
|
45
|
+
};
|