npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

copypaster

v1.1.0

Published

Has your project structure gotten so complex that to add a new feature you need to copy, paste and rename tens or hundreds of files each time? And now you're thinking of writing a code generator to help you with that repetitive manual work?

Downloads

3

Readme

Copypaster

Has your project structure gotten so complex that to add a new feature you need to copy, paste and rename tens or hundreds of files each time? And now you're thinking of writing a code generator to help you with that repetitive manual work?

This tool is a simple helper you might use instead, and it works this way:

  1. You identify all files and folders you want to use as template (let's say you have a module/user/user-settings folder)
  2. You tell the tool to replace all user occurences in the template with, let's say, dog
  3. The tool then copies the template files you specified, while replacing user with dog in all file names and their contents, preserving naming conventions (camelCase, pascalCase, snake_case, etc.)

How to use

  1. Install this tool globally npm install -g copypaster
  2. Run copypaster in your project's root directory, which will ask you to create a copypaster.config.json templates file
  3. Define which files or folders you want to use as templates in config file
  4. Run copypaster again and follow on-screen instructions to actually generate a code from template

How does config file work

You can see the example copypaster.config.json in example directory, but basically it's gonna look something like this: there's an arbitrary template name that you can set, followed by an object containing template logic:

  • replacementKey - string that will get replaced with whatever you tell the tool with. Must be in snake_case or kebab-case.
  • folders - array containing folders you want to copy
  • files - array containing files you want to copy
  • snippets - array of individual snippets you want to copy (new line gets inserted right after the specified one)
  • description - decorative text explaining what the template does, not used in generated code

The config file can be kept either in your working folder or in your home directory.

Example of a config file:

{
    "someBatchOfFilesYouWantToUseAsTemplate": {
        "replacementKey": "space_station",
        "description": "Template made from Space Station app module.",
        "folders": [
            "space-station/",
            "space-station/space-station-parts"
        ],
        "files": [
            "space-station/space-station.api.js",
            "space-station/SpaceStation.js",
            "space-station/space-station-parts/space-station-parts.service.js"
        ],
        "snippets": [
            {
                "file": "example.routes.js",
                "content": "\t\"space-station/space-station.api\","
            }
        ]
    },
    "someOtherModule": {
        "replacementKey": "station",
        "description": "Another template",
        "folders": [
            "space-station/"
        ],
        "files": [
            "space-station/space-station.api.js"
        ]
    }
}

Code structure

There's cli.ts as the entry point which handles user input, which then offloads the actual codegen part to generator.ts. All other files are helper stuff to do string or file manipulations.

Tool is currently not using any external dependencies. Typescript is used when developing locally, but built files get exported and ran as vanilla Javascript with zero dependencies.