Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@sp-packages/copyrc

SP-Packages194MIT2.3.3TypeScript support: included

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

cli, copy, copyrc, copy-files, copy-templates, files, template

readme

CopyRC

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

npm version npm downloads license build status semantic-release TypeScript Prettier codecov PRs welcome Sponsor

✨ Features

  • 📂 Copies template files to designated locations
  • 🔄 Skips existing files to prevent overwrites
  • ⚡ Works with any project type (WordPress, Node.js, PHP, etc.)
  • 🔧 Fully configurable via copyrc.json
  • 🛠️ Can be integrated into CI/CD, Lando, and other automation workflows
  • 📜 Supports programmatic usage in Node.js projects

📦 Installation

Global Installation (For system-wide use)

npm install -g @sp-packages/copyrc

This allows you to use copyrc globally in your terminal.

Local Installation (For project-specific use)

npm install @sp-packages/copyrc --save-dev

Then, run it via:

npx copyrc

⚙️ Configuration (copyrc.json)

Running the copyrc command will allow you to automatically create the copyrc.json file. Alternatively, you can manually create a copyrc.json or .copyrc.json in your project root or a custom configuration file and pass it using the -c or --config parameter:

{
  "files": [
    { "source": "./templates/.env.template", "destination": "./public/.env" },
    {
      "source": "./templates/wp-config.php.template",
      "destination": "./public/wp-config.php"
    },
    {
      "source": "./templates/.htaccess.template",
      "destination": "./public/.htaccess"
    }
  ]
}

If no --config option is provided, copyrc will look for copyrc.json or .copyrc.json in the project root by default.

🚀 CLI Usage

Basic Usage

copyrc

This will use copyrc.json or .copyrc.json from the project root.

Custom Config File Path

copyrc -c ./custom-config.json

Configuration Options:

  • files[] – Array of file mappings
    • source – Path to the template file
    • destination – Target path where the file should be copied

📜 Programmatic Usage (Inside Node.js)

You can also use copyrc inside your JavaScript/TypeScript projects.

Import and Run Directly

import { copyrc } from '@sp-packages/copyrc';

const config = {
  files: [
    { source: './templates/.env.template', destination: './public/.env' },
    {
      source: './templates/wp-config.php.template',
      destination: './public/wp-config.php'
    }
  ]
};

copyrc(config, true); // The second argument enables verbose logging

Example Use Case in a Node.js Script

Create a script setup.js:

import { copyrc } from '@sp-packages/copyrc';
import fs from 'fs';

const configPath = './copyrc.json';

if (fs.existsSync(configPath)) {
  const config = JSON.parse(fs.readFileSync(configPath, 'utf-8'));
  copyrc(config, false);
} else {
  console.error('❌ Config file not found!');
}

Then run:

node setup.js

🎯 Example Outputs

⚠ [WARNING] Destination file already exists at ./public/.env. Skipping.
✔ [SUCCESS] wp-config.php.template copied successfully to ./public/wp-config.php
✔ [SUCCESS] All required files are copied or already exist.

💡 Use Cases

  • WordPress Setup – Automate wp-config.php and .htaccess
  • Environment Files – Ensure .env files are always present
  • Project Bootstrapping – Copy necessary config files on composer install
  • CI/CD Automation – Automate file setups during deployments

1️⃣ Automating Lando Post-Start Hook

If you're using Lando, you can automatically run copyrc after lando start:

services:
  appserver:
    run_as_root:
      - copyrc

2️⃣ CI/CD Integration

Run it in GitHub Actions, GitLab CI/CD, or other automation scripts:

jobs:
  setup:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Code
        uses: actions/checkout@v3

      - name: Install Dependencies
        run: npm ci

      - name: Install Copyrc
        run: npm install -g @sp-packages/copyrc

      - name: Run Copyrc
        run: copyrc

🤝 Contributing

Contributions are welcome! Please open an issue or submit a pull request on GitHub.

📜 License

This project is licensed under the MIT License. See the LICENSE file for details.

changelog

2.3.3 (2025-05-22)

Bug Fixes

  • update quotes to single quotes for consistency across files (6b1dacb)

2.3.2 (2025-05-22)

Bug Fixes

  • dependencies: update dependencies (6bfd2e1)

2.3.1 (2025-05-22)

Bug Fixes

  • dependabot: change update schedule from daily to weekly (1845063)
  • dependencies: update dependencies (bddc4b6)
  • workflows: update workflow actions to latest versions (a576945)

2.3.0 (2025-04-01)

Features

  • dependencies: update dependencies and configurations (9ab61e0)
  • funding: add custom funding link for PayPal support (faa035b)
  • labeler: enhance labeler configuration for various file types (6696810)
  • workflows: update workflow actions and permissions for consistency (0a66962)

Bug Fixes

  • readme, config: update configuration file name to copyrc.json (c1a11ae)

2.2.0 (2025-03-28)

Features

  • makefile: add Makefile with help, start, dep, and lint targets (6679e04)

2.1.0 (2025-03-16)

Features

  • linting: add lintrc and markdownlint configuration files (4a9b4ef)

Bug Fixes

  • readme: update badge links for improved readability (b9d55ee)

2.0.0 (2025-03-14)

⚠ BREAKING CHANGES

  • copyrc: enhance CLI options and add default config generation

Features

  • codecov: integrate Codecov for improved coverage reporting (479e06a)
  • copyrc: enhance CLI options and add default config generation (959a198)
  • logger: refactor logging to use Printer from @sp-packages/printer (a33d6f7)
  • readme: enhance documentation with badges and programmatic usage (9ab21b9)
  • tests: add Vitest configuration and initial test cases (2727d60)
  • tsconfig: update TypeScript config and enhance build script (df81970)

Bug Fixes

  • workflow: add slug for Codecov in analyze.yml (81483fa)