@doki-land/nifty 0.0.0 → 0.0.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/Readme.md +30 -30
- package/cli/nifty.mjs +11 -11
- package/locales/en-US/cli.json +41 -0
- package/locales/locales.json +4 -0
- package/package.json +13 -6
- package/src/cli/authArgs.ts +52 -52
- package/src/cli/bump-cmd.ts +55 -0
- package/src/cli/bump.ts +237 -237
- package/src/cli/cli.ts +39 -0
- package/src/cli/context.ts +36 -26
- package/src/cli/index.ts +9 -8
- package/src/cli/install-native-cmd.ts +22 -0
- package/src/cli/install-native.ts +80 -0
- package/src/cli/lint-cmd.ts +33 -0
- package/src/cli/lint.ts +113 -109
- package/src/cli/main.ts +1 -64
- package/src/cli/options.ts +40 -0
- package/src/cli/publish-cmd.ts +34 -0
- package/src/cli/publish.ts +95 -85
- package/src/cli/resolveNpm.ts +16 -16
- package/src/cli/trust-cmd.ts +35 -0
- package/src/cli/trust.ts +83 -77
- package/src/cli/update-cmd.ts +20 -0
- package/src/cli/update.ts +185 -182
- package/src/cli/upload-cmd.ts +44 -0
- package/src/cli/upload.ts +313 -280
- package/src/cli/workspace.ts +124 -124
- package/src/config/defineConfig.ts +12 -12
- package/src/config/detectProject.ts +189 -189
- package/src/config/index.ts +25 -25
- package/src/config/loadConfig.ts +129 -129
- package/src/config/types.ts +43 -43
- package/src/git.ts +61 -61
- package/src/github.ts +184 -184
- package/src/gitmoji.ts +77 -77
- package/src/index.ts +36 -36
- package/src/native.ts +284 -277
- package/src/nifty.ts +95 -95
- package/src/types.ts +40 -40
package/src/config/index.ts
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
export { defineConfig } from "./defineConfig.js";
|
|
2
|
-
export {
|
|
3
|
-
detectProjectLayout,
|
|
4
|
-
discoverPackageDirs,
|
|
5
|
-
findCargoManifest,
|
|
6
|
-
findPackageManifest,
|
|
7
|
-
type ProjectKind,
|
|
8
|
-
type ProjectLayout,
|
|
9
|
-
} from "./detectProject.js";
|
|
10
|
-
export {
|
|
11
|
-
authorMapToJson,
|
|
12
|
-
defaultConfigPath,
|
|
13
|
-
ensureConfigFile,
|
|
14
|
-
findConfigFile,
|
|
15
|
-
loadConfig,
|
|
16
|
-
type LoadConfigOptions,
|
|
17
|
-
type LoadedNiftyConfig,
|
|
18
|
-
} from "./loadConfig.js";
|
|
19
|
-
export {
|
|
20
|
-
CONFIG_FILE_NAMES,
|
|
21
|
-
type NiftyAuthorEntry,
|
|
22
|
-
type NiftyConfig,
|
|
23
|
-
type NiftyConfigEnv,
|
|
24
|
-
type NiftyConfigExport,
|
|
25
|
-
} from "./types.js";
|
|
1
|
+
export { defineConfig } from "./defineConfig.js";
|
|
2
|
+
export {
|
|
3
|
+
detectProjectLayout,
|
|
4
|
+
discoverPackageDirs,
|
|
5
|
+
findCargoManifest,
|
|
6
|
+
findPackageManifest,
|
|
7
|
+
type ProjectKind,
|
|
8
|
+
type ProjectLayout,
|
|
9
|
+
} from "./detectProject.js";
|
|
10
|
+
export {
|
|
11
|
+
authorMapToJson,
|
|
12
|
+
defaultConfigPath,
|
|
13
|
+
ensureConfigFile,
|
|
14
|
+
findConfigFile,
|
|
15
|
+
loadConfig,
|
|
16
|
+
type LoadConfigOptions,
|
|
17
|
+
type LoadedNiftyConfig,
|
|
18
|
+
} from "./loadConfig.js";
|
|
19
|
+
export {
|
|
20
|
+
CONFIG_FILE_NAMES,
|
|
21
|
+
type NiftyAuthorEntry,
|
|
22
|
+
type NiftyConfig,
|
|
23
|
+
type NiftyConfigEnv,
|
|
24
|
+
type NiftyConfigExport,
|
|
25
|
+
} from "./types.js";
|
package/src/config/loadConfig.ts
CHANGED
|
@@ -1,129 +1,129 @@
|
|
|
1
|
-
import { existsSync, writeFileSync } from "node:fs";
|
|
2
|
-
import { dirname, join, resolve } from "node:path";
|
|
3
|
-
import { createJiti } from "jiti";
|
|
4
|
-
|
|
5
|
-
import type { NiftyConfig, NiftyConfigEnv, NiftyConfigExport } from "./types.js";
|
|
6
|
-
import { CONFIG_FILE_NAMES } from "./types.js";
|
|
7
|
-
import { detectProjectLayout } from "./detectProject.js";
|
|
8
|
-
|
|
9
|
-
export type LoadConfigOptions = {
|
|
10
|
-
/** Directory to start searching from (defaults to `process.cwd()`). */
|
|
11
|
-
cwd?: string;
|
|
12
|
-
/** When set, skip searching and load this file directly. */
|
|
13
|
-
configFile?: string;
|
|
14
|
-
/** Passed to functional configs: `export default defineConfig(({ mode }) => ...)`. */
|
|
15
|
-
env?: Partial<NiftyConfigEnv>;
|
|
16
|
-
/**
|
|
17
|
-
* When true (default), write `nifty.config.ts` at the detected project root if missing.
|
|
18
|
-
* Set false for `--dry-run` so commands only report what would happen.
|
|
19
|
-
*/
|
|
20
|
-
createIfMissing?: boolean;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
export type LoadedNiftyConfig = {
|
|
24
|
-
config: NiftyConfig;
|
|
25
|
-
configFile?: string;
|
|
26
|
-
/** True when this run created a new config file. */
|
|
27
|
-
created?: boolean;
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
const DEFAULT_CONFIG_TEMPLATE = `// Nifty project configuration.
|
|
31
|
-
// See @doki-land/nifty for defineConfig, githubToken, authorMap, and lint rules.
|
|
32
|
-
export default {};
|
|
33
|
-
`;
|
|
34
|
-
|
|
35
|
-
const DEFAULT_ENV = (cwd: string): NiftyConfigEnv => ({
|
|
36
|
-
mode: process.env.NODE_ENV ?? "development",
|
|
37
|
-
command: "serve",
|
|
38
|
-
layout: detectProjectLayout(cwd),
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
/** Walk upward and return the nearest existing Nifty config file. */
|
|
42
|
-
export function findConfigFile(cwd = process.cwd()): string | undefined {
|
|
43
|
-
let here = resolve(cwd);
|
|
44
|
-
while (true) {
|
|
45
|
-
for (const name of CONFIG_FILE_NAMES) {
|
|
46
|
-
const candidate = join(here, name);
|
|
47
|
-
if (existsSync(candidate)) {
|
|
48
|
-
return candidate;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
const parent = dirname(here);
|
|
52
|
-
if (parent === here) {
|
|
53
|
-
return undefined;
|
|
54
|
-
}
|
|
55
|
-
here = parent;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/** Default config path at the detected project root (prefers `nifty.config.ts`). */
|
|
60
|
-
export function defaultConfigPath(cwd = process.cwd()): string {
|
|
61
|
-
const layout = detectProjectLayout(cwd);
|
|
62
|
-
return join(layout.root, CONFIG_FILE_NAMES[0]);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/** Warn and optionally create a default config when none exists. */
|
|
66
|
-
export function ensureConfigFile(options: { cwd?: string; create?: boolean } = {}): string | undefined {
|
|
67
|
-
const cwd = options.cwd ?? process.cwd();
|
|
68
|
-
const existing = findConfigFile(cwd);
|
|
69
|
-
if (existing) {
|
|
70
|
-
return existing;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
const target = defaultConfigPath(cwd);
|
|
74
|
-
if (options.create) {
|
|
75
|
-
writeFileSync(target, DEFAULT_CONFIG_TEMPLATE, "utf8");
|
|
76
|
-
console.warn(`nifty: no config found, created default ${target}`);
|
|
77
|
-
return target;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
console.warn(`nifty: no nifty.config.* found near ${detectProjectLayout(cwd).root} (using defaults)`);
|
|
81
|
-
return undefined;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
function normalizeExport(raw: unknown): NiftyConfigExport {
|
|
85
|
-
if (raw && typeof raw === "object" && "default" in raw) {
|
|
86
|
-
return (raw as { default: NiftyConfigExport }).default;
|
|
87
|
-
}
|
|
88
|
-
return raw as NiftyConfigExport;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
async function resolveExport(exported: NiftyConfigExport, env: NiftyConfigEnv): Promise<NiftyConfig> {
|
|
92
|
-
if (typeof exported === "function") {
|
|
93
|
-
return await exported(env);
|
|
94
|
-
}
|
|
95
|
-
return exported;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/** Load `nifty.config.ts/js`, creating a default file at the project root when missing. */
|
|
99
|
-
export async function loadConfig(options: LoadConfigOptions = {}): Promise<LoadedNiftyConfig> {
|
|
100
|
-
const cwd = options.cwd ?? process.cwd();
|
|
101
|
-
let configFile = options.configFile ?? findConfigFile(cwd);
|
|
102
|
-
let created = false;
|
|
103
|
-
|
|
104
|
-
if (!configFile && options.createIfMissing !== false) {
|
|
105
|
-
configFile = ensureConfigFile({ cwd, create: true });
|
|
106
|
-
created = Boolean(configFile);
|
|
107
|
-
} else if (!configFile) {
|
|
108
|
-
ensureConfigFile({ cwd, create: false });
|
|
109
|
-
return { config: {} };
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
if (!configFile) {
|
|
113
|
-
return { config: {} };
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
const env: NiftyConfigEnv = { ...DEFAULT_ENV(cwd), ...options.env };
|
|
117
|
-
const jiti = createJiti(import.meta.url, { interopDefault: true });
|
|
118
|
-
const mod = await jiti.import(configFile);
|
|
119
|
-
const config = await resolveExport(normalizeExport(mod), env);
|
|
120
|
-
return { config, configFile, created };
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
/** Serialize `authorMap` for native helpers expecting JSON text. */
|
|
124
|
-
export function authorMapToJson(authorMap: NiftyConfig["authorMap"]): string {
|
|
125
|
-
if (!authorMap || Object.keys(authorMap).length === 0) {
|
|
126
|
-
return "{}";
|
|
127
|
-
}
|
|
128
|
-
return JSON.stringify(authorMap);
|
|
129
|
-
}
|
|
1
|
+
import { existsSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { dirname, join, resolve } from "node:path";
|
|
3
|
+
import { createJiti } from "jiti";
|
|
4
|
+
|
|
5
|
+
import type { NiftyConfig, NiftyConfigEnv, NiftyConfigExport } from "./types.js";
|
|
6
|
+
import { CONFIG_FILE_NAMES } from "./types.js";
|
|
7
|
+
import { detectProjectLayout } from "./detectProject.js";
|
|
8
|
+
|
|
9
|
+
export type LoadConfigOptions = {
|
|
10
|
+
/** Directory to start searching from (defaults to `process.cwd()`). */
|
|
11
|
+
cwd?: string;
|
|
12
|
+
/** When set, skip searching and load this file directly. */
|
|
13
|
+
configFile?: string;
|
|
14
|
+
/** Passed to functional configs: `export default defineConfig(({ mode }) => ...)`. */
|
|
15
|
+
env?: Partial<NiftyConfigEnv>;
|
|
16
|
+
/**
|
|
17
|
+
* When true (default), write `nifty.config.ts` at the detected project root if missing.
|
|
18
|
+
* Set false for `--dry-run` so commands only report what would happen.
|
|
19
|
+
*/
|
|
20
|
+
createIfMissing?: boolean;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export type LoadedNiftyConfig = {
|
|
24
|
+
config: NiftyConfig;
|
|
25
|
+
configFile?: string;
|
|
26
|
+
/** True when this run created a new config file. */
|
|
27
|
+
created?: boolean;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const DEFAULT_CONFIG_TEMPLATE = `// Nifty project configuration.
|
|
31
|
+
// See @doki-land/nifty for defineConfig, githubToken, authorMap, and lint rules.
|
|
32
|
+
export default {};
|
|
33
|
+
`;
|
|
34
|
+
|
|
35
|
+
const DEFAULT_ENV = (cwd: string): NiftyConfigEnv => ({
|
|
36
|
+
mode: process.env.NODE_ENV ?? "development",
|
|
37
|
+
command: "serve",
|
|
38
|
+
layout: detectProjectLayout(cwd),
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
/** Walk upward and return the nearest existing Nifty config file. */
|
|
42
|
+
export function findConfigFile(cwd = process.cwd()): string | undefined {
|
|
43
|
+
let here = resolve(cwd);
|
|
44
|
+
while (true) {
|
|
45
|
+
for (const name of CONFIG_FILE_NAMES) {
|
|
46
|
+
const candidate = join(here, name);
|
|
47
|
+
if (existsSync(candidate)) {
|
|
48
|
+
return candidate;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
const parent = dirname(here);
|
|
52
|
+
if (parent === here) {
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
55
|
+
here = parent;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** Default config path at the detected project root (prefers `nifty.config.ts`). */
|
|
60
|
+
export function defaultConfigPath(cwd = process.cwd()): string {
|
|
61
|
+
const layout = detectProjectLayout(cwd);
|
|
62
|
+
return join(layout.root, CONFIG_FILE_NAMES[0]);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** Warn and optionally create a default config when none exists. */
|
|
66
|
+
export function ensureConfigFile(options: { cwd?: string; create?: boolean } = {}): string | undefined {
|
|
67
|
+
const cwd = options.cwd ?? process.cwd();
|
|
68
|
+
const existing = findConfigFile(cwd);
|
|
69
|
+
if (existing) {
|
|
70
|
+
return existing;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const target = defaultConfigPath(cwd);
|
|
74
|
+
if (options.create) {
|
|
75
|
+
writeFileSync(target, DEFAULT_CONFIG_TEMPLATE, "utf8");
|
|
76
|
+
console.warn(`nifty: no config found, created default ${target}`);
|
|
77
|
+
return target;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
console.warn(`nifty: no nifty.config.* found near ${detectProjectLayout(cwd).root} (using defaults)`);
|
|
81
|
+
return undefined;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function normalizeExport(raw: unknown): NiftyConfigExport {
|
|
85
|
+
if (raw && typeof raw === "object" && "default" in raw) {
|
|
86
|
+
return (raw as { default: NiftyConfigExport }).default;
|
|
87
|
+
}
|
|
88
|
+
return raw as NiftyConfigExport;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
async function resolveExport(exported: NiftyConfigExport, env: NiftyConfigEnv): Promise<NiftyConfig> {
|
|
92
|
+
if (typeof exported === "function") {
|
|
93
|
+
return await exported(env);
|
|
94
|
+
}
|
|
95
|
+
return exported;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** Load `nifty.config.ts/js`, creating a default file at the project root when missing. */
|
|
99
|
+
export async function loadConfig(options: LoadConfigOptions = {}): Promise<LoadedNiftyConfig> {
|
|
100
|
+
const cwd = options.cwd ?? process.cwd();
|
|
101
|
+
let configFile = options.configFile ?? findConfigFile(cwd);
|
|
102
|
+
let created = false;
|
|
103
|
+
|
|
104
|
+
if (!configFile && options.createIfMissing !== false) {
|
|
105
|
+
configFile = ensureConfigFile({ cwd, create: true });
|
|
106
|
+
created = Boolean(configFile);
|
|
107
|
+
} else if (!configFile) {
|
|
108
|
+
ensureConfigFile({ cwd, create: false });
|
|
109
|
+
return { config: {} };
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (!configFile) {
|
|
113
|
+
return { config: {} };
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const env: NiftyConfigEnv = { ...DEFAULT_ENV(cwd), ...options.env };
|
|
117
|
+
const jiti = createJiti(import.meta.url, { interopDefault: true });
|
|
118
|
+
const mod = await jiti.import(configFile);
|
|
119
|
+
const config = await resolveExport(normalizeExport(mod), env);
|
|
120
|
+
return { config, configFile, created };
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** Serialize `authorMap` for native helpers expecting JSON text. */
|
|
124
|
+
export function authorMapToJson(authorMap: NiftyConfig["authorMap"]): string {
|
|
125
|
+
if (!authorMap || Object.keys(authorMap).length === 0) {
|
|
126
|
+
return "{}";
|
|
127
|
+
}
|
|
128
|
+
return JSON.stringify(authorMap);
|
|
129
|
+
}
|
package/src/config/types.ts
CHANGED
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
/** GitHub author entry in `authorMap` (same shape as `author-github.json`). */
|
|
2
|
-
export type NiftyAuthorEntry = {
|
|
3
|
-
id?: number;
|
|
4
|
-
login?: string;
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
/** Nifty project configuration (`nifty.config.ts` / `nifty.config.js`). */
|
|
8
|
-
export type NiftyConfig = {
|
|
9
|
-
/** GitHub personal access token for email search / profile fetch. */
|
|
10
|
-
githubToken?: string;
|
|
11
|
-
/** Email → GitHub author mapping. */
|
|
12
|
-
authorMap?: Record<string, NiftyAuthorEntry>;
|
|
13
|
-
/** Repository root override when discovering git metadata. */
|
|
14
|
-
repoRoot?: string;
|
|
15
|
-
/** Cargo workspace / crate root override. */
|
|
16
|
-
cargoRoot?: string;
|
|
17
|
-
/** npm package root override. */
|
|
18
|
-
npmRoot?: string;
|
|
19
|
-
/** Rule-based lint configuration. */
|
|
20
|
-
lint?: {
|
|
21
|
-
rules?: Array<{
|
|
22
|
-
id: string;
|
|
23
|
-
enabled?: boolean;
|
|
24
|
-
severity?: "error" | "warning" | "info";
|
|
25
|
-
}>;
|
|
26
|
-
};
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
export type NiftyConfigExport = NiftyConfig | ((env: NiftyConfigEnv) => NiftyConfig | Promise<NiftyConfig>);
|
|
30
|
-
|
|
31
|
-
export type NiftyConfigEnv = {
|
|
32
|
-
mode: string;
|
|
33
|
-
command: string;
|
|
34
|
-
/** Detected cargo + npm project layout for hybrid monorepos. */
|
|
35
|
-
layout: import("./detectProject.js").ProjectLayout;
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
export const CONFIG_FILE_NAMES = [
|
|
39
|
-
"nifty.config.ts",
|
|
40
|
-
"nifty.config.js",
|
|
41
|
-
"nifty.config.mjs",
|
|
42
|
-
"nifty.config.cjs",
|
|
43
|
-
] as const;
|
|
1
|
+
/** GitHub author entry in `authorMap` (same shape as `author-github.json`). */
|
|
2
|
+
export type NiftyAuthorEntry = {
|
|
3
|
+
id?: number;
|
|
4
|
+
login?: string;
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
/** Nifty project configuration (`nifty.config.ts` / `nifty.config.js`). */
|
|
8
|
+
export type NiftyConfig = {
|
|
9
|
+
/** GitHub personal access token for email search / profile fetch. */
|
|
10
|
+
githubToken?: string;
|
|
11
|
+
/** Email → GitHub author mapping. */
|
|
12
|
+
authorMap?: Record<string, NiftyAuthorEntry>;
|
|
13
|
+
/** Repository root override when discovering git metadata. */
|
|
14
|
+
repoRoot?: string;
|
|
15
|
+
/** Cargo workspace / crate root override. */
|
|
16
|
+
cargoRoot?: string;
|
|
17
|
+
/** npm package root override. */
|
|
18
|
+
npmRoot?: string;
|
|
19
|
+
/** Rule-based lint configuration. */
|
|
20
|
+
lint?: {
|
|
21
|
+
rules?: Array<{
|
|
22
|
+
id: string;
|
|
23
|
+
enabled?: boolean;
|
|
24
|
+
severity?: "error" | "warning" | "info";
|
|
25
|
+
}>;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export type NiftyConfigExport = NiftyConfig | ((env: NiftyConfigEnv) => NiftyConfig | Promise<NiftyConfig>);
|
|
30
|
+
|
|
31
|
+
export type NiftyConfigEnv = {
|
|
32
|
+
mode: string;
|
|
33
|
+
command: string;
|
|
34
|
+
/** Detected cargo + npm project layout for hybrid monorepos. */
|
|
35
|
+
layout: import("./detectProject.js").ProjectLayout;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export const CONFIG_FILE_NAMES = [
|
|
39
|
+
"nifty.config.ts",
|
|
40
|
+
"nifty.config.js",
|
|
41
|
+
"nifty.config.mjs",
|
|
42
|
+
"nifty.config.cjs",
|
|
43
|
+
] as const;
|
package/src/git.ts
CHANGED
|
@@ -1,61 +1,61 @@
|
|
|
1
|
-
import type { CommitRecord, RangeInfo, TagInfo } from "./types.js";
|
|
2
|
-
import { loadNiftyNative, mapCommitRecord, mapRangeInfo, mapTagInfo, type GitExports } from "./native.js";
|
|
3
|
-
|
|
4
|
-
export type ResolveRangeOptions = {
|
|
5
|
-
version?: string;
|
|
6
|
-
fromRef?: string;
|
|
7
|
-
toRef?: string;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Read-only git repository helpers (gix via Node-API, no `git` subprocess).
|
|
12
|
-
*/
|
|
13
|
-
export class Git {
|
|
14
|
-
constructor(private readonly wasm: GitExports) {}
|
|
15
|
-
|
|
16
|
-
static open(): Git {
|
|
17
|
-
const native = loadNiftyNative();
|
|
18
|
-
return new Git(native.git);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/** Walk upward from `startPath` to find the working tree root containing `.git`. */
|
|
22
|
-
discoverRoot(startPath: string): string {
|
|
23
|
-
return this.wasm["discover-root"](startPath);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/** List `v*` tags sorted by semver. */
|
|
27
|
-
listVersionTags(repoRoot: string): string[] {
|
|
28
|
-
return this.wasm["list-version-tags"](repoRoot);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
listTagInfos(repoRoot: string): TagInfo[] {
|
|
32
|
-
return this.wasm["list-tag-infos"](repoRoot).map(mapTagInfo);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
formatTagList(repoRoot: string): string {
|
|
36
|
-
return this.wasm["format-tag-list"](repoRoot);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
resolveRange(repoRoot: string, options: ResolveRangeOptions = {}): RangeInfo {
|
|
40
|
-
return mapRangeInfo(
|
|
41
|
-
this.wasm["resolve-range"](repoRoot, options.version, options.fromRef, options.toRef),
|
|
42
|
-
);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/** Collect non-merge commits in `fromRef..toRef` (exclusive..inclusive). */
|
|
46
|
-
collectCommits(repoRoot: string, fromRef: string | undefined, toRef: string): CommitRecord[] {
|
|
47
|
-
return this.wasm["collect-commits"](repoRoot, fromRef, toRef).map(mapCommitRecord);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
detectGithubRepo(repoRoot: string): string | undefined {
|
|
51
|
-
return this.wasm["detect-github-repo"](repoRoot);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
parseGithubRemote(url: string): string | undefined {
|
|
55
|
-
return this.wasm["parse-github-remote"](url);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export function createGit(): Git {
|
|
60
|
-
return Git.open();
|
|
61
|
-
}
|
|
1
|
+
import type { CommitRecord, RangeInfo, TagInfo } from "./types.js";
|
|
2
|
+
import { loadNiftyNative, mapCommitRecord, mapRangeInfo, mapTagInfo, type GitExports } from "./native.js";
|
|
3
|
+
|
|
4
|
+
export type ResolveRangeOptions = {
|
|
5
|
+
version?: string;
|
|
6
|
+
fromRef?: string;
|
|
7
|
+
toRef?: string;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Read-only git repository helpers (gix via Node-API, no `git` subprocess).
|
|
12
|
+
*/
|
|
13
|
+
export class Git {
|
|
14
|
+
constructor(private readonly wasm: GitExports) {}
|
|
15
|
+
|
|
16
|
+
static open(): Git {
|
|
17
|
+
const native = loadNiftyNative();
|
|
18
|
+
return new Git(native.git);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** Walk upward from `startPath` to find the working tree root containing `.git`. */
|
|
22
|
+
discoverRoot(startPath: string): string {
|
|
23
|
+
return this.wasm["discover-root"](startPath);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** List `v*` tags sorted by semver. */
|
|
27
|
+
listVersionTags(repoRoot: string): string[] {
|
|
28
|
+
return this.wasm["list-version-tags"](repoRoot);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
listTagInfos(repoRoot: string): TagInfo[] {
|
|
32
|
+
return this.wasm["list-tag-infos"](repoRoot).map(mapTagInfo);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
formatTagList(repoRoot: string): string {
|
|
36
|
+
return this.wasm["format-tag-list"](repoRoot);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
resolveRange(repoRoot: string, options: ResolveRangeOptions = {}): RangeInfo {
|
|
40
|
+
return mapRangeInfo(
|
|
41
|
+
this.wasm["resolve-range"](repoRoot, options.version, options.fromRef, options.toRef),
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Collect non-merge commits in `fromRef..toRef` (exclusive..inclusive). */
|
|
46
|
+
collectCommits(repoRoot: string, fromRef: string | undefined, toRef: string): CommitRecord[] {
|
|
47
|
+
return this.wasm["collect-commits"](repoRoot, fromRef, toRef).map(mapCommitRecord);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
detectGithubRepo(repoRoot: string): string | undefined {
|
|
51
|
+
return this.wasm["detect-github-repo"](repoRoot);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
parseGithubRemote(url: string): string | undefined {
|
|
55
|
+
return this.wasm["parse-github-remote"](url);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function createGit(): Git {
|
|
60
|
+
return Git.open();
|
|
61
|
+
}
|