mirror of
https://github.com/zoriya/v10.git
synced 2026-08-06 14:18:10 +00:00
28 lines
876 B
TypeScript
28 lines
876 B
TypeScript
import { copyFileSync, existsSync, mkdirSync, readdirSync, statSync } from 'node:fs';
|
|
import { resolve } from 'node:path';
|
|
|
|
const root = resolve(import.meta.dirname, '..');
|
|
const templatesDir = resolve(root, 'templates');
|
|
const srcDir = resolve(root, 'src');
|
|
|
|
/** Recursively copy template files into `src/`, preserving relative paths. */
|
|
function mirror(dir: string) {
|
|
for (const entry of readdirSync(dir)) {
|
|
const templatePath = resolve(dir, entry);
|
|
const targetPath = resolve(srcDir, templatePath.slice(templatesDir.length + 1));
|
|
|
|
if (statSync(templatePath).isDirectory()) {
|
|
mkdirSync(targetPath, { recursive: true });
|
|
mirror(templatePath);
|
|
continue;
|
|
}
|
|
|
|
if (!existsSync(targetPath)) {
|
|
copyFileSync(templatePath, targetPath);
|
|
console.log(`Created ${targetPath.slice(root.length + 1)}`);
|
|
}
|
|
}
|
|
}
|
|
|
|
mirror(templatesDir);
|