Giter VIP home page Giter VIP logo

creditor's Introduction

Creditor

Minimize writing boilerplate - focus on business logic!

Creditor is used for maintaining and scaffolding boiler plate template code within a repository. Once templates are defined, Creditor makes it easy create, rename, move, analyze, and use items associated with these templates.

Usage

  npm install --save-dev @acolby/creditor

Defining templates

Creditor expects there to be a ./creditor directory in the given project. This directory is where Creditor is configured and where templates are defined.

./creditor structure

The "/creditor" directory needs to be structured as follows

  /_ package.json
  /_ creditor
    /_ templates
      /_ [TEMPLATE_TYPE]
        /_ ... // location where template files are defined
    /_ aggregators
      /_ [TEMPLATE_TYPE]
        /_ ... // location where aggregators are defined
    /_ config.js

Once a [TEMPLATED_TYPE] is defined you may create this template in your repository by using the creditor cli. It is recommended that you add a line to your package.json file in order to do so.

Add to package.json:

  scripts: {
    ...
    "creditor": 'creditor inquire --verbose',
  }

Once added, defined templates can be managed by calling:

  $: npm run creditor

The cli will then prompt for the information needed to scaffold a given template.

templates are outputted to whatever output directory defined in config.js.

Defining Templates

Templates are simply files. They are generic items that contain keywords known to creditor (Creditor Keywords). The template name is the name of the folder they are defined in.

template example

A file corresponding to ./creditor/templates/comps/index.js could look like

// ./creditor/templates/comps/index.js
import { React } from "react";

function CREDITOR_UNDERSCORE_NAME(props) {
  return <h1>Hello, i am CREDITOR_PERIOD_NAME</h1>;
}

export default CREDITOR_UNDERSCORE_NAME;

Now, running creditor will allow you to create a 'comps' item, where the location of the item will determine what gets swapped out with the Creditor Keyword (CREDITOR_UNDERSCORE_NAME).

It is import to understand that a creditor template directory is allowed to contain multiple files. All of the tiles will be created in the output directory when running creditor. This allows you to scaffold any sort of File Pattern you wish.

For example you may scaffold a 'comps' with the interface file (index.js) a test file and a scss file

  /_ creditor
    /_ templates
      /_ comps
        /_ index.js
        /_ styles.scss
        /_ test.js

Creditor Keywords

The following keywords within your template files will be swapped out with the created template.

  • CREDITORUNDERSCORE_NAME -> name of component delineated by ''
  • CREDITOR_PERIOD_NAME -> name of component delineated by '.'
  • CREDITOR_DASH_NAME -> name of component delineated by '-'
  • CREDITOR_SLASH_NAME -> name of component delineated by '/'

Defining Aggregators

It is often desired to take files within a given directory and aggregate them within a top level file of that directory. Examples of this are:

  • Creating an interface file
  • Combining sub files to create a store
  • Merging files for documentation purposes

Creditor provides a mechanism for defining how items within a directory should be merged programmatically. This allows developers to focus on developing the items rather then updating the proper boilerplate aggregator files.

Similarly to templates, aggregators are defined within the creditor directory

For example you may scaffold a 'comps' with the interface file (index.js) a test file and a scss file

  /_ creditor
    /_ aggregators
      /_ routes
        /_ index.js

When creditor runs and if the comps directory is changed in any way. A corresponding /index.js file will be created at the top of the comps directory. The index.js file defined in /creditor/aggregators/comps is the definition file for how to aggregate the sub-files.

module.exports = ({ paths = [] }) => {
  const filtered = paths
    .filter((item) => item.split(path.sep).length > 1)
    .sort();

  const _exports = filtered.map((item) => {
    return `export { ${item.split("/").join("_")} } from '#src/${item}';`;
  });

  return ["", ..._exports, ""].join("\n");
};

The above example takes the directory and exports all items from a top level index file. This is to create an interface file for consumers.

export { comps_login } from "#src/comps/login";
export { comps_profile } from "#src/comps/profile";
export { comps_settings } from "#src/comps/settings";

Aggregators will run anytime the path structure of the given directory changes

Future Features

  • Publishable Templates
  • Graph analysis
  • Consumption graph
  • Linting based off of templates

creditor's People

Contributors

acolby avatar joshshearer avatar

Stargazers

 avatar Nedim Filipovic avatar  avatar John Spindler avatar

Watchers

 avatar  avatar

Forkers

joshshearer

creditor's Issues

Add Delete Item functionality

For the most part, it is okay to manually delete an item from the FS; however; if there is an aggregator, it is often required to re-run the aggregator for the template you wish to delete.

A built-in, recursive, delete action would be super helpful. It would have the following properties:

1.) delete all files recursive to the src
2.) protect against deleting folders that are used elsewhere in the project
3.) re-aggregate the pattern

Move Function Results in Collision

/home/joshshearer/Documents/Dev/ShroomSpyWebSite/node_modules/@acolby/creditor/src/index.js:145
throw new Error(creating ${filePath} results in a collision);
^

Error: creating Comps/layout/sections/news/test.js results in a collision
at /home/joshshearer/Documents/Dev/ShroomSpyWebSite/node_modules/@acolby/creditor/src/index.js:145:15
at Array.forEach ()
at Object.move (/home/joshshearer/Documents/Dev/ShroomSpyWebSite/node_modules/@acolby/creditor/src/index.js:142:39)
at async Command. (/home/joshshearer/Documents/Dev/ShroomSpyWebSite/node_modules/@acolby/creditor/cli.js:44:9)

Repeat Issues

  • Leave does not work with repeat
  • Multiple Removes do not work with repeat (I believe the issue has to do with needing to re-aggregate)

Hold Prompt until escape key given

Many times it is desired to perform several sequential operations. An example of this would be at a new project/subproject creation.
Running the start command each time becomes tedious.

Move Functionality

It seems action_move will move a file without its associated directory. the naming conventions in the creditor structure seem as though the directory should travel with the index.js file assuming is has one and is at the end of the directory branch.

When I move this index file....

/_src
   /_selectors
      /_my
         /_target
            /_item
               index.js
            /_item2
               index.js   <-----move from

I would expect the changes to reflect as shown here...

/_src
   /_selectors
      /_my <----Move to Dir
         /_item2
            index.js
         /_target
            /_item
               index.js
           

In reality creditor is doing the following...

/_src
   /_selectors
      /_my
         index.js  <--- Ends up here
         /_target
            /_item
               index.js
            /_item2 <--- Dir left in path

Move does not work if source is not in 'usage'

When running creditor 'creditor move selectors my/target other/place' creditor says 'my/target is not an existing directory'.

/_src
   /_selectors
      /_my
         /_target
            /_item
               index.js
            /_item2
               index.js

I'd expect Creditor to still move my/target as there are still items in my/target.

It seems that creditor will only move a directory if the source contains a file for example:

/_src
   /_selectors
      /_my
         /_target
            index.js           <------- works if this is here
            /_item
               index.js
            /_item2
               index.js

We need to make creditor okay with moving an item if it is empty but has sub items.

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.