All Projects → OrienteerBAP → JNPM

OrienteerBAP / JNPM

Licence: Apache-2.0 license
Native Java API to work with JavaScript Node Package Manager (NPM): query, retrieve, pack into jar (webjars), CDN

Programming Languages

java
68154 projects - #9 most used programming language
HTML
75241 projects

Projects that are alternatives of or similar to JNPM

Quantum-Computing-Resources
This repository contains the best resources for learning practical quantum computing. This repository will be updated frequently.
Stars: ✭ 60 (+275%)
Mutual labels:  resources
HumanIdiogramLibrary
Resource of human chromosome schematics & images
Stars: ✭ 76 (+375%)
Mutual labels:  resources
dev-log
A comprehensive list of links and resources about anything programming related
Stars: ✭ 55 (+243.75%)
Mutual labels:  resources
awesome-edtech-tools
An ongoing curated list with awesome tools and resources for instructional designers.
Stars: ✭ 135 (+743.75%)
Mutual labels:  resources
awesome-meilisearch
A curated list of awesome Meilisearch resources
Stars: ✭ 38 (+137.5%)
Mutual labels:  resources
UCAS-Helper
国科大(UCAS, ucas)校园网登录、课程资源下载、自动评教和分数查询助手
Stars: ✭ 105 (+556.25%)
Mutual labels:  resources
podcasting-resources
Resources and links related to podcasting. Created for W/S/C 2018 but can be forked/added to as time goes on.
Stars: ✭ 43 (+168.75%)
Mutual labels:  resources
my-action-github
awesome github
Stars: ✭ 62 (+287.5%)
Mutual labels:  resources
Innovative-Book-Resources
This repository contains books from different topics and perfect enough to give developers a boost in understanding the concepts of Data Science and Artificial Intelligence(other topics are also included but main highlights are these two).
Stars: ✭ 57 (+256.25%)
Mutual labels:  resources
android-api-loquacious
Loquacious is a localized remote resource manager library for Android
Stars: ✭ 24 (+50%)
Mutual labels:  resources
engineering-management
A list of resources about Software Engineering Management
Stars: ✭ 31 (+93.75%)
Mutual labels:  resources
resources
Awesome resources - 网络资源
Stars: ✭ 27 (+68.75%)
Mutual labels:  resources
Polyfill
An artifact repository to assist writing Gradle Plugins for Android build system.
Stars: ✭ 68 (+325%)
Mutual labels:  artifact
urban-and-regional-planning-resources
Community list of data & technology resources concerning the built environment and communities. 🏙️🌳🚌🚦🗺️
Stars: ✭ 109 (+581.25%)
Mutual labels:  resources
ds-algo-placement-resources
A complete roadmap and resources for competitive programming for placement purpose.
Stars: ✭ 58 (+262.5%)
Mutual labels:  resources
framestack
Tools, Frameworks & Libraries to help you build your projects ✨
Stars: ✭ 27 (+68.75%)
Mutual labels:  resources
awesome-solid-js
Curated resources on building sites with SolidJS, a brand new way(now 1.0) to build Javascript based interactive web applications. A very close looking cousin to React/JSX by syntax, and to Svelte by few important principles(compiler and fine-grained reactivity), it's a highly optimised way to deliver web applications with best-in-class performa…
Stars: ✭ 317 (+1881.25%)
Mutual labels:  resources
iOS-Tweak-Dev-Tools
A collection of useful development tools and forks of tools that are geared towards iOS jailbreak developers.
Stars: ✭ 37 (+131.25%)
Mutual labels:  resources
software-testing-resource-pack
Various files useful for manual testing and test automation etc.
Stars: ✭ 38 (+137.5%)
Mutual labels:  resources
awesome-n64-development
A curated list of Nintendo 64 development resources including toolchains, documentation, emulators, example code, and more
Stars: ✭ 210 (+1212.5%)
Mutual labels:  resources

Build Status javadoc

JNPM

Native Java API to work with JavaScript Node Package Manager (NPM): query, retrieve, pack into jar (webjars), CDN

  1. Java API
  2. Command Line Interface
  3. Maven Plugin (lightweight and fast replacement for frontend-maven-plugin, npm-maven-plugin and even WebJars)
  4. Make your CDN

Java API

Include JNPM Jar into pom.xml:

<dependency>
    <groupId>org.orienteer.jnpm</groupId>
    <artifactId>jnpm</artifactId>
    <version>LATEST JNPM VERSION</version>
</dependency>

Initialize JNPM API prior to use.

JNPMService.configure(JNPMSettings.builder()
  .homeDirectory(Paths.get("/home/myuser/.jnpm")) //Optional
  .downloadDirectory(Paths.get("/tmp")) //Optional
  //Other optional configurations: see JavaDoc for more info
 	.build());

JNPM API has 2 options: Synchronous API and RXJava API. Please use required one per your needs:

JNPMService jnpmService = JNPMService.instance(); //Synchronous Java API
RxJNPMService rxJnpmService = JNPMService.instance().getRxService() //RXJava API

Examples of API use:

//Print NPM Registry Information
System.out.println(JNPMService.instance().getRegistryInfo());
//Retrieve and print VUE package latest version
System.out.println(JNPMService.instance().getPackageInfo("vue").getLatest());
//Print package description for [email protected]
System.out.println(JNPMService.instance().getVersionInfo("vue", "2.6.11").getDescription());
//Print latest version prior to vue version 2 official release
System.out.println(JNPMService.instance().bestMatch("vue@<2").getVersionAsString());
//Download tarball for [email protected] and print localpath
VersionInfo vueVersion = JNPMService.instance().getVersionInfo("vue", "2.6.11");
vueVersion.downloadTarball().blockingAwait();
System.out.println(vueVersion.getLocalTarball().getAbsolutePath());
//Search for "vue" and print description for first result
System.out.println(JNPMService.instance().search("vue").getObjects().get(0).getSearchPackage().getDescription());
//Traverse through all dev dependencies of latest vue package, print information
// and install as NPM do (node_modules/vue and etc)
JNPMService.instance().getRxService()
   .traverse(TraverseDirection.WIDER, TraversalRule.DEV_DEPENDENCIES, "vue")
   .subscribe(t -> {System.out.println(t); t.install(Paths.get("target", "readme"), InstallationStrategy.NPM);});

Read javadoc for more information.

Command Line Interface

Usage: jnpm [-hV] [--download-dir=<downloadDirectory>]
            [--home-dir=<homeDirectory>] [--install-dir=<installDirectory>]
            [-P=<password>] [--registry=<registryUrl>] [-U=<username>] [COMMAND]
Java implementation of Node Package Manager
      --download-dir=<downloadDirectory>
                  Cache directory for JNPM to download packages to (default:
                    <home-dir>/cache/)
  -f, --force     Force to fetch remote resources even if a local copy exists                                                                                                    on disk
  -h, --help      Show this help message and exit.
      --home-dir=<homeDirectory>
                  Home directory for JNPM (default: C:\Users\naryzhny\.jnpm)
      --install-dir=<installDirectory>
                  Global install directory for JNPM (default:
                    <home-dir>/node_modules/)
  -L, --http-logger-level
                  HTTP Logger Level for debugging
                  Valid values: NONE, BASIC, HEADERS, BODY
  -P, --password=<password>
                  Password for authentication (optional)
      --registry=<registryUrl>
                  NPM registry URL to be used for package lookup and retrieval
                    (default: http://registry.npmjs.org/)
  -U, --username=<username>
                  Username for authentication (optional)
  -V, --version   Print version information and exit.
Commands:
  download, d  Download packages into local cache
  extract, e   Extract packages: very similiar to 'npm install', but without
                 changing package.json modification
Usage: jnpm download [-h] [--[no-]dev] [--[no-]download] [--[no-]optional] [--
                     [no-]peer] [--[no-]prod] <packageStatements>...
Download packages into local cache
      <packageStatements>...
                        Packages to be retrieved
      --[no-]dev        Download dev dependencies
      --[no-]download   Download by default. Negate if  just attempt to lookup
                          is needed
  -h, --help
      --[no-]optional   Download optional dependencies
      --[no-]peer       Download peer dependencies
      --[no-]prod       Download dependencies (default)
Usage: jnpm extract [-gh] [--[no-]dev] [--[no-]download] [--[no-]optional] [--
                    [no-]peer] [--[no-]prod] [-o=<folder>] [-s=<strategy>]
                    <packageStatements>...
Extract packages: very similiar to 'npm install', but without changing package.
json modification
      <packageStatements>...
                          Packages to be retrieved
      --[no-]dev          Download dev dependencies
      --[no-]download     Download by default. Negate if  just attempt to
                            lookup is needed
  -g                      Extract package(s) globally
  -h, --help
  -o, --output=<folder>   Output folder to extract to
      --[no-]optional     Download optional dependencies
      --[no-]peer         Download peer dependencies
      --[no-]prod         Download dependencies (default)
  -s, --strategy=<strategy>
                          Strategy for extraction: FLAT, NPM, SIMPLE,
                            SIMPLE_VERSIONED, WEBJARS, ONE_DUMP, DIST

Maven Plugin

JNPM maven plugin allows you natively integrate NPM resources into your build process. For example, you can download and pack JS packages inside your WAR to use later through WebJars extensions. To include vue and into your WAR please add the following into build>plugins section of your pom.xml

<plugin>
<groupId>org.orienteer.jnpm</groupId>
    <artifactId>jnpm-maven-plugin</artifactId>
	<version>${LATEST_JNPM_VERSION}</version>
	<executions>
		<execution>
			<goals>
				<goal>install</goal>
			</goals>
			<configuration>
				<packages>
					<package>[email protected]</package>
					<package>vuex@~3.4.0</package>
				</packages>
			</configuration>
		</execution>
	</executions>
</plugin>

More details about the plugin:

jnpm:install
  Goal to download, extract and attach npm resources

  Available parameters:

    attachResources (Default: true)
      Attach downloaded resources to the build process

    excludes
      What has to be excluded from resources to be attached

    getDev (Default: false)
      Download development dependencies

    getOptional (Default: false)
      Download optional dependencies

    getPeer (Default: false)
      Download peer dependencies

    getProd (Default: false)
      Download direct dependencies
      
    httpLoggerLevel (Default: NONE)
    	HTTP Logger Level for debugging

    includes
      What should be included as resources (Default: empty - means everything)

    outputDirectory (Default: ${project.build.directory}/jnpm/)
      Location of the output directory
      Required: Yes

    packages
      NPM packages to be downloaded and extracted (For example: [email protected])
      Required: Yes

    password
      Password for authentication (optional)

    pathPrefix
      Prefix for the directory under outputDirectory to which files will be
      placed

    registryUrl (Default: http://registry.npmjs.org/)
      NPM registry URL to be used for package lookup and retrieval

    serverId
      Server id from settings to get username and password from

    strategy (Default: WEBJARS)
      Installation strategy to be used

    useCache (Default: true)
      Use local cache. Useful if the same package version can be re-uploaded to a registry

    username
      Username for authentication (optional)

CDN

Servlet

Add the following mapping to your web.xml. Adjust as needed:

  <servlet>
    <servlet-name>CDNServlet</servlet-name>
    <servlet-class>org.orienteer.jnpm.cdn.CDNServlet</servlet-class>
  </servlet>

  <servlet-mapping>
    <servlet-name>CDNServlet</servlet-name>
    <url-pattern>/cdn/*</url-pattern>
  </servlet-mapping>

Files from NPM packages will be available through URLs with the following pattern: http(s)://<host>:<port>/<deploy-folder>/cdn/<package expression>/<required file>. For example: http://localhost:8080/cdn/[email protected]/dist/vue.js

You can user init-param to specify extra JNPM parameters, for example, registryUrl, username, password and etc.

Apache Wicket

Add the following code to your Apache Wicket WebApplication:

if(!JNPMService.isConfigured()) 
   JNPMService.configure(JNPMSettings.builder().build()); //Configure as you wish
   CDNWicketResource.mount(this, "/cdn");

Files from NPM packages will be available through URLs with the following pattern: http(s)://<host>:<port>/<deploy-folder>/cdn/<package expression>/<required file>. For example: http://localhost:8080/cdn/[email protected]/dist/vue.js

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].