-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcli.ts
More file actions
99 lines (94 loc) · 2.49 KB
/
Copy pathcli.ts
File metadata and controls
99 lines (94 loc) · 2.49 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/env node
import { readFileSync } from 'node:fs';
import { dirname, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
import { parseArgs } from 'cli-nano';
import { copyfiles } from './index.js';
import type { CopyFileOptions } from './interfaces.js';
function readPackage() {
const __dirname = dirname(fileURLToPath(import.meta.url));
const pkgPath = resolve(__dirname, '../package.json');
const pkg = readFileSync(pkgPath, 'utf8');
return JSON.parse(pkg);
}
function handleError(err?: Error) {
if (err) {
console.error(err);
process.exit(1);
} else {
process.exit(0);
}
}
try {
const results = parseArgs({
command: {
name: 'copyfiles',
description: 'Copy files from a source to a destination directory',
positionals: [
{
name: 'inFile',
description: 'Source file(s)',
type: 'string',
variadic: true,
required: true,
},
{
name: 'outDirectory',
description: 'Destination directory',
required: true,
},
],
},
options: {
all: {
alias: 'a',
type: 'boolean',
description: 'Include files & directories begining with a dot (.)',
},
dryRun: {
alias: 'd',
type: 'boolean',
description: 'Show what would be copied, but do not actually copy any files',
},
error: {
alias: 'E',
type: 'boolean',
description: 'Throw error if nothing is copied',
},
exclude: {
alias: 'e',
type: 'array',
description: 'Pattern or glob to exclude (may be passed multiple times)',
},
flat: {
alias: 'f',
type: 'boolean',
description: 'Flatten the output',
},
follow: {
alias: 'F',
type: 'boolean',
description: 'Follow symbolink links',
},
stat: {
alias: 's',
type: 'boolean',
description: 'Show statistics after execution (execution time + file count)',
},
up: {
alias: 'u',
type: 'number',
description: 'Slice a path off the bottom of the paths',
},
verbose: {
alias: 'V',
type: 'boolean',
description: 'Print more information to console',
},
},
version: readPackage().version,
});
copyfiles([...results.inFile, results.outDirectory], results as CopyFileOptions, err => handleError(err));
} catch (err) {
handleError(err as Error);
}