@rpcbase/cli 0.118.0 → 0.120.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/package.json +1 -1
  2. package/src/cmd-deploy.js +81 -14
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rpcbase/cli",
3
- "version": "0.118.0",
3
+ "version": "0.120.0",
4
4
  "type": "module",
5
5
  "main": "./index.js",
6
6
  "bin": {
package/src/cmd-deploy.js CHANGED
@@ -8,6 +8,72 @@ import validator from "validator"
8
8
  import { purgeCloudflareCaches } from "./cloudflare-purge.js"
9
9
 
10
10
 
11
+ const baseExcludeList = [
12
+ ".husky/",
13
+ ".github/",
14
+ ".git/",
15
+ ".wireit/",
16
+ "coverage/",
17
+ "node_modules/",
18
+ "infrastructure/data/",
19
+ ".gitignore",
20
+ "*.css.map",
21
+ // "*.env*",
22
+ // "*.js.map",
23
+ "*.md",
24
+ ]
25
+
26
+
27
+ const detectComposeChanges = ({ keyPath, user, host, deployDir, log, extraExcludes = [] }) => {
28
+ const includeArgs = ["--include='*/'", "--include='*compose*.yml'", "--exclude='*'"]
29
+ const excludeArgs = baseExcludeList
30
+ .concat(extraExcludes)
31
+ .map((p) => `--exclude='${p}'`)
32
+ .join(" ")
33
+
34
+ // keep --delete so remote-only compose files show up as *deleting in dry-run; dropping it hides stale files
35
+ const rsyncCmd = [
36
+ "rsync -avzn --delete --itemize-changes --filter=':- .gitignore'",
37
+ includeArgs.join(" "),
38
+ excludeArgs,
39
+ `-e "ssh -i '${keyPath}' -o StrictHostKeyChecking=no"`,
40
+ ".",
41
+ `${user}@${host}:~/apps/${deployDir}/`,
42
+ ].filter(Boolean).join(" ")
43
+
44
+ log(`Checking compose files (dry-run): ${rsyncCmd}`)
45
+
46
+ let out
47
+ try {
48
+ out = execSync(rsyncCmd, { stdio: "pipe" }).toString()
49
+ } catch (error) {
50
+ const allowedExitCodes = [23, 24]
51
+ if (allowedExitCodes.includes(error?.status) && error?.stdout) {
52
+ out = error.stdout.toString()
53
+ } else {
54
+ throw error
55
+ }
56
+ }
57
+
58
+ // rsync --itemize-changes prefixes change lines; any line that isn't a summary indicates a diff
59
+ const changeLines = out
60
+ .split("\n")
61
+ .map((line) => line.trim())
62
+ .filter((line) => {
63
+ if (!line) return false
64
+ if (line.startsWith("sending ")) return false
65
+ if (line.startsWith("sent ")) return false
66
+ if (line.startsWith("total size")) return false
67
+ if (line.startsWith("receiving incremental file list")) return false
68
+ return true
69
+ })
70
+
71
+ const hasChanges = changeLines.length > 0
72
+
73
+ return { hasChanges, output: out }
74
+ }
75
+
76
+
11
77
  export const deploy = async (argv) => {
12
78
  const log = (message) => {
13
79
  if (argv.verbose) console.log(message)
@@ -87,20 +153,21 @@ export const deploy = async (argv) => {
87
153
  console.log(`${user}@${host}`, res)
88
154
  await ssh(`mkdir -p ~/apps/${deployDir}`)
89
155
 
90
- const excludeList = [
91
- ".husky/",
92
- ".github/",
93
- ".git/",
94
- ".wireit/",
95
- "coverage/",
96
- "node_modules/",
97
- "infrastructure/data/",
98
- ".gitignore",
99
- "*.css.map",
100
- // "*.env*",
101
- // "*.js.map",
102
- "*.md",
103
- ].concat(argv.ignore)
156
+ const { hasChanges: infrastructureChanged, output: infrastructureDiff } = detectComposeChanges({
157
+ keyPath,
158
+ user,
159
+ host,
160
+ deployDir,
161
+ log,
162
+ extraExcludes: argv.ignore || [],
163
+ })
164
+
165
+ if (infrastructureChanged) {
166
+ console.log("Infrastructure compose files differ between local and remote (info only; deploy proceeds).")
167
+ if (argv.verbose) console.log(infrastructureDiff)
168
+ }
169
+
170
+ const excludeList = baseExcludeList.concat(argv.ignore)
104
171
 
105
172
 
106
173
  const excludeArgs = excludeList.map((p) => `--exclude='${p}'`).join(" ")