remote-deploy-cli 1.1.0 → 1.1.2

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/index.js CHANGED
@@ -66,14 +66,28 @@ program
66
66
  // We'll use a dynamic import or checking for the pm2 binary in a real scenario
67
67
  // But here we can just try to spawn 'pm2' command
68
68
 
69
- const args = ['start', process.argv[1], '--name', 'redep-server', '--', 'listen'];
69
+ // Use dedicated server entry point for PM2 to avoid CLI/ESM issues
70
+ // Resolve absolute path to server-entry.js
71
+ const scriptPath = new URL('../server-entry.js', import.meta.url).pathname.replace(/^\/([A-Za-z]:)/, '$1');
72
+
73
+ const args = [
74
+ 'start',
75
+ scriptPath,
76
+ '--name', 'redep-server'
77
+ ];
78
+
79
+ // We don't pass 'listen' arg because server-entry.js starts immediately
80
+ // But we do need to ensure env vars are passed if port is customized
81
+
82
+ const env = { ...process.env };
70
83
  if (options.port) {
71
- args.push('--port', options.port);
84
+ env.SERVER_PORT = options.port;
72
85
  }
73
86
 
74
87
  const pm2 = spawn('pm2', args, {
75
88
  stdio: 'inherit',
76
- shell: true // Required to find pm2 in PATH
89
+ shell: true,
90
+ env: env // Pass modified env with port
77
91
  });
78
92
 
79
93
  pm2.on('error', () => {
@@ -195,15 +209,15 @@ program
195
209
  .description('Start the server to listen for commands')
196
210
  .option('-p, --port <port>', 'Port to listen on', 3000)
197
211
  .action((options) => {
198
- const port = options.port || process.env.SERVER_PORT || getConfig('server_port') || 3000;
199
- const secret = process.env.SECRET_KEY || getConfig('secret_key');
212
+ const port = options.port || getConfig('server_port') || process.env.SERVER_PORT || 3000;
213
+ const secret = getConfig('secret_key') || process.env.SECRET_KEY;
200
214
 
201
215
  if (!secret) {
202
216
  logger.warn('Warning: No "secret_key" set in config or SECRET_KEY env var. Communication might be insecure or fail if client requires it.');
203
217
  logger.info('Run "redep config set secret_key <your-secret>" or set SECRET_KEY env var.');
204
218
  }
205
219
 
206
- const workingDir = process.env.WORKING_DIR || getConfig('working_dir');
220
+ const workingDir = getConfig('working_dir') || process.env.WORKING_DIR;
207
221
  if (!workingDir) {
208
222
  logger.error('Error: "working_dir" is not set. Please set it using "redep config set working_dir <path>" or WORKING_DIR env var.');
209
223
  process.exit(1);
@@ -217,8 +231,8 @@ program
217
231
  .command('deploy <type>')
218
232
  .description('Deploy a service (e.g., "fe") to the server machine')
219
233
  .action(async (type) => {
220
- const serverUrl = process.env.SERVER_URL || getConfig('server_url');
221
- const secret = process.env.SECRET_KEY || getConfig('secret_key');
234
+ const serverUrl = getConfig('server_url') || process.env.SERVER_URL;
235
+ const secret = getConfig('secret_key') || process.env.SECRET_KEY;
222
236
 
223
237
  if (!serverUrl) {
224
238
  logger.error('Error: "server_url" is not set. Set SERVER_URL env var or run "redep config set server_url <url>"');
package/package.json CHANGED
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "name": "remote-deploy-cli",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "main": "index.js",
5
5
  "type": "module",
6
6
  "bin": {
7
7
  "redep": "./bin/index.js"
8
8
  },
9
9
  "scripts": {
10
- "test": "echo \"Error: no test specified\" && exit 1"
10
+ "test": "echo \"Error: no test specified\" && exit 1",
11
+ "update": "node scripts/update.js"
11
12
  },
12
13
  "keywords": [],
13
14
  "author": "",
@@ -0,0 +1,90 @@
1
+ import fs from 'fs';
2
+ import { execSync } from 'child_process';
3
+ import path from 'path';
4
+
5
+ // Get arguments from command line
6
+ // Usage: node scripts/update.js <updateType> <commitMessage>
7
+ const updateType = process.argv[2];
8
+ const commitMessage = process.argv[3];
9
+
10
+ // Valid update types
11
+ const VALID_TYPES = ['patch', 'minor', 'major'];
12
+
13
+ // --- Validation ---
14
+
15
+ if (!updateType || !VALID_TYPES.includes(updateType)) {
16
+ console.error(`Error: Invalid or missing updateType. Must be one of: ${VALID_TYPES.join(', ')}`);
17
+ process.exit(1);
18
+ }
19
+
20
+ if (!commitMessage) {
21
+ console.error('Error: Missing commitMessage.');
22
+ process.exit(1);
23
+ }
24
+
25
+ const packageJsonPath = path.resolve('package.json');
26
+
27
+ if (!fs.existsSync(packageJsonPath)) {
28
+ console.error('Error: package.json not found.');
29
+ process.exit(1);
30
+ }
31
+
32
+ // --- Version Update Logic ---
33
+
34
+ try {
35
+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
36
+
37
+ if (!packageJson.version) {
38
+ console.error('Error: package.json does not contain a "version" field.');
39
+ process.exit(1);
40
+ }
41
+
42
+ const currentVersion = packageJson.version;
43
+ const versionParts = currentVersion.split('.').map(Number);
44
+
45
+ if (versionParts.length !== 3 || versionParts.some(isNaN)) {
46
+ console.error(`Error: Invalid semantic version format in package.json: ${currentVersion}`);
47
+ process.exit(1);
48
+ }
49
+
50
+ let [major, minor, patch] = versionParts;
51
+
52
+ switch (updateType) {
53
+ case 'major':
54
+ major++;
55
+ minor = 0;
56
+ patch = 0;
57
+ break;
58
+ case 'minor':
59
+ minor++;
60
+ patch = 0;
61
+ break;
62
+ case 'patch':
63
+ patch++;
64
+ break;
65
+ }
66
+
67
+ const newVersion = `${major}.${minor}.${patch}`;
68
+ packageJson.version = newVersion;
69
+
70
+ // Write updated package.json
71
+ fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2) + '\n');
72
+ console.log(`Version updated: ${currentVersion} -> ${newVersion}`);
73
+
74
+ // --- Git Operations ---
75
+
76
+ console.log('Staging changes...');
77
+ execSync('git add .', { stdio: 'inherit' });
78
+
79
+ console.log(`Committing with message: "${commitMessage}"...`);
80
+ execSync(`git commit -m "${commitMessage}"`, { stdio: 'inherit' });
81
+
82
+ console.log('Pushing to origin main...');
83
+ execSync('git push origin main', { stdio: 'inherit' });
84
+
85
+ console.log('Update process completed successfully!');
86
+
87
+ } catch (error) {
88
+ console.error(`Error during update process: ${error.message}`);
89
+ process.exit(1);
90
+ }
@@ -0,0 +1,22 @@
1
+ import { startServer } from './lib/server/index.js';
2
+ import { logger } from './lib/logger.js';
3
+ import { getConfig } from './lib/config.js';
4
+ import 'dotenv/config';
5
+
6
+ // Dedicated entry point for PM2 to ensure clean ESM handling
7
+ // PM2 sometimes struggles with CLI binaries directly in ESM mode
8
+
9
+ const port = process.env.SERVER_PORT || getConfig('server_port') || 3000;
10
+ const secret = process.env.SECRET_KEY || getConfig('secret_key');
11
+ const workingDir = process.env.WORKING_DIR || getConfig('working_dir');
12
+
13
+ if (!secret) {
14
+ logger.warn('Warning: No "secret_key" set. Communication might be insecure.');
15
+ }
16
+
17
+ if (!workingDir) {
18
+ logger.error('Error: "working_dir" is not set.');
19
+ process.exit(1);
20
+ }
21
+
22
+ startServer(port, secret, workingDir);