@curio-sd/e-module-builder 0.5.0 → 0.5.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/bin/cli.js +3 -2
- package/build-pdf.mjs +5 -3
- package/package.json +1 -1
package/bin/cli.js
CHANGED
|
@@ -51,14 +51,15 @@ async function main() {
|
|
|
51
51
|
copyAssets()
|
|
52
52
|
runContentPipeline()
|
|
53
53
|
|
|
54
|
+
const { generatePdf } = await import(pathToFileURL(path.join(PKG_DIR, 'build-pdf.mjs')).href)
|
|
55
|
+
await generatePdf({ projectDir: PROJECT_DIR })
|
|
56
|
+
|
|
54
57
|
const { createConfig } = await import(pathToFileURL(path.join(PKG_DIR, 'vite.config.js')).href)
|
|
55
58
|
const cfg = createConfig({ projectDir: PROJECT_DIR, pkgDir: PKG_DIR })
|
|
56
59
|
|
|
57
60
|
if (command === 'build') {
|
|
58
61
|
const { build } = await import('vite')
|
|
59
62
|
await build(cfg)
|
|
60
|
-
const { generatePdf } = await import(pathToFileURL(path.join(PKG_DIR, 'build-pdf.mjs')).href)
|
|
61
|
-
await generatePdf({ projectDir: PROJECT_DIR })
|
|
62
63
|
} else {
|
|
63
64
|
const { createServer } = await import('vite')
|
|
64
65
|
const server = await createServer(cfg)
|
package/build-pdf.mjs
CHANGED
|
@@ -414,7 +414,6 @@ function renderWeek(doc, weekDir, sectionLabel) {
|
|
|
414
414
|
|
|
415
415
|
export async function generatePdf({ projectDir }) {
|
|
416
416
|
const CONTENT = path.join(projectDir, 'content')
|
|
417
|
-
const DIST = path.join(projectDir, 'dist')
|
|
418
417
|
|
|
419
418
|
if (!fs.existsSync(path.join(CONTENT, 'module.md'))) {
|
|
420
419
|
console.log(' PDF skipped: no content/module.md')
|
|
@@ -428,8 +427,11 @@ export async function generatePdf({ projectDir }) {
|
|
|
428
427
|
.sort((a, b) => Number(SECTION_RE.exec(a)[2]) - Number(SECTION_RE.exec(b)[2]))
|
|
429
428
|
.slice(0, mod.weeks ?? 99)
|
|
430
429
|
|
|
430
|
+
const PUBLIC = path.join(projectDir, 'public')
|
|
431
|
+
if (!fs.existsSync(PUBLIC)) fs.mkdirSync(PUBLIC, { recursive: true })
|
|
432
|
+
|
|
431
433
|
const doc = new PDFDocument({ margin: 72, size: 'A4', autoFirstPage: true })
|
|
432
|
-
const outPath = path.join(
|
|
434
|
+
const outPath = path.join(PUBLIC, 'e-module.pdf')
|
|
433
435
|
const writeStream = fs.createWriteStream(outPath)
|
|
434
436
|
doc.pipe(writeStream)
|
|
435
437
|
|
|
@@ -448,5 +450,5 @@ export async function generatePdf({ projectDir }) {
|
|
|
448
450
|
writeStream.on('error', reject)
|
|
449
451
|
})
|
|
450
452
|
|
|
451
|
-
console.log(' PDF →
|
|
453
|
+
console.log(' PDF → public/e-module.pdf')
|
|
452
454
|
}
|