Browse Source

Check PNG, PDF and EPS packages before publishing (#1632)

pull/1635/head
Paweł Kuna 6 days ago
committed by GitHub
parent
commit
77d1e9a41f
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 63
      .build/check-image-package.mjs
  2. 5
      .github/workflows/build.yml
  3. 2
      packages/icons-eps/package.json
  4. 2
      packages/icons-pdf/package.json
  5. 2
      packages/icons-png/package.json

63
.build/check-image-package.mjs

@ -0,0 +1,63 @@
// Checks that an image package (png / pdf / eps) contains exactly one
// non-empty file per icon. Runs before publishing, so a conversion that was
// skipped (e.g. without `rsvg-convert`) or a stale `icons/` directory from a
// previous build cannot be released.
//
// Usage, from the package directory: node ../../.build/check-image-package.mjs <extension>
import { readdirSync, statSync } from 'fs';
import path from 'path';
import { getAllIcons } from './helpers.mjs';
const extension = process.argv[2];
if (!extension) {
console.error('Usage: check-image-package.mjs <extension>');
process.exit(1);
}
const listFiles = (dir) => {
try {
return readdirSync(dir).filter((file) => file.endsWith(`.${extension}`));
} catch {
return [];
}
};
const sample = (files) => files.slice(0, 10).join(', ') + (files.length > 10 ? ', …' : '');
let failed = false;
for (const [type, icons] of Object.entries(getAllIcons())) {
const dir = path.resolve('icons', type);
const expected = new Set(icons.map((icon) => `${icon.name}.${extension}`));
const actual = listFiles(dir);
const actualSet = new Set(actual);
const missing = [...expected].filter((file) => !actualSet.has(file));
const extra = actual.filter((file) => !expected.has(file));
const empty = actual.filter(
(file) => expected.has(file) && statSync(path.join(dir, file)).size === 0,
);
for (const [label, files] of [
['missing', missing],
['not an icon anymore', extra],
['empty', empty],
]) {
if (files.length > 0) {
failed = true;
console.error(`${type}: ${files.length} ${label}: ${sample(files)}`);
}
}
if (missing.length === 0 && extra.length === 0 && empty.length === 0) {
console.log(`${type}: ${actual.length} ${extension} files, all icons present`);
}
}
if (failed) {
console.error(
`\nicons/ does not match the current icons. Rebuild the package before publishing.`,
);
process.exit(1);
}

5
.github/workflows/build.yml

@ -62,6 +62,11 @@ jobs:
ICONS_LIMIT: 100
run: pnpm run build
- name: Check image packages
env:
ICONS_LIMIT: 100
run: pnpm --filter @tabler/icons-png --filter @tabler/icons-pdf --filter @tabler/icons-eps run check
# The demo apps in test/test-* have no test script and import icons outside
# the ICONS_LIMIT subset, so only the packages and the two guard suites are
# selected. @tabler/icons-angular runs in headless Chrome via Karma, which

2
packages/icons-eps/package.json

@ -16,6 +16,8 @@
"scripts": {
"build": "pnpm run clean && pnpm run copy:license && pnpm run build:icons",
"build:icons": "node build.mjs",
"check": "node ../../.build/check-image-package.mjs eps",
"prepublishOnly": "pnpm run check",
"clean": "find dist -mindepth 1 -delete 2>/dev/null; rm -rf dist && find . ! -name '.gitkeep' -path '*/icons/*' -exec rm -rf {} +",
"copy:license": "cp ../../LICENSE ./LICENSE"
},

2
packages/icons-pdf/package.json

@ -21,6 +21,8 @@
"scripts": {
"build": "pnpm run clean && pnpm run copy:license && pnpm run build:icons",
"build:icons": "node build.mjs",
"check": "node ../../.build/check-image-package.mjs pdf",
"prepublishOnly": "pnpm run check",
"clean": "find dist -mindepth 1 -delete 2>/dev/null; rm -rf dist && find . ! -name '.gitkeep' -path '*/icons/*' -exec rm -rf {} +",
"copy:license": "cp ../../LICENSE ./LICENSE"
},

2
packages/icons-png/package.json

@ -21,6 +21,8 @@
"scripts": {
"build": "pnpm run clean && pnpm run copy:license && pnpm run build:icons",
"build:icons": "node build.mjs",
"check": "node ../../.build/check-image-package.mjs png",
"prepublishOnly": "pnpm run check",
"clean": "find dist -mindepth 1 -delete 2>/dev/null; rm -rf dist && find . ! -name '.gitkeep' -path '*/icons/*' -exec rm -rf {} +",
"copy:license": "cp ../../LICENSE ./LICENSE"
},

Loading…
Cancel
Save