|
| 1 | +#!/usr/bin/env node |
| 2 | + |
| 3 | +// Copyright 2019-2023 Tauri Programme within The Commons Conservancy |
| 4 | +// SPDX-License-Identifier: Apache-2.0 |
| 5 | +// SPDX-License-Identifier: MIT |
| 6 | + |
| 7 | +import { readFileSync, readdirSync } from 'fs' |
| 8 | +import { join } from 'path' |
| 9 | + |
| 10 | +/* const ignorePackages = [ |
| 11 | + 'api-example', |
| 12 | + 'api-example-js', |
| 13 | + 'deep-link-example', |
| 14 | + 'deep-link-example-js' |
| 15 | +] */ |
| 16 | + |
| 17 | +const rsOnly = ['localhost', 'persisted-scope'] |
| 18 | + |
| 19 | +function checkChangeFiles(changeFiles) { |
| 20 | + let code = 0 |
| 21 | + |
| 22 | + for (const file of changeFiles) { |
| 23 | + const content = readFileSync(file, 'utf8') |
| 24 | + const [frontMatter] = /^---[\s\S.]*---\n/i.exec(content) |
| 25 | + const packages = frontMatter |
| 26 | + .split('\n') |
| 27 | + .filter((l) => !(l === '---' || !l)) |
| 28 | + .map((l) => l.replace(/('|")/g, '').split(':')) |
| 29 | + |
| 30 | + const rsPackages = Object.fromEntries( |
| 31 | + packages |
| 32 | + .filter((v) => !v[0].endsWith('-js')) |
| 33 | + .map((v) => [v[0], v[1].trim()]) |
| 34 | + ) |
| 35 | + const jsPackages = Object.fromEntries( |
| 36 | + packages |
| 37 | + .filter((v) => v[0].endsWith('-js')) |
| 38 | + .map((v) => [v[0].slice(0, -3), v[1].trim()]) |
| 39 | + ) |
| 40 | + |
| 41 | + for (const pkg in rsPackages) { |
| 42 | + if (rsOnly.includes(pkg)) continue |
| 43 | + |
| 44 | + if (!jsPackages[pkg]) { |
| 45 | + console.error( |
| 46 | + `Missing "${rsPackages[pkg]}" bump for JS package "${pkg}-js" in ${file}.` |
| 47 | + ) |
| 48 | + code = 1 |
| 49 | + } else if (rsPackages[pkg] != jsPackages[pkg]) { |
| 50 | + console.error( |
| 51 | + `"${pkg}" and "${pkg}-js" have different version bumps in ${file}.` |
| 52 | + ) |
| 53 | + code = 1 |
| 54 | + } |
| 55 | + } |
| 56 | + |
| 57 | + for (const pkg in jsPackages) { |
| 58 | + if (!rsPackages[pkg]) { |
| 59 | + console.error( |
| 60 | + `Missing "${jsPackages[pkg]}" bump for Rust package "${pkg}" in ${file}.` |
| 61 | + ) |
| 62 | + code = 1 |
| 63 | + } else if (rsPackages[pkg] != jsPackages[pkg]) { |
| 64 | + console.error( |
| 65 | + `"${pkg}" and "${pkg}-js" have different version bumps in ${file}.` |
| 66 | + ) |
| 67 | + code = 1 |
| 68 | + } |
| 69 | + } |
| 70 | + } |
| 71 | + |
| 72 | + process.exit(code) |
| 73 | +} |
| 74 | + |
| 75 | +const [_bin, _script, ...files] = process.argv |
| 76 | + |
| 77 | +if (files.length > 0) { |
| 78 | + checkChangeFiles( |
| 79 | + files.filter((f) => f.toLowerCase() !== '.changes/readme.md') |
| 80 | + ) |
| 81 | +} else { |
| 82 | + const changeFiles = readdirSync('.changes') |
| 83 | + .filter((f) => f.endsWith('.md') && f.toLowerCase() !== 'readme.md') |
| 84 | + .map((p) => join('.changes', p)) |
| 85 | + checkChangeFiles(changeFiles) |
| 86 | +} |
0 commit comments