phibelle-kit 1.0.26 → 1.0.27
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 +2 -0
- package/dist/commands/clone-scene.js +39 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -21,6 +21,8 @@ npx phibelle-kit watch <sceneId>
|
|
|
21
21
|
|
|
22
22
|
## After cloning
|
|
23
23
|
|
|
24
|
+
`phibelle-kit clone` initializes a local Git repository and attempts to create an initial commit automatically.
|
|
25
|
+
|
|
24
26
|
1. `cd <scene-folder>` to enter the scene directory.
|
|
25
27
|
2. `npm install` to install dependencies (for types and intellisense).
|
|
26
28
|
3. `npm run watch` in the scene folder to push edits, or run `npx phibelle-kit watch <sceneId>` from the project root.
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import chalk from "chalk";
|
|
2
2
|
import * as path from "node:path";
|
|
3
3
|
import * as fs from "node:fs/promises";
|
|
4
|
+
import { execFile } from "node:child_process";
|
|
5
|
+
import { promisify } from "node:util";
|
|
4
6
|
import { WebSocketServer } from "ws";
|
|
5
7
|
import { parseSceneJson, unpackageScene } from "../lib/scene/scene-packaging.js";
|
|
6
8
|
import { setupSceneDirectory } from "../scene-setup/setup.js";
|
|
@@ -8,6 +10,8 @@ const WS_PORT = 31113;
|
|
|
8
10
|
const CLONE_REQUEST_TYPE = "phibelle-kit-clone-request";
|
|
9
11
|
const CLONE_RESPONSE_TYPE = "phibelle-kit-clone-response";
|
|
10
12
|
const CLONE_TIMEOUT_MS = 30_000;
|
|
13
|
+
const INITIAL_COMMIT_MESSAGE = "Initial scene clone from Phibelle";
|
|
14
|
+
const execFileAsync = promisify(execFile);
|
|
11
15
|
export async function cloneSceneCommand() {
|
|
12
16
|
const parentDir = process.cwd();
|
|
13
17
|
console.log();
|
|
@@ -24,6 +28,7 @@ export async function cloneSceneCommand() {
|
|
|
24
28
|
setupSceneDirectory(sceneDir);
|
|
25
29
|
await fs.writeFile(path.join(sceneDir, "scene.phibelle"), payload.sceneData, "utf8");
|
|
26
30
|
await unpackageScene(payload.sceneData, sceneDir, payload.sceneId);
|
|
31
|
+
await initializeGitRepository(sceneDir);
|
|
27
32
|
console.log(chalk.green(" ✓ Scene cloned successfully"));
|
|
28
33
|
console.log(chalk.gray(` Directory: ${sceneDir}`));
|
|
29
34
|
console.log(chalk.yellow(" Next steps:"));
|
|
@@ -128,3 +133,37 @@ async function ensureDirectoryDoesNotExist(sceneDir) {
|
|
|
128
133
|
}
|
|
129
134
|
throw new Error(`Target folder already exists: ${sceneDir}. Rename the scene or clone into another directory.`);
|
|
130
135
|
}
|
|
136
|
+
async function initializeGitRepository(sceneDir) {
|
|
137
|
+
try {
|
|
138
|
+
try {
|
|
139
|
+
await runGit(["init", "-b", "main"], sceneDir);
|
|
140
|
+
}
|
|
141
|
+
catch {
|
|
142
|
+
// Older Git versions don't support -b / --initial-branch; fallback to default.
|
|
143
|
+
await runGit(["init"], sceneDir);
|
|
144
|
+
}
|
|
145
|
+
await runGit(["add", "."], sceneDir);
|
|
146
|
+
await runGit(["commit", "-m", INITIAL_COMMIT_MESSAGE], sceneDir);
|
|
147
|
+
console.log(chalk.green(" ✓ Initialized git repository with an initial commit"));
|
|
148
|
+
}
|
|
149
|
+
catch (error) {
|
|
150
|
+
console.log(chalk.yellow(" ! Git initialization or first commit was skipped"));
|
|
151
|
+
const details = getErrorText(error);
|
|
152
|
+
if (details) {
|
|
153
|
+
console.log(chalk.gray(` ${details}`));
|
|
154
|
+
}
|
|
155
|
+
console.log(chalk.gray(" Configure Git identity and run: git add . && git commit"));
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
async function runGit(args, cwd) {
|
|
159
|
+
await execFileAsync("git", args, { cwd });
|
|
160
|
+
}
|
|
161
|
+
function getErrorText(error) {
|
|
162
|
+
if (!error || typeof error !== "object")
|
|
163
|
+
return "";
|
|
164
|
+
const err = error;
|
|
165
|
+
const stderr = err.stderr?.trim();
|
|
166
|
+
if (stderr)
|
|
167
|
+
return stderr.split("\n").pop() ?? stderr;
|
|
168
|
+
return err.message?.trim() ?? "";
|
|
169
|
+
}
|