-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathsync.mjs
55 lines (51 loc) · 1.14 KB
/
sync.mjs
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
/**
* Copies this project to the Raspberry Pi via rsync.
* Create a JSON file named "sync.config.json" that has these properties:
* - username
* - hostname
* - directory
* - quiet (optional)
*/
import chalk from 'chalk';
import Rsync from 'rsync';
import { readFile } from 'node:fs/promises';
const {
username,
hostname,
directory,
quiet = false,
} = JSON.parse(await readFile('./sync.config.json'));
// Build the command
const rsync = Rsync.build({
shell: 'ssh',
flags: 'ahP',
recursive: true,
exclude: [
'.git',
'.DS_Store',
'node_modules',
'build',
'package-lock.json',
'.vscode',
'dist',
],
source: process.cwd(),
destination: `${username}@${hostname}:${directory}`,
});
console.log(chalk.magenta(`\n🚀\t$ ${rsync.command()}`));
// Execute the command
rsync
.output(
data =>
quiet ||
console.log(
chalk.blue(`📤\t${data.toString().split('\n').slice(0, 1).join('')}`)
)
)
.execute((error, code) => {
if (error) {
console.error(chalk.red('👎\t', error));
} else {
console.log(chalk.green(`👍\tDone! [exit code ${code}]\n\n`));
}
});