create-dacosta-proj 1.0.19 → 1.0.21

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-dacosta-proj",
3
- "version": "1.0.19",
3
+ "version": "1.0.21",
4
4
  "bin": {
5
5
  "create-dacosta-proj": "./index.js"
6
6
  }
@@ -0,0 +1,113 @@
1
+ // Global Tools
2
+
3
+ require('dotenv').config({ quiet: true });
4
+
5
+ // Packages / Helpers
6
+
7
+ const fs = require('fs');
8
+ const path = require('path');
9
+ const { NodeSSH } = require('node-ssh');
10
+ const { files } = require('./files');
11
+ const rootDir = path.resolve(__dirname, '..');
12
+
13
+ // Get All Servers
14
+
15
+ let servers = Object.keys(process.env).filter(key => key.startsWith('DEPLOY_')).length / 3;
16
+ servers = new Array(servers).fill().map((_,server) => {
17
+ return {
18
+ ip: process.env[`DEPLOY_${server+1}_IP`],
19
+ password: process.env[`DEPLOY_${server+1}_PASSWORD`],
20
+ path: process.env[`DEPLOY_${server+1}_PATH`]
21
+ };
22
+ });
23
+
24
+ // Collect Remote Directories
25
+
26
+ function collectRemoteDirs(localDir, remoteDir) {
27
+ const dirs = [];
28
+ for (const entry of fs.readdirSync(localDir, { withFileTypes: true })) {
29
+ if (entry.isDirectory()) {
30
+ const sub = path.posix.join(remoteDir, entry.name);
31
+ dirs.push(sub);
32
+ dirs.push(...collectRemoteDirs(path.join(localDir, entry.name), sub));
33
+ }
34
+ }
35
+ return dirs;
36
+ }
37
+
38
+ // Deploy to Server
39
+
40
+ async function deployTo(server) {
41
+
42
+ console.log(`\n→ ${server.ip}`);
43
+
44
+ const ssh = new NodeSSH();
45
+ await ssh.connect({
46
+ host: server.ip,
47
+ username: 'root',
48
+ password: server.password,
49
+ });
50
+
51
+ await ssh.execCommand(`mkdir -p ${server.path}`);
52
+
53
+ for (const item of files) {
54
+
55
+ const localPath = path.join(rootDir, item);
56
+ const remotePath = path.posix.join(server.path, item);
57
+
58
+ if (!fs.existsSync(localPath)) {
59
+ console.warn(` ⚠ ${item} — not found, skipping`);
60
+ continue;
61
+ }
62
+
63
+ const stat = fs.statSync(localPath);
64
+
65
+ await ssh.execCommand(`rm -rf ${remotePath}`);
66
+
67
+ if (stat.isDirectory()) {
68
+ const allDirs = [remotePath, ...collectRemoteDirs(localPath, remotePath)];
69
+ const mkdirArgs = allDirs.map(d => `'${d}'`).join(' ');
70
+ await ssh.execCommand(`mkdir -p ${mkdirArgs}`);
71
+
72
+ const failures = [];
73
+ const success = await ssh.putDirectory(localPath, remotePath, {
74
+ recursive: true,
75
+ concurrency: 1,
76
+ tick: (local, remote, error) => {
77
+ const rel = path.relative(rootDir, local);
78
+ if (error) {
79
+ failures.push(`${rel} — ${error.message}`);
80
+ console.error(` ✗ ${rel} — ${error.message}`);
81
+ } else {
82
+ console.log(` ✓ ${rel}`);
83
+ }
84
+ },
85
+ });
86
+ if (!success) throw new Error(`Upload failed for ${item} on ${server.ip}:\n ${failures.join('\n ')}`);
87
+ } else {
88
+ await ssh.putFile(localPath, remotePath);
89
+ console.log(` ✓ ${item}`);
90
+ }
91
+
92
+ }
93
+
94
+ const devrefPath = path.posix.join(server.path, 'devref.json');
95
+ await ssh.execCommand(`printf 'false' > ${devrefPath}`);
96
+ console.log(' ✓ devref.json (created)');
97
+
98
+ ssh.dispose();
99
+
100
+ }
101
+
102
+ // Start Deploy
103
+
104
+ (async () => {
105
+
106
+ for (const server of servers) {
107
+ await deployTo(server);
108
+ }
109
+
110
+ console.log('\nDeploy complete!');
111
+ process.exit();
112
+
113
+ })();
@@ -0,0 +1,8 @@
1
+ const files = [
2
+ 'src',
3
+ '.env',
4
+ 'jsconfig.json',
5
+ 'package.json',
6
+ 'package-lock.json',
7
+ ];
8
+ module.exports = { files };
@@ -1,9 +1,12 @@
1
1
  # Project
2
2
 
3
3
  PROJECT_ID=
4
- PROJECT_DOMAIN=
5
- PROJECT_WEB_DOMAIN=
6
- PROJECT_WEB_PORT=
4
+
5
+ # Deployment
6
+
7
+ DEPLOY_1_IP=
8
+ DEPLOY_1_PASSWORD=
9
+ DEPLOY_1_PATH=
7
10
 
8
11
  # Supabase
9
12
 
@@ -4,19 +4,20 @@
4
4
  "main": "src/index.js",
5
5
  "scripts": {
6
6
  "dev": "nodemon src/index.js",
7
- "start": "node src/index.js"
7
+ "start": "node src/index.js",
8
+ "deploy": "node .deploy/deploy.js"
8
9
  },
9
10
  "dependencies": {
10
11
  "@supabase/supabase-js": "^2.101.1",
11
12
  "cors": "^2.8.6",
12
13
  "dotenv": "^17.3.1",
13
14
  "module-alias": "^2.3.4",
14
- "nanoid": "^5.1.6",
15
15
  "redis": "^5.11.0",
16
16
  "simple-supabase": "^2.0.10"
17
17
  },
18
18
  "devDependencies": {
19
19
  "eslint": "^9.39.3",
20
+ "node-ssh": "^13.2.1",
20
21
  "nodemon": "^3.1.13"
21
22
  },
22
23
  "_moduleAliases": {
@@ -0,0 +1 @@
1
+ module.exports = async () => {};
@@ -1,11 +0,0 @@
1
- // Packages / Helpers
2
-
3
- const { nanoid } = require('nanoid');
4
-
5
- function generateId(customLength = 32) {
6
- customLength = customLength < 21 ? 21 : customLength;
7
- const id = nanoid(customLength);
8
- return id;
9
- }
10
-
11
- module.exports = { generateId };