Skip to content

Commit e4f6a41

Browse files
Merge pull request #4 from shoaibmohommed/feat/automatic-app-generation
Fixed project structure and automatic generate project structure in s…
2 parents ed3f293 + cb071a4 commit e4f6a41

File tree

5,116 files changed

+159082
-1505
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

5,116 files changed

+159082
-1505
lines changed

.vscode/launch.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"type": "node",
9+
"request": "launch",
10+
"name": "Launch Program",
11+
"program": "${workspaceFolder}/index.js"
12+
}
13+
]
14+
}

Readme.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ This is the seed application for node js
99

1010
## How To Start
1111
Inside node_modules folder
12-
* Navigate to @aakashdeveloper folder
13-
* Copy create-node-app and paste in new folder
14-
* Inside create-node-app run npm install > npm start
12+
* globally install this module with npm "npm install -g @aakashdeveloper/create-node-app"
13+
* go to the directory where you want to generate the project files
14+
* run "generate" in shell/cmd and follow the instructions.
15+
* inside your newly created project folder run "npm start".
1516
* Navigate to http://localhost:7600
1617

1718

index.js

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#!/usr/bin/env node
2+
const CURR_DIR = process.cwd();
3+
const inquirer = require('inquirer');
4+
const fs = require('fs');
5+
const shell = require('shelljs');
6+
7+
const CHOICES = fs.readdirSync(`${__dirname}/templates`);
8+
9+
const QUESTIONS = [
10+
{
11+
name: 'project-choice',
12+
type: 'list',
13+
message: 'What project template would you like to generate?',
14+
choices: CHOICES
15+
},
16+
{
17+
name: 'project-name',
18+
type: 'input',
19+
message: 'Project name:',
20+
validate: function (input) {
21+
if (/^([A-Za-z\-\_\d])+$/.test(input)) return true;
22+
else return 'Project name may only include letters, numbers, underscores and hashes.';
23+
}
24+
}
25+
];
26+
console.log(`index.js is running...`);
27+
inquirer.prompt(QUESTIONS)
28+
.then(answers => {
29+
const projectChoice = answers['project-choice'];
30+
const projectName = answers['project-name'];
31+
const templatePath = `${__dirname}/templates/${projectChoice}`;
32+
33+
fs.mkdirSync(`${CURR_DIR}/${projectName}`);
34+
console.log(`creating seed project....`);
35+
return Promise.all([createDirectoryContents(templatePath, projectName), projectName]);
36+
}).then(([result2, projectName]) => {
37+
console.log(`seed project created successfully....`);
38+
39+
console.log("installing modules...");
40+
console.log(`entering in ${projectName} directory...`);
41+
shell.cd(projectName);
42+
//process.chdir(`${CURR_DIR}/${projectName}`);
43+
44+
shell.echo(`current working directory is ${process.cwd()}`);
45+
if (shell.exec('npm install').code !== 0) {
46+
shell.echo('Error: Git commit failed');
47+
shell.exit(1);
48+
} else {
49+
shell.echo('packages installed successfully.');
50+
}
51+
});
52+
53+
function createDirectoryContents(templatePath, newProjectPath) {
54+
const filesToCreate = fs.readdirSync(templatePath);
55+
56+
filesToCreate.forEach(file => {
57+
const origFilePath = `${templatePath}/${file}`;
58+
59+
// get stats about the current file
60+
const stats = fs.statSync(origFilePath);
61+
62+
if (stats.isFile()) {
63+
const contents = fs.readFileSync(origFilePath, 'utf8');
64+
65+
// Rename
66+
if (file === '.npmignore') file = '.gitignore';
67+
68+
const writePath = `${CURR_DIR}/${newProjectPath}/${file}`;
69+
fs.writeFileSync(writePath, contents, 'utf8');
70+
} else if (stats.isDirectory()) {
71+
fs.mkdirSync(`${CURR_DIR}/${newProjectPath}/${file}`);
72+
73+
// recursive call
74+
createDirectoryContents(`${templatePath}/${file}`, `${newProjectPath}/${file}`);
75+
}
76+
});
77+
}

node_modules/.bin/shjs

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

node_modules/ansi-escapes/index.js

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

node_modules/ansi-escapes/license

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

node_modules/ansi-escapes/package.json

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

0 commit comments

Comments
 (0)