a-a-node 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,114 @@
1
+ # NPM Package Workflow Guide
2
+
3
+ This repository contains commonly used commands for creating, testing, and publishing an npm package.
4
+
5
+ ---
6
+
7
+ ## Initialize NPM Project
8
+
9
+ ```bash
10
+ npm init
11
+ ```
12
+
13
+ ---
14
+
15
+ ## NPM Authentication
16
+
17
+ ### Login to NPM
18
+
19
+ ```bash
20
+ npm login
21
+ ```
22
+
23
+ ### Logout from NPM
24
+
25
+ ```bash
26
+ npm logout
27
+ ```
28
+
29
+ ---
30
+
31
+ ## Local Package Linking (For Testing)
32
+
33
+ Use this to test your npm package locally before publishing.
34
+
35
+ ### Link Package Locally
36
+
37
+ ```bash
38
+ npm link
39
+ ```
40
+
41
+ ### Unlink Package Locally
42
+
43
+ ```bash
44
+ npm unlink -g <package-name>
45
+ ```
46
+
47
+ ---
48
+
49
+ ## Publishing NPM Package
50
+
51
+ ### Publish Without 2FA
52
+
53
+ ```bash
54
+ npm publish --access public
55
+ ```
56
+
57
+ ### Standard Publish
58
+
59
+ ```bash
60
+ npm publish
61
+ ```
62
+
63
+ ---
64
+
65
+ ## Update NPM Package
66
+
67
+ Increase patch version and publish:
68
+
69
+ ```bash
70
+ npm version patch
71
+ npm publish --access public
72
+ ```
73
+
74
+ Other version options:
75
+
76
+ - `npm version minor`
77
+ - `npm version major`
78
+
79
+ ---
80
+
81
+ ## Package Information
82
+
83
+ ### Check if Package Already Exists
84
+
85
+ ```bash
86
+ npm view <package-name>
87
+ ```
88
+
89
+ ### Check Package Owner
90
+
91
+ ```bash
92
+ npm owner ls <package-name>
93
+ ```
94
+
95
+ ---
96
+
97
+ ## Bypass 2FA Using NPM Token
98
+
99
+ Configure npm authentication token (useful for CI/CD):
100
+
101
+ ```bash
102
+ npm config set //registry.npmjs.org/:_authToken=<YOUR_NPM_TOKEN>
103
+ ```
104
+
105
+ ⚠️ **Important:** Never commit your npm token to source control.
106
+
107
+ ---
108
+
109
+ ## Notes
110
+
111
+ - Always update the version before publishing
112
+ - Test locally using `npm link`
113
+ - Ensure package name is unique
114
+ - Enable 2FA for better security
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: a-a-node <project-name>");
10
+ process.exit(1);
11
+ }
12
+
13
+ createProject(projectName);
package/lib/index.js ADDED
@@ -0,0 +1,107 @@
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
+ console.log(chalk.blue(`\n🚀 Creating project "${projectName}"...\n`));
13
+ console.log(
14
+ chalk.gray(`Platform: ${os.platform()} | Node: ${process.version}\n`),
15
+ );
16
+
17
+ // Check if template exists
18
+ if (!fs.existsSync(templatePath)) {
19
+ console.error(
20
+ chalk.red(`❌ Template directory not found at: ${templatePath}`),
21
+ );
22
+ process.exit(1);
23
+ }
24
+
25
+ // Check if directory already exists
26
+ if (fs.existsSync(targetPath)) {
27
+ console.error(chalk.red(`❌ Directory "${projectName}" already exists!`));
28
+ process.exit(1);
29
+ }
30
+
31
+ try {
32
+ // Step 1: Copy template files
33
+ // const copySpinner = ora("Copying template files...").start();
34
+ await fs.copy(templatePath, targetPath, {
35
+ filter: (src) => {
36
+ // Get the relative path from template
37
+ const relativePath = path.relative(templatePath, src);
38
+
39
+ // Always include the root template directory
40
+ if (relativePath === "") {
41
+ return true;
42
+ }
43
+
44
+ // Exclude specific files/folders
45
+ const excludes = ["node_modules", ".git", "dist", "build", ".env"];
46
+ const baseName = path.basename(src);
47
+
48
+ // Check if any exclude pattern matches
49
+ return !excludes.includes(baseName);
50
+ },
51
+ });
52
+ // copySpinner.succeed(chalk.green("Template files copied successfully!"));
53
+
54
+ // Step 2: Update package.json with project name
55
+ // const updateSpinner = ora("Updating package.json...").start();
56
+ const packageJsonPath = path.join(targetPath, "package.json");
57
+
58
+ if (fs.existsSync(packageJsonPath)) {
59
+ const packageJson = await fs.readJson(packageJsonPath);
60
+ packageJson.name = projectName;
61
+ await fs.writeJson(packageJsonPath, packageJson, { spaces: 2 });
62
+ // updateSpinner.succeed(chalk.green("package.json updated!"));
63
+ } else {
64
+ updateSpinner.warn(chalk.yellow("No package.json found in template"));
65
+ }
66
+
67
+ // Step 3: Create .env from .env.example if exists
68
+ const envExamplePath = path.join(targetPath, ".env.example");
69
+ const envPath = path.join(targetPath, ".env");
70
+
71
+ if (fs.existsSync(envExamplePath) && !fs.existsSync(envPath)) {
72
+ await fs.copy(envExamplePath, envPath);
73
+ // console.log(chalk.green("\n✓ .env file created from .env.example"));
74
+ }
75
+
76
+ // Step 4: Initialize git (optional)
77
+ // const gitSpinner = ora("Initializing git repository...").start();
78
+ // try {
79
+ // execSync("git init", {
80
+ // cwd: targetPath,
81
+ // stdio: "ignore",
82
+ // });
83
+ // // gitSpinner.succeed(chalk.green("Git repository initialized!"));
84
+ // } catch (error) {
85
+ // // gitSpinner.warn(chalk.yellow("Git not found or initialization skipped"));
86
+ // }
87
+
88
+ // Success message
89
+ console.log(chalk.green.bold("\n✨ Project created successfully!\n"));
90
+ // console.log(chalk.cyan("To get started, run:\n"));
91
+ // console.log(chalk.white(` cd ${projectName}`));
92
+ // console.log(chalk.white(` npm install`));
93
+ // console.log(chalk.white(` npm run dev\n`));
94
+ } catch (error) {
95
+ console.error(chalk.red("\n❌ Error creating project:"), error.message);
96
+
97
+ // Cleanup on error
98
+ if (fs.existsSync(targetPath)) {
99
+ console.log(chalk.yellow("Cleaning up..."));
100
+ await fs.remove(targetPath);
101
+ }
102
+
103
+ process.exit(1);
104
+ }
105
+ }
106
+
107
+ module.exports = { createProject };
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "a-a-node",
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
+ "a-a-node": "bin/cli.js"
8
+ },
9
+ "files": [
10
+ "bin",
11
+ "lib",
12
+ "template"
13
+ ],
14
+ "scripts": {
15
+ "test": "echo \"No tests specified\"",
16
+ "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){}\""
17
+ },
18
+ "keywords": [
19
+ "nodejs",
20
+ "boilerplate",
21
+ "cli",
22
+ "scaffold",
23
+ "template",
24
+ "typescript",
25
+ "express",
26
+ "cross-platform"
27
+ ],
28
+ "author": "Your Name",
29
+ "license": "MIT",
30
+ "dependencies": {
31
+ "chalk": "^4.1.2",
32
+ "fs-extra": "^11.1.1",
33
+ "ora": "^5.4.1"
34
+ },
35
+ "engines": {
36
+ "node": ">=14.0.0"
37
+ },
38
+ "os": [
39
+ "darwin",
40
+ "linux",
41
+ "win32"
42
+ ]
43
+ }
@@ -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://localhost:27017/sagar-pratical
3
+ JWT_SECRET=JWT_SECRET
4
+ JWT_EXPIRE=7d
5
+ JWT_REFRESH_EXPIRE=7d