create-fs-app 1.1.2 → 1.1.4
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 +44 -44
- package/package.json +1 -1
package/create-fs-app.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import fs from 'fs';
|
|
3
3
|
import child_process from "child_process";
|
|
4
4
|
import path from 'path';
|
|
5
|
-
import {fileURLToPath} from 'url';
|
|
5
|
+
import { fileURLToPath } from 'url';
|
|
6
6
|
import chalk from 'chalk';
|
|
7
7
|
import chalkAnimation from 'chalk-animation';
|
|
8
8
|
import inquirer from 'inquirer';
|
|
@@ -13,17 +13,17 @@ import gradient from 'gradient-string';
|
|
|
13
13
|
let appName = process.argv[2];
|
|
14
14
|
const currentDirectory = process.cwd();
|
|
15
15
|
const __filename = fileURLToPath(import.meta.url);
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
|
|
17
|
+
// git repository
|
|
18
18
|
const mernGitRepo = "https://github.com/Om-jannu/mern-template.git";
|
|
19
19
|
|
|
20
20
|
//sleep function
|
|
21
21
|
const sleep = (ms = 1000) => new Promise((r) => setTimeout(r, ms));
|
|
22
22
|
|
|
23
23
|
// welcome function
|
|
24
|
-
const welcome = async() =>{
|
|
24
|
+
const welcome = async () => {
|
|
25
25
|
const msg = "create-fs-app";
|
|
26
|
-
const welcomeMsg = figlet(msg,(err,data) =>{
|
|
26
|
+
const welcomeMsg = figlet(msg, (err, data) => {
|
|
27
27
|
console.log(gradient.pastel.multiline(data));
|
|
28
28
|
})
|
|
29
29
|
welcomeMsg;
|
|
@@ -36,12 +36,12 @@ const welcome = async() =>{
|
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
// qns function
|
|
39
|
-
const askFsName = async() => {
|
|
39
|
+
const askFsName = async () => {
|
|
40
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:[
|
|
41
|
+
name: "fs_app",
|
|
42
|
+
type: 'list',
|
|
43
|
+
message: 'Which FullStack App do you want to build?',
|
|
44
|
+
choices: [
|
|
45
45
|
'MERN app',
|
|
46
46
|
'MEAN app',
|
|
47
47
|
'MEVN app',
|
|
@@ -51,84 +51,84 @@ const askFsName = async() => {
|
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
//completion screen
|
|
54
|
-
const completion = async() =>{
|
|
54
|
+
const completion = async () => {
|
|
55
55
|
const completion_msg = chalkAnimation.rainbow(
|
|
56
56
|
'\nSuccesfully created your Full Stack Template'
|
|
57
57
|
);
|
|
58
58
|
await sleep();
|
|
59
59
|
completion_msg.stop();
|
|
60
60
|
console.log(chalk.bold.yellow('To access your folder :'));
|
|
61
|
-
console.log(chalk.bold.blue(
|
|
62
|
-
console.log(chalk.bold.blue(`cd ${appName}`));
|
|
61
|
+
console.log(chalk.bold.blue(`cd ${(appName=='.')?currentDirectory:appName}`));
|
|
63
62
|
console.log(chalk.bold.blue('code .'));
|
|
64
|
-
|
|
65
|
-
console.log(chalk.bold.yellow(`\nNOTE : ${chalk.bold.blue('code .')} is for opening folder in vs-code for different IDE use different Keyword`));
|
|
63
|
+
console.log(chalk.bold.yellow(`\nNOTE : ${chalk.bold.blue('code .')} is for opening folder in ${chalk.bold.blue('vs-code')} for different IDE use different Keyword`));
|
|
66
64
|
}
|
|
67
65
|
|
|
68
66
|
// answer handler
|
|
69
|
-
const handleAnswer = async(fs_app) => {
|
|
67
|
+
const handleAnswer = async (fs_app) => {
|
|
70
68
|
const spinner = createSpinner(chalk.bold.green('Creating your Project Structure...')).start();
|
|
71
69
|
await sleep();
|
|
72
70
|
spinner.stop();
|
|
73
|
-
if(fs_app == 'MERN app') {
|
|
71
|
+
if (fs_app == 'MERN app') {
|
|
74
72
|
console.log(chalk.bold.bgGreen("\nBuilding MERN structure"));
|
|
75
73
|
BuildMernStructure();
|
|
76
74
|
await sleep();
|
|
77
75
|
completion();
|
|
78
76
|
}
|
|
79
|
-
if(fs_app == 'MEAN app') {
|
|
77
|
+
if (fs_app == 'MEAN app') {
|
|
80
78
|
console.log("\nNot yet started");
|
|
81
79
|
// completion();
|
|
82
80
|
}
|
|
83
|
-
if(fs_app == 'MEVN app') {
|
|
81
|
+
if (fs_app == 'MEVN app') {
|
|
84
82
|
console.log("\nNot yet started");
|
|
85
83
|
// completion();
|
|
86
84
|
}
|
|
87
85
|
}
|
|
88
86
|
|
|
89
87
|
// function to clone a repositoy
|
|
90
|
-
const buildStructure = (dirName,dir,repo) => {
|
|
88
|
+
const buildStructure = async(dirName, dir, repo) => {
|
|
91
89
|
try {
|
|
92
|
-
child_process.execSync(`git clone ${repo} ${dirName}`,{stdio:'inherit'});
|
|
93
|
-
console.log(chalk.bold.green('\nRepository cloned successfully to '+dir));
|
|
90
|
+
child_process.execSync(`git clone ${repo} ${dirName}`, { stdio: 'inherit' });
|
|
91
|
+
console.log(chalk.bold.green('\nRepository cloned successfully to ' + dir));
|
|
94
92
|
} catch (err) {
|
|
95
|
-
console.error(chalk.
|
|
93
|
+
console.error(chalk.italic.red('Error cloning repository:', err));
|
|
96
94
|
process.exit(1);
|
|
97
95
|
}
|
|
98
96
|
}
|
|
99
97
|
|
|
98
|
+
// function to create a folder
|
|
99
|
+
async function createFolder(folderName) {
|
|
100
|
+
try {
|
|
101
|
+
if (!fs.existsSync(folderName)) {
|
|
102
|
+
fs.mkdirSync(folderName);
|
|
103
|
+
} else {
|
|
104
|
+
console.log(chalk.italic.red(`Folder ${folderName} already exists.`));
|
|
105
|
+
console.log(chalk.bold.yellow(`Try : cd ${folderName} && npx create-fs-app .`));
|
|
106
|
+
process.exit(1);
|
|
107
|
+
}
|
|
108
|
+
} catch (err) {
|
|
109
|
+
console.error(chalk.italic.red(`error creting folder ${err}`));
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
100
113
|
// function to clone mern repository
|
|
101
|
-
const BuildMernStructure = ()=>{
|
|
114
|
+
const BuildMernStructure = async() => {
|
|
102
115
|
if (!appName) {
|
|
103
|
-
console.error(chalk.
|
|
116
|
+
console.error(chalk.italic.red('Error: Please provide a directory name'));
|
|
104
117
|
process.exit(1);
|
|
105
118
|
}
|
|
106
119
|
else if (appName == ".") {
|
|
107
|
-
buildStructure(
|
|
120
|
+
buildStructure('.', currentDirectory, mernGitRepo);
|
|
108
121
|
}
|
|
109
122
|
else {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
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
|
-
});
|
|
123
|
+
const projDir = path.resolve(path.dirname(__filename),appName);
|
|
124
|
+
await createFolder(appName);
|
|
125
|
+
await buildStructure(appName,projDir,mernGitRepo);
|
|
126
126
|
}
|
|
127
127
|
}
|
|
128
128
|
|
|
129
129
|
if (process.argv.length > 3) {
|
|
130
|
-
console.log(chalk.
|
|
131
|
-
console.log(chalk.
|
|
130
|
+
console.log(chalk.italic.red("Error: Please provide a valid directory name"));
|
|
131
|
+
console.log(chalk.italic.red("Note: directory name should not contain spaces"));
|
|
132
132
|
console.log(chalk.bold.yellow("Try : npx build-mern-app app_name"));
|
|
133
133
|
process.exit(1);
|
|
134
134
|
}
|