Skip to content

Commit f499795

Browse files
committed
feat: publish to npm
1 parent 1723cee commit f499795

10 files changed

Lines changed: 333 additions & 369 deletions

File tree

.github/scripts/publish-npm.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/bash
2+
3+
# Install jco
4+
npm install -g @bytecodealliance/jco
5+
6+
# Variables
7+
safe_component=$(echo $1 | tr '-' '_')
8+
path="target/wasm32-wasip1/release/$safe_component.wasm"
9+
version=$(grep "^version = " "crates/$1/Cargo.toml" | cut -d'"' -f2)
10+
11+
# Clean up
12+
rm -rf npm/$1
13+
mkdir -p npm/$1
14+
cd npm/$1
15+
16+
# Create package.json
17+
cat > package.json << EOF
18+
{
19+
"name": "@wassemble/$1",
20+
"version": "$version",
21+
"main": "index.js",
22+
"repository": {
23+
"type": "git",
24+
"url": "https://github.com/wassemble/components.git"
25+
},
26+
"author": "Wassemble (https://github.com/wassemble/components)",
27+
"license": "Apache-2.0",
28+
"description": "WebAssembly component for $1"
29+
}
30+
EOF
31+
32+
# Generate README.md
33+
cd ../..
34+
wit-bindgen markdown crates/$1/wit/world.wit --html-in-md
35+
mv $1.md npm/$1/README.md
36+
37+
# Transpile component
38+
npx jco transpile $path -o npm/$1
39+
40+
# Publish
41+
cd npm/$1
42+
npm publish --access public --provenance

.github/workflows/cd.yml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ permissions:
1212
contents: read
1313
packages: write
1414
id-token: write
15+
actions: read
1516

1617
jobs:
1718
detect-changes:
@@ -32,6 +33,7 @@ jobs:
3233
runs-on: ubuntu-latest
3334
env:
3435
GH_TOKEN: ${{ github.token }}
36+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
3537
strategy:
3638
matrix:
3739
component: ${{ fromJson(needs.detect-changes.outputs.matrix).component }}
@@ -40,8 +42,8 @@ jobs:
4042
- uses: actions/checkout@v4
4143
- uses: dtolnay/rust-toolchain@nightly
4244
- uses: Swatinem/rust-cache@v2
43-
- uses: cargo-bins/cargo-binstall@main
44-
- run: cargo binstall --locked --force cargo-component
45+
- run: cargo install --locked cargo-component
46+
- run: cargo install --locked wit-bindgen-cli
4547

4648
# Configure registry
4749
- run: |
@@ -55,3 +57,12 @@ jobs:
5557
# Publish
5658
- run: |
5759
cargo component publish -p ${{ matrix.component }} --config config.toml
60+
61+
# NPM package
62+
- uses: actions/setup-node@v4
63+
with:
64+
node-version: '20.x'
65+
registry-url: 'https://registry.npmjs.org'
66+
- run: .github/scripts/publish-npm.sh ${{ matrix.component }}
67+
env:
68+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

.github/workflows/ci.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@ jobs:
1919
with:
2020
components: clippy, rustfmt
2121
- uses: Swatinem/rust-cache@v2
22-
- uses: cargo-bins/cargo-binstall@main
23-
- run: cargo binstall --locked cargo-machete
24-
- run: cargo binstall --locked cargo-sort-derives
22+
- run: cargo install --locked cargo-machete
23+
- run: cargo install --locked cargo-sort-derives
2524

2625
# Checks
2726
- run: cargo +nightly fmt --check

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)