-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild-pdf.js
More file actions
59 lines (47 loc) · 2.3 KB
/
build-pdf.js
File metadata and controls
59 lines (47 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env node
const { spawnSync } = require('child_process');
const path = require('path');
console.log('🚀 Building PDF-ready assets (using style-pdf.css)');
// Minify and concatenate base CSS + PDF overrides so base layout remains
const fs = require('fs');
const postcss = require('postcss');
const cssnano = require('cssnano');
const node = process.execPath;
async function buildCombinedCss() {
try {
const basePath = path.join(__dirname, 'style.css');
const pdfPath = path.join(__dirname, 'style-pdf.css');
const baseCss = fs.existsSync(basePath) ? fs.readFileSync(basePath, 'utf8') : '';
const pdfCss = fs.existsSync(pdfPath) ? fs.readFileSync(pdfPath, 'utf8') : '';
// Garder le préfixe html.pdf-mode pour que les règles soient conditionnelles
// La classe sera activée automatiquement via JS dans les pages générées
// Minify base and pdf parts separately (so comments and spacing are cleaned)
const baseResult = await postcss([cssnano]).process(baseCss, { from: 'style.css' });
const pdfResult = await postcss([cssnano]).process(pdfCss, { from: 'style-pdf.css' });
const combined = `${baseResult.css}\n${pdfResult.css}`;
fs.writeFileSync(path.join(__dirname, 'style.min.css'), combined, 'utf8');
console.log('✅ style.min.css generated: base + pdf overrides concatenated');
return true;
} catch (err) {
console.error('❌ Failed to generate combined CSS:', err.message);
return false;
}
}
(async () => {
// First, run the JS minification step (server.min.js)
const buildMinJs = spawnSync(node, [path.join(__dirname, 'build-minify.js')], { stdio: 'inherit', env: process.env });
if (buildMinJs.error || buildMinJs.status !== 0) {
console.error('❌ build-minify (JS) failed');
process.exit(buildMinJs.status || 1);
}
// Generate combined CSS
const cssOk = await buildCombinedCss();
if (!cssOk) process.exit(1);
// Then run static locales generation
const buildLocales = spawnSync(node, [path.join(__dirname, 'build-static-locales.js')], { stdio: 'inherit', env: process.env });
if (buildLocales.error || buildLocales.status !== 0) {
console.error('❌ build-static-locales failed');
process.exit(buildLocales.status || 1);
}
console.log('🎉 build:pdf completed — site generated with base + pdf CSS');
})();