pptx-templates 0.3.0 → 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.
- package/AI-INSTRUCTOR.md +130 -0
- package/CHANGELOG.md +33 -1
- package/dist/extensions/cli/index.js +8 -3
- package/dist/extensions/cli/index.js.map +1 -1
- package/dist/extensions/template-lint/cli.d.ts +71 -2
- package/dist/extensions/template-lint/cli.js +310 -40
- package/dist/extensions/template-lint/cli.js.map +1 -1
- package/dist/extensions/template-lint/config.d.ts +51 -0
- package/dist/extensions/template-lint/config.js +229 -0
- package/dist/extensions/template-lint/config.js.map +1 -0
- package/dist/extensions/template-lint/index.d.ts +2 -1
- package/dist/extensions/template-lint/index.js +2 -1
- package/dist/extensions/template-lint/index.js.map +1 -1
- package/dist/extensions/template-lint/lint.d.ts +12 -0
- package/dist/extensions/template-lint/lint.js +101 -17
- package/dist/extensions/template-lint/lint.js.map +1 -1
- package/dist/extensions/template-lint/usage-cli.d.ts +6 -0
- package/dist/extensions/template-lint/usage-cli.js +140 -0
- package/dist/extensions/template-lint/usage-cli.js.map +1 -0
- package/dist/extensions/template-lint/usage.d.ts +48 -0
- package/dist/extensions/template-lint/usage.js +255 -0
- package/dist/extensions/template-lint/usage.js.map +1 -0
- package/dist/extensions/template-lint/watch.d.ts +27 -0
- package/dist/extensions/template-lint/watch.js +78 -0
- package/dist/extensions/template-lint/watch.js.map +1 -0
- package/dist/extensions/template-logic/expression.d.ts +10 -1
- package/dist/extensions/template-logic/expression.js +26 -19
- package/dist/extensions/template-logic/expression.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.runUsageCommand = exports.formatUsage = exports.USAGE_USAGE = void 0;
|
|
13
|
+
const cli_1 = require("./cli");
|
|
14
|
+
const config_1 = require("./config");
|
|
15
|
+
const lint_1 = require("./lint");
|
|
16
|
+
exports.USAGE_USAGE = `Usage: pptx-templates usage <file.pptx>... [options]
|
|
17
|
+
pptx-templates usage [--config <file.json>] [options]
|
|
18
|
+
|
|
19
|
+
Shows which fields of the data the {{…}} tags of PowerPoint templates read,
|
|
20
|
+
which fields no tag reads, and which read paths are not in the data.
|
|
21
|
+
|
|
22
|
+
Options:
|
|
23
|
+
--data <file.json> Example data to compare with
|
|
24
|
+
--schema <file.json> JSON Schema of the data (alternative to --data)
|
|
25
|
+
-c, --config <file.json> Decks and their data from a config file; without
|
|
26
|
+
files, ${config_1.CONFIG_FILE} in this folder is used
|
|
27
|
+
--opening-tag <text> Tag start (default: {{)
|
|
28
|
+
--closing-tag <text> Tag end (default: }})
|
|
29
|
+
--fix-smart-quotes Accept typographic quotes, like renderTemplate's
|
|
30
|
+
fixSmartQuotes option
|
|
31
|
+
--json Print the result as JSON
|
|
32
|
+
-w, --watch Run again whenever a file (or the --data/--schema
|
|
33
|
+
file) is saved. Stop with Ctrl+C
|
|
34
|
+
--color / --no-color Force colors on or off (default: on in a terminal;
|
|
35
|
+
NO_COLOR and FORCE_COLOR are respected)
|
|
36
|
+
-h, --help Show this help
|
|
37
|
+
|
|
38
|
+
Without --data or --schema, only the read paths are listed.
|
|
39
|
+
Exit code: 0 done, 2 invalid call or unreadable file.`;
|
|
40
|
+
/** "slide 1 › "Titel"", as the linter shows locations. */
|
|
41
|
+
const where = (location) => (0, cli_1.issueLocation)({
|
|
42
|
+
part: location.part,
|
|
43
|
+
slide: location.slide,
|
|
44
|
+
shape: location.shape,
|
|
45
|
+
});
|
|
46
|
+
const section = (title, entries, indent, paint, tone = (t) => t) => {
|
|
47
|
+
const rows = entries.map((entry) => typeof entry === 'string'
|
|
48
|
+
? { path: entry, at: '' }
|
|
49
|
+
: { path: entry.path, at: entry.locations.map(where).join(', ') });
|
|
50
|
+
const width = Math.max(...rows.map((r) => r.path.length));
|
|
51
|
+
const lines = rows.map(({ path, at }) => {
|
|
52
|
+
const shown = paint(tone, (0, cli_1.printable)(path));
|
|
53
|
+
return at
|
|
54
|
+
? `${indent} ${shown}${' '.repeat(width - path.length)} ${paint(cli_1.style.dim, (0, cli_1.printable)(at))}`
|
|
55
|
+
: `${indent} ${shown}`;
|
|
56
|
+
});
|
|
57
|
+
return `${indent}${paint(cli_1.style.bold, `${title} (${entries.length})`)}\n${lines.join('\n')}\n`;
|
|
58
|
+
};
|
|
59
|
+
const formatUsage = (file, usage, hasData, color = false) => {
|
|
60
|
+
const paint = (fn, text) => color ? fn(text) : text;
|
|
61
|
+
let text = `${paint(cli_1.style.underline, (0, cli_1.printable)(file))}\n`;
|
|
62
|
+
text += usage.used.length
|
|
63
|
+
? section('used', usage.used, ' ', paint)
|
|
64
|
+
: ' used: none\n';
|
|
65
|
+
if (hasData) {
|
|
66
|
+
text += usage.unused.length
|
|
67
|
+
? section('unused', usage.unused, ' ', paint, cli_1.style.yellow)
|
|
68
|
+
: ' unused: none\n';
|
|
69
|
+
}
|
|
70
|
+
if (usage.missing.length) {
|
|
71
|
+
text += section('missing in data', usage.missing, ' ', paint, cli_1.style.red);
|
|
72
|
+
}
|
|
73
|
+
return text;
|
|
74
|
+
};
|
|
75
|
+
exports.formatUsage = formatUsage;
|
|
76
|
+
const hasData = (job) => !!(job.options.data || job.options.schema);
|
|
77
|
+
const usageFiles = (jobs, parsed, color) => __awaiter(void 0, void 0, void 0, function* () {
|
|
78
|
+
const paint = (fn, text) => color ? fn(text) : text;
|
|
79
|
+
const files = {};
|
|
80
|
+
let stdout = '';
|
|
81
|
+
for (const job of jobs) {
|
|
82
|
+
try {
|
|
83
|
+
files[job.file] = yield (0, lint_1.collectDataUsage)([job.file], job.options);
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
return (0, cli_1.unreadableRun)(job.file, error, stdout);
|
|
87
|
+
}
|
|
88
|
+
if (!parsed.json) {
|
|
89
|
+
stdout +=
|
|
90
|
+
(stdout ? '\n' : '') +
|
|
91
|
+
(0, exports.formatUsage)(job.file, files[job.file], hasData(job), color);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
// Decks with the same data and schema: what none of them reads
|
|
95
|
+
const byData = new Map();
|
|
96
|
+
for (const job of jobs.filter(hasData)) {
|
|
97
|
+
const key = JSON.stringify([job.dataFile, job.schemaFile]);
|
|
98
|
+
if (!byData.has(key))
|
|
99
|
+
byData.set(key, []);
|
|
100
|
+
byData.get(key).push(job);
|
|
101
|
+
}
|
|
102
|
+
const groups = [];
|
|
103
|
+
for (const members of byData.values()) {
|
|
104
|
+
const decks = members.map((job) => job.file);
|
|
105
|
+
let unused;
|
|
106
|
+
try {
|
|
107
|
+
// The decks were readable a moment ago; read them once more together
|
|
108
|
+
unused = (yield (0, lint_1.collectDataUsage)(decks, members[0].options)).unused;
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
return (0, cli_1.unreadableRun)(decks.join(', '), error, stdout);
|
|
112
|
+
}
|
|
113
|
+
groups.push(Object.assign(Object.assign(Object.assign({}, (members[0].dataFile && { data: members[0].dataFile })), (members[0].schemaFile && { schema: members[0].schemaFile })), { files: decks, unused }));
|
|
114
|
+
}
|
|
115
|
+
if (parsed.json) {
|
|
116
|
+
stdout = JSON.stringify({ files, unusedInAll: groups }, null, 2) + '\n';
|
|
117
|
+
}
|
|
118
|
+
else if (!groups.length) {
|
|
119
|
+
stdout += `\n${paint(cli_1.style.dim, 'Pass --data or --schema to see unused fields.')}\n`;
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
for (const group of groups.filter((g) => g.files.length > 1)) {
|
|
123
|
+
// Name the data only where decks use different data
|
|
124
|
+
const source = byData.size > 1
|
|
125
|
+
? ` using ${[group.data, group.schema].filter(Boolean).join(' + ')}`
|
|
126
|
+
: '';
|
|
127
|
+
const n = group.files.length;
|
|
128
|
+
stdout +=
|
|
129
|
+
'\n' +
|
|
130
|
+
(group.unused.length
|
|
131
|
+
? section(`Unused in all ${n} file(s)${source}`, group.unused, '', paint, cli_1.style.yellow)
|
|
132
|
+
: `Every field is used in at least one of the ${n} file(s)${source}\n`);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return { code: 0, stdout, stderr: '', unreadable: false };
|
|
136
|
+
});
|
|
137
|
+
/** `pptx-templates usage …`; resolves to the exit code. */
|
|
138
|
+
const runUsageCommand = (args, io) => (0, cli_1.runFileCommand)(args, io, { usage: exports.USAGE_USAGE, run: usageFiles });
|
|
139
|
+
exports.runUsageCommand = runUsageCommand;
|
|
140
|
+
//# sourceMappingURL=usage-cli.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usage-cli.js","sourceRoot":"","sources":["../../../src/extensions/template-lint/usage-cli.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,+BAUe;AACf,qCAAuC;AACvC,iCAA0C;AAW7B,QAAA,WAAW,GAAG;;;;;;;;;;qCAUU,oBAAW;;;;;;;;;;;;;sDAaM,CAAC;AAEvD,0DAA0D;AAC1D,MAAM,KAAK,GAAG,CAAC,QAA2B,EAAU,EAAE,CACpD,IAAA,mBAAa,EAAC;IACZ,IAAI,EAAE,QAAQ,CAAC,IAAI;IACnB,KAAK,EAAE,QAAQ,CAAC,KAAK;IACrB,KAAK,EAAE,QAAQ,CAAC,KAAK;CACiB,CAAC,CAAC;AAE5C,M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D,QAAA,eAAe,mBACwC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { JsonSchema } from './types';
|
|
2
|
+
/** Where a tag reads a path. */
|
|
3
|
+
export type DataUsageLocation = {
|
|
4
|
+
/** Part inside the .pptx, e.g. `ppt/slides/slide2.xml`. */
|
|
5
|
+
part: string;
|
|
6
|
+
slide?: number;
|
|
7
|
+
/** Shape name (Selection pane). */
|
|
8
|
+
shape?: string;
|
|
9
|
+
};
|
|
10
|
+
export type DataUsageEntry = {
|
|
11
|
+
/** `kunde.name`, `produkte[].preis` (`[]`: every entry of a list). */
|
|
12
|
+
path: string;
|
|
13
|
+
locations: DataUsageLocation[];
|
|
14
|
+
};
|
|
15
|
+
export type TemplateDataUsage = {
|
|
16
|
+
/**
|
|
17
|
+
* Paths the tags read, as deep as the data goes, in the order they first
|
|
18
|
+
* appear. A value that is output or passed on as a whole (`{{kunde}}`,
|
|
19
|
+
* `{{format(kunde)}}`, `{{produkte.map(…)}}`) covers everything below it.
|
|
20
|
+
*/
|
|
21
|
+
used: DataUsageEntry[];
|
|
22
|
+
/**
|
|
23
|
+
* Fields of the data or schema no tag reads. A subtree no tag reads at
|
|
24
|
+
* all is one entry (`intern`, not `intern.a`, `intern.b`). Empty without
|
|
25
|
+
* `data` and `schema`.
|
|
26
|
+
*/
|
|
27
|
+
unused: string[];
|
|
28
|
+
/** Paths the tags read that are not in the data or schema. */
|
|
29
|
+
missing: DataUsageEntry[];
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Collects which data paths the tags of a template read. Without data and
|
|
33
|
+
* schema it only lists the paths; with them, it also knows which fields are
|
|
34
|
+
* not read and which read paths do not exist.
|
|
35
|
+
*/
|
|
36
|
+
export declare class DataUsageRecorder {
|
|
37
|
+
private readonly root?;
|
|
38
|
+
private readonly used;
|
|
39
|
+
private readonly missing;
|
|
40
|
+
constructor(data?: Record<string, unknown>, schema?: JsonSchema);
|
|
41
|
+
/**
|
|
42
|
+
* A tag reads `keys` (from the data root; list entries as `[]` or an
|
|
43
|
+
* index). `whole`: the value is used as a whole, not only tested.
|
|
44
|
+
*/
|
|
45
|
+
record(keys: string[], whole: boolean, location: DataUsageLocation): void;
|
|
46
|
+
private add;
|
|
47
|
+
result(): TemplateDataUsage;
|
|
48
|
+
}
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DataUsageRecorder = void 0;
|
|
4
|
+
const node = (kind, open = false) => ({
|
|
5
|
+
kind,
|
|
6
|
+
children: new Map(),
|
|
7
|
+
open,
|
|
8
|
+
read: false,
|
|
9
|
+
whole: false,
|
|
10
|
+
});
|
|
11
|
+
const isIndex = (key) => /^\d+$/.test(key);
|
|
12
|
+
const isPlainObject = (value) => {
|
|
13
|
+
if (!value || typeof value !== 'object')
|
|
14
|
+
return false;
|
|
15
|
+
const proto = Object.getPrototypeOf(value);
|
|
16
|
+
return proto === Object.prototype || proto === null;
|
|
17
|
+
};
|
|
18
|
+
/** Combines what two sources (two list entries, data and schema) say. */
|
|
19
|
+
const merge = (a, b) => {
|
|
20
|
+
if (!a)
|
|
21
|
+
return b;
|
|
22
|
+
if (!b)
|
|
23
|
+
return a;
|
|
24
|
+
const rank = { leaf: 0, array: 1, object: 2 };
|
|
25
|
+
const result = node(rank[a.kind] >= rank[b.kind] ? a.kind : b.kind);
|
|
26
|
+
result.open = a.open || b.open;
|
|
27
|
+
for (const source of [a, b]) {
|
|
28
|
+
source.children.forEach((child, key) => result.children.set(key, merge(result.children.get(key), child)));
|
|
29
|
+
}
|
|
30
|
+
result.element = merge(a.element, b.element);
|
|
31
|
+
return result;
|
|
32
|
+
};
|
|
33
|
+
const fromData = (value) => {
|
|
34
|
+
if (value === null || value === undefined)
|
|
35
|
+
return node('leaf', true);
|
|
36
|
+
if (Array.isArray(value)) {
|
|
37
|
+
const list = node('array');
|
|
38
|
+
// Entries may differ: their fields are combined
|
|
39
|
+
value.forEach((entry) => (list.element = merge(list.element, fromData(entry))));
|
|
40
|
+
return list;
|
|
41
|
+
}
|
|
42
|
+
if (isPlainObject(value)) {
|
|
43
|
+
const object = node('object');
|
|
44
|
+
Object.entries(value).forEach(([key, child]) => object.children.set(key, fromData(child)));
|
|
45
|
+
return object;
|
|
46
|
+
}
|
|
47
|
+
// Strings, numbers, dates, …
|
|
48
|
+
return node('leaf');
|
|
49
|
+
};
|
|
50
|
+
const fromSchema = (root) => {
|
|
51
|
+
const resolve = (schema) => {
|
|
52
|
+
let current = schema;
|
|
53
|
+
for (let i = 0; (current === null || current === void 0 ? void 0 : current.$ref) && i < 20; i++) {
|
|
54
|
+
if (!current.$ref.startsWith('#'))
|
|
55
|
+
return undefined;
|
|
56
|
+
let target = root;
|
|
57
|
+
for (const segment of current.$ref.slice(1).split('/').filter(Boolean)) {
|
|
58
|
+
let key;
|
|
59
|
+
try {
|
|
60
|
+
key = decodeURIComponent(segment)
|
|
61
|
+
.replace(/~1/g, '/')
|
|
62
|
+
.replace(/~0/g, '~');
|
|
63
|
+
}
|
|
64
|
+
catch (_a) {
|
|
65
|
+
return undefined;
|
|
66
|
+
}
|
|
67
|
+
target = target === null || target === void 0 ? void 0 : target[key];
|
|
68
|
+
}
|
|
69
|
+
current = target;
|
|
70
|
+
}
|
|
71
|
+
return current;
|
|
72
|
+
};
|
|
73
|
+
const build = (input, depth) => {
|
|
74
|
+
var _a, _b, _c, _d, _e;
|
|
75
|
+
const schema = resolve(input);
|
|
76
|
+
// Unknown or too deep (recursive schemas): anything may be there
|
|
77
|
+
if (!schema || typeof schema !== 'object' || depth > 20) {
|
|
78
|
+
return node('leaf', true);
|
|
79
|
+
}
|
|
80
|
+
const types = Array.isArray(schema.type)
|
|
81
|
+
? schema.type
|
|
82
|
+
: schema.type
|
|
83
|
+
? [schema.type]
|
|
84
|
+
: [];
|
|
85
|
+
let result;
|
|
86
|
+
if (schema.properties || types.includes('object')) {
|
|
87
|
+
const object = node('object');
|
|
88
|
+
Object.entries((_a = schema.properties) !== null && _a !== void 0 ? _a : {}).forEach(([key, child]) => object.children.set(key, build(child, depth + 1)));
|
|
89
|
+
// Same convention as the linter: listed properties close the object
|
|
90
|
+
object.open =
|
|
91
|
+
!!schema.patternProperties ||
|
|
92
|
+
(schema.additionalProperties !== undefined &&
|
|
93
|
+
schema.additionalProperties !== false) ||
|
|
94
|
+
!schema.properties;
|
|
95
|
+
if (schema.additionalProperties &&
|
|
96
|
+
typeof schema.additionalProperties === 'object') {
|
|
97
|
+
object.open = true;
|
|
98
|
+
}
|
|
99
|
+
result = object;
|
|
100
|
+
}
|
|
101
|
+
if (schema.items || schema.prefixItems || types.includes('array')) {
|
|
102
|
+
const list = node('array');
|
|
103
|
+
const items = [
|
|
104
|
+
...((_b = schema.prefixItems) !== null && _b !== void 0 ? _b : []),
|
|
105
|
+
...(Array.isArray(schema.items)
|
|
106
|
+
? schema.items
|
|
107
|
+
: schema.items
|
|
108
|
+
? [schema.items]
|
|
109
|
+
: []),
|
|
110
|
+
];
|
|
111
|
+
items.forEach((item) => (list.element = merge(list.element, build(item, depth + 1))));
|
|
112
|
+
result = merge(result, list);
|
|
113
|
+
}
|
|
114
|
+
for (const branch of [
|
|
115
|
+
...((_c = schema.allOf) !== null && _c !== void 0 ? _c : []),
|
|
116
|
+
...((_d = schema.anyOf) !== null && _d !== void 0 ? _d : []),
|
|
117
|
+
...((_e = schema.oneOf) !== null && _e !== void 0 ? _e : []),
|
|
118
|
+
]) {
|
|
119
|
+
result = merge(result, build(branch, depth + 1));
|
|
120
|
+
}
|
|
121
|
+
if (result)
|
|
122
|
+
return result;
|
|
123
|
+
return types.length ? node('leaf') : node('leaf', true);
|
|
124
|
+
};
|
|
125
|
+
return build(root, 0);
|
|
126
|
+
};
|
|
127
|
+
const IDENTIFIER = /^[\p{L}_$][\p{L}\p{N}_$]*$/u;
|
|
128
|
+
const formatPath = (keys) => keys
|
|
129
|
+
.map((key, i) => {
|
|
130
|
+
if (key === '[]')
|
|
131
|
+
return '[]';
|
|
132
|
+
if (isIndex(key))
|
|
133
|
+
return `[${key}]`;
|
|
134
|
+
if (IDENTIFIER.test(key))
|
|
135
|
+
return i === 0 ? key : `.${key}`;
|
|
136
|
+
return `[${JSON.stringify(key)}]`;
|
|
137
|
+
})
|
|
138
|
+
.join('');
|
|
139
|
+
const PROTOTYPES = {
|
|
140
|
+
object: Object.prototype,
|
|
141
|
+
array: Array.prototype,
|
|
142
|
+
};
|
|
143
|
+
/**
|
|
144
|
+
* Collects which data paths the tags of a template read. Without data and
|
|
145
|
+
* schema it only lists the paths; with them, it also knows which fields are
|
|
146
|
+
* not read and which read paths do not exist.
|
|
147
|
+
*/
|
|
148
|
+
class DataUsageRecorder {
|
|
149
|
+
constructor(data, schema) {
|
|
150
|
+
this.used = new Map();
|
|
151
|
+
this.missing = new Map();
|
|
152
|
+
if (data !== undefined)
|
|
153
|
+
this.root = fromData(data);
|
|
154
|
+
if (schema !== undefined)
|
|
155
|
+
this.root = merge(this.root, fromSchema(schema));
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* A tag reads `keys` (from the data root; list entries as `[]` or an
|
|
159
|
+
* index). `whole`: the value is used as a whole, not only tested.
|
|
160
|
+
*/
|
|
161
|
+
record(keys, whole, location) {
|
|
162
|
+
if (!this.root) {
|
|
163
|
+
this.add(this.used, keys, location);
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
let current = this.root;
|
|
167
|
+
const walked = [];
|
|
168
|
+
for (let i = 0; i < keys.length; i++) {
|
|
169
|
+
const key = keys[i];
|
|
170
|
+
current.read = true;
|
|
171
|
+
let next;
|
|
172
|
+
if (current.kind === 'array' && (key === '[]' || isIndex(key))) {
|
|
173
|
+
walked.push('[]');
|
|
174
|
+
next = current.element;
|
|
175
|
+
if (!next)
|
|
176
|
+
return this.add(this.used, walked, location);
|
|
177
|
+
}
|
|
178
|
+
else if (current.kind === 'object' && current.children.has(key)) {
|
|
179
|
+
walked.push(key);
|
|
180
|
+
next = current.children.get(key);
|
|
181
|
+
}
|
|
182
|
+
else if (current.kind === 'leaf') {
|
|
183
|
+
// A property of a string or number (`name.length`), or of a value
|
|
184
|
+
// nothing is known about (null in the data): the value is read
|
|
185
|
+
current.whole = true;
|
|
186
|
+
return this.add(this.used, walked, location);
|
|
187
|
+
}
|
|
188
|
+
else if (current.open && !(key in PROTOTYPES[current.kind])) {
|
|
189
|
+
// A key the data or schema allows without listing it
|
|
190
|
+
return this.add(this.used, [...walked, ...keys.slice(i)], location);
|
|
191
|
+
}
|
|
192
|
+
else {
|
|
193
|
+
const proto = PROTOTYPES[current.kind];
|
|
194
|
+
if (key in proto) {
|
|
195
|
+
// `produkte.map(p => …)` hands every entry to the function;
|
|
196
|
+
// `produkte.length` reads none of them
|
|
197
|
+
if (typeof proto[key] === 'function') {
|
|
198
|
+
current.whole = true;
|
|
199
|
+
}
|
|
200
|
+
return this.add(this.used, walked, location);
|
|
201
|
+
}
|
|
202
|
+
return this.add(this.missing, [...walked, key], location);
|
|
203
|
+
}
|
|
204
|
+
current = next;
|
|
205
|
+
}
|
|
206
|
+
current.read = true;
|
|
207
|
+
if (whole)
|
|
208
|
+
current.whole = true;
|
|
209
|
+
this.add(this.used, walked, location);
|
|
210
|
+
}
|
|
211
|
+
add(into, keys, location) {
|
|
212
|
+
// Reading the root itself (`{{FOR x IN [1, 2]}}`) is not a data path
|
|
213
|
+
if (!keys.length)
|
|
214
|
+
return;
|
|
215
|
+
const path = formatPath(keys);
|
|
216
|
+
let entry = into.get(path);
|
|
217
|
+
if (!entry) {
|
|
218
|
+
entry = { path, locations: [] };
|
|
219
|
+
into.set(path, entry);
|
|
220
|
+
}
|
|
221
|
+
const known = entry.locations.some((l) => l.part === location.part &&
|
|
222
|
+
l.slide === location.slide &&
|
|
223
|
+
l.shape === location.shape);
|
|
224
|
+
if (!known)
|
|
225
|
+
entry.locations.push(location);
|
|
226
|
+
}
|
|
227
|
+
result() {
|
|
228
|
+
const unused = [];
|
|
229
|
+
const anyRead = (n) => n.read ||
|
|
230
|
+
n.whole ||
|
|
231
|
+
[...n.children.values()].some(anyRead) ||
|
|
232
|
+
(!!n.element && anyRead(n.element));
|
|
233
|
+
const collect = (n, keys) => {
|
|
234
|
+
if (n.whole)
|
|
235
|
+
return;
|
|
236
|
+
if (!anyRead(n)) {
|
|
237
|
+
unused.push(formatPath(keys));
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
n.children.forEach((child, key) => collect(child, [...keys, key]));
|
|
241
|
+
if (n.element)
|
|
242
|
+
collect(n.element, [...keys, '[]']);
|
|
243
|
+
};
|
|
244
|
+
if (this.root && !this.root.whole) {
|
|
245
|
+
this.root.children.forEach((child, key) => collect(child, [key]));
|
|
246
|
+
}
|
|
247
|
+
return {
|
|
248
|
+
used: [...this.used.values()],
|
|
249
|
+
unused,
|
|
250
|
+
missing: [...this.missing.values()],
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
exports.DataUsageRecorder = DataUsageRecorder;
|
|
255
|
+
//# sourceMappingURL=usage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usage.js","sourceRoot":"","sources":["../../../src/extensions/template-lint/usage.ts"],"names":[],"mappings":";;;AA+CA,MAAM,IAAI,GAAG,CAAC,IAAsB,EAAE,IAAI,GAAG,KAAK,EAAY,EAAE,CAAC,CAAC;IAChE,IAAI;IACJ,QAAQ,EAAE,IAAI,GAAG,EAAE;IACnB,IAAI;IACJ,IAAI,EAAE,KAAK;IACX,KAAK,EAAE,KAAK;CACb,CAAC,CAAC;AAEH,MAAM,OAAO,GAAG,CAAC,GAAW,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAEnD,MAAM,aAAa,GAAG,CAAC,KAAc,EAAoC,EAAE;IACzE,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IACt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,GAAG,CAAC,CAAC,CAAC,CAAC;QACpE,CAAC;QACD,OAAO;YACL,IAAI,EAAE,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;YAC7B,MAAM;YACN,OAAO,EAAE,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;SACpC,CAAC;IACJ,CAAC;CACF;AA1GD,8CA0GC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export type FileWatcher = {
|
|
2
|
+
close: () => void;
|
|
3
|
+
};
|
|
4
|
+
/**
|
|
5
|
+
* A folder to watch and which names in it count: a file to lint, or - for
|
|
6
|
+
* patterns from a config file - names a new deck or folder could have.
|
|
7
|
+
*/
|
|
8
|
+
export type WatchTarget = {
|
|
9
|
+
dir: string;
|
|
10
|
+
accepts: (name: string) => boolean;
|
|
11
|
+
};
|
|
12
|
+
/** Windows and macOS file systems ignore case; compare names the same way. */
|
|
13
|
+
export declare const nameKey: (name: string) => string;
|
|
14
|
+
/** Targets for fixed files: their folders, filtered by their names. */
|
|
15
|
+
export declare const fileTargets: (files: string[]) => WatchTarget[];
|
|
16
|
+
/**
|
|
17
|
+
* Calls `onChange` whenever a name a target accepts changes. Watches the
|
|
18
|
+
* directories, not the files: PowerPoint saves into a temporary file and
|
|
19
|
+
* renames it over the original, and a watcher on the file itself would stay
|
|
20
|
+
* with the old, deleted one. PowerPoint's `~$deck.pptx` owner file and
|
|
21
|
+
* `.tmp` files never count.
|
|
22
|
+
*
|
|
23
|
+
* One save fires several events; callers debounce.
|
|
24
|
+
*/
|
|
25
|
+
export declare const watchTargets: (targets: WatchTarget[], onChange: () => void, onError: (error: Error) => void) => FileWatcher;
|
|
26
|
+
/** Calls `onChange` whenever one of `files` changes; see `watchTargets`. */
|
|
27
|
+
export declare const watchFiles: (files: string[], onChange: () => void, onError: (error: Error) => void) => FileWatcher;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.watchFiles = exports.watchTargets = exports.fileTargets = exports.nameKey = void 0;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
/** Windows and macOS file systems ignore case; compare names the same way. */
|
|
10
|
+
const nameKey = (name) => process.platform === 'win32' || process.platform === 'darwin'
|
|
11
|
+
? name.toLowerCase()
|
|
12
|
+
: name;
|
|
13
|
+
exports.nameKey = nameKey;
|
|
14
|
+
/** PowerPoint's owner file (`~$deck.pptx`) and temporary files. */
|
|
15
|
+
const isOfficeScratch = (name) => name.startsWith('~$') || /\.tmp$/i.test(name);
|
|
16
|
+
/** Targets for fixed files: their folders, filtered by their names. */
|
|
17
|
+
const fileTargets = (files) => {
|
|
18
|
+
const namesByDir = new Map();
|
|
19
|
+
for (const file of files) {
|
|
20
|
+
const absolute = path_1.default.resolve(file);
|
|
21
|
+
const dir = path_1.default.dirname(absolute);
|
|
22
|
+
if (!namesByDir.has(dir))
|
|
23
|
+
namesByDir.set(dir, new Set());
|
|
24
|
+
namesByDir.get(dir).add((0, exports.nameKey)(path_1.default.basename(absolute)));
|
|
25
|
+
}
|
|
26
|
+
return [...namesByDir].map(([dir, names]) => ({
|
|
27
|
+
dir,
|
|
28
|
+
accepts: (name) => names.has((0, exports.nameKey)(name)),
|
|
29
|
+
}));
|
|
30
|
+
};
|
|
31
|
+
exports.fileTargets = fileTargets;
|
|
32
|
+
/**
|
|
33
|
+
* Calls `onChange` whenever a name a target accepts changes. Watches the
|
|
34
|
+
* directories, not the files: PowerPoint saves into a temporary file and
|
|
35
|
+
* renames it over the original, and a watcher on the file itself would stay
|
|
36
|
+
* with the old, deleted one. PowerPoint's `~$deck.pptx` owner file and
|
|
37
|
+
* `.tmp` files never count.
|
|
38
|
+
*
|
|
39
|
+
* One save fires several events; callers debounce.
|
|
40
|
+
*/
|
|
41
|
+
const watchTargets = (targets, onChange, onError) => {
|
|
42
|
+
// Several targets for one folder: one watcher, any of them may accept
|
|
43
|
+
const byDir = new Map();
|
|
44
|
+
for (const { dir, accepts } of targets) {
|
|
45
|
+
const key = path_1.default.resolve(dir);
|
|
46
|
+
if (!byDir.has(key))
|
|
47
|
+
byDir.set(key, []);
|
|
48
|
+
byDir.get(key).push(accepts);
|
|
49
|
+
}
|
|
50
|
+
const watchers = [];
|
|
51
|
+
const close = () => watchers.forEach((watcher) => watcher.close());
|
|
52
|
+
try {
|
|
53
|
+
for (const [dir, accepts] of byDir) {
|
|
54
|
+
const watcher = fs_1.default.watch(dir, (_event, filename) => {
|
|
55
|
+
// Some platforms report no name; then any change may be ours
|
|
56
|
+
if (!filename)
|
|
57
|
+
return onChange();
|
|
58
|
+
const name = filename.toString();
|
|
59
|
+
if (isOfficeScratch(name))
|
|
60
|
+
return;
|
|
61
|
+
if (accepts.some((accept) => accept(name)))
|
|
62
|
+
onChange();
|
|
63
|
+
});
|
|
64
|
+
watcher.on('error', onError);
|
|
65
|
+
watchers.push(watcher);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
close();
|
|
70
|
+
throw error;
|
|
71
|
+
}
|
|
72
|
+
return { close };
|
|
73
|
+
};
|
|
74
|
+
exports.watchTargets = watchTargets;
|
|
75
|
+
/** Calls `onChange` whenever one of `files` changes; see `watchTargets`. */
|
|
76
|
+
const watchFiles = (files, onChange, onError) => (0, exports.watchTargets)((0, exports.fileTargets)(files), onChange, onError);
|
|
77
|
+
exports.watchFiles = watchFiles;
|
|
78
|
+
//# sourceMappingURL=watch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"watch.js","sourceRoot":"","sources":["../../../src/extensions/template-lint/watch.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAoB;AACpB,gDA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YACH,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;YAC7B,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACzB,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,KAAK,EAAE,CAAC;QACR,MAAM,KAAK,CAAC;IACd,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,CAAC;AACnB,CAAC,CAAC;AAhCW,QAAA,YAAY,gBAgCvB;AAEF,4EAA4E;AACrE,MAAM,UAAU,GAAG,CACxB,KAAe,EACf,QAAoB,EACpB,OAA+B,EAClB,EAAE,CAAC,IAAA,oBAAY,EAAC,IAAA,mBAAW,EAAC,KAAK,CAAC,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;AAJzD,QAAA,UAAU,cAI+C"}
|
|
@@ -38,6 +38,12 @@ export type ExpressionReference = {
|
|
|
38
38
|
path: string[];
|
|
39
39
|
/** Where the name (index 0) and each key of `path` (index i + 1) are. */
|
|
40
40
|
ranges: (SourceRange | undefined)[];
|
|
41
|
+
/**
|
|
42
|
+
* The value itself is used: it is the result, passed to a function or put
|
|
43
|
+
* into a list or object. False where it is only tested or compared
|
|
44
|
+
* (`a > 1`, `!a`, the condition of `a ? b : c`).
|
|
45
|
+
*/
|
|
46
|
+
whole?: boolean;
|
|
41
47
|
};
|
|
42
48
|
export type EvaluateOptions = {
|
|
43
49
|
/** Throw on unknown names instead of treating them as undefined. */
|
|
@@ -65,8 +71,11 @@ export declare class TemplateExpression {
|
|
|
65
71
|
* property path after it (`user.name.toUpperCase()` → `user`,
|
|
66
72
|
* `['name', 'toUpperCase']`). Arrow parameters are not included; a path
|
|
67
73
|
* stops at the first computed key (`a[i].b` → `a`, plus `i`).
|
|
74
|
+
*
|
|
75
|
+
* @param asValue Whether the expression's result is used as a value
|
|
76
|
+
* (output, assignment) rather than tested (`IF`); sets `whole`.
|
|
68
77
|
*/
|
|
69
|
-
references(): ExpressionReference[];
|
|
78
|
+
references(asValue?: boolean): ExpressionReference[];
|
|
70
79
|
/**
|
|
71
80
|
* Blocked keys the expression uses with a fixed name, wherever they are:
|
|
72
81
|
* `a.constructor`, `'x'.constructor`, `x => x.__proto__`,
|