-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpush.ts
59 lines (52 loc) · 1.56 KB
/
push.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/**
* Push files from a local environment to a remote WordPress instance.
* @flag [[--with-config]] Include wp-config.php in the upload
*/
import { rsync } from './lib/utils';
import { getConfig } from './lib/config';
function header(text: string) {
console.log(`===\n=== ${text}\n===`);
}
type PushFiles = {
remote: string;
remote_path: string;
local_path: string;
excludes: {
global: string[];
paths: string[];
};
includes: string[];
}
function trailingslashit(path: string) {
return untrailingslashit(path) + '/';
}
function untrailingslashit(path: string) {
return path.replace(/\/$/, '');
}
async function pushFiles({ remote, remote_path, local_path, includes, excludes }: PushFiles) {
excludes.global.push('wpt.json');
await rsync(trailingslashit(local_path), `${remote}:${trailingslashit(remote_path)}`, {
additionalFlags: `--no-links`,
includes: includes,
excludes: excludes,
})
}
export default async function () {
const config = await getConfig(await cwd());
const PATH_REMOTE = config.path.remote;
const PATH_LOCAL = config.path.local;
const REMOTE = config.ssh_host;
header(`Pushing files to ${config.domain.remote}...`);
if (ack("Push Files?")) {
await pushFiles({
remote: REMOTE,
remote_path: PATH_REMOTE,
local_path: PATH_LOCAL,
excludes: {
global: [...config.rsync.excludes.global, ...(config.rsync.on_push?.excludes?.global || [])],
paths: [...config.rsync.excludes.paths, ...(config.rsync.on_push?.excludes?.paths || [])],
},
includes: [...config.rsync.includes, ...(config.rsync.on_push?.includes || [])],
});
}
}