@williamthorsen/nmr-core 0.4.0 → 0.6.0
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 +3 -3
- package/dist/esm/.cache +1 -1
- package/dist/esm/findPackageRoot.js +12 -15
- package/dist/esm/index.d.ts +7 -7
- package/dist/esm/index.js +6 -19
- package/dist/esm/parseArgs.d.ts +11 -2
- package/dist/esm/parseArgs.js +78 -85
- package/dist/esm/readPackageVersion.js +10 -13
- package/dist/esm/terminal.d.ts +6 -3
- package/dist/esm/terminal.js +53 -50
- package/dist/esm/writeFileWithCheck.js +39 -35
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -5,13 +5,13 @@ Shared utilities for node-monorepo-tools packages.
|
|
|
5
5
|
This package serves as the shared library foundation for the monorepo. For the nmr CLI tool, see [`@williamthorsen/nmr`](../nmr).
|
|
6
6
|
|
|
7
7
|
<!-- section:release-notes -->
|
|
8
|
-
## Release notes — v0.
|
|
8
|
+
## Release notes — v0.6.0 (2026-07-01)
|
|
9
9
|
|
|
10
10
|
### 🎉 Features
|
|
11
11
|
|
|
12
|
-
-
|
|
12
|
+
- 🚨 **Breaking:** Rebuild nmr-compile on a unified tsc emit (#455)
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
`nmr` now compiles a package's JavaScript and type declarations in one step, rewriting every import form — static, re-export, dynamic `import()`, bare side-effect, and tsconfig `paths` aliases — to runnable `.js` in both outputs. It now requires TypeScript 5.7 or newer as a peer dependency.
|
|
15
15
|
<!-- /section:release-notes -->
|
|
16
16
|
|
|
17
17
|
## Installation
|
package/dist/esm/.cache
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
6527d41fa47a32d6ecdb2ccb3a4414d730a2cd4b9ca6522babe60a12bac7acf1
|
|
@@ -1,17 +1,14 @@
|
|
|
1
|
-
import { existsSync } from
|
|
2
|
-
import { dirname, resolve } from
|
|
3
|
-
import { fileURLToPath } from
|
|
4
|
-
function findPackageRoot(fromUrl) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { dirname, resolve } from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
export function findPackageRoot(fromUrl) {
|
|
5
|
+
let dir = dirname(fileURLToPath(fromUrl));
|
|
6
|
+
while (!existsSync(resolve(dir, 'package.json'))) {
|
|
7
|
+
const parent = dirname(dir);
|
|
8
|
+
if (parent === dir) {
|
|
9
|
+
throw new Error('Could not find package root from ' + fromUrl);
|
|
10
|
+
}
|
|
11
|
+
dir = parent;
|
|
10
12
|
}
|
|
11
|
-
dir
|
|
12
|
-
}
|
|
13
|
-
return dir;
|
|
13
|
+
return dir;
|
|
14
14
|
}
|
|
15
|
-
export {
|
|
16
|
-
findPackageRoot
|
|
17
|
-
};
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export declare const PACKAGE_NAME = "@williamthorsen/nmr-core";
|
|
2
|
-
export { findPackageRoot } from './findPackageRoot.
|
|
3
|
-
export type { FlagDefinition, FlagSchema, ParsedArgs, ParsedFlags } from './parseArgs.
|
|
4
|
-
export { parseArgs,
|
|
5
|
-
export { readPackageVersion } from './readPackageVersion.
|
|
6
|
-
export { printError, printSkip, printStep, printSuccess, reportWriteResult } from './terminal.
|
|
7
|
-
export type { WriteOutcome, WriteResult } from './writeFileWithCheck.
|
|
8
|
-
export { writeFileWithCheck } from './writeFileWithCheck.
|
|
2
|
+
export { findPackageRoot } from './findPackageRoot.js';
|
|
3
|
+
export type { FlagDefinition, FlagSchema, ParseArgsOptions, ParsedArgs, ParsedFlags, ParseErrorKind, } from './parseArgs.js';
|
|
4
|
+
export { parseArgs, parseArgsOrExit, ParseError } from './parseArgs.js';
|
|
5
|
+
export { readPackageVersion } from './readPackageVersion.js';
|
|
6
|
+
export { formatErrorLine, printError, printSkip, printStep, printSuccess, reportError, reportWriteResult, } from './terminal.js';
|
|
7
|
+
export type { WriteOutcome, WriteResult } from './writeFileWithCheck.js';
|
|
8
|
+
export { writeFileWithCheck } from './writeFileWithCheck.js';
|
package/dist/esm/index.js
CHANGED
|
@@ -1,19 +1,6 @@
|
|
|
1
|
-
const PACKAGE_NAME =
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export {
|
|
8
|
-
PACKAGE_NAME,
|
|
9
|
-
findPackageRoot,
|
|
10
|
-
parseArgs,
|
|
11
|
-
printError,
|
|
12
|
-
printSkip,
|
|
13
|
-
printStep,
|
|
14
|
-
printSuccess,
|
|
15
|
-
readPackageVersion,
|
|
16
|
-
reportWriteResult,
|
|
17
|
-
translateParseError,
|
|
18
|
-
writeFileWithCheck
|
|
19
|
-
};
|
|
1
|
+
export const PACKAGE_NAME = '@williamthorsen/nmr-core';
|
|
2
|
+
export { findPackageRoot } from "./findPackageRoot.js";
|
|
3
|
+
export { parseArgs, parseArgsOrExit, ParseError } from "./parseArgs.js";
|
|
4
|
+
export { readPackageVersion } from "./readPackageVersion.js";
|
|
5
|
+
export { formatErrorLine, printError, printSkip, printStep, printSuccess, reportError, reportWriteResult, } from "./terminal.js";
|
|
6
|
+
export { writeFileWithCheck } from "./writeFileWithCheck.js";
|
package/dist/esm/parseArgs.d.ts
CHANGED
|
@@ -11,5 +11,14 @@ export interface ParsedArgs<S extends FlagSchema> {
|
|
|
11
11
|
flags: ParsedFlags<S>;
|
|
12
12
|
positionals: string[];
|
|
13
13
|
}
|
|
14
|
-
export
|
|
15
|
-
|
|
14
|
+
export interface ParseArgsOptions {
|
|
15
|
+
allowPositionals?: boolean;
|
|
16
|
+
}
|
|
17
|
+
export type ParseErrorKind = 'unknown-flag' | 'missing-value' | 'unexpected-value' | 'unexpected-positional';
|
|
18
|
+
export declare class ParseError extends Error {
|
|
19
|
+
readonly kind: ParseErrorKind;
|
|
20
|
+
readonly flag: string;
|
|
21
|
+
constructor(kind: ParseErrorKind, flag: string);
|
|
22
|
+
}
|
|
23
|
+
export declare function parseArgs<S extends FlagSchema>(argv: string[], schema: S, options?: ParseArgsOptions): ParsedArgs<S>;
|
|
24
|
+
export declare function parseArgsOrExit<S extends FlagSchema>(argv: string[], schema: S, options?: ParseArgsOptions): ParsedArgs<S>;
|
package/dist/esm/parseArgs.js
CHANGED
|
@@ -1,93 +1,86 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
if (value === "") {
|
|
13
|
-
throw new Error(`${longFlag} requires a value`);
|
|
14
|
-
}
|
|
15
|
-
return { key, value };
|
|
16
|
-
}
|
|
17
|
-
function handleBareFlag(arg, index, argv, longToKey, shortToKey, definitions) {
|
|
18
|
-
const key = longToKey.get(arg) ?? shortToKey.get(arg);
|
|
19
|
-
if (key === void 0) {
|
|
20
|
-
throw new Error(`unknown flag '${arg}'`);
|
|
21
|
-
}
|
|
22
|
-
const def = definitions.get(key);
|
|
23
|
-
if (def?.type === "boolean") {
|
|
24
|
-
return { key, value: true, advance: 0 };
|
|
25
|
-
}
|
|
26
|
-
const next = argv[index + 1];
|
|
27
|
-
if (next === void 0 || next.startsWith("-") && next !== "-") {
|
|
28
|
-
throw new Error(`${def?.long} requires a value`);
|
|
29
|
-
}
|
|
30
|
-
return { key, value: next, advance: 1 };
|
|
31
|
-
}
|
|
32
|
-
function buildLookupTables(schema) {
|
|
33
|
-
const longToKey = /* @__PURE__ */ new Map();
|
|
34
|
-
const shortToKey = /* @__PURE__ */ new Map();
|
|
35
|
-
const definitions = /* @__PURE__ */ new Map();
|
|
36
|
-
for (const [key, def] of Object.entries(schema)) {
|
|
37
|
-
longToKey.set(def.long, key);
|
|
38
|
-
definitions.set(key, def);
|
|
39
|
-
if (def.short !== void 0) {
|
|
40
|
-
shortToKey.set(def.short, key);
|
|
1
|
+
import process from 'node:process';
|
|
2
|
+
import { parseArgs as nodeParseArgs } from 'node:util';
|
|
3
|
+
import { reportError } from "./terminal.js";
|
|
4
|
+
export class ParseError extends Error {
|
|
5
|
+
kind;
|
|
6
|
+
flag;
|
|
7
|
+
constructor(kind, flag) {
|
|
8
|
+
super(formatParseErrorMessage(kind, flag));
|
|
9
|
+
this.name = 'ParseError';
|
|
10
|
+
this.kind = kind;
|
|
11
|
+
this.flag = flag;
|
|
41
12
|
}
|
|
42
|
-
}
|
|
43
|
-
return { longToKey, shortToKey, definitions };
|
|
44
13
|
}
|
|
45
|
-
function
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
if (pastDelimiter) {
|
|
56
|
-
positionals.push(arg);
|
|
57
|
-
continue;
|
|
14
|
+
export function parseArgs(argv, schema, options = {}) {
|
|
15
|
+
const nodeOptions = {};
|
|
16
|
+
const byName = new Map();
|
|
17
|
+
const flags = {};
|
|
18
|
+
for (const [key, def] of Object.entries(schema)) {
|
|
19
|
+
const name = def.long.replace(/^--/, '');
|
|
20
|
+
nodeOptions[name] =
|
|
21
|
+
def.short === undefined ? { type: def.type } : { type: def.type, short: def.short.replace(/^-/, '') };
|
|
22
|
+
byName.set(name, { key, def });
|
|
23
|
+
flags[key] = def.type === 'boolean' ? false : undefined;
|
|
58
24
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
25
|
+
const { tokens } = nodeParseArgs({
|
|
26
|
+
args: argv,
|
|
27
|
+
options: nodeOptions,
|
|
28
|
+
strict: false,
|
|
29
|
+
allowPositionals: true,
|
|
30
|
+
tokens: true,
|
|
31
|
+
});
|
|
32
|
+
const positionals = [];
|
|
33
|
+
for (const token of tokens) {
|
|
34
|
+
if (token.kind === 'positional') {
|
|
35
|
+
if (options.allowPositionals !== true) {
|
|
36
|
+
throw new ParseError('unexpected-positional', token.value);
|
|
37
|
+
}
|
|
38
|
+
positionals.push(token.value);
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
if (token.kind !== 'option') {
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
const entry = byName.get(token.name);
|
|
45
|
+
if (entry === undefined) {
|
|
46
|
+
throw new ParseError('unknown-flag', token.rawName);
|
|
47
|
+
}
|
|
48
|
+
if (entry.def.type === 'boolean') {
|
|
49
|
+
if (token.value !== undefined) {
|
|
50
|
+
throw new ParseError('unexpected-value', token.rawName);
|
|
51
|
+
}
|
|
52
|
+
flags[entry.key] = true;
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
const value = token.value;
|
|
56
|
+
if (value === undefined || value === '' || (!token.inlineValue && value.startsWith('-') && value !== '-')) {
|
|
57
|
+
throw new ParseError('missing-value', token.rawName);
|
|
58
|
+
}
|
|
59
|
+
flags[entry.key] = value;
|
|
62
60
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
61
|
+
return { flags, positionals };
|
|
62
|
+
}
|
|
63
|
+
export function parseArgsOrExit(argv, schema, options = {}) {
|
|
64
|
+
try {
|
|
65
|
+
return parseArgs(argv, schema, options);
|
|
68
66
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
67
|
+
catch (error) {
|
|
68
|
+
if (error instanceof ParseError) {
|
|
69
|
+
reportError(error.message);
|
|
70
|
+
process.exit(1);
|
|
71
|
+
}
|
|
72
|
+
throw error;
|
|
74
73
|
}
|
|
75
|
-
positionals.push(arg);
|
|
76
|
-
}
|
|
77
|
-
return { flags, positionals };
|
|
78
74
|
}
|
|
79
|
-
function
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
75
|
+
function formatParseErrorMessage(kind, flag) {
|
|
76
|
+
switch (kind) {
|
|
77
|
+
case 'unknown-flag':
|
|
78
|
+
return `Unknown option: ${flag}`;
|
|
79
|
+
case 'missing-value':
|
|
80
|
+
return `Missing value for option: ${flag}`;
|
|
81
|
+
case 'unexpected-value':
|
|
82
|
+
return `Option does not accept a value: ${flag}`;
|
|
83
|
+
case 'unexpected-positional':
|
|
84
|
+
return `Unexpected positional argument: ${flag}`;
|
|
85
|
+
}
|
|
89
86
|
}
|
|
90
|
-
export {
|
|
91
|
-
parseArgs,
|
|
92
|
-
translateParseError
|
|
93
|
-
};
|
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
import { readFileSync } from
|
|
2
|
-
import { resolve } from
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { resolve } from 'node:path';
|
|
3
3
|
import { findPackageRoot } from "./findPackageRoot.js";
|
|
4
|
-
function readPackageVersion(fromUrl) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
4
|
+
export function readPackageVersion(fromUrl) {
|
|
5
|
+
const root = findPackageRoot(fromUrl);
|
|
6
|
+
const packageJsonPath = resolve(root, 'package.json');
|
|
7
|
+
const raw = JSON.parse(readFileSync(packageJsonPath, 'utf8'));
|
|
8
|
+
if (typeof raw !== 'object' || raw === null || !('version' in raw) || typeof raw.version !== 'string') {
|
|
9
|
+
throw new Error(`No string "version" field in ${packageJsonPath}`);
|
|
10
|
+
}
|
|
11
|
+
return raw.version;
|
|
12
12
|
}
|
|
13
|
-
export {
|
|
14
|
-
readPackageVersion
|
|
15
|
-
};
|
package/dist/esm/terminal.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Writable } from 'node:stream';
|
|
2
|
+
import type { WriteResult } from './writeFileWithCheck.js';
|
|
3
|
+
export declare function formatErrorLine(message: string): string;
|
|
4
|
+
export declare function printError(message: string): void;
|
|
5
|
+
export declare function printSkip(message: string): void;
|
|
2
6
|
export declare function printStep(message: string): void;
|
|
3
7
|
export declare function printSuccess(message: string): void;
|
|
4
|
-
export declare function
|
|
5
|
-
export declare function printError(message: string): void;
|
|
8
|
+
export declare function reportError(message: string, stream?: Writable): void;
|
|
6
9
|
export declare function reportWriteResult(result: WriteResult, dryRun: boolean): void;
|
package/dist/esm/terminal.js
CHANGED
|
@@ -1,55 +1,58 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import process from 'node:process';
|
|
2
|
+
export function formatErrorLine(message) {
|
|
3
|
+
return `Error: ${message}`;
|
|
4
4
|
}
|
|
5
|
-
function
|
|
6
|
-
|
|
5
|
+
export function printError(message) {
|
|
6
|
+
process.stderr.write(` ❌ ${message}\n`);
|
|
7
7
|
}
|
|
8
|
-
function printSkip(message) {
|
|
9
|
-
|
|
8
|
+
export function printSkip(message) {
|
|
9
|
+
console.info(` ⚠️ ${message}`);
|
|
10
10
|
}
|
|
11
|
-
function
|
|
12
|
-
|
|
11
|
+
export function printStep(message) {
|
|
12
|
+
console.info(`\n> ${message}`);
|
|
13
13
|
}
|
|
14
|
-
function
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
14
|
+
export function printSuccess(message) {
|
|
15
|
+
console.info(` ✅ ${message}`);
|
|
16
|
+
}
|
|
17
|
+
export function reportError(message, stream = process.stderr) {
|
|
18
|
+
stream.write(`${formatErrorLine(message)}\n`);
|
|
19
|
+
}
|
|
20
|
+
export function reportWriteResult(result, dryRun) {
|
|
21
|
+
switch (result.outcome) {
|
|
22
|
+
case 'created':
|
|
23
|
+
if (dryRun) {
|
|
24
|
+
printSuccess(`[dry-run] Would create ${result.filePath}`);
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
printSuccess(`Created ${result.filePath}`);
|
|
28
|
+
}
|
|
29
|
+
break;
|
|
30
|
+
case 'overwritten':
|
|
31
|
+
if (dryRun) {
|
|
32
|
+
printSuccess(`[dry-run] Would overwrite ${result.filePath}`);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
printSuccess(`Overwrote ${result.filePath}`);
|
|
36
|
+
}
|
|
37
|
+
break;
|
|
38
|
+
case 'up-to-date':
|
|
39
|
+
printSuccess(`${result.filePath} (up to date)`);
|
|
40
|
+
break;
|
|
41
|
+
case 'skipped':
|
|
42
|
+
if (result.error) {
|
|
43
|
+
printSkip(`${result.filePath} (could not read for comparison: ${result.error})`);
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
printSkip(`${result.filePath} (already exists)`);
|
|
47
|
+
}
|
|
48
|
+
break;
|
|
49
|
+
case 'failed':
|
|
50
|
+
if (result.error) {
|
|
51
|
+
printError(`Failed to write ${result.filePath}: ${result.error}`);
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
printError(`Failed to write ${result.filePath}`);
|
|
55
|
+
}
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
48
58
|
}
|
|
49
|
-
export {
|
|
50
|
-
printError,
|
|
51
|
-
printSkip,
|
|
52
|
-
printStep,
|
|
53
|
-
printSuccess,
|
|
54
|
-
reportWriteResult
|
|
55
|
-
};
|
|
@@ -1,41 +1,45 @@
|
|
|
1
|
-
import { existsSync, mkdirSync, readFileSync, writeFileSync } from
|
|
2
|
-
import { dirname } from
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { dirname } from 'node:path';
|
|
3
3
|
function normalizeTrailingWhitespace(content) {
|
|
4
|
-
|
|
4
|
+
return content
|
|
5
|
+
.split('\n')
|
|
6
|
+
.map((line) => line.trimEnd())
|
|
7
|
+
.join('\n')
|
|
8
|
+
.trimEnd();
|
|
5
9
|
}
|
|
6
|
-
function writeFileWithCheck(filePath, content, options) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
+
export function writeFileWithCheck(filePath, content, options) {
|
|
11
|
+
const { dryRun, overwrite } = options;
|
|
12
|
+
const fileExists = existsSync(filePath);
|
|
13
|
+
if (fileExists && !overwrite) {
|
|
14
|
+
try {
|
|
15
|
+
const existing = readFileSync(filePath, 'utf8');
|
|
16
|
+
if (normalizeTrailingWhitespace(existing) === normalizeTrailingWhitespace(content)) {
|
|
17
|
+
return { filePath, outcome: 'up-to-date' };
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
22
|
+
return { filePath, outcome: 'skipped', error: message };
|
|
23
|
+
}
|
|
24
|
+
return { filePath, outcome: 'skipped' };
|
|
25
|
+
}
|
|
26
|
+
const outcome = fileExists ? 'overwritten' : 'created';
|
|
27
|
+
if (dryRun) {
|
|
28
|
+
return { filePath, outcome };
|
|
29
|
+
}
|
|
30
|
+
try {
|
|
31
|
+
mkdirSync(dirname(filePath), { recursive: true });
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
35
|
+
return { filePath, outcome: 'failed', error: message };
|
|
36
|
+
}
|
|
10
37
|
try {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
17
|
-
return { filePath, outcome: "skipped", error: message };
|
|
38
|
+
writeFileSync(filePath, content, 'utf8');
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
42
|
+
return { filePath, outcome: 'failed', error: message };
|
|
18
43
|
}
|
|
19
|
-
return { filePath, outcome: "skipped" };
|
|
20
|
-
}
|
|
21
|
-
const outcome = fileExists ? "overwritten" : "created";
|
|
22
|
-
if (dryRun) {
|
|
23
44
|
return { filePath, outcome };
|
|
24
|
-
}
|
|
25
|
-
try {
|
|
26
|
-
mkdirSync(dirname(filePath), { recursive: true });
|
|
27
|
-
} catch (error) {
|
|
28
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
29
|
-
return { filePath, outcome: "failed", error: message };
|
|
30
|
-
}
|
|
31
|
-
try {
|
|
32
|
-
writeFileSync(filePath, content, "utf8");
|
|
33
|
-
} catch (error) {
|
|
34
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
35
|
-
return { filePath, outcome: "failed", error: message };
|
|
36
|
-
}
|
|
37
|
-
return { filePath, outcome };
|
|
38
45
|
}
|
|
39
|
-
export {
|
|
40
|
-
writeFileWithCheck
|
|
41
|
-
};
|