Skip to content
This repository was archived by the owner on Mar 3, 2026. It is now read-only.

Commit 155237f

Browse files
committed
frontend module fix jooby-project#844
1 parent b88a206 commit 155237f

File tree

11 files changed

+1949
-0
lines changed

11 files changed

+1949
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ bin
2121
pom.xml.versionsBackup
2222
jacoco.exec
2323
.*.md.html
24+
node

doc/doc/frontend/frontend.md

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# frontend
2+
3+
Download and install <a href="https://nodejs.org">node.js</a>, install <a href="https://www.npmjs.com">npm</a>, <a href="https://yarnpkg.com">yarn</a> and
4+
runs <a href="https://www.npmjs.com">npm</a>, <a href="https://webpack.js.org">webpack</a>, <a href="https://gulpjs.com">gulp</a>, <a href="https://gruntjs.com">grunt</a> and more.
5+
6+
## dependency
7+
8+
```xml
9+
<dependency>
10+
<groupId>org.jooby</groupId>
11+
<artifactId>jooby-frontend</artifactId>
12+
<version>{{version}}</version>
13+
</dependency>
14+
```
15+
16+
## usage
17+
18+
Using <a href="https://www.npmjs.com">npm</a>:
19+
20+
```java
21+
{
22+
on("dev", () -> {
23+
use(new Npm("v8.6.0"));
24+
});
25+
26+
}
27+
```
28+
29+
Using <a href="https://yarnpkg.com">yarn</a>:
30+
31+
```java
32+
{
33+
on("dev", () -> {
34+
use(new Yarn("v8.6.0", "v1.1.0"));
35+
});
36+
37+
}
38+
```
39+
40+
> **NOTE**: The module must be used in development only. That's why we wrap the module installation using the environment predicate. In order to build a production version, you need to configure a build time process. The <a href="https://github.com/eirslett/frontend-maven-plugin">frontend</a> maven plugin does this job for maven projects. If you are a Gradle user, you might want to try the <a href="https://github.com/srs/gradle-node-plugin">gradle-node-plugin</a>.
41+
42+
## install phase
43+
44+
The module automatically sync and install dependencies at startup time.
45+
46+
## default task
47+
48+
The module runs ```npm run build``` or ```yarn run build``` at startup time (after install phase).
49+
50+
This mean your ```package.json``` must defines a ```build``` script, like:
51+
52+
```json
53+
{
54+
"scripts": {
55+
"build": "webpack"
56+
}
57+
}
58+
```
59+
60+
The default task is always executed, unless you define one or more custom tasks (see next).
61+
62+
## custom task
63+
64+
Execution of arbitrary scripts is available via [npm.onStart]({{defdocs}}/frontend/Frontend.html#onStart-org.jooby.funzy.Throwing.Consumer-) and [npm.onStarted]({{defdocs}}/frontend/Frontend.html#onStarted-org.jooby.funzy.Throwing.Consumer-).
65+
66+
The next example executes two scripts:
67+
68+
```java
69+
{
70+
use(new Npm("v8.6.0"))
71+
.onStart(npm -> {
72+
npm.executeSync("run", "local");
73+
npm.executeSync("run", "next");
74+
});
75+
);
76+
}
77+
```
78+
79+
The next example executes a script without waiting to finish (useful for background tasks):
80+
81+
```java
82+
{
83+
use(new Npm("v8.6.0"))
84+
.onStart(npm -> {
85+
npm.execute("run", "webserver");
86+
});
87+
);
88+
89+
}
90+
```
91+

modules/jooby-frontend/pom.xml

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
4+
5+
<parent>
6+
<groupId>org.jooby</groupId>
7+
<artifactId>modules</artifactId>
8+
<version>1.2.0-SNAPSHOT</version>
9+
</parent>
10+
11+
<modelVersion>4.0.0</modelVersion>
12+
<artifactId>jooby-frontend</artifactId>
13+
14+
<name>frontend module</name>
15+
16+
<build>
17+
<plugins>
18+
<!-- sure-fire -->
19+
<plugin>
20+
<groupId>org.apache.maven.plugins</groupId>
21+
<artifactId>maven-surefire-plugin</artifactId>
22+
<configuration>
23+
<includes>
24+
<include>**/*Test.java</include>
25+
<include>**/*Feature.java</include>
26+
<include>**/Issue*.java</include>
27+
</includes>
28+
</configuration>
29+
</plugin>
30+
31+
</plugins>
32+
</build>
33+
34+
<dependencies>
35+
<!-- Jooby -->
36+
<dependency>
37+
<groupId>org.jooby</groupId>
38+
<artifactId>jooby</artifactId>
39+
<version>${project.version}</version>
40+
</dependency>
41+
42+
<dependency>
43+
<groupId>com.github.eirslett</groupId>
44+
<artifactId>frontend-plugin-core</artifactId>
45+
<version>1.6</version>
46+
</dependency>
47+
48+
<!-- Test dependencies -->
49+
<dependency>
50+
<groupId>org.jooby</groupId>
51+
<artifactId>jooby</artifactId>
52+
<version>${project.version}</version>
53+
<scope>test</scope>
54+
<classifier>tests</classifier>
55+
</dependency>
56+
57+
<dependency>
58+
<groupId>junit</groupId>
59+
<artifactId>junit</artifactId>
60+
<scope>test</scope>
61+
</dependency>
62+
63+
<dependency>
64+
<groupId>org.easymock</groupId>
65+
<artifactId>easymock</artifactId>
66+
<scope>test</scope>
67+
</dependency>
68+
69+
<dependency>
70+
<groupId>org.powermock</groupId>
71+
<artifactId>powermock-api-easymock</artifactId>
72+
<scope>test</scope>
73+
</dependency>
74+
75+
<dependency>
76+
<groupId>org.powermock</groupId>
77+
<artifactId>powermock-module-junit4</artifactId>
78+
<scope>test</scope>
79+
</dependency>
80+
81+
<dependency>
82+
<groupId>org.jacoco</groupId>
83+
<artifactId>org.jacoco.agent</artifactId>
84+
<classifier>runtime</classifier>
85+
<scope>test</scope>
86+
</dependency>
87+
88+
</dependencies>
89+
90+
</project>

0 commit comments

Comments
 (0)