Skip to content

Commit

Permalink
Merge pull request jenkinsci#4425 from fqueiruga/replace-jsbuilder-wi…
Browse files Browse the repository at this point in the history
…th-webpack

[JENKINS-60734] Replace jsbuilder with webpack
  • Loading branch information
batmat authored Jan 23, 2020
2 parents 99b822e + 60a0816 commit b4ef17d
Show file tree
Hide file tree
Showing 87 changed files with 7,997 additions and 2,177 deletions.
23 changes: 23 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ This page provides information about contributing code to the Jenkins core codeb
If you hit a new issue, please report it with a `java11-devtools-compatibility` label in our issue tracker.
* Maven 3.5.4 or above. You can [download maven].
* Any IDE which supports importing Maven projects.
* Install [NodeJS](https://nodejs.org/en/). **Note:** only needed to work on the frontend assets found on the `war` module.
* Frontend tasks are ran using [yarn](https://yarnpkg.com/lang/en/). Run `npm install -g yarn` to install it.
4. Setup your development environment as described in [Preparing for Plugin Development]

If you want to contribute to Jenkins or just learn about the project,
Expand Down Expand Up @@ -49,6 +51,20 @@ mvn -pl war jetty:run

(Beware that `maven-plugin` builds will not work in this mode due to class loading conflicts.)

### Building frontend assets

To work on the `war` module frontend assets two processes are needed at the same time:

On one terminal, start a development server that will not process frontend assets:
```sh
mvn -pl war jetty:run -Dskip.yarn
```

On another terminal, move to the war folder and start a [webpack](https://webpack.js.org/) dev server:
```sh
cd war; yarn start
```

## Testing changes

Jenkins core includes unit and functional tests as a part of the repository.
Expand All @@ -67,6 +83,13 @@ In addition to the included tests, you can also find extra integration and UI
tests in the [Acceptance Test Harness (ATH)] repository.
If you propose complex UI changes, you should create new ATH tests for them.

### JavaScript unit tests

In case there's only need to run the JS tests:
```sh
cd war; yarn test
```

## Proposing Changes

The Jenkins project source code repositories are hosted at GitHub.
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/resources/lib/layout/html.jelly
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ THE SOFTWARE.
<script src="${resURL}/scripts/msie.js" type="text/javascript"/>
</j:if>

<!-- The vendors bundle is generated by webpack. It contains vendor scripts common to all JS modules -->
<script src="${resURL}/jsbundles/vendors.js" type="text/javascript"/>
</head>
<body id="jenkins" class="yui-skin-sam jenkins-${h.version}" data-version="${h.version}" data-model-type="${it.class.name}">
<div id="main-panel" style="margin-left: 0;">
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/resources/lib/layout/layout.jelly
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ THE SOFTWARE.
<script src="${resURL}/scripts/msie.js" type="text/javascript"/>
</j:if>

<!-- The vendors bundle is generated by webpack. It contains vendor scripts common to all JS modules -->
<script src="${resURL}/jsbundles/vendors.js" type="text/javascript"/>
<script src="${resURL}/jsbundles/page-init.js" type="text/javascript"/>

</head>
Expand Down
3 changes: 3 additions & 0 deletions war/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": ["@babel/preset-env"],
}
20 changes: 20 additions & 0 deletions war/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
work
target
/rebel.xml

# Node
node/
node_modules/

# Generated JavaScript Bundles
jsbundles

src/main/webapp/css/font-awesome
src/main/webapp/css/google-fonts
src/main/webapp/css/icomoon

# External scripts
src/main/webapp/scripts/yui
src/main/webapp/scripts/prototype.js
src/main/webapp/scripts/*.js
src/main/js/plugin-setup-wizard/bootstrap-detached.js
35 changes: 35 additions & 0 deletions war/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
module.exports = {
env: {
browser: true,
es6: true
},
// Uses eslint default ruleset
extends: "eslint:recommended",
plugins: [
// Keeps the default level to warn to avoid breaking the current
// CI build environment
"only-warn"
],
parserOptions: {
ecmaVersion: 2018,
sourceType: "module"
},
rules: {
},
globals: {
Atomics: "readonly",
SharedArrayBuffer: "readonly",

'__dirname': false,

// Allow jest globals used in tests
jest: false,
expect: false,
it: false,
describe: false,
beforeEach: false,
afterEach: false,
beforeAll: false,
afterAll: false,
}
};
4 changes: 4 additions & 0 deletions war/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ node_modules/

# Generated JavaScript Bundles
jsbundles

src/main/webapp/css/font-awesome
src/main/webapp/css/google-fonts
src/main/webapp/css/icomoon
9 changes: 9 additions & 0 deletions war/.stylelintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
extends: "stylelint-config-standard",
rules: {
indentation: null
},
// Keeps the default level to warn to avoid breaking the current
// CI build environment
defaultSeverity: "warning"
}
55 changes: 0 additions & 55 deletions war/gulpfile.js

This file was deleted.

7 changes: 7 additions & 0 deletions war/jest.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"transform": {
"\\.hbs$": "jest-handlebars",
"\\.js$": "babel-jest"
},
"reporters": ["jest-standard-reporter"]
}
49 changes: 40 additions & 9 deletions war/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,50 @@
"url": "https://github.com/tfennelly"
},
"private": true,
"scripts": {
"dev": "webpack --config webpack.config.js",
"prod": "webpack --config webpack.config.js --mode=production",
"build": "yarn prod",
"start": "yarn dev --watch",
"test": "jest --config=jest.config.json",
"lint:js": "eslint . --ext js",
"lint:css": "stylelint src/main/less --syntax less",
"lint": "yarn lint:js && yarn lint:css"
},
"devDependencies": {
"gulp": "^3.9.0",
"@babel/cli": "^7.7.4",
"@babel/core": "^7.7.4",
"@jenkins-cd/js-test": "^1.2.3",
"clean-webpack-plugin": "^3.0.0",
"copy-webpack-plugin": "^5.1.1",
"css-loader": "^3.2.0",
"eslint": "^6.8.0",
"eslint-plugin-only-warn": "^1.0.2",
"file-loader": "^5.0.2",
"handlebars": "^3.0.3",
"hbsfy": "^2.4.1",
"jenkins-handlebars-rt": "^1.0.1",
"jenkins-js-builder": "0.0.40",
"jenkins-js-test": "^1.0.0",
"gulp-less": "^3.1.0"
"handlebars-loader": "^1.7.1",
"jest": "^24.9.0",
"jest-handlebars": "^1.0.1",
"jest-standard-reporter": "^1.0.4",
"less": "^3.10.3",
"less-loader": "^5.0.0",
"mini-css-extract-plugin": "^0.8.0",
"stylelint-config-standard": "^19.0.0",
"webpack": "^4.41.2",
"webpack-cli": "^3.3.10",
"webpack-fix-style-only-entries": "^0.4.0"
},
"dependencies": {
"bootstrap-detached": "^3.3.5-v1",
"@babel/preset-env": "^7.7.4",
"babel-loader": "^8.0.6",
"bootstrap": "3.3.5",
"jenkins-js-modules": "^1.5.0",
"jquery-detached": "^2.1.4-v2",
"jquery": "2.1.4",
"stylelint": "^13.0.0",
"window-handle": "^1.0.0"
}
},
"browserslist": [
"defaults",
"IE 11"
]
}
35 changes: 22 additions & 13 deletions war/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ THE SOFTWARE.
<JENKINS_HOME>${basedir}/work</JENKINS_HOME>
<contextPath>/jenkins</contextPath><!-- context path during test -->
<port>8080</port><!-- HTTP listener port -->
<node.version>6.10.2</node.version>
<yarn.version>0.24.5</yarn.version>
<node.version>12.14.1</node.version>
<yarn.version>1.21.1</yarn.version>
</properties>

<dependencyManagement>
Expand Down Expand Up @@ -566,16 +566,14 @@ THE SOFTWARE.


<!--
The following profiles are required to integration the node/gulp build into this maven build.
The following profiles are required to integration the node/yarn build into this maven build.
Hopefully we can push these profiles down into a parent pom.
See https://github.com/tfennelly/jenkins-js-builder#maven-integration
-->

<profile>
<id>gulp-execution</id>
<id>yarn-execution</id>
<activation>
<file>
<exists>gulpfile.js</exists>
<exists>package.json</exists>
</file>
</activation>
<build>
Expand Down Expand Up @@ -638,27 +636,38 @@ THE SOFTWARE.

<execution>
<phase>generate-sources</phase>
<id>gulp bundle</id>
<id>yarn build</id>
<goals>
<goal>gulp</goal>
<goal>yarn</goal>
</goals>
<configuration>
<arguments>jshint bundle</arguments>
<arguments>build</arguments>
</configuration>
</execution>

<execution>
<phase>test</phase>
<id>gulp test</id>
<id>yarn test</id>
<goals>
<goal>gulp</goal>
<goal>yarn</goal>
</goals>
<configuration>
<arguments>bundle test</arguments>
<arguments>test</arguments>
<skip>${skipTests}</skip>
</configuration>
</execution>

<execution>
<phase>test</phase>
<id>yarn lint</id>
<goals>
<goal>yarn</goal>
</goals>
<configuration>
<arguments>lint</arguments>
<skip>${skipTests}</skip>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions war/src/main/js/add-item.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Initialize all modules by requiring them. Also makes sure they get bundled (see gulpfile.js).
var $ = require('jquery-detached').getJQuery();
import $ from 'jquery';

var getItems = function() {
var d = $.Deferred();
Expand All @@ -9,7 +8,7 @@ var getItems = function() {
}
);
return d.promise();
};
};

var jRoot = $('head').attr('data-rooturl');

Expand All @@ -36,6 +35,7 @@ $.when(getItems()).done(function(data) {
if (desc.indexOf('&lt;a href="') === -1) {
return desc;
}
// eslint-disable-next-line
var newDesc = desc.replace(/\&lt;/g,'<').replace(/\&gt;/g,'>');
return newDesc;
}
Expand Down
Loading

0 comments on commit b4ef17d

Please sign in to comment.