Skip to content

Commit 28a6b99

Browse files
author
Dave Syer
committed
Tweak scripts to run from main dir
1 parent ed141e3 commit 28a6b99

File tree

5 files changed

+93
-68
lines changed

5 files changed

+93
-68
lines changed

README.md

Lines changed: 89 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,49 @@
1+
## Install npm Locally
2+
3+
```
4+
<build>
5+
<plugins>
6+
<plugin>
7+
<groupId>org.springframework.boot</groupId>
8+
<artifactId>spring-boot-maven-plugin</artifactId>
9+
</plugin>
10+
<plugin>
11+
<groupId>com.github.eirslett</groupId>
12+
<artifactId>frontend-maven-plugin</artifactId>
13+
<version>1.6</version>
14+
<configuration>
15+
<nodeVersion>v8.8.1</nodeVersion>
16+
</configuration>
17+
<executions>
18+
<execution>
19+
<id>install-npm</id>
20+
<goals>
21+
<goal>install-node-and-npm</goal>
22+
</goals>
23+
</execution>
24+
</executions>
25+
</plugin>
26+
<plugin>
27+
<groupId>org.springframework.boot</groupId>
28+
<artifactId>spring-boot-maven-plugin</artifactId>
29+
</plugin>
30+
</plugins>
31+
</build>
32+
```
33+
34+
then
35+
136
```
2-
<build>
3-
<plugins>
4-
<plugin>
5-
<groupId>org.springframework.boot</groupId>
6-
<artifactId>spring-boot-maven-plugin</artifactId>
7-
</plugin>
8-
<plugin>
9-
<groupId>com.github.eirslett</groupId>
10-
<artifactId>frontend-maven-plugin</artifactId>
11-
<version>1.6</version>
12-
<configuration>
13-
<nodeVersion>v8.8.1</nodeVersion>
14-
</configuration>
15-
<executions>
16-
<execution>
17-
<id>install-npm</id>
18-
<goals>
19-
<goal>install-node-and-npm</goal>
20-
</goals>
21-
</execution>
22-
</executions>
23-
</plugin>
24-
<plugin>
25-
<groupId>org.springframework.boot</groupId>
26-
<artifactId>spring-boot-maven-plugin</artifactId>
27-
</plugin>
28-
</plugins>
29-
</build>
37+
$ mvn generate-resources
38+
$ ls node*
3039
```
3140

41+
## Install Angular CLI
42+
3243
```
33-
$ mvn generate-resources
3444
$ cat > npm
3545
#!/bin/sh
46+
cd $(dirname $0)
3647
PATH="$PWD/node/":$PATH
3748
node "node/node_modules/npm/bin/npm-cli.js" "$@"
3849
$ chmod +x npm
@@ -44,22 +55,25 @@ and run `mvn generate-resources` again.
4455
```
4556
$ cat > ng
4657
#!/bin/sh
58+
cd $(dirname $0)
4759
PATH="$PWD/node/":$PATH
4860
node_modules/@angular/cli/bin/ng "$@"
4961
$ chmod +x ng
5062
$ ./ng --version
51-
_ _ ____ _ ___
63+
_ _ ____ _ ___
5264
/ \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|
5365
/ △ \ | '_ \ / _` | | | | |/ _` | '__| | | | | | |
5466
/ ___ \| | | | (_| | |_| | | (_| | | | |___| |___ | |
5567
/_/ \_\_| |_|\__, |\__,_|_|\__,_|_| \____|_____|___|
56-
|___/
68+
|___/
5769
@angular/cli: 1.4.9
5870
node: 8.8.1
5971
os: linux x64
6072
```
6173

62-
Now create an angular app:
74+
## Create an Angular App
75+
76+
Create the app with the CLI and move it to `src/main`:
6377

6478
```
6579
$ ./ng new client
@@ -69,38 +83,40 @@ $ sed -i -e 's,dist,../../../target/classes/static,' src/main/client/.angular-cl
6983
$ mv ng npm src/main/client
7084
```
7185

86+
## Building
87+
7288
Add
7389

7490
```
75-
<configuration>
76-
<workingDirectory>src/main/client</workingDirectory>
77-
</configuration>
91+
<configuration>
92+
<workingDirectory>src/main/client</workingDirectory>
93+
</configuration>
7894
```
7995

8096
and
8197

8298
```
83-
<execution>
84-
<id>npm-install</id>
85-
<goals>
86-
<goal>npm</goal>
87-
</goals>
88-
<configuration>
89-
<arguments>install</arguments>
90-
</configuration>
91-
</execution>
99+
<execution>
100+
<id>npm-install</id>
101+
<goals>
102+
<goal>npm</goal>
103+
</goals>
104+
<configuration>
105+
<arguments>install</arguments>
106+
</configuration>
107+
</execution>
92108
```
93109

94110
Install the modules again using `mvn generate-resources`.
95111

96112
```
97-
$ (cd src/main/client; ./ng version)
98-
_ _ ____ _ ___
113+
$ src/main/client/ng version
114+
_ _ ____ _ ___
99115
/ \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|
100116
/ △ \ | '_ \ / _` | | | | |/ _` | '__| | | | | | |
101117
/ ___ \| | | | (_| | |_| | | (_| | | | |___| |___ | |
102118
/_/ \_\_| |_|\__, |\__,_|_|\__,_|_| \____|_____|___|
103-
|___/
119+
|___/
104120
@angular/cli: 1.4.9
105121
node: 8.8.1
106122
os: linux x64
@@ -122,13 +138,13 @@ typescript: 2.3.4
122138
And the tests work:
123139

124140
```
125-
$ (cd src/main/client; ./ng e2e.)
141+
$ src/main/client/ng e2e
126142
..
127143
[13:59:46] I/direct - Using ChromeDriver directly...
128144
Jasmine started
129145
130146
client App
131-
✓ should display welcome message
147+
✓ should display welcome message
132148
133149
Executed 1 of 1 spec SUCCESS in 0.718 sec.
134150
[13:59:48] I/launcher - 0 instance(s) of WebDriver still running
@@ -138,36 +154,44 @@ Executed 1 of 1 spec SUCCESS in 0.718 sec.
138154
Add
139155

140156
```
141-
<execution>
142-
<id>npm-build</id>
143-
<goals>
144-
<goal>npm</goal>
145-
</goals>
146-
<configuration>
147-
<arguments>run-script build</arguments>
148-
</configuration>
149-
</execution>
150-
157+
<execution>
158+
<id>npm-build</id>
159+
<goals>
160+
<goal>npm</goal>
161+
</goals>
162+
<configuration>
163+
<arguments>run-script build</arguments>
164+
</configuration>
165+
</execution>
151166
```
152167

153168
and then the client app will be compiled during the Maven build.
154169

170+
You can build continuously with
171+
172+
```
173+
$ src/main/client/ng build --watch
174+
```
175+
176+
Updates are built (quickly) and pushed to `target/classes` where they can be picked up by Spring Boot.
177+
178+
## Adding Bootstrap
179+
155180
https://medium.com/codingthesmartway-com-blog/using-bootstrap-with-angular-c83c3cee3f4a
156181

157182
```
158-
$ cd src/main/client
159-
$ ./npm install bootstrap@3 jquery --save
183+
$ src/main/client/npm install bootstrap@3 jquery --save
160184
```
161185

162186
and update `.angular-cli.json` to add the new content:
163187

164188
```
165189
"styles": [
166-
"styles.css",
167-
"../node_modules/bootstrap/dist/css/bootstrap.min.css"
190+
"styles.css",
191+
"../node_modules/bootstrap/dist/css/bootstrap.min.css"
168192
],
169193
"scripts": [
170-
"../node_modules/jquery/dist/jquery.min.js",
171-
"../node_modules/bootstrap/dist/js/bootstrap.min.js"
194+
"../node_modules/jquery/dist/jquery.min.js",
195+
"../node_modules/bootstrap/dist/js/bootstrap.min.js"
172196
],
173197
```

pom.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,5 +81,4 @@
8181
</plugins>
8282
</build>
8383

84-
8584
</project>

src/main/client/ng

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
#!/bin/sh
2+
cd $(dirname $0)
23
PATH="$PWD/node/":$PATH
3-
node_modules/@angular/cli/bin/ng "$@"
4+
./node_modules/@angular/cli/bin/ng "$@"

src/main/client/npm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
#!/bin/sh
2+
cd $(dirname $0)
23
PATH="$PWD/node/":$PATH
34
node "node/node_modules/npm/bin/npm-cli.js" "$@"

src/main/client/src/app/app.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ <h1>
44
Welcome {{title}}!
55
</h1>
66
<div class="container">
7-
<p>ID: <span>{{data.id}}</span></p>
7+
<p>Id: <span>{{data.id}}</span></p>
88
<p>Message: <span>{{data.content}}</span></p>
99
</div>
1010
</div>

0 commit comments

Comments
 (0)