Terminal Markdown previewer — GUI-like experience.
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat: publish npm packages

RivoLink 1162ab15 3df4536e

+259 -2
+31
.github/workflows/npm-publish.yml
··· 1 + name: NPM Publish 2 + 3 + on: 4 + workflow_run: 5 + workflows: ["Release Build"] 6 + types: [completed] 7 + 8 + jobs: 9 + publish: 10 + name: Publish npm packages 11 + runs-on: ubuntu-latest 12 + if: ${{ github.event.workflow_run.conclusion == 'success' }} 13 + 14 + permissions: 15 + contents: read 16 + id-token: write 17 + 18 + steps: 19 + - name: Checkout repository 20 + uses: actions/checkout@v4 21 + 22 + - name: Setup Node.js 23 + uses: actions/setup-node@v4 24 + with: 25 + node-version: "20" 26 + registry-url: "https://registry.npmjs.org" 27 + 28 + - name: Publish all packages 29 + run: bash npm/scripts/publish.sh "${{ github.event.workflow_run.head_branch }}" 30 + env: 31 + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
+4
.gitignore
··· 7 7 /target 8 8 **/*.rs.bk 9 9 10 + # npm platform binaries 11 + npm/platforms/*/leaf 12 + npm/platforms/*/leaf.exe 13 + 10 14 # Logs 11 15 *.log
+21 -1
README.md
··· 22 22 irm https://raw.githubusercontent.com/RivoLink/leaf/main/scripts/install.ps1 | iex 23 23 ``` 24 24 25 + npm: 26 + 27 + ```bash 28 + npm install -g @rivolink/leaf 29 + ``` 30 + 25 31 Verify the installation: 26 32 27 33 ```bash ··· 30 36 31 37 ## Update 32 38 33 - Update an existing installation to the latest published release: 39 + Update an existing installation to the latest published release. 40 + 41 + Self: 34 42 35 43 ```bash 36 44 leaf --update ··· 39 47 `leaf --update` downloads the matching published asset, verifies it against the published `checksums.txt` SHA256, and then installs it. 40 48 41 49 On Windows, if replacing the running `.exe` is blocked by the OS, rerun the PowerShell installer from the install section. 50 + 51 + npm: 52 + 53 + ```bash 54 + npm update -g @rivolink/leaf 55 + ``` 42 56 43 57 ## Build 44 58 ··· 193 207 ```powershell 194 208 Remove-Item "$env:LOCALAPPDATA\Programs\leaf\leaf.exe" -Force 195 209 ``` 210 + 211 + npm: 212 + 213 + ```bash 214 + npm uninstall -g @rivolink/leaf 215 + ```
+43
npm/bin/leaf.js
··· 1 + #!/usr/bin/env node 2 + 3 + const path = require("path"); 4 + const { spawnSync } = require("child_process"); 5 + 6 + const PLATFORM_PACKAGES = { 7 + "linux-x64": "@rivolink/leaf-linux-x64", 8 + "linux-arm64": "@rivolink/leaf-linux-arm64", 9 + "darwin-x64": "@rivolink/leaf-darwin-x64", 10 + "darwin-arm64": "@rivolink/leaf-darwin-arm64", 11 + "win32-x64": "@rivolink/leaf-win32-x64", 12 + "android-arm64": "@rivolink/leaf-android-arm64", 13 + }; 14 + 15 + const key = `${process.platform}-${process.arch}`; 16 + const pkgName = PLATFORM_PACKAGES[key]; 17 + 18 + if (!pkgName) { 19 + console.error(`[leaf] Unsupported platform: ${key}`); 20 + process.exit(1); 21 + } 22 + 23 + let binaryPath; 24 + try { 25 + const isWindows = process.platform === "win32"; 26 + const binaryName = isWindows ? "leaf.exe" : "leaf"; 27 + binaryPath = require.resolve(path.join(pkgName, binaryName)); 28 + } catch { 29 + console.error(`[leaf] Binary package not found for ${key}.`); 30 + console.error(`[leaf] Reinstall: npm install -g @rivolink/leaf`); 31 + process.exit(1); 32 + } 33 + 34 + const result = spawnSync(binaryPath, process.argv.slice(2), { 35 + stdio: "inherit", 36 + windowsHide: false, 37 + env: { 38 + ...process.env, 39 + LEAF_CURRENT_EXE: binaryPath, 40 + }, 41 + }); 42 + 43 + process.exit(result.status ?? 1);
+27
npm/package.json
··· 1 + { 2 + "name": "@rivolink/leaf", 3 + "version": "0.0.0", 4 + "description": "Terminal Markdown previewer — GUI-like experience.", 5 + "keywords": ["markdown", "terminal", "tui", "cli", "preview"], 6 + "homepage": "https://github.com/RivoLink/leaf", 7 + "repository": { 8 + "type": "git", 9 + "url": "https://github.com/RivoLink/leaf.git" 10 + }, 11 + "license": "MIT", 12 + "bin": { 13 + "leaf": "./bin/leaf.js" 14 + }, 15 + "files": ["bin/leaf.js"], 16 + "optionalDependencies": { 17 + "@rivolink/leaf-linux-x64": "0.0.0", 18 + "@rivolink/leaf-linux-arm64": "0.0.0", 19 + "@rivolink/leaf-darwin-x64": "0.0.0", 20 + "@rivolink/leaf-darwin-arm64": "0.0.0", 21 + "@rivolink/leaf-win32-x64": "0.0.0", 22 + "@rivolink/leaf-android-arm64": "0.0.0" 23 + }, 24 + "engines": { 25 + "node": ">=14" 26 + } 27 + }
+12
npm/platforms/android-arm64/package.json
··· 1 + { 2 + "name": "@rivolink/leaf-android-arm64", 3 + "version": "0.0.0", 4 + "description": "leaf binary for android arm64", 5 + "os": ["android"], 6 + "cpu": ["arm64"], 7 + "license": "MIT", 8 + "repository": { 9 + "type": "git", 10 + "url": "https://github.com/RivoLink/leaf.git" 11 + } 12 + }
+12
npm/platforms/darwin-arm64/package.json
··· 1 + { 2 + "name": "@rivolink/leaf-darwin-arm64", 3 + "version": "0.0.0", 4 + "description": "leaf binary for darwin arm64", 5 + "os": ["darwin"], 6 + "cpu": ["arm64"], 7 + "license": "MIT", 8 + "repository": { 9 + "type": "git", 10 + "url": "https://github.com/RivoLink/leaf.git" 11 + } 12 + }
+12
npm/platforms/darwin-x64/package.json
··· 1 + { 2 + "name": "@rivolink/leaf-darwin-x64", 3 + "version": "0.0.0", 4 + "description": "leaf binary for darwin x64", 5 + "os": ["darwin"], 6 + "cpu": ["x64"], 7 + "license": "MIT", 8 + "repository": { 9 + "type": "git", 10 + "url": "https://github.com/RivoLink/leaf.git" 11 + } 12 + }
+12
npm/platforms/linux-arm64/package.json
··· 1 + { 2 + "name": "@rivolink/leaf-linux-arm64", 3 + "version": "0.0.0", 4 + "description": "leaf binary for linux arm64", 5 + "os": ["linux"], 6 + "cpu": ["arm64"], 7 + "license": "MIT", 8 + "repository": { 9 + "type": "git", 10 + "url": "https://github.com/RivoLink/leaf.git" 11 + } 12 + }
+12
npm/platforms/linux-x64/package.json
··· 1 + { 2 + "name": "@rivolink/leaf-linux-x64", 3 + "version": "0.0.0", 4 + "description": "leaf binary for linux x64", 5 + "os": ["linux"], 6 + "cpu": ["x64"], 7 + "license": "MIT", 8 + "repository": { 9 + "type": "git", 10 + "url": "https://github.com/RivoLink/leaf.git" 11 + } 12 + }
+12
npm/platforms/win32-x64/package.json
··· 1 + { 2 + "name": "@rivolink/leaf-win32-x64", 3 + "version": "0.0.0", 4 + "description": "leaf binary for win32 x64", 5 + "os": ["win32"], 6 + "cpu": ["x64"], 7 + "license": "MIT", 8 + "repository": { 9 + "type": "git", 10 + "url": "https://github.com/RivoLink/leaf.git" 11 + } 12 + }
+57
npm/scripts/publish.sh
··· 1 + #!/usr/bin/env bash 2 + set -euo pipefail 3 + 4 + REPO="RivoLink/leaf" 5 + VERSION="${1:?Usage: publish.sh <version>}" 6 + VERSION="${VERSION#v}" 7 + 8 + declare -A BINARIES=( 9 + ["linux-x64"]= "leaf-linux-x86_64" 10 + ["linux-arm64"]= "leaf-linux-arm64" 11 + ["darwin-x64"]= "leaf-macos-x86_64" 12 + ["darwin-arm64"]= "leaf-macos-arm64" 13 + ["win32-x64"]= "leaf-windows-x86_64.exe" 14 + ["android-arm64"]="leaf-android-arm64" 15 + ) 16 + 17 + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 18 + NPM_DIR="$SCRIPT_DIR/.." 19 + 20 + npm version "$VERSION" --no-git-tag-version --prefix "$NPM_DIR" 21 + 22 + for platform in "${!BINARIES[@]}"; do 23 + binary="${BINARIES[$platform]}" 24 + pkg_dir="$NPM_DIR/platforms/$platform" 25 + 26 + echo "Publishing @rivolink/leaf-$platform@$VERSION..." 27 + 28 + npm version "$VERSION" --no-git-tag-version --prefix "$pkg_dir" 29 + 30 + url="https://github.com/$REPO/releases/download/$VERSION/$binary" 31 + echo "Downloading $url" 32 + curl -fsSL "$url" -o "$pkg_dir/$binary" 33 + 34 + if [[ "$platform" == win32* ]]; then 35 + mv "$pkg_dir/$binary" "$pkg_dir/leaf.exe" 36 + else 37 + mv "$pkg_dir/$binary" "$pkg_dir/leaf" 38 + chmod +x "$pkg_dir/leaf" 39 + fi 40 + 41 + npm publish "$pkg_dir" --access public 42 + echo "Published @rivolink/leaf-$platform@$VERSION" 43 + 44 + rm -f "$pkg_dir/leaf" "$pkg_dir/leaf.exe" 45 + done 46 + 47 + node -e " 48 + const fs = require('fs'); 49 + const pkg = JSON.parse(fs.readFileSync('$NPM_DIR/package.json', 'utf8')); 50 + for (const dep of Object.keys(pkg.optionalDependencies)) { 51 + pkg.optionalDependencies[dep] = '$VERSION'; 52 + } 53 + fs.writeFileSync('$NPM_DIR/package.json', JSON.stringify(pkg, null, 2) + '\n'); 54 + " 55 + 56 + npm publish "$NPM_DIR" --access public 57 + echo "Published @rivolink/leaf@$VERSION"
+4 -1
src/update.rs
··· 44 44 expected_asset_download_url(&release.tag_name, &release.assets, CHECKSUMS_ASSET_NAME)?; 45 45 let checksums = download_text_asset(checksums_url)?; 46 46 let expected_checksum = find_expected_checksum(&checksums, asset_name)?; 47 - let current_exe = std::env::current_exe().context("Cannot locate current executable")?; 47 + let current_exe = match std::env::var("LEAF_CURRENT_EXE") { 48 + Ok(path) => PathBuf::from(path), 49 + Err(_) => std::env::current_exe().context("Cannot locate current executable")?, 50 + }; 48 51 let temp_path = temp_download_path(&current_exe); 49 52 50 53 download_asset(download_url, &temp_path)?;