diff --git a/.github/workflows/socket.yml b/.github/workflows/socket.yml index 3bf771a..98f6b8f 100644 --- a/.github/workflows/socket.yml +++ b/.github/workflows/socket.yml @@ -19,6 +19,8 @@ concurrency: permissions: contents: read + issues: write + pull-requests: write jobs: socket-security: @@ -33,7 +35,7 @@ jobs: fetch-depth: ${{ github.event_name == 'pull_request' && 2 || 0 }} - name: Set up Python - uses: actions/setup-python@v5 + uses: actions/setup-python@v7 with: python-version: '3.12' diff --git a/CHANGELOG.md b/CHANGELOG.md index 82d3ee9..53345bc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,53 +5,39 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## Unreleased - -### Added - -* A compact **run summary** is printed to `stderr` after every run: the number - of processed shapes (along with excluded input files), the active sprite - modes with their enabled options (example, inline, stylesheet rendering), - the number of written files, the elapsed time and the shape concurrency. - -### Changed +## 3.0.0 — Vento-based sprite generation -* The progress bar line is capped at **80 characters** and at the current - terminal width. The width is re-read on every redraw, so terminals that are - resized while a run is in progress (e.g. xterm) are taken into account. +### Changed (breaking) -## 3.0.0 — Vento-based sprite generation +* Upgraded to `@svgforge/svgforge` 3.0.0, which replaces Mustache with + [Vento](https://vento.js.org). Examples and stylesheet resources now use + Vento templates; custom templates and `variables` functions may need + adjustment (see the + [svgforge changelog](https://github.com/svgforge/svgforge/blob/main/CHANGELOG.md)). ### Added -* An animated **progress bar** is shown on `stderr` while shapes are being - processed when running on an interactive terminal. It is fed by the - [`progress` event of the svgforge spriter](https://github.com/svgforge/svgforge/blob/main/docs/api.md#spriter-events); - non-TTY runs (CI, pipes, log files) print only a single summary line with - the final state instead of one line per processed shape, so CI logs stay - clean. +* A progress bar on `stderr` while shapes are processed (from the spriter's + `progress` event), capped at 80 characters and the current terminal width. + Non-TTY runs (CI, pipes) only print the final summary line. +* A compact run summary after each run: processed shapes (and excluded files), + active modes with their options, number of written files, elapsed time and + concurrency. +* `--quiet` / `-q` suppresses all non-error output. -### Changed (breaking) +### Fixed -* The underlying `@svgforge/svgforge` library was upgraded to **3.0.0**, which - replaces the Mustache templating engine with [Vento](https://vento.js.org). - Examples and CSS resources generated by the CLI now use the new Vento - templating (see the [svgforge changelog](https://github.com/svgforge/svgforge/blob/main/CHANGELOG.md) - for details — custom templates and `variables` functions may need adjustment). +* The published package ships the `lib/` directory (progress and report + modules); `files` previously listed only `bin/`. +* CLI template defaults use the new `.vto` suffix — `--dcss`, `-d` and example + rendering no longer fail against svgforge 3.0.0. +* The `./` base directory marker in an input glob works again: since glob >= 9 + strips `./`, the base directory name leaked into shape IDs. The marker is now + detected on the original pattern and removed from the shape IDs. -### Fixed +### Changed -* The CLI template defaults were updated to the new Vento suffix (`.vto`): - `--dcss`, `-d` and the example rendering previously failed with a missing - `tmpl/common/sprite.css` when used against svgforge 3.0.0. -* The `./` base directory marker works again: the documentation promises that a - literal `./` segment in an input glob (e.g. `assets/./**/*.svg`) marks the - base directory from which shape ID traversal starts, yielding IDs like - `path--to--source`. Since the switch to `fs.globSync` (and glob >= 9 in - general), the `./` was stripped from the glob results, so the base directory - name leaked into the shape IDs (`assets--path--to--source`). The marker is - now detected on the original pattern instead and the marked base directory - is removed from the shape IDs. +* Dependencies: `js-yaml` ^5.4.3 and `yargs` ^18.2.0. ## 2.0.1 — Do not re-ingest the output destination diff --git a/bin/config.yaml b/bin/config.yaml index 82799a5..5674849 100644 --- a/bin/config.yaml +++ b/bin/config.yaml @@ -12,6 +12,11 @@ log: description: Logging verbosity ("info", "verbose" or "debug") alias: l map: log +quiet: + description: Suppress all output except errors + alias: q + default: false + map: quiet shape: id: diff --git a/bin/svgforge.js b/bin/svgforge.js index e20f54c..1dbd0d2 100755 --- a/bin/svgforge.js +++ b/bin/svgforge.js @@ -552,7 +552,7 @@ async function main() { // before any progress events fire. The total is resolved from the glob // below before the add loop starts, because the queue processes shapes // while they are still being added. - const progressBar = createProgressBar(spriter); + const progressBar = createProgressBar(spriter, config.quiet); // Glob (>= 9, incl. fs.globSync) returns paths without the "./" segment, so // the base directory marker has to be detected on the original pattern. A diff --git a/lib/progress.js b/lib/progress.js index 3805c6a..a039ac4 100644 --- a/lib/progress.js +++ b/lib/progress.js @@ -27,11 +27,12 @@ const MAX_LINE_WIDTH = 80; in particular) are resized while a run is in progress. @param {object} spriter Spriter instance (listens to its `progress` events) + @param {boolean} [isQuiet] Suppress all progress output @returns {{refreshTotal: (total: number) => void, finish: () => void}} Progress bar controls */ -export function createProgressBar(spriter) { +export function createProgressBar(spriter, isQuiet = false) { const stream = process.stderr; - const tty = stream.isTTY; + const tty = stream.isTTY && !process.env.CI && !isQuiet; let lastUpdate = 0; let total = 0; let processed = 0; @@ -76,6 +77,11 @@ export function createProgressBar(spriter) { }, finish() { spriter.off('progress', onProgress); + + if (isQuiet) { + return; + } + if (tty) { stream.write('\n'); } else if (total > 0) { diff --git a/package.json b/package.json index 2edb821..6cb0867 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,7 @@ "test:coverage": "mkdir -p coverage && node --test --experimental-test-coverage --test-reporter=spec --test-reporter-destination=stdout --test-reporter=lcov --test-reporter-destination=coverage/lcov.info" }, "dependencies": { - "@svgforge/svgforge": "3.0.0-beta.1", + "@svgforge/svgforge": "^3.0.0", "js-yaml": "^5.4.3", "vinyl": "^3.0.1", "yargs": "^18.2.0" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 4da9e98..14b2dc6 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -9,8 +9,8 @@ importers: .: dependencies: '@svgforge/svgforge': - specifier: 3.0.0-beta.1 - version: 3.0.0-beta.1 + specifier: ^3.0.0 + version: 3.0.0 js-yaml: specifier: ^5.4.3 version: 5.4.3 @@ -307,8 +307,8 @@ packages: peerDependencies: eslint: ^9.0.0 || ^10.0.0 - '@svgforge/svgforge@3.0.0-beta.1': - resolution: {integrity: sha512-Iaa/sTfvV5NCJq5qHvLHwxoNiw8icthhFFyAWJFRXududICwu10NZiyR1PYOuF3yP7JrRZzr70/7i8CGQxfKmw==} + '@svgforge/svgforge@3.0.0': + resolution: {integrity: sha512-WjtHoZ4xEHXL5VpNA0hCRAH89WA58sKFeJTiN3I5TljQ5TCw1Rj3nAjR0elOJqyAp/RLVmg6rEY9f9rBhWLoZg==} engines: {node: '>=24'} '@tybys/wasm-util@0.10.4': @@ -2169,7 +2169,7 @@ snapshots: estraverse: 5.3.0 picomatch: 4.0.7 - '@svgforge/svgforge@3.0.0-beta.1': + '@svgforge/svgforge@3.0.0': dependencies: '@resvg/resvg-js': 2.6.2 '@xmldom/xmldom': 0.9.12 diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index dd56849..b660724 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -1,4 +1,4 @@ allowBuilds: unrs-resolver: true minimumReleaseAgeExclude: - - '@svgforge/svgforge@3.0.0-beta.1 || 3.0.0' + - '@svgforge/svgforge@3.0.0' diff --git a/test/progress.test.js b/test/progress.test.js index d70645b..df73120 100644 --- a/test/progress.test.js +++ b/test/progress.test.js @@ -1,6 +1,11 @@ import assert from 'node:assert/strict'; import process from 'node:process'; -import {describe, it} from 'node:test'; +import { + afterEach, + beforeEach, + describe, + it, +} from 'node:test'; import {setTimeout as delay} from 'node:timers/promises'; import {createProgressBar} from '../lib/progress.js'; @@ -45,6 +50,23 @@ const createSpriterStub = listeners => ({ }); describe('createProgressBar', () => { + // The progress bar treats a CI environment as non-interactive. These tests + // simulate a real terminal, so keep CI off unless a test sets it explicitly. + let originalCI; + + beforeEach(() => { + originalCI = process.env.CI; + delete process.env.CI; + }); + + afterEach(() => { + if (originalCI === undefined) { + delete process.env.CI; + } else { + process.env.CI = originalCI; + } + }); + it('writes an animated progress bar on interactive terminals', () => { const listeners = {}; const spriter = createSpriterStub(listeners); @@ -76,6 +98,43 @@ describe('createProgressBar', () => { assert.ok(rendered.endsWith('\n')); }); + describe('in a CI environment', () => { + beforeEach(() => { + process.env.CI = 'true'; + }); + + it('does not redraw on a TTY', () => { + const listeners = {}; + const spriter = createSpriterStub(listeners); + const chunks = []; + const originalIsTTY = process.stderr.isTTY; + const originalWrite = process.stderr.write; + + process.stderr.isTTY = true; + process.stderr.write = chunk => { + chunks.push(String(chunk)); + return true; + }; + + const bar = createProgressBar(spriter); + bar.refreshTotal(4); + listeners.progress({processed: 1, total: 4}); + listeners.progress({processed: 4, total: 4}); + + assert.equal(chunks.length, 0, 'no output before finish()'); + + bar.finish(); + + process.stderr.isTTY = originalIsTTY; + process.stderr.write = originalWrite; + + const rendered = chunks.join(''); + assert.equal(rendered.includes('\r'), false, 'no carriage-return redraws in CI'); + assert.equal(rendered.split('\n').filter(Boolean).length, 1, 'exactly one summary line'); + assert.match(rendered, /4\/4 \(100\.0%\)\n/u); + }); + }); + it('writes nothing while running when not on a TTY', () => { const listeners = {}; const spriter = createSpriterStub(listeners);