Git Product home page Git Product logo

assemble's Introduction

@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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.