Skip to content

Commit

Permalink
Merge branch 'release/5.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
tuananh committed Apr 28, 2020
2 parents 5882494 + 3a6014b commit fa4ef26
Show file tree
Hide file tree
Showing 23 changed files with 272 additions and 274 deletions.
15 changes: 8 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ os:
- osx
- windows
node_js:
- '8'
- '9'
- '10'
- '11'
- '12'
- '13'
- "8"
- "9"
- "10"
- "11"
- "12"
- "13"
- "14"

cache:
directories:
Expand All @@ -22,4 +23,4 @@ before_install:
- npm config set progress false
- npm config set spin false
script:
- npm test
- npm test
6 changes: 6 additions & 0 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@

## camaro

### `ready()`

Initialize module. Needed to be called once before calling other methods.

### `transform(xml, template)`

Transform xml string to JSON using the given template powered by XPath where:
Expand Down Expand Up @@ -44,6 +48,8 @@ const template = {

### `toJson(xml)`

**Not yet implemented**

Transform xml string to JSON where:
- `xml` - the input xml string

Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ The rest are pretty much vanilla XPath 1.0.
For complete API documentation, please see [API.md](API.md)

```js
const { transform, prettyPrint } = require('camaro')
const { ready, transform, prettyPrint } = require('camaro')
const fs = require('fs')

const xml = fs.readFileSync('examples/ean.xml', 'utf-8')
Expand All @@ -99,6 +99,7 @@ const template = {
}

;(async function () {
await ready()
const result = await transform(xml, template)
console.log(result)

Expand Down
3 changes: 2 additions & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ environment:
- nodejs_version: "11"
- nodejs_version: "12"
- nodejs_version: "13"
- nodejs_version: "14"

matrix:
fast_finish: true
Expand All @@ -29,4 +30,4 @@ install:
- npm install

test_script:
- npm test
- npm test
131 changes: 68 additions & 63 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
@@ -1,74 +1,79 @@
jobs:
- job: Windows
pool: "Hosted VS2017"

- job: Windows
pool: 'Hosted VS2017'
variables:
os_name: Windows

variables:
os_name: Windows
strategy:
matrix:
node_8_x:
node_version: 8.x
node_9_x:
node_version: 9.x
node_10_x:
node_version: 10.x
node_11_x:
node_version: 11.x
node_12_x:
node_version: 12.x
node_13_x:
node_version: 13.x
node_14_x:
node_version: 14.x
steps:
- template: azure-test.yml

strategy:
matrix:
node_8_x:
node_version: 8.x
node_9_x:
node_version: 9.x
node_10_x:
node_version: 10.x
node_11_x:
node_version: 11.x
node_12_x:
node_version: 12.x
node_13_x:
node_version: 13.x
steps:
- template: azure-test.yml
- job: Linux
pool:
vmImage: "Ubuntu 16.04"

- job: Linux
pool:
vmImage: 'Ubuntu 16.04'
variables:
os_name: Linux

variables:
os_name: Linux
strategy:
matrix:
node_8_x:
node_version: 8.x
node_9_x:
node_version: 9.x
node_10_x:
node_version: 10.x
node_11_x:
node_version: 11.x
node_12_x:
node_version: 12.x
node_13_x:
node_version: 13.x
node_14_x:
node_version: 14.x

strategy:
matrix:
node_8_x:
node_version: 8.x
node_9_x:
node_version: 9.x
node_10_x:
node_version: 10.x
node_11_x:
node_version: 11.x
node_12_x:
node_version: 12.x
node_13_x:
node_version: 13.x
steps:
- template: azure-test.yml

steps:
- template: azure-test.yml
- job: OSX
pool:
vmImage: "macOS 10.13"

- job: OSX
pool:
vmImage: 'macOS 10.13'
variables:
os_name: OSX

variables:
os_name: OSX
strategy:
matrix:
node_8_x:
node_version: 8.x
node_9_x:
node_version: 9.x
node_10_x:
node_version: 10.x
node_11_x:
node_version: 11.x
node_12_x:
node_version: 12.x
node_13_x:
node_version: 13.x
node_14_x:
node_version: 14.x

strategy:
matrix:
node_8_x:
node_version: 8.x
node_9_x:
node_version: 9.x
node_10_x:
node_version: 10.x
node_11_x:
node_version: 11.x
node_12_x:
node_version: 12.x
node_13_x:
node_version: 13.x

steps:
- template: azure-test.yml
steps:
- template: azure-test.yml
17 changes: 8 additions & 9 deletions azure-test.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
steps:
- task: NodeTool@0
inputs:
versionSpec: $(node_version)
displayName: "Install Node.js"

- task: NodeTool@0
inputs:
versionSpec: $(node_version)
displayName: 'Install Node.js'

- bash: |
npm install
npm run test
displayName: 'Install and test'
- bash: |
npm install
npm run test
displayName: "Install and test"
22 changes: 11 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,22 @@ function isEmptyObject(obj) {
}

let cachedInstance
const instance = Module()
instance.onRuntimeInitialized = () => {
cachedInstance = instance
}

function callWasmBinding(methodName, ...args) {
return new Promise((resolve) => {
if (!cachedInstance) throw new Error('camaro is not yet initialized. You need to call `ready()` first.')
return cachedInstance[methodName](...args)
}

const ready = () => {
return new Promise((resolve, reject) => {
if (!cachedInstance) {
const instance = Module()
instance.onRuntimeInitialized = () => {
cachedInstance = instance
const result = instance[methodName](...args)
resolve(result)
resolve()
}
} else {
const result = cachedInstance[methodName](...args)
resolve(result)
} else {
resolve()
}
})
}
Expand Down Expand Up @@ -76,4 +76,4 @@ async function prettyPrint(xml, opts={indentSize: 2}) {
return callWasmBinding('prettyPrint', xml, opts)
}

module.exports = { transform, toJson, prettyPrint }
module.exports = { ready, transform, toJson, prettyPrint }
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
{
"name": "camaro",
"version": "4.2.0",
"version": "5.0.0",
"description": "Transforming XML to JSON using Node.js binding to native pugixml parser library",
"homepage": "https://github.com/tuananh/camaro",
"bugs": "https://github.com/tuananh/camaro/issues",
"publishConfig": {
"registry": "https://npm.pkg.github.com/@tuananh"
},
"main": "index.js",
"typings": "index.d.ts",
"scripts": {
Expand Down Expand Up @@ -44,8 +41,11 @@
"json": "nlohmann/json#v3.5.0",
"fifo_map": "nlohmann/fifo_map#master"
},
"napa-config": {
"cache": false
},
"devDependencies": {
"napa": "3.0.0",
"tape": "4.13.2"
"tape": "5.0.0"
}
}
Loading

0 comments on commit fa4ef26

Please sign in to comment.