haki v0.12.0
Haki

Small generator with will powers.
$ npx haki [-e FILE] [COMMAND] [...]
# or `npm i -g haki`
# or `yarn global add haki`Run
hakiwithout arguments to get usage hints.
Example
Create a file named Hakifile.js in your project with this:
module.exports = haki => {
haki.setGenerator('the:truth', {
description: "Display if it's true, or not",
arguments: ['verb', 'value'],
abortOnFail: true,
actions(input) {
const { verb, value } = input;
if (verb === 'is' && parseInt(value, 10) === 42) {
console.log('Gotcha!');
return;
}
throw new Error('Is not true');
},
});
}Now you can execute this task through the CLI:
haki the:truthhaki the:truth is 42
API
Available methods:
load(filepath: String)— Load a Hakifile from given filepathprompt(options: Object)— Generic prompting helper, see options belowgetPrompts()— Returns Prompts instancegetLogger()— Returns LogPose instancegetPath(destName: String)— Returns a filepath for outputaddHelper(name: String, callback: Function)— Register a Mustache helper for calling on templatesgetHelperList()— Retrieve all registered helpersrenderString(value: String, data: Object)— Render template valuessetGenerator(name: String[, options: Object])— Register a generator definition, see options belowgetGenerator(name: String)— Retrieve a registered generatorrunGenerator(name: String|Object[, defaults: Object])— Execute any given generator; givennamecan be an object, see options belowhasGenerator(name: String)— Returnstrueif given generator is definedgetGeneratorList([hints: Boolean])— Retrieve all registered generators, ifhintsis given then descriptions are prefixed with their nameschooseGeneratorList([defaults: Object])— Prompt to execute from registered generators,defaultsare given as forrunGenerator()
Generators
Those can be registered or executed directly.
Valid options are:
description: String— Displayed on--helpvalidate: Object|Function— To validate inputarguments: Array— Map extraargvas inputactions: Array|Function— See belowprompts: Array|Function— See belowdefaults: Object— Initial valuesquiet: Boolean— Hide output from logsbasePath: String— Resolve sources from hereabortOnFail: Boolean— Abort whole process on failure
Both
promptsandarrayscan be functions, once executed they should return an array to be used or nothing.
Actions
Enumerated actions can perform several tasks based on its definition.
Definitions can contain:
src: String— Relative to generator'sbasePathtype: String— Action type: add, copy, clean, etc.dest: String— Relative toprocess.cwd()for outputtemplate: String— Used when creating filestemplateFile: String— Source file used when creating filesdefaultContent: String— Onmodify, used if file does not exists yetdeleteContent: Boolean— Onmodify, remove matched code instead of replacing itafter: String|RegExp— As below, used to replace before the matchbefore: String|RegExp— As below, used to replace after the match (alias ofpattern)pattern: String|RegExp— Onmodify, used to match-and-replaceunless: String|RegExp— Onmodify, used to skip matching codecontent: String— Liketemplatebut without Mustache supportgitUrl: String— Used oncloneactions, relative to githubcallback: Function— Used onextendactions to merge inputcommand: String— Used onexecactions, as shell commandquiet: Boolean— Override generator'squietvalueabortOnFail: Boolean— Override generator'sabortOnFailvalue
Prompts
User input is being done by Prompts, so any syntax supported is valid, e.g.
type: String— Generator type 1name: String— Input namemessage: String— Optional label
1 Check which types are supported by default.
Global usage
By design haki will scan for immediately available Hakifiles from the current working and other special directories.
Say, we are at $HOME/path/to/project/name so paths below are used:
/etc/.config/haki/etc/.hakirc/etc/Hakifile.js$HOME/.config/haki$HOME/.hakirc$HOME/Hakifile.js$HOME/path/to/project/name/.config/haki$HOME/path/to/project/name/.hakirc$HOME/path/to/project/name/Hakifile.js$HOME/path/to/project/.config/haki$HOME/path/to/project/.hakirc$HOME/path/to/project/Hakifile.js$HOME/path/to/.config/haki$HOME/path/to/.hakirc$HOME/path/to/Hakifile.js- etc. — scanning stops when
/or$HOMEpath is reached.
Gist usage
You can download and run remote gists too:
$ haki -g [SHA1]List available gists with haki -g only.
GitHub usage
Download github repositories with:
$ haki <USER/REPO> <DEST>5 years ago
5 years ago
7 years ago
7 years ago
7 years ago
7 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
9 years ago
9 years ago
9 years ago
9 years ago
10 years ago
10 years ago
10 years ago
10 years ago
