nuject v1.0.0
nuject
nuject is a simple and generic (language-agnostic) project generator. It creates projects from templates (also called scaffolds) and fills in parameters using text substitution.
Installing
npm install -g nuject
Usage
Config file (.nuject)
First thing you need is a config file in your home directory with the name .nuject
. It must be JSON file containing an object like this:
{
"templateDir": "/home/cyco/Documents/nuject",
"defaults": {
"name": "Fatih Aygün",
"email": "cyco130@gmail.com",
"github": "cyco130"
}
}
templatDir
tells nuject where to find nuject templates and defaults
provides nuject with some default values for template parameters so that you don't have to type them every time. Both are optional and the default template directory is {$HOME}/nuject
.
Template format
nuject templates should have the following directory structure:
{template-name}/
|- index.js
|- contents/
The index.js
file contains all the settings and should be in the following format:
module.exports = {
// Template parameteres to be filled in.
// The format is ["parameter_name", "user friendly prompt"]
params: [
["project", "Project name"],
["name", "Your name and surname"],
["email", "Your email"],
["github", "Your github name"],
["description", "Project description"],
],
// Files to copy verbatim (instead of replacing the template parameters).
// A list of binary files should be added here.
// Template parametes in file names will still be expanded.
verbatim: [],
// Shell scripts to run after copying the files.
postcopy: [
"npm install",
"git init",
// Scripts can contain template parameters too.
"git remote add origin https://github.com/{{{github}}}/{{{project}}}.git",
],
};
The contents
directory contains the actual files to be copied to create a new project. All text with the pattern {{{parameter}}}
will replaced with the value of the appropriate parameter unless the file is listed in verbatim
. File names will also be replaced in this manner, even if they are listed in verbatim
.
Command line usage
If you have a .nuject
config file and a nuject template directory containing a template called test
, creating a project with nuject is easy:
mkdir my-test-project
cd my-test-project
nuject test
The you will be prompted to provide values for template parameters. If you have defaults
defined in your .nuject
file, thos value will be used as defaults. The {{{project}}}
parameter's default value will be deduced from the directory name. If you pass -d
to nuject, it will not prompt for paramaters with default values and simply use them.
Building
nuject is written in TypeScript. Building requires a bash environment. Clone the repo, install the dependencies and build with the following commands:
git clone https://github.com/cyco130/nuject.git
cd nuject
npm install
npm run build
Authors
- Fatih Aygün - Initial work - cyco130
6 years ago