complete-cli 1.2.4 → 1.3.1
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/dist/commands/MetadataCommand.js +50 -0
- package/dist/main.js +2 -0
- package/package.json +6 -6
- package/src/commands/MetadataCommand.ts +69 -0
- package/src/main.ts +2 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Command, Option } from "clipanion";
|
|
2
|
+
import { assertObject, isObject } from "complete-common";
|
|
3
|
+
import { getFilePath, isFileAsync, readFileAsync, writeFileAsync, } from "complete-node";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
export class MetadataCommand extends Command {
|
|
6
|
+
static paths = [["metadata"], ["m"]];
|
|
7
|
+
// The first positional argument.
|
|
8
|
+
dependencyName = Option.String({
|
|
9
|
+
required: true,
|
|
10
|
+
});
|
|
11
|
+
reason = Option.String({
|
|
12
|
+
required: false,
|
|
13
|
+
});
|
|
14
|
+
static usage = Command.Usage({
|
|
15
|
+
description: 'Creates a "package-metadata.json" file to document locked dependencies. (The "update" command will respect the contents of this file.)',
|
|
16
|
+
});
|
|
17
|
+
async execute() {
|
|
18
|
+
const packageJSONPath = await getFilePath("package.json", undefined);
|
|
19
|
+
const packageRoot = path.dirname(packageJSONPath);
|
|
20
|
+
const packageMetadataPath = path.join(packageRoot, "package-metadata.json");
|
|
21
|
+
const packageMetadataExists = await isFileAsync(packageMetadataPath);
|
|
22
|
+
let packageMetadata;
|
|
23
|
+
if (packageMetadataExists) {
|
|
24
|
+
const packageMetadataContents = await readFileAsync(packageMetadataPath);
|
|
25
|
+
const packageMetadataUnknown = JSON.parse(packageMetadataContents);
|
|
26
|
+
assertObject(packageMetadataUnknown, `Failed to parse the metadata file at: ${packageMetadataPath}`);
|
|
27
|
+
packageMetadata = packageMetadataUnknown;
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
packageMetadata = {};
|
|
31
|
+
}
|
|
32
|
+
let dependencies;
|
|
33
|
+
if (isObject(packageMetadata["dependencies"])) {
|
|
34
|
+
// eslint-disable-next-line @typescript-eslint/prefer-destructuring
|
|
35
|
+
dependencies = packageMetadata["dependencies"];
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
dependencies = {};
|
|
39
|
+
packageMetadata["dependencies"] = dependencies;
|
|
40
|
+
}
|
|
41
|
+
dependencies[this.dependencyName] = {
|
|
42
|
+
"lock-version": true,
|
|
43
|
+
"lock-reason": this.reason ?? "",
|
|
44
|
+
};
|
|
45
|
+
const packageMetadataJSON = JSON.stringify(packageMetadata, undefined, 2);
|
|
46
|
+
await writeFileAsync(packageMetadataPath, packageMetadataJSON);
|
|
47
|
+
const verb = packageMetadataExists ? "modified" : "created";
|
|
48
|
+
console.log(`Successfully ${verb}: ${packageMetadataPath}`);
|
|
49
|
+
}
|
|
50
|
+
}
|
package/dist/main.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { Builtins, Cli } from "clipanion";
|
|
3
3
|
import { CheckCommand } from "./commands/CheckCommand.js";
|
|
4
4
|
import { InitCommand } from "./commands/InitCommand.js";
|
|
5
|
+
import { MetadataCommand } from "./commands/MetadataCommand.js";
|
|
5
6
|
import { NukeCommand } from "./commands/NukeCommand.js";
|
|
6
7
|
import { PublishCommand } from "./commands/PublishCommand.js";
|
|
7
8
|
import { UpdateCommand } from "./commands/UpdateCommand.js";
|
|
@@ -16,6 +17,7 @@ async function main() {
|
|
|
16
17
|
});
|
|
17
18
|
cli.register(CheckCommand);
|
|
18
19
|
cli.register(InitCommand);
|
|
20
|
+
cli.register(MetadataCommand);
|
|
19
21
|
cli.register(NukeCommand);
|
|
20
22
|
cli.register(PublishCommand);
|
|
21
23
|
cli.register(UpdateCommand);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "complete-cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"description": "A command line tool for bootstrapping TypeScript projects.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript"
|
|
@@ -35,20 +35,20 @@
|
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"@zamiell/clack-prompts": "0.10.2",
|
|
38
|
-
"chalk": "5.
|
|
38
|
+
"chalk": "5.5.0",
|
|
39
39
|
"clipanion": "4.0.0-rc.4",
|
|
40
40
|
"complete-common": "2.5.0",
|
|
41
|
-
"complete-node": "7.4.4
|
|
41
|
+
"complete-node": "7.4.4",
|
|
42
42
|
"klaw-sync": "7.0.0",
|
|
43
43
|
"yaml": "2.8.0"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@types/klaw-sync": "6.0.5",
|
|
47
|
-
"@types/node": "24.
|
|
47
|
+
"@types/node": "24.2.0",
|
|
48
48
|
"ts-loader": "9.5.2",
|
|
49
49
|
"tsconfig-paths-webpack-plugin": "4.2.0",
|
|
50
|
-
"typescript": "5.
|
|
51
|
-
"typescript-eslint": "8.
|
|
50
|
+
"typescript": "5.9.2",
|
|
51
|
+
"typescript-eslint": "8.39.0",
|
|
52
52
|
"webpack": "5.101.0",
|
|
53
53
|
"webpack-cli": "6.0.1",
|
|
54
54
|
"webpack-shebang-plugin": "1.1.8"
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { Command, Option } from "clipanion";
|
|
2
|
+
import { assertObject, isObject } from "complete-common";
|
|
3
|
+
import {
|
|
4
|
+
getFilePath,
|
|
5
|
+
isFileAsync,
|
|
6
|
+
readFileAsync,
|
|
7
|
+
writeFileAsync,
|
|
8
|
+
} from "complete-node";
|
|
9
|
+
import path from "node:path";
|
|
10
|
+
|
|
11
|
+
export class MetadataCommand extends Command {
|
|
12
|
+
static override paths = [["metadata"], ["m"]];
|
|
13
|
+
|
|
14
|
+
// The first positional argument.
|
|
15
|
+
dependencyName = Option.String({
|
|
16
|
+
required: true,
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
reason = Option.String({
|
|
20
|
+
required: false,
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
static override usage = Command.Usage({
|
|
24
|
+
description:
|
|
25
|
+
'Creates a "package-metadata.json" file to document locked dependencies. (The "update" command will respect the contents of this file.)',
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
async execute(): Promise<void> {
|
|
29
|
+
const packageJSONPath = await getFilePath("package.json", undefined);
|
|
30
|
+
const packageRoot = path.dirname(packageJSONPath);
|
|
31
|
+
const packageMetadataPath = path.join(packageRoot, "package-metadata.json");
|
|
32
|
+
const packageMetadataExists = await isFileAsync(packageMetadataPath);
|
|
33
|
+
|
|
34
|
+
let packageMetadata: Record<string, unknown>;
|
|
35
|
+
if (packageMetadataExists) {
|
|
36
|
+
const packageMetadataContents = await readFileAsync(packageMetadataPath);
|
|
37
|
+
const packageMetadataUnknown = JSON.parse(
|
|
38
|
+
packageMetadataContents,
|
|
39
|
+
) as unknown;
|
|
40
|
+
assertObject(
|
|
41
|
+
packageMetadataUnknown,
|
|
42
|
+
`Failed to parse the metadata file at: ${packageMetadataPath}`,
|
|
43
|
+
);
|
|
44
|
+
packageMetadata = packageMetadataUnknown;
|
|
45
|
+
} else {
|
|
46
|
+
packageMetadata = {};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
let dependencies: Record<string, unknown>;
|
|
50
|
+
if (isObject(packageMetadata["dependencies"])) {
|
|
51
|
+
// eslint-disable-next-line @typescript-eslint/prefer-destructuring
|
|
52
|
+
dependencies = packageMetadata["dependencies"];
|
|
53
|
+
} else {
|
|
54
|
+
dependencies = {};
|
|
55
|
+
packageMetadata["dependencies"] = dependencies;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
dependencies[this.dependencyName] = {
|
|
59
|
+
"lock-version": true,
|
|
60
|
+
"lock-reason": this.reason ?? "",
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const packageMetadataJSON = JSON.stringify(packageMetadata, undefined, 2);
|
|
64
|
+
await writeFileAsync(packageMetadataPath, packageMetadataJSON);
|
|
65
|
+
|
|
66
|
+
const verb = packageMetadataExists ? "modified" : "created";
|
|
67
|
+
console.log(`Successfully ${verb}: ${packageMetadataPath}`);
|
|
68
|
+
}
|
|
69
|
+
}
|
package/src/main.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import { Builtins, Cli } from "clipanion";
|
|
4
4
|
import { CheckCommand } from "./commands/CheckCommand.js";
|
|
5
5
|
import { InitCommand } from "./commands/InitCommand.js";
|
|
6
|
+
import { MetadataCommand } from "./commands/MetadataCommand.js";
|
|
6
7
|
import { NukeCommand } from "./commands/NukeCommand.js";
|
|
7
8
|
import { PublishCommand } from "./commands/PublishCommand.js";
|
|
8
9
|
import { UpdateCommand } from "./commands/UpdateCommand.js";
|
|
@@ -21,6 +22,7 @@ async function main() {
|
|
|
21
22
|
|
|
22
23
|
cli.register(CheckCommand);
|
|
23
24
|
cli.register(InitCommand);
|
|
25
|
+
cli.register(MetadataCommand);
|
|
24
26
|
cli.register(NukeCommand);
|
|
25
27
|
cli.register(PublishCommand);
|
|
26
28
|
cli.register(UpdateCommand);
|