nimiq-branding-cli 1.2.0 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/scripts/_browser.mjs +27 -0
- package/scripts/lint.mjs +2 -2
- package/scripts/verify.mjs +2 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nimiq-branding-cli",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "nq — pixel-verified Nimiq UI component registry + CLI. 39 components (Vue 3 + plain HTML) diffed against the real Nimiq apps, plus the team's real asset library. Unofficial community tool.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// Shared browser bootstrap for `nq lint` and `nq verify`.
|
|
2
|
+
// Playwright is intentionally NOT a runtime dependency (it pulls a ~hundreds-of-MB browser),
|
|
3
|
+
// so we load it lazily and, if it's missing, print a one-line fix instead of a raw stack
|
|
4
|
+
// trace. Exit code 2 = "setup needed", distinct from lint's 1 = violations / 0 = clean.
|
|
5
|
+
export async function launchChromium(cmd = 'this command') {
|
|
6
|
+
let chromium;
|
|
7
|
+
try {
|
|
8
|
+
({ chromium } = await import('playwright'));
|
|
9
|
+
} catch {
|
|
10
|
+
console.error(
|
|
11
|
+
`\nnq: ${cmd} needs Playwright (a headless browser) to render pages.\n` +
|
|
12
|
+
`It isn't bundled, to keep installs light. One-time setup:\n\n` +
|
|
13
|
+
` npm i -g playwright && npx playwright install chromium\n\n` +
|
|
14
|
+
`Then re-run. Only \`nq lint\` and \`nq verify\` need it — the rest of nq works without it.\n`,
|
|
15
|
+
);
|
|
16
|
+
process.exit(2);
|
|
17
|
+
}
|
|
18
|
+
try {
|
|
19
|
+
return await chromium.launch();
|
|
20
|
+
} catch (e) {
|
|
21
|
+
if (/Executable doesn't exist|playwright install|please run the following/i.test(String(e))) {
|
|
22
|
+
console.error(`\nnq: Playwright is installed but its browser isn't. Run:\n\n npx playwright install chromium\n`);
|
|
23
|
+
process.exit(2);
|
|
24
|
+
}
|
|
25
|
+
throw e;
|
|
26
|
+
}
|
|
27
|
+
}
|
package/scripts/lint.mjs
CHANGED
|
@@ -247,8 +247,8 @@ export async function lint(target, opts = {}) {
|
|
|
247
247
|
if (!isUrl && !existsSync(filePath)) throw new Error(`no such file: ${target}`);
|
|
248
248
|
const url = isUrl ? target : pathToFileURL(filePath).href;
|
|
249
249
|
|
|
250
|
-
const {
|
|
251
|
-
const browser = await
|
|
250
|
+
const { launchChromium } = await import('./_browser.mjs');
|
|
251
|
+
const browser = await launchChromium('nq lint');
|
|
252
252
|
const out = (s = '') => console.log(s);
|
|
253
253
|
let errorCount = 0, warnCount = 0;
|
|
254
254
|
try {
|
package/scripts/verify.mjs
CHANGED
|
@@ -18,7 +18,7 @@ export async function verify(name) {
|
|
|
18
18
|
if (!existsSync(demo)) return { status: 'skip', reason: 'no html/demo.html' };
|
|
19
19
|
if (!existsSync(ref)) return { status: 'skip', reason: 'no reference.png' };
|
|
20
20
|
|
|
21
|
-
const {
|
|
21
|
+
const { launchChromium } = await import('./_browser.mjs');
|
|
22
22
|
const { PNG } = await import('pngjs');
|
|
23
23
|
const pixelmatch = (await import('pixelmatch')).default;
|
|
24
24
|
|
|
@@ -26,7 +26,7 @@ export async function verify(name) {
|
|
|
26
26
|
const viewport = v.viewport ?? { width: 800, height: 600 };
|
|
27
27
|
const threshold = v.maxDiffPct ?? 1.0; // percent of pixels allowed to differ
|
|
28
28
|
|
|
29
|
-
const browser = await
|
|
29
|
+
const browser = await launchChromium('nq verify');
|
|
30
30
|
try {
|
|
31
31
|
const page = await browser.newPage({ viewport, deviceScaleFactor: v.scale ?? 2 });
|
|
32
32
|
await page.goto('file://' + demo);
|