@jsenv/snapshot 1.2.6 → 1.2.7
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.
- package/package.json +1 -1
- package/src/cli.mjs +15 -6
package/package.json
CHANGED
package/src/cli.mjs
CHANGED
|
@@ -5,14 +5,14 @@ import { pathToFileURL } from "node:url";
|
|
|
5
5
|
import { clearDirectorySync } from "@jsenv/filesystem";
|
|
6
6
|
|
|
7
7
|
const options = {
|
|
8
|
-
|
|
9
|
-
type: "boolean",
|
|
10
|
-
},
|
|
11
|
-
"include-dev": {
|
|
8
|
+
help: {
|
|
12
9
|
type: "boolean",
|
|
13
10
|
},
|
|
14
11
|
};
|
|
15
|
-
const { values, positionals } = parseArgs({
|
|
12
|
+
const { values, positionals } = parseArgs({
|
|
13
|
+
options,
|
|
14
|
+
allowPositionals: true,
|
|
15
|
+
});
|
|
16
16
|
|
|
17
17
|
if (values.help || positionals.length === 0) {
|
|
18
18
|
console.log(`snapshot: Manage snapshot files generated during tests.
|
|
@@ -27,9 +27,10 @@ pattern: files matching this pattern will be removed; can use "*" and "**"
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
const commandHandlers = {
|
|
30
|
-
clear:
|
|
30
|
+
clear: (pattern) => {
|
|
31
31
|
const currentDirectoryPath = process.cwd();
|
|
32
32
|
const currentDirectoryUrl = pathToFileURL(`${currentDirectoryPath}/`);
|
|
33
|
+
console.log(`clear files matching ${pattern} in ${currentDirectoryPath}`);
|
|
33
34
|
clearDirectorySync(currentDirectoryUrl, pattern);
|
|
34
35
|
},
|
|
35
36
|
};
|
|
@@ -42,4 +43,12 @@ if (!commandHandler) {
|
|
|
42
43
|
process.exit(1);
|
|
43
44
|
}
|
|
44
45
|
|
|
46
|
+
if (commandHandler.length) {
|
|
47
|
+
const args = positionals.slice(1);
|
|
48
|
+
if (args.length === 0) {
|
|
49
|
+
console.error(`Error: "${command}" command expect arguments.`);
|
|
50
|
+
process.exit(1);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
45
54
|
await commandHandler(...positionals.slice(1));
|