Skip to content

Commit a9e5759

Browse files
committed
Automatically strip dangling commas in templated JSON files
1 parent f973b03 commit a9e5759

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,12 @@ function copyFiles(templateFile: string, config: Config) {
380380
if (filename.endsWith('.ejs')) {
381381
const template = fs.readFileSync(templatePath, 'utf-8')
382382
const target = targetPath.replace(/\.ejs$/, '')
383-
const content = ejs.render(template, { config })
383+
let content = ejs.render(template, { config })
384+
385+
if (target.endsWith('.json')) {
386+
// Remove trailing commas
387+
content = content.replace(/,(\s*)([}\]])/g, '$1$2')
388+
}
384389

385390
fs.writeFileSync(target, content)
386391
} else if (['package.json', 'vite.config.mts', 'config.mts', 'index.md', 'introduction.md', 'App.vue', 'tsconfig.app.json', 'env.d.ts'].includes(filename)) {

src/template/base/config/packages/@projectName@/tsconfig.app.json.ejs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
"include": ["env.d.ts", "src/**/*", "src/**/*.vue"],
44
"exclude": ["src/**/__tests__/*"],
55
"compilerOptions": {
6-
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo"<%_ if (config.includeAtAliases) { _%>,
6+
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
7+
<%_ if (config.includeAtAliases) { _%>
78
"paths": {
89
"@/*": ["./src/*"]
9-
}<%_ } %>
10+
}
11+
<%_ } _%>
1012
}
1113
}

0 commit comments

Comments
 (0)