From: Haoqun Jiang Date: Mon, 26 Jul 2021 08:59:22 +0000 (+0800) Subject: feat: add jsconfig.json for javascript template X-Git-Tag: v3.0.0-alpha.2~34 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cb91607b22fc446ae41c80a7ca3dd2a9fdf86b34;p=thirdparty%2Fvuejs%2Fcreate-vue.git feat: add jsconfig.json for javascript template --- diff --git a/index.js b/index.js index d07f8dc9..dd0a5942 100755 --- a/index.js +++ b/index.js @@ -150,6 +150,28 @@ async function init() { } if (shouldUseTypeScript) { render('config/typescript') + + // rename all `.js` files to `.ts` + // rename jsconfig.json to tsconfig.json + function traverseAndRename(dir) { + for (const filename of fs.readdirSync(dir)) { + const fullpath = path.resolve(dir, filename) + if (fs.lstatSync(fullpath).isDirectory()) { + traverseAndRename(fullpath) + continue + } + + if (filename.endsWith('.js')) { + fs.renameSync(fullpath, fullpath.replace(/\.js$/, '.ts')) + } + + if (filename === 'jsconfig.json') { + fs.renameSync(fullpath, fullpath.replace(/jsconfig\.json$/, 'tsconfig.json')) + } + } + } + + traverseAndRename(root) } // Render code template. @@ -162,11 +184,6 @@ async function init() { // Cleanup. - if (shouldUseTypeScript) { - // Should remove the `vite.config.js` from the base config - fs.unlinkSync(path.resolve(root, 'vite.config.js')) - } - if (!shouldAddCypress) { // All templates assumes the need of tests. // If the user doesn't need it: diff --git a/template/config/typescript/tsconfig.json b/template/config/base/jsconfig.json similarity index 84% rename from template/config/typescript/tsconfig.json rename to template/config/base/jsconfig.json index 883a694c..d63ac93b 100644 --- a/template/config/typescript/tsconfig.json +++ b/template/config/base/jsconfig.json @@ -18,11 +18,9 @@ "lib": ["esnext", "dom", "dom.iterable", "scripthost"] }, "include": [ - "vite.config.ts", + "vite.config.*", - "src/**/*.ts", - "src/**/*.d.ts", - "src/**/*.tsx", + "src/**/*", "src/**/*.vue" ] } diff --git a/template/config/typescript/src/shims-vue.d.ts b/template/config/base/src/shims-vue.d.ts similarity index 100% rename from template/config/typescript/src/shims-vue.d.ts rename to template/config/base/src/shims-vue.d.ts diff --git a/template/config/typescript/src/vite-env.d.ts b/template/config/base/src/vite-env.d.ts similarity index 100% rename from template/config/typescript/src/vite-env.d.ts rename to template/config/base/src/vite-env.d.ts diff --git a/template/config/cypress/cypress/tsconfig.json b/template/config/cypress/cypress/jsconfig.json similarity index 79% rename from template/config/cypress/cypress/tsconfig.json rename to template/config/cypress/cypress/jsconfig.json index e5d5ea63..b5b2f972 100644 --- a/template/config/cypress/cypress/tsconfig.json +++ b/template/config/cypress/cypress/jsconfig.json @@ -4,5 +4,5 @@ "lib": ["es5", "dom"], "types": ["cypress"] }, - "include": ["./**/*.ts"] + "include": ["./**/*"] } diff --git a/template/config/typescript/vite.config.ts b/template/config/typescript/vite.config.ts deleted file mode 100644 index 8ae6fd07..00000000 --- a/template/config/typescript/vite.config.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { defineConfig } from 'vite' -import vue from '@vitejs/plugin-vue' -import vueJsx from '@vitejs/plugin-vue-jsx' - -// https://vitejs.dev/config/ -export default defineConfig({ - plugins: [vue(), vueJsx()], - resolve: { - alias: { - '@/': new URL('./src/', import.meta.url).pathname, - }, - } -})