create-fs-app 1.0.0

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 +56 -0
  2. package/package.json +12 -0
@@ -0,0 +1,56 @@
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
+ }
17
+ let appName = process.argv[2];
18
+ 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) => {
23
+ try {
24
+ execSync(`git clone ${gitRepo} ${dirName}`,{stdio:'inherit'});
25
+ console.log('Repository cloned successfully to '+dir);
26
+ } catch (err) {
27
+ console.error('Error cloning repository:', err);
28
+ process.exit(1);
29
+ }
30
+ }
31
+ if (!appName) {
32
+ console.error('Error: Please provide a directory name');
33
+ process.exit(1);
34
+ }
35
+ else if (appName == ".") {
36
+ buildStructure(".",currentDirectory);
37
+ }
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
+ }
package/package.json ADDED
@@ -0,0 +1,12 @@
1
+ {
2
+ "name": "create-fs-app",
3
+ "version": "1.0.0",
4
+ "description": "A command line tool to create Full Stack templates",
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"],
10
+ "author": "Om Jannu",
11
+ "license": "ISC"
12
+ }