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.
Files changed (172) hide show
  1. package/README.md +20 -19
  2. package/dist/api/assets/assets.js +1 -14
  3. package/dist/api/components/components.js +2 -1
  4. package/dist/api/components/components.sync.d.ts +8 -0
  5. package/dist/api/components/components.sync.js +193 -0
  6. package/dist/api/data-migration/component-data-migration.js +2 -2
  7. package/dist/api/datasources/datasource-entries.js +4 -5
  8. package/dist/api/datasources/datasources.d.ts +5 -2
  9. package/dist/api/datasources/datasources.js +42 -35
  10. package/dist/api/datasources/datasources.sync.d.ts +2 -0
  11. package/dist/api/datasources/datasources.sync.js +11 -0
  12. package/dist/api/datasources/datasources.types.d.ts +1 -1
  13. package/dist/api/datasources/index.d.ts +2 -1
  14. package/dist/api/datasources/index.js +2 -1
  15. package/dist/api/managementApi.d.ts +2 -2
  16. package/dist/api/migrate.d.ts +1 -1
  17. package/dist/api/migrate.js +3 -48
  18. package/dist/api/plugins/index.d.ts +2 -1
  19. package/dist/api/plugins/index.js +2 -1
  20. package/dist/api/plugins/plugins.d.ts +7 -2
  21. package/dist/api/plugins/plugins.js +28 -15
  22. package/dist/api/plugins/plugins.sync.d.ts +2 -0
  23. package/dist/api/plugins/plugins.sync.js +11 -0
  24. package/dist/api/roles/index.d.ts +2 -1
  25. package/dist/api/roles/index.js +2 -1
  26. package/dist/api/roles/roles.d.ts +5 -2
  27. package/dist/api/roles/roles.js +34 -11
  28. package/dist/api/roles/roles.sync.d.ts +2 -0
  29. package/dist/api/roles/roles.sync.js +6 -0
  30. package/dist/api/roles/roles.types.d.ts +1 -1
  31. package/dist/api/stories/stories.js +3 -11
  32. package/dist/api/sync/sync.types.d.ts +30 -0
  33. package/dist/api/sync/sync.types.js +1 -0
  34. package/dist/api/testApi.d.ts +2 -2
  35. package/dist/api/utils/helper-functions.d.ts +5 -1
  36. package/dist/api/utils/helper-functions.js +6 -1
  37. package/dist/api/utils/request.d.ts +1 -1
  38. package/dist/api/utils/request.js +11 -2
  39. package/dist/api/utils/resolverTransformations.js +2 -57
  40. package/dist/api-v2/assets/index.d.ts +13 -0
  41. package/dist/api-v2/assets/index.js +25 -0
  42. package/dist/api-v2/auth/index.d.ts +3 -0
  43. package/dist/api-v2/auth/index.js +8 -0
  44. package/dist/api-v2/client.d.ts +13 -0
  45. package/dist/api-v2/client.js +17 -0
  46. package/dist/api-v2/components/index.d.ts +10 -0
  47. package/dist/api-v2/components/index.js +29 -0
  48. package/dist/api-v2/datasources/index.d.ts +8 -0
  49. package/dist/api-v2/datasources/index.js +58 -0
  50. package/dist/api-v2/discover/discover.d.ts +36 -0
  51. package/dist/api-v2/discover/discover.js +281 -0
  52. package/dist/api-v2/discover/index.d.ts +2 -0
  53. package/dist/api-v2/discover/index.js +1 -0
  54. package/dist/api-v2/index.d.ts +19 -0
  55. package/dist/api-v2/index.js +21 -0
  56. package/dist/api-v2/plugins/index.d.ts +9 -0
  57. package/dist/api-v2/plugins/index.js +42 -0
  58. package/dist/api-v2/precompile/index.d.ts +2 -0
  59. package/dist/api-v2/precompile/index.js +1 -0
  60. package/dist/api-v2/precompile/precompile.d.ts +65 -0
  61. package/dist/api-v2/precompile/precompile.js +127 -0
  62. package/dist/api-v2/presets/index.d.ts +13 -0
  63. package/dist/api-v2/presets/index.js +25 -0
  64. package/dist/api-v2/requestConfig.d.ts +5 -0
  65. package/dist/api-v2/requestConfig.js +34 -0
  66. package/dist/api-v2/roles/index.d.ts +5 -0
  67. package/dist/api-v2/roles/index.js +35 -0
  68. package/dist/api-v2/spaces/index.d.ts +7 -0
  69. package/dist/api-v2/spaces/index.js +11 -0
  70. package/dist/api-v2/stories/index.d.ts +34 -0
  71. package/dist/api-v2/stories/index.js +172 -0
  72. package/dist/api-v2/stories/types.d.ts +28 -0
  73. package/dist/api-v2/stories/types.js +1 -0
  74. package/dist/api-v2/sync/index.d.ts +24 -0
  75. package/dist/api-v2/sync/index.js +109 -0
  76. package/dist/api-v2/sync/types.d.ts +1 -0
  77. package/dist/api-v2/sync/types.js +1 -0
  78. package/dist/api-v2/test.d.ts +15 -0
  79. package/dist/api-v2/test.js +21 -0
  80. package/dist/cli/commands/backup.js +7 -3
  81. package/dist/cli/commands/copy.js +2 -2
  82. package/dist/cli/commands/migrate.js +1 -2
  83. package/dist/cli/commands/migrations.js +2 -2
  84. package/dist/cli/commands/remove.js +1 -1
  85. package/dist/cli/commands/revert.js +2 -2
  86. package/dist/cli/commands/sync.js +1 -2
  87. package/dist/cli/index.js +1 -1
  88. package/dist/cli/utils/cli-utils.d.ts +69 -0
  89. package/dist/cli/utils/cli-utils.js +100 -0
  90. package/dist/cli/utils/discover.d.ts +3 -22
  91. package/dist/cli/utils/discover.js +4 -51
  92. package/dist/config/config.d.ts +2 -39
  93. package/dist/config/config.types.d.ts +40 -0
  94. package/dist/config/config.types.js +1 -0
  95. package/dist/config/defaultConfig.d.ts +1 -1
  96. package/dist/config/defaultConfig.js +2 -2
  97. package/dist/utils/array-utils.d.ts +20 -0
  98. package/dist/utils/array-utils.js +20 -0
  99. package/dist/utils/async-utils.d.ts +13 -0
  100. package/dist/utils/async-utils.js +13 -0
  101. package/dist/utils/date-utils.d.ts +14 -0
  102. package/dist/utils/date-utils.js +21 -0
  103. package/dist/utils/files.d.ts +35 -0
  104. package/dist/utils/files.js +57 -2
  105. package/dist/utils/main.d.ts +8 -18
  106. package/dist/utils/main.js +12 -104
  107. package/dist/utils/migrations.d.ts +9 -3
  108. package/dist/utils/object-utils.d.ts +46 -0
  109. package/dist/utils/object-utils.js +71 -0
  110. package/dist/utils/others.d.ts +6 -9
  111. package/dist/utils/others.js +8 -15
  112. package/dist/utils/path-utils.d.ts +89 -0
  113. package/dist/utils/path-utils.js +106 -0
  114. package/dist/utils/pkg.d.ts +16 -2
  115. package/dist/utils/pkg.js +16 -3
  116. package/dist/utils/string-utils.d.ts +33 -0
  117. package/dist/utils/string-utils.js +45 -0
  118. package/dist/utils/transform-utils.d.ts +62 -0
  119. package/dist/utils/transform-utils.js +113 -0
  120. package/dist-cjs/api/auth/auth.js +28 -0
  121. package/dist-cjs/api/auth/auth.types.js +2 -0
  122. package/dist-cjs/api/components/components.js +202 -0
  123. package/dist-cjs/api/components/components.sync.js +199 -0
  124. package/dist-cjs/api/components/components.types.js +2 -0
  125. package/dist-cjs/api/datasources/datasource-entries.js +166 -0
  126. package/dist-cjs/api/datasources/datasources.js +166 -0
  127. package/dist-cjs/api/datasources/datasources.types.js +2 -0
  128. package/dist-cjs/api/plugins/plugins.js +132 -0
  129. package/dist-cjs/api/plugins/plugins.types.js +2 -0
  130. package/dist-cjs/api/presets/componentPresets.js +25 -0
  131. package/dist-cjs/api/presets/presets.js +92 -0
  132. package/dist-cjs/api/presets/presets.types.js +2 -0
  133. package/dist-cjs/api/presets/resolvePresets.js +49 -0
  134. package/dist-cjs/api/roles/roles.js +131 -0
  135. package/dist-cjs/api/roles/roles.types.js +2 -0
  136. package/dist-cjs/api/spaces/spaces.js +34 -0
  137. package/dist-cjs/api/spaces/spaces.types.js +2 -0
  138. package/dist-cjs/api/stories/stories.js +214 -0
  139. package/dist-cjs/api/stories/stories.types.js +2 -0
  140. package/dist-cjs/api/sync/sync.types.js +2 -0
  141. package/dist-cjs/api/utils/request.js +48 -0
  142. package/dist-cjs/api/utils/resolvers.types.js +2 -0
  143. package/dist-cjs/api-v2/assets/index.js +30 -0
  144. package/dist-cjs/api-v2/auth/index.js +12 -0
  145. package/dist-cjs/api-v2/client.js +23 -0
  146. package/dist-cjs/api-v2/components/index.js +40 -0
  147. package/dist-cjs/api-v2/datasources/index.js +64 -0
  148. package/dist-cjs/api-v2/discover/discover.js +321 -0
  149. package/dist-cjs/api-v2/discover/index.js +9 -0
  150. package/dist-cjs/api-v2/index.js +60 -0
  151. package/dist-cjs/api-v2/plugins/index.js +49 -0
  152. package/dist-cjs/api-v2/precompile/index.js +7 -0
  153. package/dist-cjs/api-v2/precompile/precompile.js +136 -0
  154. package/dist-cjs/api-v2/presets/index.js +33 -0
  155. package/dist-cjs/api-v2/requestConfig.js +37 -0
  156. package/dist-cjs/api-v2/roles/index.js +41 -0
  157. package/dist-cjs/api-v2/spaces/index.js +16 -0
  158. package/dist-cjs/api-v2/stories/index.js +180 -0
  159. package/dist-cjs/api-v2/stories/types.js +2 -0
  160. package/dist-cjs/api-v2/sync/index.js +115 -0
  161. package/dist-cjs/api-v2/sync/types.js +2 -0
  162. package/dist-cjs/api-v2/test.js +25 -0
  163. package/dist-cjs/config/config.types.js +2 -0
  164. package/dist-cjs/config/constants.js +29 -0
  165. package/dist-cjs/package.json +3 -0
  166. package/dist-cjs/utils/array-utils.js +24 -0
  167. package/dist-cjs/utils/logger.js +32 -0
  168. package/dist-cjs/utils/object-utils.js +77 -0
  169. package/dist-cjs/utils/path-utils.js +115 -0
  170. package/package.json +37 -20
  171. package/dist/utils/pkg-require.d.ts +0 -2
  172. package/dist/utils/pkg-require.js +0 -4
@@ -1,18 +1,8 @@
1
- export declare const prop: (k: any) => (o: any) => any;
2
- export declare const pipe: (...fns: any[]) => (x: any) => any;
3
- export declare const unpackElements: (input: string[]) => string[];
4
- export declare const unpackOne: (input: string[]) => string | undefined;
5
- export declare const getFileContent: (data: {
6
- file: string;
7
- }) => any;
8
- export declare const getFileContentWithRequire: (data: {
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";
@@ -1,104 +1,12 @@
1
- import fs from "fs";
2
- import { createRequire } from "module";
3
- import path from "path";
4
- export const prop = (k) => (o) => o[k];
5
- export const pipe = (...fns) => (x) => [...fns].reduce((acc, f) => f(acc), x);
6
- export const unpackElements = (input) => {
7
- const [_1, _2, ...elementsForUse] = input;
8
- return elementsForUse;
9
- };
10
- export const unpackOne = (input) => {
11
- const [_1, _2, elementForUse] = input;
12
- return elementForUse;
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
- type MigrationNames = "transitionsOnEnter" | "otherMigration" | "cardsMigration" | "hideToVisibility";
2
- type VersionMapping = Record<string, MigrationNames[]>;
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
+ };
@@ -1,9 +1,6 @@
1
- import type { RequestBaseConfig } from "../api/utils/request.js";
2
- export declare const generateDatestamp: (datestamp: Date) => string;
3
- export declare const getFrom: (flags: any, config: RequestBaseConfig) => string;
4
- export declare const getTo: (flags: any, config: RequestBaseConfig) => string;
5
- export declare const getSourceSpace: (flags: any, config: RequestBaseConfig) => string;
6
- export declare const getTargetSpace: (flags: any, config: RequestBaseConfig) => string;
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";
@@ -1,15 +1,8 @@
1
- export const generateDatestamp = (datestamp) => {
2
- const year = datestamp.getFullYear();
3
- const month = datestamp.getMonth() + 1;
4
- const day = datestamp.getDate();
5
- const hours = datestamp.getHours();
6
- const minutes = datestamp.getMinutes();
7
- return `${year}-${month}-${day}_${hours}-${minutes}`;
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
+ };
@@ -1,2 +1,16 @@
1
- declare const pkg: (path: string) => any;
2
- export { pkg };
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
- // return require(`${process.cwd()}/package.json`);
4
- const pkg = (path) => {
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
+ };