Coder Social home page Coder Social logo

matt-daniel-brown / feathers-generator Goto Github PK

View Code? Open in Web Editor NEW

This project forked from feathersjs-ecosystem/feathers-generator

0.0 1.0 0.0 205 KB

A metalsmith based generator for scaffolding Feathers apps.

License: MIT License

JavaScript 84.82% HTML 15.18%

feathers-generator's Introduction

feathers-generator

Build Status Code Climate Test Coverage Dependency Status Download Status Slack Status

A metalsmith based generator for scaffolding Feathers apps. Used by feathers-cli.

Generators

The available generators are:

  • apps
  • hooks
  • services
  • filters
  • models
  • middlewares
  • plugins

File Structure

Each generator has:

  • a main <type>.generator.js file which has all the logic for the given generator.
  • a templates/ directory that contains all the static and dynamic templates the generator uses.
  • a meta.json file.

API

Each main generator file must implement these methods:

  • loadAppConfigs - This loads any existing Feathers application config files that reside in feathers-app/config/ so that they can be referenced and re-written with new values if necessary.
  • loadPackageJSON - This loads the existing Feathers application package.json file so it can be referenced and re-written with new values if necessary.
  • getQuestions - This returns the questions from the meta.json file
  • generate - This takes in the answers from the user and generates/copies the appropriate files based on their answers.

meta.json

This file contains the meta data that each generator uses to tell the CLI which questions it needs the user to answer and when.

prompts

The CLI uses inquirer to ask the user questions and gather information. The prompts section in the meta.json file tells the CLI which questions to ask and when.

They are almost exactly the same as when defining prompts with vanilla inquirer. The only difference is that for every Inquirer question key that supports a function, we've already wrapped your value in function for you so that we can expose additional properties. Therefore your default, when, filter, and validate values can reference:

  • answers - The ongoing answers to the questionnaire in the current Inquirer session.
  • options - The existing options prior to prompting
  • pkg - Any package.json fields for the existing Feathers app
  • config.default - Any config/default.json fields for the existing app
  • config.staging - Any config/staging.json fields for the existing app
  • config.production - Any config/production.json fields for the existing app

See this meta.json for an example.

Generating Stuff

Generating an app or component goes something like this:

const inquirer = require('inquirer');
const Generator = require('feathers-generator');

const args = {
  template: 'app', // one of the templates
  name: 'my-app', // the name of your generated thing
  root: '/path/to/project/root', // the root directory of your project
  force: false, // whether it should override any existing values or files without confirmation
};

// Get the appropriate generator based on the `template` you supplied
// By this point the generator has already read in existing app configs
// and the package.json file.
const generator = Generator(args);

generator.getQuestions()
  .then(questions => {
    // Get user to answer questions
    return inquirer.prompt(questions);
  })
  .then(answers => {
    // Send answers back to generator
    return generator.generate(answers);
  })
  .then(dependencies => {
    // npm install dependencies
    // { devDependencies: [], dependencies: [] }
  })
  .catch(error => {
    if (error) {
      console.log(error));
    }
  });

feathers-generator's People

Contributors

kc-dot-io avatar corymsmith avatar ekryski avatar chasenlehara avatar bertho-zero avatar

Watchers

James Cloos avatar

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.