diff --git a/create-vite-express/src/main.ts b/create-vite-express/src/main.ts index ac8662a..986d217 100644 --- a/create-vite-express/src/main.ts +++ b/create-vite-express/src/main.ts @@ -37,7 +37,7 @@ export async function main({ const filePath = path.join(projectPath, patch); if (fs.existsSync(filePath)) { const content = fs.readFileSync(filePath, "utf-8"); - fs.writeFileSync(filePath, PATCHES[patch](content)); + fs.writeFileSync(filePath, PATCHES[patch](content, { projectName })); } } diff --git a/create-vite-express/src/patches.ts b/create-vite-express/src/patches.ts index 5662c69..945fee9 100644 --- a/create-vite-express/src/patches.ts +++ b/create-vite-express/src/patches.ts @@ -1,16 +1,21 @@ -export const PATCHES: Record string> = { - "package.json": (content: string) => { - console.log(process.platform); +type Variables = { + projectName?: string +} + +export const PATCHES: Record string> = { + "package.json": (content: string, variables: Variables) => { + const json = JSON.parse(content); + + json["name"] = variables.projectName + if (process.platform === "win32") { - const json = JSON.parse(content); json.scripts["start"] = json.scripts["start"].replace( "NODE_ENV=production", "cross-env NODE_ENV=production", ); json.dependencies["cross-env"] = "^7.0.3"; - return JSON.stringify(json, null, 2); - } else { - return content; - } + } + + return JSON.stringify(json, null, 2); }, };