create-fs-app 1.0.2 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/create-fs-app.js +132 -46
- package/package.json +22 -3
package/create-fs-app.js
CHANGED
|
@@ -1,56 +1,142 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
console.log("Note: directory name should not contain spaces");
|
|
14
|
-
console.log("Try : npx build-mern-app app_name");
|
|
15
|
-
process.exit(1);
|
|
16
|
-
}
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import child_process from "child_process";
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import {fileURLToPath} from 'url';
|
|
6
|
+
import chalk from 'chalk';
|
|
7
|
+
import chalkAnimation from 'chalk-animation';
|
|
8
|
+
import inquirer from 'inquirer';
|
|
9
|
+
import { createSpinner } from 'nanospinner';
|
|
10
|
+
import figlet from 'figlet';
|
|
11
|
+
import gradient from 'gradient-string';
|
|
12
|
+
|
|
17
13
|
let appName = process.argv[2];
|
|
18
14
|
const currentDirectory = process.cwd();
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const
|
|
15
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
16
|
+
const parentDir = path.resolve(path.dirname(__filename),'../');
|
|
17
|
+
console.log(parentDir);
|
|
18
|
+
const mernGitRepo = "https://github.com/Om-jannu/mern-template.git";
|
|
19
|
+
|
|
20
|
+
//sleep function
|
|
21
|
+
const sleep = (ms = 1000) => new Promise((r) => setTimeout(r, ms));
|
|
22
|
+
|
|
23
|
+
// welcome function
|
|
24
|
+
const welcome = async() =>{
|
|
25
|
+
const msg = "create-fs-app";
|
|
26
|
+
const welcomeMsg = figlet(msg,(err,data) =>{
|
|
27
|
+
console.log(gradient.pastel.multiline(data));
|
|
28
|
+
})
|
|
29
|
+
welcomeMsg;
|
|
30
|
+
await sleep();
|
|
31
|
+
console.log(`
|
|
32
|
+
I am your personal FullStack template generator
|
|
33
|
+
I can create Full Stack Templates for you ${chalk.green('in seconds')}😉
|
|
34
|
+
Let's get started...
|
|
35
|
+
`);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// qns function
|
|
39
|
+
const askFsName = async() => {
|
|
40
|
+
const answers = await inquirer.prompt({
|
|
41
|
+
name:"fs_app",
|
|
42
|
+
type:'list',
|
|
43
|
+
message:'Which FullStack App do you want to build?',
|
|
44
|
+
choices:[
|
|
45
|
+
'MERN app',
|
|
46
|
+
'MEAN app',
|
|
47
|
+
'MEVN app',
|
|
48
|
+
],
|
|
49
|
+
});
|
|
50
|
+
return handleAnswer(answers.fs_app);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
//completion screen
|
|
54
|
+
const completion = async() =>{
|
|
55
|
+
const completion_msg = chalkAnimation.rainbow(
|
|
56
|
+
'\nSuccesfully created your Full Stack Template'
|
|
57
|
+
);
|
|
58
|
+
await sleep();
|
|
59
|
+
completion_msg.stop();
|
|
60
|
+
console.log(chalk.bold.yellow('To access your folder :'));
|
|
61
|
+
console.log(chalk.bold.blue('cd ..'));
|
|
62
|
+
console.log(chalk.bold.blue(`cd ${appName}`));
|
|
63
|
+
console.log(chalk.bold.blue('code .'));
|
|
64
|
+
const projectdirname = parentDir+'/'+appName;
|
|
65
|
+
console.log(chalk.bold.yellow(`\nNOTE : ${chalk.bold.blue('code .')} is for opening folder in vs-code for different IDE use different Keyword`));
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// answer handler
|
|
69
|
+
const handleAnswer = async(fs_app) => {
|
|
70
|
+
const spinner = createSpinner(chalk.bold.green('Creating your Project Structure...')).start();
|
|
71
|
+
await sleep();
|
|
72
|
+
spinner.stop();
|
|
73
|
+
if(fs_app == 'MERN app') {
|
|
74
|
+
console.log(chalk.bold.bgGreen("\nBuilding MERN structure"));
|
|
75
|
+
BuildMernStructure();
|
|
76
|
+
await sleep();
|
|
77
|
+
completion();
|
|
78
|
+
}
|
|
79
|
+
if(fs_app == 'MEAN app') {
|
|
80
|
+
console.log("\nNot yet started");
|
|
81
|
+
// completion();
|
|
82
|
+
}
|
|
83
|
+
if(fs_app == 'MEVN app') {
|
|
84
|
+
console.log("\nNot yet started");
|
|
85
|
+
// completion();
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// function to clone a repositoy
|
|
90
|
+
const buildStructure = (dirName,dir,repo) => {
|
|
23
91
|
try {
|
|
24
|
-
execSync(`git clone ${
|
|
25
|
-
console.log('
|
|
92
|
+
child_process.execSync(`git clone ${repo} ${dirName}`,{stdio:'inherit'});
|
|
93
|
+
console.log(chalk.bold.green('\nRepository cloned successfully to '+dir));
|
|
26
94
|
} catch (err) {
|
|
27
|
-
console.error('Error cloning repository:', err);
|
|
95
|
+
console.error(chalk.bold.red('Error cloning repository:', err));
|
|
28
96
|
process.exit(1);
|
|
29
97
|
}
|
|
30
98
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
99
|
+
|
|
100
|
+
// function to clone mern repository
|
|
101
|
+
const BuildMernStructure = ()=>{
|
|
102
|
+
if (!appName) {
|
|
103
|
+
console.error(chalk.bold.red('Error: Please provide a directory name'));
|
|
104
|
+
process.exit(1);
|
|
105
|
+
}
|
|
106
|
+
else if (appName == ".") {
|
|
107
|
+
buildStructure(".",currentDirectory,mernGitRepo);
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
fs.access(parentDir, fs.constants.F_OK, (error) => {
|
|
111
|
+
if (error) {
|
|
112
|
+
console.error(chalk.bold.red(`Error: Directory "${parentDir}" does not exist`));
|
|
113
|
+
process.exit(1);
|
|
114
|
+
}
|
|
115
|
+
process.chdir(parentDir);
|
|
116
|
+
console.log(chalk.bold.yellow(`Current directory : ${process.cwd()}`));
|
|
117
|
+
if (fs.existsSync(path.join(parentDir, appName))) {
|
|
118
|
+
console.log(chalk.bold.red("Folder already exists"));
|
|
119
|
+
process.exit(0);
|
|
120
|
+
}
|
|
121
|
+
fs.mkdirSync(appName);
|
|
122
|
+
const projectdirname = parentDir+'\\'+appName;
|
|
123
|
+
buildStructure(appName,projectdirname,mernGitRepo);
|
|
124
|
+
console.log(chalk.bold.green(`Project "${appName}" has been created`));
|
|
125
|
+
});
|
|
126
|
+
}
|
|
34
127
|
}
|
|
35
|
-
|
|
36
|
-
|
|
128
|
+
|
|
129
|
+
if (process.argv.length > 3) {
|
|
130
|
+
console.log(chalk.bold.red("Error: Please provide a valid directory name"));
|
|
131
|
+
console.log(chalk.bold.red("Note: directory name should not contain spaces"));
|
|
132
|
+
console.log(chalk.bold.yellow("Try : npx build-mern-app app_name"));
|
|
133
|
+
process.exit(1);
|
|
37
134
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
console.log(`Current directory after changing: ${process.cwd()}`);
|
|
47
|
-
if (fs.existsSync(path.join(parentDir, appName))) {
|
|
48
|
-
console.log("file already exists");
|
|
49
|
-
process.exit(0);
|
|
50
|
-
}
|
|
51
|
-
fs.mkdirSync(appName);
|
|
52
|
-
const projectdirname = parentDir+'\.'+appName;
|
|
53
|
-
buildStructure(appName,projectdirname);
|
|
54
|
-
console.log(`Project "${appName}" has been created`);
|
|
55
|
-
});
|
|
56
|
-
}
|
|
135
|
+
|
|
136
|
+
await welcome();
|
|
137
|
+
await askFsName();
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
|
package/package.json
CHANGED
|
@@ -1,14 +1,33 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-fs-app",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "A command line tool to create Full Stack templates",
|
|
5
5
|
"main": "./create-fs-app",
|
|
6
6
|
"bin": "./create-fs-app.js",
|
|
7
|
-
"keywords": [
|
|
7
|
+
"keywords": [
|
|
8
|
+
"full Stack",
|
|
9
|
+
"full",
|
|
10
|
+
"Stack",
|
|
11
|
+
"mern",
|
|
12
|
+
"mean",
|
|
13
|
+
"react",
|
|
14
|
+
"express",
|
|
15
|
+
"mongodb",
|
|
16
|
+
"mongo"
|
|
17
|
+
],
|
|
8
18
|
"repository": {
|
|
9
19
|
"type": "git",
|
|
10
20
|
"url": "https://github.com/Om-jannu/create-fs-app.git"
|
|
11
21
|
},
|
|
22
|
+
"type": "module",
|
|
12
23
|
"author": "Om Jannu",
|
|
13
|
-
"license": "ISC"
|
|
24
|
+
"license": "ISC",
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"chalk": "^5.2.0",
|
|
27
|
+
"chalk-animation": "^2.0.3",
|
|
28
|
+
"figlet": "^1.5.2",
|
|
29
|
+
"gradient-string": "^2.0.2",
|
|
30
|
+
"inquirer": "^9.1.4",
|
|
31
|
+
"nanospinner": "^1.1.0"
|
|
32
|
+
}
|
|
14
33
|
}
|