build-member-groups.mjs 1.7 KB

123456789101112131415161718192021
  1. // Build only the two new functions; do not rebuild/deploy the existing identity functions.
  2. import fs from 'node:fs';
  3. import path from 'node:path';
  4. import crypto from 'node:crypto';
  5. import { fileURLToPath } from 'node:url';
  6. const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
  7. const data = JSON.parse(fs.readFileSync(path.join(root, 'references/runtime-data.json')));
  8. const out = path.join(root, 'dist/member-groups');fs.mkdirSync(out, { recursive: true });
  9. const source = [path.join(root, '../src/core/member-groups.js'), ...['postgres.mjs', 'files.mjs', 'core.mjs', 'confirmation.mjs',
  10. 'workshop.mjs', 'board-actions.mjs', 'member-groups.mjs', 'bootstrap.mjs'].map((f) => path.join(root, 'src', f))]
  11. .map((p) => fs.readFileSync(p, 'utf8').replace(/^import .*;\r?\n/gm, '').replace(/^export /gm, '')).join('\n');
  12. const html = fs.readFileSync(path.join(root, 'web/confirm.html'), 'utf8');
  13. const functions = [];
  14. for (const name of ['ksfGetPublicMemberGroups', 'ksfManagePublicMemberGroups']) {
  15. const code = source + '\nasync function handler(request,response){return runDatabaseFunction(' + JSON.stringify(name) + ',request,response,' + JSON.stringify(data) + ',' + JSON.stringify(html) + ');}\n';
  16. new Function(code);
  17. fs.writeFileSync(path.join(out, name + '.js'), code);
  18. functions.push({ name, path: '/' + name, file: name + '.js', sha256: crypto.createHash('sha256').update(code).digest('hex') });
  19. }
  20. fs.writeFileSync(path.join(out, 'manifest.json'), JSON.stringify({ release: 'ksf.member-groups.20261105.v1', existingFunctionsModified: false, functions }, null, 2));
  21. console.log(JSON.stringify({ built: functions.length, out, existingFunctionsModified: false }));