@williamthorsen/preflight 0.2.0 → 0.3.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/dist/esm/.cache
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
0c229676e52104b716c0f727df6151f36cf71cdb51efc78a6f2e985688b2310e
|
|
@@ -1,19 +1,21 @@
|
|
|
1
|
-
import { printError, printStep } from "
|
|
1
|
+
import { printError, printStep, reportWriteResult } from "@williamthorsen/node-monorepo-core";
|
|
2
2
|
import { scaffoldConfig } from "./scaffold.js";
|
|
3
3
|
function initCommand({ dryRun, force }) {
|
|
4
4
|
if (dryRun) {
|
|
5
5
|
console.info("[dry-run mode]");
|
|
6
6
|
}
|
|
7
7
|
printStep("Scaffolding config");
|
|
8
|
+
let result;
|
|
8
9
|
try {
|
|
9
|
-
|
|
10
|
-
if (!ok) {
|
|
11
|
-
return 1;
|
|
12
|
-
}
|
|
10
|
+
result = scaffoldConfig({ dryRun, force });
|
|
13
11
|
} catch (error) {
|
|
14
12
|
printError(`Failed to scaffold config: ${error instanceof Error ? error.message : String(error)}`);
|
|
15
13
|
return 1;
|
|
16
14
|
}
|
|
15
|
+
reportWriteResult(result, dryRun);
|
|
16
|
+
if (result.outcome === "failed") {
|
|
17
|
+
return 1;
|
|
18
|
+
}
|
|
17
19
|
if (!dryRun) {
|
|
18
20
|
printStep("Next steps");
|
|
19
21
|
console.info(`
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import type { WriteResult } from '@williamthorsen/node-monorepo-core';
|
|
1
2
|
interface ScaffoldOptions {
|
|
2
3
|
dryRun: boolean;
|
|
3
4
|
force: boolean;
|
|
4
5
|
}
|
|
5
|
-
export declare function scaffoldConfig({ dryRun, force }: ScaffoldOptions):
|
|
6
|
+
export declare function scaffoldConfig({ dryRun, force }: ScaffoldOptions): WriteResult;
|
|
6
7
|
export {};
|
|
@@ -1,62 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { dirname } from "node:path";
|
|
3
|
-
import { printError, printSkip, printSuccess } from "../lib/terminal.js";
|
|
1
|
+
import { writeFileWithCheck } from "@williamthorsen/node-monorepo-core";
|
|
4
2
|
import { preflightConfigTemplate } from "./templates.js";
|
|
5
3
|
const CONFIG_PATH = ".config/preflight.config.ts";
|
|
6
|
-
function normalizeTrailingWhitespace(content) {
|
|
7
|
-
return content.split("\n").map((line) => line.trimEnd()).join("\n").trimEnd();
|
|
8
|
-
}
|
|
9
|
-
function tryWriteFile(filePath, content) {
|
|
10
|
-
try {
|
|
11
|
-
writeFileSync(filePath, content, "utf8");
|
|
12
|
-
return true;
|
|
13
|
-
} catch (error) {
|
|
14
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
15
|
-
printError(`Failed to write ${filePath}: ${message}`);
|
|
16
|
-
return false;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
function writeIfAbsent(filePath, content, dryRun, overwrite) {
|
|
20
|
-
const fileAlreadyExists = existsSync(filePath);
|
|
21
|
-
if (fileAlreadyExists && !overwrite) {
|
|
22
|
-
try {
|
|
23
|
-
const existing = readFileSync(filePath, "utf8");
|
|
24
|
-
if (normalizeTrailingWhitespace(existing) === normalizeTrailingWhitespace(content)) {
|
|
25
|
-
printSuccess(`${filePath} (up to date)`);
|
|
26
|
-
return true;
|
|
27
|
-
}
|
|
28
|
-
} catch (error) {
|
|
29
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
30
|
-
printError(`Could not read ${filePath}: ${message}`);
|
|
31
|
-
}
|
|
32
|
-
if (dryRun) {
|
|
33
|
-
printSkip(`[dry-run] Would skip ${filePath} (already exists)`);
|
|
34
|
-
} else {
|
|
35
|
-
printSkip(`${filePath} (already exists)`);
|
|
36
|
-
}
|
|
37
|
-
return true;
|
|
38
|
-
}
|
|
39
|
-
if (dryRun) {
|
|
40
|
-
const verb = fileAlreadyExists ? "overwrite" : "create";
|
|
41
|
-
printSuccess(`[dry-run] Would ${verb} ${filePath}`);
|
|
42
|
-
return true;
|
|
43
|
-
}
|
|
44
|
-
try {
|
|
45
|
-
mkdirSync(dirname(filePath), { recursive: true });
|
|
46
|
-
} catch (error) {
|
|
47
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
48
|
-
printError(`Failed to create directory for ${filePath}: ${message}`);
|
|
49
|
-
return false;
|
|
50
|
-
}
|
|
51
|
-
if (tryWriteFile(filePath, content)) {
|
|
52
|
-
const verb = fileAlreadyExists ? "Overwrote" : "Created";
|
|
53
|
-
printSuccess(`${verb} ${filePath}`);
|
|
54
|
-
return true;
|
|
55
|
-
}
|
|
56
|
-
return false;
|
|
57
|
-
}
|
|
58
4
|
function scaffoldConfig({ dryRun, force }) {
|
|
59
|
-
return
|
|
5
|
+
return writeFileWithCheck(CONFIG_PATH, preflightConfigTemplate, { dryRun, overwrite: force });
|
|
60
6
|
}
|
|
61
7
|
export {
|
|
62
8
|
scaffoldConfig
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@williamthorsen/preflight",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Run pre-deployment checks to verify environment and configuration",
|
|
6
6
|
"keywords": [
|
|
@@ -34,7 +34,8 @@
|
|
|
34
34
|
"dist"
|
|
35
35
|
],
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"jiti": "2.6.1"
|
|
37
|
+
"jiti": "2.6.1",
|
|
38
|
+
"@williamthorsen/node-monorepo-core": "0.2.1"
|
|
38
39
|
},
|
|
39
40
|
"engines": {
|
|
40
41
|
"node": ">=18.17.0"
|