pptx-templates 0.3.1 → 0.3.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.
Files changed (29) hide show
  1. package/AI-INSTRUCTOR.md +108 -0
  2. package/CHANGELOG.md +18 -1
  3. package/dist/extensions/cli/index.js +7 -3
  4. package/dist/extensions/cli/index.js.map +1 -1
  5. package/dist/extensions/template-lint/cli.d.ts +57 -2
  6. package/dist/extensions/template-lint/cli.js +222 -106
  7. package/dist/extensions/template-lint/cli.js.map +1 -1
  8. package/dist/extensions/template-lint/config.d.ts +51 -0
  9. package/dist/extensions/template-lint/config.js +229 -0
  10. package/dist/extensions/template-lint/config.js.map +1 -0
  11. package/dist/extensions/template-lint/index.d.ts +2 -1
  12. package/dist/extensions/template-lint/index.js +2 -1
  13. package/dist/extensions/template-lint/index.js.map +1 -1
  14. package/dist/extensions/template-lint/lint.d.ts +12 -0
  15. package/dist/extensions/template-lint/lint.js +101 -17
  16. package/dist/extensions/template-lint/lint.js.map +1 -1
  17. package/dist/extensions/template-lint/usage-cli.d.ts +6 -0
  18. package/dist/extensions/template-lint/usage-cli.js +140 -0
  19. package/dist/extensions/template-lint/usage-cli.js.map +1 -0
  20. package/dist/extensions/template-lint/usage.d.ts +48 -0
  21. package/dist/extensions/template-lint/usage.js +255 -0
  22. package/dist/extensions/template-lint/usage.js.map +1 -0
  23. package/dist/extensions/template-lint/watch.d.ts +19 -5
  24. package/dist/extensions/template-lint/watch.js +41 -14
  25. package/dist/extensions/template-lint/watch.js.map +1 -1
  26. package/dist/extensions/template-logic/expression.d.ts +10 -1
  27. package/dist/extensions/template-logic/expression.js +26 -19
  28. package/dist/extensions/template-logic/expression.js.map +1 -1
  29. package/package.json +1 -1
package/AI-INSTRUCTOR.md CHANGED
@@ -1102,6 +1102,55 @@ with Ctrl+C.
1102
1102
  - In a terminal, the screen is cleared before each run.
1103
1103
  - `--watch` cannot be combined with `--json`.
1104
1104
 
1105
+ ### Config file
1106
+
1107
+ When decks need different data, list them in `pptx-templates.json`. Each
1108
+ entry pairs a file pattern with the data (or schema) for the decks it
1109
+ matches:
1110
+
1111
+ ```text
1112
+ pptx-templates.json
1113
+ data/
1114
+ cover_de.json cover_en.json
1115
+ report_de.json report_en.json
1116
+ customer-a/
1117
+ cover_de.pptx cover_en.pptx
1118
+ report_de.pptx report_en.pptx
1119
+ customer-b/
1120
+ cover_de.pptx cover_en.pptx
1121
+ ```
1122
+
1123
+ ```json
1124
+ {
1125
+ "templates": [
1126
+ { "files": "{customer}/cover_{lang}.pptx", "data": "data/cover_{lang}.json" },
1127
+ { "files": "{customer}/report_{lang}.pptx", "data": "data/report_{lang}.json" }
1128
+ ]
1129
+ }
1130
+ ```
1131
+
1132
+ ```bash
1133
+ npx pptx-templates lint # reads pptx-templates.json in this folder
1134
+ npx pptx-templates lint --watch
1135
+ npx pptx-templates lint --config other.json
1136
+ ```
1137
+
1138
+ - `files` is a pattern or a list of patterns, relative to the config file.
1139
+ `*` matches any part of a name, `**` any number of folders, and
1140
+ `{name}` matches like `*` and remembers the part: `data` and `schema`
1141
+ fill it in. Above, `customer-a/cover_en.pptx` gets
1142
+ `data/cover_en.json`.
1143
+ - A pattern that matches no file is fine (customer-b has no report);
1144
+ the command notes it. If no pattern matches anything, that is an error.
1145
+ - Data next to the decks works the same:
1146
+ `{ "files": "{customer}/deck_{lang}.pptx", "data": "{customer}/data_{lang}.json" }`.
1147
+ - A deck that two entries match is an error, so the data is never ambiguous.
1148
+ - Optional top-level `openingTag`, `closingTag` and `fixSmartQuotes` apply to
1149
+ all decks; the same options on the command line win.
1150
+ - With `--watch`, saving any deck, data file or the config file lints again,
1151
+ and new decks or folders that match a pattern are picked up.
1152
+ - Folders starting with `.` and `node_modules` are not searched.
1153
+
1105
1154
  ## What it checks
1106
1155
 
1107
1156
  | Rule | Severity | Finds |
@@ -1179,6 +1228,65 @@ If you render with `fixSmartQuotes: true`, lint with the same option
1179
1228
  (`--fix-smart-quotes` on the command line), so the linter accepts the same
1180
1229
  tags as the renderer.
1181
1230
 
1231
+ ## Data usage
1232
+
1233
+ `templateDataUsage` answers the opposite question: which fields of the data
1234
+ do the tags read, and which does no tag read? It shows what a template needs
1235
+ from the data, and what the data could drop.
1236
+
1237
+ ```ts
1238
+ import { templateDataUsage } from 'pptx-templates';
1239
+
1240
+ const usage = await templateDataUsage('templates/Offer.pptx', {
1241
+ data: { user: { name: 'Ada', mail: 'ada@example.com' }, items: [{ name: 'Apples', price: 1.5 }] },
1242
+ });
1243
+ // usage.used: [{ path: 'user.name', locations: [{ part: 'ppt/slides/slide1.xml', slide: 1, shape: 'Title' }] },
1244
+ // { path: 'items', … }, { path: 'items[].name', … }, { path: 'items[].price', … }]
1245
+ // usage.unused: ['user.mail']
1246
+ // usage.missing: paths the tags read that are not in the data
1247
+ ```
1248
+
1249
+ On the command line:
1250
+
1251
+ ```bash
1252
+ npx pptx-templates usage templates/Offer.pptx --data example.json
1253
+ npx pptx-templates usage cover_de.pptx cover_en.pptx --schema data.schema.json
1254
+ ```
1255
+
1256
+ ```text
1257
+ templates/Offer.pptx
1258
+ used (4)
1259
+ user.name slide 1 › "Title"
1260
+ items slide 2 › "Table"
1261
+ items[].name slide 2 › "Table"
1262
+ items[].price slide 2 › "Table"
1263
+ unused (1)
1264
+ user.mail
1265
+ ```
1266
+
1267
+ With several files, a last section lists the fields that none of them
1268
+ reads. With a [config file](#config-file), that section comes once per data
1269
+ file, for the decks that share it (`npx pptx-templates usage` alone reads
1270
+ `pptx-templates.json`). `--json` prints the result as JSON, and `--watch`
1271
+ runs again on every save, as with `lint`. Without `--data` or `--schema`,
1272
+ only the read paths are listed.
1273
+
1274
+ How paths are counted:
1275
+
1276
+ - **Loops and EXEC are traced back to the data.** In
1277
+ `{{FOR p IN items}}{{p.price}}{{END-FOR}}`, `p.price` reads `items[].price`
1278
+ (`[]`: every entry). `{{EXEC a = user.address}}{{a.city}}` reads
1279
+ `user.address.city`.
1280
+ - **Output vs. tested.** A value that is output or passed on as a whole
1281
+ (`{{user}}`, `{{format(user)}}`, `{{items.map(i => i.name)}}`, `{{user[key]}}`)
1282
+ covers every field below it. A value that is only tested (`{{IF user}}`,
1283
+ `{{IF items.length > 0}}`) counts itself, not its fields.
1284
+ - **Unused subtrees are one entry**: `intern` rather than `intern.id`,
1285
+ `intern.note`. `items[]` means no field of any entry is read.
1286
+ - Fields the data shows in only some list entries count for all entries.
1287
+ - Tags in layouts, masters, notes and charts are not rendered, so they do not
1288
+ count. Neither does data your own code reads outside the tags.
1289
+
1182
1290
  ## Modify Tables
1183
1291
 
1184
1292
  You can use a PowerPoint table and add/modify data and style. It is also possible to add rows and columns and to style cells.
package/CHANGELOG.md CHANGED
@@ -6,6 +6,22 @@ semver, with the pre-1.0 convention that **breaking changes bump the minor**.
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.3.2] - 2026-11-13
10
+
11
+ ### Added
12
+
13
+ - `templateDataUsage` and `pptx-templates usage`: which fields of the data
14
+ the tags of a template read, which fields no tag reads, and which read
15
+ paths are not in the data. Loop variables and EXEC names are traced back
16
+ to the data (`produkte[].preis`); with several files, the command also
17
+ lists the fields none of them reads. Supports `--json` and `--watch`.
18
+ - Config file `pptx-templates.json` for `lint` and `usage`: file patterns,
19
+ each with its own data or schema. `{name}` placeholders carry parts of
20
+ the deck path into the data path (`{customer}/cover_{lang}.pptx` →
21
+ `data/cover_{lang}.json`). Without file arguments, the commands read
22
+ `pptx-templates.json` from the current folder; `--watch` picks up new
23
+ decks and folders that match.
24
+
9
25
  ## [0.3.1] - 2026-11-13
10
26
 
11
27
  ### Added
@@ -185,7 +201,8 @@ for that history.
185
201
  into one `.png` part. The fallback now gets the same placeholder PNG that
186
202
  pptxgenjs 3.12 wrote.
187
203
 
188
- [Unreleased]: https://github.com/DaBorsten/pptx-templates/compare/v0.3.1...HEAD
204
+ [Unreleased]: https://github.com/DaBorsten/pptx-templates/compare/v0.3.2...HEAD
205
+ [0.3.2]: https://github.com/DaBorsten/pptx-templates/compare/v0.3.1...v0.3.2
189
206
  [0.3.1]: https://github.com/DaBorsten/pptx-templates/compare/v0.3.0...v0.3.1
190
207
  [0.3.0]: https://github.com/DaBorsten/pptx-templates/compare/v0.2.1...v0.3.0
191
208
  [0.2.1]: https://github.com/DaBorsten/pptx-templates/compare/v0.2.0...v0.2.1
@@ -15,16 +15,20 @@ exports.runCli = void 0;
15
15
  * `npx pptx-templates <command>` (the package's `bin`). Fork extension.
16
16
  */
17
17
  const cli_1 = require("../template-lint/cli");
18
- const USAGE = `Usage: pptx-templates <command>
18
+ const usage_cli_1 = require("../template-lint/usage-cli");
19
+ const USAGE = `Usage: pptx-templates <command> [options]
19
20
 
20
21
  Commands:
21
- lint <file.pptx>... Check the {{…}} tags of templates
22
+ lint <file.pptx>... Check the {{…}} tags of templates
23
+ usage <file.pptx>... Show which data fields the tags read, and which not
22
24
 
23
- ${cli_1.LINT_USAGE}`;
25
+ Run pptx-templates <command> --help for the options of a command.`;
24
26
  const runCli = (args, io) => __awaiter(void 0, void 0, void 0, function* () {
25
27
  const [command, ...rest] = args;
26
28
  if (command === 'lint')
27
29
  return (0, cli_1.runLintCommand)(rest, io);
30
+ if (command === 'usage')
31
+ return (0, usage_cli_1.runUsageCommand)(rest, io);
28
32
  if (command === '-h' || command === '--help') {
29
33
  io.stdout(`${USAGE}\n`);
30
34
  return 0;
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/extensions/cli/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;AACA;;GAEG;AACH,8CAK8B;AAE9B,MAAM,KAAK,GAAG;;;;;EAKZ,gBAAU,EAAE,CAAC;AAER,MAAM,MAAM,GAAG,CAAO,IAAc,EAAE,EAAS,EAAmB,EAAE;IACzE,MAAM,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC;IAChC,IAAI,OAAO,KAAK,MAAM;QAAE,OAAO,IAAA,oBAAc,EAAC,IAAI,EAA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AK,CAAC,IAAI,CAAC;QAC5C,KAAK,EAAE,IAAA,mBAAa,GAAE;QACtB,WAAW,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK;KACpC,CAAC,CAAC,IAAI,CACL,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,EACnC,CAAC,KAAK,EAAE,EAAE;;QACR,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,MAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,KAAK,mCAAI,KAAK,IAAI,CAAC,CAAC;QACnD,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;IACvB,CAAC,CACF,CAAC;AACJ,CAAC"}
@@ -1,4 +1,4 @@
1
- import { TemplateLintIssue } from './types';
1
+ import { LintTemplateOptions, TemplateLintIssue } from './types';
2
2
  export type CliIO = {
3
3
  stdout: (text: string) => void;
4
4
  stderr: (text: string) => void;
@@ -18,12 +18,67 @@ type WatchTiming = {
18
18
  retries: number;
19
19
  retryDelayMs: number;
20
20
  };
21
- export declare const LINT_USAGE = "Usage: pptx-templates lint <file.pptx>... [options]\n\nChecks the {{\u2026}} tags of PowerPoint templates before rendering.\n\nOptions:\n --data <file.json> Example data: report names and properties that\n are not in it\n --schema <file.json> JSON Schema of the data (alternative to --data)\n --opening-tag <text> Tag start (default: {{)\n --closing-tag <text> Tag end (default: }})\n --fix-smart-quotes Accept typographic quotes, like renderTemplate's\n fixSmartQuotes option\n --max-warnings <n> Fail when there are more than n warnings\n --json Print the issues as JSON\n -w, --watch Lint again whenever a file (or the --data/--schema\n file) is saved; the deck may stay open in\n PowerPoint. Stop with Ctrl+C\n --color / --no-color Force colors on or off (default: on in a terminal;\n NO_COLOR and FORCE_COLOR are respected)\n -h, --help Show this help\n\nExit code: 0 no errors, 1 errors (or too many warnings), 2 invalid call.";
21
+ export declare const LINT_USAGE = "Usage: pptx-templates lint <file.pptx>... [options]\n pptx-templates lint [--config <file.json>] [options]\n\nChecks the {{\u2026}} tags of PowerPoint templates before rendering.\n\nOptions:\n --data <file.json> Example data: report names and properties that\n are not in it\n --schema <file.json> JSON Schema of the data (alternative to --data)\n -c, --config <file.json> Decks and their data from a config file; without\n files, pptx-templates.json in this folder is used\n --opening-tag <text> Tag start (default: {{)\n --closing-tag <text> Tag end (default: }})\n --fix-smart-quotes Accept typographic quotes, like renderTemplate's\n fixSmartQuotes option\n --max-warnings <n> Fail when there are more than n warnings\n --json Print the issues as JSON\n -w, --watch Lint again whenever a file (or the --data/--schema\n file) is saved; the deck may stay open in\n PowerPoint. Stop with Ctrl+C\n --color / --no-color Force colors on or off (default: on in a terminal;\n NO_COLOR and FORCE_COLOR are respected)\n -h, --help Show this help\n\nExit code: 0 no errors, 1 errors (or too many warnings), 2 invalid call.";
22
22
  /** Where in the deck an issue is, for humans: "slide 2 › Title". */
23
23
  export declare const issueLocation: (issue: TemplateLintIssue) => string;
24
+ export declare const style: {
25
+ bold: (text: string) => string;
26
+ dim: (text: string) => string;
27
+ underline: (text: string) => string;
28
+ red: (text: string) => string;
29
+ yellow: (text: string) => string;
30
+ cyan: (text: string) => string;
31
+ };
24
32
  /** Color on for a real terminal, off for pipes, `NO_COLOR` and `--no-color`. */
25
33
  export declare const supportsColor: (env?: NodeJS.ProcessEnv, isTTY?: boolean) => boolean;
34
+ /**
35
+ * Text from the .pptx (tags, shape names) goes to a terminal: control
36
+ * characters could hide or forge output there. Each becomes one space, so
37
+ * the marker line under a tag still fits (a tab would shift it, too).
38
+ */
39
+ export declare const printable: (text: string) => string;
26
40
  export declare const formatIssues: (file: string, issues: TemplateLintIssue[], color?: boolean) => string;
41
+ export type ParsedArgs = {
42
+ files: string[];
43
+ options: LintTemplateOptions;
44
+ /** Read on every run, so `--watch` picks up changes. */
45
+ dataFile?: string;
46
+ schemaFile?: string;
47
+ /** `--config`, or `pptx-templates.json` when no file is given. */
48
+ configFile?: string;
49
+ json: boolean;
50
+ color?: boolean;
51
+ maxWarnings?: number;
52
+ watch: boolean;
53
+ help: boolean;
54
+ };
55
+ /** One deck to process, with the options (data, schema) that belong to it. */
56
+ export type Job = {
57
+ file: string;
58
+ options: LintTemplateOptions;
59
+ dataFile?: string;
60
+ schemaFile?: string;
61
+ };
62
+ /** Output of one run over all files, collected rather than printed. */
63
+ export type CommandRun = {
64
+ code: number;
65
+ stdout: string;
66
+ stderr: string;
67
+ /** A file could not be read; `--watch` tries again before reporting. */
68
+ unreadable: boolean;
69
+ };
70
+ type RunFiles = (jobs: Job[], parsed: ParsedArgs, color: boolean) => Promise<CommandRun>;
71
+ /** The run result for a deck that cannot be read. */
72
+ export declare const unreadableRun: (file: string, error: unknown, stdout?: string) => CommandRun;
73
+ /**
74
+ * A command over .pptx files with the shared options (`--data`, `--watch`,
75
+ * `--config`, …); resolves to the exit code.
76
+ */
77
+ export declare const runFileCommand: (args: string[], io: CliIO, command: {
78
+ usage: string;
79
+ run: RunFiles;
80
+ lintOnly?: boolean;
81
+ }) => Promise<number>;
27
82
  /** `pptx-templates lint …`; resolves to the exit code. */
28
83
  export declare const runLintCommand: (args: string[], io: CliIO) => Promise<number>;
29
84
  export {};