MCPcopy Create free account
hub / github.com/code-forge-io/Remix-Forge / generateRouteFile

Function generateRouteFile

src/commands/generateRouteFile.ts:6–65  ·  view source on GitHub ↗
(uri: vscode.Uri, _: any, name?: string, opts?: GeneratorOption[])

Source from the content-addressed store, hash-verified

4
5// biome-ignore lint/suspicious/noExplicitAny: <explanation>
6export const generateRouteFile = async (uri: vscode.Uri, _: any, name?: string, opts?: GeneratorOption[]) => {
7 const config = vscode.workspace.getConfiguration(EXTENSION_CONFIG_SECTION);
8
9 const fileName = name
10 ? name
11 : await vscode.window.showInputBox({
12 prompt: "Enter the name of the route to generate",
13 });
14
15 if (fileName) {
16 const options = opts
17 ? opts
18 : await vscode.window.showQuickPick(generatorOptions(config), {
19 canPickMany: true,
20 title: "Select the segments you want to generate",
21 });
22
23 const filePath = vscode.Uri.joinPath(uri, `${fileName}.tsx`);
24 if (options?.length) {
25 // The user has made a selection
26 const selectedGenerators = options.map((option) => option.key);
27 const withLoader = selectedGenerators.includes("loader");
28 const configOrder = config.get<Exclude<Generator, "dependencies">[]>("orderOfGeneration");
29 // If the user has a custom order of generation, use that, otherwise use the default
30 const orderOfGeneration = configOrder?.length ? configOrder : defaultGenerationOrder;
31 const fileContent = [
32 // generates dependencies first
33 GENERATORS.dependencies(config, selectedGenerators),
34 // Generates the rest of the file
35 ...orderOfGeneration.map((generatorKey) => {
36 if (generatorKey === "component") {
37 return GENERATORS[generatorKey](config, withLoader);
38 }
39 if (selectedGenerators.includes(generatorKey)) {
40 return GENERATORS[generatorKey](config);
41 }
42 return undefined;
43 }),
44 ]
45 .filter(Boolean)
46 .join("\n\n");
47
48 // Get the contents of the file
49 const fileContents = Buffer.from(fileContent);
50
51 // Write the file to the file system
52 await vscode.workspace.fs.writeFile(filePath, fileContents);
53 } else {
54 // The user dismissed the dialog
55 const fileContent = GENERATORS.component(config);
56 const fileContents = Buffer.from(fileContent);
57 // Write the file to the file system
58 await vscode.workspace.fs.writeFile(filePath, fileContents);
59 }
60 vscode.window.showInformationMessage(`Remix Route generated for ${fileName}!`);
61 // add your code to generate the Remix Route here
62 } else {
63 vscode.window.showWarningMessage("No route name entered, no route generated");

Callers 1

startDevToolsFunction · 0.90

Calls 1

generatorOptionsFunction · 0.90

Tested by

no test coverage detected