remote-deploy-cli 1.1.1 → 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 +17 -3
- package/package.json +3 -2
- package/scripts/update.js +90 -0
- package/server-entry.js +22 -0
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
|
-
|
|
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
|
-
|
|
84
|
+
env.SERVER_PORT = options.port;
|
|
72
85
|
}
|
|
73
86
|
|
|
74
87
|
const pm2 = spawn('pm2', args, {
|
|
75
88
|
stdio: 'inherit',
|
|
76
|
-
shell: true
|
|
89
|
+
shell: true,
|
|
90
|
+
env: env // Pass modified env with port
|
|
77
91
|
});
|
|
78
92
|
|
|
79
93
|
pm2.on('error', () => {
|
package/package.json
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "remote-deploy-cli",
|
|
3
|
-
"version": "1.1.
|
|
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
|
+
}
|
package/server-entry.js
ADDED
|
@@ -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);
|