trekoon 0.3.5 → 0.3.6
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/package.json +1 -1
- package/src/commands/init.ts +36 -0
package/package.json
CHANGED
package/src/commands/init.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
|
|
1
4
|
import { unexpectedFailureResult } from "./error-utils";
|
|
2
5
|
|
|
3
6
|
import { ensureBoardInstalled } from "../board/install";
|
|
@@ -6,6 +9,11 @@ import { DomainError } from "../domain/types";
|
|
|
6
9
|
import { failResult, okResult } from "../io/output";
|
|
7
10
|
import { type CliContext, type CliResult } from "../runtime/command-types";
|
|
8
11
|
import { openTrekoonDatabase, type TrekoonDatabase } from "../storage/database";
|
|
12
|
+
import { type StorageMode } from "../storage/path";
|
|
13
|
+
|
|
14
|
+
type GitignoreAction = "created" | "already_exists" | "skipped";
|
|
15
|
+
|
|
16
|
+
const GITIGNORE_CONTENT = "*\n";
|
|
9
17
|
|
|
10
18
|
function buildRecoverySummary(database: TrekoonDatabase): string[] {
|
|
11
19
|
const diagnostics = database.diagnostics;
|
|
@@ -76,6 +84,24 @@ function recoveryFailureResult(error: DomainError): CliResult | null {
|
|
|
76
84
|
});
|
|
77
85
|
}
|
|
78
86
|
|
|
87
|
+
function ensureGitignore(storageDir: string, storageMode: StorageMode): GitignoreAction {
|
|
88
|
+
if (storageMode === "cwd") {
|
|
89
|
+
return "skipped";
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const gitignorePath: string = resolve(storageDir, ".gitignore");
|
|
93
|
+
|
|
94
|
+
if (existsSync(gitignorePath)) {
|
|
95
|
+
const existing: string = readFileSync(gitignorePath, "utf8");
|
|
96
|
+
if (existing === GITIGNORE_CONTENT) {
|
|
97
|
+
return "already_exists";
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
writeFileSync(gitignorePath, GITIGNORE_CONTENT, "utf8");
|
|
102
|
+
return "created";
|
|
103
|
+
}
|
|
104
|
+
|
|
79
105
|
export async function runInit(context: CliContext): Promise<CliResult> {
|
|
80
106
|
let database: TrekoonDatabase | undefined;
|
|
81
107
|
|
|
@@ -87,6 +113,11 @@ export async function runInit(context: CliContext): Promise<CliResult> {
|
|
|
87
113
|
workingDirectory: context.cwd,
|
|
88
114
|
...(bundledAssetRoot === undefined ? {} : { bundledAssetRoot }),
|
|
89
115
|
});
|
|
116
|
+
const gitignoreAction: GitignoreAction = ensureGitignore(
|
|
117
|
+
database.paths.storageDir,
|
|
118
|
+
diagnostics.storageMode,
|
|
119
|
+
);
|
|
120
|
+
|
|
90
121
|
const humanLines: string[] = [
|
|
91
122
|
"Trekoon initialized.",
|
|
92
123
|
`Storage mode: ${diagnostics.storageMode}`,
|
|
@@ -96,6 +127,7 @@ export async function runInit(context: CliContext): Promise<CliResult> {
|
|
|
96
127
|
`Database file: ${database.paths.databaseFile}`,
|
|
97
128
|
`Board assets: ${board.action}`,
|
|
98
129
|
`Board runtime root: ${board.paths.runtimeRoot}`,
|
|
130
|
+
`Gitignore: ${gitignoreAction}`,
|
|
99
131
|
...buildRecoverySummary(database),
|
|
100
132
|
];
|
|
101
133
|
|
|
@@ -115,6 +147,10 @@ export async function runInit(context: CliContext): Promise<CliResult> {
|
|
|
115
147
|
paths: board.paths,
|
|
116
148
|
manifest: board.manifest,
|
|
117
149
|
},
|
|
150
|
+
gitignore: {
|
|
151
|
+
action: gitignoreAction,
|
|
152
|
+
path: resolve(database.paths.storageDir, ".gitignore"),
|
|
153
|
+
},
|
|
118
154
|
legacyStateDetected: diagnostics.legacyStateDetected,
|
|
119
155
|
recoveryRequired: diagnostics.recoveryRequired,
|
|
120
156
|
recoveryStatus: diagnostics.recoveryStatus,
|