mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-23 07:41:53 +08:00
Merge branch 'feature/project-reactor' of https://gitee.com/zhijiantianya/ruoyi-vue-pro into feature/project-reactor
This commit is contained in:
commit
3e77061c40
@ -8,10 +8,12 @@ import org.apache.commons.io.FileUtils;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 项目修改器,一键替换 Maven 的 groupId、artifactId,项目的 package 等
|
* 项目修改器,一键替换 Maven 的 groupId、artifactId,项目的 package 等
|
||||||
*
|
* <p>
|
||||||
* 通过修改 groupIdNew、artifactIdNew、projectBaseDirNew 三个变量
|
* 通过修改 groupIdNew、artifactIdNew、projectBaseDirNew 三个变量
|
||||||
*
|
*
|
||||||
* @author 芋道源码
|
* @author 芋道源码
|
||||||
@ -25,6 +27,7 @@ public class ProjectReactor {
|
|||||||
private static final String TITLE = "芋道管理系统";
|
private static final String TITLE = "芋道管理系统";
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
long start = System.currentTimeMillis();
|
||||||
String projectBaseDir = getProjectBaseDir();
|
String projectBaseDir = getProjectBaseDir();
|
||||||
|
|
||||||
// ========== 配置,需要你手动修改 ==========
|
// ========== 配置,需要你手动修改 ==========
|
||||||
@ -33,7 +36,7 @@ public class ProjectReactor {
|
|||||||
String packageNameNew = "cn.start.pp";
|
String packageNameNew = "cn.start.pp";
|
||||||
String titleNew = "土豆管理系统";
|
String titleNew = "土豆管理系统";
|
||||||
String projectBaseDirNew = projectBaseDir + "-new"; // 一键改名后,“新”项目所在的目录
|
String projectBaseDirNew = projectBaseDir + "-new"; // 一键改名后,“新”项目所在的目录
|
||||||
// ========== ==========
|
log.info("[main][新项目路径地址]projectBaseDirNew: " + projectBaseDirNew);
|
||||||
|
|
||||||
// 获得需要复制的文件
|
// 获得需要复制的文件
|
||||||
log.info("[main][开始获得需要重写的文件]");
|
log.info("[main][开始获得需要重写的文件]");
|
||||||
@ -44,22 +47,26 @@ public class ProjectReactor {
|
|||||||
String content = replaceFileContent(file, groupIdNew, artifactIdNew, packageNameNew, titleNew);
|
String content = replaceFileContent(file, groupIdNew, artifactIdNew, packageNameNew, titleNew);
|
||||||
writeFile(file, content, projectBaseDir, projectBaseDirNew, packageNameNew, artifactIdNew);
|
writeFile(file, content, projectBaseDir, projectBaseDirNew, packageNameNew, artifactIdNew);
|
||||||
});
|
});
|
||||||
log.info("[main][重写完成]");
|
log.info("[main][重写完成]共耗时:{} 秒", (System.currentTimeMillis() - start) / 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getProjectBaseDir() {
|
private static String getProjectBaseDir() {
|
||||||
// noinspection ConstantConditions
|
return StrUtil.subBefore(new File(ProjectReactor.class.getClassLoader().getResource(File.separator).getFile()).getPath(), File.separator + "yudao-server", false);
|
||||||
return StrUtil.subBefore(ProjectReactor.class.getClassLoader().getResource("").getFile(),
|
|
||||||
"/yudao-server", false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Collection<File> listFiles(String projectBaseDir) {
|
private static Collection<File> listFiles(String projectBaseDir) {
|
||||||
Collection<File> files = FileUtils.listFiles(new File(projectBaseDir), null, true);
|
Collection<File> files = FileUtils.listFiles(new File(projectBaseDir), null, true);
|
||||||
files.removeIf(file -> file.getPath().contains("/target/"));
|
// 移除 IDEA Git GitHub 自身的文件; Node 编译出来的文件
|
||||||
files.removeIf(file -> file.getPath().contains("/node_modules/"));
|
files = files.stream()
|
||||||
files.removeIf(file -> file.getPath().contains("/.idea/")); // 移除 IDEA 自身的文件
|
.filter(file -> !file.getPath().contains(File.separator + "target" + File.separator)
|
||||||
files.removeIf(file -> file.getPath().contains("/.git/")); // 移除 Git 自身的文件
|
&& !file.getPath().contains(File.separator + "node_modules" + File.separator)
|
||||||
files.removeIf(file -> file.getPath().contains("/dist/")); // 移除 Node 编译出来的
|
&& !file.getPath().contains(File.separator + ".idea" + File.separator)
|
||||||
|
&& !file.getPath().contains(File.separator + ".git" + File.separator)
|
||||||
|
&& !file.getPath().contains(File.separator + ".github" + File.separator)
|
||||||
|
&& !file.getPath().contains(File.separator + "dist" + File.separator)
|
||||||
|
&& !file.getPath().contains(".iml")
|
||||||
|
&& !file.getPath().contains(".html.gz"))
|
||||||
|
.collect(Collectors.toList());
|
||||||
return files;
|
return files;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,11 +84,10 @@ public class ProjectReactor {
|
|||||||
private static void writeFile(File file, String fileContent, String projectBaseDir,
|
private static void writeFile(File file, String fileContent, String projectBaseDir,
|
||||||
String projectBaseDirNew, String packageNameNew, String artifactIdNew) {
|
String projectBaseDirNew, String packageNameNew, String artifactIdNew) {
|
||||||
String newPath = file.getPath().replace(projectBaseDir, projectBaseDirNew) // 新目录
|
String newPath = file.getPath().replace(projectBaseDir, projectBaseDirNew) // 新目录
|
||||||
.replace(PACKAGE_NAME.replaceAll("\\.", File.separator),
|
.replace(PACKAGE_NAME.replaceAll("\\.", Matcher.quoteReplacement(File.separator)),
|
||||||
packageNameNew.replaceAll("\\.", File.separator))
|
packageNameNew.replaceAll("\\.", Matcher.quoteReplacement(File.separator)))
|
||||||
.replace(ARTIFACT_ID, artifactIdNew) //
|
.replace(ARTIFACT_ID, artifactIdNew) //
|
||||||
.replaceAll(StrUtil.upperFirst(ARTIFACT_ID), StrUtil.upperFirst(artifactIdNew));
|
.replaceAll(StrUtil.upperFirst(ARTIFACT_ID), StrUtil.upperFirst(artifactIdNew));
|
||||||
FileUtil.writeUtf8String(fileContent, newPath);
|
FileUtil.writeUtf8String(fileContent, newPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user