alphavalid-sdk 0.0.16 → 0.0.17
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/package.json +2 -1
- package/scripts/copy-models.cjs +76 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "alphavalid-sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.17",
|
|
4
4
|
"description": "SDK de validação facial e liveness",
|
|
5
5
|
"main": "dist/alphavalid.umd.js",
|
|
6
6
|
"module": "dist/alphavalid.es.js",
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
"files": [
|
|
9
9
|
"dist",
|
|
10
10
|
"models",
|
|
11
|
+
"scripts",
|
|
11
12
|
"README.md",
|
|
12
13
|
"package.json",
|
|
13
14
|
"vite.config.ts",
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// Copies alphavalid-sdk face-api model files from this package into a consumer app folder.
|
|
4
|
+
// Usage (from consumer app):
|
|
5
|
+
// node ./node_modules/alphavalid-sdk/scripts/copy-models.cjs ./src/assets/alphavalid-models
|
|
6
|
+
|
|
7
|
+
const fs = require('fs');
|
|
8
|
+
const path = require('path');
|
|
9
|
+
|
|
10
|
+
function copyDir(src, dest) {
|
|
11
|
+
fs.mkdirSync(dest, { recursive: true });
|
|
12
|
+
for (const entry of fs.readdirSync(src, { withFileTypes: true })) {
|
|
13
|
+
const srcPath = path.join(src, entry.name);
|
|
14
|
+
const destPath = path.join(dest, entry.name);
|
|
15
|
+
if (entry.isDirectory()) {
|
|
16
|
+
copyDir(srcPath, destPath);
|
|
17
|
+
} else {
|
|
18
|
+
fs.copyFileSync(srcPath, destPath);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function patchManifest(destDir) {
|
|
24
|
+
const candidates = [
|
|
25
|
+
'tiny_face_detector_model-weights_manifest.json',
|
|
26
|
+
'face_landmark_68_tiny_model-weights_manifest.json'
|
|
27
|
+
];
|
|
28
|
+
|
|
29
|
+
for (const file of candidates) {
|
|
30
|
+
const manifestPath = path.join(destDir, file);
|
|
31
|
+
if (!fs.existsSync(manifestPath)) continue;
|
|
32
|
+
|
|
33
|
+
const raw = fs.readFileSync(manifestPath, 'utf8');
|
|
34
|
+
let patched = raw;
|
|
35
|
+
|
|
36
|
+
patched = patched.replaceAll('tiny_face_detector_model-shard1"', 'tiny_face_detector_model-shard1.bin"');
|
|
37
|
+
patched = patched.replaceAll('face_landmark_68_tiny_model-shard1"', 'face_landmark_68_tiny_model-shard1.bin"');
|
|
38
|
+
|
|
39
|
+
if (patched !== raw) fs.writeFileSync(manifestPath, patched);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function ensureBinShard(destDir) {
|
|
44
|
+
const renames = [
|
|
45
|
+
['tiny_face_detector_model-shard1', 'tiny_face_detector_model-shard1.bin'],
|
|
46
|
+
['face_landmark_68_tiny_model-shard1', 'face_landmark_68_tiny_model-shard1.bin']
|
|
47
|
+
];
|
|
48
|
+
|
|
49
|
+
for (const [from, to] of renames) {
|
|
50
|
+
const oldShard = path.join(destDir, from);
|
|
51
|
+
const binShard = path.join(destDir, to);
|
|
52
|
+
if (fs.existsSync(oldShard) && !fs.existsSync(binShard)) {
|
|
53
|
+
fs.renameSync(oldShard, binShard);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const destArg = process.argv[2];
|
|
59
|
+
if (!destArg) {
|
|
60
|
+
console.error('Missing destination path. Example: node copy-models.cjs ./src/assets/alphavalid-models');
|
|
61
|
+
process.exit(1);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const pkgRoot = path.resolve(__dirname, '..');
|
|
65
|
+
const srcModels = path.join(pkgRoot, 'models');
|
|
66
|
+
if (!fs.existsSync(srcModels)) {
|
|
67
|
+
console.error('models/ folder not found in package.');
|
|
68
|
+
process.exit(1);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const dest = path.resolve(process.cwd(), destArg);
|
|
72
|
+
copyDir(srcModels, dest);
|
|
73
|
+
ensureBinShard(dest);
|
|
74
|
+
patchManifest(dest);
|
|
75
|
+
|
|
76
|
+
console.log(`[alphavalid-sdk] Models copied to: ${dest}`);
|