@tertium/hlpr 0.5.1 → 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,55 +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
- if (/^[A-Z_][A-Z0-9_]*=/.test(trimmed))
51
- continue;
52
- try {
53
- console.log(`→ ${trimmed}`);
54
- execSync(trimmed, {
55
- stdio: "inherit",
56
- cwd,
57
- shell: true
58
- });
59
- } catch (error) {
60
- console.error(`
61
- ✗ Command failed: ${trimmed}
62
- `);
63
- process.exit(1);
64
- }
65
- }
66
- }
67
36
  function deploy() {
68
- const skipBuild = process.argv[2] === "skip-build";
69
37
  const projectDir = process.cwd();
70
38
  const env = loadEnv(projectDir);
71
39
  validate(env);
72
- const scriptPath = path.join(__dirname2, "deploy.sh");
73
- if (!existsSync(scriptPath)) {
74
- console.error(`Error: Deploy script not found at ${scriptPath}`);
75
- process.exit(1);
76
- }
77
- const scriptContent = readFileSync(scriptPath, "utf-8");
78
- const variables = {
79
- ...env,
80
- SKIP_BUILD: skipBuild ? "true" : "false"
81
- };
82
40
  console.log(`
83
- Deploying to ${env.DEPLOY_HOST}:${env.DEPLOY_PATH}`);
84
- console.log(`==========================================
41
+ Deploying to ${env.DEPLOY_HOST}:${env.DEPLOY_PATH}
85
42
  `);
86
43
  try {
87
- executeScript(scriptContent, variables, projectDir);
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
+ `);
88
61
  } catch (error) {
89
62
  console.error(`
90
63
  ✗ Deployment failed: ${error.message}
@@ -1,41 +1,13 @@
1
1
  #!/bin/bash
2
- # @description Deploy application to remote server with environment variables
2
+ # @description Deploy application to remote server
3
3
 
4
- SKIP_BUILD="{{SKIP_BUILD}}"
5
- DEPLOY_USER="{{DEPLOY_USER}}"
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/ $DEPLOY_USER@$DEPLOY_HOST:$DEPLOY_PATH/
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 $DEPLOY_USER@$DEPLOY_HOST "cd $DEPLOY_PATH && bun install --production && pm2 restart $APP_NAME --update-env"
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!"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tertium/hlpr",
3
- "version": "0.5.1",
3
+ "version": "0.5.2",
4
4
  "description": "Windows and *Nix utility for typical programming activity",
5
5
  "author": "Vitalii Balabanov",
6
6
  "email": "tertiumnon@gmail.com",