From f1c01f9d47ae1e14b6fe9212e4d2a1f9b52fc8c2 Mon Sep 17 00:00:00 2001 From: Niko PLP Date: Sat, 9 Sep 2023 15:29:39 +0300 Subject: [PATCH] automatic including of sdk in web app --- README.md | 6 +-- ng-app/README.md | 19 ++++---- ng-app/{index.html => index-native.html} | 0 ng-app/index-web.html | 61 ++++++++++++++++++++++++ ng-app/package.json | 15 +++--- ng-app/src/App.svelte | 2 - ng-app/src/main-web.ts | 19 ++++++++ ng-sdk-js/README.md | 13 +++-- pnpm-lock.yaml | 33 +++++++++++++ 9 files changed, 143 insertions(+), 25 deletions(-) rename ng-app/{index.html => index-native.html} (100%) create mode 100644 ng-app/index-web.html create mode 100644 ng-app/src/main-web.ts diff --git a/README.md b/README.md index 9fa0af6..fba57ff 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,7 @@ cargo install wasm-pack --git https://github.com/rustwasm/wasm-pack.git --rev c2 cargo install cargo-watch // 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: git clone https://git.nextgraph.org/NextGraph/nextgraph-rs.git cd nextgraph-rs cargo build ``` @@ -58,7 +59,7 @@ The crates are organized as follow : - ng-wallet : keeps the secret keys of all identities of the user in a safe wallet - [ng-sdk-js](ng-sdk-js/README.md) : contains the JS SDK, with example apps: web app, react app, or node service. - [ng-app](ng-app/README.md) : all the native apps, based on Tauri, and the web app. -- [ngone](ngone/README.md) : server for nextgraph.one (boostrap into the right app) +- [ngone](ngone/README.md) : server for nextgraph.one (helps user bootstrap into the right app) - [ngaccount](ngaccount/README.md) : server for nextgraph's Broker Service Provider account manager. ### Run @@ -125,7 +126,6 @@ Otherwise, build from source the single-file release of ng-app npm install -g pnpm cd ng-sdk-js wasm-pack build --target bundler -// uncomment line 14 of ng-app/src/App.svelte: import * as api from "ng-sdk-js"; cd ../ng-app pnpm install pnpm webfilebuild @@ -146,7 +146,7 @@ The CLI tool can be obtained with : cargo build -r -p ngcli ``` -you can then use the binary `target/release/ngd` +you can then use the binary `target/release/ngcli` For usage, see the documentation [here](ngd/README.md). diff --git a/ng-app/README.md b/ng-app/README.md index 90a56ce..7964c05 100644 --- a/ng-app/README.md +++ b/ng-app/README.md @@ -34,22 +34,23 @@ pnpm webdev #### Prod -``` -pnpm webbuild -// then the application is available in dist-web folder -// can be served with: -cd dist-web ; python3 -m http.server -``` - -in order to build a self-contained html file, useful for offline use, do: +this will produce a single html file embedding all the resources. this is what you need for production ``` -// uncomment line 14 of src/App.svelte: import * as api from "ng-sdk-js"; pnpm webfilebuild // single file is available in dist-file/index.html ``` +alternatively, to obtain a regular dist folder with all resources (we dont use it anymore): + +``` +pnpm webbuild +// then the application is available in dist-web folder +// can be served with: +cd dist-web ; python3 -m http.server +``` + ## Desktop ``` diff --git a/ng-app/index.html b/ng-app/index-native.html similarity index 100% rename from ng-app/index.html rename to ng-app/index-native.html diff --git a/ng-app/index-web.html b/ng-app/index-web.html new file mode 100644 index 0000000..23d0399 --- /dev/null +++ b/ng-app/index-web.html @@ -0,0 +1,61 @@ + + + + + + + + NextGraph + + + +
+ + + diff --git a/ng-app/package.json b/ng-app/package.json index 06b3900..06ddbb4 100644 --- a/ng-app/package.json +++ b/ng-app/package.json @@ -4,13 +4,13 @@ "version": "0.1.0", "type": "module", "scripts": { - "dev": "vite", - "webdev": "cross-env NG_APP_WEB=1 TAURI_DEBUG=1 vite", - "webbuild": "cross-env NG_APP_WEB=1 vite build && rm -f ./dist-web/assets/*.svg && tar --exclude .DS_Store -zcvf dist-web.tar.gz dist-web", - "webfilebuild": "cross-env NG_APP_WEB=1 NG_APP_FILE=1 vite build && node prepare-app-file.cjs && rm -rf ./dist-file/assets && tar --exclude .DS_Store -zcvf dist-file.tar.gz dist-file", - "webfilebuilddebug": "cross-env NG_APP_WEB=1 NG_APP_FILE=1 TAURI_DEBUG=1 vite build -m debug", - "build": "vite build && rm -f ./dist/assets/*.svg", - "buildfile": "cross-env NG_APP_FILE=1 vite build && rm -rf ./dist/assets && tar --exclude .DS_Store -zcvf dist.tar.gz dist", + "dev": "shx cp index-native.html index.html && vite", + "webdev": "shx cp index-web.html index.html && cross-env NG_APP_WEB=1 TAURI_DEBUG=1 vite", + "webbuild": "shx cp index-web.html index.html && cross-env NG_APP_WEB=1 vite build && rm -f ./dist-web/assets/*.svg && tar --exclude .DS_Store -zcvf dist-web.tar.gz dist-web", + "webfilebuild": "shx cp index-web.html index.html && cross-env NG_APP_WEB=1 NG_APP_FILE=1 vite build && node prepare-app-file.cjs && rm -rf ./dist-file/assets && tar --exclude .DS_Store -zcvf dist-file.tar.gz dist-file", + "webfilebuilddebug": "shx cp index-web.html index.html && cross-env NG_APP_WEB=1 NG_APP_FILE=1 TAURI_DEBUG=1 vite build -m debug", + "build": "shx cp index-native.html index.html && vite build && rm -f ./dist/assets/*.svg", + "buildfile": "shx cp index-native.html index.html && cross-env NG_APP_FILE=1 vite build && rm -rf ./dist/assets && tar --exclude .DS_Store -zcvf dist.tar.gz dist", "preview": "vite preview", "check": "svelte-check --tsconfig ./tsconfig.json", "tauri": "tauri" @@ -38,6 +38,7 @@ "node-gzip": "^1.1.2", "postcss": "^8.4.23", "postcss-load-config": "^4.0.1", + "shx": "^0.3.4", "svelte": "^3.54.0", "svelte-check": "^3.0.0", "svelte-preprocess": "^5.0.3", diff --git a/ng-app/src/App.svelte b/ng-app/src/App.svelte index 6997d0e..4ee6ffc 100644 --- a/ng-app/src/App.svelte +++ b/ng-app/src/App.svelte @@ -10,8 +10,6 @@ -->