Skip to content

Commit

Permalink
Update package.json name field to project name (#146)
Browse files Browse the repository at this point in the history
  • Loading branch information
shishkevichd authored Sep 10, 2024
1 parent 66ca07b commit c02eed1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion create-vite-express/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }));
}
}

Expand Down
21 changes: 13 additions & 8 deletions create-vite-express/src/patches.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
export const PATCHES: Record<string, (content: string) => string> = {
"package.json": (content: string) => {
console.log(process.platform);
type Variables = {
projectName?: string
}

export const PATCHES: Record<string, (content: string, variables: Variables) => 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);
},
};

0 comments on commit c02eed1

Please sign in to comment.