Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/socket.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ concurrency:

permissions:
contents: read
issues: write
pull-requests: write

jobs:
socket-security:
Expand All @@ -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'

Expand Down
62 changes: 24 additions & 38 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 5 additions & 0 deletions bin/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion bin/svgforge.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 8 additions & 2 deletions lib/progress.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
10 changes: 5 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pnpm-workspace.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
allowBuilds:
unrs-resolver: true
minimumReleaseAgeExclude:
- '@svgforge/svgforge@3.0.0-beta.1 || 3.0.0'
- '@svgforge/svgforge@3.0.0'
61 changes: 60 additions & 1 deletion test/progress.test.js
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
Loading