UNPKG

@sp-packages/copyrc

Version:

A lightweight CLI tool to automate copying template files during project setup or runtime.

2 lines (1 loc) 525 B
"use strict";import t from"fs";import f from"path";import{Printer as i}from"./logger.js";export function copyTemplateFile(e,r){if(!t.existsSync(e))return i.error(`Source file not found at ${e}, skipping.`),!1;const o=f.dirname(r);if(t.existsSync(o)||t.mkdirSync(o,{recursive:!0}),t.existsSync(r))return i.log(`Destination file already exists at ${r}. Skipping.`,"warning"),!0;try{return t.copyFileSync(e,r),i.log(`${e} copied successfully to ${r}`,"success"),!0}catch(c){return i.error(`Failed to copy ${e} to ${r}:`,c),!1}}