Skip to content

Commit cb91607

Browse files
committed
feat: add jsconfig.json for javascript template
1 parent e3ed252 commit cb91607

File tree

6 files changed

+25
-23
lines changed

6 files changed

+25
-23
lines changed

index.js

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,28 @@ async function init() {
150150
}
151151
if (shouldUseTypeScript) {
152152
render('config/typescript')
153+
154+
// rename all `.js` files to `.ts`
155+
// rename jsconfig.json to tsconfig.json
156+
function traverseAndRename(dir) {
157+
for (const filename of fs.readdirSync(dir)) {
158+
const fullpath = path.resolve(dir, filename)
159+
if (fs.lstatSync(fullpath).isDirectory()) {
160+
traverseAndRename(fullpath)
161+
continue
162+
}
163+
164+
if (filename.endsWith('.js')) {
165+
fs.renameSync(fullpath, fullpath.replace(/\.js$/, '.ts'))
166+
}
167+
168+
if (filename === 'jsconfig.json') {
169+
fs.renameSync(fullpath, fullpath.replace(/jsconfig\.json$/, 'tsconfig.json'))
170+
}
171+
}
172+
}
173+
174+
traverseAndRename(root)
153175
}
154176

155177
// Render code template.
@@ -162,11 +184,6 @@ async function init() {
162184

163185
// Cleanup.
164186

165-
if (shouldUseTypeScript) {
166-
// Should remove the `vite.config.js` from the base config
167-
fs.unlinkSync(path.resolve(root, 'vite.config.js'))
168-
}
169-
170187
if (!shouldAddCypress) {
171188
// All templates assumes the need of tests.
172189
// If the user doesn't need it:

template/config/typescript/tsconfig.json renamed to template/config/base/jsconfig.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,9 @@
1818
"lib": ["esnext", "dom", "dom.iterable", "scripthost"]
1919
},
2020
"include": [
21-
"vite.config.ts",
21+
"vite.config.*",
2222

23-
"src/**/*.ts",
24-
"src/**/*.d.ts",
25-
"src/**/*.tsx",
23+
"src/**/*",
2624
"src/**/*.vue"
2725
]
2826
}

template/config/cypress/cypress/tsconfig.json renamed to template/config/cypress/cypress/jsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
"lib": ["es5", "dom"],
55
"types": ["cypress"]
66
},
7-
"include": ["./**/*.ts"]
7+
"include": ["./**/*"]
88
}

template/config/typescript/vite.config.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)