File size: 2,004 Bytes
7d5a851
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env node
// register.js — merge npu-forge's own registry into FLM's model_list.json.
// Forge entries live in npu-forge\registry.json (user-space, permanent);
// FLM's list lives in Program Files and gets RESET by flm updates — so this
// merge is idempotent and re-runnable any time a custom model "disappears."
// Needs elevation (run via register-admin.bat). Always backs up first.
'use strict';
const fs = require('fs');
const path = require('path');

const FORGE = path.join(__dirname, '..');
const FLM_LIST = 'C:\\Program Files\\flm\\model_list.json';
const REGISTRY = path.join(FORGE, 'registry.json');

function main() {
  if (!fs.existsSync(REGISTRY)) { console.log('No registry.json — nothing to register.'); return; }
  const reg = JSON.parse(fs.readFileSync(REGISTRY, 'utf8').replace(/^/, ''));
  const ml = JSON.parse(fs.readFileSync(FLM_LIST, 'utf8').replace(/^/, ''));

  // timestamped backup beside the forge registry (user-space, survives anything)
  const stamp = new Date().toISOString().replace(/[:.]/g, '-');
  fs.copyFileSync(FLM_LIST, path.join(FORGE, `model_list.backup-${stamp}.json`));

  let added = 0, kept = 0;
  for (const [key, sizes] of Object.entries(reg.models || {})) {
    for (const [size, entry] of Object.entries(sizes)) {
      ml.models[key] = ml.models[key] || {};
      if (ml.models[key][size] && JSON.stringify(ml.models[key][size]) === JSON.stringify(entry)) { kept++; continue; }
      ml.models[key][size] = entry;
      added++;
      console.log(`registered: ${key}:${size} -> ${entry.name}`);
    }
  }
  try {
    fs.writeFileSync(FLM_LIST, JSON.stringify(ml, null, 2));
  } catch (e) {
    console.error('\n[!] Could not write ' + FLM_LIST);
    console.error('    This needs administrator rights — double-click register-admin.bat instead.');
    process.exit(1);
  }
  console.log(`\nDone: ${added} entries written, ${kept} already current.`);
  console.log('Verify with: flm list  (your models end in -forge)');
}

main();