File size: 1,278 Bytes
ea7122c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import { cp, mkdir, readFile, rm, stat } from 'node:fs/promises';
import { fileURLToPath } from 'node:url';
import path from 'node:path';

const root = fileURLToPath(new URL('../', import.meta.url));
const output = path.join(root, 'dist');
const directories = ['assets', 'src', 'runtime', 'vendor', 'file-icons', 'library-icons', 'licenses'];
const files = ['index.html', 'favicon.svg', 'empty-cat-v1.png', 'modal-cat-v1.png',
  'openbmb-avatar.webp', 'cat-meow-v1.mp3', 'social-thumbnail-v3.png', 'LICENSE', 'NOTICE'];

// Catch missing LFS downloads before packaging what would look like broken images.
for (const name of ['empty-cat-v1.png', 'modal-cat-v1.png', 'social-thumbnail-v3.png']) {
  const file = await readFile(path.join(root, name));
  if (file.subarray(0, 42).toString().startsWith('version https://git-lfs.github.com/spec/')) {
    throw new Error(`${name} is a Git LFS pointer. Run git lfs pull before building.`);
  }
}
await rm(output, { recursive: true, force: true });
await mkdir(output);
for (const item of [...directories, ...files]) {
  await stat(path.join(root, item));
  await cp(path.join(root, item), path.join(output, item), { recursive: true });
}
console.log('Built dist/ — static files ready for localhost or a Hugging Face static Space.');