@doki-land/nifty 0.0.2 → 0.0.3

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 (44) hide show
  1. package/README.md +29 -0
  2. package/cli/nifty.mjs +11 -11
  3. package/locales/en-US/cli.json +68 -64
  4. package/locales/locales.json +4 -4
  5. package/package.json +20 -16
  6. package/src/cli/authArgs.ts +52 -52
  7. package/src/cli/bump-cmd.ts +55 -55
  8. package/src/cli/bump.ts +237 -237
  9. package/src/cli/change-logs-cmd.ts +97 -97
  10. package/src/cli/cli.ts +47 -45
  11. package/src/cli/context.ts +36 -36
  12. package/src/cli/format-cmd.ts +23 -0
  13. package/src/cli/format.ts +28 -0
  14. package/src/cli/index.ts +9 -9
  15. package/src/cli/install-native-cmd.ts +22 -22
  16. package/src/cli/install-native.ts +80 -80
  17. package/src/cli/lint-cmd.ts +35 -33
  18. package/src/cli/lint.ts +102 -113
  19. package/src/cli/main.ts +1 -1
  20. package/src/cli/options.ts +40 -40
  21. package/src/cli/publish-cmd.ts +38 -34
  22. package/src/cli/publish.ts +95 -95
  23. package/src/cli/resolveNpm.ts +16 -16
  24. package/src/cli/retime-cmd.ts +62 -62
  25. package/src/cli/reword-cmd.ts +87 -87
  26. package/src/cli/trust-cmd.ts +38 -38
  27. package/src/cli/trust.ts +83 -83
  28. package/src/cli/update-cmd.ts +20 -20
  29. package/src/cli/update.ts +32 -185
  30. package/src/cli/upload-cmd.ts +44 -44
  31. package/src/cli/upload.ts +313 -313
  32. package/src/cli/workspace.ts +124 -124
  33. package/src/config/defineConfig.ts +12 -12
  34. package/src/config/detectProject.ts +189 -189
  35. package/src/config/index.ts +25 -25
  36. package/src/config/loadConfig.ts +129 -129
  37. package/src/config/types.ts +57 -57
  38. package/src/git.ts +61 -61
  39. package/src/github.ts +184 -184
  40. package/src/gitmoji.ts +77 -77
  41. package/src/index.ts +36 -36
  42. package/src/native.ts +665 -507
  43. package/src/nifty.ts +95 -95
  44. package/src/types.ts +40 -40
package/src/cli/update.ts CHANGED
@@ -1,185 +1,32 @@
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
- }
1
+ import { loadNiftyNative } from "../native.js";
2
+
3
+ export type UpdateOptions = {
4
+ interactive: boolean;
5
+ cwd?: string;
6
+ };
7
+
8
+ export async function runUpdate(argv: string[]): Promise<void> {
9
+ await updateWorkspace(parseUpdateArgs(argv));
10
+ }
11
+
12
+ export async function updateWorkspace(options: UpdateOptions): Promise<void> {
13
+ const native = loadNiftyNative();
14
+ native.updater.run({
15
+ cwd: options.cwd,
16
+ interactive: options.interactive,
17
+ });
18
+ }
19
+
20
+ function parseUpdateArgs(argv: string[]): UpdateOptions {
21
+ let interactive = false;
22
+ let cwd: string | undefined;
23
+ for (let i = 0; i < argv.length; i += 1) {
24
+ const arg = argv[i];
25
+ if (arg === "-i" || arg === "--interactive") {
26
+ interactive = true;
27
+ } else if (arg === "-C" || arg === "--cwd") {
28
+ cwd = argv[++i];
29
+ }
30
+ }
31
+ return { interactive, cwd };
32
+ }
@@ -1,44 +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
- }
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
+ }