exifreader 4.54.0 → 4.55.0
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/README.md +398 -27
- package/bin/analyze.js +139 -9
- package/bin/build-pages.js +21 -35
- package/bin/cli.js +81 -13
- package/bin/generate-tag-modules.js +287 -0
- package/dist/exif-reader.js +1 -1
- package/dist/exif-reader.js.map +1 -1
- package/exif-reader.d.ts +213 -38
- package/package.json +71 -11
- package/src/composable/brand.js +10 -0
- package/src/composable/composition-tag-filter.js +97 -0
- package/src/composable/composition.js +195 -0
- package/src/composable/core.d.ts +148 -0
- package/src/composable/core.js +526 -0
- package/src/composable/exif-block-reader.js +197 -0
- package/src/composable/formats/avif.js +19 -0
- package/src/composable/formats/gif.js +28 -0
- package/src/composable/formats/heic.js +19 -0
- package/src/composable/formats/iso-bmff-file-reader.js +14 -0
- package/src/composable/formats/jpeg.js +55 -0
- package/src/composable/formats/jxl.js +30 -0
- package/src/composable/formats/png.js +187 -0
- package/src/composable/formats/tiff.js +18 -0
- package/src/composable/formats/webp.js +28 -0
- package/src/composable/formats/xml.js +18 -0
- package/src/composable/formats.d.ts +17 -0
- package/src/composable/formats.js +17 -0
- package/src/composable/group-helpers.js +129 -0
- package/src/composable/groups/canon.js +26 -0
- package/src/composable/groups/composite.js +43 -0
- package/src/composable/groups/exif.js +48 -0
- package/src/composable/groups/gps.js +75 -0
- package/src/composable/groups/icc.js +52 -0
- package/src/composable/groups/iptc.js +86 -0
- package/src/composable/groups/maker-notes.js +21 -0
- package/src/composable/groups/mpf.js +25 -0
- package/src/composable/groups/pentax.js +34 -0
- package/src/composable/groups/photoshop.js +18 -0
- package/src/composable/groups/thumbnail.js +131 -0
- package/src/composable/groups/xmp.js +118 -0
- package/src/composable/groups.d.ts +20 -0
- package/src/composable/groups.js +105 -0
- package/src/composable/iptc-block-reader.js +44 -0
- package/src/composable/read-view.js +165 -0
- package/src/composable/tag-binding-name.js +17 -0
- package/src/composable/tags/exif.d.ts +295 -0
- package/src/composable/tags/exif.js +396 -0
- package/src/composable/tags/iptc.d.ts +84 -0
- package/src/composable/tags/iptc.js +109 -0
- package/src/composable/value-budget.js +24 -0
- package/src/composite.js +2 -2
- package/src/decompression.js +60 -0
- package/src/engine.js +50 -106
- package/src/errors.js +8 -2
- package/src/exif-reader.d.ts +8 -0
- package/src/exif-reader.js +112 -763
- package/src/file-loaders.js +74 -1
- package/src/file-tags.js +9 -9
- package/src/image-header.js +13 -47
- package/src/iptc-tag-names-descriptions.js +334 -0
- package/src/iptc-tag-names.js +50 -306
- package/src/iptc-tags.js +41 -27
- package/src/jfif-tags.js +9 -9
- package/src/load-auto.js +2 -2
- package/src/loadview-pipeline.js +52 -192
- package/src/node-require.js +15 -2
- package/src/png-text-tags.js +5 -3
- package/src/tag-filter-config.js +24 -15
- package/src/tag-filter.js +15 -3
- package/src/tag-names-0th-ifd-descriptions.js +232 -0
- package/src/tag-names-0th-ifd.js +49 -173
- package/src/tag-names-common.js +263 -211
- package/src/tag-names-exif-ifd-descriptions.js +249 -0
- package/src/tag-names-exif-ifd.js +55 -187
- package/src/tag-names-gps-ifd-descriptions.js +156 -0
- package/src/tag-names-gps-ifd.js +39 -146
- package/src/tag-names-utils.js +28 -3
- package/src/tags-helpers.js +6 -2
- package/src/types.js +2 -0
- package/src/unsupported-format-error.js +21 -0
- package/src/utils.js +22 -85
- package/src/xmp-tag-names.js +42 -21
- package/webpack.config.js +1 -1
package/bin/analyze.js
CHANGED
|
@@ -28,6 +28,20 @@ const GROUP_MODULES = {
|
|
|
28
28
|
photoshop: 'photoshop',
|
|
29
29
|
makerNotes: 'maker_notes'
|
|
30
30
|
};
|
|
31
|
+
const COMPOSABLE_FORMATS = ['tiff', 'jpeg', 'png', 'heic', 'avif', 'jxl', 'webp', 'gif', 'xml'];
|
|
32
|
+
const COMPOSABLE_GROUP_MODULES = {
|
|
33
|
+
iptc: 'iptc',
|
|
34
|
+
xmp: 'xmp',
|
|
35
|
+
icc: 'icc',
|
|
36
|
+
photoshop: 'photoshop',
|
|
37
|
+
mpf: 'mpf',
|
|
38
|
+
maker_notes: 'makerNotes',
|
|
39
|
+
thumbnail: 'thumbnail'
|
|
40
|
+
};
|
|
41
|
+
const COMPOSABLE_RESULT_GROUPS = ['gps', 'composite'];
|
|
42
|
+
const COMPOSABLE_GROUPS = ['iptc', 'xmp', 'icc', 'photoshop', 'mpf', 'makerNotes', 'gps', 'composite', 'thumbnail'];
|
|
43
|
+
const DOM_PARSER_COMMENT = '// Outside browsers, xmp needs a domParser in createReader, for example '
|
|
44
|
+
+ 'new DOMParser({onError: onErrorStopParsing}) from @xmldom/xmldom.';
|
|
31
45
|
const THUMBNAIL_NON_TAG_KEYS = ['image', 'base64', 'type'];
|
|
32
46
|
const GPS_POINTER = 'GPS Info IFD Pointer';
|
|
33
47
|
const INTEROPERABILITY_POINTER = 'Interoperability IFD Pointer';
|
|
@@ -35,9 +49,12 @@ const INTEROPERABILITY_POINTER = 'Interoperability IFD Pointer';
|
|
|
35
49
|
module.exports = {
|
|
36
50
|
collectImagePaths,
|
|
37
51
|
loadFullParser,
|
|
52
|
+
loadTagBindingName,
|
|
53
|
+
loadIptcTagExportNames,
|
|
38
54
|
resolveDomParser,
|
|
39
55
|
analyzeImages,
|
|
40
56
|
deriveConfig,
|
|
57
|
+
deriveImports,
|
|
41
58
|
writeConfigToPackageJson
|
|
42
59
|
};
|
|
43
60
|
|
|
@@ -108,6 +125,27 @@ function loadFullParser() {
|
|
|
108
125
|
return import(sourceUrl).then((sourceModule) => sourceModule.default);
|
|
109
126
|
}
|
|
110
127
|
|
|
128
|
+
/**
|
|
129
|
+
* Load the function that names the exports of exifreader/tags/*, from the
|
|
130
|
+
* ES module source.
|
|
131
|
+
*
|
|
132
|
+
* @returns {Promise<function(string): string>} Resolves to getTagBindingName.
|
|
133
|
+
*/
|
|
134
|
+
function loadTagBindingName() {
|
|
135
|
+
const sourceUrl = url.pathToFileURL(path.join(EXIFREADER_ROOT_DIR, 'src', 'composable', 'tag-binding-name.js')).href;
|
|
136
|
+
return import(sourceUrl).then((sourceModule) => sourceModule.getTagBindingName);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Load the names exifreader/tags/iptc exports, from the ES module source.
|
|
141
|
+
*
|
|
142
|
+
* @returns {Promise<string[]>}
|
|
143
|
+
*/
|
|
144
|
+
function loadIptcTagExportNames() {
|
|
145
|
+
const sourceUrl = url.pathToFileURL(path.join(EXIFREADER_ROOT_DIR, 'src', 'composable', 'tags', 'iptc.js')).href;
|
|
146
|
+
return import(sourceUrl).then((sourceModule) => Object.keys(sourceModule));
|
|
147
|
+
}
|
|
148
|
+
|
|
111
149
|
/**
|
|
112
150
|
* Create the xmldom DOM parser the way src/dom-parser.js does, resolving the
|
|
113
151
|
* package from the exifreader directory first and then from cwd.
|
|
@@ -158,9 +196,10 @@ async function analyzeImages(paths, deps) {
|
|
|
158
196
|
* the given parse results.
|
|
159
197
|
*
|
|
160
198
|
* @param {Object[]} results Expanded ExifReader results.
|
|
199
|
+
* @param {string} [product] What the warnings call the result: 'build' or 'reader'.
|
|
161
200
|
* @returns {{config: {include: Object}, fileTypes: string[], warnings: string[]}}
|
|
162
201
|
*/
|
|
163
|
-
function deriveConfig(results) {
|
|
202
|
+
function deriveConfig(results, product = 'build') {
|
|
164
203
|
const found = {modules: new Set(), exifNames: new Set(), iptcNames: new Set(), fileTypes: new Set(), exifArray: false};
|
|
165
204
|
for (const tags of results) {
|
|
166
205
|
observeResult(tags, found);
|
|
@@ -185,7 +224,7 @@ function deriveConfig(results) {
|
|
|
185
224
|
return {
|
|
186
225
|
config: {include},
|
|
187
226
|
fileTypes: Array.from(found.fileTypes).sort(),
|
|
188
|
-
warnings: warningsFor(found.modules)
|
|
227
|
+
warnings: warningsFor(found.modules, product)
|
|
189
228
|
};
|
|
190
229
|
}
|
|
191
230
|
|
|
@@ -209,7 +248,7 @@ function observeResult(tags, found) {
|
|
|
209
248
|
}
|
|
210
249
|
if ('exif' in tags) {
|
|
211
250
|
found.exifArray = true;
|
|
212
|
-
addNames(found.exifNames,
|
|
251
|
+
addNames(found.exifNames, exifGroupNames(tags));
|
|
213
252
|
}
|
|
214
253
|
observeThumbnail(tags.Thumbnail, found);
|
|
215
254
|
observeThumbnail(tags.exif && tags.exif.Thumbnail, found);
|
|
@@ -218,6 +257,10 @@ function observeResult(tags, found) {
|
|
|
218
257
|
}
|
|
219
258
|
}
|
|
220
259
|
|
|
260
|
+
function exifGroupNames(tags) {
|
|
261
|
+
return Object.keys(tags.exif).filter((name) => name !== 'Thumbnail');
|
|
262
|
+
}
|
|
263
|
+
|
|
221
264
|
function addNames(names, newNames) {
|
|
222
265
|
for (const name of newNames) {
|
|
223
266
|
names.add(name);
|
|
@@ -266,25 +309,112 @@ function withoutInjectedNames(names, modules) {
|
|
|
266
309
|
return names.filter((name) => !injected.includes(name));
|
|
267
310
|
}
|
|
268
311
|
|
|
269
|
-
function warningsFor(modules) {
|
|
312
|
+
function warningsFor(modules, product) {
|
|
270
313
|
const warnings = [];
|
|
271
314
|
const missingFormats = FORMATS.filter((format) => !modules.has(format)).map((format) => FORMAT_NAMES[format]);
|
|
272
315
|
if (missingFormats.length > 0) {
|
|
273
|
-
warnings.push(missingFormatsWarning(missingFormats));
|
|
316
|
+
warnings.push(missingFormatsWarning(missingFormats, product));
|
|
274
317
|
}
|
|
275
|
-
warnings.push(
|
|
318
|
+
warnings.push(`Tags and metadata groups that do not appear in these images are left out of the ${product}, so pass a `
|
|
276
319
|
+ 'sample of every kind of image your app reads, all in one run.');
|
|
277
320
|
return warnings;
|
|
278
321
|
}
|
|
279
322
|
|
|
280
|
-
function missingFormatsWarning(names) {
|
|
323
|
+
function missingFormatsWarning(names, product) {
|
|
281
324
|
if (names.length === 1) {
|
|
282
|
-
return `No ${names[0]} images were found, so the
|
|
325
|
+
return `No ${names[0]} images were found, so the ${product} will not read that format.`;
|
|
283
326
|
}
|
|
284
|
-
return `No ${names.slice(0, -1).join(', ')} or ${names[names.length - 1]} images were found, so the
|
|
327
|
+
return `No ${names.slice(0, -1).join(', ')} or ${names[names.length - 1]} images were found, so the ${product} `
|
|
285
328
|
+ 'will not read those formats.';
|
|
286
329
|
}
|
|
287
330
|
|
|
331
|
+
/**
|
|
332
|
+
* Derive the createReader imports of the composable API that read everything
|
|
333
|
+
* found in the given parse results.
|
|
334
|
+
*
|
|
335
|
+
* @param {Object[]} results Expanded ExifReader results.
|
|
336
|
+
* @param {function(string): string} getTagBindingName The function
|
|
337
|
+
* loadTagBindingName resolves to.
|
|
338
|
+
* @param {string[]} iptcTagExportNames The names loadIptcTagExportNames
|
|
339
|
+
* resolves to.
|
|
340
|
+
* @returns {string} JavaScript import lines and a createReader call.
|
|
341
|
+
*/
|
|
342
|
+
function deriveImports(results, getTagBindingName, iptcTagExportNames) {
|
|
343
|
+
const derived = deriveConfig(results);
|
|
344
|
+
const formats = COMPOSABLE_FORMATS.filter((name) => derived.fileTypes.includes(name));
|
|
345
|
+
const iptcTags = composableIptcTags(results, getTagBindingName, iptcTagExportNames);
|
|
346
|
+
const groups = composableGroups(derived.config.include, results, formats)
|
|
347
|
+
.filter((name) => name !== 'iptc' || iptcTags.length === 0);
|
|
348
|
+
const tables = [
|
|
349
|
+
{key: 'formats', names: formats, specifier: 'exifreader/formats'},
|
|
350
|
+
{key: 'groups', names: groups, specifier: 'exifreader/groups'},
|
|
351
|
+
{key: 'tags', names: composableTags(results, getTagBindingName), specifier: 'exifreader/tags/exif'},
|
|
352
|
+
{key: 'tags', names: iptcTags, specifier: 'exifreader/tags/iptc'}
|
|
353
|
+
].filter((table) => table.names.length > 0);
|
|
354
|
+
|
|
355
|
+
const lines = ['import {createReader} from \'exifreader/core\';']
|
|
356
|
+
.concat(tables.map((table) => `import {${table.names.join(', ')}} from '${table.specifier}';`), ['']);
|
|
357
|
+
if (groups.includes('xmp')) {
|
|
358
|
+
lines.push(DOM_PARSER_COMMENT);
|
|
359
|
+
}
|
|
360
|
+
const entries = getEntries(tables).map((entry) => `${entry.key}: [${entry.names.join(', ')}]`);
|
|
361
|
+
lines.push(`const reader = createReader({${entries.join(', ')}});`);
|
|
362
|
+
return lines.join('\n');
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
// Every iptc name as a tag, or none when exifreader/tags/iptc has no export
|
|
366
|
+
// for a name, as the iptc group then has to read it.
|
|
367
|
+
function composableIptcTags(results, getTagBindingName, iptcTagExportNames) {
|
|
368
|
+
const names = new Set();
|
|
369
|
+
for (const tags of results.filter((result) => 'iptc' in result)) {
|
|
370
|
+
addNames(names, Object.keys(tags.iptc));
|
|
371
|
+
}
|
|
372
|
+
const bindingNames = Array.from(names).map((name) => getTagBindingName(name));
|
|
373
|
+
if (bindingNames.some((bindingName) => !iptcTagExportNames.includes(bindingName))) {
|
|
374
|
+
return [];
|
|
375
|
+
}
|
|
376
|
+
return bindingNames.sort();
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
// An XMP sidecar is read only with xmp composed, and the gps and composite
|
|
380
|
+
// groups have no custom build module of their own.
|
|
381
|
+
function composableGroups(include, results, formats) {
|
|
382
|
+
const groups = new Set(Object.keys(include)
|
|
383
|
+
.filter((name) => name in COMPOSABLE_GROUP_MODULES)
|
|
384
|
+
.map((name) => COMPOSABLE_GROUP_MODULES[name]));
|
|
385
|
+
for (const group of COMPOSABLE_RESULT_GROUPS.filter((name) => results.some((tags) => name in tags))) {
|
|
386
|
+
groups.add(group);
|
|
387
|
+
}
|
|
388
|
+
if (formats.includes('xml')) {
|
|
389
|
+
groups.add('xmp');
|
|
390
|
+
}
|
|
391
|
+
return COMPOSABLE_GROUPS.filter((name) => groups.has(name));
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
// Every exif name, the ones a composed group reads included: a reader returns
|
|
395
|
+
// those only when they are in its tags.
|
|
396
|
+
function composableTags(results, getTagBindingName) {
|
|
397
|
+
const names = new Set();
|
|
398
|
+
for (const tags of results.filter((result) => 'exif' in result)) {
|
|
399
|
+
addNames(names, exifGroupNames(tags).map((name) => getTagBindingName(name)));
|
|
400
|
+
}
|
|
401
|
+
return Array.from(names).sort();
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
// One entry per key, so the exif and iptc tag tables make one tags entry.
|
|
405
|
+
function getEntries(tables) {
|
|
406
|
+
const entries = [];
|
|
407
|
+
for (const table of tables) {
|
|
408
|
+
const entry = entries.find(({key}) => key === table.key);
|
|
409
|
+
if (entry) {
|
|
410
|
+
entry.names = entry.names.concat(table.names);
|
|
411
|
+
} else {
|
|
412
|
+
entries.push({key: table.key, names: table.names});
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
return entries;
|
|
416
|
+
}
|
|
417
|
+
|
|
288
418
|
/**
|
|
289
419
|
* Set the include section of the "exifreader" key in a package.json file,
|
|
290
420
|
* replacing any include or exclude section there and keeping everything else,
|
package/bin/build-pages.js
CHANGED
|
@@ -14,29 +14,24 @@ const path = require('path');
|
|
|
14
14
|
const ROOT = path.join(__dirname, '..');
|
|
15
15
|
const GH_PAGES_TEMP_DIR = path.join(ROOT, 'gh-pages');
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
buildSite();
|
|
19
|
-
|
|
20
|
-
function createTempDirectory() {
|
|
21
|
-
try {
|
|
22
|
-
fs.mkdirSync(GH_PAGES_TEMP_DIR);
|
|
23
|
-
} catch (error) {
|
|
24
|
-
if (error.code !== 'EEXIST') {
|
|
25
|
-
console.error(error); // eslint-disable-line no-console
|
|
26
|
-
process.exit(1);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
17
|
+
if (require.main === module) {
|
|
18
|
+
buildSite(ROOT, GH_PAGES_TEMP_DIR);
|
|
29
19
|
}
|
|
30
20
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
21
|
+
/**
|
|
22
|
+
* Collects the example pages, the whole source tree and the bundle, and copies
|
|
23
|
+
* them into the output directory, creating every directory on the way.
|
|
24
|
+
*
|
|
25
|
+
* @param {string} root The repository root.
|
|
26
|
+
* @param {string} outputDirectory Where the site is assembled.
|
|
27
|
+
*/
|
|
28
|
+
function buildSite(root, outputDirectory) {
|
|
29
|
+
let files = collectFiles(path.join(root, 'examples'), '', ['html', 'css', 'js']);
|
|
30
|
+
files = collectFiles(root, 'src', ['js'], files);
|
|
31
|
+
files[path.join(root, 'dist/exif-reader.js')] = 'exif-reader.js';
|
|
32
|
+
files[path.join(root, 'dist/exif-reader.js.map')] = 'exif-reader.js.map';
|
|
37
33
|
|
|
38
|
-
|
|
39
|
-
copyFiles(files);
|
|
34
|
+
copyFiles(files, outputDirectory);
|
|
40
35
|
}
|
|
41
36
|
|
|
42
37
|
function collectFiles(rootDirectory, subDirectory, extensions, files = {}) {
|
|
@@ -55,21 +50,12 @@ function hasFileExtension(filename, extensions) {
|
|
|
55
50
|
return extensions.some((extension) => filename.endsWith(extension));
|
|
56
51
|
}
|
|
57
52
|
|
|
58
|
-
function
|
|
59
|
-
directories.forEach((directory) => {
|
|
60
|
-
try {
|
|
61
|
-
fs.mkdirSync(path.join(GH_PAGES_TEMP_DIR, directory));
|
|
62
|
-
} catch (error) {
|
|
63
|
-
if (error.code !== 'EEXIST') {
|
|
64
|
-
console.error(error); // eslint-disable-line no-console
|
|
65
|
-
process.exit(1);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
function copyFiles(files) {
|
|
53
|
+
function copyFiles(files, outputDirectory) {
|
|
72
54
|
for (const from in files) {
|
|
73
|
-
|
|
55
|
+
const to = path.join(outputDirectory, files[from]);
|
|
56
|
+
fs.mkdirSync(path.dirname(to), {recursive: true});
|
|
57
|
+
fs.copyFileSync(from, to);
|
|
74
58
|
}
|
|
75
59
|
}
|
|
60
|
+
|
|
61
|
+
module.exports = {buildSite};
|
package/bin/cli.js
CHANGED
|
@@ -10,10 +10,22 @@ const path = require('path');
|
|
|
10
10
|
const fs = require('fs');
|
|
11
11
|
const {createRequire} = require('module');
|
|
12
12
|
const {readMarker, markerMatches} = require('./custom-build-marker');
|
|
13
|
-
const {
|
|
13
|
+
const {
|
|
14
|
+
collectImagePaths,
|
|
15
|
+
loadFullParser,
|
|
16
|
+
loadTagBindingName,
|
|
17
|
+
loadIptcTagExportNames,
|
|
18
|
+
resolveDomParser,
|
|
19
|
+
analyzeImages,
|
|
20
|
+
deriveConfig,
|
|
21
|
+
deriveImports,
|
|
22
|
+
writeConfigToPackageJson
|
|
23
|
+
} = require('./analyze');
|
|
14
24
|
const {verifyImages, loadCustomParser} = require('./verify-build');
|
|
15
25
|
|
|
16
26
|
const EXIFREADER_ROOT_DIR = path.join(__dirname, '..');
|
|
27
|
+
const COMPOSABLE_API_URL = 'https://github.com/mattiasw/ExifReader#composable-api';
|
|
28
|
+
const MIGRATION_URL = 'https://github.com/mattiasw/ExifReader#migrating-to-the-composable-api';
|
|
17
29
|
|
|
18
30
|
module.exports = {parseArgs, run, checkLocalInstall, readConfigFile};
|
|
19
31
|
|
|
@@ -31,6 +43,8 @@ if (require.main === module) {
|
|
|
31
43
|
build: (options) => require('./build').runBuild(options),
|
|
32
44
|
fs,
|
|
33
45
|
loadFullParser,
|
|
46
|
+
loadTagBindingName,
|
|
47
|
+
loadIptcTagExportNames,
|
|
34
48
|
loadCustomParser,
|
|
35
49
|
resolveDomParser,
|
|
36
50
|
log: console.log,
|
|
@@ -79,6 +93,7 @@ function parseArgs(argv) {
|
|
|
79
93
|
ifNeeded: args.includes('--if-needed'),
|
|
80
94
|
config: configPath(args),
|
|
81
95
|
write: args.includes('--write'),
|
|
96
|
+
imports: args.includes('--imports'),
|
|
82
97
|
auto: args.includes('--auto'),
|
|
83
98
|
verify: args.includes('--verify'),
|
|
84
99
|
paths: positionals(args).slice(1)
|
|
@@ -109,6 +124,8 @@ function helpText() {
|
|
|
109
124
|
+ ' build Rebuild dist/exif-reader.js using the "exifreader" custom build\n'
|
|
110
125
|
+ ' configuration (include/exclude) from --config, the\n'
|
|
111
126
|
+ ' EXIFREADER_CUSTOM_BUILD env var, or your project\'s package.json.\n'
|
|
127
|
+
+ ' Deprecated: the custom build is removed in v5. Compose a reader\n'
|
|
128
|
+
+ ' with createReader from exifreader/core instead.\n'
|
|
112
129
|
+ ' analyze <paths...> Read the given image files and directories with the full parser\n'
|
|
113
130
|
+ ' and print the include configuration that reads everything found\n'
|
|
114
131
|
+ ' in them.\n'
|
|
@@ -128,6 +145,8 @@ function helpText() {
|
|
|
128
145
|
+ 'Options for analyze:\n'
|
|
129
146
|
+ ' --write Put the configuration in your project\'s package.json, replacing\n'
|
|
130
147
|
+ ' its include or exclude section.\n'
|
|
148
|
+
+ ' --imports Print the createReader imports of the composable API that read\n'
|
|
149
|
+
+ ' everything found, instead of the configuration.\n'
|
|
131
150
|
+ '\n'
|
|
132
151
|
+ 'Options:\n'
|
|
133
152
|
+ ' -h, --help Show this help.\n'
|
|
@@ -204,6 +223,10 @@ function sampleOptionError(args) {
|
|
|
204
223
|
return '--write is an option of analyze, not build. To save the configuration, run '
|
|
205
224
|
+ '"npx exifreader analyze <paths...> --write", then "npx exifreader build".';
|
|
206
225
|
}
|
|
226
|
+
if (args.imports) {
|
|
227
|
+
return '--imports is an option of analyze, not build. To print the createReader imports for your '
|
|
228
|
+
+ 'images, run "npx exifreader analyze <paths...> --imports".';
|
|
229
|
+
}
|
|
207
230
|
if (args.auto && args.config !== undefined) {
|
|
208
231
|
return '--auto and --config cannot be used together. --auto builds the configuration it derives '
|
|
209
232
|
+ 'from the images, so leave out --config.';
|
|
@@ -251,7 +274,7 @@ function reportSkipped(skipped, deps) {
|
|
|
251
274
|
}
|
|
252
275
|
|
|
253
276
|
function runAutoBuild(args, cwd, imagePaths, install, deps) {
|
|
254
|
-
return failOnRejection(analyzeSample(imagePaths, cwd, deps).then((analysis) => {
|
|
277
|
+
return failOnRejection(analyzeSample(imagePaths, cwd, deps, renderConfig).then((analysis) => {
|
|
255
278
|
if (!analysis) {
|
|
256
279
|
return undefined;
|
|
257
280
|
}
|
|
@@ -260,18 +283,23 @@ function runAutoBuild(args, cwd, imagePaths, install, deps) {
|
|
|
260
283
|
}), deps);
|
|
261
284
|
}
|
|
262
285
|
|
|
286
|
+
function renderConfig(derived) {
|
|
287
|
+
return JSON.stringify(derived.config, null, 2);
|
|
288
|
+
}
|
|
289
|
+
|
|
263
290
|
function failOnRejection(promise, deps) {
|
|
264
291
|
return promise.catch((error) => fail(deps, error.message));
|
|
265
292
|
}
|
|
266
293
|
|
|
267
|
-
// Prints the derived configuration
|
|
268
|
-
//
|
|
269
|
-
//
|
|
270
|
-
|
|
294
|
+
// Prints what render returns for the derived configuration and the expanded
|
|
295
|
+
// results on stdout and the summary on stderr, and resolves to the
|
|
296
|
+
// configuration and the images it was derived from. Resolves to undefined
|
|
297
|
+
// after failing when no image could be read.
|
|
298
|
+
async function analyzeSample(imagePaths, cwd, deps, render, product) {
|
|
271
299
|
const domParser = deps.resolveDomParser(cwd);
|
|
272
300
|
if (!domParser) {
|
|
273
301
|
deps.error('@xmldom/xmldom was not found, so the XMP content of the images was not read. '
|
|
274
|
-
+ 'XMP is still included
|
|
302
|
+
+ 'XMP is still included when an image has it, unless it is Brotli-compressed in a JPEG XL file.');
|
|
275
303
|
}
|
|
276
304
|
const parser = await deps.loadFullParser();
|
|
277
305
|
const {results, skipped} = await withoutConsoleWarnings(!domParser, () => analyzeImages(imagePaths, {fs: deps.fs, parser, domParser}));
|
|
@@ -281,8 +309,9 @@ async function analyzeSample(imagePaths, cwd, deps) {
|
|
|
281
309
|
return undefined;
|
|
282
310
|
}
|
|
283
311
|
|
|
284
|
-
const
|
|
285
|
-
|
|
312
|
+
const expandedResults = results.map((result) => result.tags);
|
|
313
|
+
const derived = deriveConfig(expandedResults, product);
|
|
314
|
+
deps.log(render(derived, expandedResults));
|
|
286
315
|
deps.error(`Analyzed ${countOf(results.length, 'image')} (${derived.fileTypes.join(', ')}).`);
|
|
287
316
|
for (const warning of derived.warnings) {
|
|
288
317
|
deps.error(warning);
|
|
@@ -323,9 +352,15 @@ function buildUnlessUpToDate(config, args, install, deps) {
|
|
|
323
352
|
deps.error(sharedInstallMessage(install.distPath));
|
|
324
353
|
}
|
|
325
354
|
deps.log(`Building a custom exifreader bundle at ${install.distPath}`);
|
|
355
|
+
deps.error(customBuildDeprecationMessage());
|
|
326
356
|
deps.build({config});
|
|
327
357
|
}
|
|
328
358
|
|
|
359
|
+
function customBuildDeprecationMessage() {
|
|
360
|
+
return 'The custom build is deprecated and will be removed in exifreader v5. For a small bundle, compose a '
|
|
361
|
+
+ `reader with createReader from exifreader/core instead: ${COMPOSABLE_API_URL}`;
|
|
362
|
+
}
|
|
363
|
+
|
|
329
364
|
async function verifyBuild(imagePaths, cwd, install, deps) {
|
|
330
365
|
const domParser = deps.resolveDomParser(cwd);
|
|
331
366
|
if (!domParser) {
|
|
@@ -360,6 +395,12 @@ async function verifyBuild(imagePaths, cwd, install, deps) {
|
|
|
360
395
|
}
|
|
361
396
|
|
|
362
397
|
function runAnalyzeCommand(args, deps) {
|
|
398
|
+
if (args.imports && args.write) {
|
|
399
|
+
fail(deps, '--imports and --write cannot be used together. --write saves a custom build configuration '
|
|
400
|
+
+ 'to package.json, and --imports prints createReader imports instead of that configuration.');
|
|
401
|
+
return undefined;
|
|
402
|
+
}
|
|
403
|
+
|
|
363
404
|
const cwd = deps.cwd();
|
|
364
405
|
if (args.paths.length === 0) {
|
|
365
406
|
fail(deps, 'analyze needs the image files or directories to read, for example '
|
|
@@ -382,7 +423,7 @@ function runAnalyzeCommand(args, deps) {
|
|
|
382
423
|
return undefined;
|
|
383
424
|
}
|
|
384
425
|
|
|
385
|
-
return failOnRejection(
|
|
426
|
+
return failOnRejection(analyzeForCommand(args, imagePaths, cwd, deps).then((analysis) => {
|
|
386
427
|
if (!analysis) {
|
|
387
428
|
return;
|
|
388
429
|
}
|
|
@@ -390,12 +431,39 @@ function runAnalyzeCommand(args, deps) {
|
|
|
390
431
|
writeToPackageJson(path.join(packageDir, 'package.json'), analysis.config.include, deps);
|
|
391
432
|
return;
|
|
392
433
|
}
|
|
393
|
-
deps.error(
|
|
394
|
-
+ '"npx exifreader build", or save it to a file and run "npx exifreader build --config <file>". '
|
|
395
|
-
+ 'Run this command again with --write to update package.json for you.');
|
|
434
|
+
deps.error(args.imports ? importsHint() : configHint());
|
|
396
435
|
}), deps);
|
|
397
436
|
}
|
|
398
437
|
|
|
438
|
+
function analyzeForCommand(args, imagePaths, cwd, deps) {
|
|
439
|
+
if (!args.imports) {
|
|
440
|
+
return analyzeSample(imagePaths, cwd, deps, renderConfig);
|
|
441
|
+
}
|
|
442
|
+
return Promise.all([deps.loadTagBindingName(), deps.loadIptcTagExportNames()])
|
|
443
|
+
.then(([getTagBindingName, iptcTagExportNames]) => analyzeSample(
|
|
444
|
+
imagePaths,
|
|
445
|
+
cwd,
|
|
446
|
+
deps,
|
|
447
|
+
(derived, results) => deriveImports(results, getTagBindingName, iptcTagExportNames),
|
|
448
|
+
'reader'
|
|
449
|
+
));
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
function importsHint() {
|
|
453
|
+
return 'To use it, put it in place of "import ExifReader from \'exifreader\'" and pass reader.load the image '
|
|
454
|
+
+ 'as bytes or a Blob or File: it takes no path, URL, length, async, domParser or decompress option (domParser and decompress go to createReader), '
|
|
455
|
+
+ 'and always returns a Promise. It returns the tags grouped (tags.exif, tags.gps, ...); '
|
|
456
|
+
+ 'pass expanded: false for flat tags. '
|
|
457
|
+
+ `See ${MIGRATION_URL} for what differs from ExifReader.load and ${COMPOSABLE_API_URL} for how to load each kind of input.`;
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
function configHint() {
|
|
461
|
+
return 'To use it, set it as the "exifreader" section of your package.json and run '
|
|
462
|
+
+ '"npx exifreader build", or save it to a file and run "npx exifreader build --config <file>". '
|
|
463
|
+
+ 'Run this command again with --write to update package.json for you. Or run it with --imports to '
|
|
464
|
+
+ 'print the createReader imports of the composable API, which replaces the custom build.';
|
|
465
|
+
}
|
|
466
|
+
|
|
399
467
|
function writeToPackageJson(filePath, include, deps) {
|
|
400
468
|
let outcome;
|
|
401
469
|
try {
|