Skip to content

Commit

Permalink
Merge pull request #1 from knowbee/master
Browse files Browse the repository at this point in the history
merging changes
  • Loading branch information
Urban Ishimwe authored Apr 8, 2020
2 parents 084580b + 05a68b8 commit 49c68af
Show file tree
Hide file tree
Showing 22 changed files with 350 additions and 1,391 deletions.
6 changes: 0 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@ node_js:
cache:
directories:
- node_modules
before_script:
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
- chmod +x ./cc-test-reporter
- ./cc-test-reporter before-build
after_script:
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
script: npm run test
after_success:
- npm run coverage
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2019 Igwaneza Bruce <[email protected]>
Copyright (c) 2020 Igwaneza Bruce <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
58 changes: 42 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
[![Open Source Love](https://badges.frapsoft.com/os/v1/open-source.svg?v=102)](https://github.com/ellerbrock/open-source-badge/)
[![Open Source Love](https://badges.frapsoft.com/os/mit/mit.svg?v=102)](https://github.com/ellerbrock/open-source-badge/)

Generate nodejs CI template files, Eslint config files, gitignore, docker and readme file from the command line when keza's CLI is installed globally
Generate template files(babelrc, eslint, readme, etc...) from the command line

## Install

Expand All @@ -23,36 +23,62 @@ yarn global add keza

## Preview

![keza](https://res.cloudinary.com/pcesar/image/upload/v1577030211/keza_iyw2eg.gif)
<p>
<img src="https://raw.githubusercontent.com/knowbee/hosting/master/assets/keza.PNG" width="400px" height="auto" hspace="10"/>
</p>

## Supported template files

| Template file
| ------------ |--
| ✔ .babelrc |
| ✔ .travis.yml |
| ✔ .dockerignore |
| ✔ .eslintignore |
| ✔ .eslintrc |
| ✔ .hound.yml |
| ✔ .sequerizerc |
| ✔ Dockerfile |
| ✔ Procfile |
| ✔ README.md |
|

## Using Keza CLI

#### Command Line

```cli
$ keza <options>
$ keza
```

## Options:

- `-h` or `--help`: display helper screen.
- `-b` or `--babel`: generate .babelrc.
- `-d` or `--docker`: generate docker file.
- `-e` or `--eslint`: generate .eslintrc and .eslintignore file.
- `-g` or `--gitignore`: generate nodejs .gitignore.
- `-ho` or `--hound`: generate hound yml file.
- `-r` or `--readme`: generate readme file.
- `-s` or `--sequelize`: generate .sequerizerc.
- `-t` or `--travis`: generate travis yml file.
- `--help`: display helper screen.

## Contribution

- Please before making a PR, read first this [Contributing Guideline](./CONTRIBUTING.md)
Please before making a PR, read first this [Contributing Guideline](./CONTRIBUTING.md)

## License

MIT
MIT License

## Author
Copyright (c) 2020 Igwaneza Bruce <[email protected]>

Igwaneza Bruce
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
102 changes: 27 additions & 75 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,89 +1,41 @@
#!/usr/bin/env node

const fs = require("fs");
const clear = require("clear");
const chalk = require("chalk");
const figlet = require("figlet");
const inquirer = require("inquirer");
const { templates, questions } = require("./lib/constants");
const { helper } = require("./lib/help");
const { generateTemplate } = require("./lib/generate");
const path = require("path");
const bar = require("cli-progress");
const cli = require("commander");

clear();
const keza = new cli.Command();
console.log(chalk.green(figlet.textSync("Keza", { horizontalLayout: "full" })));
const progress = new bar.SingleBar({
format: "Done |" + chalk.magenta("{bar}") + "| {percentage}%",
barCompleteChar: "\u2588",
hideCursor: true
hideCursor: true,
});

if (fs.existsSync("package.json")) {
helper();
process.argv.slice(2).forEach(function(item) {
if (item === "-b" || item === "--babel") {
generate(__dirname + "/templates/" + ".babelrc", ".babelrc");
} else if (item === "-d" || item === "--docker") {
generate(__dirname + "/templates/" + ".dockerignore", ".dockerignore");
generate(__dirname + "/templates/" + "Dockerfile", "Dockerfile");
} else if (item === "-e" || item === "--eslint") {
generate(__dirname + "/templates/" + ".eslintrc", ".eslintrc");
generate(__dirname + "/templates/" + ".eslintignore", ".eslintignore");
} else if (item === "-g" || item === "--gitignore") {
generate(__dirname + "/templates/" + "gitignore", ".gitignore");
} else if (item === "-ho" || item === "--hound") {
generate(__dirname + "/templates/" + ".hound.yml", ".hound.yml");
} else if (item === "-r" || item === "--readme") {
generate(__dirname + "/templates/" + "README.md", "README.md");
} else if (item === "-s" || item === "--sequelizerc") {
generate(__dirname + "/templates/" + ".sequelizerc", ".sequelizerc");
} else if (item === "-t" || item === "--travis") {
generate(__dirname + "/templates/" + ".travis.yml", ".travis.yml");
}
});
if (process.argv.length == 2) {
fs.readdir(__dirname + "/templates", function(err, filenames) {
if (err) {
return;
}
progress.start(filenames.length);
filenames.forEach(file => {
generate(__dirname + "/templates/" + file, file);
progress.update(filenames.length);
clear();
helper();
console.log(
chalk.magenta(figlet.textSync("Keza", { horizontalLayout: "full" }))
);
console.log(chalk.green("generate template files very fast"));
if (process.argv.length == 2) {
inquirer.prompt(questions).then((answers) => {
let choices = [];
Object.keys(answers).forEach((a) => {
Object.keys(templates).forEach((t) => {
if (a === t && answers[a].length >= 1) {
answers[a].map((file) => {
choices = [...choices, templates[a][file]];
});
}
});
progress.stop();
});
}
function generate(from, to) {
progress.start(to.length);
fs.copyFile(from, to, err => {
progress.update(100);
if (err) throw err;
progress.stop();
progress.start(choices.length);
choices.forEach((choice) => {
generateTemplate(choice, path.basename(choice));
});
}
} else {
helper();
console.log(
chalk.magenta("You have to initialize your project with npm or yarn first")
);

process.exit();
}
function helper() {
keza
.version("1.0.4")
.option("-b, --babel", "generate babelrc")
.option("-d, --docker", "generate docker file")
.option("-e, --eslint", "generate eslintrc and eslintignore")
.option("-g, --gitignore", "generate nodejs gitignore")
.option("-ho, --hound", "generate hound file")
.option("-r, --readme", "generate readme file")
.option("-s, --sequelize", "generate sequerizerc")
.option("-t, --travis", "generate travis")
.parse(process.argv);
keza.on("--help", function() {
console.log("Examples:");
console.log(" $ keza --help");
console.log(" $ keza -h");
console.log(" $ keza -b -d -t");
progress.update(100);
progress.stop();
});
}
69 changes: 69 additions & 0 deletions lib/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
const path = require("path")
/**
* only change this file if you want to add more template files
*/
exports.templates = {
ci: {
travis: path.join(__dirname) + "\\templates\\.travis.yml",
hound: path.join(__dirname) + "\\templates\\.hound.yml",
},
docker: {
dockerignore: path.join(__dirname) + "\\templates\\.dockerignore",
dockerfile: path.join(__dirname) + "\\templates\\Dockerfile",
},
lint: {
eslintrc: path.join(__dirname) + "\\templates\\.eslintrc",
eslintignore: path.join(__dirname) + "\\templates\\.eslintignore",
},
babel: {
babelrc: path.join(__dirname) + "\\templates\\.babelrc",
},
database: {
sequelizerc: path.join(__dirname) + "\\templates\\.sequelizerc",
procfile:path.join(__dirname) + "\\templates\\Procfile"
},
documentation: {
readme: path.join(__dirname) + "\\templates\\README.md",
}
};



exports.questions = [
{
type: "checkbox",
message: "CI\\CD",
name: "ci",
choices: ["travis", "hound"]
},
{
type: "checkbox",
message: "Dockerize",
name: "docker",
choices: ["dockerfile", "dockerignore"]
},
{
type: "checkbox",
message: "Linter",
name: "lint",
choices: ["eslintrc", "eslintignore"]
},
{
type: "checkbox",
message: "Database",
name: "database",
choices: ["sequelizerc", "procfile"]
},
{
type: "checkbox",
message: "Babel",
name: "babel",
choices: ["babelrc"]
},
{
type: "checkbox",
message: "Documentation",
name: "documentation",
choices: ["readme"]
}
];
11 changes: 11 additions & 0 deletions lib/generate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const fs = require("fs")
const chalk = require("chalk");
exports.generateTemplate = (from, to) => {
try {
fs.copyFileSync(from, to);
} catch (error) {
console.log("\n");
console.log(chalk.yellow("oooh no! try again"));
process.exit(1)
}
}
14 changes: 14 additions & 0 deletions lib/help.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const cli = require("commander");

const keza = new cli.Command();
exports.helper = () => {
keza
.description("generate template files very fast")
.version("1.0.9")
.parse(process.argv);
keza.on("--help", function () {
console.log("Examples:");
console.log(" $ keza --help");
console.log(" $ keza -g");
});
};
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
25 changes: 25 additions & 0 deletions lib/templates/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Generated by keza





## Installation






## Usage



## Examples


## Contribution



## License
Loading

0 comments on commit 49c68af

Please sign in to comment.