diff --git a/.github/workflows/artifacts.yml b/.github/workflows/artifacts.yml
index ddd934c9..efe17a3f 100644
--- a/.github/workflows/artifacts.yml
+++ b/.github/workflows/artifacts.yml
@@ -136,6 +136,19 @@ jobs:
name: pyoxigraph_wheel_x86_64_windows
path: target/wheels/*.whl
+ npm_tarball:
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v2
+ - run: rustup update
+ - run: cargo install wasm-pack
+ - run: npm run pack
+ working-directory: ./js
+ - uses: actions/upload-artifact@v2
+ with:
+ name: oxigraph_wasm_npm
+ path: js/*.tgz
+
docker:
runs-on: ubuntu-latest
steps:
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index b7f052a5..3e2dad6f 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -157,12 +157,14 @@ jobs:
- run: cargo install wasm-pack
- run: npm install
working-directory: ./js
- - run: npm run build
- working-directory: ./js
- run: npm run release
working-directory: ./js
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
+ - run: npm run pack
+ - uses: softprops/action-gh-release@v1
+ with:
+ files: js/*.tgz
publish_python_doc:
runs-on: ubuntu-latest
diff --git a/js/README.md b/js/README.md
index f5dffff2..aa2af2a3 100644
--- a/js/README.md
+++ b/js/README.md
@@ -13,31 +13,75 @@ Oxigraph for JavaScript is a work in progress and currently offers a simple in-m
The store is also able to load RDF serialized in [Turtle](https://www.w3.org/TR/turtle/), [TriG](https://www.w3.org/TR/trig/), [N-Triples](https://www.w3.org/TR/n-triples/), [N-Quads](https://www.w3.org/TR/n-quads/) and [RDF/XML](https://www.w3.org/TR/rdf-syntax-grammar/).
+It is distributed using a [a NPM package](https://www.npmjs.com/package/oxigraph) that should work with Node.JS 12+ and modern web browsers compatible with WebAssembly.
-It is distributed using a [a NPM package](https://www.npmjs.com/package/oxigraph) that should work with nodeJS 12+.
-
+To install:
```bash
npm install oxigraph
```
+To load with Node.JS:
```js
const oxigraph = require('oxigraph');
```
-## Example
+or with ES modules:
+```js
+import oxigraph from './node_modules/oxigraph/node.js';
+```
+
+To load on an HTML web page:
+```html
+
+```
+
+## Node.JS Example
+
+Insert the triple ` "example"` and log the name of `` in SPARQL:
-Insert the triple ` "example"` and log the name of `` in SPARQL:
```js
const oxigraph = require('oxigraph');
const store = new oxigraph.Store();
const ex = oxigraph.namedNode("http://example/");
const schemaName = oxigraph.namedNode("http://schema.org/name");
store.add(oxigraph.triple(ex, schemaName, oxigraph.literal("example")));
-for (binding of store.query("SELECT ?name WHERE { ?name }")) {
+for (const binding of store.query("SELECT ?name WHERE { ?name }")) {
console.log(binding.get("name").value);
}
```
+## Web Example
+
+Insert the triple ` "example"` and log the name of `` in
+SPARQL:
+
+```html
+
+
+```
+
## API
Oxigraph currently provides a simple JS API.
diff --git a/js/build_package.js b/js/build_package.js
new file mode 100644
index 00000000..901a8a08
--- /dev/null
+++ b/js/build_package.js
@@ -0,0 +1,31 @@
+#! /usr/bin/env node
+
+const fs = require('fs')
+
+// We copy file to the new directory
+fs.mkdirSync('pkg')
+for (const file of fs.readdirSync('./pkg-web')) {
+ fs.copyFileSync('./pkg-web/' + file, './pkg/' + file)
+}
+for (const file of fs.readdirSync('./pkg-node')) {
+ fs.copyFileSync('./pkg-node/' + file, './pkg/' + file)
+}
+
+const pkg = JSON.parse(fs.readFileSync('./pkg/package.json'))
+pkg.name = 'oxigraph'
+pkg.main = 'node.js'
+pkg.browser = 'web.js'
+pkg.files = [
+ '*.{js,wasm,d.ts}'
+]
+pkg.homepage = 'https://github.com/oxigraph/oxigraph/tree/master/js'
+pkg.bugs = {
+ url: 'https://github.com/oxigraph/oxigraph/issues'
+}
+pkg.collaborators = undefined
+pkg.repository = {
+ type: 'git',
+ url: 'https://github.com/oxigraph/oxigraph.git',
+ directory: 'js'
+}
+fs.writeFileSync('./pkg/package.json', JSON.stringify(pkg, null, 2))
diff --git a/js/package.json b/js/package.json
index bf96eae6..f4dcab7a 100644
--- a/js/package.json
+++ b/js/package.json
@@ -8,8 +8,14 @@
"standard": "^16.0.0"
},
"scripts": {
- "test": "standard test/* && wasm-pack build --dev --target nodejs && mocha",
- "build": "wasm-pack build --release --target nodejs && sed -i 's/oxigraph_js/oxigraph/g' pkg/package.json",
- "release": "wasm-pack pack && wasm-pack publish"
+ "test": "standard && wasm-pack build --debug --target nodejs && mocha",
+ "build": "rm -rf pkg && wasm-pack build --release --target web --out-name web && mv pkg pkg-web && wasm-pack build --release --target nodejs --out-name node && mv pkg pkg-node && node build_package.js && rm -r pkg-web && rm -r pkg-node",
+ "release": "npm run build && npm publish ./pkg",
+ "pack": "npm run build && npm pack ./pkg"
+ },
+ "standard": {
+ "ignore": [
+ "pkg*"
+ ]
}
}