custom-deploy 1.0.0 → 1.2.0

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.
Files changed (2) hide show
  1. package/index.js +59 -5
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -2,6 +2,7 @@
2
2
  import 'dotenv/config';
3
3
  import {execSync} from 'child_process';
4
4
  import fs from 'fs';
5
+ import os from 'os';
5
6
  import path from 'path';
6
7
  import axios from 'axios';
7
8
  import FormData from 'form-data';
@@ -11,10 +12,55 @@ const TELEGRAM_BOT_TOKEN = process.env.BOT_TOKEN;
11
12
  const CHAT_ID = process.env.CHAT_ID;
12
13
  const DIST_PATH = path.resolve('dist');
13
14
 
15
+ function expandHome(p) {
16
+ if (p === '~') return os.homedir();
17
+ if (p.startsWith('~/')) return path.join(os.homedir(), p.slice(2));
18
+ return p;
19
+ }
20
+
21
+ function parseArgs(argv) {
22
+ const opts = {output: null};
23
+
24
+ for (let i = 0; i < argv.length; i++) {
25
+ const arg = argv[i];
26
+
27
+ if (arg === '-o' || arg === '--output') {
28
+ const next = argv[i + 1];
29
+ // Allow `-o` with no path to default to ~/Downloads
30
+ if (!next || next.startsWith('-')) {
31
+ opts.output = path.join(os.homedir(), 'Downloads');
32
+ } else {
33
+ opts.output = path.resolve(expandHome(next));
34
+ i++;
35
+ }
36
+ }
37
+ }
38
+
39
+ return opts;
40
+ }
41
+
42
+ function copyToOutput(zipPath, outputDir) {
43
+ fs.mkdirSync(outputDir, {recursive: true});
44
+ const dest = path.join(outputDir, path.basename(zipPath));
45
+ fs.copyFileSync(zipPath, dest);
46
+ return dest;
47
+ }
48
+
14
49
  function getCurrentBranch() {
15
50
  return execSync('git rev-parse --abbrev-ref HEAD').toString().trim();
16
51
  }
17
52
 
53
+ function getProjectName() {
54
+ const pkg = JSON.parse(fs.readFileSync(path.resolve('package.json'), 'utf8'));
55
+ return pkg.name;
56
+ }
57
+
58
+ function getGitUser() {
59
+ const name = execSync('git config user.name').toString().trim();
60
+ const email = execSync('git config user.email').toString().trim();
61
+ return `${name} <${email}>`;
62
+ }
63
+
18
64
  function getBuildCommand(branch) {
19
65
  const upper = branch.toUpperCase();
20
66
 
@@ -24,11 +70,10 @@ function getBuildCommand(branch) {
24
70
  throw new Error(`Unsupported branch: ${branch}`);
25
71
  }
26
72
 
27
- function getZipPath(branch) {
73
+ function getZipPath(branch, projectName) {
28
74
  const upper = branch.toUpperCase();
29
75
 
30
- if (upper === 'PROD') return path.resolve('build-prod.zip');
31
- if (upper === 'DEV') return path.resolve('build-dev.zip');
76
+ if (upper === 'PROD' || upper === 'DEV') return path.resolve(`${projectName}-${branch.toLowerCase()}.zip`);
32
77
 
33
78
  throw new Error(`Unsupported branch for zip: ${branch}`);
34
79
  }
@@ -75,9 +120,13 @@ async function main() {
75
120
  throw new Error('Missing TELEGRAM_BOT_TOKEN or CHAT_ID');
76
121
  }
77
122
 
123
+ const opts = parseArgs(process.argv.slice(2));
124
+
78
125
  const branch = getCurrentBranch();
126
+ const projectName = getProjectName();
127
+ const sender = getGitUser();
79
128
  const buildCommand = getBuildCommand(branch);
80
- const zipPath = getZipPath(branch);
129
+ const zipPath = getZipPath(branch, projectName);
81
130
 
82
131
  console.log(`Branch: ${branch}`);
83
132
 
@@ -89,10 +138,15 @@ async function main() {
89
138
 
90
139
  await zipDist(zipPath);
91
140
 
92
- await sendTelegramMessage(`✅ Build completed for branch: ${branch}`);
141
+ await sendTelegramMessage(`✅ Build completed\nProject: ${projectName}\nBranch: ${branch}\nSent by: ${sender}`);
93
142
  await sendTelegramFile(zipPath);
94
143
 
95
144
  console.log(`Sent: ${zipPath}`);
145
+
146
+ if (opts.output) {
147
+ const dest = copyToOutput(zipPath, opts.output);
148
+ console.log(`Copied to: ${dest}`);
149
+ }
96
150
  } catch (err) {
97
151
  console.error('❌', err.message);
98
152
  if (TELEGRAM_BOT_TOKEN && CHAT_ID) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "custom-deploy",
3
- "version": "1.0.0",
3
+ "version": "1.2.0",
4
4
  "description": "CLI tool to build and send deployment artifacts via Telegram",
5
5
  "type": "module",
6
6
  "bin": {