generateproj 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.
package/README.md ADDED
@@ -0,0 +1,78 @@
1
+ # Welcome to Progen 👋
2
+
3
+ [![Version](https://img.shields.io/npm/v/creaprogetto.svg)](https://www.npmjs.com/package/creaprogetto)
4
+ [![Documentation](https://img.shields.io/badge/documentation-yes-brightgreen.svg)](https://www.npmjs.com/package/creaprogetto)
5
+ [![License: ISC](https://img.shields.io/badge/License-ISC-yellow.svg)](#)
6
+
7
+ > **creaprogetto** è uno strumento da riga di comando pensato per semplificare e velocizzare la creazione di progetti software.
8
+ > Supporta la generazione automatica di strutture base per i linguaggi e ambienti più comuni: **Java**, **Node.js**, **HTML/CSS/JavaScript**, **C++**, **astro**, **python**, **react (react+vite)** e **nextjs base**.
9
+
10
+ Con un'interfaccia interattiva semplice e intuitiva, `creaprogetto` ti guida nella scelta del tipo di progetto da creare, generando per te una struttura di directory completa e pronta all’uso, comprensiva di file essenziali come `README.md`, `.gitignore`, `main.*` e cartelle organizzate per ogni linguaggio.
11
+
12
+ ---
13
+
14
+ ## 🚀 Installazione
15
+
16
+ ### Installazione Globale
17
+
18
+ ```bash
19
+ npm install -g creaprogetto
20
+ ```
21
+
22
+ ### Installazione Locale
23
+
24
+ ```bash
25
+ npm install creaprogetto
26
+ ```
27
+
28
+ ---
29
+
30
+ ## 🧪 Utilizzo
31
+
32
+ ### Creazione di un nuovo progetto
33
+
34
+ ```bash
35
+ creaprogetto init <tipo>
36
+ ```
37
+
38
+ Dove `<tipo>` può essere uno dei seguenti:
39
+
40
+ - `java`
41
+ - `nodejs`
42
+ - `html`
43
+ - `cpp`
44
+ - `astro`
45
+ - `python`
46
+ - `react (react+vite)`
47
+ - `nextjs`
48
+
49
+ Esempio:
50
+
51
+ ```bash
52
+ creaprogetto init java
53
+ creaprogetto init nodejs
54
+ creaprogetto init html
55
+ creaprogetto init cpp
56
+ creaprogetto init astro
57
+ creaprogetto init python
58
+ creaprogetto init react
59
+ creaprogetto init nextjs
60
+ ```
61
+
62
+ ---
63
+
64
+ ## 👤 Autore
65
+
66
+ **Ciro Andrea Strazzullo**
67
+
68
+ - GitHub: [@strazzullociroandrea](https://github.com/strazzullociroandrea)
69
+ - LinkedIn: [Ciro Andrea Strazzullo](https://www.linkedin.com/in/ciro-strazzullo-8484a5339)
70
+
71
+ ---
72
+
73
+ ## ⭐️ Supporta il progetto ##
74
+
75
+ Se questo progetto ti è sembrato utile o vuoi dare delle opinioni non esitare a scrivermi!
76
+
77
+ ---
78
+
package/cli.js ADDED
@@ -0,0 +1,75 @@
1
+ #!/usr/bin/env node
2
+ const fs = require('fs');
3
+ const path = require('path');
4
+ const args = process.argv.slice(2);
5
+
6
+ /**
7
+ * Show the version of the application.
8
+ */
9
+ if (args.includes('--version') || args.includes('-v')) {
10
+ try {
11
+ const packageJsonPath = path.join(__dirname, '..', 'package.json');
12
+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
13
+ console.log(`Version: ${packageJson.version}`);
14
+ } catch (e) {
15
+ console.error('Unable to read version from package.json');
16
+ }
17
+ process.exit(0);
18
+ }
19
+
20
+ /**
21
+ * Show the possibile type of project that you can initialize.
22
+ */
23
+ if (args.includes('--help') || args.includes('-h')) {
24
+ try {
25
+ const projects = ['Java', 'Nodejs', 'HTML', 'C++', 'Astro', 'Python', 'React', 'NextJs'];
26
+ console.log(`Available projects: ${projects.join(', ')}`);
27
+ console.log('\nUsage: generateproj <project-type>');
28
+ } catch (e) {
29
+ console.error('Unable to display available project types.');
30
+ }
31
+ process.exit(0);
32
+ }
33
+
34
+ /**
35
+ * Argument check
36
+ */
37
+ if (args.length === 0) {
38
+ console.log('Usage: generateproj [nodejs|java|html|cpp|astro|python|react|nextjs]');
39
+ process.exit(1);
40
+ }
41
+
42
+ const projectType = args[1].toLowerCase();
43
+
44
+ switch (projectType) {
45
+ case 'nodejs':
46
+ require('./dist/Nodejs/nodejs')();
47
+ break;
48
+ case 'java':
49
+ require('./dist/Java/java')();
50
+ break;
51
+ case 'html':
52
+ require('./dist/HTML/html')();
53
+ break;
54
+ case 'cpp':
55
+ case 'c++':
56
+ case 'c':
57
+ require('./dist/Cpp/cpp')();
58
+ break;
59
+ case 'astro':
60
+ require('./dist/Astro/astro')();
61
+ break;
62
+ case 'python':
63
+ require('./dist/Python/python')();
64
+ break;
65
+ case 'react':
66
+ require('./dist/React/react')();
67
+ break;
68
+ case 'nextjs':
69
+ require('./dist/NextJS/next')();
70
+ break;
71
+ default:
72
+ console.log(`Unsupported project type: ${projectType}`);
73
+ console.log('Run "generateproj --help" to see all options.');
74
+ process.exit(1);
75
+ }
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env node
2
+
3
+ const {execSync} = require('child_process');
4
+
5
+ /**
6
+ * Function to create a new Astro project.
7
+ * @returns {Promise<void>} The result of the project creation.
8
+ */
9
+ const createAstroProject = async () => {
10
+ try {
11
+ execSync('npm create astro@latest', {stdio: 'inherit'});
12
+ } catch (err) {
13
+ console.error(`Error: Could not initialize your astro project. ${err.message}`);
14
+ process.exit(1);
15
+ }
16
+ }
17
+
18
+ module.exports = createAstroProject;
@@ -0,0 +1,78 @@
1
+ #!/usr/bin/env node
2
+ const fs = require('fs');
3
+ const path = require('path');
4
+ const askQuestion = require('../lib/askQuestion');
5
+ const gitIsAvailable = require('../lib/gitIsAvailable');
6
+
7
+ /**
8
+ * Function to create a new C++ project.
9
+ * @returns {Promise<void>} The result of the project creation.
10
+ */
11
+ const createCppProject = async () => {
12
+ try {
13
+ const baseDir = process.cwd();
14
+ let projectName;
15
+
16
+ while (!projectName || projectName.trim() === '') {
17
+ projectName = await askQuestion("Enter the project name: ");
18
+
19
+ if (!projectName.trim()) {
20
+ console.log("Error: Project name cannot be empty.");
21
+ }
22
+ }
23
+
24
+ console.log(`Initializing C++ project: ${projectName}...`);
25
+
26
+ const projectPath = path.join(baseDir, projectName);
27
+
28
+ if (fs.existsSync(projectPath)) {
29
+ console.error(`Error: The folder '${projectName}' already exists.`);
30
+ process.exit(1);
31
+ }
32
+
33
+ console.log(`Creating project folder: ${projectPath}`);
34
+ fs.mkdirSync(projectPath);
35
+ console.log(`Project folder created: ${projectPath}`);
36
+
37
+ console.log("Creating 'main.cpp' file.");
38
+ fs.writeFileSync(path.join(projectPath, 'main.cpp'), fs.readFileSync(path.join(__dirname, '.', 'templates', 'Main.txt'), 'utf8'));
39
+ console.log("Created 'main.cpp' file.");
40
+
41
+ console.log("Creating 'Makefile' file.");
42
+ fs.writeFileSync(path.join(projectPath, 'Makefile'), fs.readFileSync(path.join(__dirname, '.', 'templates', 'Makefile.txt'), 'utf8').replace("$projectName", projectName));
43
+ console.log("Created 'Makefile' file.");
44
+
45
+ const useGit = gitIsAvailable()
46
+ ? (await askQuestion("Initialize a Git repository? (y/n): ")).toLowerCase() === 'y'
47
+ : false;
48
+
49
+ if (useGit) {
50
+ console.log("Initializing local Git repository...");
51
+
52
+ try {
53
+ execSync("git init", {cwd: projectPath, stdio: 'ignore'});
54
+
55
+ const gitignorePath = path.join(projectPath, '.gitignore');
56
+ if (!fs.existsSync(gitignorePath))
57
+ fs.writeFileSync(gitignorePath, "");
58
+
59
+
60
+ const readmePath = path.join(projectPath, 'README.md');
61
+ if (!fs.existsSync(readmePath))
62
+ fs.writeFileSync(readmePath, "");
63
+
64
+ console.log("Local Git repository initialized successfully.");
65
+ } catch (error) {
66
+ console.error("Failed to initialize Git repository. Skipping...");
67
+ }
68
+ }
69
+
70
+ console.log(`C++ project '${projectName}' initialized successfully at ${projectPath}.`);
71
+
72
+ } catch (err) {
73
+ console.error(`Error: Could not initialize your HTML project. ${err.message}`);
74
+ process.exit(1);
75
+ }
76
+ }
77
+
78
+ module.exports = createCppProject;
@@ -0,0 +1,8 @@
1
+ #include <iostream>
2
+ using namespace std;
3
+
4
+ int main() {
5
+ cout << "Hello World!" << endl;
6
+ return 0;
7
+ }
8
+
@@ -0,0 +1,5 @@
1
+ all:
2
+ \tg++ -o $projectName main.cpp
3
+
4
+ clean:
5
+ \trm -f $projectName
@@ -0,0 +1,82 @@
1
+ #!/usr/bin/env node
2
+ const fs = require('fs');
3
+ const path = require('path');
4
+ const askQuestion = require('../lib/askQuestion');
5
+ const gitIsAvailable = require('../lib/gitIsAvailable');
6
+
7
+ /**
8
+ * Function to create a new HTML project.
9
+ * @returns {Promise<void>} The result of the project creation.
10
+ */
11
+ const createHtmlProject = async () => {
12
+ try {
13
+ const baseDir = process.cwd();
14
+ let projectName;
15
+
16
+ while (!projectName || projectName.trim() === '') {
17
+ projectName = await askQuestion("Enter the project name: ");
18
+
19
+ if (!projectName.trim()) {
20
+ console.log("Error: Project name cannot be empty.");
21
+ }
22
+ }
23
+
24
+ console.log(`Initializing HTML project: ${projectName}...`);
25
+ const projectPath = path.join(baseDir, projectName);
26
+
27
+ if (fs.existsSync(projectPath)) {
28
+ console.error(`Error: The folder '${projectName}' already exists.`);
29
+ process.exit(1);
30
+ }
31
+
32
+ console.log(`Creating project folder: ${projectPath}`);
33
+ fs.mkdirSync(projectPath);
34
+ console.log(`Project folder created: ${projectPath}`);
35
+
36
+
37
+ console.log("Creating 'index.html' file.");
38
+ fs.writeFileSync(path.join(projectPath, 'index.html'), fs.readFileSync(path.join(__dirname, '.', 'templates', 'index.txt'), 'utf8'));
39
+ console.log("Created 'index.html' file.");
40
+
41
+ console.log("Creating 'style.css' file.");
42
+ fs.writeFileSync(path.join(projectPath, 'style.css'), `/* CSS Styles for ${projectName} */`, 'utf8');
43
+ console.log("Created 'style.css' file.");
44
+
45
+ console.log("Creating 'script.js' file.");
46
+ fs.writeFileSync(path.join(projectPath, 'script.js'), `// JavaScript for ${projectName}\nconsole.log("Hello from ${projectName} script!");`, 'utf8');
47
+ console.log("Created 'script.js' file.");
48
+
49
+ const useGit = gitIsAvailable()
50
+ ? (await askQuestion("Initialize a Git repository? (y/n): ")).toLowerCase() === 'y'
51
+ : false;
52
+
53
+
54
+ if (useGit) {
55
+ console.log("Initializing local Git repository...");
56
+
57
+ try {
58
+ execSync("git init", {cwd: projectPath, stdio: 'ignore'});
59
+
60
+ const gitignorePath = path.join(projectPath, '.gitignore');
61
+ if (!fs.existsSync(gitignorePath))
62
+ fs.writeFileSync(gitignorePath, "");
63
+
64
+
65
+ const readmePath = path.join(projectPath, 'README.md');
66
+ if (!fs.existsSync(readmePath))
67
+ fs.writeFileSync(readmePath, "");
68
+
69
+ console.log("Local Git repository initialized successfully.");
70
+ } catch (error) {
71
+ console.error("Failed to initialize Git repository. Skipping...");
72
+ }
73
+ }
74
+ console.log(`HTML project '${projectName}' initialized successfully at ${projectPath}.`);
75
+
76
+ } catch (err) {
77
+ console.error(`Error: Could not initialize your HTML project. ${err.message}`);
78
+ process.exit(1);
79
+ }
80
+ }
81
+
82
+ module.exports = createHtmlProject;
@@ -0,0 +1,15 @@
1
+ <!DOCTYPE html>
2
+ <html lang="it">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Your project</title>
7
+ <link rel="stylesheet" href="style.css">
8
+ </head>
9
+ <body>
10
+ <div id="app">
11
+ <h1>Hello World!</h1>
12
+ </div>
13
+ <script src="script.js"></script>
14
+ </body>
15
+ </html>
@@ -0,0 +1,79 @@
1
+ #!/usr/bin/env node
2
+
3
+ const fs = require('fs');
4
+ const path = require('path');
5
+ const askQuestion = require('../lib/askQuestion');
6
+ const gitIsAvailable = require('../lib/gitIsAvailable');
7
+
8
+ /**
9
+ * Function to create a new Java project.
10
+ * @returns {Promise<void>} The result of the project creation.
11
+ */
12
+ const createJavaProject = async () => {
13
+ try {
14
+ const baseDir = process.cwd();
15
+ let projectName;
16
+
17
+ while (!projectName || projectName.trim() === '') {
18
+ projectName = await askQuestion("Enter the project name: ");
19
+
20
+ if (!projectName.trim()) {
21
+ console.log("Error: Project name cannot be empty.");
22
+ }
23
+ }
24
+
25
+ console.log(`Initializing Java project: ${projectName}...`);
26
+
27
+ const projectPath = path.join(baseDir, projectName);
28
+
29
+ if (fs.existsSync(projectPath)) {
30
+ console.error(`Error: The folder '${projectName}' already exists.`);
31
+ process.exit(1);
32
+ }
33
+
34
+ console.log(`Creating project folder: ${projectPath}`);
35
+ fs.mkdirSync(projectPath);
36
+ console.log(`Project folder created: ${projectPath}`);
37
+
38
+
39
+ console.log("Creating 'src' folder.");
40
+ fs.mkdirSync(path.join(projectPath, 'src'), {recursive: true});
41
+ console.log("Created 'src' folder.");
42
+
43
+ console.log("Creating 'Main.java' file.");
44
+ fs.writeFileSync(path.join(projectPath, 'src', 'Main.java'), fs.readFileSync(path.join(__dirname, '.', 'templates', 'Main.txt'), 'utf8'));
45
+ console.log("Created 'Main.java' file.");
46
+
47
+ const useGit = gitIsAvailable()
48
+ ? (await askQuestion("Initialize a Git repository? (y/n): ")).toLowerCase() === 'y'
49
+ : false;
50
+
51
+ if (useGit) {
52
+ console.log("Initializing local Git repository...");
53
+
54
+ try {
55
+ execSync("git init", {cwd: projectPath, stdio: 'ignore'});
56
+
57
+ const gitignorePath = path.join(projectPath, '.gitignore');
58
+ if (!fs.existsSync(gitignorePath))
59
+ fs.writeFileSync(gitignorePath, "");
60
+
61
+
62
+ const readmePath = path.join(projectPath, 'README.md');
63
+ if (!fs.existsSync(readmePath))
64
+ fs.writeFileSync(readmePath, "");
65
+
66
+ console.log("Local Git repository initialized successfully.");
67
+ } catch (error) {
68
+ console.error("Failed to initialize Git repository. Skipping...");
69
+ }
70
+ }
71
+
72
+ console.log(`Java project '${projectName}' initialized successfully at ${projectPath}.`);
73
+
74
+
75
+ } catch (err) {
76
+ console.error(`Error: Could not initialize your Java project. ${err.message}`);
77
+ process.exit(1);
78
+ }
79
+ }
@@ -0,0 +1,5 @@
1
+ public class Main {
2
+ public static void main(String[] args) {
3
+ System.out.println("Hello World!");
4
+ }
5
+ }
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env node
2
+ const fs = require('fs');
3
+ const path = require('path');
4
+ const askQuestion = require('../lib/askQuestion');
5
+ const gitIsAvailable = require('../lib/gitIsAvailable');
6
+ const {execSync} = require('child_process');
7
+
8
+ /**
9
+ * Function to create a new NextJs project.
10
+ * @returns {Promise<void>} The result of the project creation.
11
+ */
12
+ const createHtmlProject = async () => {
13
+ try {
14
+
15
+ try {
16
+ execSync("npx -v", {stdio: 'ignore'});
17
+ } catch {
18
+ execSync("npx install -g npx", {stdio: 'ignore'});
19
+ try {
20
+ execSync("npx -v", {stdio: 'ignore'});
21
+ } catch (e) {
22
+ console.log("npx: package not found")
23
+ }
24
+ }
25
+
26
+ console.log("Initializing NextJs project...");
27
+ execSync('npx create-next-app@latest --src-dir', {stdio: 'inherit'});
28
+ console.log("NextJs project initialized successfully.");
29
+
30
+ } catch (err) {
31
+ console.error(`Error: Could not initialize your NextJs project. ${err.message}`);
32
+ process.exit(1);
33
+ }
34
+ }
35
+
36
+ module.exports = createHtmlProject;
@@ -0,0 +1,113 @@
1
+ #!/usr/bin/env node
2
+ const fs = require('fs');
3
+ const path = require('path');
4
+ const askQuestion = require('../lib/askQuestion');
5
+ const gitIsAvailable = require('../lib/gitIsAvailable');
6
+ const {execSync} = require('child_process');
7
+
8
+ /**
9
+ * Function to create a new C++ project.
10
+ * @returns {Promise<void>} The result of the project creation.
11
+ */
12
+ const createNodejsProject = async () => {
13
+ try {
14
+ const baseDir = process.cwd();
15
+ let projectName;
16
+
17
+ while (!projectName || projectName.trim() === '') {
18
+ projectName = await askQuestion("Enter the project name: ");
19
+
20
+ if (!projectName.trim()) {
21
+ console.log("Error: Project name cannot be empty.");
22
+ }
23
+ }
24
+
25
+ console.log(`Initializing Nodejs project: ${projectName}...`);
26
+
27
+ let type = '';
28
+ while (type !== 'module' && type !== 'commonjs') {
29
+ type = (await askQuestion("Select module type (module/commonjs): ")).toLowerCase();
30
+
31
+ if (type !== 'module' && type !== 'commonjs') {
32
+ console.log("Error: Please enter 'module' or 'commonjs'.");
33
+ }
34
+ }
35
+
36
+ const projectPath = path.join(baseDir, projectName);
37
+
38
+ if (fs.existsSync(projectPath)) {
39
+ console.error(`Error: The folder '${projectName}' already exists.`);
40
+ process.exit(1);
41
+ }
42
+
43
+ console.log(`Creating project folder: ${projectPath}`);
44
+ fs.mkdirSync(projectPath);
45
+ console.log(`Project folder created: ${projectPath}`);
46
+
47
+ console.log("Initializing nodejs project...");
48
+ execSync(`npm init -y`, {cwd: projectPath, stdio: 'ignore'});
49
+
50
+ console.log("Installing minimal dependencies...");
51
+ execSync(`npm install dotenv express path body-parser`, {cwd: projectPath, stdio: 'ignore'});
52
+
53
+ if (type == 'module') {
54
+ execSync(`npm install url`, {cwd: projectPath, stdio: 'ignore'});
55
+ const packageJsonPath = path.join(projectPath, 'package.json');
56
+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
57
+ packageJson.type = "module";
58
+ fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
59
+ }
60
+
61
+ console.log("All minimal dependencies installed.");
62
+
63
+ console.log("Creating 'index.js' file.");
64
+ fs.writeFileSync(path.join(projectPath, 'index.js'), fs.readFileSync(path.join(__dirname, '.', 'templates', type == "module" ? "serverImport.txt" : "serverRequire.txt"), 'utf8'));
65
+ console.log("Created 'index.js' file.");
66
+
67
+ console.log("Creating 'public' folder.");
68
+ fs.mkdirSync(path.join(projectPath, 'public'));
69
+ console.log("Created 'public' folder.");
70
+
71
+ console.log("Creating 'html-public' file.");
72
+ fs.writeFileSync(path.join(path.join(projectPath, 'public'), 'index.html'), fs.readFileSync(path.join(__dirname, '.', 'templates', 'html-base.txt'), 'utf8'));
73
+ console.log("Created 'index.html' file.");
74
+
75
+ console.log("Creating '.env' file.");
76
+ fs.writeFileSync(path.join(projectPath, '.env'), fs.readFileSync(path.join(__dirname, '.', 'templates', '.env.txt'), 'utf8'));
77
+ console.log("Created '.env' file.");
78
+
79
+ const useGit = gitIsAvailable()
80
+ ? (await askQuestion("Initialize a Git repository? (y/n): ")).toLowerCase() === 'y'
81
+ : false;
82
+
83
+ if (useGit) {
84
+ console.log("Initializing local Git repository...");
85
+
86
+ try {
87
+ execSync("git init", {cwd: projectPath, stdio: 'ignore'});
88
+
89
+ const gitignorePath = path.join(projectPath, '.gitignore');
90
+ if (!fs.existsSync(gitignorePath))
91
+ fs.writeFileSync(gitignorePath, "");
92
+
93
+
94
+ const readmePath = path.join(projectPath, 'README.md');
95
+ if (!fs.existsSync(readmePath))
96
+ fs.writeFileSync(readmePath, "");
97
+
98
+ console.log("Local Git repository initialized successfully.");
99
+ } catch (error) {
100
+ console.error("Failed to initialize Git repository. Skipping...");
101
+ }
102
+ }
103
+
104
+ console.log(`Nodejs project '${projectName}' initialized successfully at ${projectPath}.`);
105
+
106
+
107
+ } catch (err) {
108
+ console.error(`Error: Could not initialize your Nodejs project. ${err.message}`);
109
+ process.exit(1);
110
+ }
111
+ }
112
+
113
+ module.exports = createNodejsProject;
@@ -0,0 +1 @@
1
+ PORT=3000
@@ -0,0 +1,9 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Base</title>
5
+ </head>
6
+ <body>
7
+ <h2> Server is running correctly! </h2>
8
+ </body>
9
+ </html>
@@ -0,0 +1,34 @@
1
+ require('dotenv').config();
2
+ import express from 'express';
3
+ import http from 'http';
4
+ import path from 'path';
5
+ import bodyParser from 'body-parser';
6
+ import fs from 'fs';
7
+ import { dirname } from 'path';
8
+ import { fileURLToPath } from 'url';
9
+ const __filename = fileURLToPath(import.meta.url);
10
+ const __dirname = dirname(__filename);
11
+ const app = express();
12
+ const server = http.createServer(app);
13
+
14
+
15
+ (()=>{
16
+ try{
17
+ app.use(bodyParser.json());
18
+
19
+ app.use(
20
+ bodyParser.urlencoded({
21
+ extended: true,
22
+ })
23
+ );
24
+
25
+ app.use("/", express.static(path.join(__dirname, "public")));
26
+
27
+ server.listen(process.env.PORT, () => {
28
+ console.log("---> server running on http://localhost:" + process.env.PORT);
29
+ });
30
+
31
+ }catch(error){
32
+ console.error(error);
33
+ }
34
+ })();
@@ -0,0 +1,29 @@
1
+ require('dotenv').config();
2
+ const express = require('express');
3
+ const http = require('http');
4
+ const path = require('path');
5
+ const bodyParser = require('body-parser');
6
+ const app = express();
7
+ const server = http.createServer(app);
8
+
9
+
10
+ (() => {
11
+ try {
12
+ app.use(bodyParser.json());
13
+
14
+ app.use(
15
+ bodyParser.urlencoded({
16
+ extended: true,
17
+ })
18
+ );
19
+
20
+ app.use("/", express.static(path.join(__dirname, "public")));
21
+
22
+ server.listen(process.env.PORT, () => {
23
+ console.log("---> server running on http://localhost:" + process.env.PORT);
24
+ });
25
+
26
+ } catch (error) {
27
+ console.error(error);
28
+ }
29
+ })();
@@ -0,0 +1,78 @@
1
+ #!/usr/bin/env node
2
+
3
+ const fs = require('fs');
4
+ const path = require('path');
5
+ const askQuestion = require('../lib/askQuestion');
6
+ const gitIsAvailable = require('../lib/gitIsAvailable');
7
+
8
+ /**
9
+ * Function to create a new Python project.
10
+ * @returns {Promise<void>} The result of the project creation.
11
+ */
12
+ const createPythonProject = async () => {
13
+ try {
14
+ const baseDir = process.cwd();
15
+ let projectName;
16
+
17
+ while (!projectName || projectName.trim() === '') {
18
+ projectName = await askQuestion("Enter the project name: ");
19
+
20
+ if (!projectName.trim()) {
21
+ console.log("Error: Project name cannot be empty.");
22
+ }
23
+ }
24
+
25
+ console.log(`Initializing Python project: ${projectName}...`);
26
+
27
+ const projectPath = path.join(baseDir, projectName);
28
+
29
+ if (fs.existsSync(projectPath)) {
30
+ console.error(`Error: The folder '${projectName}' already exists.`);
31
+ process.exit(1);
32
+ }
33
+
34
+ console.log(`Creating project folder: ${projectPath}`);
35
+ fs.mkdirSync(projectPath);
36
+ console.log(`Project folder created: ${projectPath}`);
37
+
38
+ console.log("Creating 'main.py' file.");
39
+ fs.writeFileSync(path.join(projectPath, 'main.py'), fs.readFileSync(path.join(__dirname, '.', 'templates', 'Main.txt'), 'utf8'));
40
+ console.log("Created 'main.py' file.");
41
+
42
+ console.log("Creating 'requirements.txt' file.");
43
+ fs.writeFileSync(path.join(projectPath, 'requirements.txt'), '');
44
+ console.log("Created 'requirements.txt' file.");
45
+
46
+ const useGit = gitIsAvailable()
47
+ ? (await askQuestion("Initialize a Git repository? (y/n): ")).toLowerCase() === 'y'
48
+ : false;
49
+
50
+ if (useGit) {
51
+ console.log("Initializing local Git repository...");
52
+
53
+ try {
54
+ execSync("git init", {cwd: projectPath, stdio: 'ignore'});
55
+
56
+ const gitignorePath = path.join(projectPath, '.gitignore');
57
+ if (!fs.existsSync(gitignorePath))
58
+ fs.writeFileSync(gitignorePath, "");
59
+
60
+
61
+ const readmePath = path.join(projectPath, 'README.md');
62
+ if (!fs.existsSync(readmePath))
63
+ fs.writeFileSync(readmePath, "");
64
+
65
+ console.log("Local Git repository initialized successfully.");
66
+ } catch (error) {
67
+ console.error("Failed to initialize Git repository. Skipping...");
68
+ }
69
+ }
70
+
71
+ console.log(`Python project '${projectName}' initialized successfully at ${projectPath}.`);
72
+ } catch (err) {
73
+ console.error(`Error: Could not initialize your Python project. ${err.message}`);
74
+ process.exit(1);
75
+ }
76
+ }
77
+
78
+ module.exports = createPythonProject;
@@ -0,0 +1,5 @@
1
+ def greet():
2
+ print("Hello world")
3
+
4
+ if __name__ == "__main__":
5
+ greet()
@@ -0,0 +1,58 @@
1
+ #!/usr/bin/env node
2
+ const {execSync} = require('child_process');
3
+ const fs = require('fs');
4
+ const path = require('path');
5
+ const askQuestion = require('../lib/askQuestion');
6
+ const gitIsAvailable = require('../lib/gitIsAvailable');
7
+
8
+ /**
9
+ * Function to create a new React + Vite project.
10
+ * @returns {Promise<void>} The result of the project creation.
11
+ */
12
+ const createReactViteProject = async () => {
13
+ try {
14
+ const baseDir = process.cwd();
15
+ let projectName;
16
+
17
+ while (!projectName || projectName.trim() === '') {
18
+ projectName = await askQuestion("Enter the project name: ");
19
+
20
+ if (!projectName.trim()) {
21
+ console.log("Error: Project name cannot be empty.");
22
+ }
23
+ }
24
+
25
+
26
+ execSync(`npm create vite@latest ${projectName} -- --template react`, {stdio: 'inherit'});
27
+ const useGit = gitIsAvailable()
28
+ ? (await askQuestion("Initialize a Git repository? (y/n): ")).toLowerCase() === 'y'
29
+ : false;
30
+
31
+ if (useGit) {
32
+ console.log("Initializing local Git repository...");
33
+ const projectPath = path.join(baseDir, projectName);
34
+
35
+ try {
36
+ execSync("git init", {cwd: projectPath, stdio: 'ignore'});
37
+
38
+ const gitignorePath = path.join(projectPath, '.gitignore');
39
+ if (!fs.existsSync(gitignorePath))
40
+ fs.writeFileSync(gitignorePath, "");
41
+
42
+
43
+ const readmePath = path.join(projectPath, 'README.md');
44
+ if (!fs.existsSync(readmePath))
45
+ fs.writeFileSync(readmePath, "");
46
+
47
+ console.log("Local Git repository initialized successfully.");
48
+ } catch (error) {
49
+ console.error("Failed to initialize Git repository. Skipping...");
50
+ }
51
+ }
52
+ } catch (err) {
53
+ console.error(`Error: Could not initialize your React + Vite project. ${err.message}`);
54
+ process.exit(1);
55
+ }
56
+ }
57
+
58
+ module.exports = createReactViteProject;
@@ -0,0 +1,22 @@
1
+ const readline = require('readline');
2
+
3
+ /**
4
+ * Function to ask a question to the user via command line.
5
+ * @param quest {string} The question to ask the user.
6
+ * @returns {Promise<unknown>} The user's answer.
7
+ */
8
+ const askQuestion = (quest) => {
9
+ const rl = readline.createInterface({
10
+ input: process.stdin,
11
+ output: process.stdout,
12
+ });
13
+
14
+ return new Promise((resolve) => {
15
+ rl.question(quest, (answer) => {
16
+ rl.close();
17
+ resolve(answer.trim());
18
+ });
19
+ });
20
+ }
21
+
22
+ module.exports = askQuestion;
@@ -0,0 +1,16 @@
1
+ const {execSync} = require('child_process');
2
+
3
+ /**
4
+ * Is Git available on the system?
5
+ * @returns {boolean} True if Git is available, false otherwise.
6
+ */
7
+
8
+ const gitIsAvailable = async () => {
9
+ try {
10
+ execSync("git --version", {stdio: 'ignore'});
11
+ return true;
12
+ } catch {
13
+ return false;
14
+ }
15
+ }
16
+ module.exports = gitIsAvailable;
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "generateproj",
3
+ "version": "1.0.0",
4
+ "main": "cli.js",
5
+ "scripts": {
6
+ "test": "echo \"Error: no test specified\" && exit 1"
7
+ },
8
+ "author": "Strazzullo Ciro Andrea",
9
+ "license": "ISC",
10
+ "description": "A simple CLI tool to create basic and useful projects in various programming languages.",
11
+ "bin": {
12
+ "generateproj": "cli.js"
13
+ },
14
+ "dependencies": {
15
+ "child_process": "^1.0.2",
16
+ "https": "^1.0.0",
17
+ "path": "^0.12.7",
18
+ "readline": "^1.3.0",
19
+ "util": "^0.12.5"
20
+ },
21
+ "keywords": [
22
+ "Create starter projects",
23
+ "Utils",
24
+ "Project generator",
25
+ "Create projects",
26
+ "Cli",
27
+ "Starter",
28
+ "Java",
29
+ "Nodejs",
30
+ "HTML",
31
+ "C++",
32
+ "Astro",
33
+ "Python",
34
+ "React + Vite",
35
+ "NextJs"
36
+ ]
37
+ }