Skip to content

Commit 9598550

Browse files
committed
Clean up
1 parent 2bb47b8 commit 9598550

File tree

15 files changed

+133
-109
lines changed

15 files changed

+133
-109
lines changed

backend/build.gradle

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
buildscript {
22
ext {
33
springBootVersion = '2.0.0.M4'
4-
gradleNodeVersion = '1.2.0'
54
}
65

76
repositories {
87
mavenCentral()
9-
maven { url "https://repo.spring.io/snapshot" }
108
maven { url "https://repo.spring.io/milestone" }
11-
maven { url "https://plugins.gradle.org/m2/" }
129
}
1310

1411
dependencies {
@@ -17,36 +14,56 @@ buildscript {
1714
}
1815

1916

20-
apply plugin: 'org.springframework.boot'
17+
18+
//------------------------------------------------------------------------------------------------------------------------
19+
// Plugins - Application
20+
//------------------------------------------------------------------------------------------------------------------------
21+
2122
apply plugin: 'io.spring.dependency-management'
23+
apply plugin: 'org.springframework.boot'
2224
apply plugin: 'java'
25+
apply plugin: 'war'
2326

27+
//------------------------------------------------------------------------------------------------------------------------
28+
// Plugins - Configuration
29+
//------------------------------------------------------------------------------------------------------------------------
2430

2531
sourceCompatibility = 1.8
2632
targetCompatibility = 1.8
2733

34+
war {
35+
baseName = 'spring5_angular4_demo'
36+
version = '1.0'
37+
manifest {
38+
attributes 'Main-Class': 'angularboot.AngularBootApplication'
39+
}
40+
}
41+
2842

29-
//idea {
30-
// module {
31-
// inheritOutputDirs = false
32-
// outputDir = file("${buildDir}/classes/main/")
33-
// }
34-
//}
3543

44+
//------------------------------------------------------------------------------------------------------------------------
45+
// Tasks - Standalone backend
46+
//------------------------------------------------------------------------------------------------------------------------
3647

3748
task bootStandaloneBackend {
3849
group 'application'
3950
dependsOn bootRun
4051
}
4152

42-
jar.dependsOn(':client:buildClient')
53+
jar.dependsOn ':client:buildClientToSpring'
54+
war.dependsOn ':client:buildClientToSpring'
55+
4356

4457

58+
//------------------------------------------------------------------------------------------------------------------------
59+
// Dependencies
60+
//------------------------------------------------------------------------------------------------------------------------
61+
4562
dependencies {
4663
compile 'org.springframework.boot:spring-boot-starter-data-neo4j'
4764
compile 'org.springframework.boot:spring-boot-starter-web'
4865

4966
compileOnly 'org.projectlombok:lombok'
5067

5168
testCompile 'org.springframework.boot:spring-boot-starter-test'
52-
}
69+
}

backend/src/main/java/angularboot/AngularBootApplication.java

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package angularboot;
22

3+
import angularboot.domain.Greeting;
4+
import angularboot.domain.Hero;
35
import org.springframework.boot.SpringApplication;
46
import org.springframework.boot.autoconfigure.SpringBootApplication;
57
import org.springframework.web.bind.annotation.RequestMapping;
@@ -11,22 +13,35 @@
1113
import java.util.UUID;
1214
import java.util.stream.Collectors;
1315

14-
@SpringBootApplication
1516
@RestController
1617
@RequestMapping("api")
18+
@SpringBootApplication
1719
public class AngularBootApplication {
18-
public static void main(String[] args) {
19-
SpringApplication.run(AngularBootApplication.class, args);
20-
}
2120

22-
public static final List<Hero> HEROES;
21+
private static final List<Hero> HEROES;
2322

2423
static {
2524
Random r = new Random();
26-
final String[] NAMES = {"Mr. Nice", "Narco", "Bombasto", "Celeritas", "Magneta", "RubberMan", "Dynama",
27-
"Dr IQ", "Magma", "Tornado"};
28-
HEROES = Arrays.stream(NAMES).map(name -> new Hero(r.ints(0,20).findFirst()
29-
.getAsInt(), name)).collect(Collectors.toList());
25+
26+
final String[] NAMES = {
27+
"Mr. Nice",
28+
"Narco",
29+
"Bombasto",
30+
"Celeritas",
31+
"Magneta",
32+
"RubberMan",
33+
"Dynama",
34+
"Dr IQ",
35+
"Magma",
36+
"Tornado"};
37+
38+
HEROES = Arrays.stream(NAMES)
39+
.map(name -> new Hero(r.ints(0,20).findFirst().orElse(0), name))
40+
.collect(Collectors.toList());
41+
}
42+
43+
public static void main(String[] args) {
44+
SpringApplication.run(AngularBootApplication.class, args);
3045
}
3146

3247
@RequestMapping("/resource")

backend/src/main/java/angularboot/Greeting.java renamed to backend/src/main/java/angularboot/domain/Greeting.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package angularboot;
1+
package angularboot.domain;
22

33
public class Greeting {
44
String id;

backend/src/main/java/angularboot/Hero.java renamed to backend/src/main/java/angularboot/domain/Hero.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package angularboot;
1+
package angularboot.domain;
22

33
public class Hero {
44
int id;

build.gradle

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ group = 'com.dmitrijdrandarov'
22
version = '0.0.1-SNAPSHOT'
33

44

5+
56
allprojects {
67
repositories {
78
mavenCentral()
@@ -11,26 +12,22 @@ allprojects {
1112
}
1213

1314

15+
1416
//------------------------------------------------------------------------------------------------------------------------
15-
// Whole application
17+
// Tasks - Application
1618
//------------------------------------------------------------------------------------------------------------------------
1719

18-
task bootApplication(type: GradleBuild) {
19-
group = 'application'
20-
tasks = [':client:clean', ':client:buildClientDev', ':backend:bootRun']
20+
task bootFullApplication(type: GradleBuild) {
21+
group 'application'
22+
setTasks([':client:npmUpdate', ':client:clean', ':client:buildClientToSpring', ':backend:bootRun'])
2123
}
2224

23-
task clean {
24-
group = 'build'
25-
}
26-
27-
2825
//------------------------------------------------------------------------------------------------------------------------
29-
// Init
26+
// Tasks - Init project
3027
//------------------------------------------------------------------------------------------------------------------------
3128

3229
task wrapper(type: Wrapper) {
33-
group = 'init'
34-
gradleVersion = '4.1'
35-
distributionType = 'ALL'
30+
group 'init'
31+
gradleVersion '4.2'
32+
distributionType Wrapper.DistributionType.ALL
3633
}

client/.angular-cli.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"apps": [
77
{
88
"root": "src",
9-
"outDir": "../backend/src/main/resources/static",
9+
"outDir": "dist",
1010
"assets": [
1111
"assets",
1212
"favicon.ico"

client/.editorconfig

Lines changed: 0 additions & 17 deletions
This file was deleted.

client/build.gradle

Lines changed: 41 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ buildscript {
55

66
repositories {
77
mavenCentral()
8-
maven { url "https://repo.spring.io/snapshot" }
9-
maven { url "https://repo.spring.io/milestone" }
108
maven { url "https://plugins.gradle.org/m2/" }
119
}
1210

@@ -17,11 +15,14 @@ buildscript {
1715

1816

1917

20-
apply plugin: 'com.moowork.node'
18+
//------------------------------------------------------------------------------------------------------------------------
19+
// Plugins - Application
20+
//------------------------------------------------------------------------------------------------------------------------
2121

22+
apply plugin: 'com.moowork.node'
2223

2324
//------------------------------------------------------------------------------------------------------------------------
24-
// NodeJS Setup
25+
// Plugin configuration
2526
//------------------------------------------------------------------------------------------------------------------------
2627

2728
node {
@@ -33,60 +34,67 @@ node {
3334
}
3435

3536

37+
3638
//------------------------------------------------------------------------------------------------------------------------
37-
// Clean tasks
39+
// Tasks - NPM
3840
//------------------------------------------------------------------------------------------------------------------------
3941

40-
task clean() {
42+
task clean(type: Delete) {
4143
group 'build client'
42-
dependsOn 'cleanDist'
43-
}
44-
45-
task cleanDist(type: Delete) {
46-
group = 'build client'
4744
delete "${rootDir}/client/dist", "${rootDir}/backend/src/main/resources/static"
4845
}
4946

5047
task cleanNpm(type: Delete) {
51-
group = 'build client'
48+
group 'build client'
49+
dependsOn 'clean'
5250
delete "${rootDir}/client/node", "${rootDir}/client/node_modules"
5351
}
5452

53+
task npmUpdate {
54+
group 'build client'
55+
dependsOn 'npm_update'
56+
}
5557

5658
//------------------------------------------------------------------------------------------------------------------------
57-
// Prod tasks
59+
// Tasks - Standalone client
5860
//------------------------------------------------------------------------------------------------------------------------
5961

60-
task serveClient(type: NpmTask, dependsOn: npmInstall) {
61-
group = 'build client'
62-
description = "Compile client side folder for production"
63-
args = ['start']
62+
task buildStandaloneClient(type: NpmTask, dependsOn: npmInstall) {
63+
group 'build client'
64+
description = 'Compile client side folder for development'
65+
args = ['run', 'buildStandalone']
6466
}
6567

66-
task buildClient(type: NpmTask, dependsOn: npmInstall) {
67-
group = 'build client'
68-
description = 'Compile client side folder for development'
69-
args = ['run', 'build']
68+
task buildStandaloneClientWatch(type: NpmTask, dependsOn: npmInstall) {
69+
group 'build client'
70+
description = "Build and watches the client side assets for rebuilding"
71+
args = ['run', 'buildStandaloneWatch']
72+
}
73+
74+
task serveStandaloneClient(type: NpmTask, dependsOn: npmInstall) {
75+
group 'build client'
76+
description = "Compile client side folder for production"
77+
args = ['start']
7078
}
7179

7280
task bootStandaloneClient(type: GradleBuild) {
73-
group = 'application'
74-
tasks = [clean, buildClient, serveClient]
81+
group 'application'
82+
setTasks(['clean', 'buildStandaloneClient', 'serveStandaloneClient'])
83+
// finalizedBy 'npm_shutdown'
7584
}
7685

86+
task bootStandaloneClientWatch(type: GradleBuild) {
87+
group 'application'
88+
setTasks(['clean', 'buildStandaloneClientWatch', 'serveStandaloneClient'])
89+
// finalizedBy 'npm_shutdown'
90+
}
7791

7892
//------------------------------------------------------------------------------------------------------------------------
79-
// Dev tasks
93+
// Tasks - Integrated client
8094
//------------------------------------------------------------------------------------------------------------------------
8195

82-
task buildClientDev(type: NpmTask, dependsOn: npmInstall) {
83-
group = 'build client'
96+
task buildClientToSpring(type: NpmTask, dependsOn: npmInstall) {
97+
group 'build client'
8498
description = 'Compile client side folder for development'
85-
args = ['run', 'buildDev']
86-
}
87-
88-
task buildClientDevWatch(type: NpmTask, dependsOn: npmInstall) {
89-
group = 'build client'
90-
description = "Build and watches the client side assets for rebuilding"
91-
args = ['run', 'buildWatch']
99+
args = ['run', 'buildToSpring']
92100
}

client/package.json

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,28 @@
55
"scripts": {
66
"ng": "ng",
77
"start": "ng serve --proxy-config proxy-dev.json",
8-
"build": "ng build --op=dist --prod",
9-
"buildDev": "ng build",
10-
"buildDevWatch": "ng build --watch=true",
8+
"buildProd": "ng build --prod",
9+
"buildStandalone": "ng build",
10+
"buildStandaloneWatch": "ng build --watch=true",
11+
"buildToSpring": "ng build --op=../backend/src/main/resources/static",
1112
"test": "ng test",
1213
"lint": "ng lint",
1314
"e2e": "ng e2e"
1415
},
1516
"private": true,
1617
"dependencies": {
17-
"@angular/animations": "^4.2.4",
18-
"@angular/common": "^4.2.4",
19-
"@angular/compiler": "^4.2.4",
20-
"@angular/core": "^4.2.4",
21-
"@angular/forms": "^4.2.4",
22-
"@angular/http": "^4.2.4",
23-
"@angular/platform-browser": "^4.2.4",
24-
"@angular/platform-browser-dynamic": "^4.2.4",
25-
"@angular/router": "^4.2.4",
26-
"core-js": "^2.4.1",
27-
"rxjs": "^5.4.2",
28-
"zone.js": "^0.8.14"
18+
"@angular/animations": "^4.4.3",
19+
"@angular/common": "^4.4.3",
20+
"@angular/compiler": "^4.4.3",
21+
"@angular/core": "^4.4.3",
22+
"@angular/forms": "^4.4.3",
23+
"@angular/http": "^4.4.3",
24+
"@angular/platform-browser": "^4.4.3",
25+
"@angular/platform-browser-dynamic": "^4.4.3",
26+
"@angular/router": "^4.4.3",
27+
"core-js": "^2.5.1",
28+
"rxjs": "^5.4.3",
29+
"zone.js": "^0.8.17"
2930
},
3031
"devDependencies": {
3132
"@angular/cli": "1.4.2",

client/proxy-dev.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
2-
"/api": {
3-
"target": "http://localhost:8080"
2+
"/api/*": {
3+
"target": "http://localhost:8080",
4+
"secure": false
45
}
5-
}
6+
}

0 commit comments

Comments
 (0)