@doki-land/nifty 0.0.0 → 0.0.2

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.
Files changed (42) hide show
  1. package/cli/nifty.mjs +11 -11
  2. package/locales/en-US/cli.json +64 -0
  3. package/locales/locales.json +4 -0
  4. package/package.json +22 -19
  5. package/src/cli/authArgs.ts +52 -52
  6. package/src/cli/bump-cmd.ts +55 -0
  7. package/src/cli/bump.ts +237 -237
  8. package/src/cli/change-logs-cmd.ts +97 -0
  9. package/src/cli/cli.ts +45 -0
  10. package/src/cli/context.ts +36 -26
  11. package/src/cli/index.ts +9 -8
  12. package/src/cli/install-native-cmd.ts +22 -0
  13. package/src/cli/install-native.ts +80 -0
  14. package/src/cli/lint-cmd.ts +33 -0
  15. package/src/cli/lint.ts +113 -109
  16. package/src/cli/main.ts +1 -64
  17. package/src/cli/options.ts +40 -0
  18. package/src/cli/publish-cmd.ts +34 -0
  19. package/src/cli/publish.ts +95 -85
  20. package/src/cli/resolveNpm.ts +16 -16
  21. package/src/cli/retime-cmd.ts +62 -0
  22. package/src/cli/reword-cmd.ts +87 -0
  23. package/src/cli/trust-cmd.ts +38 -0
  24. package/src/cli/trust.ts +83 -77
  25. package/src/cli/update-cmd.ts +20 -0
  26. package/src/cli/update.ts +185 -182
  27. package/src/cli/upload-cmd.ts +44 -0
  28. package/src/cli/upload.ts +313 -280
  29. package/src/cli/workspace.ts +124 -124
  30. package/src/config/defineConfig.ts +12 -12
  31. package/src/config/detectProject.ts +189 -189
  32. package/src/config/index.ts +25 -25
  33. package/src/config/loadConfig.ts +129 -129
  34. package/src/config/types.ts +57 -43
  35. package/src/git.ts +61 -61
  36. package/src/github.ts +184 -184
  37. package/src/gitmoji.ts +77 -77
  38. package/src/index.ts +36 -36
  39. package/src/native.ts +507 -277
  40. package/src/nifty.ts +95 -95
  41. package/src/types.ts +40 -40
  42. package/Readme.md +0 -30
package/src/cli/update.ts CHANGED
@@ -1,182 +1,185 @@
1
- import { spawnSync } from "node:child_process";
2
- import { stdin as input, stdout as output } from "node:process";
3
- import { createInterface } from "node:readline/promises";
4
- import { dirname } from "node:path";
5
-
6
- import { detectProjectLayout, discoverPackageDirs } from "../config/detectProject.js";
7
-
8
- type UpdateOptions = {
9
- interactive: boolean;
10
- cwd?: string;
11
- };
12
-
13
- type CargoUpgrade = {
14
- crate: string;
15
- from: string;
16
- to: string;
17
- };
18
-
19
- type NpmOutdated = {
20
- name: string;
21
- current: string;
22
- wanted: string;
23
- latest: string;
24
- };
25
-
26
- export async function runUpdate(argv: string[]): Promise<void> {
27
- const options = parseUpdateArgs(argv);
28
- const cwd = options.cwd ?? process.cwd();
29
- const layout = detectProjectLayout(cwd);
30
-
31
- if (layout.kind === "unknown") {
32
- throw new Error(`no Cargo.toml or package.json found from ${cwd}`);
33
- }
34
-
35
- if (layout.kind === "cargo" || layout.kind === "hybrid") {
36
- await updateCargo(layout, options.interactive);
37
- }
38
- if (layout.kind === "npm" || layout.kind === "hybrid") {
39
- await updateNpm(layout, options.interactive);
40
- }
41
- }
42
-
43
- function parseUpdateArgs(argv: string[]): UpdateOptions {
44
- let interactive = false;
45
- let cwd: string | undefined;
46
- for (let i = 0; i < argv.length; i += 1) {
47
- const arg = argv[i];
48
- if (arg === "-i" || arg === "--interactive") {
49
- interactive = true;
50
- } else if (arg === "-C" || arg === "--cwd") {
51
- cwd = argv[++i];
52
- }
53
- }
54
- return { interactive, cwd };
55
- }
56
-
57
- function cargoRoot(layout: ReturnType<typeof detectProjectLayout>): string | undefined {
58
- return (
59
- layout.cargoWorkspaceRoot ??
60
- (layout.cargoManifest ? dirname(layout.cargoManifest) : undefined)
61
- );
62
- }
63
-
64
- async function updateCargo(layout: ReturnType<typeof detectProjectLayout>, interactive: boolean): Promise<void> {
65
- const root = cargoRoot(layout);
66
- if (!root) {
67
- throw new Error("cargo project not found");
68
- }
69
-
70
- const dry = spawnSync("cargo", ["upgrade", "--workspace", "--dry-run"], {
71
- cwd: root,
72
- encoding: "utf8",
73
- });
74
- const combined = `${dry.stdout ?? ""}${dry.stderr ?? ""}`;
75
- const upgrades = parseCargoUpgrades(combined);
76
- if (dry.status !== 0 && !combined.includes("no upgrades found") && upgrades.length === 0) {
77
- throw new Error(`cargo upgrade --dry-run failed:\n${combined}`);
78
- }
79
-
80
- if (upgrades.length === 0) {
81
- console.log("cargo: dependencies already up to date");
82
- return;
83
- }
84
-
85
- if (interactive) {
86
- const selected = await pickItems(
87
- "Select cargo upgrades",
88
- upgrades.map((item) => `${item.crate} ${item.from} -> ${item.to}`),
89
- );
90
- for (const index of selected) {
91
- const item = upgrades[index];
92
- run("cargo", ["upgrade", "--workspace", "-p", item.crate], root);
93
- }
94
- } else {
95
- run("cargo", ["upgrade", "--workspace"], root);
96
- }
97
- }
98
-
99
- async function updateNpm(layout: ReturnType<typeof detectProjectLayout>, interactive: boolean): Promise<void> {
100
- const packages = discoverPackageDirs(layout);
101
- if (packages.length === 0) {
102
- console.log("npm: no package.json directories found");
103
- return;
104
- }
105
- for (const packageDir of packages) {
106
- await updateNpmDir(packageDir, interactive);
107
- }
108
- }
109
-
110
- async function updateNpmDir(packageDir: string, interactive: boolean): Promise<void> {
111
- const outdated = listNpmOutdated(packageDir);
112
- if (outdated.length === 0) {
113
- console.log(`npm (${packageDir}): dependencies already up to date`);
114
- return;
115
- }
116
-
117
- if (interactive) {
118
- const selected = await pickItems(
119
- `Select npm upgrades (${packageDir})`,
120
- outdated.map((item) => `${item.name} ${item.current} -> ${item.wanted}`),
121
- );
122
- for (const index of selected) {
123
- const item = outdated[index];
124
- run("npm", ["install", `${item.name}@${item.wanted}`], packageDir);
125
- }
126
- } else {
127
- run("npm", ["update"], packageDir);
128
- }
129
- }
130
-
131
- function parseCargoUpgrades(text: string): CargoUpgrade[] {
132
- const upgrades: CargoUpgrade[] = [];
133
- for (const line of text.split(/\r?\n/)) {
134
- const match = line.match(/^\s*(\S+)\s+v(\S+)\s+->\s+v(\S+)/);
135
- if (match) {
136
- upgrades.push({ crate: match[1], from: match[2], to: match[3] });
137
- }
138
- }
139
- return upgrades;
140
- }
141
-
142
- function listNpmOutdated(packageDir: string): NpmOutdated[] {
143
- const result = spawnSync("npm", ["outdated", "--json"], { cwd: packageDir, encoding: "utf8" });
144
- if (!result.stdout?.trim()) {
145
- return [];
146
- }
147
- const parsed = JSON.parse(result.stdout) as Record<
148
- string,
149
- { current: string; wanted: string; latest: string }
150
- >;
151
- return Object.entries(parsed).map(([name, entry]) => ({
152
- name,
153
- current: entry.current,
154
- wanted: entry.wanted,
155
- latest: entry.latest,
156
- }));
157
- }
158
-
159
- async function pickItems(prompt: string, labels: string[]): Promise<number[]> {
160
- console.log(prompt);
161
- for (const [index, label] of labels.entries()) {
162
- console.log(` [${index}] ${label}`);
163
- }
164
- const rl = createInterface({ input, output });
165
- const answer = await rl.question("Indexes (comma-separated, empty = all): ");
166
- rl.close();
167
- const trimmed = answer.trim();
168
- if (!trimmed) {
169
- return labels.map((_, index) => index);
170
- }
171
- return trimmed
172
- .split(",")
173
- .map((part) => Number.parseInt(part.trim(), 10))
174
- .filter((index) => Number.isInteger(index) && index >= 0 && index < labels.length);
175
- }
176
-
177
- function run(command: string, args: string[], cwd: string): void {
178
- const result = spawnSync(command, args, { cwd, stdio: "inherit" });
179
- if (result.status !== 0) {
180
- throw new Error(`${command} ${args.join(" ")} failed`);
181
- }
182
- }
1
+ import { spawnSync } from "node:child_process";
2
+ import { stdin as input, stdout as output } from "node:process";
3
+ import { createInterface } from "node:readline/promises";
4
+ import { dirname } from "node:path";
5
+
6
+ import { detectProjectLayout, discoverPackageDirs } from "../config/detectProject.js";
7
+
8
+ type UpdateOptions = {
9
+ interactive: boolean;
10
+ cwd?: string;
11
+ };
12
+
13
+ type CargoUpgrade = {
14
+ crate: string;
15
+ from: string;
16
+ to: string;
17
+ };
18
+
19
+ type NpmOutdated = {
20
+ name: string;
21
+ current: string;
22
+ wanted: string;
23
+ latest: string;
24
+ };
25
+
26
+ export async function runUpdate(argv: string[]): Promise<void> {
27
+ await updateWorkspace(parseUpdateArgs(argv));
28
+ }
29
+
30
+ export async function updateWorkspace(options: UpdateOptions): Promise<void> {
31
+ const cwd = options.cwd ?? process.cwd();
32
+ const layout = detectProjectLayout(cwd);
33
+
34
+ if (layout.kind === "unknown") {
35
+ throw new Error(`no Cargo.toml or package.json found from ${cwd}`);
36
+ }
37
+
38
+ if (layout.kind === "cargo" || layout.kind === "hybrid") {
39
+ await updateCargo(layout, options.interactive);
40
+ }
41
+ if (layout.kind === "npm" || layout.kind === "hybrid") {
42
+ await updateNpm(layout, options.interactive);
43
+ }
44
+ }
45
+
46
+ function parseUpdateArgs(argv: string[]): UpdateOptions {
47
+ let interactive = false;
48
+ let cwd: string | undefined;
49
+ for (let i = 0; i < argv.length; i += 1) {
50
+ const arg = argv[i];
51
+ if (arg === "-i" || arg === "--interactive") {
52
+ interactive = true;
53
+ } else if (arg === "-C" || arg === "--cwd") {
54
+ cwd = argv[++i];
55
+ }
56
+ }
57
+ return { interactive, cwd };
58
+ }
59
+
60
+ function cargoRoot(layout: ReturnType<typeof detectProjectLayout>): string | undefined {
61
+ return (
62
+ layout.cargoWorkspaceRoot ??
63
+ (layout.cargoManifest ? dirname(layout.cargoManifest) : undefined)
64
+ );
65
+ }
66
+
67
+ async function updateCargo(layout: ReturnType<typeof detectProjectLayout>, interactive: boolean): Promise<void> {
68
+ const root = cargoRoot(layout);
69
+ if (!root) {
70
+ throw new Error("cargo project not found");
71
+ }
72
+
73
+ const dry = spawnSync("cargo", ["upgrade", "--workspace", "--dry-run"], {
74
+ cwd: root,
75
+ encoding: "utf8",
76
+ });
77
+ const combined = `${dry.stdout ?? ""}${dry.stderr ?? ""}`;
78
+ const upgrades = parseCargoUpgrades(combined);
79
+ if (dry.status !== 0 && !combined.includes("no upgrades found") && upgrades.length === 0) {
80
+ throw new Error(`cargo upgrade --dry-run failed:\n${combined}`);
81
+ }
82
+
83
+ if (upgrades.length === 0) {
84
+ console.log("cargo: dependencies already up to date");
85
+ return;
86
+ }
87
+
88
+ if (interactive) {
89
+ const selected = await pickItems(
90
+ "Select cargo upgrades",
91
+ upgrades.map((item) => `${item.crate} ${item.from} -> ${item.to}`),
92
+ );
93
+ for (const index of selected) {
94
+ const item = upgrades[index];
95
+ run("cargo", ["upgrade", "--workspace", "-p", item.crate], root);
96
+ }
97
+ } else {
98
+ run("cargo", ["upgrade", "--workspace"], root);
99
+ }
100
+ }
101
+
102
+ async function updateNpm(layout: ReturnType<typeof detectProjectLayout>, interactive: boolean): Promise<void> {
103
+ const packages = discoverPackageDirs(layout);
104
+ if (packages.length === 0) {
105
+ console.log("npm: no package.json directories found");
106
+ return;
107
+ }
108
+ for (const packageDir of packages) {
109
+ await updateNpmDir(packageDir, interactive);
110
+ }
111
+ }
112
+
113
+ async function updateNpmDir(packageDir: string, interactive: boolean): Promise<void> {
114
+ const outdated = listNpmOutdated(packageDir);
115
+ if (outdated.length === 0) {
116
+ console.log(`npm (${packageDir}): dependencies already up to date`);
117
+ return;
118
+ }
119
+
120
+ if (interactive) {
121
+ const selected = await pickItems(
122
+ `Select npm upgrades (${packageDir})`,
123
+ outdated.map((item) => `${item.name} ${item.current} -> ${item.wanted}`),
124
+ );
125
+ for (const index of selected) {
126
+ const item = outdated[index];
127
+ run("npm", ["install", `${item.name}@${item.wanted}`], packageDir);
128
+ }
129
+ } else {
130
+ run("npm", ["update"], packageDir);
131
+ }
132
+ }
133
+
134
+ function parseCargoUpgrades(text: string): CargoUpgrade[] {
135
+ const upgrades: CargoUpgrade[] = [];
136
+ for (const line of text.split(/\r?\n/)) {
137
+ const match = line.match(/^\s*(\S+)\s+v(\S+)\s+->\s+v(\S+)/);
138
+ if (match) {
139
+ upgrades.push({ crate: match[1], from: match[2], to: match[3] });
140
+ }
141
+ }
142
+ return upgrades;
143
+ }
144
+
145
+ function listNpmOutdated(packageDir: string): NpmOutdated[] {
146
+ const result = spawnSync("npm", ["outdated", "--json"], { cwd: packageDir, encoding: "utf8" });
147
+ if (!result.stdout?.trim()) {
148
+ return [];
149
+ }
150
+ const parsed = JSON.parse(result.stdout) as Record<
151
+ string,
152
+ { current: string; wanted: string; latest: string }
153
+ >;
154
+ return Object.entries(parsed).map(([name, entry]) => ({
155
+ name,
156
+ current: entry.current,
157
+ wanted: entry.wanted,
158
+ latest: entry.latest,
159
+ }));
160
+ }
161
+
162
+ async function pickItems(prompt: string, labels: string[]): Promise<number[]> {
163
+ console.log(prompt);
164
+ for (const [index, label] of labels.entries()) {
165
+ console.log(` [${index}] ${label}`);
166
+ }
167
+ const rl = createInterface({ input, output });
168
+ const answer = await rl.question("Indexes (comma-separated, empty = all): ");
169
+ rl.close();
170
+ const trimmed = answer.trim();
171
+ if (!trimmed) {
172
+ return labels.map((_, index) => index);
173
+ }
174
+ return trimmed
175
+ .split(",")
176
+ .map((part) => Number.parseInt(part.trim(), 10))
177
+ .filter((index) => Number.isInteger(index) && index >= 0 && index < labels.length);
178
+ }
179
+
180
+ function run(command: string, args: string[], cwd: string): void {
181
+ const result = spawnSync(command, args, { cwd, stdio: "inherit" });
182
+ if (result.status !== 0) {
183
+ throw new Error(`${command} ${args.join(" ")} failed`);
184
+ }
185
+ }
@@ -0,0 +1,44 @@
1
+ import type { Cli, ParsedOptions } from "@vmz/commander";
2
+
3
+ import { bootstrapFromOptions } from "./context.js";
4
+ import { uploadFromOptions } from "./upload.js";
5
+ import { cwdFrom, flag, str } from "./options.js";
6
+
7
+ export function registerUploadCommand(cli: Cli): void {
8
+ cli.command("upload", "cli.cmd.upload")
9
+ .option("--release", "cli.opt.release")
10
+ .option("--pages", "cli.opt.pages")
11
+ .option("--both", "cli.opt.both")
12
+ .option("-d, --dir <path>", "cli.opt.dir")
13
+ .option("-t, --tag <tag>", "cli.opt.tag")
14
+ .option("--repo <repo>", "cli.opt.repo")
15
+ .option("--token <token>", "cli.opt.token")
16
+ .option("--name <title>", "cli.opt.name")
17
+ .option("--notes <body>", "cli.opt.notes")
18
+ .option("--notes-file <path>", "cli.opt.notes-file")
19
+ .option("--draft", "cli.opt.draft")
20
+ .option("--no-generate-notes", "cli.opt.no-generate-notes")
21
+ .option("--github-action", "cli.opt.github-action")
22
+ .action(async (options) => cmdUpload(options));
23
+ }
24
+
25
+ export async function cmdUpload(options: ParsedOptions): Promise<number> {
26
+ await bootstrapFromOptions(options);
27
+ await uploadFromOptions({
28
+ release: flag(options, "release"),
29
+ pages: flag(options, "pages"),
30
+ both: flag(options, "both"),
31
+ dir: str(options, "dir") ?? "dist",
32
+ tag: str(options, "tag"),
33
+ repo: str(options, "repo"),
34
+ token: str(options, "token"),
35
+ name: str(options, "name"),
36
+ notes: str(options, "notes"),
37
+ notesFile: str(options, "notes-file"),
38
+ draft: flag(options, "draft"),
39
+ generateNotes: !flag(options, "no-generate-notes"),
40
+ githubAction: flag(options, "github-action"),
41
+ cwd: cwdFrom(options),
42
+ });
43
+ return 0;
44
+ }