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

@jdpnielsen/assemble

v1.1.0

Published

CLI to generate files based on templates

Downloads

696

Readme

@jdpnielsen/assemble

npm package Build Status Downloads Issues Commitizen Friendly Semantic Release

Command-line tool to generate files based on templates

Install

npm install @jdpnielsen/assemble

Blueprints

Blueprints are the core of Assemble. They are the templates that Assemble uses to generate files. A blueprint is a directory that contains a index.ts file and any .eta templates that are needed.

The index.ts file is where the blueprint is defined. Its executes a runner function that is passed a AssembleContext object.

// ./blueprints/component/index.ts
import { prompt, changeCase, AssembleContext, runner, assembleTemplate } from '@jdpnielsen/assemble';

runner(async (context: AssembleContext) => {
  // Enquirer is bundled with Assemble and can be used to prompt the user for input
  const { name } = await prompt([
    {
      type: 'text',
      name: 'name',
      message: 'What is the name of the component?',
      required: true,
    },
  ]);

  const name = changeCase(answers.name);

  await assembleTemplate({
    // Assemble uses eta for templating
    input: path.join(__dirname, './blueprint.tsx.eta'),
    output: path.join(context.cwd, `./src/components/${name.kebabCase}/${name.kebabCase}.tsx`),
    templateVariables: {
      componentName: name.pascalCase,
    },
    context,
  });
}).catch((error) => {
  console.error(error);
  process.exit(1);
})

See example folder for examples.

To make a blueprint available to Assemble, you need to add it to the config file.

// assemble.config.ts
import { defineConfig } from '@jdpnielsen/assemble';

export default defineConfig({
  blueprints: [
    {
      name: 'component',
      recipe: './blueprints/component/index.ts',
    },
  ],
});

Once a blueprint is added to the config file, it can be used by Assemble.

$ npx assemble --blueprint component

Motivation

Assemble was created to make it easier to generate files based on templates. The core idea is that you can create a blueprint that defines how a file should be generated using bundled helpers from the Assemble library. Assemble bundles Enquirer, Eta and ts-morph to make it easier to create blueprints.

Assemble cli then makes it easy to generate files using the Assemble command-line tool.