diff --git a/index.ts b/index.ts
index 6ab53ab8..026e9794 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({
@@ -178,6 +198,7 @@ async function init() {
needsEslint?: false | 'eslintOnly' | 'speedUpWithOxlint'
needsOxlint?: boolean
needsPrettier?: boolean
+ runtime?: 'node' | 'bun'
} = {}
console.log()
@@ -190,6 +211,7 @@ async function init() {
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
@@ -202,8 +224,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: () => (argv.runtime ? 'select' : null),
+ message: language.needsRuntime.message,
+ initial: 0,
+ choices: [
+ {
+ 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',
+ },
+ ],
+ },
{
name: 'projectName',
type: targetDir ? null : 'text',
@@ -370,6 +411,7 @@ async function init() {
needsPinia = argv.pinia,
needsVitest = argv.vitest || argv.tests,
needsPrettier = argv['eslint-with-prettier'],
+ runtime = detectRuntime(),
} = result
const needsEslint = Boolean(argv.eslint || argv['eslint-with-prettier'] || result.needsEslint)
@@ -401,8 +443,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 = path.resolve(templateRoot, 'others-runtime', runtime, templateName)
+ if (!fs.existsSync(templateDir)) {
+ templateDir = path.resolve(templateRoot, templateName)
+ }
renderTemplate(templateDir, root, callbacks)
}
// Render base template
@@ -449,7 +494,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',
diff --git a/locales/en-US.json b/locales/en-US.json
index d1f8a169..eacbf90d 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": {
+ "node": {
+ "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 9ff6d131..931d41fc 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": {
+ "node": {
+ "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/tr-TR.json b/locales/tr-TR.json
index 323acac1..c7da3f9e 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 c74002f0..24bd3f23 100644
--- a/locales/zh-Hans.json
+++ b/locales/zh-Hans.json
@@ -59,6 +59,19 @@
"needsPrettier": {
"message": "是否引入 Prettier 用于代码格式化?"
},
+ "needsRuntime": {
+ "message": "选择运行时环境:",
+ "selectOptions": {
+ "node": {
+ "title": "Node.js",
+ "desc": "传统且广泛支持的运行时"
+ },
+ "bun": {
+ "title": "Bun",
+ "desc": "快速的一体化 JavaScript 运行时"
+ }
+ }
+ },
"errors": {
"operationCancelled": "操作取消"
},
diff --git a/locales/zh-Hant.json b/locales/zh-Hant.json
index 4837230e..241e6592 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": "操作取消"
},
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 00000000..11f02fe2
--- /dev/null
+++ b/template/others-runtime/bun/config/typescript/env.d.ts
@@ -0,0 +1 @@
+///