mirror of
https://github.com/amitwh/markdown-converter.git
synced 2026-10-01 09:19:34 +05:30
feat(brand): adopt the new M↓ brand kit; fix CI tool downloads
Branding: - All app icons regenerated from the new vector brand kit (M↓ mark): icon.png/icon@2x (app + packaging), favicon.png, tray-icon.png, and the full assets/icons/ size set — generate-icons.js now rasterizes app-icon.svg directly (docico1.png removed) - index.html gets proper favicon/apple-touch links from the kit - Welcome tab hero shows the new mark; README gets the horizontal wordmark - assets/logo.png (ConcreteInfo) intentionally untouched CI release fixes (win/mac jobs were failing): - FiraCode download moved from moving raw/master URLs (hash drifted upstream, tripping the pin) to the immutable 6.2 release asset; repo fonts updated to the pinned 6.2 bits - macOS pandoc extractor locates the binary in the archive instead of assuming a bin/ layout that the macOS zip doesn't have Stray upload archive (markdown-converter-assets (1).zip) excluded.
This commit is contained in:
+49
-21
@@ -19,6 +19,7 @@ const crypto = require('crypto');
|
||||
const { execSync } = require('child_process');
|
||||
|
||||
const PANDOC_VERSION = '3.9.0.2';
|
||||
const FIRACODE_VERSION = '6.2';
|
||||
|
||||
/**
|
||||
* SHA-256 of each downloaded artifact, keyed "<platform>:<file>" or
|
||||
@@ -31,8 +32,9 @@ const KNOWN_SHA256 = {
|
||||
// Fill these from a trusted machine after the first download of each
|
||||
// platform (the script prints the computed hash):
|
||||
// 'darwin:pandoc': '…',
|
||||
'fonts:FiraCode-Regular.ttf': '3c79d234a9161c790410ebb2a80de7efb7c15f581062c130e0fa78503ccdd0da',
|
||||
'fonts:FiraCode-Bold.ttf': '975f26779fac1029c2cbdac1e9fac7e9ddeec05e064675e4aac63bffa121742f',
|
||||
// Fira Code 6.2 (immutable GitHub release asset)
|
||||
'fonts:FiraCode-Regular.ttf': '5992ab9640e2df491b2f609467b1de60e8bc39b2c28db184342a0592d98f6117',
|
||||
'fonts:FiraCode-Bold.ttf': '41f6554e845e2f5b70adad3950122334b866aac436793b7742ade600067701be',
|
||||
'fonts:FiraCode-LICENSE.txt': '1d41e10031ab125302780a05ec4c91d218e47db0c7e37cf315cce5e608cdc25c',
|
||||
};
|
||||
|
||||
@@ -41,6 +43,20 @@ function sha256File(filePath) {
|
||||
return crypto.createHash('sha256').update(fs.readFileSync(filePath)).digest('hex');
|
||||
}
|
||||
|
||||
/** Recursively find an executable file by name inside a directory. */
|
||||
function findBinary(dir, name) {
|
||||
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
||||
const full = path.join(dir, entry.name);
|
||||
if (entry.isDirectory()) {
|
||||
const hit = findBinary(full, name);
|
||||
if (hit) return hit;
|
||||
} else if (entry.name === name || entry.name === name + '.exe') {
|
||||
return full;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify a file against KNOWN_SHA256. Throws on mismatch; prints the computed
|
||||
* hash with a pin-me hint when no hash is recorded yet (soft-fail so new
|
||||
@@ -104,8 +120,11 @@ const PANDOC_CONFIG = {
|
||||
const tmpDir = path.join(os.tmpdir(), `pandoc-${Date.now()}`);
|
||||
fs.mkdirSync(tmpDir, { recursive: true });
|
||||
execSync(`unzip -o "${archivePath}" -d "${tmpDir}"`);
|
||||
const src = path.join(tmpDir, `pandoc-${PANDOC_VERSION}`, 'bin', 'pandoc');
|
||||
fs.copyFileSync(src, path.join(destDir, 'pandoc'));
|
||||
// macOS zips don't carry a stable layout (bin/ subdir vs. flat) —
|
||||
// locate the binary in the extracted tree instead of guessing a path
|
||||
const found = findBinary(tmpDir, 'pandoc');
|
||||
if (!found) throw new Error('pandoc binary not found inside the macOS archive');
|
||||
fs.copyFileSync(found, path.join(destDir, 'pandoc'));
|
||||
fs.chmodSync(path.join(destDir, 'pandoc'), 0o755);
|
||||
fs.rmSync(tmpDir, { recursive: true, force: true });
|
||||
},
|
||||
@@ -161,25 +180,34 @@ function download(url, destPath) {
|
||||
async function downloadFiraCode() {
|
||||
const destDir = path.join(__dirname, '..', 'assets', 'fonts');
|
||||
fs.mkdirSync(destDir, { recursive: true });
|
||||
const wanted = ['FiraCode-Regular.ttf', 'FiraCode-Bold.ttf', 'FiraCode-LICENSE.txt'];
|
||||
|
||||
const targets = [
|
||||
{ url: 'https://github.com/tonsky/FiraCode/raw/master/distr/ttf/FiraCode-Regular.ttf', out: 'FiraCode-Regular.ttf' },
|
||||
{ url: 'https://github.com/tonsky/FiraCode/raw/master/distr/ttf/FiraCode-Bold.ttf', out: 'FiraCode-Bold.ttf' },
|
||||
{ url: 'https://raw.githubusercontent.com/tonsky/FiraCode/master/LICENSE', out: 'FiraCode-LICENSE.txt' },
|
||||
];
|
||||
|
||||
for (const t of targets) {
|
||||
const destFile = path.join(destDir, t.out);
|
||||
if (fs.existsSync(destFile)) {
|
||||
// Re-verify cached artifacts so a tampered cache never ships
|
||||
verifyArtifact(`fonts:${t.out}`, destFile);
|
||||
console.log(`[download-tools] ${t.out} already present — skipping.`);
|
||||
continue;
|
||||
}
|
||||
console.log(`[download-tools] Downloading ${t.out}...`);
|
||||
await download(t.url, destFile);
|
||||
verifyArtifact(`fonts:${t.out}`, destFile);
|
||||
// All three present (and hash-verified) → nothing to do
|
||||
const missing = wanted.filter((f) => !fs.existsSync(path.join(destDir, f)));
|
||||
if (missing.length === 0) {
|
||||
for (const f of wanted) verifyArtifact(`fonts:${f}`, path.join(destDir, f));
|
||||
console.log('[download-tools] Fira Code already present — skipping.');
|
||||
return;
|
||||
}
|
||||
|
||||
// Immutable release asset (raw/master URLs move and break hash pinning)
|
||||
const zipUrl = `https://github.com/tonsky/FiraCode/releases/download/${FIRACODE_VERSION}/Fira_Code_v${FIRACODE_VERSION}.zip`;
|
||||
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), `firacode-${Date.now()}`));
|
||||
const tmpZip = path.join(tmpDir, 'firacode.zip');
|
||||
console.log(`[download-tools] Downloading Fira Code ${FIRACODE_VERSION}...`);
|
||||
await download(zipUrl, tmpZip);
|
||||
execSync(`unzip -o -j "${tmpZip}" "ttf/FiraCode-Regular.ttf" "ttf/FiraCode-Bold.ttf" -d "${tmpDir}"`);
|
||||
|
||||
fs.copyFileSync(path.join(tmpDir, 'FiraCode-Regular.ttf'), path.join(destDir, 'FiraCode-Regular.ttf'));
|
||||
fs.copyFileSync(path.join(tmpDir, 'FiraCode-Bold.ttf'), path.join(destDir, 'FiraCode-Bold.ttf'));
|
||||
// License text from the immutable tag
|
||||
await download(
|
||||
`https://raw.githubusercontent.com/tonsky/FiraCode/${FIRACODE_VERSION}/LICENSE`,
|
||||
path.join(destDir, 'FiraCode-LICENSE.txt')
|
||||
);
|
||||
fs.rmSync(tmpDir, { recursive: true, force: true });
|
||||
|
||||
for (const f of wanted) verifyArtifact(`fonts:${f}`, path.join(destDir, f));
|
||||
}
|
||||
|
||||
async function downloadPandoc() {
|
||||
|
||||
+44
-50
@@ -1,78 +1,72 @@
|
||||
/**
|
||||
* Icon Generator for MarkdownConverter
|
||||
* Generates all required icon sizes from NewIcon.jpg
|
||||
*
|
||||
* Rasterizes the brand kit's vector app icon (the "M↓" mark,
|
||||
* assets/markdown-converter-assets/app-icon.svg) into every size the app and
|
||||
* its packaging need:
|
||||
*
|
||||
* assets/icon.png 512×512 — app icon (electron-builder converts to
|
||||
* .ico/.icns for Windows/macOS from this)
|
||||
* assets/icon@2x.png 1024×1024 — hi-dpi variant
|
||||
* assets/favicon.png 32×32 — in-app/browser favicon
|
||||
* assets/tray-icon.png 24×24 — system tray
|
||||
* assets/icons/* 16…1024 — multi-size set (ico/icns input)
|
||||
*
|
||||
* assets/logo.png is NOT touched — that is the ConcreteInfo logo used in the
|
||||
* app header and About dialog.
|
||||
*/
|
||||
|
||||
const sharp = require('sharp');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
// Source image
|
||||
const sourceImage = path.join(__dirname, '..', 'assets', 'docico1.png');
|
||||
// Brand kit sources (vector, primary)
|
||||
const brandDir = path.join(__dirname, '..', 'assets', 'markdown-converter-assets');
|
||||
const sourceSvg = path.join(brandDir, 'app-icon.svg');
|
||||
const assetsDir = path.join(__dirname, '..', 'assets');
|
||||
|
||||
// Icon sizes needed for different platforms
|
||||
const iconSizes = [16, 24, 32, 48, 64, 128, 256, 512, 1024];
|
||||
|
||||
async function generateIcons() {
|
||||
console.log('Generating icons from docico1.png...');
|
||||
/**
|
||||
* Rasterize the SVG source at a given size. `density` scales the vector so
|
||||
* small renders stay crisp; the explicit resize guarantees exact dimensions.
|
||||
*/
|
||||
async function renderIcon(size, outPath) {
|
||||
await sharp(sourceSvg, { density: Math.max(72, Math.round((size / 512) * 384)) })
|
||||
.resize(size, size, { fit: 'contain', background: { r: 255, g: 255, b: 255, alpha: 0 } })
|
||||
.png()
|
||||
.toFile(outPath);
|
||||
console.log(`Generated ${path.relative(process.cwd(), outPath)} (${size}x${size})`);
|
||||
}
|
||||
|
||||
// Check if source exists
|
||||
if (!fs.existsSync(sourceImage)) {
|
||||
console.error('Source image not found:', sourceImage);
|
||||
async function generateIcons() {
|
||||
console.log('Generating icons from the brand kit (app-icon.svg)...');
|
||||
|
||||
if (!fs.existsSync(sourceSvg)) {
|
||||
console.error('Brand source not found:', sourceSvg);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
try {
|
||||
// Generate main icon.png (512x512)
|
||||
await sharp(sourceImage)
|
||||
.resize(512, 512, { fit: 'contain', background: { r: 255, g: 255, b: 255, alpha: 0 } })
|
||||
.png()
|
||||
.toFile(path.join(assetsDir, 'icon.png'));
|
||||
console.log('Generated icon.png (512x512)');
|
||||
// Main app icons consumed by main.js windows and electron-builder
|
||||
await renderIcon(512, path.join(assetsDir, 'icon.png'));
|
||||
await renderIcon(1024, path.join(assetsDir, 'icon@2x.png'));
|
||||
|
||||
// Generate icon@2x.png (1024x1024)
|
||||
await sharp(sourceImage)
|
||||
.resize(1024, 1024, { fit: 'contain', background: { r: 255, g: 255, b: 255, alpha: 0 } })
|
||||
.png()
|
||||
.toFile(path.join(assetsDir, 'icon@2x.png'));
|
||||
console.log('Generated icon@2x.png (1024x1024)');
|
||||
// Favicon + tray
|
||||
await renderIcon(32, path.join(assetsDir, 'favicon.png'));
|
||||
await renderIcon(24, path.join(assetsDir, 'tray-icon.png'));
|
||||
|
||||
// Create icons directory for multi-size icons
|
||||
// Multi-size set for packaging converters (ico/icns)
|
||||
const iconsDir = path.join(assetsDir, 'icons');
|
||||
if (!fs.existsSync(iconsDir)) {
|
||||
fs.mkdirSync(iconsDir, { recursive: true });
|
||||
}
|
||||
|
||||
// Generate all sizes
|
||||
fs.mkdirSync(iconsDir, { recursive: true });
|
||||
for (const size of iconSizes) {
|
||||
await sharp(sourceImage)
|
||||
.resize(size, size, { fit: 'contain', background: { r: 255, g: 255, b: 255, alpha: 0 } })
|
||||
.png()
|
||||
.toFile(path.join(iconsDir, `${size}x${size}.png`));
|
||||
console.log(`Generated icons/${size}x${size}.png`);
|
||||
await renderIcon(size, path.join(iconsDir, `${size}x${size}.png`));
|
||||
}
|
||||
|
||||
// Generate favicon
|
||||
await sharp(sourceImage)
|
||||
.resize(32, 32, { fit: 'contain', background: { r: 255, g: 255, b: 255, alpha: 0 } })
|
||||
.png()
|
||||
.toFile(path.join(assetsDir, 'favicon.png'));
|
||||
console.log('Generated favicon.png (32x32)');
|
||||
|
||||
// Generate tray icon (smaller, for system tray)
|
||||
await sharp(sourceImage)
|
||||
.resize(24, 24, { fit: 'contain', background: { r: 255, g: 255, b: 255, alpha: 0 } })
|
||||
.png()
|
||||
.toFile(path.join(assetsDir, 'tray-icon.png'));
|
||||
console.log('Generated tray-icon.png (24x24)');
|
||||
|
||||
console.log('\nIcon generation complete!');
|
||||
console.log('\nFor Windows .ico file, use an online converter or:');
|
||||
console.log(' magick convert assets/icons/*.png assets/icon.ico');
|
||||
console.log('\nFor macOS .icns file, use:');
|
||||
console.log(' iconutil -c icns assets/icon.iconset -o assets/icon.icns');
|
||||
|
||||
console.log('Windows .ico and macOS .icns are generated automatically by');
|
||||
console.log('electron-builder from assets/icon.png during packaging.');
|
||||
} catch (error) {
|
||||
console.error('Error generating icons:', error);
|
||||
process.exit(1);
|
||||
|
||||
Reference in New Issue
Block a user