|
@ -4,8 +4,10 @@ import java.util.zip.GZIPOutputStream |
|
|
|
|
|
|
|
|
apply from: "build-version.gradle" |
|
|
apply from: "build-version.gradle" |
|
|
|
|
|
|
|
|
|
|
|
// 判断项目是否是普通前端项目 |
|
|
def isFrontendProject(currentDir){ |
|
|
def isFrontendProject(currentDir){ |
|
|
return file(currentDir.getAbsolutePath() + '/package.json').exists() && !file(currentDir.getAbsolutePath() + '/webpack.env.lib.cjs').exists(); |
|
|
return file(currentDir.getAbsolutePath() + '/package.json').exists() |
|
|
|
|
|
&& !file(currentDir.getAbsolutePath() + '/webpack.env.lib.cjs').exists(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/*********************************************************************** |
|
|
/*********************************************************************** |
|
@ -19,6 +21,7 @@ buildscript { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
dependencies { |
|
|
dependencies { |
|
|
|
|
|
classpath "com.gradleup.shadow:shadow-gradle-plugin:${shadow_gradle_plugin_version}" |
|
|
classpath "org.springframework.boot:org.springframework.boot.gradle.plugin:${spring_boot_version}" |
|
|
classpath "org.springframework.boot:org.springframework.boot.gradle.plugin:${spring_boot_version}" |
|
|
classpath "io.sc:io.sc.platform.gradle:${platform_plugin_version}" |
|
|
classpath "io.sc:io.sc.platform.gradle:${platform_plugin_version}" |
|
|
classpath "org.asciidoctor:asciidoctor-gradle-jvm:${asciidoctor_version}" |
|
|
classpath "org.asciidoctor:asciidoctor-gradle-jvm:${asciidoctor_version}" |
|
@ -44,7 +47,7 @@ subprojects { |
|
|
apply plugin: 'maven-publish' |
|
|
apply plugin: 'maven-publish' |
|
|
apply plugin: 'org.springframework.boot' |
|
|
apply plugin: 'org.springframework.boot' |
|
|
apply plugin: 'io.spring.dependency-management' |
|
|
apply plugin: 'io.spring.dependency-management' |
|
|
apply plugin: "org.asciidoctor.jvm.convert" |
|
|
apply plugin: 'org.asciidoctor.jvm.convert' |
|
|
|
|
|
|
|
|
configurations.all { |
|
|
configurations.all { |
|
|
//设置 gradle 拉取依赖包的缓存策略为不进行缓存,可保证每次拉取最新的依赖包 |
|
|
//设置 gradle 拉取依赖包的缓存策略为不进行缓存,可保证每次拉取最新的依赖包 |
|
@ -155,9 +158,12 @@ subprojects { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
clean { |
|
|
clean { |
|
|
//delete 'dist' //删除前端自动生成的资源目录 |
|
|
delete 'bin' //删除 eclipse 编译的 bin 目录 |
|
|
//delete 'bin' //删除 eclipse 编译的 bin 目录 |
|
|
|
|
|
delete 'build' //删除 gradle 构建目录 |
|
|
delete 'build' //删除 gradle 构建目录 |
|
|
|
|
|
delete 'dist' //删除前端打包后的目录 |
|
|
|
|
|
delete 'node_modules' //删除前端 node_modules 目录 |
|
|
|
|
|
delete 'pnpm-lock.yaml' //删除前端 pnpm 文件 |
|
|
|
|
|
delete 'package-lock.json' //删除前端 npm 文件 |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------- |
|
|
/*----------------------------------------------------------------- |
|
@ -395,15 +401,15 @@ subprojects { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------- |
|
|
/*----------------------------------------------------------------- |
|
|
* pnpm re install |
|
|
* pnpm sync |
|
|
*----------------------------------------------------------------*/ |
|
|
*----------------------------------------------------------------*/ |
|
|
task frontendNpmReInstall(type:Exec){ |
|
|
task frontendNpmSync(type:Exec){ |
|
|
if(isFrontendProject(file('.'))){ |
|
|
if(isFrontendProject(file('.')) && !project.name.contains("io.sc.platform.security.frontend")){ |
|
|
workingDir '.' |
|
|
workingDir '.' |
|
|
if(org.gradle.internal.os.OperatingSystem.current().isWindows()){ |
|
|
if(org.gradle.internal.os.OperatingSystem.current().isWindows()){ |
|
|
commandLine 'cmd', '/c', 'pnpm', 'install' |
|
|
commandLine 'cmd', '/c', 'pnpm', 'sync' |
|
|
}else{ |
|
|
}else{ |
|
|
commandLine 'pnpm', 'install' |
|
|
commandLine 'pnpm', 'sync' |
|
|
} |
|
|
} |
|
|
}else{ |
|
|
}else{ |
|
|
if(org.gradle.internal.os.OperatingSystem.current().isWindows()){ |
|
|
if(org.gradle.internal.os.OperatingSystem.current().isWindows()){ |
|
@ -413,22 +419,22 @@ subprojects { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
tasks.frontendNpmReInstall.doFirst { |
|
|
tasks.frontendNpmSync.doFirst { |
|
|
if(isFrontendProject(file('.'))) { |
|
|
if(isFrontendProject(file('.'))) { |
|
|
println '开始执行 pnpm re install ......'; |
|
|
println '开始执行 pnpm sync ......'; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------- |
|
|
/*----------------------------------------------------------------- |
|
|
* pnpm sync |
|
|
* pnpm re install |
|
|
*----------------------------------------------------------------*/ |
|
|
*----------------------------------------------------------------*/ |
|
|
task frontendNpmSync(type:Exec){ |
|
|
task frontendNpmReInstall(type:Exec){ |
|
|
if(isFrontendProject(file('.')) && !project.name.contains("io.sc.platform.security.frontend")){ |
|
|
if(isFrontendProject(file('.'))){ |
|
|
workingDir '.' |
|
|
workingDir '.' |
|
|
if(org.gradle.internal.os.OperatingSystem.current().isWindows()){ |
|
|
if(org.gradle.internal.os.OperatingSystem.current().isWindows()){ |
|
|
commandLine 'cmd', '/c', 'pnpm', 'sync' |
|
|
commandLine 'cmd', '/c', 'pnpm', 'install' |
|
|
}else{ |
|
|
}else{ |
|
|
commandLine 'pnpm', 'sync' |
|
|
commandLine 'pnpm', 'install' |
|
|
} |
|
|
} |
|
|
}else{ |
|
|
}else{ |
|
|
if(org.gradle.internal.os.OperatingSystem.current().isWindows()){ |
|
|
if(org.gradle.internal.os.OperatingSystem.current().isWindows()){ |
|
@ -438,9 +444,9 @@ subprojects { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
tasks.frontendNpmSync.doFirst { |
|
|
tasks.frontendNpmReInstall.doFirst { |
|
|
if(isFrontendProject(file('.'))) { |
|
|
if(isFrontendProject(file('.'))) { |
|
|
println '开始执行 pnpm sync ......'; |
|
|
println '开始执行 pnpm re install ......'; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -508,6 +514,9 @@ subprojects { |
|
|
} |
|
|
} |
|
|
tasks.frontendGenerateThymeleafTemplate.doLast { |
|
|
tasks.frontendGenerateThymeleafTemplate.doLast { |
|
|
if(isFrontendProject(file('.'))) { |
|
|
if(isFrontendProject(file('.'))) { |
|
|
|
|
|
if(!file("dist/public/${project.name}/index.html").exists()){ |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
def content = file("dist/public/${project.name}/index.html").text; |
|
|
def content = file("dist/public/${project.name}/index.html").text; |
|
|
content = content.replace('<script defer src="javascript/main', """<script defer src="${project.name}/javascript/main"""); |
|
|
content = content.replace('<script defer src="javascript/main', """<script defer src="${project.name}/javascript/main"""); |
|
|
def output = file("java-src/main/resources/templates/${project.name}.html"); |
|
|
def output = file("java-src/main/resources/templates/${project.name}.html"); |
|
@ -582,6 +591,9 @@ subprojects { |
|
|
} |
|
|
} |
|
|
tasks.frontendGenerateMenus.doLast { |
|
|
tasks.frontendGenerateMenus.doLast { |
|
|
if(isFrontendProject(file('.'))) { |
|
|
if(isFrontendProject(file('.'))) { |
|
|
|
|
|
if(!file('src/menus/menus.json').exists()) { |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
java.nio.file.Files.copy(file('src/menus/menus.json').toPath(), file('java-src/main/resources/META-INF/platform/plugins/menus.json').toPath()); |
|
|
java.nio.file.Files.copy(file('src/menus/menus.json').toPath(), file('java-src/main/resources/META-INF/platform/plugins/menus.json').toPath()); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
@ -598,12 +610,15 @@ subprojects { |
|
|
} |
|
|
} |
|
|
tasks.frontendGenerateRoutes.doLast { |
|
|
tasks.frontendGenerateRoutes.doLast { |
|
|
if(isFrontendProject(file('.'))) { |
|
|
if(isFrontendProject(file('.'))) { |
|
|
|
|
|
if(!file("src/routes/routes.json").exists()) { |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
def routes = new groovy.json.JsonSlurper().parseText(file("src/routes/routes.json").text); |
|
|
def routes = new groovy.json.JsonSlurper().parseText(file("src/routes/routes.json").text); |
|
|
for(def route : routes){ |
|
|
for (def route : routes) { |
|
|
route.module=project.name; |
|
|
route.module = project.name; |
|
|
} |
|
|
} |
|
|
def json = groovy.json.JsonOutput.toJson(routes); |
|
|
def json = groovy.json.JsonOutput.toJson(routes); |
|
|
def outputFile =file("java-src/main/resources/META-INF/platform/plugins/frontend-routes.json"); |
|
|
def outputFile = file("java-src/main/resources/META-INF/platform/plugins/frontend-routes.json"); |
|
|
outputFile.withWriter('UTF-8') { writer -> |
|
|
outputFile.withWriter('UTF-8') { writer -> |
|
|
writer.write(groovy.json.JsonOutput.prettyPrint(json)); |
|
|
writer.write(groovy.json.JsonOutput.prettyPrint(json)); |
|
|
} |
|
|
} |
|
@ -624,10 +639,12 @@ subprojects { |
|
|
if(isFrontendProject(file('.'))) { |
|
|
if(isFrontendProject(file('.'))) { |
|
|
//components--------------------------------------- |
|
|
//components--------------------------------------- |
|
|
List<String> components =new ArrayList<String>(); |
|
|
List<String> components =new ArrayList<String>(); |
|
|
|
|
|
if(file("java-src/main/resources/META-INF/platform/plugins/frontend-routes.json").exists()) { |
|
|
def routes = new groovy.json.JsonSlurper().parseText(file("java-src/main/resources/META-INF/platform/plugins/frontend-routes.json").text); |
|
|
def routes = new groovy.json.JsonSlurper().parseText(file("java-src/main/resources/META-INF/platform/plugins/frontend-routes.json").text); |
|
|
for(def route : routes){ |
|
|
for (def route : routes) { |
|
|
components.add(route.component); |
|
|
components.add(route.component); |
|
|
} |
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
//resources---------------------------------------- |
|
|
//resources---------------------------------------- |
|
|
List<String> resources = new ArrayList<String>(); |
|
|
List<String> resources = new ArrayList<String>(); |
|
@ -647,12 +664,12 @@ subprojects { |
|
|
}else{ |
|
|
}else{ |
|
|
def tree = fileTree('dist') { |
|
|
def tree = fileTree('dist') { |
|
|
include '**/*.*' |
|
|
include '**/*.*' |
|
|
exclude '**/webjars/**/*.*' |
|
|
// exclude '**/webjars/**/*.*' |
|
|
exclude "public/${project.name}/configure.js" |
|
|
// exclude "public/${project.name}/configure.js" |
|
|
exclude "public/${project.name}/favicon.svg" |
|
|
// exclude "public/${project.name}/favicon.svg" |
|
|
exclude "public/${project.name}/index.html" |
|
|
// exclude "public/${project.name}/index.html" |
|
|
exclude "public/${project.name}/login-bg.jpg" |
|
|
// exclude "public/${project.name}/login-bg.jpg" |
|
|
exclude "public/${project.name}/logo.svg" |
|
|
// exclude "public/${project.name}/logo.svg" |
|
|
} |
|
|
} |
|
|
tree.each { File file -> |
|
|
tree.each { File file -> |
|
|
resources.add(file.absolutePath.substring(dirPath.length())); |
|
|
resources.add(file.absolutePath.substring(dirPath.length())); |
|
@ -674,36 +691,6 @@ subprojects { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
task gzipFrontend(){} |
|
|
|
|
|
tasks.gzipFrontend.doFirst { |
|
|
|
|
|
if(isFrontendProject(file('.'))) { |
|
|
|
|
|
println '开始执行 gzip frontend ......' |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
tasks.frontendModule.doLast { |
|
|
|
|
|
if(isFrontendProject(file('.'))) { |
|
|
|
|
|
// 压缩前端 js 和 css |
|
|
|
|
|
def tree = fileTree('dist') { |
|
|
|
|
|
include '**/*.js' |
|
|
|
|
|
include '**/*.css' |
|
|
|
|
|
} |
|
|
|
|
|
tree.each { File file -> |
|
|
|
|
|
println file.getAbsolutePath() |
|
|
|
|
|
FileInputStream ins = new FileInputStream(file); |
|
|
|
|
|
GZIPOutputStream gos = new GZIPOutputStream(new FileOutputStream(file.getAbsolutePath() + ".gz")); |
|
|
|
|
|
def count; |
|
|
|
|
|
def data = new byte[1024]; |
|
|
|
|
|
while ((count = ins.read(data, 0, 1024)) != -1) { |
|
|
|
|
|
gos.write(data, 0, count); |
|
|
|
|
|
} |
|
|
|
|
|
gos.finish(); |
|
|
|
|
|
gos.flush(); |
|
|
|
|
|
gos.close(); |
|
|
|
|
|
ins.close(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------- |
|
|
/*----------------------------------------------------------------- |
|
|
* 打包 jar 之前处理前端资源 |
|
|
* 打包 jar 之前处理前端资源 |
|
|
*----------------------------------------------------------------*/ |
|
|
*----------------------------------------------------------------*/ |
|
@ -717,7 +704,7 @@ subprojects { |
|
|
// 定义前端构建任务的依赖及执行顺序 |
|
|
// 定义前端构建任务的依赖及执行顺序 |
|
|
frontendNpmInstall.dependsOn(frontendUpdatePackageJson) |
|
|
frontendNpmInstall.dependsOn(frontendUpdatePackageJson) |
|
|
frontendNpmSync.dependsOn(frontendNpmInstall) |
|
|
frontendNpmSync.dependsOn(frontendNpmInstall) |
|
|
frontendNpmReInstall.dependsOn(frontendNpmSync); |
|
|
frontendNpmReInstall.dependsOn(frontendNpmSync) |
|
|
frontendNpmBuild.dependsOn(frontendNpmReInstall) |
|
|
frontendNpmBuild.dependsOn(frontendNpmReInstall) |
|
|
frontendNpmProd.dependsOn(frontendNpmReInstall) |
|
|
frontendNpmProd.dependsOn(frontendNpmReInstall) |
|
|
|
|
|
|
|
@ -736,10 +723,8 @@ subprojects { |
|
|
frontendGenerateMenus.dependsOn(frontendGenerateI18n); |
|
|
frontendGenerateMenus.dependsOn(frontendGenerateI18n); |
|
|
frontendGenerateRoutes.dependsOn(frontendGenerateMenus); |
|
|
frontendGenerateRoutes.dependsOn(frontendGenerateMenus); |
|
|
frontendModule.dependsOn(frontendGenerateRoutes); |
|
|
frontendModule.dependsOn(frontendGenerateRoutes); |
|
|
gzipFrontend.dependsOn(frontendModule); |
|
|
frontend.dependsOn(frontendModule); |
|
|
frontend.dependsOn(gzipFrontend); |
|
|
|
|
|
|
|
|
|
|
|
//tasks.preBuild.dependsOn(frontend); |
|
|
|
|
|
processResources.dependsOn(frontend) |
|
|
processResources.dependsOn(frontend) |
|
|
|
|
|
|
|
|
processResources { |
|
|
processResources { |
|
@ -765,16 +750,6 @@ subprojects { |
|
|
excludeDirs += file('dist') |
|
|
excludeDirs += file('dist') |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
clean { |
|
|
|
|
|
doFirst{ |
|
|
|
|
|
if(isFrontendProject(file('.'))) { |
|
|
|
|
|
delete 'dist' |
|
|
|
|
|
delete 'node_modules' |
|
|
|
|
|
delete 'pnpm-lock.yaml' |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/*********************************************************************** |
|
|
/*********************************************************************** |
|
|