Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 2 additions & 37 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,38 +1,3 @@
{
"rules": {
"indent": [ 2, 2, {
"VariableDeclarator": { "const": 3, "let": 2, "var": 2 },
"FunctionDeclaration": { "parameters": 2 }
} ],
"keyword-spacing": [ 2 ],
"mocha/no-exclusive-tests": 2,
"no-console": 0,
"no-unused-vars": [ 2, { "args": "none" } ],
"no-trailing-spaces": [ 2 ],
"object-curly-spacing": [ 2, "always"],
"semi": [ 2, "always" ],
"space-before-blocks": [ 2, "always"],
"space-before-function-paren": [ 2, "never" ],
"quotes": [ 2, "single" ]
},
"env": {
"browser": true,
"node": true
},
"extends": "eslint:recommended",
"parserOptions": {
"ecmaVersion": 5
},
"plugins": [
"mocha"
],
"globals": {
"after": true,
"afterEach": true,
"before": true,
"beforeEach": true,
"describe": false,
"expect": false,
"it": false
}
}
"extends": "plugin:bpmn-io/es5"
}
133 changes: 133 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
name: CI
on: [ push, pull_request ]
jobs:

Build:
runs-on: ${{ matrix.os }}

strategy:
matrix:
os: [ ubuntu-latest ]
node-version: [ 14.x ]

steps:
- name: Checkout
uses: actions/checkout@v2
- name: Use Node.js ${{matrix.node-version}}
uses: actions/setup-node@v2
with:
node-version: ${{matrix.node-version}}
- name: Cache Node.js modules
uses: actions/cache@v2
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm
key: ${{ runner.OS }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.OS }}-node-
${{ runner.OS }}-
- name: Install dependencies
run: npm ci
- name: Build
env:
LOG_DEBUG: 'xsd-schema-validator'
run: npm run all

Build-Nodes:
runs-on: ${{ matrix.os }}

strategy:
matrix:
os: [ ubuntu-latest ]
node-version: [ 10.x, 12.x, 14.x ]

steps:
- name: Checkout
uses: actions/checkout@v2
- name: Use Node.js ${{matrix.node-version}}
uses: actions/setup-node@v2
with:
node-version: ${{matrix.node-version}}
- name: Cache Node.js modules
uses: actions/cache@v2
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm
key: ${{ runner.OS }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.OS }}-node-
${{ runner.OS }}-
- name: Install dependencies
run: npm ci
- name: Build
env:
LOG_DEBUG: 'xsd-schema-validator'
run: npm run all

Build-Platforms:
runs-on: ${{ matrix.os }}

strategy:
matrix:
os: [ macos-latest, windows-latest ]
node-version: [ 14.x ]

steps:
- name: Checkout
uses: actions/checkout@v2
- name: Use Node.js ${{matrix.node-version}}
uses: actions/setup-node@v2
with:
node-version: ${{matrix.node-version}}
- name: Cache Node.js modules
uses: actions/cache@v2
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm
key: ${{ runner.OS }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.OS }}-node-
${{ runner.OS }}-
- name: Install dependencies
run: npm ci
- name: Build
env:
LOG_DEBUG: 'xsd-schema-validator'
run: npm run all

Build-Javas:
runs-on: ${{ matrix.os }}

strategy:
matrix:
os: [ ubuntu-latest ]
node-version: [14.x]
java-home: [ JAVA_HOME_8_X64, JAVA_HOME_11_X64 ]

steps:
- name: Checkout
uses: actions/checkout@v2
- name: Use Node.js ${{matrix.node-version}}
uses: actions/setup-node@v2
with:
node-version: ${{matrix.node-version}}
- name: Cache Node.js modules
uses: actions/cache@v2
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm
key: ${{ runner.OS }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.OS }}-node-
${{ runner.OS }}-
- name: Install dependencies
run: npm ci
- name: Set JAVA_HOME
run: |
echo 'JAVA_HOME<<EOF' >> $GITHUB_ENV
echo "$${{matrix.java-home}}" >> $GITHUB_ENV
echo 'EOF' >> $GITHUB_ENV
- name: Build
env:
LOG_DEBUG: 'xsd-schema-validator'
run: npm run all
4 changes: 4 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.github
test
.eslintrc
support/XMLValidator.class
9 changes: 0 additions & 9 deletions .travis.yml

This file was deleted.

18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Changelog

All notable changes to [node-xsd-schema-validator](https://github.com/nikku/node-xsd-schema-validator) are documented here. We use [semantic versioning](http://semver.org/) for releases.

## Unreleased

___Note:__ Yet to be released changes appear here._

## 0.7.0

* `FEAT`: setup validation helper post install
* `FEAT`: add validator `#setup` hook
* `FEAT`: allow debug mode to be toggled via environment variable
* `FEAT`: gracefully handle missing `java`/`javac`

## ...

Check `git log` for earlier history.
21 changes: 12 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
# xsd-schema-validator

[![Build Status](https://travis-ci.org/nikku/node-xsd-schema-validator.svg?branch=master)](https://travis-ci.org/nikku/node-xsd-schema-validator)
[![CI](https://github.com/nikku/node-xsd-schema-validator/workflows/CI/badge.svg)](https://github.com/nikku/node-xsd-schema-validator/actions?query=workflow%3ACI)

A (XSD) schema validator for [NodeJS](nodejs.org) that uses [Java](https://www.java.com) to perform the actual validation.
A (XSD) schema validator for [NodeJS](nodejs.org) that uses [Java](https://www.java.com) to perform the actual validation. [:arrow_right: Why?](#why)


## Prerequisites

This utility assumes that `javac` and `java` are on the path _or_ that
the `JAVA_HOME` environment exists and points to an installed JDK.
Under the hood, this utility uses Java to do the actual validation.

It assumes that `javac` and `java` are on the path. If a `JAVA_HOME` environment variable exists it uses that to locate an installed JDK.

On some platforms, i.e. [Mac OSX](http://www.mkyong.com/java/how-to-set-java_home-environment-variable-on-mac-os-x/) you need to define `JAVA_HOME` manually.


## How to Use
## Installation

Install via [npm](http://npmjs.org):
Install the package via [npm](http://npmjs.org):

```
npm install --save xsd-schema-validator
```


## Usage

Use in your application:

```javascript
Expand All @@ -37,21 +41,20 @@ validator.validateXML(xmlStr, 'resources/foo.xsd', function(err, result) {
});
```

You may validate readable streams, too:
You may validate readable streams:

```javascript
var xmlStream = fs.createReadableStream('some.xml');

validator.validateXML(xmlStream, ...);
```

...and files, too:
You may validate files, too:

```javascript
validator.validateXML({ file: 'some.xml' }, ...);
```


## Why

Because Java can do schema validation and NodeJS cannot.
Expand Down
20 changes: 20 additions & 0 deletions lib/post-install.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
var validator = require('./validator');

var fs = require('fs');

try {
fs.unlinkSync(__dirname + '/../support/XMLValidator.class');
} catch (err) {

// ignore
}

console.log('[xsd-schema-validator] Compiling helper...');

validator.setup(function(err) {
if (err) {
console.error(err);

process.exit(1);
}
});
Loading