Skip to content

Commit

Permalink
Merge pull request #4 from dvishal485/main
Browse files Browse the repository at this point in the history
add WASM
  • Loading branch information
dvishal485 authored Aug 21, 2024
2 parents 59cb228 + 12d17a1 commit 5a77f5b
Show file tree
Hide file tree
Showing 10 changed files with 375 additions and 136 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,9 @@ jobs:

- name: Get to target dir
run: cargo install --path .

- name: Generate node package using wasm-pack
run: wasm-pack build -t nodejs --features wasm

- name: Update node package
run: rsync -avz --delete pkg/ ~/notification-system-wasm
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/target
node_modules
143 changes: 143 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,20 @@ edition = "2021"
[dependencies]
select = "0.6.0"
serde = { version = "1.0.208", features = ["derive"] }
serde-wasm-bindgen = { version = "0.6.5", optional = true }
serde_json = "1.0.125"
tsify = { version = "0.4.5", optional = true }
url = "2.5.2"
wasm-bindgen = { version = "0.2.93", optional = true }

[lib]
crate-type = ["cdylib", "rlib"]
name = "notification_wrapper"
path = "src/scrape.rs"

[[bin]]
name = "notification-system"
path = "src/main.rs"

[features]
wasm = ["dep:wasm-bindgen", "dep:tsify", "dep:serde-wasm-bindgen"]
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,34 @@
# notification-system

Web scraper of the DTU Website as a base to create the notification alerts system

## Build

For building binary which prints `json` response, use the following command:

```bash
cargo build --release
```

For wasm build (to use it as `npm` package), build with the following command

```bash
wasm-pack build -t nodejs --features wasm
```

## Installation

Install as a binary

```bash
cargo install --path .
```

Install as npm package

```bash
wasm-pack build -t nodejs --features wasm # this builds and output a pkg/ directory, copy this to root of your node project

# with pkg/ folder in root of your node project
npm i pkg
```
10 changes: 10 additions & 0 deletions example/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import notification_system from "notification-system";

let scraped_json = await fetch("https://dtu.ac.in/")
.then(response => {
return response.text();
})
.then(notification_system.scrape)
.then((info) => JSON.stringify(info, null, 2));

console.log(scraped_json);
24 changes: 24 additions & 0 deletions example/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions example/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "example",
"version": "1.0.0",
"type": "module",
"main": "index.js",
"scripts": {
"start": "node index.js"
},
"author": "",
"license": "ISC",
"description": "",
"dependencies": {
"notification-system": "file:../pkg"
}
}
Loading

0 comments on commit 5a77f5b

Please sign in to comment.