@digimakers/cli 0.2.1 → 0.3.21

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/dist/index.js CHANGED
@@ -3,12 +3,49 @@ import 'dotenv/config';
3
3
  import yargs from 'yargs';
4
4
  import { hideBin } from 'yargs/helpers';
5
5
  import path from 'path';
6
+ import readline from 'readline/promises';
6
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
+ if (!process.env.GOOGLE_GENERATIVE_AI_API_KEY) {
12
+ process.env.GOOGLE_GENERATIVE_AI_API_KEY = process.env.GEMINI_API_KEY;
13
+ }
14
+ return true;
15
+ }
16
+ if (!process.stdin.isTTY || !process.stdout.isTTY) {
17
+ logger.error('GEMINI_API_KEY is required. Set it or pass --gemini-key.');
18
+ return false;
19
+ }
20
+ const rl = readline.createInterface({
21
+ input: process.stdin,
22
+ output: process.stdout,
23
+ });
24
+ const key = await rl.question('Enter GEMINI_API_KEY (input will be visible): ');
25
+ rl.close();
26
+ const trimmed = key.trim();
27
+ if (!trimmed) {
28
+ logger.error('GEMINI_API_KEY is required. Set it or pass --gemini-key.');
29
+ return false;
30
+ }
31
+ process.env.GEMINI_API_KEY = trimmed;
32
+ process.env.GOOGLE_GENERATIVE_AI_API_KEY = trimmed;
33
+ return true;
34
+ }
8
35
  async function main() {
9
36
  await yargs(hideBin(process.argv))
10
37
  .scriptName('digimaker')
11
38
  .usage('$0 <command> [options]')
39
+ .option('gemini-key', {
40
+ type: 'string',
41
+ description: 'Gemini API key (overrides GEMINI_API_KEY)',
42
+ })
43
+ .middleware((argv) => {
44
+ if (argv.geminiKey) {
45
+ process.env.GEMINI_API_KEY = String(argv.geminiKey);
46
+ process.env.GOOGLE_GENERATIVE_AI_API_KEY = String(argv.geminiKey);
47
+ }
48
+ })
12
49
  .command('convert [path]', 'Convert .docx files to PDF', (yargs) => yargs
13
50
  .positional('path', {
14
51
  type: 'string',
@@ -33,6 +70,10 @@ async function main() {
33
70
  default: POOL_SIZE,
34
71
  description: 'Maximum concurrent file processing',
35
72
  }), async (argv) => {
73
+ const hasKey = await ensureGeminiKey();
74
+ if (!hasKey) {
75
+ return;
76
+ }
36
77
  const targetPath = path.resolve(argv.path);
37
78
  const files = await findDocxFiles(targetPath, { recursive: argv.recursive });
38
79
  if (files.length === 0) {
@@ -94,19 +135,7 @@ async function main() {
94
135
  await stopServer(server);
95
136
  }
96
137
  })
97
- .command('serve', 'Start server for manual browser testing', {}, async () => {
98
- const server = await startServer();
99
- logger.info(`\nOpen ${server.url} in your browser`);
100
- logger.info('Press Ctrl+C to stop\n');
101
- process.on('SIGINT', async () => {
102
- await stopServer(server);
103
- process.exit(0);
104
- });
105
- })
106
- .demandCommand(1, 'Specify a command: convert, generate, or serve')
107
- .help()
108
- .alias('help', 'h')
109
- .parse();
138
+ .parseAsync();
110
139
  }
111
140
  main().catch((error) => {
112
141
  logger.error({ err: error }, 'Error');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digimakers/cli",
3
- "version": "0.2.1",
3
+ "version": "0.3.21",
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": {