slides-grab 1.0.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.
@@ -0,0 +1,148 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { existsSync, readdirSync } from 'node:fs';
4
+ import { createRequire } from 'node:module';
5
+ import { resolve } from 'node:path';
6
+
7
+ import PptxGenJS from 'pptxgenjs';
8
+
9
+ import {
10
+ configureFigmaExportPresentation,
11
+ ensureOutputDirectory,
12
+ getFigmaImportCaveats,
13
+ normalizeFigmaOutput,
14
+ SLIDE_FILE_PATTERN,
15
+ sortFigmaSlideFiles,
16
+ } from '../src/figma.js';
17
+
18
+ const require = createRequire(import.meta.url);
19
+ const html2pptx = require('../src/html2pptx.cjs');
20
+
21
+ const DEFAULT_SLIDES_DIR = 'slides';
22
+
23
+ function printUsage() {
24
+ process.stdout.write(
25
+ [
26
+ 'Usage: slides-grab figma [options]',
27
+ '',
28
+ 'Options:',
29
+ ` --slides-dir <path> Slide directory (default: ${DEFAULT_SLIDES_DIR})`,
30
+ ' --output <path> Output PPTX file (default: <slides-dir>-figma.pptx)',
31
+ ' -h, --help Show this help message',
32
+ '',
33
+ 'Exports an experimental / unstable Figma Slides importable PPTX using the existing html2pptx pipeline.',
34
+ 'Treat both PPTX and Figma export as best-effort only.',
35
+ ].join('\n'),
36
+ );
37
+ process.stdout.write('\n');
38
+ }
39
+
40
+ function readOptionValue(args, index, optionName) {
41
+ const next = args[index + 1];
42
+ if (!next || next.startsWith('-')) {
43
+ throw new Error(`Missing value for ${optionName}.`);
44
+ }
45
+ return next;
46
+ }
47
+
48
+ function parseArgs(args) {
49
+ const options = {
50
+ slidesDir: DEFAULT_SLIDES_DIR,
51
+ output: '',
52
+ help: false,
53
+ };
54
+
55
+ for (let i = 0; i < args.length; i += 1) {
56
+ const arg = args[i];
57
+ if (arg === '-h' || arg === '--help') {
58
+ options.help = true;
59
+ continue;
60
+ }
61
+
62
+ if (arg === '--slides-dir') {
63
+ options.slidesDir = readOptionValue(args, i, '--slides-dir');
64
+ i += 1;
65
+ continue;
66
+ }
67
+
68
+ if (arg.startsWith('--slides-dir=')) {
69
+ options.slidesDir = arg.slice('--slides-dir='.length);
70
+ continue;
71
+ }
72
+
73
+ if (arg === '--output') {
74
+ options.output = readOptionValue(args, i, '--output');
75
+ i += 1;
76
+ continue;
77
+ }
78
+
79
+ if (arg.startsWith('--output=')) {
80
+ options.output = arg.slice('--output='.length);
81
+ continue;
82
+ }
83
+
84
+ throw new Error(`Unknown option: ${arg}`);
85
+ }
86
+
87
+ if (typeof options.slidesDir !== 'string' || options.slidesDir.trim() === '') {
88
+ throw new Error('--slides-dir must be a non-empty string.');
89
+ }
90
+
91
+ options.slidesDir = options.slidesDir.trim();
92
+ options.output = normalizeFigmaOutput(options.slidesDir, options.output);
93
+ return options;
94
+ }
95
+
96
+ function getHtmlSlides(slidesDir) {
97
+ if (!existsSync(slidesDir)) {
98
+ throw new Error(`Slides directory not found: ${slidesDir}`);
99
+ }
100
+
101
+ const files = readdirSync(slidesDir)
102
+ .filter((fileName) => SLIDE_FILE_PATTERN.test(fileName))
103
+ .sort(sortFigmaSlideFiles);
104
+
105
+ if (files.length === 0) {
106
+ throw new Error(`No slide-*.html files found in ${slidesDir}`);
107
+ }
108
+
109
+ return files;
110
+ }
111
+
112
+ async function main() {
113
+ const options = parseArgs(process.argv.slice(2));
114
+ if (options.help) {
115
+ printUsage();
116
+ return;
117
+ }
118
+
119
+ const slidesDir = resolve(process.cwd(), options.slidesDir);
120
+ const outputFile = resolve(process.cwd(), options.output);
121
+ const files = getHtmlSlides(slidesDir);
122
+
123
+ const pres = new PptxGenJS();
124
+ configureFigmaExportPresentation(pres);
125
+
126
+ console.log(`Exporting ${files.length} slide(s) for Figma from ${slidesDir}`);
127
+
128
+ for (const file of files) {
129
+ const filePath = resolve(slidesDir, file);
130
+ console.log(` Processing: ${file}`);
131
+ await html2pptx(filePath, pres);
132
+ }
133
+
134
+ await ensureOutputDirectory(outputFile);
135
+ await pres.writeFile({ fileName: outputFile });
136
+
137
+ console.log(`\nSaved Figma-importable PPTX: ${outputFile}`);
138
+ console.log('\nFigma import caveats:');
139
+ for (const caveat of getFigmaImportCaveats()) {
140
+ console.log(`- ${caveat}`);
141
+ }
142
+ console.log('\nManual import: Figma Slides -> Import -> select the generated .pptx file.');
143
+ }
144
+
145
+ main().catch((error) => {
146
+ console.error(`[slides-grab] ${error.message}`);
147
+ process.exit(1);
148
+ });