codebot

0.0.12 • Public • Published

{--} CodebotJS

NPM Version Build Status Downloads Dependency Status License

This project is under development

Codebot is the easy way to make applications from templates.

The idea is that you need to write the code one time, then use a model.

Think an application, write it as templates and then use to make multiple apps changin the model, if you improve something, change the templates and every app will take the benefit.

Install

npm i --save-dev codebot

Templates

Codebot use ejs as default template engine

If the src is not defined on /path/from/module/codebot.json, the templates will be searched on the /path/from/module/src/ folder

Directives to filenames and folders

directive usage description
# #layername layer/folder names
@ @filename automatic file
! !filename injector file (not supported yet)
${} ${target} dynamics names
$this ${$this} current dynamic name from parent

Modifiers

character usage description
l $l{target} write the target as lowerCase*
u $u{target} write the target as upperCase*
c $c{target} write the target as camelCase*
s $s{target} write the target as snakeCase*
k $k{target} write the target as kebabCase*
p $p{target} write the target as capitalize*

*please see the lodash documentation

Configuration file

// codebot.json
{
  "src": "the_source/",
  "ignore": [ "some_file/expression" ]
}

NOTE: you can set the config into the package.json like

{
  "name": "my-awesome-template",
  ....
  "codebot": {
    "src": "the_source/"
  }
  ....
}

Usage

import codebot from 'codebot';
 
let model = {
  foo: 'bar'
};
 
let ops = {
  modules: [
    '/path/from/templates/module1',
    'path/from/templates/module2'
  ],
  output: '/path/to/',
  model: model
};
 
codebot(ops)
  .then(results => {
    // all tamplates are processed
 
    // show the trees
    results.modules.forEach( m => {
      console.log(m.toString(true, 'source-tree'));
    });
    console.log('');
    results.modules.forEach( m => {
      console.log(m.toString(true, 'output-tree'));
    });
  })
  .catch(err => {
    console.log(err);
  });

The inject file example (not supported yet)

the transpiler match a full line with the codebot:inject thing

  // !some.js
  // inject:codebot
  console.log($this.name);
  // endinject
  // !some.html
  <!-- inject:codebot -->
  <h1><%= $this.title %></h1>
  <!-- endinject -->

Usage with gulp

npm i --save-dev gulp-codebot
var codebot = require('gulp-codebot');
 
var modules = [
  '/path/from/templates/module1',
  '/path/from/templates/module2'
];
 
gulp.src('./model.json')
    .pipe(codebot({ modules: modules }))
    .pipe(gulp.dest('./src'));

Example

//model.json
{
  layer: {
    'app': './client/app',
    'routes': './server/routes'
  },
  target: {
    'actor': { 
      plurals: 'actors',
      view: {
        'add': {/*view stuff*/}
      }
    },
    'director': { 
      plurals: 'directors',
      view: {
        'add': {/*view stuff*/}
      }
    },
    'movie': { 
      plurals: 'movies',
      view: {
        'add': {/*view stuff*/},
        'edit': {/*view stuff*/},
        'search': {/*view stuff*/},
      }
    }
  }
}

Templates example

// /path/from/angular/src/
- #app
  - ${target}
    - @${$current}.controller.js
    - @${$current.view}.html
    - !config.js
  - @app.config.js
  - app.js
// /path/from/api/src/
- #routes
  - @${target.plurals}.js

The output

./client/app/actor/actor.controller.js       // writed every time
./client/app/actor/config.js                 // writed/injected every time
./client/app/actor/add.html                  // writed every time
 
./client/app/director/director.controller.js // writed every time
./client/app/director/config.js              // writed if the output is not exists
./client/app/director/add.html               // writed every time
 
./client/app/movie/movie.controller.js       // writed every time
./client/app/movie/config.js                 // writed if the output is not exists
./client/app/movie/add.html                  // writed every time
./client/app/movie/edit.html                 // writed every time
./client/app/movie/search.html               // writed every time
 
./client/app/app.config.js                   // writed every time
./client/app/app.js                          // writed if the output is not exists
 
./server/routes/actors.js                    // writed every time
./server/routes/directors.js                 // writed every time
./server/routes/movies.js                    // writed every time

License

MIT © Delmo

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.0.12
    2
    • latest

Version History

Package Sidebar

Install

npm i codebot

Weekly Downloads

2

Version

0.0.12

License

MIT

Last publish

Collaborators

  • delmosaurio