@rpcbase/cli 0.80.0 → 0.82.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/package.json +1 -1
- package/src/cmd-deploy.js +48 -15
- package/src/cmd-ssh.js +15 -15
package/package.json
CHANGED
package/src/cmd-deploy.js
CHANGED
|
@@ -10,30 +10,30 @@ export const deploy = async (argv) => {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
const {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
RB_SSH_HOST,
|
|
14
|
+
RB_SSH_USER,
|
|
15
|
+
RB_SSH_KEY,
|
|
16
16
|
RB_DEPLOY_DIR,
|
|
17
17
|
} = argv.env || {};
|
|
18
18
|
|
|
19
19
|
if (
|
|
20
|
-
!
|
|
21
|
-
!validator.isURL(
|
|
20
|
+
!RB_SSH_HOST ||
|
|
21
|
+
!validator.isURL(RB_SSH_HOST, { require_tld: false })
|
|
22
22
|
) {
|
|
23
23
|
throw new Error(
|
|
24
|
-
"Missing or invalid required environment variable:
|
|
24
|
+
"Missing or invalid required environment variable: RB_SSH_HOST",
|
|
25
25
|
);
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
if (!
|
|
28
|
+
if (!RB_SSH_USER || !validator.isLength(RB_SSH_USER, { min: 1 })) {
|
|
29
29
|
throw new Error(
|
|
30
|
-
"Missing or invalid required environment variable:
|
|
30
|
+
"Missing or invalid required environment variable: RB_SSH_USER",
|
|
31
31
|
);
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
if (!
|
|
34
|
+
if (!RB_SSH_KEY || !validator.isLength(RB_SSH_KEY, { min: 1 })) {
|
|
35
35
|
throw new Error(
|
|
36
|
-
"Missing or invalid required environment variable:
|
|
36
|
+
"Missing or invalid required environment variable: RB_SSH_KEY",
|
|
37
37
|
);
|
|
38
38
|
}
|
|
39
39
|
|
|
@@ -43,10 +43,10 @@ export const deploy = async (argv) => {
|
|
|
43
43
|
);
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
const host =
|
|
47
|
-
const user =
|
|
46
|
+
const host = RB_SSH_HOST;
|
|
47
|
+
const user = RB_SSH_USER;
|
|
48
48
|
const deployDir = RB_DEPLOY_DIR;
|
|
49
|
-
let keyPath =
|
|
49
|
+
let keyPath = RB_SSH_KEY;
|
|
50
50
|
|
|
51
51
|
let tempKeyPath = null;
|
|
52
52
|
|
|
@@ -65,8 +65,8 @@ export const deploy = async (argv) => {
|
|
|
65
65
|
if (keyPath.startsWith("~")) keyPath = keyPath.replace("~", os.homedir());
|
|
66
66
|
|
|
67
67
|
if (!fs.existsSync(keyPath)) {
|
|
68
|
-
// try to treat
|
|
69
|
-
const keyContent = Buffer.from(
|
|
68
|
+
// try to treat RB_SSH_KEY as base64-encoded key content
|
|
69
|
+
const keyContent = Buffer.from(RB_SSH_KEY, "base64").toString("utf-8");
|
|
70
70
|
if (!keyContent.includes("-----BEGIN")) {
|
|
71
71
|
throw new Error(
|
|
72
72
|
"Decoded content does not appear to be a valid SSH key",
|
|
@@ -136,4 +136,37 @@ export const deploy = async (argv) => {
|
|
|
136
136
|
}
|
|
137
137
|
}
|
|
138
138
|
}
|
|
139
|
+
|
|
140
|
+
// Purge Cloudflare Cache if CLOUDFLARE_ZONE and CLOUDFLARE_TOKEN are set
|
|
141
|
+
const { CLOUDFLARE_ZONE, CLOUDFLARE_TOKEN } = process.env;
|
|
142
|
+
|
|
143
|
+
if (!CLOUDFLARE_ZONE || !CLOUDFLARE_TOKEN) {
|
|
144
|
+
console.warn("Cloudflare cache purge will not run: missing CLOUDFLARE_ZONE or CLOUDFLARE_TOKEN environment variables");
|
|
145
|
+
} else {
|
|
146
|
+
console.log("Purging Cloudflare cache...");
|
|
147
|
+
|
|
148
|
+
try {
|
|
149
|
+
const axios = (await import('axios')).default;
|
|
150
|
+
const response = await axios.post(
|
|
151
|
+
`https://api.cloudflare.com/client/v4/zones/${CLOUDFLARE_ZONE}/purge_cache`,
|
|
152
|
+
{ purge_everything: true },
|
|
153
|
+
{
|
|
154
|
+
headers: {
|
|
155
|
+
'Authorization': `Bearer ${CLOUDFLARE_TOKEN}`,
|
|
156
|
+
'Content-Type': 'application/json'
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
);
|
|
160
|
+
|
|
161
|
+
if (response.data.success) {
|
|
162
|
+
console.log("Successfully purged Cloudflare cache for zone:", CLOUDFLARE_ZONE);
|
|
163
|
+
} else {
|
|
164
|
+
console.warn("Failed to purge Cloudflare cache:", response.data.errors);
|
|
165
|
+
}
|
|
166
|
+
} catch (error) {
|
|
167
|
+
console.error("Error purging Cloudflare cache:", error.message);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
console.log("Done.")
|
|
139
172
|
};
|
package/src/cmd-ssh.js
CHANGED
|
@@ -10,35 +10,35 @@ export const ssh = async (argv) => {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
const {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
RB_SSH_HOST,
|
|
14
|
+
RB_SSH_USER,
|
|
15
|
+
RB_SSH_KEY,
|
|
16
16
|
} = argv.env || {};
|
|
17
17
|
|
|
18
18
|
if (
|
|
19
|
-
!
|
|
20
|
-
!validator.isURL(
|
|
19
|
+
!RB_SSH_HOST ||
|
|
20
|
+
!validator.isURL(RB_SSH_HOST, { require_tld: false })
|
|
21
21
|
) {
|
|
22
22
|
throw new Error(
|
|
23
|
-
"Missing or invalid required environment variable:
|
|
23
|
+
"Missing or invalid required environment variable: RB_SSH_HOST",
|
|
24
24
|
);
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
if (!
|
|
27
|
+
if (!RB_SSH_USER || !validator.isLength(RB_SSH_USER, { min: 1 })) {
|
|
28
28
|
throw new Error(
|
|
29
|
-
"Missing or invalid required environment variable:
|
|
29
|
+
"Missing or invalid required environment variable: RB_SSH_USER",
|
|
30
30
|
);
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
if (!
|
|
33
|
+
if (!RB_SSH_KEY || !validator.isLength(RB_SSH_KEY, { min: 1 })) {
|
|
34
34
|
throw new Error(
|
|
35
|
-
"Missing or invalid required environment variable:
|
|
35
|
+
"Missing or invalid required environment variable: RB_SSH_KEY",
|
|
36
36
|
);
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
const host =
|
|
40
|
-
const user =
|
|
41
|
-
let keyPath =
|
|
39
|
+
const host = RB_SSH_HOST;
|
|
40
|
+
const user = RB_SSH_USER;
|
|
41
|
+
let keyPath = RB_SSH_KEY;
|
|
42
42
|
|
|
43
43
|
let tempKeyPath = null;
|
|
44
44
|
|
|
@@ -56,8 +56,8 @@ export const ssh = async (argv) => {
|
|
|
56
56
|
if (keyPath.startsWith("~")) keyPath = keyPath.replace("~", os.homedir());
|
|
57
57
|
|
|
58
58
|
if (!fs.existsSync(keyPath)) {
|
|
59
|
-
// try to treat
|
|
60
|
-
const keyContent = Buffer.from(
|
|
59
|
+
// try to treat RB_SSH_KEY as base64-encoded key content
|
|
60
|
+
const keyContent = Buffer.from(RB_SSH_KEY, "base64").toString("utf-8");
|
|
61
61
|
if (!keyContent.includes("-----BEGIN")) {
|
|
62
62
|
throw new Error(
|
|
63
63
|
"Decoded content does not appear to be a valid SSH key",
|