@superblocksteam/cli 2.0.6-next.23 → 2.0.6-next.25
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 +1 -1
- package/dist/index.js +408 -410
- package/oclif.manifest.json +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -14,7 +14,7 @@ $ npm install -g @superblocksteam/cli
|
|
|
14
14
|
$ superblocks COMMAND
|
|
15
15
|
running command...
|
|
16
16
|
$ superblocks (--version)
|
|
17
|
-
@superblocksteam/cli/2.0.6-next.
|
|
17
|
+
@superblocksteam/cli/2.0.6-next.25 linux-x64 node-v20.19.0
|
|
18
18
|
$ superblocks --help [COMMAND]
|
|
19
19
|
USAGE
|
|
20
20
|
$ superblocks COMMAND
|
package/dist/index.js
CHANGED
|
@@ -400202,7 +400202,7 @@ var Property = {
|
|
|
400202
400202
|
Expression: (value2) => PropertyInfo(value2, "EXPRESSION"),
|
|
400203
400203
|
Event: (value2) => PropertyInfo(value2, "EVENT"),
|
|
400204
400204
|
Dimension: (value2) => PropertyInfo(value2, "DIMENSION"),
|
|
400205
|
-
Computed: (value2, args) => PropertyInfo(value2, "COMPUTED", Array.isArray(args) && args.length > 0 ? { args } : {}),
|
|
400205
|
+
Computed: (value2, args) => PropertyInfo(value2, "COMPUTED", Array.isArray(args) && args.length > 0 || typeof args === "string" ? { args } : {}),
|
|
400206
400206
|
Any: (value2, type2 = "STATIC") => PropertyInfo(value2, type2)
|
|
400207
400207
|
};
|
|
400208
400208
|
function isPropertyInfo(value2) {
|
|
@@ -431941,6 +431941,7 @@ init_cjs_shims();
|
|
|
431941
431941
|
import path21 from "node:path";
|
|
431942
431942
|
var PAGES_DIRECTORY = "pages";
|
|
431943
431943
|
var CUSTOM_COMPONENTS_DIRECTORY = "components";
|
|
431944
|
+
var API_FOLDER = "apis";
|
|
431944
431945
|
var ROUTES_FILE = "routes.json";
|
|
431945
431946
|
var SCOPE_FILE = "scope.ts";
|
|
431946
431947
|
function getPageFolder(rootPath, pageName) {
|
|
@@ -431952,6 +431953,9 @@ function getPageFilePath(rootPath, pageName) {
|
|
|
431952
431953
|
function isPageFilePath(filePath) {
|
|
431953
431954
|
return /pages\/.*\/index\.tsx/.test(filePath);
|
|
431954
431955
|
}
|
|
431956
|
+
function getApiFilePath(rootPath, pageName, apiName) {
|
|
431957
|
+
return path21.join(getPageFolder(rootPath, pageName), API_FOLDER, apiName, "api.yaml");
|
|
431958
|
+
}
|
|
431955
431959
|
|
|
431956
431960
|
// ../../../vite-plugin-file-sync/dist/traverse.js
|
|
431957
431961
|
init_cjs_shims();
|
|
@@ -432596,7 +432600,11 @@ function findFirstValidExpression(testCases) {
|
|
|
432596
432600
|
function toCodeComputed(value2, info) {
|
|
432597
432601
|
let argsString = "";
|
|
432598
432602
|
if (isComputedPropertyInfo(info)) {
|
|
432599
|
-
|
|
432603
|
+
if (Array.isArray(info.args)) {
|
|
432604
|
+
argsString = `{ ${info.args.join(", ")} }`;
|
|
432605
|
+
} else if (typeof info.args === "string") {
|
|
432606
|
+
argsString = info.args;
|
|
432607
|
+
}
|
|
432600
432608
|
}
|
|
432601
432609
|
const { hasThisReference, hasReturnStatement } = getFunctionBodyThisExpressionData(value2);
|
|
432602
432610
|
if (hasThisReference) {
|
|
@@ -436807,6 +436815,9 @@ var FileSystemManager = class extends import_shared32.TracedEventEmitter {
|
|
|
436807
436815
|
registeredComponentPaths = {};
|
|
436808
436816
|
renameManager = new RenameManager();
|
|
436809
436817
|
_tracer;
|
|
436818
|
+
transactionNonce = Date.now();
|
|
436819
|
+
pendingTransactions = /* @__PURE__ */ new Set();
|
|
436820
|
+
processedTransactions = [];
|
|
436810
436821
|
constructor(fsOperationQueue, generationNumberSequence, tracer2) {
|
|
436811
436822
|
super(tracer2, { captureRejections: true });
|
|
436812
436823
|
this.rootDir = "/";
|
|
@@ -436863,27 +436874,7 @@ var FileSystemManager = class extends import_shared32.TracedEventEmitter {
|
|
|
436863
436874
|
}
|
|
436864
436875
|
return path27.join(this.rootDir, "App.tsx");
|
|
436865
436876
|
}
|
|
436866
|
-
|
|
436867
|
-
if (!this.rootDir) {
|
|
436868
|
-
throw new Error("Root directory not set");
|
|
436869
|
-
}
|
|
436870
|
-
const { api: apiContents, stepPathMap } = content2;
|
|
436871
|
-
const pageName = getPageName2(path55);
|
|
436872
|
-
let scopeId = this.sourceTracker?.getScopeDefinitionForPage(pageName)?.id;
|
|
436873
|
-
if (!scopeId) {
|
|
436874
|
-
console.warn("Scope ID not found for API", apiContents.metadata.name);
|
|
436875
|
-
scopeId = "";
|
|
436876
|
-
}
|
|
436877
|
-
const updatedApi = {
|
|
436878
|
-
apiPb: import_yaml2.default.parse(JSON.stringify(apiContents)),
|
|
436879
|
-
pageName,
|
|
436880
|
-
stepPathMap,
|
|
436881
|
-
scopeId
|
|
436882
|
-
};
|
|
436883
|
-
const isNewApi = !this.apiFiles[path55];
|
|
436884
|
-
this.apiFiles[path55] = updatedApi;
|
|
436885
|
-
return { updatedApi, pageName, isNewApi };
|
|
436886
|
-
};
|
|
436877
|
+
// MARK: core setup/init
|
|
436887
436878
|
async watch(watcher, rootPath) {
|
|
436888
436879
|
const logger3 = getLogger();
|
|
436889
436880
|
this.rootDir = rootPath;
|
|
@@ -436961,11 +436952,113 @@ var FileSystemManager = class extends import_shared32.TracedEventEmitter {
|
|
|
436961
436952
|
return;
|
|
436962
436953
|
const { type: type2, path: path55 } = file;
|
|
436963
436954
|
if (type2 === "api") {
|
|
436964
|
-
this.
|
|
436955
|
+
this.updateInternalApiData(content2, path55);
|
|
436965
436956
|
}
|
|
436966
436957
|
});
|
|
436967
436958
|
watcher.on("all", this.handleFileChange);
|
|
436968
436959
|
}
|
|
436960
|
+
initializeSourceTracker() {
|
|
436961
|
+
this.sourceTracker = new SourceTracker(this._tracer);
|
|
436962
|
+
this.sourceTracker.initializeSourceTracker({
|
|
436963
|
+
files: this.tsFiles
|
|
436964
|
+
});
|
|
436965
|
+
}
|
|
436966
|
+
handleNonVisualChangeByDeletingIds(path55, content2) {
|
|
436967
|
+
if (!this.sourceTracker) {
|
|
436968
|
+
throw new Error("Source tracker not initialized");
|
|
436969
|
+
}
|
|
436970
|
+
return this.sourceTracker.handleNonVisualChangeByDeletingIds(path55, content2);
|
|
436971
|
+
}
|
|
436972
|
+
async getFileWithIds(filePath) {
|
|
436973
|
+
const logger3 = getLogger();
|
|
436974
|
+
if (!this.sourceTracker) {
|
|
436975
|
+
throw new Error("Source tracker not initialized");
|
|
436976
|
+
}
|
|
436977
|
+
const files = this.sourceTracker.getCurrentFiles();
|
|
436978
|
+
if (!files[filePath]) {
|
|
436979
|
+
throw new Error("File not found in source tracker " + filePath);
|
|
436980
|
+
}
|
|
436981
|
+
const ast = files[filePath].ast;
|
|
436982
|
+
if (!ast) {
|
|
436983
|
+
throw new Error("No AST found for file in source tracker " + filePath);
|
|
436984
|
+
}
|
|
436985
|
+
const clonedAst = await (0, import_core3.transformFromAstAsync)(ast, void 0, {
|
|
436986
|
+
ast: true
|
|
436987
|
+
});
|
|
436988
|
+
if (!clonedAst?.ast) {
|
|
436989
|
+
throw new Error("Failed to clone AST for file " + filePath);
|
|
436990
|
+
}
|
|
436991
|
+
const componentsManager = ComponentsManager.getInstance();
|
|
436992
|
+
const processedTransactions = this.getProcessedTransactionsWithNonce();
|
|
436993
|
+
const customImports = /* @__PURE__ */ new Set();
|
|
436994
|
+
traverse(clonedAst.ast, {
|
|
436995
|
+
Program: {
|
|
436996
|
+
exit(nodePath) {
|
|
436997
|
+
if (isCustomBuildEnabled()) {
|
|
436998
|
+
addLegacyCustomComponentVariables(nodePath, customImports);
|
|
436999
|
+
}
|
|
437000
|
+
const name18 = componentsManager.getComponentName(filePath);
|
|
437001
|
+
if (name18) {
|
|
437002
|
+
nodePath.pushContainer("body", import_types26.default.variableDeclaration("const", [
|
|
437003
|
+
import_types26.default.variableDeclarator(import_types26.default.identifier("componentName"), import_types26.default.stringLiteral(name18))
|
|
437004
|
+
]));
|
|
437005
|
+
}
|
|
437006
|
+
}
|
|
437007
|
+
},
|
|
437008
|
+
ImportDeclaration(path55) {
|
|
437009
|
+
if (isCustomBuildEnabled()) {
|
|
437010
|
+
modifyLegacyCustomComponentImports(path55, customImports);
|
|
437011
|
+
}
|
|
437012
|
+
},
|
|
437013
|
+
JSXElement(path55) {
|
|
437014
|
+
if (isCustomBuildEnabled()) {
|
|
437015
|
+
modifyLegacyCustomComponentElements(path55, customImports);
|
|
437016
|
+
}
|
|
437017
|
+
},
|
|
437018
|
+
ReturnStatement(path55) {
|
|
437019
|
+
const argument = path55.get("argument");
|
|
437020
|
+
if (!argument.isJSXElement()) {
|
|
437021
|
+
return;
|
|
437022
|
+
}
|
|
437023
|
+
const openingElement = argument.get("openingElement");
|
|
437024
|
+
if (!openingElement.isJSXOpeningElement()) {
|
|
437025
|
+
return;
|
|
437026
|
+
}
|
|
437027
|
+
openingElement.pushContainer("attributes", makeJSXAttribute(ROOT_WIDGET_ATTRIBUTE, "true"));
|
|
437028
|
+
openingElement.pushContainer("attributes", generateJSXAttribute(PROCESSED_TRANSACTIONS_ATTRIBUTE, {
|
|
437029
|
+
value: processedTransactions,
|
|
437030
|
+
type: "EXPRESSION",
|
|
437031
|
+
__info: true
|
|
437032
|
+
}));
|
|
437033
|
+
},
|
|
437034
|
+
JSXOpeningElement(path55) {
|
|
437035
|
+
const elementId = getSbElementId(path55.node);
|
|
437036
|
+
if (elementId) {
|
|
437037
|
+
path55.pushContainer("attributes", makeJSXAttribute(WIDGET_SOURCE_ID_ATTRIBUTE, elementId));
|
|
437038
|
+
}
|
|
437039
|
+
},
|
|
437040
|
+
ObjectProperty(path55) {
|
|
437041
|
+
const elementId = getSbElementId(path55.node);
|
|
437042
|
+
if (!elementId) {
|
|
437043
|
+
path55.skip();
|
|
437044
|
+
return;
|
|
437045
|
+
}
|
|
437046
|
+
path55.traverse({
|
|
437047
|
+
ObjectExpression(path56) {
|
|
437048
|
+
path56.pushContainer("properties", import_types26.default.objectProperty(import_types26.default.identifier("id"), import_types26.default.stringLiteral(elementId)));
|
|
437049
|
+
path56.skip();
|
|
437050
|
+
}
|
|
437051
|
+
});
|
|
437052
|
+
}
|
|
437053
|
+
});
|
|
437054
|
+
try {
|
|
437055
|
+
const result = generate(clonedAst.ast);
|
|
437056
|
+
return result.code;
|
|
437057
|
+
} catch (e) {
|
|
437058
|
+
logger3.error("Error generating file with ids", getErrorMeta(e));
|
|
437059
|
+
return null;
|
|
437060
|
+
}
|
|
437061
|
+
}
|
|
436969
437062
|
enableOperationsQueue() {
|
|
436970
437063
|
this.operationProcessor.enable();
|
|
436971
437064
|
}
|
|
@@ -436975,6 +437068,7 @@ var FileSystemManager = class extends import_shared32.TracedEventEmitter {
|
|
|
436975
437068
|
async flushOperations() {
|
|
436976
437069
|
await this.operationProcessor.flush();
|
|
436977
437070
|
}
|
|
437071
|
+
// MARK: file change handling
|
|
436978
437072
|
handleFileChange = async (event, filePath) => {
|
|
436979
437073
|
const logger3 = getLogger();
|
|
436980
437074
|
logger3.info(`File changed: ${filePath}, event: ${event}`);
|
|
@@ -437024,7 +437118,7 @@ var FileSystemManager = class extends import_shared32.TracedEventEmitter {
|
|
|
437024
437118
|
case "api":
|
|
437025
437119
|
case "python-api-step":
|
|
437026
437120
|
case "js-api-step": {
|
|
437027
|
-
await this.
|
|
437121
|
+
await this.processApiFileUpdates(filePath, fileType);
|
|
437028
437122
|
break;
|
|
437029
437123
|
}
|
|
437030
437124
|
}
|
|
@@ -437085,7 +437179,7 @@ var FileSystemManager = class extends import_shared32.TracedEventEmitter {
|
|
|
437085
437179
|
case "python-api-step":
|
|
437086
437180
|
case "js-api-step":
|
|
437087
437181
|
{
|
|
437088
|
-
await this.
|
|
437182
|
+
await this.processApiFileUpdates(filePath, fileType2);
|
|
437089
437183
|
}
|
|
437090
437184
|
break;
|
|
437091
437185
|
}
|
|
@@ -437110,7 +437204,7 @@ var FileSystemManager = class extends import_shared32.TracedEventEmitter {
|
|
|
437110
437204
|
filePath
|
|
437111
437205
|
},
|
|
437112
437206
|
execute: async () => {
|
|
437113
|
-
await this.
|
|
437207
|
+
await this.removeApiData(filePath);
|
|
437114
437208
|
}
|
|
437115
437209
|
});
|
|
437116
437210
|
}
|
|
@@ -437118,9 +437212,6 @@ var FileSystemManager = class extends import_shared32.TracedEventEmitter {
|
|
|
437118
437212
|
}
|
|
437119
437213
|
}
|
|
437120
437214
|
};
|
|
437121
|
-
getApiFiles() {
|
|
437122
|
-
return this.formatApisToClientApis(this.apiFiles);
|
|
437123
|
-
}
|
|
437124
437215
|
async deleteTsFile(filePath) {
|
|
437125
437216
|
delete this.tsFiles[filePath];
|
|
437126
437217
|
this.sourceTracker?.removeFile(filePath);
|
|
@@ -437128,35 +437219,13 @@ var FileSystemManager = class extends import_shared32.TracedEventEmitter {
|
|
|
437128
437219
|
this.emit("deletePage", filePath);
|
|
437129
437220
|
}
|
|
437130
437221
|
}
|
|
437131
|
-
async deleteApiFile(filePath) {
|
|
437132
|
-
const api = this.apiFiles[filePath];
|
|
437133
|
-
if (!api) {
|
|
437134
|
-
return;
|
|
437135
|
-
}
|
|
437136
|
-
delete this.apiFiles[filePath];
|
|
437137
|
-
this.sourceTracker?.deleteApi({
|
|
437138
|
-
pageName: api.pageName,
|
|
437139
|
-
apiName: api.apiPb.metadata.name
|
|
437140
|
-
});
|
|
437141
|
-
const changes = await this.sourceTracker?.getAndFlushChanges() ?? [];
|
|
437142
|
-
await this.writeChanges(changes);
|
|
437143
|
-
const scopeId = this.sourceTracker?.getScopeDefinitionForPage(api.pageName)?.id;
|
|
437144
|
-
this.emit("apiManualDelete", {
|
|
437145
|
-
api: {
|
|
437146
|
-
id: getClientApiId(api.apiPb.metadata.name, api.pageName),
|
|
437147
|
-
apiName: api.apiPb.metadata.name,
|
|
437148
|
-
// TODO(saksham): get pagename more defensively
|
|
437149
|
-
pageName: getPageName2(filePath),
|
|
437150
|
-
scopeId
|
|
437151
|
-
}
|
|
437152
|
-
});
|
|
437153
|
-
}
|
|
437154
437222
|
getTsFilePaths() {
|
|
437155
437223
|
return Object.keys(this.tsFiles);
|
|
437156
437224
|
}
|
|
437157
437225
|
getSourceTracker() {
|
|
437158
437226
|
return this.sourceTracker;
|
|
437159
437227
|
}
|
|
437228
|
+
// MARK: fs read/write
|
|
437160
437229
|
async writeFile(path55, content2, kind) {
|
|
437161
437230
|
if (kind === "ts") {
|
|
437162
437231
|
this.tsFiles[path55] = content2;
|
|
@@ -437170,7 +437239,7 @@ var FileSystemManager = class extends import_shared32.TracedEventEmitter {
|
|
|
437170
437239
|
delete apiPb.metadata.id;
|
|
437171
437240
|
}
|
|
437172
437241
|
const stepPathMap = currentApiFile?.stepPathMap ?? {};
|
|
437173
|
-
this.
|
|
437242
|
+
this.updateInternalApiData({ api: apiPb, stepPathMap }, path55);
|
|
437174
437243
|
await this.fsOperationQueue.enqueue(async () => {
|
|
437175
437244
|
await (0, import_util23.writeApiFiles)({ apiPb }, "api", path55.split("/").slice(0, -1).join("/"), false, [], [], { extractLargeSourceFiles: true, minLinesForExtraction: 1 }, new Set(Object.keys(this.apiFiles)), stepPathMap);
|
|
437176
437245
|
if (this.apiFiles[path55]) {
|
|
@@ -437182,107 +437251,26 @@ var FileSystemManager = class extends import_shared32.TracedEventEmitter {
|
|
|
437182
437251
|
readFile(path55) {
|
|
437183
437252
|
return this.tsFiles[path55];
|
|
437184
437253
|
}
|
|
437185
|
-
|
|
437186
|
-
|
|
437187
|
-
|
|
437188
|
-
files: this.tsFiles
|
|
437189
|
-
});
|
|
437190
|
-
}
|
|
437191
|
-
handleNonVisualChangeByDeletingIds(path55, content2) {
|
|
437192
|
-
if (!this.sourceTracker) {
|
|
437193
|
-
throw new Error("Source tracker not initialized");
|
|
437254
|
+
async addRoute(route, filePath) {
|
|
437255
|
+
if (!this.rootDir) {
|
|
437256
|
+
throw new Error("Root directory not set");
|
|
437194
437257
|
}
|
|
437195
|
-
|
|
437258
|
+
this.routes[route] = { file: this.getRelativeRoutePath(filePath) };
|
|
437259
|
+
await this.writeFile(path27.join(this.rootDir, ROUTES_FILE), JSON.stringify(this.routes, null, 2));
|
|
437196
437260
|
}
|
|
437197
|
-
async
|
|
437198
|
-
|
|
437199
|
-
|
|
437200
|
-
throw new Error("Source tracker not initialized");
|
|
437201
|
-
}
|
|
437202
|
-
const files = this.sourceTracker.getCurrentFiles();
|
|
437203
|
-
if (!files[filePath]) {
|
|
437204
|
-
throw new Error("File not found in source tracker " + filePath);
|
|
437205
|
-
}
|
|
437206
|
-
const ast = files[filePath].ast;
|
|
437207
|
-
if (!ast) {
|
|
437208
|
-
throw new Error("No AST found for file in source tracker " + filePath);
|
|
437209
|
-
}
|
|
437210
|
-
const clonedAst = await (0, import_core3.transformFromAstAsync)(ast, void 0, {
|
|
437211
|
-
ast: true
|
|
437212
|
-
});
|
|
437213
|
-
if (!clonedAst?.ast) {
|
|
437214
|
-
throw new Error("Failed to clone AST for file " + filePath);
|
|
437215
|
-
}
|
|
437216
|
-
const componentsManager = ComponentsManager.getInstance();
|
|
437217
|
-
const processedTransactions = this.getProcessedTransactionsWithNonce();
|
|
437218
|
-
const customImports = /* @__PURE__ */ new Set();
|
|
437219
|
-
traverse(clonedAst.ast, {
|
|
437220
|
-
Program: {
|
|
437221
|
-
exit(nodePath) {
|
|
437222
|
-
if (isCustomBuildEnabled()) {
|
|
437223
|
-
addLegacyCustomComponentVariables(nodePath, customImports);
|
|
437224
|
-
}
|
|
437225
|
-
const name18 = componentsManager.getComponentName(filePath);
|
|
437226
|
-
if (name18) {
|
|
437227
|
-
nodePath.pushContainer("body", import_types26.default.variableDeclaration("const", [
|
|
437228
|
-
import_types26.default.variableDeclarator(import_types26.default.identifier("componentName"), import_types26.default.stringLiteral(name18))
|
|
437229
|
-
]));
|
|
437230
|
-
}
|
|
437231
|
-
}
|
|
437232
|
-
},
|
|
437233
|
-
ImportDeclaration(path55) {
|
|
437234
|
-
if (isCustomBuildEnabled()) {
|
|
437235
|
-
modifyLegacyCustomComponentImports(path55, customImports);
|
|
437236
|
-
}
|
|
437237
|
-
},
|
|
437238
|
-
JSXElement(path55) {
|
|
437239
|
-
if (isCustomBuildEnabled()) {
|
|
437240
|
-
modifyLegacyCustomComponentElements(path55, customImports);
|
|
437241
|
-
}
|
|
437242
|
-
},
|
|
437243
|
-
ReturnStatement(path55) {
|
|
437244
|
-
const argument = path55.get("argument");
|
|
437245
|
-
if (!argument.isJSXElement()) {
|
|
437246
|
-
return;
|
|
437247
|
-
}
|
|
437248
|
-
const openingElement = argument.get("openingElement");
|
|
437249
|
-
if (!openingElement.isJSXOpeningElement()) {
|
|
437250
|
-
return;
|
|
437251
|
-
}
|
|
437252
|
-
openingElement.pushContainer("attributes", makeJSXAttribute(ROOT_WIDGET_ATTRIBUTE, "true"));
|
|
437253
|
-
openingElement.pushContainer("attributes", generateJSXAttribute(PROCESSED_TRANSACTIONS_ATTRIBUTE, {
|
|
437254
|
-
value: processedTransactions,
|
|
437255
|
-
type: "EXPRESSION",
|
|
437256
|
-
__info: true
|
|
437257
|
-
}));
|
|
437258
|
-
},
|
|
437259
|
-
JSXOpeningElement(path55) {
|
|
437260
|
-
const elementId = getSbElementId(path55.node);
|
|
437261
|
-
if (elementId) {
|
|
437262
|
-
path55.pushContainer("attributes", makeJSXAttribute(WIDGET_SOURCE_ID_ATTRIBUTE, elementId));
|
|
437263
|
-
}
|
|
437264
|
-
},
|
|
437265
|
-
ObjectProperty(path55) {
|
|
437266
|
-
const elementId = getSbElementId(path55.node);
|
|
437267
|
-
if (!elementId) {
|
|
437268
|
-
path55.skip();
|
|
437269
|
-
return;
|
|
437270
|
-
}
|
|
437271
|
-
path55.traverse({
|
|
437272
|
-
ObjectExpression(path56) {
|
|
437273
|
-
path56.pushContainer("properties", import_types26.default.objectProperty(import_types26.default.identifier("id"), import_types26.default.stringLiteral(elementId)));
|
|
437274
|
-
path56.skip();
|
|
437275
|
-
}
|
|
437276
|
-
});
|
|
437277
|
-
}
|
|
437278
|
-
});
|
|
437279
|
-
try {
|
|
437280
|
-
const result = generate(clonedAst.ast);
|
|
437281
|
-
return result.code;
|
|
437282
|
-
} catch (e) {
|
|
437283
|
-
logger3.error("Error generating file with ids", getErrorMeta(e));
|
|
437284
|
-
return null;
|
|
437261
|
+
async removeRoute(filePath) {
|
|
437262
|
+
if (!this.rootDir) {
|
|
437263
|
+
throw new Error("Root directory not set");
|
|
437285
437264
|
}
|
|
437265
|
+
const relativeFilePath = this.getRelativeRoutePath(filePath);
|
|
437266
|
+
this.routes = Object.fromEntries(Object.entries(this.routes).filter(([_, value2]) => value2.file !== relativeFilePath));
|
|
437267
|
+
await this.writeFile(path27.join(this.rootDir, ROUTES_FILE), JSON.stringify(this.routes, null, 2));
|
|
437268
|
+
}
|
|
437269
|
+
async writeChanges(changes, callback) {
|
|
437270
|
+
return Promise.all(changes.map(async ({ fileName, source: source2, kind }) => {
|
|
437271
|
+
await this.writeFile(fileName, source2, kind);
|
|
437272
|
+
return callback?.(fileName, source2);
|
|
437273
|
+
}));
|
|
437286
437274
|
}
|
|
437287
437275
|
getLocalBindingEntities(path55) {
|
|
437288
437276
|
const logger3 = getLogger();
|
|
@@ -437311,8 +437299,35 @@ var FileSystemManager = class extends import_shared32.TracedEventEmitter {
|
|
|
437311
437299
|
});
|
|
437312
437300
|
return Array.from(localBindingEntities);
|
|
437313
437301
|
}
|
|
437314
|
-
|
|
437315
|
-
|
|
437302
|
+
getPageRoots(filePath) {
|
|
437303
|
+
const scopeFilePath = path27.join(path27.dirname(filePath), "index.tsx");
|
|
437304
|
+
const currentFile = this.sourceTracker?.getCurrentFiles()[scopeFilePath];
|
|
437305
|
+
if (!currentFile) {
|
|
437306
|
+
return null;
|
|
437307
|
+
}
|
|
437308
|
+
return getPageRoots(filePath, currentFile);
|
|
437309
|
+
}
|
|
437310
|
+
getScope(filePath) {
|
|
437311
|
+
const scopeFilePath = path27.join(path27.dirname(filePath), SCOPE_FILE);
|
|
437312
|
+
const currentFile = this.sourceTracker?.getCurrentFiles()[scopeFilePath];
|
|
437313
|
+
if (!currentFile) {
|
|
437314
|
+
console.log("File not found", scopeFilePath);
|
|
437315
|
+
return null;
|
|
437316
|
+
}
|
|
437317
|
+
const scope = getScope(scopeFilePath, currentFile);
|
|
437318
|
+
return scope;
|
|
437319
|
+
}
|
|
437320
|
+
getRoutes() {
|
|
437321
|
+
const routes = [];
|
|
437322
|
+
for (const [path55, { file }] of Object.entries(this.routes)) {
|
|
437323
|
+
routes.push({
|
|
437324
|
+
path: path55,
|
|
437325
|
+
component: file
|
|
437326
|
+
});
|
|
437327
|
+
}
|
|
437328
|
+
return routes;
|
|
437329
|
+
}
|
|
437330
|
+
// MARK: transaction handling
|
|
437316
437331
|
flushTransactions = () => {
|
|
437317
437332
|
this.processedTransactions = this.processedTransactions.slice(-20);
|
|
437318
437333
|
this.processedTransactions.push(...Array.from(this.pendingTransactions));
|
|
@@ -437324,13 +437339,13 @@ var FileSystemManager = class extends import_shared32.TracedEventEmitter {
|
|
|
437324
437339
|
}
|
|
437325
437340
|
this.pendingTransactions.add(transactionId);
|
|
437326
437341
|
};
|
|
437327
|
-
transactionNonce = Date.now();
|
|
437328
437342
|
// Until we have a sophisticated way to track ALL operations, including non-UI initiated ops, we will use a nonce
|
|
437329
437343
|
// TODO https://github.com/superblocksteam/superblocks/pull/11788
|
|
437330
437344
|
getProcessedTransactionsWithNonce() {
|
|
437331
437345
|
const nonce = `t-${this.transactionNonce++}`;
|
|
437332
437346
|
return this.processedTransactions.concat(nonce);
|
|
437333
437347
|
}
|
|
437348
|
+
// MARK: editor operations
|
|
437334
437349
|
handleCreatePage = async (payload) => {
|
|
437335
437350
|
const { name: name18 } = payload;
|
|
437336
437351
|
if (!this.rootDir) {
|
|
@@ -437350,7 +437365,9 @@ function Page() {
|
|
|
437350
437365
|
export default registerPage(Page, { name: "${name18}" });
|
|
437351
437366
|
`
|
|
437352
437367
|
);
|
|
437353
|
-
await
|
|
437368
|
+
await this.fsOperationQueue.enqueue(async () => {
|
|
437369
|
+
await fs12.mkdir(pagePath, { recursive: true });
|
|
437370
|
+
});
|
|
437354
437371
|
await this.writeFile(pageIndexPath, pageContent, "ts");
|
|
437355
437372
|
await this.handleNonVisualChangeByDeletingIds(pageIndexPath, pageContent);
|
|
437356
437373
|
this.emit("addPage", pageIndexPath);
|
|
@@ -437477,173 +437494,7 @@ export default registerPage(Page, { name: "${name18}" });
|
|
|
437477
437494
|
this.flushTransactions();
|
|
437478
437495
|
return returnValues;
|
|
437479
437496
|
};
|
|
437480
|
-
|
|
437481
|
-
const { api } = payload;
|
|
437482
|
-
if (!this.sourceTracker) {
|
|
437483
|
-
throw new Error("Source tracker not initialized");
|
|
437484
|
-
}
|
|
437485
|
-
if (!this.rootDir) {
|
|
437486
|
-
throw new Error("Root directory not set");
|
|
437487
|
-
}
|
|
437488
|
-
if (!api.pageName) {
|
|
437489
|
-
throw new Error("API page name is not set");
|
|
437490
|
-
}
|
|
437491
|
-
const apiName = api.apiPb.metadata.name;
|
|
437492
|
-
if (!apiName) {
|
|
437493
|
-
throw new Error("API name is not set");
|
|
437494
|
-
}
|
|
437495
|
-
const apiDir = path27.join(this.rootDir, "pages", api.pageName, "apis", apiName);
|
|
437496
|
-
const apiPath = path27.join(apiDir, "api.yaml");
|
|
437497
|
-
const isNewApi = !this.getApiFiles()[apiPath];
|
|
437498
|
-
try {
|
|
437499
|
-
const stats = await fs12.stat(apiDir);
|
|
437500
|
-
if (!stats.isDirectory()) {
|
|
437501
|
-
await fs12.mkdir(apiDir, { recursive: true });
|
|
437502
|
-
}
|
|
437503
|
-
} catch {
|
|
437504
|
-
await fs12.mkdir(apiDir, { recursive: true });
|
|
437505
|
-
}
|
|
437506
|
-
await this.writeFile(apiPath, import_yaml2.default.stringify(api.apiPb), "api");
|
|
437507
|
-
const generationNumber = this.generationNumberSequence.next();
|
|
437508
|
-
const apiDef = this.createClientApi(api);
|
|
437509
|
-
let scopeId = "";
|
|
437510
|
-
if (isNewApi) {
|
|
437511
|
-
scopeId = await this.createScopedApi(api);
|
|
437512
|
-
} else {
|
|
437513
|
-
const scopeDef = this.sourceTracker.getScopeDefinitionForPage(api.pageName);
|
|
437514
|
-
scopeId = scopeDef?.id ?? "";
|
|
437515
|
-
}
|
|
437516
|
-
this.emit("apiUpdate", { api: apiDef, scopeId });
|
|
437517
|
-
return { api: apiDef, scopeId, generationNumber };
|
|
437518
|
-
};
|
|
437519
|
-
createScopedApi = async (api) => {
|
|
437520
|
-
if (!this.sourceTracker) {
|
|
437521
|
-
throw new Error("Source tracker not initialized");
|
|
437522
|
-
}
|
|
437523
|
-
const scopeId = await this.sourceTracker.addApi({
|
|
437524
|
-
pageName: api.pageName,
|
|
437525
|
-
apiName: api.apiPb.metadata.name
|
|
437526
|
-
});
|
|
437527
|
-
const changes = await this.sourceTracker?.getAndFlushChanges() ?? [];
|
|
437528
|
-
await this.writeChanges(changes);
|
|
437529
|
-
return scopeId;
|
|
437530
|
-
};
|
|
437531
|
-
handleDeleteApi = async (payload) => {
|
|
437532
|
-
const logger3 = getLogger();
|
|
437533
|
-
const { apis } = payload;
|
|
437534
|
-
if (!this.rootDir) {
|
|
437535
|
-
throw new Error("Root directory not set");
|
|
437536
|
-
}
|
|
437537
|
-
const rootDir = this.rootDir;
|
|
437538
|
-
const executeDeleteApis = Promise.all(apis.map(({ apiName, pageName }) => {
|
|
437539
|
-
return new Promise(
|
|
437540
|
-
// eslint-disable-next-line no-async-promise-executor
|
|
437541
|
-
async (resolve9) => {
|
|
437542
|
-
const apiFilePath = path27.join(rootDir, "pages", pageName, "apis", apiName, "api.yaml");
|
|
437543
|
-
const api = this.apiFiles[apiFilePath];
|
|
437544
|
-
if (!api || !this.sourceTracker) {
|
|
437545
|
-
return resolve9(void 0);
|
|
437546
|
-
}
|
|
437547
|
-
const apiDir = path27.join(rootDir, "pages", pageName, "apis", apiName);
|
|
437548
|
-
try {
|
|
437549
|
-
const stats = await fs12.stat(apiDir);
|
|
437550
|
-
if (stats.isDirectory()) {
|
|
437551
|
-
await fs12.rmdir(apiDir, { recursive: true });
|
|
437552
|
-
}
|
|
437553
|
-
delete this.apiFiles[apiFilePath];
|
|
437554
|
-
const scopeId = this.sourceTracker.deleteApi({
|
|
437555
|
-
pageName,
|
|
437556
|
-
apiName
|
|
437557
|
-
});
|
|
437558
|
-
resolve9({
|
|
437559
|
-
apiName,
|
|
437560
|
-
pageName,
|
|
437561
|
-
scopeId
|
|
437562
|
-
});
|
|
437563
|
-
} catch (e) {
|
|
437564
|
-
logger3.warn(`Could not delete api ${apiFilePath} ${JSON.stringify(e)}`);
|
|
437565
|
-
resolve9(void 0);
|
|
437566
|
-
}
|
|
437567
|
-
resolve9(void 0);
|
|
437568
|
-
}
|
|
437569
|
-
);
|
|
437570
|
-
}));
|
|
437571
|
-
const deletedApis = (await executeDeleteApis).filter((api) => api !== void 0);
|
|
437572
|
-
const changes = await this.sourceTracker?.getAndFlushChanges() ?? [];
|
|
437573
|
-
await this.writeChanges(changes);
|
|
437574
|
-
this.emit("apiDelete", {
|
|
437575
|
-
apis: deletedApis.filter((api) => api !== void 0)
|
|
437576
|
-
});
|
|
437577
|
-
return { deletedApis };
|
|
437578
|
-
};
|
|
437579
|
-
handleRenameApi = async (payload) => {
|
|
437580
|
-
const { oldName, newName, pageName } = payload;
|
|
437581
|
-
if (!this.rootDir) {
|
|
437582
|
-
throw new Error("Root directory not set");
|
|
437583
|
-
}
|
|
437584
|
-
const pagePath = getPageFolder(this.rootDir, pageName);
|
|
437585
|
-
const existingApiFolder = path27.join(this.rootDir, "pages", pageName, "apis", oldName);
|
|
437586
|
-
const newApiFolder = path27.join(this.rootDir, "pages", pageName, "apis", newName);
|
|
437587
|
-
const files = this.sourceTracker?.getCurrentFiles();
|
|
437588
|
-
const file = files?.[path27.join(pagePath, "index.tsx")];
|
|
437589
|
-
if (!file || !file.ast) {
|
|
437590
|
-
throw new Error(`Page ${pageName} not found`);
|
|
437591
|
-
}
|
|
437592
|
-
const apiFilePath = path27.join(existingApiFolder, "api.yaml");
|
|
437593
|
-
const apiDef = this.apiFiles[apiFilePath];
|
|
437594
|
-
if (!apiDef) {
|
|
437595
|
-
throw new Error(`API ${oldName} not found`);
|
|
437596
|
-
}
|
|
437597
|
-
const otherPageAPIs = structuredClone(Object.keys(this.apiFiles).filter((path55) => path55.startsWith(pagePath) && path55 !== apiFilePath).map((path55) => ({
|
|
437598
|
-
api: { apiPb: this.apiFiles[path55]?.apiPb },
|
|
437599
|
-
filePath: path55
|
|
437600
|
-
})).filter((api) => !!api.api));
|
|
437601
|
-
const newApiFolderExists = await fs12.stat(newApiFolder).catch(() => false);
|
|
437602
|
-
if (newApiFolderExists) {
|
|
437603
|
-
throw new Error(`API ${newName} already exists`);
|
|
437604
|
-
}
|
|
437605
|
-
this.watcher?.unwatch(existingApiFolder);
|
|
437606
|
-
this.watcher?.unwatch(newApiFolder);
|
|
437607
|
-
apiDef.apiPb.metadata.name = newName;
|
|
437608
|
-
await fs12.rename(existingApiFolder, newApiFolder);
|
|
437609
|
-
const scopeDef = this.sourceTracker?.getScopeDefinitionForPage(pageName);
|
|
437610
|
-
if (!scopeDef) {
|
|
437611
|
-
throw new Error(`Scope definition not found for API`);
|
|
437612
|
-
}
|
|
437613
|
-
this.sourceTracker?.renameEntity({
|
|
437614
|
-
oldName,
|
|
437615
|
-
newName,
|
|
437616
|
-
entityId: scopeDef.scopeNameToEntityId[oldName]
|
|
437617
|
-
});
|
|
437618
|
-
delete this.apiFiles[apiFilePath];
|
|
437619
|
-
this.writeFile(path27.join(newApiFolder, "api.yaml"), import_yaml2.default.stringify(apiDef.apiPb), "api");
|
|
437620
|
-
this.watcher?.add(existingApiFolder);
|
|
437621
|
-
this.watcher?.add(newApiFolder);
|
|
437622
|
-
const changes = await this.sourceTracker?.getAndFlushChanges() ?? [];
|
|
437623
|
-
await this.writeChanges(changes);
|
|
437624
|
-
this.emit("apiManualUpdate", {
|
|
437625
|
-
api: this.createClientApi(apiDef),
|
|
437626
|
-
oldName,
|
|
437627
|
-
pageName,
|
|
437628
|
-
scopeId: scopeDef?.id ?? ""
|
|
437629
|
-
}, true);
|
|
437630
|
-
await this.renameManager.renameEntityInApis({
|
|
437631
|
-
oldName,
|
|
437632
|
-
newName,
|
|
437633
|
-
apis: otherPageAPIs
|
|
437634
|
-
});
|
|
437635
|
-
await Promise.all(otherPageAPIs.map(async ({ api, filePath }) => {
|
|
437636
|
-
if (isEqual_default(api?.apiPb, this.apiFiles[filePath]?.apiPb)) {
|
|
437637
|
-
return Promise.resolve();
|
|
437638
|
-
}
|
|
437639
|
-
await this.writeFile(filePath, import_yaml2.default.stringify(api?.apiPb), "api");
|
|
437640
|
-
this.emit("apiManualUpdate", {
|
|
437641
|
-
api: this.createClientApi(api),
|
|
437642
|
-
pageName,
|
|
437643
|
-
scopeId: scopeDef?.id ?? ""
|
|
437644
|
-
}, true);
|
|
437645
|
-
}));
|
|
437646
|
-
};
|
|
437497
|
+
// MARK: entity operations
|
|
437647
437498
|
handleAddEntity = async (payload) => {
|
|
437648
437499
|
this.sourceTracker?.addEntity({
|
|
437649
437500
|
scopeId: payload.scopeId,
|
|
@@ -437692,6 +437543,7 @@ export default registerPage(Page, { name: "${name18}" });
|
|
|
437692
437543
|
const changes = await this.sourceTracker?.getAndFlushChanges() ?? [];
|
|
437693
437544
|
await this.writeChanges(changes);
|
|
437694
437545
|
};
|
|
437546
|
+
// MARK: rename operations
|
|
437695
437547
|
handleRenameElement = async (payload) => {
|
|
437696
437548
|
if (payload.kind === "component") {
|
|
437697
437549
|
return this.handleRenameComponent(payload);
|
|
@@ -437767,93 +437619,195 @@ export default registerPage(Page, { name: "${name18}" });
|
|
|
437767
437619
|
this.watcher?.add(newPageFolder);
|
|
437768
437620
|
this.watcher?.add(oldPageFolder);
|
|
437769
437621
|
};
|
|
437770
|
-
|
|
437771
|
-
|
|
437772
|
-
|
|
437773
|
-
if (!currentFile) {
|
|
437774
|
-
return null;
|
|
437622
|
+
getRelativeRoutePath(filePath) {
|
|
437623
|
+
if (!this.rootDir) {
|
|
437624
|
+
throw new Error("Root directory not set");
|
|
437775
437625
|
}
|
|
437776
|
-
return
|
|
437626
|
+
return path27.relative(path27.join(this.rootDir, PAGES_DIRECTORY), filePath);
|
|
437777
437627
|
}
|
|
437778
|
-
|
|
437779
|
-
|
|
437780
|
-
const
|
|
437781
|
-
if (!
|
|
437782
|
-
|
|
437783
|
-
return null;
|
|
437628
|
+
// MARK: API operations
|
|
437629
|
+
handleUpdateApi = async (payload) => {
|
|
437630
|
+
const { api } = payload;
|
|
437631
|
+
if (!this.sourceTracker) {
|
|
437632
|
+
throw new Error("Source tracker not initialized");
|
|
437784
437633
|
}
|
|
437785
|
-
|
|
437786
|
-
|
|
437787
|
-
}
|
|
437788
|
-
getRoutes() {
|
|
437789
|
-
const routes = [];
|
|
437790
|
-
for (const [path55, { file }] of Object.entries(this.routes)) {
|
|
437791
|
-
routes.push({
|
|
437792
|
-
path: path55,
|
|
437793
|
-
component: file
|
|
437794
|
-
});
|
|
437634
|
+
if (!this.rootDir) {
|
|
437635
|
+
throw new Error("Root directory not set");
|
|
437795
437636
|
}
|
|
437796
|
-
|
|
437797
|
-
|
|
437798
|
-
|
|
437637
|
+
if (!api.pageName) {
|
|
437638
|
+
throw new Error("API page name is not set");
|
|
437639
|
+
}
|
|
437640
|
+
const apiName = api.apiPb.metadata.name;
|
|
437641
|
+
if (!apiName) {
|
|
437642
|
+
throw new Error("API name is not set");
|
|
437643
|
+
}
|
|
437644
|
+
const apiFilePath = getApiFilePath(this.rootDir, api.pageName, apiName);
|
|
437645
|
+
const apiDir = path27.dirname(apiFilePath);
|
|
437646
|
+
const isNewApi = !this.getApiFiles()[apiFilePath];
|
|
437647
|
+
try {
|
|
437648
|
+
const stats = await fs12.stat(apiDir);
|
|
437649
|
+
if (!stats.isDirectory()) {
|
|
437650
|
+
await this.fsOperationQueue.enqueue(async () => await fs12.mkdir(apiDir, { recursive: true }));
|
|
437651
|
+
}
|
|
437652
|
+
} catch {
|
|
437653
|
+
await this.fsOperationQueue.enqueue(async () => await fs12.mkdir(apiDir, { recursive: true }));
|
|
437654
|
+
}
|
|
437655
|
+
await this.writeFile(apiFilePath, import_yaml2.default.stringify(api.apiPb), "api");
|
|
437656
|
+
const generationNumber = this.generationNumberSequence.next();
|
|
437657
|
+
const apiDef = this.createClientApi(api);
|
|
437658
|
+
let scopeId = "";
|
|
437659
|
+
if (isNewApi) {
|
|
437660
|
+
scopeId = await this.addApiToScope(api);
|
|
437661
|
+
} else {
|
|
437662
|
+
const scopeDef = this.sourceTracker.getScopeDefinitionForPage(api.pageName);
|
|
437663
|
+
scopeId = scopeDef?.id ?? "";
|
|
437664
|
+
}
|
|
437665
|
+
this.emit("apiUpdate", { api: apiDef, scopeId });
|
|
437666
|
+
return { api: apiDef, scopeId, generationNumber };
|
|
437667
|
+
};
|
|
437668
|
+
handleDeleteApi = async (payload) => {
|
|
437669
|
+
const logger3 = getLogger();
|
|
437670
|
+
const { apis } = payload;
|
|
437799
437671
|
if (!this.rootDir) {
|
|
437800
437672
|
throw new Error("Root directory not set");
|
|
437801
437673
|
}
|
|
437802
|
-
|
|
437803
|
-
|
|
437804
|
-
|
|
437805
|
-
|
|
437674
|
+
const rootDir = this.rootDir;
|
|
437675
|
+
const deletedApis = [];
|
|
437676
|
+
for (const { apiName, pageName } of apis) {
|
|
437677
|
+
const apiFilePath = getApiFilePath(rootDir, pageName, apiName);
|
|
437678
|
+
const api = this.apiFiles[apiFilePath];
|
|
437679
|
+
if (!api || !this.sourceTracker) {
|
|
437680
|
+
continue;
|
|
437681
|
+
}
|
|
437682
|
+
const apiDir = path27.dirname(apiFilePath);
|
|
437683
|
+
try {
|
|
437684
|
+
const stats = await fs12.stat(apiDir);
|
|
437685
|
+
if (stats.isDirectory()) {
|
|
437686
|
+
await fs12.rmdir(apiDir, { recursive: true });
|
|
437687
|
+
}
|
|
437688
|
+
delete this.apiFiles[apiFilePath];
|
|
437689
|
+
const scopeId = this.sourceTracker.deleteApi({
|
|
437690
|
+
pageName,
|
|
437691
|
+
apiName
|
|
437692
|
+
});
|
|
437693
|
+
deletedApis.push({
|
|
437694
|
+
apiName,
|
|
437695
|
+
pageName,
|
|
437696
|
+
scopeId
|
|
437697
|
+
});
|
|
437698
|
+
} catch (e) {
|
|
437699
|
+
logger3.warn(`Could not delete api ${apiFilePath} ${JSON.stringify(e)}`);
|
|
437700
|
+
}
|
|
437701
|
+
}
|
|
437702
|
+
const changes = await this.sourceTracker?.getAndFlushChanges() ?? [];
|
|
437703
|
+
await this.writeChanges(changes);
|
|
437704
|
+
this.emit("apiDelete", {
|
|
437705
|
+
apis: deletedApis.filter((api) => api !== void 0)
|
|
437706
|
+
});
|
|
437707
|
+
return { deletedApis };
|
|
437708
|
+
};
|
|
437709
|
+
handleRenameApi = async (payload) => {
|
|
437710
|
+
const { oldName, newName, pageName } = payload;
|
|
437806
437711
|
if (!this.rootDir) {
|
|
437807
437712
|
throw new Error("Root directory not set");
|
|
437808
437713
|
}
|
|
437809
|
-
const
|
|
437810
|
-
|
|
437811
|
-
|
|
437812
|
-
|
|
437813
|
-
|
|
437814
|
-
|
|
437815
|
-
|
|
437816
|
-
return callback?.(fileName, source2);
|
|
437817
|
-
}));
|
|
437818
|
-
}
|
|
437819
|
-
getNodeForWidgetSourceId(id2) {
|
|
437820
|
-
return this.sourceTracker?.getElementToLocation(id2);
|
|
437821
|
-
}
|
|
437822
|
-
getAstForWidgetSourceId(id2) {
|
|
437823
|
-
const filePath = this.sourceTracker?.getElementToFilePath(id2);
|
|
437824
|
-
if (!filePath) {
|
|
437825
|
-
return null;
|
|
437714
|
+
const pagePath = getPageFolder(this.rootDir, pageName);
|
|
437715
|
+
const existingApiFolder = path27.join(this.rootDir, "pages", pageName, "apis", oldName);
|
|
437716
|
+
const newApiFolder = path27.join(this.rootDir, "pages", pageName, "apis", newName);
|
|
437717
|
+
const files = this.sourceTracker?.getCurrentFiles();
|
|
437718
|
+
const file = files?.[path27.join(pagePath, "index.tsx")];
|
|
437719
|
+
if (!file || !file.ast) {
|
|
437720
|
+
throw new Error(`Page ${pageName} not found`);
|
|
437826
437721
|
}
|
|
437827
|
-
|
|
437828
|
-
|
|
437829
|
-
|
|
437830
|
-
|
|
437722
|
+
const apiFilePath = path27.join(existingApiFolder, "api.yaml");
|
|
437723
|
+
const apiDef = this.apiFiles[apiFilePath];
|
|
437724
|
+
if (!apiDef) {
|
|
437725
|
+
throw new Error(`API ${oldName} not found`);
|
|
437726
|
+
}
|
|
437727
|
+
const otherPageAPIs = structuredClone(Object.keys(this.apiFiles).filter((path55) => path55.startsWith(pagePath) && path55 !== apiFilePath).map((path55) => ({
|
|
437728
|
+
api: { apiPb: this.apiFiles[path55]?.apiPb },
|
|
437729
|
+
filePath: path55
|
|
437730
|
+
})).filter((api) => !!api.api));
|
|
437731
|
+
const newApiFolderExists = await fs12.stat(newApiFolder).catch(() => false);
|
|
437732
|
+
if (newApiFolderExists) {
|
|
437733
|
+
throw new Error(`API ${newName} already exists`);
|
|
437734
|
+
}
|
|
437735
|
+
this.watcher?.unwatch(existingApiFolder);
|
|
437736
|
+
this.watcher?.unwatch(newApiFolder);
|
|
437737
|
+
apiDef.apiPb.metadata.name = newName;
|
|
437738
|
+
await fs12.rename(existingApiFolder, newApiFolder);
|
|
437739
|
+
const scopeDef = this.sourceTracker?.getScopeDefinitionForPage(pageName);
|
|
437740
|
+
if (!scopeDef) {
|
|
437741
|
+
throw new Error(`Scope definition not found for API`);
|
|
437742
|
+
}
|
|
437743
|
+
this.sourceTracker?.renameEntity({
|
|
437744
|
+
oldName,
|
|
437745
|
+
newName,
|
|
437746
|
+
entityId: scopeDef.scopeNameToEntityId[oldName]
|
|
437747
|
+
});
|
|
437748
|
+
delete this.apiFiles[apiFilePath];
|
|
437749
|
+
this.writeFile(path27.join(newApiFolder, "api.yaml"), import_yaml2.default.stringify(apiDef.apiPb), "api");
|
|
437750
|
+
this.watcher?.add(existingApiFolder);
|
|
437751
|
+
this.watcher?.add(newApiFolder);
|
|
437752
|
+
const changes = await this.sourceTracker?.getAndFlushChanges() ?? [];
|
|
437753
|
+
await this.writeChanges(changes);
|
|
437754
|
+
this.emit("apiManualUpdate", {
|
|
437755
|
+
api: this.createClientApi(apiDef),
|
|
437756
|
+
oldName,
|
|
437757
|
+
pageName,
|
|
437758
|
+
scopeId: scopeDef?.id ?? ""
|
|
437759
|
+
}, true);
|
|
437831
437760
|
await this.renameManager.renameEntityInApis({
|
|
437832
437761
|
oldName,
|
|
437833
437762
|
newName,
|
|
437834
|
-
|
|
437835
|
-
apis: apisInScope
|
|
437763
|
+
apis: otherPageAPIs
|
|
437836
437764
|
});
|
|
437837
|
-
await Promise.all(
|
|
437765
|
+
await Promise.all(otherPageAPIs.map(async ({ api, filePath }) => {
|
|
437838
437766
|
if (isEqual_default(api?.apiPb, this.apiFiles[filePath]?.apiPb)) {
|
|
437839
437767
|
return Promise.resolve();
|
|
437840
437768
|
}
|
|
437841
|
-
|
|
437769
|
+
await this.writeFile(filePath, import_yaml2.default.stringify(api?.apiPb), "api");
|
|
437770
|
+
this.emit("apiManualUpdate", {
|
|
437771
|
+
api: this.createClientApi(api),
|
|
437772
|
+
pageName,
|
|
437773
|
+
scopeId: scopeDef?.id ?? ""
|
|
437774
|
+
}, true);
|
|
437842
437775
|
}));
|
|
437843
437776
|
};
|
|
437844
|
-
|
|
437845
|
-
const
|
|
437846
|
-
if (!
|
|
437847
|
-
return
|
|
437848
|
-
}
|
|
437849
|
-
const pagePath = path27.dirname(filePath);
|
|
437850
|
-
return Object.entries(this.apiFiles).filter(([filePath2]) => filePath2.includes(pagePath)).map(([filePath2, api]) => ({ api, filePath: filePath2 }));
|
|
437851
|
-
};
|
|
437852
|
-
getRelativeRoutePath(filePath) {
|
|
437853
|
-
if (!this.rootDir) {
|
|
437854
|
-
throw new Error("Root directory not set");
|
|
437777
|
+
async removeApiData(filePath) {
|
|
437778
|
+
const api = this.apiFiles[filePath];
|
|
437779
|
+
if (!api) {
|
|
437780
|
+
return;
|
|
437855
437781
|
}
|
|
437856
|
-
|
|
437782
|
+
delete this.apiFiles[filePath];
|
|
437783
|
+
this.sourceTracker?.deleteApi({
|
|
437784
|
+
pageName: api.pageName,
|
|
437785
|
+
apiName: api.apiPb.metadata.name
|
|
437786
|
+
});
|
|
437787
|
+
const changes = await this.sourceTracker?.getAndFlushChanges() ?? [];
|
|
437788
|
+
await this.writeChanges(changes);
|
|
437789
|
+
const scopeId = this.sourceTracker?.getScopeDefinitionForPage(api.pageName)?.id;
|
|
437790
|
+
this.emit("apiManualDelete", {
|
|
437791
|
+
api: {
|
|
437792
|
+
id: getClientApiId(api.apiPb.metadata.name, api.pageName),
|
|
437793
|
+
apiName: api.apiPb.metadata.name,
|
|
437794
|
+
// TODO(saksham): get pagename more defensively
|
|
437795
|
+
pageName: getPageName2(filePath),
|
|
437796
|
+
scopeId
|
|
437797
|
+
}
|
|
437798
|
+
});
|
|
437799
|
+
}
|
|
437800
|
+
getApiFiles() {
|
|
437801
|
+
return Object.keys(this.apiFiles).reduce((acc, key2) => {
|
|
437802
|
+
if (!this.apiFiles[key2]) {
|
|
437803
|
+
return acc;
|
|
437804
|
+
}
|
|
437805
|
+
acc[key2] = {
|
|
437806
|
+
api: this.createClientApi(this.apiFiles[key2]),
|
|
437807
|
+
scopeId: this.apiFiles[key2].scopeId
|
|
437808
|
+
};
|
|
437809
|
+
return acc;
|
|
437810
|
+
}, {});
|
|
437857
437811
|
}
|
|
437858
437812
|
// Utilities for converting server API format to Client API format
|
|
437859
437813
|
// We internally save the API as the server does, but we return should always return it
|
|
@@ -437870,19 +437824,19 @@ export default registerPage(Page, { name: "${name18}" });
|
|
|
437870
437824
|
}
|
|
437871
437825
|
};
|
|
437872
437826
|
}
|
|
437873
|
-
|
|
437874
|
-
|
|
437875
|
-
|
|
437876
|
-
|
|
437877
|
-
|
|
437878
|
-
|
|
437879
|
-
|
|
437880
|
-
|
|
437881
|
-
|
|
437882
|
-
|
|
437883
|
-
|
|
437884
|
-
}
|
|
437885
|
-
async
|
|
437827
|
+
addApiToScope = async (api) => {
|
|
437828
|
+
if (!this.sourceTracker) {
|
|
437829
|
+
throw new Error("Source tracker not initialized");
|
|
437830
|
+
}
|
|
437831
|
+
const scopeId = await this.sourceTracker.addApi({
|
|
437832
|
+
pageName: api.pageName,
|
|
437833
|
+
apiName: api.apiPb.metadata.name
|
|
437834
|
+
});
|
|
437835
|
+
const changes = await this.sourceTracker?.getAndFlushChanges() ?? [];
|
|
437836
|
+
await this.writeChanges(changes);
|
|
437837
|
+
return scopeId;
|
|
437838
|
+
};
|
|
437839
|
+
async processApiFileUpdates(filePath, fileType) {
|
|
437886
437840
|
let yamlPath = filePath;
|
|
437887
437841
|
if (fileType.type === "python-api-step" || fileType.type === "js-api-step") {
|
|
437888
437842
|
const apiFolderPath = filePath.split("/").slice(0, -1).join("/");
|
|
@@ -437898,7 +437852,7 @@ export default registerPage(Page, { name: "${name18}" });
|
|
|
437898
437852
|
logger3.info(`API structure is valid: ${yamlPath}`);
|
|
437899
437853
|
const parsedData = { apiPb: apiContent?.api };
|
|
437900
437854
|
if (!(yamlPath in this.apiFiles && isEqual_default(this.apiFiles[yamlPath]?.apiPb, parsedData.apiPb))) {
|
|
437901
|
-
const { updatedApi, pageName, isNewApi } = this.
|
|
437855
|
+
const { updatedApi, pageName, isNewApi } = this.updateInternalApiData({
|
|
437902
437856
|
api: parsedData.apiPb,
|
|
437903
437857
|
stepPathMap: apiContent.stepPathMap
|
|
437904
437858
|
}, yamlPath);
|
|
@@ -437909,7 +437863,7 @@ export default registerPage(Page, { name: "${name18}" });
|
|
|
437909
437863
|
return;
|
|
437910
437864
|
}
|
|
437911
437865
|
if (isNewApi) {
|
|
437912
|
-
await this.
|
|
437866
|
+
await this.addApiToScope(updatedApi);
|
|
437913
437867
|
}
|
|
437914
437868
|
this.emit("apiManualUpdate", {
|
|
437915
437869
|
api: this.createClientApi(updatedApi),
|
|
@@ -437923,6 +437877,50 @@ export default registerPage(Page, { name: "${name18}" });
|
|
|
437923
437877
|
logger3.error(`Error updating API: ${yamlPath}, error: ${error}`);
|
|
437924
437878
|
}
|
|
437925
437879
|
}
|
|
437880
|
+
updateInternalApiData = (content2, path55) => {
|
|
437881
|
+
if (!this.rootDir) {
|
|
437882
|
+
throw new Error("Root directory not set");
|
|
437883
|
+
}
|
|
437884
|
+
const { api: apiContents, stepPathMap } = content2;
|
|
437885
|
+
const pageName = getPageName2(path55);
|
|
437886
|
+
let scopeId = this.sourceTracker?.getScopeDefinitionForPage(pageName)?.id;
|
|
437887
|
+
if (!scopeId) {
|
|
437888
|
+
console.warn("Scope ID not found for API", apiContents.metadata.name);
|
|
437889
|
+
scopeId = "";
|
|
437890
|
+
}
|
|
437891
|
+
const updatedApi = {
|
|
437892
|
+
apiPb: import_yaml2.default.parse(JSON.stringify(apiContents)),
|
|
437893
|
+
pageName,
|
|
437894
|
+
stepPathMap,
|
|
437895
|
+
scopeId
|
|
437896
|
+
};
|
|
437897
|
+
const isNewApi = !this.apiFiles[path55];
|
|
437898
|
+
this.apiFiles[path55] = updatedApi;
|
|
437899
|
+
return { updatedApi, pageName, isNewApi };
|
|
437900
|
+
};
|
|
437901
|
+
renameIdentifierInApis = async ({ elementId, oldName, newName, parentBinding }) => {
|
|
437902
|
+
const apisInScope = structuredClone(this.getApisInScope(elementId));
|
|
437903
|
+
await this.renameManager.renameEntityInApis({
|
|
437904
|
+
oldName,
|
|
437905
|
+
newName,
|
|
437906
|
+
parentBinding,
|
|
437907
|
+
apis: apisInScope
|
|
437908
|
+
});
|
|
437909
|
+
await Promise.all(apisInScope.map(({ api, filePath }) => {
|
|
437910
|
+
if (isEqual_default(api?.apiPb, this.apiFiles[filePath]?.apiPb)) {
|
|
437911
|
+
return Promise.resolve();
|
|
437912
|
+
}
|
|
437913
|
+
return this.writeFile(filePath, import_yaml2.default.stringify(api?.apiPb), "api");
|
|
437914
|
+
}));
|
|
437915
|
+
};
|
|
437916
|
+
getApisInScope = (elementId) => {
|
|
437917
|
+
const filePath = this.sourceTracker?.getElementToFilePath(elementId);
|
|
437918
|
+
if (!filePath) {
|
|
437919
|
+
return [];
|
|
437920
|
+
}
|
|
437921
|
+
const pagePath = path27.dirname(filePath);
|
|
437922
|
+
return Object.entries(this.apiFiles).filter(([filePath2]) => filePath2.includes(pagePath)).map(([filePath2, api]) => ({ api, filePath: filePath2 }));
|
|
437923
|
+
};
|
|
437926
437924
|
};
|
|
437927
437925
|
async function readFile6(path55) {
|
|
437928
437926
|
try {
|
|
@@ -442801,7 +442799,7 @@ var import_util30 = __toESM(require_dist3(), 1);
|
|
|
442801
442799
|
// ../sdk/package.json
|
|
442802
442800
|
var package_default = {
|
|
442803
442801
|
name: "@superblocksteam/sdk",
|
|
442804
|
-
version: "2.0.6-next.
|
|
442802
|
+
version: "2.0.6-next.25",
|
|
442805
442803
|
type: "module",
|
|
442806
442804
|
description: "Superblocks JS SDK",
|
|
442807
442805
|
homepage: "https://www.superblocks.com",
|
|
@@ -442842,11 +442840,11 @@ var package_default = {
|
|
|
442842
442840
|
"@opentelemetry/semantic-conventions": "^1.28.0",
|
|
442843
442841
|
"@rollup/wasm-node": "^4.35.0",
|
|
442844
442842
|
"@superblocksteam/bucketeer-sdk": "0.5.0",
|
|
442845
|
-
"@superblocksteam/library": "2.0.6-next.
|
|
442846
|
-
"@superblocksteam/library-shared": "2.0.6-next.
|
|
442843
|
+
"@superblocksteam/library": "2.0.6-next.25",
|
|
442844
|
+
"@superblocksteam/library-shared": "2.0.6-next.25",
|
|
442847
442845
|
"@superblocksteam/shared": "0.9198.0",
|
|
442848
|
-
"@superblocksteam/util": "2.0.6-next.
|
|
442849
|
-
"@superblocksteam/vite-plugin-file-sync": "2.0.6-next.
|
|
442846
|
+
"@superblocksteam/util": "2.0.6-next.25",
|
|
442847
|
+
"@superblocksteam/vite-plugin-file-sync": "2.0.6-next.25",
|
|
442850
442848
|
"@vitejs/plugin-react": "^4.3.4",
|
|
442851
442849
|
axios: "^1.4.0",
|
|
442852
442850
|
chokidar: "^4.0.3",
|
|
@@ -450418,7 +450416,7 @@ async function startVite({ app, httpServer: httpServer2, root: root2, mode, port
|
|
|
450418
450416
|
const isCustomBuildEnabled2 = await isCustomComponentsEnabled();
|
|
450419
450417
|
const customFolder = path37.join(root2, "custom");
|
|
450420
450418
|
const draftsFolder = path37.join(root2, ".superblocks");
|
|
450421
|
-
const cdnUrl = "https://assets-cdn.superblocks.com/library/2.0.6-next.
|
|
450419
|
+
const cdnUrl = "https://assets-cdn.superblocks.com/library/2.0.6-next.25";
|
|
450422
450420
|
const env3 = loadEnv(mode, root2, "");
|
|
450423
450421
|
const hmrPort = await getFreePort();
|
|
450424
450422
|
const hmrOptions = {
|
package/oclif.manifest.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@superblocksteam/cli",
|
|
3
|
-
"version": "2.0.6-next.
|
|
3
|
+
"version": "2.0.6-next.25",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Official Superblocks CLI",
|
|
6
6
|
"homepage": "https://www.superblocks.com",
|
|
@@ -42,9 +42,9 @@
|
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@eslint/js": "^9.16.0",
|
|
44
44
|
"@oclif/test": "^4.1.11",
|
|
45
|
-
"@superblocksteam/sdk": "2.0.6-next.
|
|
45
|
+
"@superblocksteam/sdk": "2.0.6-next.25",
|
|
46
46
|
"@superblocksteam/shared": "0.9198.0",
|
|
47
|
-
"@superblocksteam/util": "2.0.6-next.
|
|
47
|
+
"@superblocksteam/util": "2.0.6-next.25",
|
|
48
48
|
"@types/babel__core": "^7.20.0",
|
|
49
49
|
"@types/chai": "^4",
|
|
50
50
|
"@types/fs-extra": "^11.0.1",
|