|
| 1 | +#!/usr/bin/env node |
| 2 | +// Copies template files (src/**/*.template.*) into dist/, preserving the |
| 3 | +// directory structure relative to src/. Replaces the previous `cpx` dependency, |
| 4 | +// which pulled in a vulnerable chokidar@2 -> micromatch@3 -> braces chain |
| 5 | +// (GHSA-grv7-fg5c-xmjg) with no patch available for the 1.x/2.x line. |
| 6 | +const fs = require('fs'); |
| 7 | +const path = require('path'); |
| 8 | + |
| 9 | +const SRC_DIR = path.resolve(__dirname, '..', 'src'); |
| 10 | +const DIST_DIR = path.resolve(__dirname, '..', 'dist'); |
| 11 | +const TEMPLATE_RE = /\.template\.[^.]+$/; |
| 12 | + |
| 13 | +function collectTemplates(dir) { |
| 14 | + return fs.readdirSync(dir, { withFileTypes: true }).flatMap((entry) => { |
| 15 | + const fullPath = path.join(dir, entry.name); |
| 16 | + if (entry.isDirectory()) return collectTemplates(fullPath); |
| 17 | + return TEMPLATE_RE.test(entry.name) ? [fullPath] : []; |
| 18 | + }); |
| 19 | +} |
| 20 | + |
| 21 | +const templates = collectTemplates(SRC_DIR); |
| 22 | + |
| 23 | +for (const srcPath of templates) { |
| 24 | + const relPath = path.relative(SRC_DIR, srcPath); |
| 25 | + const destPath = path.join(DIST_DIR, relPath); |
| 26 | + fs.mkdirSync(path.dirname(destPath), { recursive: true }); |
| 27 | + fs.copyFileSync(srcPath, destPath); |
| 28 | +} |
| 29 | + |
| 30 | +console.log(`copy-templates: ${templates.length} file(s) copied to dist/`); |
0 commit comments