Giter Club home page Giter Club logo

ferdi's Introduction

ferdi

ferdi is a flexible component creation helper, it helps you to stay consistent in your component style and reduces the time required to create new components.

You create File Templates and ferdi will create Files you want in a Folder you define.

Installation

You can install ferdi global or local. yarn

yarn global add ferdi

npm

npm install -g ferdi

Usage

$ferdi --help

Usage: ferdi [options]

Path Options
// differs depending on your config
--atomic, -a    ferdi creates Module at src/atoms/
--molecule, -m  ferdi creates Module at src/molecules/

Options:
  // differs depending on your config
  --flat        Create component Files in the Folder itself and not in a component named subfolder
  --template    ferdi should create a Template File
  --css         ferdi should create a Stylesheet File
  --help        output usage information
  --version     output the version number


Commands:
  new <name>    Create new Module
  init          Copy Config File to current Folder
  copy          Copy Example Templates to your Project

If you installed ferdi locally you have to add an npm script to use it or if you use yarn you could use it as yarn ferdi <command>.

To Start with ferdi please use ferdi init in your Project root, this will create a .ferdirc.js config file with some prefilled values.

The config contains 3 different parts fileHeader, files and paths

fileHeader

In the file Header you can add Informations you want to use in your config File, the default Templates are using the Project Authors and Project Name (could be referenced by your package.json). The file- and moduleName are added automatically.

Available Data in Templates

  • Everything you add to the File Header Object, in the default config <%= projectName %> and <%= authors.[name, email] %>
  • <%= file %> the filename you used
  • <%= moduleName %> the component Name
  • <% pathOptions %> Every path Option you have in your config.
  • <%= modulePath %> Path and Filename (without extension)

Defaults – since version 0.0.8

In the .ferdirc.js File you can add an Object like this:

defaults: {
    template: true,
    css: true,
    javascript: true,
    vue: false,
    fractal: false,
  }

Every time you add a new component without any flags these default files are created (template, css and js in this case). The key must be the same as in the files Object. Every key in the files Object must also be in the defaults Object.

Multiple "Components"

If you want to add multiple Components with the same options you can do that by writing ferdi foo bar --option this creates a foo and a bar component

files

This is where the 'magic' happens, ferdi create a new entry for every file type you wish to have a boilerplate for. This is the format ferdi needs:

kind: {
      name: '', // if you define a name ferdi will take this as a base for the filename, if it is empty the last part of the path is taken as filename
      postfix: 'template', // gets added to the filename if you omit the name, leave empty if you don't want that
      extension: 'html', // extension to search for in the template folder and for the final module
      description: 'ferdi should create a Template File', // description for the --help flag
      path: 'js/store/modules' // Added in 0.0.15 | if file has a path option every path option provided by flag will be ignored and the module will be created in the specified folder. 
    },

You can now create new modules with ferdi module/name --css --template --javascript

templates

If you want to create your own templates they have to be named like the key in the files object with -template attached to it.

If you have an object with the key style with the extension .scss your template needs to be named style-template.scss.

paths

Define the path needed for ferdi

paths: {
    templateBase: 'tmpl/', // template folder relative to the .ferdirc file
    modulePath: 'src/', // output path for new modules relative to .ferdirc file
    // you can add multiple subfolders in this object, relative to the modulePath
    // the key is for the option
    pathOptions: {
      // the first character of each key works as an alias for the path so you could use `-a` as an alias for atomic
      atomic: 'atomic/',
      modules: 'modules/',
    },
  }

Flat Option

If you add the --flat flag to your command the component files will get created in the specified folder instead of in a folder named after the component

Examples

paths: {
    templateBase: 'tmpl/',
    modulePath: 'src/',
    pathOptions: {
      // the first character of each key works as an alias for the path so you could use `-a` as an alias for atomic
      atomic: 'atomic/',
      modules: 'modules/',
    },
  },

When you type ferdi forms/input -a your new component gets created in /project/folder/src/atomic/forms/input with filenames like this input-template.html, _input-style.scss or input-script.js

ferdi's People

Contributors

dependabot[bot] avatar gisu avatar martinherweg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

gisu dannystarkde

ferdi's Issues

Add correct prefix in SASS/HTML template files according to the flag/type

// Modul
.m-<%= moduleName.replace('-', '_') %>  {
}

The m should be the flag/type of the created module. If i create a atom with -a flag, then it should be named .a-Name etc. The same for the html templates. There should be the flag/type variable available.

Quick-Fix:
<%= pathOptions.key.charAt(0) %>-<%= moduleName.replace('-', '_') %>

Register Flags to use Variants

const pkg = require('./package');

module.exports = {
  defaults: {
    config: false,
    scss: true,
    twig: true,
    basicJs: true,
    basicScss: true,
    basicTwig: true,
    basicVue: true,
  },
  fileHeader: {
    author: pkg.author,
    projectName: pkg.name,
  },
  files: {
    twig: {
      name: '_template',
      postfix: '',
      extension: 'twig',
    },
    basicTwig: {
      name: 'variant-basic/_template',
      postfix: '',
      extension: 'twig',
    },
    scss: {
      name: '_style',
      postfix: '',
      extension: 'scss',
    },
    basicScss: {
      name: 'variant-basic/_style',
      postfix: '',
      extension: 'scss',
    },
    basicJs: {
      name: 'variant-basic/_script',
      postfix: '',
      extension: 'js',
    },
    basicVue: {
      name: 'variant-basic/_component',
      postfix: '',
      extension: 'vue',
    },
    config: {
      name: 'config',
      postfix: '',
      extension: 'php',
    },
  },
  paths: {
    templateBase: 'src/ferdi/',
    modulePath: 'src/templates/',
    pathOptions: {
      // the first character of each key works as an alias for the path so you could use `-a` as an alias for atomic
      atoms: '_atoms/',
      molecules: '_molecules/',
      organisms: '_organisms/',
    },
  },
};

das variant-basic müsste dann zu varian-${variant} werden. Ferdi sollte dann so aussehen:

ferdi image -a
erstellt laut config:

atoms/image/variant-basic/_component.vue
atoms/image/variant-basic/_script.js
atoms/image/variant-basic/_style.scss
atoms/image/variant-basic/_template.twig
atoms/image/_style.scss
atoms/image/_template.twig

ferdi image -a --variant=foo sollte dann das hier erstellen:

atoms/image/variant-foo/_component.vue
atoms/image/variant-foo/_script.js
atoms/image/variant-foo/_style.scss
atoms/image/variant-foo/_template.twig

Template Variations

Allow Template variations maybe as addition to the flag with --variationName.

Add "flat" option

Add an option that creates a new component in the specified component folder itself and not in an folder named like the component.

Not working 0.0.6 — 0.0.8

Reinstalled global
Reinstalled within the project

When I do ferdi foo -m nothing happens
image

And Global when I do ferdi --help

# dh at davidhellmann.local in ~ [23:26:50]
→ ferdi --help
assert.js:43
  throw new errors.AssertionError({
  ^

AssertionError [ERR_ASSERTION]: missing path
    at Module.require (module.js:515:3)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/Users/dh/.nvm/versions/node/v8.4.0/lib/node_modules/ferdi/src/createModule.js:22:13)
    at Module._compile (module.js:573:30)
    at Object.Module._extensions..js (module.js:584:10)
    at Module.load (module.js:507:32)
    at tryModuleLoad (module.js:470:12)
    at Function.Module._load (module.js:462:3)
    at Module.require (module.js:517:17)
    at require (internal/module.js:11:18)

ferdi init doesn't work

Installed the script locally in the project.

→ ferdi init
zsh: command not found: ferdi

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.