From 7331289e0ff9e64ae4a5a8b0e06fd68058ac5560 Mon Sep 17 00:00:00 2001 From: Niko PLP Date: Thu, 27 Feb 2025 21:05:24 +0200 Subject: [PATCH] improve script for building JS SDK --- DEV.md | 7 +++-- ng-app/README.md | 13 +++++----- ng-app/src/classes.ts | 2 +- ng-sdk-js/.gitignore | 3 +++ ng-sdk-js/Cargo.toml | 8 ++++++ ng-sdk-js/DEV.md | 49 +++++++++++++++++++---------------- ng-sdk-js/app-react/README.md | 9 +++---- ng-sdk-js/app-web/README.md | 9 +++---- ng-sdk-js/prepare-node.js | 3 +++ 9 files changed, 62 insertions(+), 41 deletions(-) create mode 100644 ng-sdk-js/.gitignore diff --git a/DEV.md b/DEV.md index 96d0b05..168aeac 100644 --- a/DEV.md +++ b/DEV.md @@ -14,13 +14,14 @@ cargo install wasm-pack --git https://github.com/rustwasm/wasm-pack.git --rev c2 ``` cargo install cargo-watch +cargo install cargo-run-script // optionally, if you want a Rust REPL: cargo install evcxr_repl git clone git@git.nextgraph.org:NextGraph/nextgraph-rs.git // or if you don't have a git account with us: git clone https://git.nextgraph.org/NextGraph/nextgraph-rs.git cd nextgraph-rs npm install -g pnpm cd ng-sdk-js -wasm-pack build --target bundler +cargo run-script app npm install --no-save pkg cd ../ng-app pnpm install @@ -167,9 +168,11 @@ cd .. Otherwise, build from source the single-file release of ng-app ``` +cargo install cargo-run-script npm install -g pnpm cd ng-sdk-js -wasm-pack build --target bundler +cargo run-script app +npm install --no-save pkg cd ../ng-app pnpm install pnpm webfilebuild diff --git a/ng-app/README.md b/ng-app/README.md index d5f90d9..1f2fb75 100644 --- a/ng-app/README.md +++ b/ng-app/README.md @@ -21,7 +21,8 @@ prerequisites: compile the local SDK ``` cd ../ng-sdk-js -wasm-pack build --target bundler +cargo install cargo-run-script +cargo run-script app npm install --no-save pkg cd ../ng-app ``` @@ -95,15 +96,15 @@ cargo tauri build --target x86_64-pc-windows-msvc ### Android -- [Install Android Studio](https://developer.android.com/studio) +- [Install Android Studio](https://developer.android.com/studio) -- add the rust targets for android +- add the rust targets for android ``` rustup target add aarch64-linux-android armv7-linux-androideabi i686-linux-android x86_64-linux-android ``` -- follow the steps for Android in the [Prerequisites guide of Tauri](https://v2.tauri.app/start/prerequisites/#configure-for-mobile-targets) +- follow the steps for Android in the [Prerequisites guide of Tauri](https://v2.tauri.app/start/prerequisites/#configure-for-mobile-targets) Until I find out how to do this properly, if you are compiling the android app from a macos station, you need to override an env var. this is due to reqwest needing SSL support, and on linux and android it compiles it from source. apparently the compiler (cc-rs) doesn't know that when cross compiling to android targets, the tool ranlib is called llvm-ranlib (and not [target]-ranlib) @@ -129,8 +130,8 @@ cargo tauri android build to debug the Svelte app, use Chrome : -- [chrome://inspect/#devices](chrome://inspect/#devices) -- install the [svelte extension](https://chrome.google.com/webstore/detail/svelte-devtools/ckolcbmkjpjmangdbmnkpjigpkddpogn) +- [chrome://inspect/#devices](chrome://inspect/#devices) +- install the [svelte extension](https://chrome.google.com/webstore/detail/svelte-devtools/ckolcbmkjpjmangdbmnkpjigpkddpogn) ### iOS diff --git a/ng-app/src/classes.ts b/ng-app/src/classes.ts index 3588f2f..d999f19 100644 --- a/ng-app/src/classes.ts +++ b/ng-app/src/classes.ts @@ -382,7 +382,7 @@ export const official_classes = { "ng:n": "Email", "ng:a": "Email content and headers", "ng:x": { - "email": "http://www.invincea.com/ontologies/icas/1.0/email#" //https://raw.githubusercontent.com/twosixlabs/icas-ontology/master/ontology/email.ttl + "email": "http://www.invincea.com/ontologies/icas/1.0/email#" //https://raw.githubusercontent.com/twosixlabs/icas-ontology/master/ontology/email.ttl // https://www.semanticdesktop.org/ontologies/2007/03/22/nmo/ }, "ng:compat": ["file:iana:message:rfc822","file:iana:multipart:related"], }, diff --git a/ng-sdk-js/.gitignore b/ng-sdk-js/.gitignore new file mode 100644 index 0000000..e2ae7c4 --- /dev/null +++ b/ng-sdk-js/.gitignore @@ -0,0 +1,3 @@ +pkg/* +pkg-node/* +web/* \ No newline at end of file diff --git a/ng-sdk-js/Cargo.toml b/ng-sdk-js/Cargo.toml index fdb9e8c..86b3bef 100644 --- a/ng-sdk-js/Cargo.toml +++ b/ng-sdk-js/Cargo.toml @@ -16,6 +16,14 @@ rust-version.workspace = true [package.metadata.wasm-pack.profile.release] wasm-opt = false +[package.metadata.scripts] +appdev = "rm -r pkg && wasm-pack build --target bundler" +app = "rm -r pkg && wasm-pack build --target bundler" +nodedev = "rm -r pkg-node && wasm-pack build --dev -t nodejs -d pkg-node && node prepare-node.js" +node = "rm -r pkg-node && wasm-pack build -t nodejs -d pkg-node && node prepare-node.js" +web = "rm -r web && wasm-pack build --target web -d web" +webdev = "rm -r web && wasm-pack build --dev --target web -d web" + [lib] crate-type = ["cdylib"] diff --git a/ng-sdk-js/DEV.md b/ng-sdk-js/DEV.md index f583ca9..bb37b52 100644 --- a/ng-sdk-js/DEV.md +++ b/ng-sdk-js/DEV.md @@ -14,11 +14,11 @@ JS/WASM crate containing the SDK of NextGraph This crate is composed of -- the npm package `ng-sdk-js` which is the SDK -- an example of web app using the ESmodule and webpack as bundler `app-web` -- an example of React web app `app-react` -- an example of node-js app `app-node` -- `index.html` an example of vanilla JS usage of the SDK +- the npm package `ng-sdk-js` which is the SDK +- an example of web app using the ESmodule and webpack as bundler `app-web` +- an example of React web app `app-react` +- an example of node-js app `app-node` +- `index.html` an example of vanilla JS usage of the SDK ## Support @@ -31,27 +31,37 @@ And our community forum where you can ask questions is here [https://forum.nextg Read our [getting started guide](https://docs.nextgraph.org/en/getting-started/). ``` +// for nodejs +npm i nextgraph +// or for browser (not published to npm yet) npm i ng-sdk-js ``` ## For contributors +First of all, run: + +``` +cargo install cargo-run-script +``` + We recommend contributors to use the production build, as the creation and opening of wallets is very slow in the dev build. Only use the dev build when debugging the sdk. see the next chapter for the production build. Please note that the dev and prod builds share the same output folder, they thus override each other. When building the app, be sure to have the production build of the SDK in the output folder. ``` -wasm-pack build --dev --target bundler +// for the app sdk (browser) +cargo run-script appdev -wasm-pack build --dev -t nodejs -d pkg-node -node prepare-node.js +// for the nodejs sdk +cargo run-script nodedev ``` For testing in vanilla JS ``` -wasm-pack build --dev --target web -d web +cargo run-script webdev python3 -m http.server // open http://localhost:8000 @@ -66,15 +76,10 @@ wasm-pack test --chrome --headless ## Production build ``` -wasm-pack build --target bundler +cargo run-script app tar --exclude .DS_Store -zcvf pkg.tar.gz pkg -wasm-pack build -t nodejs -d pkg-node -wasm-pack build --target web -d web -node prepare-node.js -cd pkg -npm publish --access=public -cd ../pkg-node -npm publish --access=public +cargo run-script node +cargo run-script web ``` ### Example Plain JS web app @@ -83,7 +88,8 @@ npm publish --access=public cd ../app-web // for local development npm install --no-save ../pkg -// or, for install from npm registry: npm install +// or, for installation from npm registry: npm install +// then: npm start ``` @@ -121,13 +127,12 @@ additional terms or conditions.s Licensed under either of -- Apache License, Version 2.0 ([LICENSE-APACHE2](LICENSE-APACHE2) or http://www.apache.org/licenses/LICENSE-2.0) -- MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) - at your option. +- Apache License, Version 2.0 ([LICENSE-APACHE2](LICENSE-APACHE2) or http://www.apache.org/licenses/LICENSE-2.0) +- MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) + at your option. `SPDX-License-Identifier: Apache-2.0 OR MIT` --- NextGraph received funding through the [NGI Assure Fund](https://nlnet.nl/assure) and the [NGI Zero Commons Fund](https://nlnet.nl/commonsfund/), both funds established by [NLnet](https://nlnet.nl/) Foundation with financial support from the European Commission's [Next Generation Internet](https://ngi.eu/) programme, under the aegis of DG Communications Networks, Content and Technology under grant agreements No 957073 and No 101092990, respectively. - diff --git a/ng-sdk-js/app-react/README.md b/ng-sdk-js/app-react/README.md index 57b4c16..8773462 100644 --- a/ng-sdk-js/app-react/README.md +++ b/ng-sdk-js/app-react/README.md @@ -16,7 +16,7 @@ Build the JS SDK ``` cd .. -wasm-pack build --target bundler +cargo run-script app ``` ``` @@ -31,13 +31,12 @@ Open this URL in browser : [http://localhost:8080](http://localhost:8080) Licensed under either of -- Apache License, Version 2.0 ([LICENSE-APACHE2](LICENSE-APACHE2) or http://www.apache.org/licenses/LICENSE-2.0) -- MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) - at your option. +- Apache License, Version 2.0 ([LICENSE-APACHE2](LICENSE-APACHE2) or http://www.apache.org/licenses/LICENSE-2.0) +- MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) + at your option. `SPDX-License-Identifier: Apache-2.0 OR MIT` --- NextGraph received funding through the [NGI Assure Fund](https://nlnet.nl/assure) and the [NGI Zero Commons Fund](https://nlnet.nl/commonsfund/), both funds established by [NLnet](https://nlnet.nl/) Foundation with financial support from the European Commission's [Next Generation Internet](https://ngi.eu/) programme, under the aegis of DG Communications Networks, Content and Technology under grant agreements No 957073 and No 101092990, respectively. - diff --git a/ng-sdk-js/app-web/README.md b/ng-sdk-js/app-web/README.md index dbd2032..a6a264c 100644 --- a/ng-sdk-js/app-web/README.md +++ b/ng-sdk-js/app-web/README.md @@ -16,7 +16,7 @@ Build the JS SDK ``` cd .. -wasm-pack build --target bundler +cargo run-script app ``` ``` @@ -31,13 +31,12 @@ Open this URL in browser : [http://localhost:8080](http://localhost:8080) Licensed under either of -- Apache License, Version 2.0 ([LICENSE-APACHE2](LICENSE-APACHE2) or http://www.apache.org/licenses/LICENSE-2.0) -- MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) - at your option. +- Apache License, Version 2.0 ([LICENSE-APACHE2](LICENSE-APACHE2) or http://www.apache.org/licenses/LICENSE-2.0) +- MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) + at your option. `SPDX-License-Identifier: Apache-2.0 OR MIT` --- NextGraph received funding through the [NGI Assure Fund](https://nlnet.nl/assure) and the [NGI Zero Commons Fund](https://nlnet.nl/commonsfund/), both funds established by [NLnet](https://nlnet.nl/) Foundation with financial support from the European Commission's [Next Generation Internet](https://ngi.eu/) programme, under the aegis of DG Communications Networks, Content and Technology under grant agreements No 957073 and No 101092990, respectively. - diff --git a/ng-sdk-js/prepare-node.js b/ng-sdk-js/prepare-node.js index a95cbbd..17158a3 100644 --- a/ng-sdk-js/prepare-node.js +++ b/ng-sdk-js/prepare-node.js @@ -6,7 +6,10 @@ const PATH_README = './pkg-node/README.md'; const pkg_json = fs.readFileSync(PATH); let pkg = JSON.parse(pkg_json) pkg.name = "nextgraph"; +pkg.version = "0.1.1-alpha.1"; pkg.description = "nodeJS SDK of NextGraph"; +pkg.files.push("ng_sdk_js_bg.wasm.d.ts"); +pkg.files.push("snippets/**/*.js"); fs.writeFileSync(PATH, JSON.stringify(pkg, null, 2), 'utf8'); fs.readFile(PATH_README, 'utf8', function (err,data) {