@digimakers/cli 0.1.4 → 0.3.20

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.
@@ -0,0 +1 @@
1
+ code[class*=language-],pre[class*=language-]{color:#ccc;background:none;font-family:Consolas,Monaco,Andale Mono,Ubuntu Mono,monospace;font-size:1em;text-align:left;white-space:pre;word-spacing:normal;word-break:normal;word-wrap:normal;line-height:1.5;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-hyphens:none;-moz-hyphens:none;-ms-hyphens:none;hyphens:none}pre[class*=language-]{padding:1em;margin:.5em 0;overflow:auto}:not(pre)>code[class*=language-],pre[class*=language-]{background:#2d2d2d}:not(pre)>code[class*=language-]{padding:.1em;border-radius:.3em;white-space:normal}.token.comment,.token.block-comment,.token.prolog,.token.doctype,.token.cdata{color:#999}.token.punctuation{color:#ccc}.token.tag,.token.attr-name,.token.namespace,.token.deleted{color:#e2777a}.token.function-name{color:#6196cc}.token.boolean,.token.number,.token.function{color:#f08d49}.token.property,.token.class-name,.token.constant,.token.symbol{color:#f8c555}.token.selector,.token.important,.token.atrule,.token.keyword,.token.builtin{color:#cc99cd}.token.string,.token.char,.token.attr-value,.token.regex,.token.variable{color:#7ec699}.token.operator,.token.entity,.token.url{color:#67cdcc}.token.important,.token.bold{font-weight:700}.token.italic{font-style:italic}.token.entity{cursor:help}.token.inserted{color:green}:root{--offwhite-color: #f5f5f5;--codeblock-background-color: #2d2d2d}.pagedjs_pages{display:flex;flex-direction:column;align-items:center}.pagedjs_page{background-color:#fff;margin-bottom:30px;box-shadow:0 5px 15px #00000080}.pagedjs_sheet{background-color:#fff}body{scrollbar-gutter:stable!important;margin:0;padding:0}@page{size:A4;margin:0}body.print-mode,body.print-mode app-root{height:auto!important;overflow:visible!important}img{max-height:240mm;object-fit:contain}@media print{body{background:#fff!important}.pane-left{display:none!important}.split-layout,.pane-right,app-lesson-preview,.pdf-preview{display:block!important;width:100%!important;height:auto!important;overflow:visible!important;padding:0!important;margin:0!important;background:transparent!important}.pagedjs_pages{display:block!important}.pagedjs_page{box-shadow:none!important;margin:0!important;page-break-after:always;break-after:page}.pagedjs_page:last-child{page-break-after:auto;break-after:auto}}@font-face{font-family:Poppins;src:url("./media/Poppins-Regular-JNHL4IDV.ttf") format("opentype");font-weight:400;font-style:normal}@font-face{font-family:Jetbrains;src:url("./media/JetBrainsMono-Regular-2AOUELG6.ttf") format("opentype");font-weight:400;font-style:normal}
package/dist/index.js CHANGED
@@ -3,12 +3,44 @@ import 'dotenv/config';
3
3
  import yargs from 'yargs';
4
4
  import { hideBin } from 'yargs/helpers';
5
5
  import path from 'path';
6
- import { startServer, stopServer, createPdfGenerator, findDocxFiles, parseDocx, sampleLessonData, logger, } from '@digimakers/core';
6
+ import readline from 'readline/promises';
7
+ import { startServer, stopServer, createPdfGenerator, convertWithConcurrency, findDocxFiles, sampleLessonData, logger, POOL_SIZE, } from '@digimakers/core';
7
8
  const OUTPUT_DIR = path.resolve(process.cwd(), 'output');
9
+ async function ensureGeminiKey() {
10
+ if (process.env.GEMINI_API_KEY) {
11
+ return true;
12
+ }
13
+ if (!process.stdin.isTTY || !process.stdout.isTTY) {
14
+ logger.error('GEMINI_API_KEY is required. Set it or pass --gemini-key.');
15
+ return false;
16
+ }
17
+ const rl = readline.createInterface({
18
+ input: process.stdin,
19
+ output: process.stdout,
20
+ });
21
+ const key = await rl.question('Enter GEMINI_API_KEY (input will be visible): ');
22
+ rl.close();
23
+ const trimmed = key.trim();
24
+ if (!trimmed) {
25
+ logger.error('GEMINI_API_KEY is required. Set it or pass --gemini-key.');
26
+ return false;
27
+ }
28
+ process.env.GEMINI_API_KEY = trimmed;
29
+ return true;
30
+ }
8
31
  async function main() {
9
32
  await yargs(hideBin(process.argv))
10
33
  .scriptName('digimaker')
11
34
  .usage('$0 <command> [options]')
35
+ .option('gemini-key', {
36
+ type: 'string',
37
+ description: 'Gemini API key (overrides GEMINI_API_KEY)',
38
+ })
39
+ .middleware((argv) => {
40
+ if (argv.geminiKey) {
41
+ process.env.GEMINI_API_KEY = String(argv.geminiKey);
42
+ }
43
+ })
12
44
  .command('convert [path]', 'Convert .docx files to PDF', (yargs) => yargs
13
45
  .positional('path', {
14
46
  type: 'string',
@@ -26,27 +58,47 @@ async function main() {
26
58
  type: 'boolean',
27
59
  default: false,
28
60
  description: 'Recursively search directories',
61
+ })
62
+ .option('concurrency', {
63
+ alias: 'c',
64
+ type: 'number',
65
+ default: POOL_SIZE,
66
+ description: 'Maximum concurrent file processing',
29
67
  }), async (argv) => {
68
+ const hasKey = await ensureGeminiKey();
69
+ if (!hasKey) {
70
+ return;
71
+ }
30
72
  const targetPath = path.resolve(argv.path);
31
73
  const files = await findDocxFiles(targetPath, { recursive: argv.recursive });
32
74
  if (files.length === 0) {
33
75
  logger.warn('No .docx files found');
34
76
  return;
35
77
  }
36
- logger.info(`Converting ${files.length} file(s)...`);
78
+ logger.info(`Converting ${files.length} file(s) with concurrency ${argv.concurrency}...`);
37
79
  const server = await startServer();
38
80
  try {
39
81
  const generator = await createPdfGenerator(server.url);
40
- const items = await Promise.all(files.map(async (file) => {
41
- const result = await parseDocx(file.path);
42
- return {
43
- data: result.data,
44
- options: { outputDir: argv.output, filename: file.name },
45
- };
46
- }));
47
- await generator.generateBatch(items);
82
+ const results = await convertWithConcurrency(files, generator, argv.output, argv.concurrency);
48
83
  await generator.close();
49
- logger.info(`Done! ${files.length} PDF(s) saved to ${argv.output}`);
84
+ // Summary
85
+ const succeeded = results.filter((r) => r.success);
86
+ const failed = results.filter((r) => !r.success);
87
+ logger.info('');
88
+ logger.info('=== Conversion Summary ===');
89
+ logger.info(`Succeeded: ${succeeded.length}`);
90
+ logger.info(`Failed: ${failed.length}`);
91
+ if (failed.length > 0) {
92
+ logger.info('');
93
+ logger.info('Failed files:');
94
+ for (const f of failed) {
95
+ logger.info(` - ${f.file}: ${f.error}`);
96
+ }
97
+ }
98
+ if (succeeded.length > 0) {
99
+ logger.info('');
100
+ logger.info(`PDFs saved to: ${argv.output}`);
101
+ }
50
102
  }
51
103
  finally {
52
104
  await stopServer(server);
@@ -78,19 +130,7 @@ async function main() {
78
130
  await stopServer(server);
79
131
  }
80
132
  })
81
- .command('serve', 'Start server for manual browser testing', {}, async () => {
82
- const server = await startServer();
83
- logger.info(`\nOpen ${server.url} in your browser`);
84
- logger.info('Press Ctrl+C to stop\n');
85
- process.on('SIGINT', async () => {
86
- await stopServer(server);
87
- process.exit(0);
88
- });
89
- })
90
- .demandCommand(1, 'Specify a command: convert, generate, or serve')
91
- .help()
92
- .alias('help', 'h')
93
- .parse();
133
+ .parseAsync();
94
134
  }
95
135
  main().catch((error) => {
96
136
  logger.error({ err: error }, 'Error');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digimakers/cli",
3
- "version": "0.1.4",
3
+ "version": "0.3.20",
4
4
  "description": "CLI tool to convert .docx lesson sheets into stylised PDFs",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -13,6 +13,9 @@
13
13
  "dev": "tsx src/index.ts",
14
14
  "start": "node dist/index.js",
15
15
  "clean": "rm -rf dist",
16
+ "pdf-to-png": "node scripts/pdf-to-png.js",
17
+ "docling-cleaner": "node scripts/run-docling-cleaner.js",
18
+ "docling-cleaner:save": "node scripts/run-docling-cleaner.js > output/docling-output.txt",
16
19
  "prepublishOnly": "npm run build"
17
20
  },
18
21
  "dependencies": {
@@ -1 +0,0 @@
1
- code[class*=language-],pre[class*=language-]{color:#ccc;background:none;font-family:Consolas,Monaco,Andale Mono,Ubuntu Mono,monospace;font-size:1em;text-align:left;white-space:pre;word-spacing:normal;word-break:normal;word-wrap:normal;line-height:1.5;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-hyphens:none;-moz-hyphens:none;-ms-hyphens:none;hyphens:none}pre[class*=language-]{padding:1em;margin:.5em 0;overflow:auto}:not(pre)>code[class*=language-],pre[class*=language-]{background:#2d2d2d}:not(pre)>code[class*=language-]{padding:.1em;border-radius:.3em;white-space:normal}.token.comment,.token.block-comment,.token.prolog,.token.doctype,.token.cdata{color:#999}.token.punctuation{color:#ccc}.token.tag,.token.attr-name,.token.namespace,.token.deleted{color:#e2777a}.token.function-name{color:#6196cc}.token.boolean,.token.number,.token.function{color:#f08d49}.token.property,.token.class-name,.token.constant,.token.symbol{color:#f8c555}.token.selector,.token.important,.token.atrule,.token.keyword,.token.builtin{color:#cc99cd}.token.string,.token.char,.token.attr-value,.token.regex,.token.variable{color:#7ec699}.token.operator,.token.entity,.token.url{color:#67cdcc}.token.important,.token.bold{font-weight:700}.token.italic{font-style:italic}.token.entity{cursor:help}.token.inserted{color:green}:root{--offwhite-color: #f5f5f5}.pagedjs_pages{display:flex;flex-direction:column;align-items:center}.pagedjs_page{background-color:#fff;margin-bottom:30px;box-shadow:0 5px 15px #00000080}.pagedjs_sheet{background-color:#fff}body{scrollbar-gutter:stable!important;margin:0;padding:0}@page{size:A4;margin:0}body.print-mode,body.print-mode app-root{height:auto!important;overflow:visible!important}@media print{body{background:#fff!important}.pane-left{display:none!important}.split-layout,.pane-right,app-lesson-preview,.pdf-preview{display:block!important;width:100%!important;height:auto!important;overflow:visible!important;padding:0!important;margin:0!important;background:transparent!important}.pagedjs_pages{display:block!important}.pagedjs_page{box-shadow:none!important;margin:0!important;page-break-after:always;break-after:page}.pagedjs_page:last-child{page-break-after:auto;break-after:auto}}@font-face{font-family:Poppins;src:url("./media/Poppins-Regular-JNHL4IDV.ttf") format("opentype");font-weight:400;font-style:normal}@font-face{font-family:Jetbrains;src:url("./media/JetBrainsMono-Regular-2AOUELG6.ttf") format("opentype");font-weight:400;font-style:normal}