1.0.4 • Published 6 years ago

jen-cli v1.0.4

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

jen-cli

CLI tool to easily generate directories and folders

Installation

npm install jen-cli -g

or

yarn global add jen-cli

Configuration

You have to create a jenfile.js in the root of your project and export a configuration object from it.

Supported API:

  • sourceDir - The folder where your app is located.
  • commands - Array of commands you want to expose
    • command - The actual command used from the CLI to trigger this template usage
    • description - Optional parameter to describe the current command
    • directoryName - The name of the directory under which to generate the tree
    • tree - Array of nodes to be created.

The tree array can be a list of string's, object's or a combination of both. If it's a list of string's then they will be treated as folders and empty folders will be generated as no children are specified. If on the other hand there is an extension (ie. [name].js) then the corresponding file will be created.

Example

// When running
jen-cli --component CheckBox

// With tree config
tree: ['[name]', '[name]-test', '[name].js'];

// Will generate all at the same level
'CheckBox' <- Folder
'CheckBox-test' <- Folder
'CheckBox.js' <- .js File

Note the usage of the placeholder [name]. Currently this is the only placeholder. When you run jen-cli --component Modal, [name] will be replaced with Modal.

When setting up the tree nodes in the config file, you can set them as object's with only one argument: name. If you do so the behavior will be identical to the one explained above.

// When running
jen-cli --component CheckBox

// With tree config
tree: [{ name: '[name]' }, { name: '[name]-test' }, { name: '[name].js' }]

// The output is identical to the one for
tree: ['[name]', '[name]-test', '[name].js'];

However, if a node has the body argument and has an extension in the name, a file with that name will be generated and the body content will be used to create the file. body is an array where each element represents one line. After the end of each line a new line (\n) will be appended. If you want to have an empty line, just add an empty string to the array. The same logic for the placeholders applies here, [name] will be replaced with the argument/arguments passed.

The las and the most important argument is children as it allows to nest all the functionality explained above.

// When running
jen-cli --component Button

// With tree config
module.exports = {
  sourceDir: 'src',
  commands: [
    {
      command: '--component',
      description: 'Create component with test',
      directoryName: 'components',
      tree: [
        {
          name: '[name]',
          children: [
            { name: 'assets' },
            {
              name: 'styles',
              children: ['[name].sass']
            },
            {
              name: '[name].js',
              body: [
                "import React from 'react';",
                '',
                "import './styles/[name].sass'",
                '',
                'const [name] = () => <div>Empty component</div>;',
                '',
                'export default [name]',
              ],
            },
            {
              name: '[name].test.js',
              body: [
                "import React from 'react';",
                "import renderer from 'react-test-renderer';",
                '',
                "import [name] from './[name]';",
                '',
                "describe('<[name]>', () => {",
                "  it('should render correctly', () => {",
                "    const wrapper = renderer.create(<[name] />).toJSON()",
                "    expect(wrapper).toMatchSnapshot();",
                '  });'
                '});',
              ],
            },
          ],
        },
      ],
    },
  ],
};

// Will generate
'Button' <- Folder
|- 'assets' <- Folder
|- 'styles' <- Folder
|- |- 'Button.sass' <- .sass File with empty body as nothing was specified
|- 'Button.js' <- .js File with the specified body
|- 'Button.test.js' <- .js File with the specified body

TODO

  • Publish as npm package
  • Add version command
  • Add help command
  • Parse arguments with yarg
  • Add template load from file
  • Add default jenfile on first install
  • Refactor the code
  • Rewrite in TypeScript
  • Write tests
1.0.4

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago