@superblocksteam/vite-plugin-file-sync 2.0.37-next.51 → 2.0.37-next.6
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/dist/ai-service/agent/apis-system-prompt.d.ts +1 -1
- package/dist/ai-service/agent/apis-system-prompt.d.ts.map +1 -1
- package/dist/ai-service/agent/apis-system-prompt.js +2 -214
- package/dist/ai-service/agent/apis-system-prompt.js.map +1 -1
- package/dist/ai-service/agent/apis.d.ts.map +1 -1
- package/dist/ai-service/agent/apis.js +6 -71
- package/dist/ai-service/agent/apis.js.map +1 -1
- package/dist/ai-service/agent/tool-message-utils.js +14 -14
- package/dist/ai-service/agent/tool-message-utils.js.map +1 -1
- package/dist/ai-service/agent/tools/build-finalize.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/build-finalize.js +6 -2
- package/dist/ai-service/agent/tools/build-finalize.js.map +1 -1
- package/dist/ai-service/agent/tools/build-list-available-components.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/build-list-available-components.js +31 -5
- package/dist/ai-service/agent/tools/build-list-available-components.js.map +1 -1
- package/dist/ai-service/agent/utils.d.ts +0 -6
- package/dist/ai-service/agent/utils.d.ts.map +1 -1
- package/dist/ai-service/agent/utils.js +4 -46
- package/dist/ai-service/agent/utils.js.map +1 -1
- package/dist/ai-service/clark-provider/clark-language-model.d.ts.map +1 -1
- package/dist/ai-service/clark-provider/clark-language-model.js +10 -23
- package/dist/ai-service/clark-provider/clark-language-model.js.map +1 -1
- package/dist/ai-service/const.d.ts +12 -0
- package/dist/ai-service/const.d.ts.map +1 -1
- package/dist/ai-service/const.js +5 -0
- package/dist/ai-service/const.js.map +1 -1
- package/dist/ai-service/context/app-context.d.ts +0 -5
- package/dist/ai-service/context/app-context.d.ts.map +1 -1
- package/dist/ai-service/context/app-context.js +1 -18
- package/dist/ai-service/context/app-context.js.map +1 -1
- package/dist/ai-service/index.d.ts +1 -3
- package/dist/ai-service/index.d.ts.map +1 -1
- package/dist/ai-service/index.js +2 -25
- package/dist/ai-service/index.js.map +1 -1
- package/dist/ai-service/integrations/metadata/database.d.ts.map +1 -1
- package/dist/ai-service/integrations/metadata/database.js +5 -34
- package/dist/ai-service/integrations/metadata/database.js.map +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/library-components/ButtonPropsDocs.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/library-components/CheckboxPropsDocs.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/library-components/ColumnPropsDocs.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/library-components/ContainerPropsDocs.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/library-components/DatePickerPropsDocs.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/library-components/DropdownPropsDocs.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/library-components/IconPropsDocs.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/library-components/ImagePropsDocs.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/library-components/InputPropsDocs.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/library-components/ModalPropsDocs.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/library-components/PagePropsDocs.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/library-components/SectionPropsDocs.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/library-components/SlideoutPropsDocs.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/library-components/SwitchPropsDocs.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/library-components/TablePropsDocs.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/library-components/TextPropsDocs.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/library-typedefs/Dim.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/library-typedefs/EventFlow.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/library-typedefs/TextStyleWithVariant.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/platform-parts/full-examples.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/platform-parts/superblocks-api.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/platform-parts/superblocks-components-rules.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/platform-parts/superblocks-custom-components.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/platform-parts/superblocks-data-filtering.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/platform-parts/superblocks-event-flow.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/platform-parts/superblocks-forms.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/platform-parts/superblocks-layouts.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/platform-parts/superblocks-page.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/platform-parts/superblocks-rbac.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/platform-parts/superblocks-routes.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/platform-parts/superblocks-state.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/platform-parts/superblocks-theming-chakra-new.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/platform-parts/system-base.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/platform-parts/system-incremental.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/platform-parts/system-specific-edit.js +1 -1
- package/dist/ai-service/state-machine/clark-fsm.d.ts +1 -3
- package/dist/ai-service/state-machine/clark-fsm.d.ts.map +1 -1
- package/dist/ai-service/state-machine/clark-fsm.js.map +1 -1
- package/dist/ai-service/state-machine/handlers/agent-planning.d.ts.map +1 -1
- package/dist/ai-service/state-machine/handlers/agent-planning.js +1 -2
- package/dist/ai-service/state-machine/handlers/agent-planning.js.map +1 -1
- package/dist/ai-service/state-machine/handlers/llm-generating.d.ts.map +1 -1
- package/dist/ai-service/state-machine/handlers/llm-generating.js +5 -33
- package/dist/ai-service/state-machine/handlers/llm-generating.js.map +1 -1
- package/dist/ai-service/state-machine/handlers/simple-prompt-builder.d.ts.map +1 -1
- package/dist/ai-service/state-machine/handlers/simple-prompt-builder.js +80 -180
- package/dist/ai-service/state-machine/handlers/simple-prompt-builder.js.map +1 -1
- package/dist/custom-components.d.ts +6 -0
- package/dist/custom-components.d.ts.map +1 -0
- package/dist/custom-components.js +51 -0
- package/dist/custom-components.js.map +1 -0
- package/dist/file-sync-vite-plugin.d.ts.map +1 -1
- package/dist/file-sync-vite-plugin.js +68 -24
- package/dist/file-sync-vite-plugin.js.map +1 -1
- package/dist/file-system-manager.d.ts +2 -7
- package/dist/file-system-manager.d.ts.map +1 -1
- package/dist/file-system-manager.js +151 -139
- package/dist/file-system-manager.js.map +1 -1
- package/dist/parsing/theme.d.ts +3 -0
- package/dist/parsing/theme.d.ts.map +1 -0
- package/dist/parsing/theme.js +87 -0
- package/dist/parsing/theme.js.map +1 -0
- package/dist/socket-manager.d.ts +1 -2
- package/dist/socket-manager.d.ts.map +1 -1
- package/dist/socket-manager.js +4 -3
- package/dist/socket-manager.js.map +1 -1
- package/dist/source-tracker.d.ts +9 -1
- package/dist/source-tracker.d.ts.map +1 -1
- package/dist/source-tracker.js +16 -0
- package/dist/source-tracker.js.map +1 -1
- package/package.json +6 -6
- package/dist/ai-service/state-machine/helpers/cache-breakpoint.d.ts +0 -29
- package/dist/ai-service/state-machine/helpers/cache-breakpoint.d.ts.map +0 -1
- package/dist/ai-service/state-machine/helpers/cache-breakpoint.js +0 -58
- package/dist/ai-service/state-machine/helpers/cache-breakpoint.js.map +0 -1
|
@@ -10,6 +10,7 @@ import { isEqual } from "lodash-es";
|
|
|
10
10
|
import yaml from "yaml";
|
|
11
11
|
import { generateJSXAttribute } from "./codegen.js";
|
|
12
12
|
import { ComponentsManager } from "./components-manager.js";
|
|
13
|
+
import { addLegacyCustomComponentVariables, modifyLegacyCustomComponentElements, modifyLegacyCustomComponentImports, } from "./custom-components.js";
|
|
13
14
|
import { applyErrorHandling, } from "./errors/error-handler.js";
|
|
14
15
|
import { getApiFilePath, getPageFolder, isPageFilePath, PAGES_DIRECTORY, ROUTES_FILE, SCOPE_FILE, } from "./file-system-helpers.js";
|
|
15
16
|
import { generate } from "./generate.js";
|
|
@@ -19,7 +20,7 @@ import { getSbElementId } from "./parsing/ids.js";
|
|
|
19
20
|
import { makeJSXAttribute } from "./parsing/jsx.js";
|
|
20
21
|
import { getRootNodes } from "./parsing/page.js";
|
|
21
22
|
import { getScope } from "./parsing/scope.js";
|
|
22
|
-
import { getLegacyComponentsFolder } from "./plugin-options.js";
|
|
23
|
+
import { getLegacyComponentsFolder, isCustomBuildEnabled, } from "./plugin-options.js";
|
|
23
24
|
import { RenameManager } from "./rename-manager.js";
|
|
24
25
|
import { getFullImportPath } from "./resolver.js";
|
|
25
26
|
import { SourceTracker } from "./source-tracker.js";
|
|
@@ -52,6 +53,7 @@ const SUPPORTED_FILETYPES = [
|
|
|
52
53
|
extension: ".json",
|
|
53
54
|
},
|
|
54
55
|
];
|
|
56
|
+
const APP_THEME_FILE_NAME = "appTheme.ts";
|
|
55
57
|
export class FileSystemManager extends TracedEventEmitter {
|
|
56
58
|
rootDir;
|
|
57
59
|
tsFiles = {};
|
|
@@ -98,6 +100,7 @@ export class FileSystemManager extends TracedEventEmitter {
|
|
|
98
100
|
handleAddEntity: { operation: "adding an entity" },
|
|
99
101
|
handleUpdateEntity: { operation: "updating an entity" },
|
|
100
102
|
handleDeleteEntity: { operation: "deleting an entity" },
|
|
103
|
+
handleUpdateTheme: { operation: "updating the theme" },
|
|
101
104
|
handleRenameElement: { operation: "renaming an element" },
|
|
102
105
|
});
|
|
103
106
|
const methods = [
|
|
@@ -115,6 +118,7 @@ export class FileSystemManager extends TracedEventEmitter {
|
|
|
115
118
|
"handleAddEntity",
|
|
116
119
|
"handleUpdateEntity",
|
|
117
120
|
"handleDeleteEntity",
|
|
121
|
+
"handleUpdateTheme",
|
|
118
122
|
"handleRenameElement",
|
|
119
123
|
];
|
|
120
124
|
addTracingToMethods(this, methods, tracer);
|
|
@@ -142,6 +146,8 @@ export class FileSystemManager extends TracedEventEmitter {
|
|
|
142
146
|
const tsxFiles = fileNames.filter((f) => f.endsWith(".tsx") && !f.includes(`${getLegacyComponentsFolder()}/`));
|
|
143
147
|
const yamlFiles = fileNames.filter((f) => f.endsWith(".yaml"));
|
|
144
148
|
const scopeFiles = fileNames.filter((f) => f.endsWith(SCOPE_FILE));
|
|
149
|
+
// For the moment, the theme file is `appTheme.ts`. This may change in the future.
|
|
150
|
+
const appThemeFile = path.join(rootPath, APP_THEME_FILE_NAME);
|
|
145
151
|
logger.info(`scanning ${tsxFiles.length} code files`);
|
|
146
152
|
logger.info(`scanning ${yamlFiles.length} api files`);
|
|
147
153
|
logger.info(`scanning app theme file`);
|
|
@@ -169,6 +175,13 @@ export class FileSystemManager extends TracedEventEmitter {
|
|
|
169
175
|
};
|
|
170
176
|
}),
|
|
171
177
|
].flat();
|
|
178
|
+
if (appThemeFile) {
|
|
179
|
+
allFiles.push({
|
|
180
|
+
type: "ts",
|
|
181
|
+
path: appThemeFile,
|
|
182
|
+
content: readFile(appThemeFile),
|
|
183
|
+
});
|
|
184
|
+
}
|
|
172
185
|
const contents = await Promise.allSettled(allFiles.map((f) => f.content));
|
|
173
186
|
contents.forEach((result, i) => {
|
|
174
187
|
if (result.status === "rejected") {
|
|
@@ -258,9 +271,13 @@ export class FileSystemManager extends TracedEventEmitter {
|
|
|
258
271
|
}
|
|
259
272
|
const componentsManager = ComponentsManager.getInstance();
|
|
260
273
|
const processedTransactions = this.getProcessedTransactionsWithNonce();
|
|
274
|
+
const customImports = new Set();
|
|
261
275
|
traverse(clonedAst.ast, {
|
|
262
276
|
Program: {
|
|
263
277
|
exit(nodePath) {
|
|
278
|
+
if (isCustomBuildEnabled()) {
|
|
279
|
+
addLegacyCustomComponentVariables(nodePath, customImports);
|
|
280
|
+
}
|
|
264
281
|
// we want to inject the component name into the file so we can use it for hot reloading purposes
|
|
265
282
|
const name = componentsManager.getComponentName(filePath);
|
|
266
283
|
if (name) {
|
|
@@ -270,6 +287,19 @@ export class FileSystemManager extends TracedEventEmitter {
|
|
|
270
287
|
}
|
|
271
288
|
},
|
|
272
289
|
},
|
|
290
|
+
ImportDeclaration(path) {
|
|
291
|
+
if (isCustomBuildEnabled()) {
|
|
292
|
+
// when we see a custom component, we want to track the import and modify it to point
|
|
293
|
+
// to the built source
|
|
294
|
+
modifyLegacyCustomComponentImports(path, customImports);
|
|
295
|
+
}
|
|
296
|
+
},
|
|
297
|
+
JSXElement(path) {
|
|
298
|
+
if (isCustomBuildEnabled()) {
|
|
299
|
+
// based on the imports we see, we want to modify the JSXElement that uses the custom component
|
|
300
|
+
modifyLegacyCustomComponentElements(path, customImports);
|
|
301
|
+
}
|
|
302
|
+
},
|
|
273
303
|
ReturnStatement(path) {
|
|
274
304
|
const argument = path.get("argument");
|
|
275
305
|
if (!argument.isJSXElement()) {
|
|
@@ -939,6 +969,19 @@ export const ${name} = ${name}Scope.entities;
|
|
|
939
969
|
}
|
|
940
970
|
});
|
|
941
971
|
};
|
|
972
|
+
handleUpdateTheme = async (payload) => {
|
|
973
|
+
const { theme } = payload;
|
|
974
|
+
if (!this.rootDir) {
|
|
975
|
+
throw new Error("Root directory not set");
|
|
976
|
+
}
|
|
977
|
+
const filePath = path.join(this.rootDir, APP_THEME_FILE_NAME);
|
|
978
|
+
this.sourceTracker?.updateTheme({
|
|
979
|
+
themeFilePath: filePath,
|
|
980
|
+
theme,
|
|
981
|
+
});
|
|
982
|
+
const changes = (await this.sourceTracker?.getAndFlushChanges()) ?? [];
|
|
983
|
+
await this.writeChanges(changes);
|
|
984
|
+
};
|
|
942
985
|
handleAddComponentNameToScope = async (payload) => {
|
|
943
986
|
const { scopeName, componentName } = payload;
|
|
944
987
|
this.sourceTracker?.addScopeComponent({
|
|
@@ -998,164 +1041,133 @@ export const ${name} = ${name}Scope.entities;
|
|
|
998
1041
|
if (!this.rootDir) {
|
|
999
1042
|
throw new Error("Root directory not set");
|
|
1000
1043
|
}
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
throw
|
|
1044
|
+
const newPageFolder = getPageFolder(this.rootDir, newName);
|
|
1045
|
+
const oldPageFolder = getPageFolder(this.rootDir, oldName);
|
|
1046
|
+
const newIndexFilePath = path.join(newPageFolder, "index.tsx");
|
|
1047
|
+
const oldIndexFilePath = path.join(oldPageFolder, "index.tsx");
|
|
1048
|
+
const doesFileExist = await fs.stat(newIndexFilePath).catch(() => false);
|
|
1049
|
+
if (doesFileExist) {
|
|
1050
|
+
throw new Error(`Page ${newName} already exists`);
|
|
1008
1051
|
}
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1052
|
+
this.watcher?.unwatch(newPageFolder);
|
|
1053
|
+
this.watcher?.unwatch(oldPageFolder);
|
|
1054
|
+
let oldScope;
|
|
1055
|
+
let newScope;
|
|
1056
|
+
const oldScopeFilePath = path.join(oldPageFolder, SCOPE_FILE);
|
|
1057
|
+
const newScopeFilePath = path.join(newPageFolder, SCOPE_FILE);
|
|
1058
|
+
const existingRoute = Object.keys(this.routes).find((route) => this.routes[route]?.file ===
|
|
1059
|
+
this.getRelativeRoutePath(oldIndexFilePath));
|
|
1016
1060
|
try {
|
|
1017
|
-
if (!this.rootDir) {
|
|
1018
|
-
throw new Error("Root directory not set");
|
|
1019
|
-
}
|
|
1020
|
-
const newPageFolder = getPageFolder(this.rootDir, newName);
|
|
1021
|
-
const oldPageFolder = getPageFolder(this.rootDir, oldName);
|
|
1022
|
-
const newIndexFilePath = path.join(newPageFolder, "index.tsx");
|
|
1023
|
-
const oldIndexFilePath = path.join(oldPageFolder, "index.tsx");
|
|
1024
|
-
const oldScopeFilePath = path.join(oldPageFolder, SCOPE_FILE);
|
|
1025
|
-
const newScopeFilePath = path.join(newPageFolder, SCOPE_FILE);
|
|
1026
|
-
// Early validations
|
|
1027
|
-
const doesFileExist = await fs.stat(newIndexFilePath).catch(() => false);
|
|
1028
|
-
if (doesFileExist) {
|
|
1029
|
-
throw new Error(`Page ${newName} already exists`);
|
|
1030
|
-
}
|
|
1031
|
-
const existingRoute = Object.keys(this.routes).find((route) => this.routes[route]?.file ===
|
|
1032
|
-
this.getRelativeRoutePath(oldIndexFilePath));
|
|
1033
1061
|
if (!existingRoute) {
|
|
1034
1062
|
throw new Error(`Route for ${oldName} not found`);
|
|
1035
1063
|
}
|
|
1036
|
-
|
|
1064
|
+
oldScope = this.sourceTracker?.getScopeDefinitionForPage(oldName);
|
|
1037
1065
|
if (!oldScope) {
|
|
1038
1066
|
throw new Error(`Scope definition not found for old page, ${oldName}`);
|
|
1039
1067
|
}
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
newPageFolder,
|
|
1047
|
-
oldPageFolder,
|
|
1048
|
-
newIndexFilePath,
|
|
1049
|
-
oldIndexFilePath,
|
|
1050
|
-
newScopeFilePath,
|
|
1051
|
-
oldScopeFilePath,
|
|
1052
|
-
oldScope,
|
|
1053
|
-
existingRoute,
|
|
1054
|
-
};
|
|
1055
|
-
await this.commitRenamePageChanges(oldName, newName, changes);
|
|
1056
|
-
}
|
|
1057
|
-
catch (error) {
|
|
1058
|
-
if (snapshot && changes) {
|
|
1059
|
-
await this.rollbackRenamePageChanges(snapshot, changes);
|
|
1068
|
+
// we copy because its a safer operation than a rename, so it lets us
|
|
1069
|
+
// recover from errors
|
|
1070
|
+
await fs.cp(oldPageFolder, newPageFolder, { recursive: true });
|
|
1071
|
+
const newIndexFile = await readFile(newIndexFilePath);
|
|
1072
|
+
if (!newIndexFile) {
|
|
1073
|
+
throw new Error(`New index file ${newIndexFilePath} not found`);
|
|
1060
1074
|
}
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
async commitRenamePageChanges(oldName, newName, changes) {
|
|
1065
|
-
const { newPageFolder, oldPageFolder, newIndexFilePath, oldIndexFilePath, newScopeFilePath, oldScopeFilePath, existingRoute, } = changes;
|
|
1066
|
-
// we don't want to trigger fs events during the operation
|
|
1067
|
-
this.watcher?.unwatch(newPageFolder);
|
|
1068
|
-
this.watcher?.unwatch(oldPageFolder);
|
|
1069
|
-
await fs.cp(oldPageFolder, newPageFolder, { recursive: true });
|
|
1070
|
-
const newIndexFile = await readFile(newIndexFilePath);
|
|
1071
|
-
if (!newIndexFile) {
|
|
1072
|
-
throw new Error(`New index file ${newIndexFilePath} not found`);
|
|
1073
|
-
}
|
|
1074
|
-
const newScopeFile = await readFile(newScopeFilePath);
|
|
1075
|
-
if (!newScopeFile) {
|
|
1076
|
-
throw new Error(`New scope file ${newScopeFilePath} not found`);
|
|
1077
|
-
}
|
|
1078
|
-
delete this.tsFiles[oldIndexFilePath];
|
|
1079
|
-
delete this.tsFiles[oldScopeFilePath];
|
|
1080
|
-
// lets setup all the ast stuff for the new files
|
|
1081
|
-
await this.handleNonVisualChangeByDeletingIds(newScopeFilePath, newScopeFile);
|
|
1082
|
-
await this.handleNonVisualChangeByDeletingIds(newIndexFilePath, newIndexFile);
|
|
1083
|
-
Object.entries(this.tsFiles).forEach(([key, value]) => {
|
|
1084
|
-
if (key.startsWith(oldPageFolder)) {
|
|
1085
|
-
this.tsFiles[key.replace(oldPageFolder, newPageFolder)] = value;
|
|
1086
|
-
delete this.tsFiles[key];
|
|
1075
|
+
const newScopeFile = await readFile(newScopeFilePath);
|
|
1076
|
+
if (!newScopeFile) {
|
|
1077
|
+
throw new Error(`New scope file ${newScopeFilePath} not found`);
|
|
1087
1078
|
}
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
pageId: newScope.id,
|
|
1111
|
-
},
|
|
1112
|
-
},
|
|
1113
|
-
scopeId: newScope.id,
|
|
1114
|
-
pageName: newName,
|
|
1115
|
-
};
|
|
1116
|
-
delete this.apiFiles[key];
|
|
1079
|
+
delete this.tsFiles[oldIndexFilePath];
|
|
1080
|
+
delete this.tsFiles[oldScopeFilePath];
|
|
1081
|
+
// you have to write the scope first, otherwise the page parsing breaks
|
|
1082
|
+
await this.handleNonVisualChangeByDeletingIds(newScopeFilePath, newScopeFile);
|
|
1083
|
+
await this.handleNonVisualChangeByDeletingIds(newIndexFilePath, newIndexFile);
|
|
1084
|
+
// move all ts file sources first
|
|
1085
|
+
Object.entries(this.tsFiles).forEach(([key, value]) => {
|
|
1086
|
+
if (key.startsWith(oldPageFolder)) {
|
|
1087
|
+
this.tsFiles[key.replace(oldPageFolder, newPageFolder)] = value;
|
|
1088
|
+
}
|
|
1089
|
+
});
|
|
1090
|
+
// once we are tracking scope internally, we can perform all of the refactoring/renaming
|
|
1091
|
+
// in the actual code files
|
|
1092
|
+
this.sourceTracker?.renamePage({
|
|
1093
|
+
oldName,
|
|
1094
|
+
newName,
|
|
1095
|
+
scopeFilePath: newScopeFilePath,
|
|
1096
|
+
pageFilePath: newIndexFilePath,
|
|
1097
|
+
});
|
|
1098
|
+
newScope = this.sourceTracker?.getScopeDefinitionForPage(newName);
|
|
1099
|
+
if (!newScope) {
|
|
1100
|
+
throw new Error(`Scope definition not found for new page, ${newName}`);
|
|
1117
1101
|
}
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1102
|
+
// since we have a scope here, we can move APIs now
|
|
1103
|
+
Object.entries(this.apiFiles).forEach(([key, value]) => {
|
|
1104
|
+
if (key.startsWith(oldPageFolder)) {
|
|
1105
|
+
this.apiFiles[key.replace(oldPageFolder, newPageFolder)] = {
|
|
1106
|
+
...value,
|
|
1107
|
+
apiPb: {
|
|
1108
|
+
...value.apiPb,
|
|
1109
|
+
trigger: {
|
|
1110
|
+
...value.apiPb.trigger,
|
|
1111
|
+
pageName: newName,
|
|
1112
|
+
pageId: newScope.id,
|
|
1113
|
+
},
|
|
1114
|
+
},
|
|
1115
|
+
scopeId: newScope.id,
|
|
1116
|
+
pageName: newName,
|
|
1117
|
+
};
|
|
1118
|
+
delete this.apiFiles[key];
|
|
1119
|
+
}
|
|
1120
|
+
});
|
|
1121
|
+
}
|
|
1122
|
+
catch (error) {
|
|
1123
|
+
// reverse setting the files to the new paths
|
|
1124
|
+
Object.entries(this.tsFiles).forEach(([key, value]) => {
|
|
1125
|
+
if (key.startsWith(newPageFolder)) {
|
|
1126
|
+
this.tsFiles[key.replace(newPageFolder, oldPageFolder)] = value;
|
|
1127
|
+
}
|
|
1128
|
+
});
|
|
1129
|
+
Object.entries(this.apiFiles).forEach(([key, value]) => {
|
|
1130
|
+
if (key.startsWith(newPageFolder)) {
|
|
1131
|
+
this.apiFiles[key.replace(newPageFolder, oldPageFolder)] = {
|
|
1132
|
+
...value,
|
|
1133
|
+
apiPb: {
|
|
1134
|
+
...value.apiPb,
|
|
1135
|
+
trigger: {
|
|
1136
|
+
...value.apiPb.trigger,
|
|
1137
|
+
pageName: oldName,
|
|
1138
|
+
pageId: oldScope.id,
|
|
1139
|
+
},
|
|
1140
|
+
},
|
|
1141
|
+
scopeId: oldScope.id,
|
|
1142
|
+
pageName: oldName,
|
|
1143
|
+
};
|
|
1144
|
+
delete this.apiFiles[key];
|
|
1145
|
+
}
|
|
1146
|
+
});
|
|
1137
1147
|
await fs.rm(newPageFolder, { recursive: true }).catch((error) => {
|
|
1138
|
-
getLogger().warn(`Failed to delete new page folder ${newPageFolder}
|
|
1148
|
+
getLogger().warn(`Failed to delete new page folder ${newPageFolder}. Error: ${error}`);
|
|
1139
1149
|
});
|
|
1140
|
-
const oldScopeFile = await readFile(oldScopeFilePath)
|
|
1150
|
+
const oldScopeFile = await readFile(oldScopeFilePath);
|
|
1141
1151
|
if (oldScopeFile) {
|
|
1142
1152
|
await this.handleNonVisualChangeByDeletingIds(oldScopeFilePath, oldScopeFile);
|
|
1143
1153
|
}
|
|
1144
|
-
const oldIndexFile = await readFile(oldIndexFilePath)
|
|
1154
|
+
const oldIndexFile = await readFile(oldIndexFilePath);
|
|
1145
1155
|
if (oldIndexFile) {
|
|
1146
1156
|
await this.handleNonVisualChangeByDeletingIds(oldIndexFilePath, oldIndexFile);
|
|
1147
1157
|
}
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
await this.writeFile(path.join(this.rootDir, ROUTES_FILE), JSON.stringify(snapshot.routes, null, 2));
|
|
1151
|
-
}
|
|
1152
|
-
// resume watching the original folder
|
|
1153
|
-
this.watcher?.add(oldPageFolder);
|
|
1154
|
-
}
|
|
1155
|
-
catch (rollbackError) {
|
|
1156
|
-
getLogger().error("Error during transaction rollback", getErrorMeta(rollbackError));
|
|
1158
|
+
getLogger().error("Error renaming page", getErrorMeta(error));
|
|
1159
|
+
throw error;
|
|
1157
1160
|
}
|
|
1158
|
-
|
|
1161
|
+
await this.removeRoute(oldIndexFilePath);
|
|
1162
|
+
await this.addRoute(existingRoute, newIndexFilePath);
|
|
1163
|
+
await this.sourceTracker?.removeFile(oldIndexFilePath);
|
|
1164
|
+
await this.sourceTracker?.removeFile(oldScopeFilePath);
|
|
1165
|
+
const changes = (await this.sourceTracker?.getAndFlushChanges()) ?? [];
|
|
1166
|
+
await this.writeChanges(changes);
|
|
1167
|
+
this.watcher?.add(newPageFolder);
|
|
1168
|
+
await fs.rm(oldPageFolder, { recursive: true });
|
|
1169
|
+
this.emit("renamePage", newName);
|
|
1170
|
+
};
|
|
1159
1171
|
getRelativeRoutePath(filePath) {
|
|
1160
1172
|
if (!this.rootDir) {
|
|
1161
1173
|
throw new Error("Root directory not set");
|