UNPKG

hasnav

Version:

A package to copy a folder to a user-specified location

21 lines (16 loc) 816 B
const fs = require('fs'); const path = require('path'); const ncp = require('ncp').ncp; // Get the folder path inside your package (the folder to be copied) const sourceFolder = path.join(__dirname, 'folder-to-copy'); // Ask the user to specify the target folder (e.g., a folder named `app-folder`) const destinationFolder = path.join(process.cwd(), 'app-folder'); // or use a custom path from environment variable // Ensure the destination folder exists, or create it fs.mkdirSync(destinationFolder, { recursive: true }); // Post-install: copy the folder to the specified destination ncp(sourceFolder, destinationFolder, function (err) { if (err) { return console.error('Error while copying folder:', err); } console.log(`Folder successfully copied from ${sourceFolder} to ${destinationFolder}`); });