]> git.ipfire.org Git - thirdparty/vuejs/create-vue.git/commitdiff
feat: add jsconfig.json for javascript template
authorHaoqun Jiang <haoqunjiang@gmail.com>
Mon, 26 Jul 2021 08:59:22 +0000 (16:59 +0800)
committerHaoqun Jiang <haoqunjiang@gmail.com>
Mon, 26 Jul 2021 08:59:22 +0000 (16:59 +0800)
index.js
template/config/base/jsconfig.json [moved from template/config/typescript/tsconfig.json with 84% similarity]
template/config/base/src/shims-vue.d.ts [moved from template/config/typescript/src/shims-vue.d.ts with 100% similarity]
template/config/base/src/vite-env.d.ts [moved from template/config/typescript/src/vite-env.d.ts with 100% similarity]
template/config/cypress/cypress/jsconfig.json [moved from template/config/cypress/cypress/tsconfig.json with 79% similarity]
template/config/typescript/vite.config.ts [deleted file]

index d07f8dc9b82c186f3e01d4512a68c09038f667f2..dd0a59429c91c3f0a3032c554f6cb9b5042c1caf 100755 (executable)
--- 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:
similarity index 84%
rename from template/config/typescript/tsconfig.json
rename to template/config/base/jsconfig.json
index 883a694c425a90da25ea1dea676ba341e45ab0b3..d63ac93b82aa4bc5d5eddb1fd34950cf29035369 100644 (file)
     "lib": ["esnext", "dom", "dom.iterable", "scripthost"]
   },
   "include": [
-    "vite.config.ts",
+    "vite.config.*",
 
-    "src/**/*.ts",
-    "src/**/*.d.ts",
-    "src/**/*.tsx",
+    "src/**/*",
     "src/**/*.vue"
   ]
 }
similarity index 79%
rename from template/config/cypress/cypress/tsconfig.json
rename to template/config/cypress/cypress/jsconfig.json
index e5d5ea638cea092a61ddee40ef294af12515ecec..b5b2f972cd5b29097579b24dda59d3a760b0cbf3 100644 (file)
@@ -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 (file)
index 8ae6fd0..0000000
+++ /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,
-    },
-  }
-})