feature/fix-deployment-script
claude/smbcloud-github-app-k9641p
development
feature/apps
feature/build-release
feature/ci-docs
feature/ci-ruby-gems
feature/cicd
feature/completion
feature/dist-nuget
feature/fix-ci-sdk-pypi-rubygem
feature/fix-clippy-on-stable-channel
feature/fix-deployment-script
feature/github-email
feature/gresiq-v1
feature/project-new-structure
feature/rsync-deploy
feature/ruby-runner
feature/sdk-npm
feature/sdk-workflows
feature/smbcloud-cli-release-npm
feature/smbcloud-deploy
feature/wasm
main
release/v0.7.4
| 1 | import { cpSync, existsSync, mkdirSync, readFileSync, rmSync } from "node:fs"; |
| 2 | import { resolve } from "node:path"; |
| 3 | import { execFileSync } from "node:child_process"; |
| 4 | |
| 5 | const packageDir = resolve(import.meta.dirname); |
| 6 | const repoRoot = resolve(packageDir, "../../.."); |
| 7 | const crateDir = resolve(repoRoot, "crates/smbcloud-auth-sdk-wasm"); |
| 8 | const stageDir = resolve(repoRoot, "target/npm/sdk-auth"); |
| 9 | const distDir = resolve(packageDir, "dist"); |
| 10 | const npmPackageJsonPath = resolve(packageDir, "package.json"); |
| 11 | const cargoTomlPath = resolve(crateDir, "Cargo.toml"); |
| 12 | |
| 13 | const stageFiles = [ |
| 14 | "smbcloud_auth_wasm.js", |
| 15 | "smbcloud_auth_wasm.d.ts", |
| 16 | "smbcloud_auth_wasm_bg.wasm", |
| 17 | "smbcloud_auth_wasm_bg.wasm.d.ts", |
| 18 | ]; |
| 19 | |
| 20 | const npmPackage = JSON.parse(readFileSync(npmPackageJsonPath, "utf8")); |
| 21 | const cargoToml = readFileSync(cargoTomlPath, "utf8"); |
| 22 | const cargoVersionMatch = cargoToml.match(/^version\s*=\s*"([^"]+)"/m); |
| 23 | |
| 24 | if (!cargoVersionMatch) { |
| 25 | throw new Error(`Unable to find version in ${cargoTomlPath}`); |
| 26 | } |
| 27 | |
| 28 | const crateVersion = cargoVersionMatch[1]; |
| 29 | const npmVersion = npmPackage.version; |
| 30 | |
| 31 | if (crateVersion !== npmVersion) { |
| 32 | throw new Error( |
| 33 | [ |
| 34 | "Version mismatch for @smbcloud/sdk-auth.", |
| 35 | `npm package version: ${npmVersion}`, |
| 36 | `Rust crate version: ${crateVersion}`, |
| 37 | "Update sdk/npm/smbcloud-auth/package.json or crates/smbcloud-auth-sdk-wasm/Cargo.toml so they match before publishing.", |
| 38 | ].join("\n"), |
| 39 | ); |
| 40 | } |
| 41 | |
| 42 | rmSync(stageDir, { recursive: true, force: true }); |
| 43 | rmSync(distDir, { recursive: true, force: true }); |
| 44 | mkdirSync(stageDir, { recursive: true }); |
| 45 | mkdirSync(distDir, { recursive: true }); |
| 46 | |
| 47 | execFileSync( |
| 48 | "wasm-pack", |
| 49 | ["build", crateDir, "--target", "web", "--out-dir", stageDir], |
| 50 | { cwd: repoRoot, stdio: "inherit" }, |
| 51 | ); |
| 52 | |
| 53 | for (const file of stageFiles) { |
| 54 | const source = resolve(stageDir, file); |
| 55 | const destination = resolve(distDir, file); |
| 56 | |
| 57 | if (!existsSync(source)) { |
| 58 | throw new Error(`Missing generated artifact: ${source}`); |
| 59 | } |
| 60 | |
| 61 | cpSync(source, destination); |
| 62 | } |
| 63 | |
| 64 | console.log("Prepared @smbcloud/sdk-auth package in", packageDir); |