浏览代码

[create]Add jsconfig.json file confirm.

dufu1991 2 年之前
父节点
当前提交
a1500a5aac
共有 3 个文件被更改,包括 42 次插入4 次删除
  1. 7 0
      packages/create-stdf/common/jsconfig.json
  2. 25 4
      packages/create-stdf/src/index.js
  3. 10 0
      packages/create-stdf/src/lang.js

+ 7 - 0
packages/create-stdf/common/jsconfig.json

@@ -0,0 +1,7 @@
+{
+	"compilerOptions": {
+		"checkJs": true
+	},
+	"include": ["src/**/*.js", "src/**/*.svelte"],
+	"exclude": ["node_modules", "dist"]
+}

+ 25 - 4
packages/create-stdf/src/index.js

@@ -11,6 +11,7 @@ import * as langAll from './lang';
 
 // 获取版本号
 // Get version
+// @ts-ignore
 const { version } = JSON.parse(fs.readFileSync(new URL('../package.json', import.meta.url), 'utf-8'));
 
 // 显示版本号
@@ -127,6 +128,17 @@ else if (argvProjectName && argvTemplate) {
 			});
 		}
 
+		// 是否启用类型检查
+		// Whether to enable type checking
+		const isTypeCheck = await p.confirm({
+			message: bold(lang.wtetcfjsf),
+		});
+
+		if (p.isCancel(isTypeCheck)) {
+			p.cancel(red('⛔ ') + lang.oc);
+			process.exit(0);
+		}
+
 		// 输入项目名称
 		// Enter the project name
 		const projectName = await p.text({
@@ -155,13 +167,13 @@ else if (argvProjectName && argvTemplate) {
 		// According to the value of template, copy all files under the corresponding directory to the current directory
 		templateOptions.forEach(async item => {
 			if (item.value === template) {
-				createFunc(projectName, item);
+				createFunc(projectName, item, isTypeCheck);
 			}
 		});
 	})();
 }
 
-function createFunc(projectName, item) {
+function createFunc(projectName, item, isTypeCheck = true) {
 	// 如果 projectName 是数字,转为字符串
 	// If projectName is a number, convert it to a string
 	if (typeof projectName === 'number') {
@@ -178,6 +190,7 @@ function createFunc(projectName, item) {
 
 	// 获取模板目录的绝对路径,考虑到 Windows 系统的兼容性, 使用 path.join
 	// Get the absolute path of the template directory, considering the compatibility of the Windows system, use path.join
+	// @ts-ignore
 	const templatePath = path.resolve(fileURLToPath(import.meta.url), '../..', `templates/${item.template}`);
 
 	// 将 templatePath 目录下的所有文件复制到 projectDir 目录下
@@ -187,6 +200,14 @@ function createFunc(projectName, item) {
 			spinner.stop();
 			p.outro(`${projectName} - ${lang.pcsucc} 🎉`);
 
+			// 如果 isTypeCheck 为 true,将 common 目录下的 jsconfig.json 文件复制到项目目录下
+			// If isTypeCheck is true, copy the jsconfig.json file under the common directory to the project directory
+			if (isTypeCheck) {
+				// @ts-ignore
+				const commonPath = path.resolve(fileURLToPath(import.meta.url), '../..', 'common');
+				fs.copySync(path.join(commonPath, '/jsconfig.json'), path.join(projectDir, 'jsconfig.json'));
+			}
+
 			// 读取 package.json 文件
 			// Read the package.json file
 			const packageJson = JSON.parse(fs.readFileSync(`${projectDir}/package.json`, 'utf-8'));
@@ -243,8 +264,8 @@ function createFunc(projectName, item) {
 				`👉 ${bold(lang.tgs)}
 
     ${blue(`cd ${projectName}`)}
-    ${blue('bun i / pnpm i / npm i / yarn')}
-    ${blue('bun dev / npm run dev')}
+    ${blue('pnpm i / npm i / yarn / bun i')}
+    ${blue('npm dev / bun dev')}
     `,
 			);
 			// 显示配置主题色

+ 10 - 0
packages/create-stdf/src/lang.js

@@ -16,6 +16,7 @@ export const en_US = {
 	pcyt_vu: 'Tip: please configure Initial Color System in src/app.css, and Color System in uno.config.js',
 	cferror: 'Failed to create file',
 	pectn: 'Please enter the correct template name!',
+	wtetcfjsf: 'Whether to enable type checking for all .js and .svelte files in src?',
 };
 
 // 简体中文 chinese
@@ -36,6 +37,7 @@ export const zh_CN = {
 	pcyt_vu: '提示:请到 src/app.css 配置初始主题色,uno.config.js 配置颜色系统',
 	cferror: '创建文件失败',
 	pectn: '请输入正确的模板名称!',
+	wtetcfjsf: '是否对 src 内的所有 .js 与 .svelte 文件启用类型检查?',
 };
 
 // 繁體中文 chinese traditional
@@ -56,6 +58,7 @@ export const zh_TW = {
 	pcyt_vu: '提示:請到 src/app.css 配置初始主題色,uno.config.js 配置顏色系統',
 	cferror: '創建文件失敗',
 	pectn: '請輸入正確的模板名稱!',
+	wtetcfjsf: '是否對 src 內的所有 .js 與 .svelte 文件啟用類型檢查?',
 };
 
 // 日语 japanese
@@ -76,6 +79,7 @@ export const ja_JP = {
 	pcyt_vu: 'ヒント:src/app.css ファイルで初期カラーシステムを設定し、uno.config.js ファイルでカラーシステムを設定します',
 	cferror: 'ファイルの作成に失敗しました',
 	pectn: '正しいテンプレート名を入力してください!',
+	wtetcfjsf: 'src 内のすべての .js と .svelte ファイルに型チェックを有効にしますか?',
 };
 
 // 韩语 korean
@@ -96,6 +100,7 @@ export const ko_KR = {
 	pcyt_vu: '팁: src/app.css 파일에서 초기 색상 시스템을 구성하고 uno.config.js 파일에서 색상 시스템을 구성하십시오',
 	cferror: '파일 생성 실패',
 	pectn: '올바른 템플릿 이름을 입력하십시오!',
+	wtetcfjsf: 'src 내의 모든 .js 및 .svelte 파일에 대한 유형 검사를 활성화 하시겠습니까?',
 };
 
 // 西班牙语 spanish
@@ -116,6 +121,7 @@ export const es_ES = {
 	pcyt_vu: 'Consejo: configure su sistema de colores iniciales en el archivo uno.config.js',
 	cferror: 'Error al crear archivo',
 	pectn: '¡Por favor ingrese el nombre de la plantilla correcto!',
+	wtetcfjsf: '¿Desea habilitar la comprobación de tipos para todos los archivos .js y .svelte en src?',
 };
 
 // 俄语 russian
@@ -136,6 +142,7 @@ export const ru_RU = {
 	pcyt_vu: 'Совет: пожалуйста, настройте свою систему цветов в файле uno.config.js',
 	cferror: 'Не удалось создать файл',
 	pectn: 'Пожалуйста, введите правильное имя шаблона!',
+	wtetcfjsf: 'Включить проверку типов для всех файлов .js и .svelte в src?',
 };
 
 // 法语 french
@@ -156,6 +163,7 @@ export const fr_FR = {
 	pcyt_vu: 'Conseil: veuillez configurer votre système de couleurs initiales dans le fichier uno.config.js',
 	cferror: 'Échec de la création du fichier',
 	pectn: 'Veuillez saisir le nom du modèle correct!',
+	wtetcfjsf: 'Activer la vérification des types pour tous les fichiers .js et .svelte dans src?',
 };
 
 // 德语 german
@@ -176,6 +184,7 @@ export const de_DE = {
 	pcyt_vu: 'Tipp: Konfigurieren Sie Ihr Initial Color System in der Datei uno.config.js',
 	cferror: 'Fehler beim Erstellen der Datei',
 	pectn: 'Bitte geben Sie den richtigen Vorlagennamen ein!',
+	wtetcfjsf: 'Möchten Sie die Typüberprüfung für alle .js- und .svelte-Dateien in src aktivieren?',
 };
 
 // 意大利语 italian
@@ -196,4 +205,5 @@ export const it_IT = {
 	pcyt_vu: 'Suggerimento: configura il tuo sistema di colori iniziale nel file uno.config.js',
 	cferror: 'Impossibile creare il file',
 	pectn: 'Inserisci il nome del modello corretto!',
+	wtetcfjsf: 'Abilitare il controllo dei tipi per tutti i file .js e .svelte in src?',
 };