Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First stable release #9

Merged
merged 18 commits into from
Nov 13, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 35 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# blah
Blah version. Blah gitignore. Blah README. Boring. You need blah.
![Blah - A command line tool to optimize the repetitive actions.](http://i.imgur.com/at4TK2R.png)

## Installation
Run the following commands to download and install the application:
Expand All @@ -17,11 +16,11 @@ $ ./blah.js --version
## Help

```sh
$ ./blah.js --help
$ blah --help
blah --help
usage: blah [options] [actions]

Blah version. Blah gitignore. Blah README. Boring. You need blah.
A command line tool to optimize the repetitive actions.

options:
--v, --version prints the version
Expand All @@ -31,46 +30,58 @@ actions:
readme creates the README.md file containing the documentation also
gitignore creates .gitignore file
license [license-name] creates the LICENSE file by providing the license name
docs creates the DOCUMENTATION.md file
docs <input-file> creates the DOCUMENTATION.md file from main file or <input-file>
if this was provided
version <what> where <what> can be 'major', 'minor' or 'patch'. Default: patch

Documentation can be found at https://github.com/IonicaBizau/node-blah
examples:
$ blah --version # outputs the version
$ blah readme # generates the README.md file using package.json
$ blah gitignore # generates the .gitignore file
$ blah license mit # generates the LICENSE file taking copyright holder information
# from package.json or GIT variables
$ blah docs index.js # generates DOCUMENTATION.md from index.js, parsing JSDoc comments
$ blah version major # bumps the major field of version, in package.json file
```

## Documentation
## `getPackage()`

Below you find the list with the methods that can be accessed programmatically:

### `getPackage()`
Returns the parsed content of package.json

### Return:
* **String** content of package.json file found in the current directory
#### Return
- **String** content of package.json file found in the current directory

## `generateDocs(file, callback)`
### `generateDocs(input, output, callback)`
Generate documentation file from package.json main file.

### Params:
* **String** `file`: Output file name (default: `DOCUMENTATION.md`)
* **Function** `callback`: The callback function
#### Params
- **String** `input`: Input file name (default: main file from package.json)
- **String** `output`: Output file name (default: `DOCUMENTATION.md`)
- **Function** `callback`: The callback function

## `generateReadme(callback)`
### `generateReadme(callback)`
Returns a string representing the readme content of the project.

### Params:
* **Function** `callback`: The callback function
#### Params
- **Function** `callback`: The callback function

## `generateGitignore()`
### `generateGitignore()`
Returns the content of .gitignore file

### Return:
* **String** Content of gitignore file.
#### Return
- **String** Content of gitignore file.

## `generateLicense(licenseName)`
### `generateLicense(licenseName)`
Returns the content of the LICENSE by providing the `@licenseName`.

### Params:
* **String** `licenseName`: The license name (e.g. `mit`)
#### Params
- **String** `licenseName`: The license name (e.g. `mit`)

### Return:
* **String** The content of license.
#### Return
- **String** The content of license.

## How to contribute

Expand Down
153 changes: 153 additions & 0 deletions bin/blah.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
#!/usr/bin/env node

// Dependencies
var Blah = require("../index.js")
, Fs = require("fs")
;

// Help content
const HELP =
"blah --help" +
"\nusage: blah [options] [actions]" +
"\n" +
"\nA command line tool to optimize the repetitive actions." +
"\n" +
"\noptions:" +
"\n --v, --version prints the version" +
"\n --help prints this output" +
"\n" +
"\nactions:" +
"\n readme creates the README.md file containing the documentation also" +
"\n gitignore creates .gitignore file" +
"\n license [license-name] creates the LICENSE file by providing the license name" +
"\n docs <input-file> creates the DOCUMENTATION.md file from main file or <input-file>" +
"\n if this was provided" +
"\n version <what> where <what> can be 'major', 'minor' or 'patch'. Default: patch" +
"\n" +
"\nexamples:" +
"\n $ blah --version # outputs the version" +
"\n $ blah readme # generates the README.md file using package.json" +
"\n $ blah gitignore # generates the .gitignore file" +
"\n $ blah license mit # generates the LICENSE file taking copyright holder information" +
"\n # from package.json or GIT variables" +
"\n $ blah docs index.js # generates DOCUMENTATION.md from index.js, parsing JSDoc comments" +
"\n $ blah version major # bumps the major field of version, in package.json file";

/*!
* Available options and actions
*
*/
var options = {

// Options
"version": {
run: function() {
console.log("Blah v" + require("../package").version);
}
, aliases: ["-v", "--version", "--v", "-version"]
}
, "help": {
run: function() {
console.log(HELP);
}
, aliases: ["-h", "--help", "--h", "-help"]
}

// Actions
, "readme": {
run: function() {
Blah.generateReadme(function (err, content) {
if (err) { return console.log(err); }
Fs.writeFileSync( "./README.md" , content);
});
}
, aliases: ["readme"]
}
, "gitignore": {
run: function() {
Fs.writeFileSync(
"./.gitignore"
, Blah.generateGitignore()
);
}
, aliases: ["gitignore"]
}
, "license": {
run: function() {
Fs.writeFileSync(
"./LICENSE"
, Blah.generateLicense(process.argv[3])
);
}
, aliases: ["license"]
}
, "docs": {
run: function() {
Blah.generateDocs(process.argv[3], "", function (err, data) {
if (err) { return console.log(err); }
console.log("Generated DOCUMENTATION.md");
});
}
, aliases: ["docs"]
}
, "bump-version": {
run: function() {
var pack = Blah.getPackage()
, version = pack.version.split(".").map(function (x) {
return parseInt(x, 10);
})
, what = process.argv[3] || "patch"
;

switch (what) {
case "major":
++version[0];
version[1] = 0;
version[2] = 0;
break;
case "minor":
++version[1];
version[2] = 0;
break;
case "patch":
++version[2];
break;
default:
console.error("Invalid input: " + what + ". Pass one of the following values: major, minor, patch.");
process.exit(1);
break;
}

pack.version = version.join(".");
Fs.writeFileSync(process.env.PWD + "/package.json", JSON.stringify(
pack, null, 2
));
}
, aliases: ["version"]
}
};

// Parse process.argv and run the needed action
var found = false;
for (var i = 2; i < process.argv.length; ++i) {
var cArg = process.argv[i];
for (var op in options) {
var cOp = options[op];
if (cOp.aliases.indexOf(cArg) !== -1) {
cOp.run();
found = true;
break;
}
}
}

// No actions, no fun
if (process.argv.length === 2 && !found) {
console.error("No action/option provided. Run blah --help for more information");
found = true;
}

// Invalid option/action
if (!found) {
console.error("Invalid option or action: " + process.argv.slice(2).join(", "));
}
Loading