Skip to content

Commit cde06c0

Browse files
committed
templates
0 parents  commit cde06c0

File tree

19 files changed

+14842
-0
lines changed

19 files changed

+14842
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

cli.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env node
2+
3+
console.log("HI")

index.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/usr/bin/env node
2+
const inquirer = require("inquirer");
3+
const fs = require("fs");
4+
5+
const CHOICES = fs.readdirSync(`${__dirname}/templates`);
6+
7+
const QUESTIONS = [
8+
{
9+
name: "project-choice",
10+
type: "list",
11+
message: "What project template would you like to generate?",
12+
choices: CHOICES
13+
},
14+
{
15+
name: "project-name",
16+
type: "input",
17+
message: "Project name:",
18+
validate: function(input) {
19+
if (/^([A-Za-z\-\_\d])+$/.test(input)) return true;
20+
else
21+
return "Project name may only include letters, numbers, underscores and hashes.";
22+
}
23+
}
24+
];
25+
26+
const CURR_DIR = process.cwd();
27+
28+
29+
function createDirectoryContents(templatePath, newProjectPath) {
30+
const filesToCreate = fs.readdirSync(templatePath);
31+
32+
filesToCreate.forEach(file => {
33+
const origFilePath = `${templatePath}/${file}`;
34+
35+
// get stats about the current file
36+
const stats = fs.statSync(origFilePath);
37+
38+
if (stats.isFile()) {
39+
const contents = fs.readFileSync(origFilePath, "utf8");
40+
41+
const writePath = `${CURR_DIR}/${newProjectPath}/${file}`;
42+
fs.writeFileSync(writePath, contents, "utf8");
43+
}
44+
});
45+
}
46+
47+
inquirer.prompt(QUESTIONS).then(answers => {
48+
const projectChoice = answers["project-choice"];
49+
const projectName = answers["project-name"];
50+
const templatePath = `${__dirname}/templates/${projectChoice}`;
51+
52+
fs.mkdirSync(`${CURR_DIR}/${projectName}`);
53+
54+
createDirectoryContents(templatePath, projectName);
55+
});

package-lock.json

Lines changed: 261 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "demo-generator",
3+
"version": "1.0.0",
4+
"bin": "index.js",
5+
"pkg": {
6+
"targets": [
7+
"node8-macos",
8+
"node8-linux",
9+
"node8-win"
10+
]
11+
},
12+
"scripts": {
13+
"start": "node index.js"
14+
},
15+
"dependencies": {
16+
"fs": "0.0.1-security",
17+
"inquirer": "^6.2.2"
18+
}
19+
}

templates/cli-template/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules
2+
.DS_Store
3+
dist/
4+
lib/

templates/cli-template/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Template for creating a new cli tool
2+
3+
The name of the tool is found in package.json
4+
5+
## Running Instructions
6+
To install all the necessary dependencies run ``` npm install```.
7+
8+
To build the cli tool ``` npm run build```. Any time you make a change, you have to rebuild the tool.
9+
10+
To link the tool to the command line, run ```npm link```.
11+
12+
13+
14+

0 commit comments

Comments
 (0)