build: Add build process for newgui (#7351)

This commit is contained in:
Jakob Borg 2021-02-10 14:29:17 +01:00
parent d117b4b570
commit b2c9e7b07b
123 changed files with 38050 additions and 17178 deletions

1
.gitignore vendored
View File

@ -18,3 +18,4 @@ deb
*.bz2 *.bz2
/repos /repos
/proto/scripts/protoc-gen-gosyncthing /proto/scripts/protoc-gen-gosyncthing
/gui/next-gen-gui

View File

@ -34,23 +34,24 @@ import (
) )
var ( var (
goarch string goarch string
goos string goos string
noupgrade bool noupgrade bool
version string version string
goCmd string goCmd string
race bool race bool
debug = os.Getenv("BUILDDEBUG") != "" debug = os.Getenv("BUILDDEBUG") != ""
extraTags string extraTags string
installSuffix string installSuffix string
pkgdir string pkgdir string
cc string cc string
run string run string
benchRun string benchRun string
debugBinary bool debugBinary bool
coverage bool coverage bool
timeout = "120s" timeout = "120s"
numVersions = 5 numVersions = 5
withNextGenGUI = os.Getenv("BUILD_NEXT_GEN_GUI") != ""
) )
type target struct { type target struct {
@ -372,6 +373,7 @@ func parseFlags() {
flag.IntVar(&numVersions, "num-versions", numVersions, "Number of versions for changelog command") flag.IntVar(&numVersions, "num-versions", numVersions, "Number of versions for changelog command")
flag.StringVar(&run, "run", "", "Specify which tests to run") flag.StringVar(&run, "run", "", "Specify which tests to run")
flag.StringVar(&benchRun, "bench", "", "Specify which benchmarks to run") flag.StringVar(&benchRun, "bench", "", "Specify which benchmarks to run")
flag.BoolVar(&withNextGenGUI, "with-next-gen-gui", withNextGenGUI, "Also build 'newgui'")
flag.Parse() flag.Parse()
} }
@ -438,6 +440,10 @@ func benchArgs() []string {
} }
func install(target target, tags []string) { func install(target target, tags []string) {
if (target.name == "syncthing" || target.name == "") && !withNextGenGUI {
log.Println("Notice: Next generation GUI will not be built; see --with-next-gen-gui.")
}
lazyRebuildAssets() lazyRebuildAssets()
tags = append(target.tags, tags...) tags = append(target.tags, tags...)
@ -467,6 +473,10 @@ func install(target target, tags []string) {
} }
func build(target target, tags []string) { func build(target target, tags []string) {
if (target.name == "syncthing" || target.name == "") && !withNextGenGUI {
log.Println("Notice: Next generation GUI will not be built; see --with-next-gen-gui.")
}
lazyRebuildAssets() lazyRebuildAssets()
tags = append(target.tags, tags...) tags = append(target.tags, tags...)
@ -764,11 +774,46 @@ func rebuildAssets() {
} }
func lazyRebuildAssets() { func lazyRebuildAssets() {
if shouldRebuildAssets("lib/api/auto/gui.files.go", "gui") || shouldRebuildAssets("cmd/strelaypoolsrv/auto/gui.files.go", "cmd/strelaypoolsrv/gui") { shouldRebuild := shouldRebuildAssets("lib/api/auto/gui.files.go", "gui") ||
shouldRebuildAssets("cmd/strelaypoolsrv/auto/gui.files.go", "cmd/strelaypoolsrv/gui")
if withNextGenGUI {
shouldRebuild = buildNextGenGUI() || shouldRebuild
}
if shouldRebuild {
rebuildAssets() rebuildAssets()
} }
} }
func buildNextGenGUI() bool {
// Check if we need to run the npm process, and if so also set the flag
// to rebuild Go assets afterwards. The index.html is regenerated every
// time by the build process. This assumes the new GUI ends up in
// next-gen-gui/dist/next-gen-gui.
if !shouldRebuildAssets("gui/next-gen-gui/index.html", "next-gen-gui") {
// The GUI is up to date.
return false
}
runPrintInDir("next-gen-gui", "npm", "install")
runPrintInDir("next-gen-gui", "npm", "run", "build", "--", "--prod", "--subresource-integrity")
rmr("gui/tech-ui")
for _, src := range listFiles("next-gen-gui/dist") {
rel, _ := filepath.Rel("next-gen-gui/dist", src)
dst := filepath.Join("gui", rel)
if err := copyFile(src, dst, 0644); err != nil {
fmt.Println("copy:", err)
os.Exit(1)
}
}
return true
}
func shouldRebuildAssets(target, srcdir string) bool { func shouldRebuildAssets(target, srcdir string) bool {
info, err := os.Stat(target) info, err := os.Stat(target)
if err != nil { if err != nil {

17151
newgui/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -3,7 +3,7 @@
"version": 1, "version": 1,
"newProjectRoot": "projects", "newProjectRoot": "projects",
"projects": { "projects": {
"tech-ui": { "next-gen-gui": {
"projectType": "application", "projectType": "application",
"schematics": { "schematics": {
"@schematics/angular:component": { "@schematics/angular:component": {
@ -17,7 +17,7 @@
"build": { "build": {
"builder": "@angular-devkit/build-angular:browser", "builder": "@angular-devkit/build-angular:browser",
"options": { "options": {
"outputPath": "dist/tech-ui", "outputPath": "dist/next-gen-gui",
"index": "src/index.html", "index": "src/index.html",
"main": "src/main.ts", "main": "src/main.ts",
"polyfills": "src/polyfills.ts", "polyfills": "src/polyfills.ts",
@ -66,18 +66,18 @@
"serve": { "serve": {
"builder": "@angular-devkit/build-angular:dev-server", "builder": "@angular-devkit/build-angular:dev-server",
"options": { "options": {
"browserTarget": "tech-ui:build" "browserTarget": "next-gen-gui:build"
}, },
"configurations": { "configurations": {
"production": { "production": {
"browserTarget": "tech-ui:build:production" "browserTarget": "next-gen-gui:build:production"
} }
} }
}, },
"extract-i18n": { "extract-i18n": {
"builder": "@angular-devkit/build-angular:extract-i18n", "builder": "@angular-devkit/build-angular:extract-i18n",
"options": { "options": {
"browserTarget": "tech-ui:build" "browserTarget": "next-gen-gui:build"
} }
}, },
"test": { "test": {
@ -114,15 +114,15 @@
"builder": "@angular-devkit/build-angular:protractor", "builder": "@angular-devkit/build-angular:protractor",
"options": { "options": {
"protractorConfig": "e2e/protractor.conf.js", "protractorConfig": "e2e/protractor.conf.js",
"devServerTarget": "tech-ui:serve" "devServerTarget": "next-gen-gui:serve"
}, },
"configurations": { "configurations": {
"production": { "production": {
"devServerTarget": "tech-ui:serve:production" "devServerTarget": "next-gen-gui:serve:production"
} }
} }
} }
} }
}}, }},
"defaultProject": "tech-ui" "defaultProject": "next-gen-gui"
} }

37977
next-gen-gui/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,5 @@
{ {
"name": "tech-ui", "name": "next-gen-gui",
"version": "1.0.0", "version": "1.0.0",
"scripts": { "scripts": {
"ng": "ng", "ng": "ng",

View File

Before

Width:  |  Height:  |  Size: 734 KiB

After

Width:  |  Height:  |  Size: 734 KiB

Some files were not shown because too many files have changed in this diff Show More