sb-mig 5.3.0-beta.5 → 5.3.0

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 CHANGED
@@ -123,7 +123,7 @@ module.exports = {
123
123
  This is what a basic storyblok `.sb.js` schema file which maps to a component looks like:
124
124
 
125
125
  ```
126
- expport default {
126
+ export default {
127
127
  name: "text-block",
128
128
  display_name: "Text block",
129
129
  is_root: false,
@@ -1,5 +1,5 @@
1
1
  import { apiConfig } from "../cli/api-config.js";
2
- import { compare, discover, discoverMany, discoverManyByPackageName, discoverResolvers, discoverStories, LOOKUP_TYPE, SCOPE, } from "../cli/utils/discover.js";
2
+ import { compare, discover, discoverMany, discoverManyByPackageName, discoverStories, LOOKUP_TYPE, SCOPE, } from "../cli/utils/discover.js";
3
3
  import { dumpToFile } from "../utils/files.js";
4
4
  import Logger from "../utils/logger.js";
5
5
  import { getFileContentWithRequire, getFilesContentWithRequire, isObjectEmpty, } from "../utils/main.js";
@@ -10,7 +10,7 @@ import { backupStories } from "./stories/backup.js";
10
10
  import { getAllStories } from "./stories/stories.js";
11
11
  import { createTree, traverseAndCreate } from "./stories/tree.js";
12
12
  import { _uniqueValuesFrom } from "./utils/helper-functions.js";
13
- import { resolverTransformations } from "./utils/resolverTransformations.js";
13
+ import { resolveGlobalTransformations } from "./utils/resolverTransformations.js";
14
14
  const _checkAndPrepareGroups = async (groupsToCheck, config) => {
15
15
  const componentsGroups = await managementApi.components.getAllComponentsGroups(config);
16
16
  const groupExist = (groupName) => componentsGroups.find((group) => group.name === groupName);
@@ -60,19 +60,12 @@ export const syncComponents = async (specifiedComponents, presets, config) => {
60
60
  let specifiedComponentsContent = await Promise.all(specifiedComponents.map((component) => {
61
61
  return getFileContentWithRequire({ file: component.p });
62
62
  }));
63
- const resolversFilenames = await discoverResolvers({
64
- scope: SCOPE.local,
65
- type: LOOKUP_TYPE.fileName,
66
- });
67
- /*
68
- * if resolversFilenames exist, then do stuff if not, than follow with the old approach
69
- * */
70
- if (resolversFilenames.length !== 0) {
71
- const resolverFilesContent = await Promise.all(resolversFilenames.map((filename) => {
72
- return getFileContentWithRequire({ file: filename });
73
- }));
74
- specifiedComponentsContent = resolverTransformations(specifiedComponentsContent, resolverFilesContent);
75
- }
63
+ /**
64
+ * Resolve all the global transformations you find
65
+ * - storyblok.config file resolvers
66
+ * - .sb.resolvers.ts files resolvers
67
+ */
68
+ specifiedComponentsContent = await resolveGlobalTransformations(specifiedComponentsContent);
76
69
  const groupsToCheck = _uniqueValuesFrom(specifiedComponentsContent
77
70
  .filter((component) => component.component_group_name)
78
71
  .map((component) => component.component_group_name));
@@ -1 +1,23 @@
1
- export declare const resolverTransformations: (specifiedComponentsContent: any, resolverFilesContent: any) => any[];
1
+ import type { StoryblokComponentSchemaBase } from "storyblok-schema-types";
2
+ type ComponentData = {
3
+ [K in keyof StoryblokComponentSchemaBase<any>]: any;
4
+ };
5
+ export interface ResolversBy {
6
+ match: string[];
7
+ componentData: Partial<ComponentData>;
8
+ }
9
+ export interface SchemaGlobalResolvers {
10
+ all?: Omit<ResolversBy, "match">;
11
+ byPluginNames?: ResolversBy[];
12
+ byComponentGroupNames?: ResolversBy[];
13
+ byComponentNames?: ResolversBy[];
14
+ }
15
+ export declare const transformWithResolverFiles: (componentsContent: any) => Promise<any>;
16
+ export declare const transformWithMainConfigFile: (componentsContent: any) => any;
17
+ /**
18
+ * side effect: true
19
+ */
20
+ export declare const resolveGlobalTransformations: (componentsContent: any) => Promise<any>;
21
+ export declare const extendFields: (componentNamesResolver: any, component: any) => void;
22
+ export declare const resolverTransformations: (componentsContent: any, resolverFilesContent: any) => any[];
23
+ export {};
@@ -1,3 +1,78 @@
1
+ import { discoverResolvers, LOOKUP_TYPE, SCOPE, } from "../../cli/utils/discover.js";
2
+ import config from "../../config/config.js";
3
+ import { getFileContentWithRequire } from "../../utils/main.js";
4
+ export const transformWithResolverFiles = async (componentsContent) => {
5
+ componentsContent = structuredClone(componentsContent);
6
+ const resolversFilenames = await discoverResolvers({
7
+ scope: SCOPE.local,
8
+ type: LOOKUP_TYPE.fileName,
9
+ });
10
+ /*
11
+ * if resolversFilenames exist, then do stuff if not, than follow with the old approach
12
+ * */
13
+ if (resolversFilenames.length !== 0) {
14
+ const resolverFilesContent = await Promise.all(
15
+ // TODO: change to allSettled
16
+ resolversFilenames.map((filename) => {
17
+ return getFileContentWithRequire({ file: filename });
18
+ }));
19
+ componentsContent = resolverTransformations(componentsContent, resolverFilesContent[0]);
20
+ }
21
+ return componentsContent;
22
+ };
23
+ const isContentAvailableAsBloks = (component) => "content" in component.schema &&
24
+ component.schema.content.component_whitelist &&
25
+ component.schema.content.type === "bloks";
26
+ const isItemsAvailableAsBloks = (component) => "items" in component.schema &&
27
+ component.schema.items.component_whitelist &&
28
+ component.schema.items.type === "bloks";
29
+ const updateComponentWhitelist = ({ component, update, }) => {
30
+ if (isContentAvailableAsBloks(component)) {
31
+ component.schema.content.component_whitelist = [
32
+ ...new Set(update(component.schema.content.component_whitelist)), // make sure it will have unique items
33
+ ];
34
+ }
35
+ else if (isItemsAvailableAsBloks(component)) {
36
+ component.schema.items.component_whitelist = [
37
+ ...new Set(update(component.schema.items.component_whitelist)), // make sure it will have unique items
38
+ ];
39
+ }
40
+ };
41
+ export const transformWithMainConfigFile = (componentsContent) => {
42
+ componentsContent = structuredClone(componentsContent);
43
+ if (config.resolvers && config.resolvers.length > 0) {
44
+ config.resolvers.map((resolver) => {
45
+ componentsContent = componentsContent.map((component) => {
46
+ // If the component that we try to sync is in resolved component names list to resolve / transform
47
+ if (resolver.match.includes(component.name)) {
48
+ if (resolver.fields.component_whitelist) {
49
+ updateComponentWhitelist({
50
+ component,
51
+ update: resolver.fields.component_whitelist,
52
+ });
53
+ }
54
+ if (resolver.fields.translatable) {
55
+ component.schema.icon.translatable =
56
+ resolver.fields.translatable(component.schema.icon.translatable);
57
+ }
58
+ }
59
+ return component;
60
+ });
61
+ });
62
+ }
63
+ if (config.advancedResolvers) {
64
+ componentsContent = resolverTransformations(componentsContent, config.advancedResolvers);
65
+ }
66
+ return componentsContent;
67
+ };
68
+ /**
69
+ * side effect: true
70
+ */
71
+ export const resolveGlobalTransformations = async (componentsContent) => {
72
+ componentsContent = await transformWithResolverFiles(componentsContent);
73
+ componentsContent = await transformWithMainConfigFile(componentsContent);
74
+ return componentsContent;
75
+ };
1
76
  const extendField = (obj, targetField, newValue) => {
2
77
  if (typeof obj !== "object" || obj === null) {
3
78
  return false;
@@ -28,40 +103,76 @@ const resolveAll = (resolver, componentsContent) => {
28
103
  return componentsContent;
29
104
  return componentsContent;
30
105
  };
31
- const resolveComponentGroupNames = (resolver, componentsContent) => {
32
- if (!resolver.componentGroupNames)
33
- return componentsContent;
34
- return componentsContent;
106
+ export const extendFields = (componentNamesResolver, component) => {
107
+ const targetField = Object.keys(componentNamesResolver.methods.extend)[0];
108
+ console.log("This is target field ?");
109
+ console.log(targetField);
110
+ extendField(component, targetField, componentNamesResolver.methods.extend[targetField]);
111
+ };
112
+ function deepTransform(obj, transformers) {
113
+ if (typeof obj !== "object" || obj === null) {
114
+ return obj;
115
+ }
116
+ const result = Array.isArray(obj) ? [...obj] : { ...obj };
117
+ for (const key in transformers) {
118
+ if (typeof transformers[key] === "function") {
119
+ result[key] = transformers[key](obj[key]);
120
+ }
121
+ else if (typeof transformers[key] === "object" &&
122
+ transformers[key] !== null) {
123
+ result[key] = deepTransform(obj[key] || {}, transformers[key]);
124
+ }
125
+ else {
126
+ result[key] = transformers[key];
127
+ }
128
+ }
129
+ // Preserve untransformed properties
130
+ for (const key in obj) {
131
+ if (!(key in transformers)) {
132
+ result[key] = obj[key];
133
+ }
134
+ }
135
+ return result;
136
+ }
137
+ export const resolverTransformations = (componentsContent, resolverFilesContent) => {
138
+ let resolvedComponents = [];
139
+ resolvedComponents = resolveComponentNames(resolverFilesContent, componentsContent);
140
+ /**
141
+ *
142
+ * TODO: implement this
143
+ *
144
+ * */
145
+ // resolvedComponents = resolveComponentGroupNames(
146
+ // resolver,
147
+ // resolvedComponents,
148
+ // );
149
+ // resolvedComponents = resolvePluginNames(resolver, resolvedComponents);
150
+ return resolvedComponents;
35
151
  };
36
152
  const resolveComponentNames = (resolver, componentsContent) => {
37
- if (!resolver.componentNames)
153
+ if (!resolver.byComponentNames)
38
154
  return componentsContent;
39
- const componentNamesResolver = resolver.componentNames;
40
- componentsContent.map((component) => {
41
- if (componentNamesResolver.names.includes(component.name)) {
42
- const targetField = Object.keys(componentNamesResolver.methods.extend)[0];
43
- console.log("This is target field ?");
44
- console.log(targetField);
45
- extendField(component, targetField, componentNamesResolver.methods.extend[targetField]);
46
- }
47
- return component;
155
+ componentsContent = structuredClone(componentsContent);
156
+ resolver.byComponentNames.map((componentNameResolver) => {
157
+ componentsContent = componentsContent.map((component) => {
158
+ // If the component that we try to sync is in resolved component names list to resolve / transform
159
+ if (componentNameResolver &&
160
+ componentNameResolver.match.includes(component.name)) {
161
+ const changedObj = deepTransform(component, componentNameResolver.componentData);
162
+ component = changedObj;
163
+ }
164
+ return component;
165
+ });
48
166
  });
49
167
  return componentsContent;
50
168
  };
51
- export const resolverTransformations = (specifiedComponentsContent, resolverFilesContent) => {
52
- let resolvedComponents = [];
53
- console.log("#### Specified Components Content to Resolve ####");
54
- console.log(specifiedComponentsContent);
55
- console.log("#### Resolver Files Content ####");
56
- console.log(resolverFilesContent);
57
- const resolver = resolverFilesContent[0];
58
- console.log("kjashdkjhaskjdh");
59
- console.log(resolver);
60
- // resolvedComponents = resolveAll(resolver, specifiedComponentsContent)
61
- // resolvedComponents = resolveComponentGroupNames(resolver, resolvedComponents)
62
- resolvedComponents = resolveComponentNames(resolver, specifiedComponentsContent);
63
- console.log("@@@@@@@@");
64
- console.log(resolvedComponents[0].schema);
65
- console.log("@@@@@@@@");
66
- return resolvedComponents;
169
+ const resolvePluginNames = (resolver, componentsContent) => {
170
+ if (!resolver.componentPluginNames)
171
+ return componentsContent;
172
+ return componentsContent;
173
+ };
174
+ const resolveComponentGroupNames = (resolver, componentsContent) => {
175
+ if (!resolver.componentGroupNames)
176
+ return componentsContent;
177
+ return componentsContent;
67
178
  };
@@ -0,0 +1,24 @@
1
+ import type { StoryblokComponentSchemaBase } from "storyblok-schema-types";
2
+ type ComponentData = {
3
+ [K in keyof StoryblokComponentSchemaBase<any>]: any;
4
+ };
5
+ export interface ResolversBy {
6
+ match: string[];
7
+ componentData: Partial<ComponentData>;
8
+ }
9
+ export interface SchemaGlobalResolvers {
10
+ all?: Omit<ResolversBy, "match">;
11
+ byPluginNames?: ResolversBy[];
12
+ byComponentGroupNames?: ResolversBy[];
13
+ byComponentNames?: ResolversBy[];
14
+ }
15
+ export type ComponentWhitelistSimpleResolver = (prevComponentWhitelist: string[]) => string[];
16
+ export type TranslatableSimpleResolver = (prevTranslatable: boolean) => boolean;
17
+ export interface SimpleResolver {
18
+ match: string[];
19
+ fields: {
20
+ component_whitelist?: ComponentWhitelistSimpleResolver;
21
+ translatable?: TranslatableSimpleResolver;
22
+ };
23
+ }
24
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -7,5 +7,4 @@ export declare const migrationsDescription = "\n Usage\n $ sb-mig migr
7
7
  export declare const removeDescription = "\n Usage\n $ sb-mig remove [components|roles|datasources] [space separated file names] or --all \n \n Description\n Remove components or roles with Storyblok space.\n \n COMMANDS\n components - remove components\n roles - remove roles\n datasources - remove datasources\n \n FLAGS\n --all - Remove all components \n \n EXAMPLES\n $ sb-mig remove components --all\n $ sb-mig remove components accordion accordion-item\n $ sb-mig remove roles --all\n $ sb-mig remove datasources --all\n";
8
8
  export declare const backupDescription = "\n Usage\n $ sb-mig backup [components|component-groups|roles|datasources|presets|component-presets] component-name or --all\n Description\n Command for backing up anything related to Storyblok\n \n COMMANDS\n components - backup components\n component-groups - backup component-groups\n roles - backup components\n datasources - backup components\n presets - backup presets\n component-presets - backup component presets\n plugins - backup plugins\n stories - backup stories (only --all)\n\n \n FLAGS\n --all - Backup all \n \n EXAMPLES\n $ sb-mig backup components --all\n $ sb-mig backup components accordion \n $ sb-mig backup datasources --all\n $ sb-mig backup roles admin\n $ sb-mig backup plugins --all\n $ sb-mig backup plugins my-awesome-plugin\n $ sb-mig backup stories --all\n";
9
9
  export declare const debugDescription = "\n Usage\n $ sb-mig debug\n Description\n Output extra debugging information\n";
10
- export declare const askDescription = "\n !! ALPHA !!!\n Usage\n $ sb-mig ask \"What sb-mig version am I using?\"\n $ sb-mig ask \"What is the schema type i should write?\"\n $ sb-mig ask \"Is debug mode turned on ?\"\n $ sb-mig ask \"What storyblok api urls I am using?\"\n $ sb-mig ask \"How would I sync just couple components ? what command should i use? I would like to also sync presets for this components\"\n $ sb-mig ask \"Can you give me a brief overview of sb-mig tool features, I would like to be sure i do not miss anything super important while using it\"\n Description\n Ask sb-mig about anything, especially stuff related to sb-mig and storyblok components.\n \n Needs OPENAI_API_KEY= environment set in your project. (Config will pick it up automatically, no need to modify\n storyblok.config.[c|m]js file\n \n Also, right now, you need to install @mrck-labs/anton-sdk in your project, since its not bundled.\n";
11
10
  export declare const initDescription = "\n Usage\n $ sb-mig init\n Description\n Init and update your project\n";
@@ -185,23 +185,6 @@ export const debugDescription = `
185
185
  Description
186
186
  Output extra debugging information
187
187
  `;
188
- export const askDescription = `
189
- !! ALPHA !!!
190
- Usage
191
- $ sb-mig ask "What sb-mig version am I using?"
192
- $ sb-mig ask "What is the schema type i should write?"
193
- $ sb-mig ask "Is debug mode turned on ?"
194
- $ sb-mig ask "What storyblok api urls I am using?"
195
- $ sb-mig ask "How would I sync just couple components ? what command should i use? I would like to also sync presets for this components"
196
- $ sb-mig ask "Can you give me a brief overview of sb-mig tool features, I would like to be sure i do not miss anything super important while using it"
197
- Description
198
- Ask sb-mig about anything, especially stuff related to sb-mig and storyblok components.
199
-
200
- Needs OPENAI_API_KEY= environment set in your project. (Config will pick it up automatically, no need to modify
201
- storyblok.config.[c|m]js file
202
-
203
- Also, right now, you need to install @mrck-labs/anton-sdk in your project, since its not bundled.
204
- `;
205
188
  export const initDescription = `
206
189
  Usage
207
190
  $ sb-mig init
@@ -1,7 +1,7 @@
1
1
  import path from "path";
2
2
  import config from "../../config/config.js";
3
+ import { getConsumerPackageJson, getSbMigPackageJson, } from "../../utils/files.js";
3
4
  import Logger from "../../utils/logger.js";
4
- import { getFileContentWithRequire } from "../../utils/main.js";
5
5
  import { pkg } from "../../utils/pkg.js";
6
6
  export const debug = async () => {
7
7
  console.log("storyblok.config.js: ", config, "\n");
@@ -10,15 +10,15 @@ export const debug = async () => {
10
10
  Logger.log(" ");
11
11
  Logger.log(" ");
12
12
  try {
13
- const fileContent = await getFileContentWithRequire({
14
- file: path.join("..", "..", "package.json"),
15
- });
13
+ const fileContent = await getSbMigPackageJson();
14
+ const consumerPkg = await getConsumerPackageJson();
16
15
  Logger.log("sb-mig version: ");
17
16
  Logger.success(fileContent["version"]);
18
17
  Logger.log(" ");
19
18
  Logger.log("Version used: ");
20
19
  Logger.success(`storyblok-js-client: ${fileContent["dependencies"]["storyblok-js-client"]}`);
21
20
  Logger.success(`typescript: ${fileContent["dependencies"]["typescript"]}`);
21
+ Logger.success(`@ef-global/backpack: ${consumerPkg["dependencies"]["@ef-global/backpack"]}`);
22
22
  Logger.log(" ");
23
23
  Logger.log(" ");
24
24
  if (pkg(path.join(`${process.cwd()}`, `package.json`)).type === "module") {
@@ -3,6 +3,7 @@ import Logger from "../../utils/logger.js";
3
3
  import { apiConfig } from "../api-config.js";
4
4
  const INIT_COMMANDS = {
5
5
  stories: "stories",
6
+ resolvers: "resolvers",
6
7
  };
7
8
  export const testCommand = async (props) => {
8
9
  const { input, flags } = props;
package/dist/cli/index.js CHANGED
@@ -1,8 +1,7 @@
1
1
  #! /usr/bin/env node
2
2
  import meow from "meow";
3
3
  import { pipe, prop } from "../utils/main.js";
4
- import { backupDescription, debugDescription, mainDescription, syncDescription, removeDescription, initDescription, discoverDescription, migrateDescription, revertDescription, migrationsDescription, askDescription, } from "./cli-descriptions.js";
5
- import { ask } from "./commands/ask.js";
4
+ import { backupDescription, debugDescription, mainDescription, syncDescription, removeDescription, initDescription, discoverDescription, migrateDescription, revertDescription, migrationsDescription, } from "./cli-descriptions.js";
6
5
  import { backup } from "./commands/backup.js";
7
6
  import { debug } from "./commands/debug.js";
8
7
  import { discover } from "./commands/discover.js";
@@ -105,15 +104,6 @@ app.debug = () => ({
105
104
  debug();
106
105
  },
107
106
  });
108
- app.ask = () => ({
109
- cli: meow(askDescription, {
110
- importMeta: import.meta,
111
- booleanDefault: undefined,
112
- }),
113
- action: (cli) => {
114
- ask(cli);
115
- },
116
- });
117
107
  app.init = () => ({
118
108
  cli: meow(initDescription, {
119
109
  importMeta: import.meta,
@@ -539,13 +539,13 @@ export const discoverResolvers = async (request) => {
539
539
  pattern = filesPattern({
540
540
  mainDirectory: directory,
541
541
  componentDirectories: onlyLocalComponentsDirectories,
542
- ext: "resolvers.schema.sb.ts",
542
+ ext: "sb.resolvers.ts",
543
543
  });
544
544
  const listOfFilesToCompile = glob.sync(pattern.replace(/\\/g, "/"), {
545
545
  follow: true,
546
546
  });
547
547
  await buildOnTheFly({ files: listOfFilesToCompile });
548
- pattern = path.join(directory, ".next", "cache", "sb-mig", "**", `[^_]*.resolvers.schema.sb.cjs`);
548
+ pattern = path.join(directory, ".next", "cache", "sb-mig", "**", `[^_]*.sb.resolvers.cjs`);
549
549
  listOFSchemaTSFilesCompiled = glob.sync(pattern.replace(/\\/g, "/"), {
550
550
  follow: true,
551
551
  });
@@ -553,7 +553,7 @@ export const discoverResolvers = async (request) => {
553
553
  pattern = filesPattern({
554
554
  mainDirectory: directory,
555
555
  componentDirectories: onlyLocalComponentsDirectories,
556
- ext: "resolvers.schema.sb.cjs",
556
+ ext: "sb.resolvers.cjs",
557
557
  });
558
558
  listOfFiles = glob.sync(pattern.replace(/\\/g, "/"), {
559
559
  follow: true,
@@ -1,3 +1,4 @@
1
+ import type { SchemaGlobalResolvers, SimpleResolver } from "../api/utils/resolvers.types.js";
1
2
  import type StoryblokClient from "storyblok-js-client";
2
3
  import { SCHEMA } from "./helper.js";
3
4
  type SchemaType = (typeof SCHEMA)[keyof typeof SCHEMA];
@@ -34,7 +35,9 @@ export interface IStoryblokConfig {
34
35
  cacheDir: string;
35
36
  debug: boolean;
36
37
  rateLimit: number;
37
- sbApi?: () => StoryblokClient | StoryblokClient;
38
+ sbApi?: () => StoryblokClient;
39
+ resolvers?: SimpleResolver[];
40
+ advancedResolvers?: SchemaGlobalResolvers;
38
41
  }
39
42
  declare const _default: IStoryblokConfig;
40
43
  export default _default;
@@ -25,4 +25,6 @@ export declare const createAndSaveToFile: CreateAndSaveToFile;
25
25
  export declare const createAndSaveComponentListToFile: CreateAndSaveComponentListToFile;
26
26
  export declare const readFile: (pathToFile: string) => Promise<string | undefined>;
27
27
  export declare const dumpToFile: (path: string, content: string) => Promise<void>;
28
+ export declare const getConsumerPackageJson: () => Promise<any>;
29
+ export declare const getSbMigPackageJson: () => Promise<any>;
28
30
  export {};
@@ -3,6 +3,7 @@ import { writeFile } from "fs";
3
3
  import path from "path";
4
4
  import pkg from "ncp";
5
5
  import Logger from "./logger.js";
6
+ import { getFileContentWithRequire } from "./main.js";
6
7
  import { generateDatestamp } from "./others.js";
7
8
  const { ncp } = pkg;
8
9
  export const isDirectoryExists = (path) => fs.existsSync(path);
@@ -134,3 +135,15 @@ export const dumpToFile = async (path, content) => {
134
135
  }
135
136
  });
136
137
  };
138
+ export const getConsumerPackageJson = async () => {
139
+ const consumerPkg = await getFileContentWithRequire({
140
+ file: path.join(process.cwd(), "package.json"),
141
+ });
142
+ return consumerPkg;
143
+ };
144
+ export const getSbMigPackageJson = async () => {
145
+ const sbMigPkg = await getFileContentWithRequire({
146
+ file: path.join("..", "..", "package.json"),
147
+ });
148
+ return sbMigPkg;
149
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sb-mig",
3
- "version": "5.3.0-beta.5",
3
+ "version": "5.3.0",
4
4
  "description": "CLI to rule the world. (and handle stuff related to Storyblok CMS)",
5
5
  "author": "Marcin Krawczyk <marckraw@icloud.com>",
6
6
  "license": "MIT",
@@ -38,6 +38,7 @@
38
38
  "lint-staged": "node ./src/scripts/fix-esm.js && lint-staged",
39
39
  "build": "rm -rf dist && tsc -p tsconfig.json && chmod +x ./dist/cli/index.js",
40
40
  "build:dev": "chokidar 'src/**/*.{js,ts,cjs,mjs}' -c 'yarn build'",
41
+ "build:dev:yalc": "chokidar 'src/**/*.{js,ts,cjs,mjs}' -c 'yarn build && yalc push'",
41
42
  "build:test": "tsc -p tsconfig.test.json",
42
43
  "build:test:dev": "chokidar '__tests__/**/*.ts' -c 'yarn build:test'",
43
44
  "lint:fix": "eslint --fix",
@@ -52,21 +53,21 @@
52
53
  "build:yalc": "yarn build && yalc push"
53
54
  },
54
55
  "dependencies": {
55
- "@mrck-labs/anton-sdk": "^0.0.15",
56
56
  "@swc/core": "1.3.41",
57
57
  "@swc/helpers": "0.4.14",
58
58
  "chalk": "^5.3.0",
59
- "dotenv": "^16.3.1",
59
+ "dotenv": "^16.4.5",
60
60
  "form-data": "^4.0.0",
61
- "fs-extra": "^11.1.1",
61
+ "fs-extra": "^11.2.0",
62
62
  "glob": "8",
63
63
  "meow": "^11.0.0",
64
64
  "ncp": "^2.0.0",
65
65
  "node-fetch": "^3.3.2",
66
66
  "rollup": "^3.28.0",
67
67
  "rollup-plugin-ts": "^3.4.4",
68
- "semver": "^7.5.4",
68
+ "semver": "^7.6.2",
69
69
  "storyblok-js-client": "^5.12.0",
70
+ "storyblok-schema-types": "^1.1.2",
70
71
  "typescript": "^5.1.6",
71
72
  "uuid": "^9.0.0"
72
73
  },
@@ -79,6 +80,7 @@
79
80
  "@semantic-release/changelog": "^6.0.3",
80
81
  "@semantic-release/git": "^10.0.1",
81
82
  "@sindresorhus/tsconfig": "^3.0.1",
83
+ "@storyblok/react": "^3.0.10",
82
84
  "@types/chai": "^4.3.10",
83
85
  "@types/fs-extra": "^11.0.4",
84
86
  "@types/glob": "^8.1.0",
@@ -1,2 +0,0 @@
1
- import type { CLIOptions } from "../../utils/interfaces.js";
2
- export declare const ask: (props: CLIOptions) => Promise<void>;
@@ -1,65 +0,0 @@
1
- import path from "path";
2
- import { Anton } from "@mrck-labs/anton-sdk";
3
- import config from "../../config/config.js";
4
- import Logger from "../../utils/logger.js";
5
- import { getFileContentWithRequire } from "../../utils/main.js";
6
- import * as descriptions from "../cli-descriptions.js";
7
- export const ask = async (props) => {
8
- const { input, flags } = props;
9
- console.log("whatever ?");
10
- try {
11
- const fileContent = await getFileContentWithRequire({
12
- file: path.join("..", "..", "package.json"),
13
- });
14
- const anton = new Anton(config.openaiToken);
15
- console.log(anton.setInitialMessages);
16
- // anton.doWhatever()
17
- anton.setInitialMessages([
18
- {
19
- role: "system",
20
- content: "Act like a lady from high house",
21
- },
22
- ]);
23
- const question = input[1];
24
- const cleanPackageJSON = {
25
- ...fileContent,
26
- scripts: null,
27
- };
28
- const cleanStoryblokConfig = {
29
- ...config,
30
- oauthToken: "hidden",
31
- openaiToken: "hidden",
32
- };
33
- const cleanAllDescriptions = {
34
- ...descriptions,
35
- };
36
- Logger.warning("Got it! Thinking...");
37
- const data = await anton.chatCompletion({
38
- body: {
39
- messages: [
40
- {
41
- role: "system",
42
- content: `Giving below context which is json object, answer the question asked with ONLY on using the CONTEXT.
43
- If u dont know the answet to question, simply say don't know. DO NOT try to generate answers at all cost if the context
44
- doesnt give you the answer.
45
- ### context start ###
46
- ${JSON.stringify(cleanStoryblokConfig, null, 0)}
47
- ${JSON.stringify(cleanPackageJSON, null, 0)}
48
- ${JSON.stringify(cleanAllDescriptions, null, 0)}
49
- ### context end ###
50
- `,
51
- },
52
- {
53
- role: "user",
54
- content: question,
55
- },
56
- ],
57
- },
58
- });
59
- Logger.success(data?.choices[0]?.message?.content);
60
- }
61
- catch (e) {
62
- console.log(e);
63
- Logger.warning("Can't find package.json");
64
- }
65
- };