SPB Git

Repository Public

assets-node.ts 3.1 KB 83 lines typescript

1/**2 * =============================================================================3 *                  SP BOUCHER | SOFTWARE & RESEARCH4 *             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project          : KA Maps Engine8 * File             : sdk/web/src/assets-node.ts9 * Module           : sdk10 * Repository       : https://git.spboucher.ai/ka-maps-engine11 * Created          : 2026-12-0112 * Last Modified    : 2026-12-0113 *14 * Author           : Simon-Pierre Boucher15 * Position         : Professor of Finance16 * Institution      : Université du Québec en Outaouais (UQO)17 * Organization     : SP Boucher18 * Website          : https://spboucher.ai19 * Git              : https://git.spboucher.ai20 *21 * Preferred Contact: support@spboucher.ai22 * Development      : dev@spboucher.ai23 * Support          : support@spboucher.ai24 * Security/Admin   : admin@spboucher.ai25 *26 * Copyright (c) 202627 * Simon-Pierre Boucher28 * All rights reserved where applicable. This file is governed by the29 * applicable project license, copyright notices and relevant law.30 * Existing third-party rights and notices remain unaffected.31 *32 * License          : None specified (no license file in this repository)33 *34 * Do not embed credentials, private keys, access tokens,35 * certificates or confidential personal information.36 *37 * =============================================================================38 * END OF SP BOUCHER SOURCE HEADER39 * =============================================================================40 */4142// Outils Node (non importés par le code navigateur) : emplacement des actifs du paquet et copie43// vers le dossier public d'un site.4445import { copyFileSync, existsSync, mkdirSync, readFileSync, statSync } from 'node:fs';46import { dirname, join } from 'node:path';47import { fileURLToPath } from 'node:url';48import { VERSION } from './version.js';4950export const ASSET_FILES = ['km_wasm_bg.wasm', 'ka-maps-worker.js'] as const;5152/** Dossier `dist/assets` du paquet installé. */53export function assetsDir(): string {54  return join(dirname(fileURLToPath(import.meta.url)), 'assets');55}5657/** Chemin public par défaut des actifs : `/ka-maps/<version>/`. */58export function defaultPublicPath(): string {59  return `/ka-maps/${VERSION}/`;60}6162/**63 * Copie les actifs dans `<publicDir>/ka-maps/<version>/` (ou `<publicDir>/<subdir>/`).64 * Ne recopie pas un fichier identique (taille et contenu). Rend la liste des fichiers écrits.65 */66export function copyAssets(publicDir: string, subdir = `ka-maps/${VERSION}`): { dir: string; written: string[] } {67  const src = assetsDir();68  const dst = join(publicDir, subdir);69  mkdirSync(dst, { recursive: true });70  const written: string[] = [];71  for (const f of ASSET_FILES) {72    const from = join(src, f);73    const to = join(dst, f);74    if (!existsSync(from)) throw new Error(`@ka/maps : actif manquant dans le paquet : ${from}`);75    if (existsSync(to) && statSync(to).size === statSync(from).size && readFileSync(to).equals(readFileSync(from))) continue;76    copyFileSync(from, to);77    written.push(to);78  }79  return { dir: dst, written };80}8182export { VERSION };83
Files main
Menu

Theme