burj
v1.3.0
Published
Customizable project structure generator. 🏗👷
Downloads
4
Maintainers
Readme
🏗 Burj - Structure generator
Burj is a command line tool built to help developers create and maintain a clean project structure and speed up the process of creating components, routes, services, etc. By giving access to custom file templates it can be used in a variety of projects, no matter if they're back-end or front-end ones. It's meant to be easy and quick to use, as well as to provide a highly flexible project structure.
Table of contents
Installation
Prerequisites: Node.js 8.x or newer.
You can install the module from npm either globally
# Using npm
$ npm install -g burj
# Using yarn
$ yarn globals add burj
or locally
# Using npm
$ npm install --save-dev burj
# Using yarn
$ yarn add -D burj
Keep in mind that you have to use
$ ./node_modules/.bin/burj ...
instead of
$ burj ...
if you installed the package locally.
Usage
If you don't want to define your own project structure, you can use default file templates that will follow this hierarchy. You can create new structure elements by running commands in your command line, like below:
# burj [type] [name] [...params]
# or burj --new [type] [name] [...params]
# or burj -n [type] [name] [...params]
$ burj component AwesomeFooter
$ burj reducer user
$ burj action savePhoto
$ burj view LoginPage class redux
$ burj route books
type
- defines which structure element will be created.name
- name of the file(s) to be created.params
- all other params that you want to pass to the template.
Configuration
To define a custom structure:
- Create a
.burjrc
,.burjrc.json
or.burjrc.js
file in the root directory of your project. - Create a directory for template files and code them.
.burjrc
file
// ./.burjrc
{
"baseDir": "./src", // Path to new structure elements
"templatesDir": "./templates", // Path to templates
"structure": {
// Name of structure elements
"components": {
"wrapElements": true, // Should create files inside of a new directory
"elements": [
{
"extension": ".jsx",
"template": "./component" // Path to template
},
{
"extension": ".test.js",
"template": "./test",
"path": "../../../test/components/" // Override default creation path
},
{
"filename": "index.js", // Override file name
"template": "./index"
},
{
// components/index.js for exporting all components
"filename": "index.js",
"template": "./export",
"append": true, // Append to file instead of writing
"path": "../",
}
]
},
"weirdOnes": {
"elementType": "weird", // Use if plural name is not singular + 's'
"elements": [
{ "extension": ".asd", "template": "./weird" }
]
}
}
}
Template files
Template file should be created as a JavaScript module that exports a function. Below you can see an example template file that will create a simple express.js router.
// ./templates/route.js
module.exports = ({ name, type, params } = {}) => `const express = require('express');
const router = express.Router();
router.use('/', (req, res) => res.send('This is an awesome ${name} route!'));
module.exports = router;
`;
Keep in mind that you can make use of type
, name
and params
arguments described in usage section. It might be useful, e.g. for creating stateless / class components in React:
// ./templates/component.js
module.exports = ({ name, type, params } = {}) => {
const [variant] = params;
return variant === 'class'
? classComponentString(name)
: statelessComponentString(name);
}
Default structure
You can use default templates provided with this module:
React component
$ burj component CoolButton
Will create the following files:
|-- src
| |-- components
| |-- index.js - Adds export
| |-- CoolButton
| | |-- CoolButton.jsx
| | |-- CoolButton.style.js
| | |-- index.js
| | ...
|-- test
| |-- components
| |-- CoolButton.test.jsx
| | ...
Additionaly you can specify params such as class
or redux
, which will generate a class component and/or connect it to redux, e.g.:
$ burj component CoolButton class
$ burj component CoolButton redux
$ burj component CoolButton class redux
React view component
It's the same as a component but can be used as a container.
$ burj view LoginPage
Action
$ burj action books
Will create the following files:
|-- src
| |-- actions
| |-- books.js
| | ...
|-- test
| |-- actions
| |-- books.js
| | ...
Additionaly you can specify a name of an action creator that will be created in a new file.
$ burj actions books getBook
Reducer
$ burj reducer books
Will create the following files:
|-- src
| |-- reducers
| |-- books.js
| | ...
|-- test
| |-- reducers
| |-- books.js
| | ...
Route
$ burj route auth
Will create the following files:
|-- src
| |-- routes
| |-- auth.js
| | ...
|-- test
| |-- routes
| |-- auth.js
| | ...
Author
Michał Wilk - whereiswolf.
License
Burj is MIT licensed.