Coder Social home page Coder Social logo

feathers-generator's Introduction

feathers-generator

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

Unmaintained

This module was experimental and is no longer under active development. Use the Feathers CLI at @feathersjs/cli to generate a new Feathers application and generator-feathers as a template to modify the generated application.

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

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

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

feathers-generator's Issues

model configuration

overview

Currently a model service.json will assume that options such as path will be defined in the global configuration. That said, we need to have a way to check this and define it if it isn't upon generating a service.

tasks

TBD

redis adapter

overview

implement a redis adapter

tasks

  • add model choice
  • add model choice dependencies
  • add model templates
  • test that it works

mysql adapter

overview

implement a mysql adapter using knex template

tasks

  • add model choice
  • add model choice dependencies
  • add model templates
  • test that it works

mongoose >= 4.11.0 logs a deprecation warning for generated service

feathers generate service
Choose mongoose
Choose /messages
node ./src
and the console logs

(node:4447) DeprecationWarning: `open()` is deprecated in mongoose >= 4.11.0, use `openUri()` instead, or set the `useMongoClient` option if using `connect()` or `createConnection()`. See http://mongoosejs.com/docs/connections.html#use-mongo-client

errors inside generators are surpressed

As I was creating a generator for services I noticed generators are suppressing errors so there are no stack trace.

For example: an undefined variables inside the scope of the generator function is suppressed and provides no stack trace but causes the program to halt.

It's not the end of the world but it's probably worth fixing so we at least get a stack trace for debugging purposes so we don't waste time on typos etc.

I'll try to track down the reason for this as I go and suggest a solution.

service updating

overview

A generated service should be able to be updated. For example, I might generate a service with a memory model to prototype, but when I'm ready to go to production I may change to mongo. I should be able to update the service.json with minimal regression via cli.

tasks

TBD

move all console.logs to debug

overview

console.log sucks, all of the default logs should be moved to debug and flagged on by default with DEBUG=${app}:* so that when a user first runs npm start in development, they get pretty outputs that are separated from the machine readable logs of bunyan and the boring logs of console.

service model migrations

Do you have any particular thoughts on how model updates and migrations would fit into this? Currently when I make a feathers app I manually delete all the model.sync() calls after generating a model and then create a sequelize migration manually. There's not currently a way to programmatically add new fields to a model and create the appropriate migration, so things can sometimes get out of sync. 😞

handlebars

We don't need to do a lot of templating and templates/string injection should definitely NOT be used for code. We learned that lesson the first time with the old generator.

Common situations where we need templates to inject things dynamically:

  • comments (file names)
  • function names (possibly). For example hook/filter names so that they aren't anonymous functions. This makes debugging easier.
  • readme files

Any JSON file should never use templating and instead should be read in, modified, and written back out.

Generators

  • App
  • Services
  • Models
  • Middleware
  • Hooks
  • Filters

generate client

overview

It would be cool to generate a client boiler plate for both react and vue.

tasks

  • add question / options to meta.json
  • update package.json with build cmd
  • add templates to be put in ./public
  • test that it works

sequelize adapter

overview

implement a sequelize adapter

tasks

  • add model choice
  • add model choice dependencies
  • add model templates
  • test that it works

Update default Feathers Secret to be 2048 bit

@marshallswain pointed out to me in Slack that our current auto-generated keys are too small. They are only about 300-400 bits. HS256 algorithm for JWTs should have a secret of at least 1024 bits if not 2056 or more so that they can't be easily brute forced.

We should use crypto.randomBytes(2048).toString('hex') for secret creation.

knex adapter

overview

implement a knex adapter

tasks

  • add model choice
  • add model choice dependencies
  • add model templates
  • test that it works

mongodb adapter

overview

implement a mongodb adapter

tasks

  • add model choice
  • add model choice dependencies
  • add model templates
  • test that it works

Generate Services

Should generate a service.json file with the appropriate default hooks and config values based on the current application configuration state.

It should also register the service with the main application or set it up as a stand alone app if that option was specified.

better file conflicts

If a force option isn't passed and there is a file conflict we need to:

  • tell the user that we have a conflict
  • tell them which file is conflicting
  • prompt for confirmation of overwrite
  • write or ignore based on their answer

fix plugin standalone

overview

standalone plugin mode isn't working properly right now (path is false).

tasks

  • make sure that the defaults still work
  • double check all the standalones
  • make sure overlaying repo generation is ok on all

fix docker env

overview

with switching to babel, we need to make sure docker starts the lib directory both during tests and when running. we might also need to add a step where js is compiled prior to starting.

github issue templates

overview

we should add default / customizable github issue templates to app and repo templates

Generator V3

overview

This epic includes all of the work needed to get to a stable v2 of the generator and cli.

goals

  • fix service generation defaults introduced in #10
  • service models should be configurable via prompts and templates
  • implement feathers-nedb
  • implement feathers-memory
  • implement feathers-mongoose
  • implement feathers-rethinkdb
  • use service.json
  • use feathers.json
  • support database initiation
  • support handlebars
  • implement hooks generator
  • implement filters generator
  • implement middleware generator
  • implement plugin generator
  • implement repo generator
  • implement semi-standard
  • implement auto testing when generating
  • implement docker support
  • implement feathers-knex
  • implement feathers-sequelize
  • implement feathers-mongodb
  • configure logging
  • implement feathers-elasticsearch
  • better test coverage
  • readme + documentation

technical debt

  • update app templates for eslint + semistandard
  • model configuration based on model meta.json
  • refactor some of the duplicate service middleware into base utils
  • fix up todos added in #10

configure auth

overview

we need to be able to configure authentication when generating an app

es6 generations

overview

Right now it seems like all generations are converted to ES5, which is cool but it would be nice if the generations could be set to ES6 so we don't end up with a bunch of verbose ES5 polyfill when ES6 is supported.

answer prompts via args

overview

It would be great if we could answer each of the prompt questions using a --key value setup in the cli commands. This will allow us to generate things on the fly so that we do not need to answer every single question, which is useful for things like tests that need to test generated work.

tasks

  • come up with naming schema
  • implement some way in feathers-cli to pass through all xargs
  • map xargs to inquirer prompts
  • populate answers using a middleware in generator chain
  • make sure things get generated and still work
  • unblock #16

linting of generated templates

overview

The current generated templates do not pass linting. Not sure if we can make them pass all of the syntax checking in parallel if syntax checking supports different rules. Might be worth just moving everything to semistandard by default.

@feathersjs/core-team thoughts?

ref #18

remove babel

overview

there is still some legacy babel es5 stuff left around that should be removed since we don't really care about supporting es5 anymore

Action required: Greenkeeper could not be activated 🚨

🚨 You need to enable Continuous Integration on all branches of this repository. 🚨

To enable Greenkeeper, you need to make sure that a commit status is reported on all branches. This is required by Greenkeeper because it uses your CI build statuses to figure out when to notify you about breaking changes.

Since we didn’t receive a CI status on the greenkeeper/initial branch, it’s possible that you don’t have CI set up yet. We recommend using Travis CI, but Greenkeeper will work with every other CI service as well.

If you have already set up a CI for this repository, you might need to check how it’s configured. Make sure it is set to run on all new branches. If you don’t want it to run on absolutely every branch, you can whitelist branches starting with greenkeeper/.

Once you have installed and configured CI on this repository correctly, you’ll need to re-trigger Greenkeeper’s initial pull request. To do this, please delete the greenkeeper/initial branch in this repository, and then remove and re-add this repository to the Greenkeeper integration’s white list on Github. You'll find this list on your repo or organization’s settings page, under Installed GitHub Apps.

tests

overview

We should add tests that run a generated app, perhaps from the example dir. The generated app should be configured with services, hooks etc so that the tests are testing it. If we take this approach we need some way of making sure we don't get false positives by testing against out dated generations. The test runner should generate on the fly, but this is blocked unless we have an inline way to answer the inquirer prompts.

tasks

  • unblock generator through cli flags
  • setup a .sh file that generates a full app
  • setup a npm test cmd that runs test of generated app

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.