Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/szgabsz91/npm-maven-extension
A Maven extension and a Maven plugin to download NPM packages into the local Maven repository and extract them into an arbitrary folder
https://github.com/szgabsz91/npm-maven-extension
maven maven-extension maven-plugin npm
Last synced: 24 days ago
JSON representation
A Maven extension and a Maven plugin to download NPM packages into the local Maven repository and extract them into an arbitrary folder
- Host: GitHub
- URL: https://github.com/szgabsz91/npm-maven-extension
- Owner: szgabsz91
- License: mit
- Created: 2019-05-19T07:34:36.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-11-14T17:51:54.000Z (12 months ago)
- Last Synced: 2024-10-01T16:09:42.084Z (about 1 month ago)
- Topics: maven, maven-extension, maven-plugin, npm
- Language: Java
- Size: 881 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# npm-maven-extension
[![Build Status](https://img.shields.io/circleci/project/github/szgabsz91/npm-maven-extension/master.svg)](https://circleci.com/gh/szgabsz91/workflows/npm-maven-extension)
[![Maven Central](https://img.shields.io/maven-central/v/com.github.szgabsz91/npm-maven-extension-parent)](https://central.sonatype.com/artifact/com.github.szgabsz91/npm-maven-extension-parent)
[![License](https://img.shields.io/github/license/szgabsz91/npm-maven-extension.svg)](https://github.com/szgabsz91/npm-maven-extension/blob/master/LICENSE)This is an experimental project that demonstrates an alternative way of downloading NPM packages during a Maven build.
The most mainstream way of doing this would be to use [webjars](https://www.webjars.org/). This project contains another
way that I don't recommend using in production, but had much fun implementing it.The main building blocks are the following:
* [npm-maven-extension](extension): downloads the NPM packages added to the pom.xml from an arbitrary NPM repository,
with or without authentication. The downloaded tar.gz file will be stored in the
local Maven repository.
* [npm-maven-plugin](plugin): during the Maven build,
the [extract](plugin/src/main/java/com/github/szgabsz91/maven/plugins/npm/ExtractMojo.java)
goal can extract the downloaded tar.gz file into an arbitrary, configurable folder. The
extracted resources can be referenced by your client web application.
* [npm-maven-extension-demo](demo): a Spring Boot demo application that contains a single HTML page that displays a
Bootstrap based welcome page. Bootstrap is downloaded using the custom extension.The site documentation of this project can be found on [Github Pages](https://szgabsz91.github.io/npm-maven-extension/introduction.html).
## Requirements
### settings.xml
The `~/.m2/settings.xml` file must at least contain an NPM server and a repository that uses *npm-http* or *npm-https*
as its protocol. The URL can point to the public npmjs.org server or any other private NPM repositories. The server node
can contain authentication information, too.A sample settings.xml file looks like this:
```xml
npm
${optional_username}
${optional_password}
npm
npm
npm-https://registry.npmjs.org
never
ignore
never
ignore
npm
```
### pom.xml
In the pom.xml file of your client project, you must reference the NPM dependencies with the *npm* type property, and
define the extension, as well as the plugin.A sample pom.xml file looks like this:
```xml
4.0.0
com.demo
demo
1.0.0-SNAPSHOT
5.2.3
<_angular_router.version>15.0.4
1.0.1
npm
bootstrap
${bootstrap.version}
npm
npm
_angular_router
${_angular_router.version}
npm
com.github.szgabsz91
npm-maven-extension
${npm-maven-extension.version}
com.github.szgabsz91
npm-maven-plugin
${npm-maven-extension.version}
extract
${project.basedir}/src/main/resources/static/npm
```
This project downloads [[email protected]](https://www.npmjs.com/package/bootstrap) and
[@angular/[email protected]](https://www.npmjs.com/package/@angular/router) into the `src/main/resources/static/npm` folder.For a working example, see the [demo application](demo).
## Testing the Project
You can test the project with the following commands:
```bash
./mvnw clean site install
cd demo
./mvnw clean install
```After that, if you open the `demo/src/main/resources/static/npm` folder, you'll see
* angular
* router
* package
* ...
* bootstrap
* package
* ...Also, you can build a Docker image from this simple war project and run it:
```bash
./mvnw clean install -Pdocker
docker run -p 8080:8080 npm-maven-extension-demo
```After that, opening `http://localhost:8080/npm-maven-extension-demo`, you'll see a Bootstrap based welcome page: