create-fs-app 1.1.2 → 1.1.3

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