@tertium/hlpr 0.5.0 → 0.5.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.
|
@@ -4,9 +4,6 @@
|
|
|
4
4
|
import { execSync } from "child_process";
|
|
5
5
|
import { existsSync, readFileSync } from "fs";
|
|
6
6
|
import * as path from "path";
|
|
7
|
-
import { fileURLToPath } from "url";
|
|
8
|
-
var __filename2 = fileURLToPath(import.meta.url);
|
|
9
|
-
var __dirname2 = path.dirname(__filename2);
|
|
10
7
|
function loadEnv(projectDir) {
|
|
11
8
|
const envPath = path.join(projectDir, ".env");
|
|
12
9
|
if (!existsSync(envPath)) {
|
|
@@ -36,53 +33,31 @@ function validate(env) {
|
|
|
36
33
|
process.exit(1);
|
|
37
34
|
}
|
|
38
35
|
}
|
|
39
|
-
function executeScript(scriptContent, variables, cwd) {
|
|
40
|
-
let script = scriptContent;
|
|
41
|
-
for (const [key, value] of Object.entries(variables)) {
|
|
42
|
-
script = script.replace(new RegExp(`{{${key}}}`, "g"), value);
|
|
43
|
-
}
|
|
44
|
-
const lines = script.split(`
|
|
45
|
-
`);
|
|
46
|
-
for (const line of lines) {
|
|
47
|
-
const trimmed = line.trim();
|
|
48
|
-
if (!trimmed || trimmed.startsWith("#") || trimmed.startsWith("#!/"))
|
|
49
|
-
continue;
|
|
50
|
-
try {
|
|
51
|
-
console.log(`→ ${trimmed}`);
|
|
52
|
-
execSync(trimmed, {
|
|
53
|
-
stdio: "inherit",
|
|
54
|
-
cwd,
|
|
55
|
-
shell: true
|
|
56
|
-
});
|
|
57
|
-
} catch (error) {
|
|
58
|
-
console.error(`
|
|
59
|
-
✗ Command failed: ${trimmed}
|
|
60
|
-
`);
|
|
61
|
-
process.exit(1);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
36
|
function deploy() {
|
|
66
|
-
const skipBuild = process.argv[2] === "skip-build";
|
|
67
37
|
const projectDir = process.cwd();
|
|
68
38
|
const env = loadEnv(projectDir);
|
|
69
39
|
validate(env);
|
|
70
|
-
const scriptPath = path.join(__dirname2, "deploy.sh");
|
|
71
|
-
if (!existsSync(scriptPath)) {
|
|
72
|
-
console.error(`Error: Deploy script not found at ${scriptPath}`);
|
|
73
|
-
process.exit(1);
|
|
74
|
-
}
|
|
75
|
-
const scriptContent = readFileSync(scriptPath, "utf-8");
|
|
76
|
-
const variables = {
|
|
77
|
-
...env,
|
|
78
|
-
SKIP_BUILD: skipBuild ? "true" : "false"
|
|
79
|
-
};
|
|
80
40
|
console.log(`
|
|
81
|
-
Deploying to ${env.DEPLOY_HOST}:${env.DEPLOY_PATH}
|
|
82
|
-
console.log(`==========================================
|
|
41
|
+
Deploying to ${env.DEPLOY_HOST}:${env.DEPLOY_PATH}
|
|
83
42
|
`);
|
|
84
43
|
try {
|
|
85
|
-
|
|
44
|
+
const scpCmd = `scp -r dist/ ${env.DEPLOY_USER}@${env.DEPLOY_HOST}:${env.DEPLOY_PATH}/`;
|
|
45
|
+
console.log(`→ ${scpCmd}`);
|
|
46
|
+
execSync(scpCmd, {
|
|
47
|
+
stdio: "inherit",
|
|
48
|
+
cwd: projectDir,
|
|
49
|
+
shell: true
|
|
50
|
+
});
|
|
51
|
+
const sshCmd = `ssh ${env.DEPLOY_USER}@${env.DEPLOY_HOST} "cd ${env.DEPLOY_PATH} && bun install --production && pm2 restart ${env.APP_NAME} --update-env"`;
|
|
52
|
+
console.log(`→ ${sshCmd}`);
|
|
53
|
+
execSync(sshCmd, {
|
|
54
|
+
stdio: "inherit",
|
|
55
|
+
cwd: projectDir,
|
|
56
|
+
shell: true
|
|
57
|
+
});
|
|
58
|
+
console.log(`
|
|
59
|
+
✓ Deployment complete!
|
|
60
|
+
`);
|
|
86
61
|
} catch (error) {
|
|
87
62
|
console.error(`
|
|
88
63
|
✗ Deployment failed: ${error.message}
|
|
@@ -1,41 +1,13 @@
|
|
|
1
1
|
#!/bin/bash
|
|
2
|
-
# @description Deploy application to remote server
|
|
2
|
+
# @description Deploy application to remote server
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
DEPLOY_HOST="{{DEPLOY_HOST}}"
|
|
7
|
-
DEPLOY_PATH="{{DEPLOY_PATH}}"
|
|
8
|
-
APP_NAME="{{APP_NAME}}"
|
|
9
|
-
|
|
10
|
-
echo "Deploying to $DEPLOY_HOST:$DEPLOY_PATH"
|
|
11
|
-
echo "=========================================="
|
|
12
|
-
|
|
13
|
-
# Build phase (unless skip-build is set)
|
|
14
|
-
if [ "$SKIP_BUILD" != "true" ]; then
|
|
15
|
-
echo "Building..."
|
|
16
|
-
bun run build
|
|
17
|
-
if [ $? -ne 0 ]; then
|
|
18
|
-
echo "✗ Build failed"
|
|
19
|
-
exit 1
|
|
20
|
-
fi
|
|
21
|
-
fi
|
|
22
|
-
|
|
23
|
-
# Deploy phase
|
|
4
|
+
echo "Building..."
|
|
5
|
+
bun run build
|
|
24
6
|
echo ""
|
|
25
7
|
echo "Copying files to remote server..."
|
|
26
|
-
scp -r dist/
|
|
27
|
-
if [ $? -ne 0 ]; then
|
|
28
|
-
echo "✗ SCP failed"
|
|
29
|
-
exit 1
|
|
30
|
-
fi
|
|
31
|
-
|
|
8
|
+
scp -r dist/ {{DEPLOY_USER}}@{{DEPLOY_HOST}}:{{DEPLOY_PATH}}/
|
|
32
9
|
echo ""
|
|
33
10
|
echo "Installing dependencies and restarting service..."
|
|
34
|
-
ssh
|
|
35
|
-
if [ $? -ne 0 ]; then
|
|
36
|
-
echo "✗ Remote deployment failed"
|
|
37
|
-
exit 1
|
|
38
|
-
fi
|
|
39
|
-
|
|
11
|
+
ssh {{DEPLOY_USER}}@{{DEPLOY_HOST}} "cd {{DEPLOY_PATH}} && bun install --production && pm2 restart {{APP_NAME}} --update-env"
|
|
40
12
|
echo ""
|
|
41
13
|
echo "✓ Deployment complete!"
|