-
Notifications
You must be signed in to change notification settings - Fork 13
/
cmd.js
executable file
·62 lines (56 loc) · 2.34 KB
/
cmd.js
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
60
61
62
#!/usr/bin/env node
'use strict';
const commander = require('commander');
const { sync: run, formatParams } = require('./index');
const actor = function actor({ srcDir, targetDir, options }, { quiet }) {
if (!quiet) {
console.log([
'',
'sync-directory cli: syncdir <srcDir> <targetDir> [options]',
` - srcDir: ${srcDir}`,
` - targetDir: ${targetDir}`,
` - watch: ${options.watch}`,
` - skipInitialSync: ${options.skipInitialSync}`,
` - deleteOrphaned: ${options.deleteOrphaned}`,
` - type: ${options.type}`,
` - exclude: ${options.exclude}`,
` - nodeep: ${options.nodeep}`,
` - supportSymlink: ${options.supportSymlink}`,
'',
].join('\n'));
}
run(srcDir, targetDir, {
...options,
cwd: process.cwd(),
afterEachSync({ eventType, relativePath }) {
if (!quiet) {
console.log(`${eventType}: `, relativePath);
}
},
});
};
commander
.version(require('./package.json').version, '-v, --version')
.arguments('<srcDir> <targetDir>')
.option('-w, --watch', 'Watch unnecessary changes')
.option('--quiet', 'disable logs')
.option('-si, --skipInitialSync', 'skip the first time sync actions')
.option('-do, --deleteOrphaned', 'delete orphaned files/folders in target folder')
.option('-symlink, --symlink', 'support symlink while sync running')
.option('-c, --copy', 'Sync with type `copy`, `copy` as default')
.option('-hardlink, --hardlink', 'Sync with type `hardlink`, `copy` as default')
.option('-e, --exclude <strings...>', 'Filter which src files should not be synced')
.option('-nd, --nodeep', 'Just walk the first level sub files/folders')
.action((srcDir, targetDir, options) => {
const standardParams = formatParams(srcDir, targetDir, {
watch: !!options.watch,
skipInitialSync: !!options.skipInitialSync,
deleteOrphaned: !!options.deleteOrphaned,
supportSymlink: !!options.symlink,
exclude: options.exclude,
nodeep: !!options.nodeep,
type: options.hardlink ? 'hardlink' : 'copy',
});
actor(standardParams, { quiet: options.quiet });
});
commander.parse(process.argv)