Просмотр исходного кода

Fix 修复模板生成新项目的一些问题

YueYunyun 2 лет назад
Родитель
Сommit
ecb6a20538

+ 1 - 1
.gitignore

@@ -62,6 +62,6 @@ build/
 
 ### dist  ###
 /UI/dist/
-/UIdist
+/UI/dist
 /UI/**/dist.rar
 

+ 17 - 10
SERVER/VberAdminPlus/vber-generator/src/main/java/com/vber/generator/util/ProjectReactorUtils.java

@@ -24,7 +24,9 @@ public class ProjectReactorUtils {
     private static final String PACKAGE_NAME = "com.vber";
     private static final String MODULE_PREFIX = "vber-";
     private static final String MODULE_ARTIFACT_ID_PREFIX = "<artifactId>" + MODULE_PREFIX;
-    private static final String TITLE = "VberAdminPlus后台管理系统";
+    private static final String MODULE_ID_PREFIX = "<module>" + MODULE_PREFIX;
+    private static final String TITLE = "VAP后台管理系统";
+    private static final String UI_FILE = "VAP.VUE";
     /**
      * 白名单文件,不进行重写,避免出问题
      */
@@ -33,6 +35,7 @@ public class ProjectReactorUtils {
 
     public static void Build(@NotNull String groupId, @NotNull String artifactId, @NotNull String packageName, @NotNull String title, @NotNull String projectDir, String modulePrefix) {
         modulePrefix = StrUtil.isEmpty(modulePrefix) ? "vber-" : modulePrefix;
+        projectDir= projectDir.endsWith("\\") ? projectDir : projectDir + "\\";
         Build(new ProjectInfo(groupId, artifactId, packageName, title, projectDir, modulePrefix));
     }
 
@@ -45,6 +48,8 @@ public class ProjectReactorUtils {
         String packageName = StrUtil.isEmpty(projectInfo.getPackageName()) ? PACKAGE_NAME : projectInfo.getPackageName();
         String modulePrefix = StrUtil.isEmpty(projectInfo.getModulePrefix()) ? MODULE_PREFIX : projectInfo.getModulePrefix();
         String moduleArtifactIdPrefix = "<artifactId>" + modulePrefix;
+        String moduleIdPrefix = "<module>" + modulePrefix;
+        String uiFile = modulePrefix.replace("-","").toUpperCase()+".VUE";
         String title = StrUtil.isEmpty(projectInfo.getTitle()) ? TITLE : projectInfo.getTitle();
 
         if (StrUtil.isEmpty(projectInfo.getGroupId())) {
@@ -83,12 +88,12 @@ public class ProjectReactorUtils {
             // 如果是白名单的文件类型,不进行重写,直接拷贝
             String fileType = getFileType(file);
             if (WHITE_FILE_TYPES.contains(fileType)) {
-                copyFile(file, oldProjectDir, projectDir, packageName, artifactId, modulePrefix);
+                copyFile(file, oldProjectDir, projectDir, packageName, artifactId, modulePrefix,uiFile);
                 return;
             }
             // 如果非白名单的文件类型,重写内容,在生成文件
-            String content = replaceFileContent(file, groupId, artifactId, packageName, title, moduleArtifactIdPrefix);
-            writeFile(file, content, oldProjectDir, projectDir, packageName, artifactId, modulePrefix);
+            String content = replaceFileContent(file, groupId, artifactId, packageName, title, moduleArtifactIdPrefix,moduleIdPrefix);
+            writeFile(file, content, oldProjectDir, projectDir, packageName, artifactId, modulePrefix,uiFile);
         });
         log.info("[重写完成]共耗时:{} 秒", (System.currentTimeMillis() - start) / 1000);
     }
@@ -123,7 +128,7 @@ public class ProjectReactorUtils {
 
     private static String replaceFileContent(File file, String groupIdNew,
                                              String artifactIdNew, String packageNameNew,
-                                             String titleNew, String moduleArtifactIdPrefix) {
+                                             String titleNew, String moduleArtifactIdPrefix,String moduleIdSuffix) {
         String content = FileUtil.readString(file, StandardCharsets.UTF_8);
         // 如果是白名单的文件类型,不进行重写
         String fileType = getFileType(file);
@@ -136,25 +141,27 @@ public class ProjectReactorUtils {
                 .replaceAll(MODULE_ARTIFACT_ID_PREFIX, moduleArtifactIdPrefix)
                 .replaceAll(ARTIFACT_ID, artifactIdNew) // 必须放在最后替换,因为 ARTIFACT_ID 太短!
                 .replaceAll(StrUtil.upperFirst(ARTIFACT_ID), StrUtil.upperFirst(artifactIdNew))
+                .replaceAll(StrUtil.upperFirst(MODULE_ID_PREFIX), StrUtil.upperFirst(moduleIdSuffix))
                 .replaceAll(TITLE, titleNew);
     }
 
-    private static void writeFile(File file, String fileContent, String projectBaseDir, String projectBaseDirNew, String packageNameNew, String artifactIdNew, String modulePrefix) {
-        String newPath = buildNewFilePath(file, projectBaseDir, projectBaseDirNew, packageNameNew, artifactIdNew, modulePrefix);
+    private static void writeFile(File file, String fileContent, String projectBaseDir, String projectBaseDirNew, String packageNameNew, String artifactIdNew, String modulePrefix,String uiFile) {
+        String newPath = buildNewFilePath(file, projectBaseDir, projectBaseDirNew, packageNameNew, artifactIdNew, modulePrefix,uiFile);
         FileUtil.writeUtf8String(fileContent, newPath);
     }
 
-    private static void copyFile(File file, String projectBaseDir, String projectBaseDirNew, String packageNameNew, String artifactIdNew, String modulePrefix) {
-        String newPath = buildNewFilePath(file, projectBaseDir, projectBaseDirNew, packageNameNew, artifactIdNew, modulePrefix);
+    private static void copyFile(File file, String projectBaseDir, String projectBaseDirNew, String packageNameNew, String artifactIdNew, String modulePrefix,String uiFile) {
+        String newPath = buildNewFilePath(file, projectBaseDir, projectBaseDirNew, packageNameNew, artifactIdNew, modulePrefix,uiFile);
         FileUtil.copyFile(file, new File(newPath));
     }
 
-    private static String buildNewFilePath(File file, String projectBaseDir, String projectBaseDirNew, String packageNameNew, String artifactIdNew, String modulePrefix) {
+    private static String buildNewFilePath(File file, String projectBaseDir, String projectBaseDirNew, String packageNameNew, String artifactIdNew, String modulePrefix,String uiFile) {
         return file.getPath().replace(projectBaseDir, projectBaseDirNew) // 新目录
                 .replace(PACKAGE_NAME.replaceAll("\\.", Matcher.quoteReplacement(separator)),
                         packageNameNew.replaceAll("\\.", Matcher.quoteReplacement(separator)))
                 .replace(ARTIFACT_ID, artifactIdNew) //
                 .replace(MODULE_PREFIX, modulePrefix) //
+                .replace(UI_FILE, uiFile) //
                 .replaceAll(StrUtil.upperFirst(ARTIFACT_ID), StrUtil.upperFirst(artifactIdNew));
     }
 

+ 0 - 31
UI/VAP.VUE/vite/vite/plugins/_auto-import.ts

@@ -1,31 +0,0 @@
-import AutoImport from "unplugin-auto-import/vite"
-import Components from "unplugin-vue-components/vite"
-import { ElementPlusResolver } from "unplugin-vue-components/resolvers"
-
-export default function createAutoImport(): any[] {
-	return [
-		AutoImport({
-			imports: ["vue", "vue-router", "pinia"],
-			// plus按需引入
-			resolvers: [ElementPlusResolver()],
-			dirs: ["src/core/utils", "src/core/services"],
-			dts: "vite/auto-import/auto-import.d.ts",
-			eslintrc: {
-				enabled: true,
-				filepath: "vite/auto-import/.eslintrc-auto-import.json",
-				globalsPropValue: true
-			}
-		}),
-		// plus按需引入
-		Components({
-			resolvers: [ElementPlusResolver()],
-			// 指定组件位置,默认是src/components
-			dirs: ["src/components"],
-			// 组件的有效文件扩展名。
-			extensions: ["vue"],
-			// 搜索子目录
-			deep: true,
-			dts: "vite/auto-import/components.d.ts"
-		})
-	]
-}

+ 0 - 27
UI/VAP.VUE/vite/vite/plugins/_compression.ts

@@ -1,27 +0,0 @@
-import compression from "vite-plugin-compression"
-
-export default function createCompression(env: Record<string, string>): any[] {
-	const { VITE_BUILD_COMPRESS } = env
-	const plugin = []
-	if (VITE_BUILD_COMPRESS != "") {
-		const compressList = VITE_BUILD_COMPRESS.split(",")
-		if (compressList.includes("gzip")) {
-			plugin.push(
-				compression({
-					ext: ".gz",
-					deleteOriginFile: false
-				})
-			)
-		}
-		if (compressList.includes("brotli")) {
-			plugin.push(
-				compression({
-					ext: ".br",
-					algorithm: "brotliCompress",
-					deleteOriginFile: false
-				})
-			)
-		}
-	}
-	return plugin
-}

+ 0 - 5
UI/VAP.VUE/vite/vite/plugins/_setup-extend.ts

@@ -1,5 +0,0 @@
-import setupExtend from "vite-plugin-vue-setup-extend"
-
-export default function createSetupExtend() {
-	return setupExtend()
-}

+ 0 - 12
UI/VAP.VUE/vite/vite/plugins/index.ts

@@ -1,12 +0,0 @@
-import vue from "@vitejs/plugin-vue"
-import createAutoImport from "./_auto-import"
-import createSetupExtend from "./_setup-extend"
-import createCompression from "./_compression"
-
-export default function createVitePlugins(viteEnv: Record<string, string>, isBuild = false): any[] {
-	const vitePlugins = [vue()]
-	vitePlugins.push(...createAutoImport())
-	vitePlugins.push(createSetupExtend())
-	isBuild && vitePlugins.push(...createCompression(viteEnv))
-	return vitePlugins
-}

+ 1 - 1
UI/VAP.Vue/index.html

@@ -6,7 +6,7 @@
 		<meta name="description" content="Vap后台管理系统" />
 		<link rel="icon" href="/favicon.ico" />
 		<link rel="stylesheet" href="/splash-screen.css" />
-		<title>Vap后台管理系统</title>
+		<title>VAP后台管理系统</title>
 	</head>
 	<body>
 		<script>