-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathapp.plugin.js
More file actions
84 lines (69 loc) · 2.08 KB
/
app.plugin.js
File metadata and controls
84 lines (69 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
const pkg = require('./package.json');
let configPlugins;
try {
configPlugins = require('@expo/config-plugins');
} catch (error) {
if (error && error.code !== 'MODULE_NOT_FOUND') {
throw error;
}
configPlugins = require('expo/config-plugins');
}
const { createRunOncePlugin } = configPlugins;
const withAndroidGradleProperties =
typeof configPlugins.withAndroidGradleProperties === 'function'
? configPlugins.withAndroidGradleProperties
: configPlugins.withGradleProperties;
if (typeof withAndroidGradleProperties !== 'function') {
throw new Error(
`${pkg.name}: incompatible expo config-plugins API (missing Gradle properties helper).`
);
}
const VALID_FEATURES = new Set(['barcode', 'text', 'tables']);
const PROPERTY_KEY = 'DocumentScanner_analysisFeatures';
function normalizeAnalysisFeatures(raw) {
if (raw == null || raw === '') {
return 'none';
}
const value = String(raw).trim().toLowerCase();
if (value === 'none') {
return 'none';
}
if (value === 'all') {
return 'all';
}
const features = value
.split(',')
.map((f) => f.trim())
.filter(Boolean);
const invalid = features.filter((f) => !VALID_FEATURES.has(f));
if (invalid.length > 0) {
throw new Error(
`${pkg.name}: invalid analysisFeatures value(s): ${invalid.join(', ')}. ` +
`Expected comma-separated combination of 'barcode', 'text', 'tables', or 'all' / 'none'.`
);
}
return features.join(',');
}
function withDocumentScannerAnalysisFeatures(config, props = {}) {
const analysisFeatures = normalizeAnalysisFeatures(props.analysisFeatures);
return withAndroidGradleProperties(config, (mod) => {
const existing = mod.modResults.find(
(item) => item.type === 'property' && item.key === PROPERTY_KEY
);
if (existing) {
existing.value = analysisFeatures;
} else {
mod.modResults.push({
type: 'property',
key: PROPERTY_KEY,
value: analysisFeatures,
});
}
return mod;
});
}
module.exports = createRunOncePlugin(
withDocumentScannerAnalysisFeatures,
pkg.name,
pkg.version
);