custom-deploy 1.1.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.
- package/index.js +42 -0
- 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,6 +12,40 @@ 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
|
}
|
|
@@ -85,6 +120,8 @@ async function main() {
|
|
|
85
120
|
throw new Error('Missing TELEGRAM_BOT_TOKEN or CHAT_ID');
|
|
86
121
|
}
|
|
87
122
|
|
|
123
|
+
const opts = parseArgs(process.argv.slice(2));
|
|
124
|
+
|
|
88
125
|
const branch = getCurrentBranch();
|
|
89
126
|
const projectName = getProjectName();
|
|
90
127
|
const sender = getGitUser();
|
|
@@ -105,6 +142,11 @@ async function main() {
|
|
|
105
142
|
await sendTelegramFile(zipPath);
|
|
106
143
|
|
|
107
144
|
console.log(`Sent: ${zipPath}`);
|
|
145
|
+
|
|
146
|
+
if (opts.output) {
|
|
147
|
+
const dest = copyToOutput(zipPath, opts.output);
|
|
148
|
+
console.log(`Copied to: ${dest}`);
|
|
149
|
+
}
|
|
108
150
|
} catch (err) {
|
|
109
151
|
console.error('❌', err.message);
|
|
110
152
|
if (TELEGRAM_BOT_TOKEN && CHAT_ID) {
|