create-fs-app 1.0.1 → 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.
Files changed (2) hide show
  1. package/create-fs-app.js +132 -46
  2. package/package.json +23 -6
package/create-fs-app.js CHANGED
@@ -1,56 +1,142 @@
1
1
  #!/usr/bin/env node
2
- const fs = require('fs');
3
- const { execSync } = require("child_process");
4
- const os = require("os");
5
- const path = require('path');
6
- const { dir } = require('console');
7
- // const processEditor = require('process-editor');
8
-
9
- // console.log(process.argv.length);
10
- // console.log(processEditor.name);
11
- if (process.argv.length > 3) {
12
- console.log("Error: Please provide a valid directory name\n");
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 parentDir = path.resolve(__dirname, '..');
20
- console.log("parent directory"+parentDir);
21
- const gitRepo = "https://github.com/Om-jannu/mern-template.git";
22
- const buildStructure = (dirName,dir) => {
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 ${gitRepo} ${dirName}`,{stdio:'inherit'});
25
- console.log('Repository cloned successfully to '+dir);
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
- if (!appName) {
32
- console.error('Error: Please provide a directory name');
33
- process.exit(1);
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
- else if (appName == ".") {
36
- buildStructure(".",currentDirectory);
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
- else {
39
- fs.access(parentDir, fs.constants.F_OK, (error) => {
40
- if (error) {
41
- console.error(`Error: Directory "${dirName}" does not exist`);
42
- process.exit(1);
43
- }
44
- process.chdir(parentDir);
45
- console.log("changed to parent directory");
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,16 +1,33 @@
1
1
  {
2
2
  "name": "create-fs-app",
3
- "version": "1.0.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
- "scripts": {
7
- "test": "echo \"Error: no test specified\" && exit 1"
8
- },
9
- "keywords": ["full Stack","full","Stack","mern","mean","react","express","mongodb","mongo"],
6
+ "bin": "./create-fs-app.js",
7
+ "keywords": [
8
+ "full Stack",
9
+ "full",
10
+ "Stack",
11
+ "mern",
12
+ "mean",
13
+ "react",
14
+ "express",
15
+ "mongodb",
16
+ "mongo"
17
+ ],
10
18
  "repository": {
11
19
  "type": "git",
12
20
  "url": "https://github.com/Om-jannu/create-fs-app.git"
13
21
  },
22
+ "type": "module",
14
23
  "author": "Om Jannu",
15
- "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
+ }
16
33
  }