From 2b6d937d75b43bd6a6912d0c464e4c1979feb85d Mon Sep 17 00:00:00 2001 From: Youssef Amr El-Shehaby Date: Tue, 12 Dec 2023 15:45:29 +0200 Subject: [PATCH 1/2] fix version number --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a80eed1..7513e69 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ All notable changes to **Project Explorer** will be documented in this file. -## [0.1.5] - 2023-12-12 +## [0.2.0] - 2023-12-12 ### Added From d9a677591e4793fc97b870a09079bd72c842cbad Mon Sep 17 00:00:00 2001 From: Youssef Amr El-Shehaby Date: Fri, 1 Mar 2024 14:39:14 +0200 Subject: [PATCH 2/2] add quick pick menu to create a new layout or page --- src/commands/nextjs-command.ts | 46 ++++++++++++++++++++++++++++------ 1 file changed, 39 insertions(+), 7 deletions(-) diff --git a/src/commands/nextjs-command.ts b/src/commands/nextjs-command.ts index e9ef835..d05fa51 100644 --- a/src/commands/nextjs-command.ts +++ b/src/commands/nextjs-command.ts @@ -39,27 +39,59 @@ export default class NextJsCommand implements Command { } async createPageOrLayout(uri: vscode.Uri): Promise { + const pageOrLayout = await vscode.window.showQuickPick(["Page", "Layout"], { + placeHolder: "Choose page or layout", + }); + + if (!pageOrLayout) { + vscode.window.showErrorMessage("No page or layout selected"); + return; + } + + const isPage = pageOrLayout === "Page"; + const input = await vscode.window.showInputBox({ - prompt: "Enter the name of the page or layout relative to 'app/'", + prompt: `Enter the name of the ${ + isPage ? "page" : "layout" + } relative to 'app/' without extension`, + value: pageOrLayout === "Page" ? "page.tsx" : "layout.tsx", }); + if (!input) { vscode.window.showErrorMessage("No file name provided"); + return; } - const pathToFileUri = vscode.Uri.joinPath(uri, input!); + + const pathToFileUri = vscode.Uri.joinPath(uri, input); const pathToFile = pathToFileUri.fsPath; - const fileName = pathToFile.split("\\").at(-1)!.slice(0, -4); + const fileName = pathToFile.split("\\").at(-2); + await vscode.workspace.fs.writeFile( pathToFileUri, new Uint8Array( Buffer.from(` - export default function ${fileName}() { - return
${fileName}
- } - `) + ${ + isPage + ? ` + export default function ${ + fileName![0].toUpperCase() + fileName!.slice(1) + pageOrLayout + }() { + return
${fileName} page
+ }` + : ` + export default function ${ + fileName![0].toUpperCase() + fileName!.slice(1) + pageOrLayout + }({ children }) { + return
{children}
+ }` + } + `) ) ); + await this._openFile(pathToFileUri); } + isValidNextFile = (fileName: string) => fileName.endsWith(".tsx") || fileName.endsWith(".jsx");