sk-test-node-deploy 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/bin/cli.js ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env node
2
+
3
+ const { createProject } = require("../lib/index");
4
+
5
+ const projectName = process.argv[2];
6
+
7
+ if (!projectName) {
8
+ console.error("āŒ Please provide a project name");
9
+ console.log("Usage: sk-test-node-deploy <project-name>");
10
+ process.exit(1);
11
+ }
12
+
13
+ createProject(projectName);
package/lib/index.js ADDED
@@ -0,0 +1,134 @@
1
+ const fs = require("fs-extra");
2
+ const path = require("path");
3
+ const { execSync } = require("child_process");
4
+ const chalk = require("chalk");
5
+ const ora = require("ora");
6
+ const os = require("os");
7
+
8
+ async function createProject(projectName) {
9
+ const targetPath = path.join(process.cwd(), projectName);
10
+ const templatePath = path.join(__dirname, "../template");
11
+
12
+ // Check if directory already exists
13
+ if (fs.existsSync(targetPath)) {
14
+ console.error(chalk.red(`āŒ Directory "${projectName}" already exists!`));
15
+ process.exit(1);
16
+ }
17
+
18
+ console.log(chalk.blue(`\nšŸš€ Creating project "${projectName}"...\n`));
19
+ console.log(
20
+ chalk.gray(`Platform: ${os.platform()} | Node: ${process.version}\n`),
21
+ );
22
+
23
+ try {
24
+ // Step 1: Copy template files
25
+ const copySpinner = ora("Copying template files...").start();
26
+ await fs.copy(templatePath, targetPath, {
27
+ filter: (src) => {
28
+ // Exclude unwanted files/folders
29
+ const excludes = ["node_modules", ".git", "dist", "build", ".env"];
30
+ return !excludes.some((exclude) => src.includes(exclude));
31
+ },
32
+ });
33
+ copySpinner.succeed(chalk.green("Template files copied successfully!"));
34
+
35
+ // Step 2: Update package.json with project name
36
+ const updateSpinner = ora("Updating package.json...").start();
37
+ const packageJsonPath = path.join(targetPath, "package.json");
38
+
39
+ if (fs.existsSync(packageJsonPath)) {
40
+ const packageJson = await fs.readJson(packageJsonPath);
41
+ packageJson.name = projectName;
42
+ await fs.writeJson(packageJsonPath, packageJson, { spaces: 2 });
43
+ updateSpinner.succeed(chalk.green("package.json updated!"));
44
+ } else {
45
+ updateSpinner.warn(chalk.yellow("No package.json found in template"));
46
+ }
47
+
48
+ // Step 3: Detect package manager
49
+ const packageManager = detectPackageManager();
50
+ console.log(chalk.gray(`Using package manager: ${packageManager}\n`));
51
+
52
+ // Step 4: Install production dependencies (REMOVED csv-parser)
53
+ console.log(chalk.blue("šŸ“¦ Installing dependencies...\n"));
54
+ const installSpinner = ora("Installing production dependencies...").start();
55
+
56
+ try {
57
+ const prodCmd = `${packageManager} ${packageManager === "npm" ? "install" : "add"} bcryptjs compression cors dotenv express helmet joi jsonwebtoken mongoose socket.io multer`;
58
+ execSync(prodCmd, {
59
+ cwd: targetPath,
60
+ stdio: "inherit",
61
+ shell: true,
62
+ });
63
+ installSpinner.succeed(chalk.green("Production dependencies installed!"));
64
+ } catch (error) {
65
+ installSpinner.fail(
66
+ chalk.red("Failed to install production dependencies"),
67
+ );
68
+ throw error;
69
+ }
70
+
71
+ // Step 5: Install dev dependencies (NO csv-parser types)
72
+ const devInstallSpinner = ora("Installing dev dependencies...").start();
73
+
74
+ try {
75
+ const devCmd = `${packageManager} ${packageManager === "npm" ? "install -D" : "add -D"} typescript ts-node @types/node @types/express @types/bcryptjs @types/compression @types/cors @types/jsonwebtoken @types/mongoose @types/socket.io @types/multer nodemon`;
76
+ execSync(devCmd, {
77
+ cwd: targetPath,
78
+ stdio: "inherit",
79
+ shell: true,
80
+ });
81
+ devInstallSpinner.succeed(chalk.green("Dev dependencies installed!"));
82
+ } catch (error) {
83
+ devInstallSpinner.fail(chalk.red("Failed to install dev dependencies"));
84
+ throw error;
85
+ }
86
+
87
+ // Step 6: Initialize git (optional)
88
+ const gitSpinner = ora("Initializing git repository...").start();
89
+ try {
90
+ execSync("git --version", { stdio: "ignore", shell: true });
91
+ execSync("git init", { cwd: targetPath, stdio: "ignore", shell: true });
92
+ gitSpinner.succeed(chalk.green("Git repository initialized!"));
93
+ } catch (error) {
94
+ gitSpinner.warn(chalk.yellow("Git not found or initialization skipped"));
95
+ }
96
+
97
+ // Step 7: Create .env from .env.example if exists
98
+ const envExamplePath = path.join(targetPath, ".env.example");
99
+ const envPath = path.join(targetPath, ".env");
100
+
101
+ if (fs.existsSync(envExamplePath) && !fs.existsSync(envPath)) {
102
+ await fs.copy(envExamplePath, envPath);
103
+ console.log(chalk.green("āœ“ .env file created from .env.example"));
104
+ }
105
+
106
+ // Success message
107
+ console.log(chalk.green.bold("\n✨ Project created successfully!\n"));
108
+ console.log(chalk.cyan("To get started, run:"));
109
+ console.log(chalk.white(` cd ${projectName}`));
110
+ console.log(chalk.white(" npm run dev\n"));
111
+ } catch (error) {
112
+ console.error(chalk.red("\nāŒ Error creating project:"), error.message);
113
+
114
+ // Cleanup on error
115
+ if (fs.existsSync(targetPath)) {
116
+ console.log(chalk.yellow("Cleaning up..."));
117
+ await fs.remove(targetPath);
118
+ }
119
+
120
+ process.exit(1);
121
+ }
122
+ }
123
+
124
+ // Detect which package manager is available
125
+ function detectPackageManager() {
126
+ try {
127
+ execSync("yarn --version", { stdio: "ignore", shell: true });
128
+ return "yarn";
129
+ } catch {
130
+ return "npm";
131
+ }
132
+ }
133
+
134
+ module.exports = { createProject };
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "sk-test-node-deploy",
3
+ "version": "1.0.0",
4
+ "description": "CLI tool to quickly scaffold a Node.js boilerplate project",
5
+ "main": "lib/index.js",
6
+ "bin": {
7
+ "sk-test-node-deploy": "bin/cli.js"
8
+ },
9
+ "scripts": {
10
+ "test": "echo \"No tests specified\"",
11
+ "postinstall": "node -e \"try{const fs=require('fs');const path=require('path');const binPath=path.join(__dirname,'bin','cli.js');if(fs.existsSync(binPath)){fs.chmodSync(binPath,0o755);}}catch(e){}\""
12
+ },
13
+ "keywords": [
14
+ "nodejs",
15
+ "boilerplate",
16
+ "cli",
17
+ "scaffold",
18
+ "template",
19
+ "typescript",
20
+ "express",
21
+ "cross-platform"
22
+ ],
23
+ "author": "Your Name",
24
+ "license": "MIT",
25
+ "dependencies": {
26
+ "chalk": "^4.1.2",
27
+ "fs-extra": "^11.1.1",
28
+ "ora": "^5.4.1"
29
+ },
30
+ "engines": {
31
+ "node": ">=14.0.0"
32
+ },
33
+ "os": [
34
+ "darwin",
35
+ "linux",
36
+ "win32"
37
+ ]
38
+ }
@@ -0,0 +1,25 @@
1
+ name: Deploy to staging
2
+
3
+ on:
4
+ workflow_dispatch:
5
+ pull_request:
6
+ types:
7
+ - closed
8
+ branches:
9
+ - staging
10
+
11
+ jobs:
12
+ deploy:
13
+ timeout-minutes: 10
14
+ if: github.event.pull_request.merged == true
15
+ runs-on: ubuntu-latest
16
+ steps:
17
+ - name: Deploy to Staging
18
+ id: deploy
19
+ continue-on-error: true
20
+ uses: fifsky/ssh-action@master
21
+ with:
22
+ host: ${{ secrets.STAGING_SERVER }}
23
+ user: ${{ secrets.STAGING_USER }}
24
+ key: ${{ secrets.STAGING_PRIVATE_KEY }}
25
+ command: bash -i -c 'cd /home/ubuntu/Project-Backend && git checkout package-lock.json && git pull && npm i && npm run migrate && npm run build && pm2 restart all'
@@ -0,0 +1,3 @@
1
+ npm install bcryptjs compression cors dotenv express helmet joi jsonwebtoken mongoose socket.io multer
2
+
3
+ npm install -D typescript ts-node @types/node @types/express @types/bcryptjs @types/compression @types/cors @types/jsonwebtoken @types/mongoose @types/socket.io @types/multer nodemon
@@ -0,0 +1,5 @@
1
+ PORT=3000
2
+ MONGODB_URI=mongodb+srv://sagarkgohil123_db_user:mZGkApCGe3OZmsAl@boilerplate.tlhtdp2.mongodb.net/?appName=BoilerPlate
3
+ JWT_SECRET=JWT_SECRET
4
+ JWT_EXPIRE=7d
5
+ JWT_REFRESH_EXPIRE=7d