From 89ac705fbc5d8114812ecfab97360630b86a691e Mon Sep 17 00:00:00 2001
From: zhang-san <2306860505@qq.com>
Date: Thu, 5 Dec 2024 16:22:37 +0800
Subject: [PATCH 1/3] =?UTF-8?q?=E6=B7=BB=E5=8A=A0bun=E8=BF=90=E8=A1=8C?=
=?UTF-8?q?=E6=97=B6=E6=A8=A1=E6=9D=BF?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
index.ts | 35 ++++++++++++++++---
locales/en-US.json | 13 +++++++
locales/fr-FR.json | 13 +++++++
locales/zh-Hans.json | 13 +++++++
.../bun/config/typescript/package.json | 13 +++++++
.../bun/tsconfig/base/package.json | 6 ++++
.../bun/tsconfig/base/tsconfig.app.json | 13 +++++++
.../bun/tsconfig/base/tsconfig.bun.json | 19 ++++++++++
utils/getLanguage.ts | 1 +
9 files changed, 121 insertions(+), 5 deletions(-)
create mode 100644 template/others-runtime/bun/config/typescript/package.json
create mode 100644 template/others-runtime/bun/tsconfig/base/package.json
create mode 100644 template/others-runtime/bun/tsconfig/base/tsconfig.app.json
create mode 100644 template/others-runtime/bun/tsconfig/base/tsconfig.bun.json
diff --git a/index.ts b/index.ts
index 40f70304b..14ccfab5b 100755
--- a/index.ts
+++ b/index.ts
@@ -140,10 +140,12 @@ async function init() {
needsEslint?: false | 'eslintOnly' | 'speedUpWithOxlint'
needsOxlint?: boolean
needsPrettier?: boolean
+ runtime?: 'nodejs' | 'bun'
} = {}
try {
// Prompts:
+ // - Choose runtime environment: Node.js / Bun
// - Project name:
// - whether to overwrite the existing directory or not?
// - enter a valid package name for package.json
@@ -156,8 +158,27 @@ async function init() {
// - Add Playwright for end-to-end testing?
// - Add ESLint for code quality?
// - Add Prettier for code formatting?
+
result = await prompts(
[
+ {
+ name: 'runtime',
+ type: () => (isFeatureFlagsUsed ? null : 'select'),
+ message: language.needsRuntime.message,
+ initial: 0,
+ choices: [
+ {
+ title: language.needsRuntime.selectOptions.nodejs.title,
+ description: language.needsRuntime.selectOptions.nodejs.desc,
+ value: 'nodejs'
+ },
+ {
+ title: language.needsRuntime.selectOptions.bun.title,
+ description: language.needsRuntime.selectOptions.bun.desc,
+ value: 'bun'
+ }
+ ]
+ },
{
name: 'projectName',
type: targetDir ? null : 'text',
@@ -324,6 +345,7 @@ async function init() {
needsPinia = argv.pinia,
needsVitest = argv.vitest || argv.tests,
needsPrettier = argv['eslint-with-prettier'],
+ runtime = 'nodejs',
} = result
const needsEslint = Boolean(argv.eslint || argv['eslint-with-prettier'] || result.needsEslint)
@@ -355,8 +377,11 @@ async function init() {
// const templateRoot = new URL('./template', import.meta.url).pathname
const templateRoot = path.resolve(__dirname, 'template')
const callbacks = []
- const render = function render(templateName) {
- const templateDir = path.resolve(templateRoot, templateName)
+ const render = function render(templateName: string) {
+ let templateDir = fs.existsSync(path.resolve(templateRoot, runtime, templateName))
+ if (!fs.existsSync(targetDir)) {
+ templateDir = path.resolve(templateRoot, templateName)
+ }
renderTemplate(templateDir, root, callbacks)
}
// Render base template
@@ -501,7 +526,7 @@ async function init() {
// EJS template rendering
preOrderDirectoryTraverse(
root,
- () => {},
+ () => { },
(filepath) => {
if (filepath.endsWith('.ejs')) {
const template = fs.readFileSync(filepath, 'utf-8')
@@ -531,7 +556,7 @@ async function init() {
// `jsconfig.json` is not reused, because we use solution-style `tsconfig`s, which are much more complicated.
preOrderDirectoryTraverse(
root,
- () => {},
+ () => { },
(filepath) => {
if (filepath.endsWith('.js') && !filepath.endsWith('eslint.config.js')) {
const tsFilePath = filepath.replace(/\.js$/, '.ts')
@@ -554,7 +579,7 @@ async function init() {
// Remove all the remaining `.ts` files
preOrderDirectoryTraverse(
root,
- () => {},
+ () => { },
(filepath) => {
if (filepath.endsWith('.ts')) {
fs.unlinkSync(filepath)
diff --git a/locales/en-US.json b/locales/en-US.json
index d1f8a1698..007a6221e 100644
--- a/locales/en-US.json
+++ b/locales/en-US.json
@@ -59,6 +59,19 @@
"needsPrettier": {
"message": "Add Prettier for code formatting?"
},
+ "needsRuntime": {
+ "message": "Choose runtime environment:",
+ "selectOptions": {
+ "nodejs": {
+ "title": "Node.js",
+ "desc": "Traditional and widely supported runtime"
+ },
+ "bun": {
+ "title": "Bun",
+ "desc": "Fast all-in-one JavaScript runtime"
+ }
+ }
+ },
"errors": {
"operationCancelled": "Operation cancelled"
},
diff --git a/locales/fr-FR.json b/locales/fr-FR.json
index 9ff6d1313..42eae82be 100644
--- a/locales/fr-FR.json
+++ b/locales/fr-FR.json
@@ -59,6 +59,19 @@
"needsPrettier": {
"message": "Ajouter Prettier pour le formatage du code\u00a0?"
},
+ "needsRuntime": {
+ "message": "Choisir l'environnement d'exécution :",
+ "selectOptions": {
+ "nodejs": {
+ "title": "Node.js",
+ "desc": "Runtime traditionnel largement supporté"
+ },
+ "bun": {
+ "title": "Bun",
+ "desc": "Runtime JavaScript tout-en-un rapide"
+ }
+ }
+ },
"errors": {
"operationCancelled": "Operation annulée"
},
diff --git a/locales/zh-Hans.json b/locales/zh-Hans.json
index c74002f01..6efc0f094 100644
--- a/locales/zh-Hans.json
+++ b/locales/zh-Hans.json
@@ -59,6 +59,19 @@
"needsPrettier": {
"message": "是否引入 Prettier 用于代码格式化?"
},
+ "needsRuntime": {
+ "message": "选择运行时环境:",
+ "selectOptions": {
+ "nodejs": {
+ "title": "Node.js",
+ "desc": "传统且广泛支持的运行时"
+ },
+ "bun": {
+ "title": "Bun",
+ "desc": "快速的一体化 JavaScript 运行时"
+ }
+ }
+ },
"errors": {
"operationCancelled": "操作取消"
},
diff --git a/template/others-runtime/bun/config/typescript/package.json b/template/others-runtime/bun/config/typescript/package.json
new file mode 100644
index 000000000..d5bb41fbe
--- /dev/null
+++ b/template/others-runtime/bun/config/typescript/package.json
@@ -0,0 +1,13 @@
+{
+ "scripts": {
+ "build": "run-p type-check \"build-only {@}\" --",
+ "build-only": "vite build",
+ "type-check": "vue-tsc --build"
+ },
+ "devDependencies": {
+ "@types/bun": "^1.1.13",
+ "npm-run-all2": "^7.0.1",
+ "typescript": "~5.6.3",
+ "vue-tsc": "^2.1.10"
+ }
+}
diff --git a/template/others-runtime/bun/tsconfig/base/package.json b/template/others-runtime/bun/tsconfig/base/package.json
new file mode 100644
index 000000000..a3b507c61
--- /dev/null
+++ b/template/others-runtime/bun/tsconfig/base/package.json
@@ -0,0 +1,6 @@
+{
+ "devDependencies": {
+ "@tsconfig/bun": "^1.0.7",
+ "@vue/tsconfig": "^0.7.0"
+ }
+}
diff --git a/template/others-runtime/bun/tsconfig/base/tsconfig.app.json b/template/others-runtime/bun/tsconfig/base/tsconfig.app.json
new file mode 100644
index 000000000..93f952f1d
--- /dev/null
+++ b/template/others-runtime/bun/tsconfig/base/tsconfig.app.json
@@ -0,0 +1,13 @@
+{
+ "extends": "@vue/tsconfig/tsconfig.dom.json",
+ "include": ["env.d.ts", "src/**/*", "src/**/*.vue"],
+ "exclude": ["src/**/__tests__/*"],
+ "compilerOptions": {
+ "composite": true,
+ "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
+
+ "paths": {
+ "@/*": ["./src/*"]
+ }
+ }
+}
diff --git a/template/others-runtime/bun/tsconfig/base/tsconfig.bun.json b/template/others-runtime/bun/tsconfig/base/tsconfig.bun.json
new file mode 100644
index 000000000..0e734154e
--- /dev/null
+++ b/template/others-runtime/bun/tsconfig/base/tsconfig.bun.json
@@ -0,0 +1,19 @@
+{
+ "extends": "@tsconfig/bun/tsconfig.json",
+ "include": [
+ "vite.config.*",
+ "vitest.config.*",
+ "cypress.config.*",
+ "nightwatch.conf.*",
+ "playwright.config.*"
+ ],
+ "compilerOptions": {
+ "composite": true,
+ "noEmit": true,
+ "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
+
+ "module": "ESNext",
+ "moduleResolution": "Bundler",
+ "types": ["node"]
+ }
+}
diff --git a/utils/getLanguage.ts b/utils/getLanguage.ts
index c96f7c7ec..2f2cfbb30 100644
--- a/utils/getLanguage.ts
+++ b/utils/getLanguage.ts
@@ -30,6 +30,7 @@ interface Language {
needsE2eTesting: LanguageItem
needsEslint: LanguageItem
needsPrettier: LanguageItem
+ needsRuntime: LanguageItem
errors: {
operationCancelled: string
}
From 0a824b526b842ebdca4ad23ad255daa65fdfef1c Mon Sep 17 00:00:00 2001
From: zhang-san <2306860505@qq.com>
Date: Thu, 5 Dec 2024 17:03:14 +0800
Subject: [PATCH 2/3] =?UTF-8?q?=E4=BF=AE=E6=AD=A3tsconfig=E6=96=87?=
=?UTF-8?q?=E4=BB=B6=E6=8C=87=E5=90=91=E9=94=99=E8=AF=AF=EF=BC=8C=E9=80=89?=
=?UTF-8?q?=E9=A1=B9=E7=9A=84=E5=9B=BD=E9=99=85=E5=8C=96=E6=94=AF=E6=8C=81?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
index.ts | 28 ++++++++++++++--------------
locales/en-US.json | 2 +-
locales/fr-FR.json | 2 +-
locales/tr-TR.json | 13 +++++++++++++
locales/zh-Hans.json | 2 +-
locales/zh-Hant.json | 13 +++++++++++++
6 files changed, 43 insertions(+), 17 deletions(-)
diff --git a/index.ts b/index.ts
index 14ccfab5b..04919b7d1 100755
--- a/index.ts
+++ b/index.ts
@@ -140,7 +140,7 @@ async function init() {
needsEslint?: false | 'eslintOnly' | 'speedUpWithOxlint'
needsOxlint?: boolean
needsPrettier?: boolean
- runtime?: 'nodejs' | 'bun'
+ runtime?: 'node' | 'bun'
} = {}
try {
@@ -168,16 +168,16 @@ async function init() {
initial: 0,
choices: [
{
- title: language.needsRuntime.selectOptions.nodejs.title,
- description: language.needsRuntime.selectOptions.nodejs.desc,
- value: 'nodejs'
+ title: language.needsRuntime.selectOptions.node.title,
+ description: language.needsRuntime.selectOptions.node.desc,
+ value: 'node',
},
{
title: language.needsRuntime.selectOptions.bun.title,
description: language.needsRuntime.selectOptions.bun.desc,
- value: 'bun'
- }
- ]
+ value: 'bun',
+ },
+ ],
},
{
name: 'projectName',
@@ -345,7 +345,7 @@ async function init() {
needsPinia = argv.pinia,
needsVitest = argv.vitest || argv.tests,
needsPrettier = argv['eslint-with-prettier'],
- runtime = 'nodejs',
+ runtime = 'node',
} = result
const needsEslint = Boolean(argv.eslint || argv['eslint-with-prettier'] || result.needsEslint)
@@ -378,8 +378,8 @@ async function init() {
const templateRoot = path.resolve(__dirname, 'template')
const callbacks = []
const render = function render(templateName: string) {
- let templateDir = fs.existsSync(path.resolve(templateRoot, runtime, templateName))
- if (!fs.existsSync(targetDir)) {
+ let templateDir = path.resolve(templateRoot, 'others-runtime', runtime, templateName)
+ if (!fs.existsSync(templateDir)) {
templateDir = path.resolve(templateRoot, templateName)
}
renderTemplate(templateDir, root, callbacks)
@@ -428,7 +428,7 @@ async function init() {
// All templates contain at least a `.node` and a `.app` tsconfig.
references: [
{
- path: './tsconfig.node.json',
+ path: `./tsconfig.${runtime}.json`,
},
{
path: './tsconfig.app.json',
@@ -526,7 +526,7 @@ async function init() {
// EJS template rendering
preOrderDirectoryTraverse(
root,
- () => { },
+ () => {},
(filepath) => {
if (filepath.endsWith('.ejs')) {
const template = fs.readFileSync(filepath, 'utf-8')
@@ -556,7 +556,7 @@ async function init() {
// `jsconfig.json` is not reused, because we use solution-style `tsconfig`s, which are much more complicated.
preOrderDirectoryTraverse(
root,
- () => { },
+ () => {},
(filepath) => {
if (filepath.endsWith('.js') && !filepath.endsWith('eslint.config.js')) {
const tsFilePath = filepath.replace(/\.js$/, '.ts')
@@ -579,7 +579,7 @@ async function init() {
// Remove all the remaining `.ts` files
preOrderDirectoryTraverse(
root,
- () => { },
+ () => {},
(filepath) => {
if (filepath.endsWith('.ts')) {
fs.unlinkSync(filepath)
diff --git a/locales/en-US.json b/locales/en-US.json
index 007a6221e..eacbf90d1 100644
--- a/locales/en-US.json
+++ b/locales/en-US.json
@@ -62,7 +62,7 @@
"needsRuntime": {
"message": "Choose runtime environment:",
"selectOptions": {
- "nodejs": {
+ "node": {
"title": "Node.js",
"desc": "Traditional and widely supported runtime"
},
diff --git a/locales/fr-FR.json b/locales/fr-FR.json
index 42eae82be..931d41fc7 100644
--- a/locales/fr-FR.json
+++ b/locales/fr-FR.json
@@ -62,7 +62,7 @@
"needsRuntime": {
"message": "Choisir l'environnement d'exécution :",
"selectOptions": {
- "nodejs": {
+ "node": {
"title": "Node.js",
"desc": "Runtime traditionnel largement supporté"
},
diff --git a/locales/tr-TR.json b/locales/tr-TR.json
index 323acac1d..c7da3f9ee 100644
--- a/locales/tr-TR.json
+++ b/locales/tr-TR.json
@@ -59,6 +59,19 @@
"needsPrettier": {
"message": "Kod formatlama için Prettier eklensin mi?"
},
+ "needsRuntime": {
+ "message": "Çalışma zamanı ortamını seçin:",
+ "selectOptions": {
+ "node": {
+ "title": "Node.js",
+ "desc": "Geleneksel ve yaygın olarak desteklenen çalışma zamanı"
+ },
+ "bun": {
+ "title": "Bun",
+ "desc": "Hızlı, hepsi bir arada JavaScript çalışma zamanı"
+ }
+ }
+ },
"errors": {
"operationCancelled": "İşlem iptal edildi"
},
diff --git a/locales/zh-Hans.json b/locales/zh-Hans.json
index 6efc0f094..24bd3f239 100644
--- a/locales/zh-Hans.json
+++ b/locales/zh-Hans.json
@@ -62,7 +62,7 @@
"needsRuntime": {
"message": "选择运行时环境:",
"selectOptions": {
- "nodejs": {
+ "node": {
"title": "Node.js",
"desc": "传统且广泛支持的运行时"
},
diff --git a/locales/zh-Hant.json b/locales/zh-Hant.json
index 4837230e7..241e65927 100644
--- a/locales/zh-Hant.json
+++ b/locales/zh-Hant.json
@@ -63,6 +63,19 @@
"needsPrettier": {
"message": "是否引入 Prettier 用於程式碼格式化?"
},
+ "needsRuntime": {
+ "message": "選擇執行環境:",
+ "selectOptions": {
+ "node": {
+ "title": "Node.js",
+ "desc": "傳統且廣泛支援的執行環境"
+ },
+ "bun": {
+ "title": "Bun",
+ "desc": "快速的一體化 JavaScript 執行環境"
+ }
+ }
+ },
"errors": {
"operationCancelled": "操作取消"
},
From 505bbc14cf96f7617cf46bbbff13d715c74a793a Mon Sep 17 00:00:00 2001
From: dt_4653622669 <2306860505@qq.com>
Date: Thu, 6 Feb 2025 20:42:39 +0800
Subject: [PATCH 3/3] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E5=88=A4=E6=96=AD?=
=?UTF-8?q?=E8=BF=90=E8=A1=8C=E6=97=B6=EF=BC=8C=E6=9B=B4=E6=96=B0=E4=BE=9D?=
=?UTF-8?q?=E8=B5=96?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
index.ts | 24 +++++++++++++++++--
.../bun/config/typescript/env.d.ts | 1 +
.../bun/config/typescript/package.json | 6 ++---
3 files changed, 26 insertions(+), 5 deletions(-)
create mode 100644 template/others-runtime/bun/config/typescript/env.d.ts
diff --git a/index.ts b/index.ts
index a1e4c4e4f..026e9794a 100755
--- a/index.ts
+++ b/index.ts
@@ -63,6 +63,22 @@ function emptyDir(dir) {
)
}
+// get now user runtime
+function detectRuntime() {
+ // @ts-ignore
+ if (typeof Bun !== 'undefined') {
+ return 'bun'
+ }
+ if (typeof process !== 'undefined' && process.versions && process.versions.node) {
+ return 'node'
+ }
+ // @ts-ignore
+ if (typeof Deno !== 'undefined') {
+ return 'deno'
+ }
+ return 'unknown'
+}
+
const helpMessage = `\
Usage: create-vue [FEATURE_FLAGS...] [OPTIONS...] [DIRECTORY]
@@ -105,6 +121,9 @@ Available feature flags:
--eslint-with-prettier
Add Prettier for code formatting in addition to ESLint.
+ --runtime
+ Show runtime environment selection prompt.
+
Unstable feature flags:
--tests, --with-tests
Add both unit testing and end-to-end testing support.
@@ -123,6 +142,7 @@ async function init() {
tests: { type: 'boolean' },
'vue-router': { type: 'boolean' },
router: { type: 'boolean' },
+ runtime: { type: 'boolean' },
} as const
const { values: argv, positionals } = parseArgs({
@@ -209,7 +229,7 @@ async function init() {
[
{
name: 'runtime',
- type: () => (isFeatureFlagsUsed ? null : 'select'),
+ type: () => (argv.runtime ? 'select' : null),
message: language.needsRuntime.message,
initial: 0,
choices: [
@@ -391,7 +411,7 @@ async function init() {
needsPinia = argv.pinia,
needsVitest = argv.vitest || argv.tests,
needsPrettier = argv['eslint-with-prettier'],
- runtime = 'node',
+ runtime = detectRuntime(),
} = result
const needsEslint = Boolean(argv.eslint || argv['eslint-with-prettier'] || result.needsEslint)
diff --git a/template/others-runtime/bun/config/typescript/env.d.ts b/template/others-runtime/bun/config/typescript/env.d.ts
new file mode 100644
index 000000000..11f02fe2a
--- /dev/null
+++ b/template/others-runtime/bun/config/typescript/env.d.ts
@@ -0,0 +1 @@
+///