@grainulation/mill 1.1.0 → 1.1.2
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/mill.js +10 -0
- package/lib/exporters/pdf-worker.js +28 -0
- package/lib/exporters/pdf.js +3 -16
- package/package.json +13 -10
- package/lib/server.js +0 -645
- package/public/index.html +0 -891
package/bin/mill.js
CHANGED
|
@@ -476,7 +476,17 @@ async function runCiArtifacts(args) {
|
|
|
476
476
|
}
|
|
477
477
|
|
|
478
478
|
function runServe(args) {
|
|
479
|
+
const fs = require("node:fs");
|
|
479
480
|
const serverPath = path.join(LIB_DIR, "server.js");
|
|
481
|
+
if (!fs.existsSync(serverPath)) {
|
|
482
|
+
console.error(
|
|
483
|
+
"mill: server.js is not included in the npm package.\n" +
|
|
484
|
+
"The serve command requires a full clone of the repository.\n\n" +
|
|
485
|
+
" git clone https://github.com/grainulation/mill.git\n" +
|
|
486
|
+
" cd mill && node bin/mill.js serve"
|
|
487
|
+
);
|
|
488
|
+
process.exit(1);
|
|
489
|
+
}
|
|
480
490
|
const child = fork(serverPath, args, { stdio: "inherit" });
|
|
481
491
|
child.on("exit", (code) => process.exit(code ?? 0));
|
|
482
492
|
process.on("SIGTERM", () => child.kill("SIGTERM"));
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* PDF worker — standalone script that converts an HTML file to PDF using puppeteer.
|
|
6
|
+
*
|
|
7
|
+
* Usage: node pdf-worker.js <inputPath> <outputPath>
|
|
8
|
+
*
|
|
9
|
+
* Extracted from pdf.js to avoid constructing JS as a string and executing
|
|
10
|
+
* via `node -e`, which triggers Socket AI-anomaly alerts.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
const inputPath = process.argv[2];
|
|
14
|
+
const outputPath = process.argv[3];
|
|
15
|
+
|
|
16
|
+
if (!inputPath || !outputPath) {
|
|
17
|
+
process.stderr.write("Usage: node pdf-worker.js <inputPath> <outputPath>\n");
|
|
18
|
+
process.exit(1);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
(async () => {
|
|
22
|
+
const puppeteer = require("puppeteer");
|
|
23
|
+
const browser = await puppeteer.launch({ headless: "new" });
|
|
24
|
+
const page = await browser.newPage();
|
|
25
|
+
await page.goto(`file://${inputPath}`, { waitUntil: "networkidle0" });
|
|
26
|
+
await page.pdf({ path: outputPath, format: "A4", printBackground: true });
|
|
27
|
+
await browser.close();
|
|
28
|
+
})();
|
package/lib/exporters/pdf.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
// which needs network access. All other mill export formats are zero-dep.
|
|
6
6
|
|
|
7
7
|
const path = require("node:path");
|
|
8
|
-
const { execFile } = require("node:child_process");
|
|
8
|
+
const { execFile, execFileSync } = require("node:child_process");
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Export HTML or Markdown files to PDF.
|
|
@@ -70,22 +70,9 @@ async function exportFromMarkdown(inputPath, outputPath) {
|
|
|
70
70
|
|
|
71
71
|
async function exportFromHtml(inputPath, outputPath) {
|
|
72
72
|
const out = deriveOutputPath(inputPath, outputPath);
|
|
73
|
-
|
|
74
|
-
// Escape single quotes, backticks, and ${} to prevent template literal injection
|
|
75
|
-
const escapePath = (p) =>
|
|
76
|
-
p.replace(/'/g, "\\'").replace(/`/g, "\\`").replace(/\$\{/g, "\\${");
|
|
77
|
-
const script = `
|
|
78
|
-
const puppeteer = require('puppeteer');
|
|
79
|
-
(async () => {
|
|
80
|
-
const browser = await puppeteer.launch({ headless: 'new' });
|
|
81
|
-
const page = await browser.newPage();
|
|
82
|
-
await page.goto('file://${escapePath(inputPath)}', { waitUntil: 'networkidle0' });
|
|
83
|
-
await page.pdf({ path: '${escapePath(out)}', format: 'A4', printBackground: true });
|
|
84
|
-
await browser.close();
|
|
85
|
-
})();
|
|
86
|
-
`;
|
|
73
|
+
const workerPath = path.join(__dirname, "pdf-worker.js");
|
|
87
74
|
try {
|
|
88
|
-
|
|
75
|
+
execFileSync("node", [workerPath, inputPath, out], { timeout: 120_000 });
|
|
89
76
|
} catch (err) {
|
|
90
77
|
throw npxToolError("puppeteer", err);
|
|
91
78
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@grainulation/mill",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "Turn wheat sprint artifacts into shareable formats",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -8,22 +8,25 @@
|
|
|
8
8
|
},
|
|
9
9
|
"exports": {
|
|
10
10
|
".": "./lib/index.js",
|
|
11
|
-
"./
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
"./formats/markdown": "./lib/formats/markdown.js",
|
|
15
|
-
"./formats/csv": "./lib/formats/csv.js",
|
|
16
|
-
"./formats/json-ld": "./lib/formats/json-ld.js",
|
|
11
|
+
"./formats/markdown": "./lib/formats/markdown.mjs",
|
|
12
|
+
"./formats/csv": "./lib/formats/csv.mjs",
|
|
13
|
+
"./formats/json-ld": "./lib/formats/json-ld.mjs",
|
|
17
14
|
"./tokens": "./public/grainulation-tokens.css"
|
|
18
15
|
},
|
|
19
16
|
"files": [
|
|
20
17
|
"bin/",
|
|
21
|
-
"lib/",
|
|
22
|
-
"
|
|
18
|
+
"lib/index.js",
|
|
19
|
+
"lib/formats.js",
|
|
20
|
+
"lib/json-ld-common.js",
|
|
21
|
+
"lib/serve-mcp.js",
|
|
22
|
+
"lib/exporters/",
|
|
23
|
+
"lib/publishers/",
|
|
24
|
+
"lib/formats/",
|
|
23
25
|
"CHANGELOG.md",
|
|
24
26
|
"LICENSE",
|
|
25
27
|
"CODE_OF_CONDUCT.md",
|
|
26
|
-
"CONTRIBUTING.md"
|
|
28
|
+
"CONTRIBUTING.md",
|
|
29
|
+
"public/grainulation-tokens.css"
|
|
27
30
|
],
|
|
28
31
|
"scripts": {
|
|
29
32
|
"test": "node test/basic.test.js",
|