framer-code-link 0.8.0 → 0.10.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/dist/index.mjs +24 -8
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
3
|
import { Command } from "commander";
|
|
4
4
|
import fs from "fs/promises";
|
|
5
|
-
import { WebSocketServer } from "ws";
|
|
6
5
|
import path from "path";
|
|
6
|
+
import { WebSocketServer } from "ws";
|
|
7
7
|
import { createHash } from "crypto";
|
|
8
8
|
import { setupTypeAcquisition } from "@typescript/ata";
|
|
9
9
|
import ts from "typescript";
|
|
@@ -1893,11 +1893,17 @@ async function findOrCreateProjectDir(projectHash, projectName, explicitDir) {
|
|
|
1893
1893
|
if (explicitDir) {
|
|
1894
1894
|
const resolved = path.resolve(explicitDir);
|
|
1895
1895
|
await fs.mkdir(path.join(resolved, "files"), { recursive: true });
|
|
1896
|
-
return
|
|
1896
|
+
return {
|
|
1897
|
+
dir: resolved,
|
|
1898
|
+
created: false
|
|
1899
|
+
};
|
|
1897
1900
|
}
|
|
1898
1901
|
const cwd = process.cwd();
|
|
1899
1902
|
const existing = await findExistingProjectDir(cwd, projectHash);
|
|
1900
|
-
if (existing) return
|
|
1903
|
+
if (existing) return {
|
|
1904
|
+
dir: existing,
|
|
1905
|
+
created: false
|
|
1906
|
+
};
|
|
1901
1907
|
if (!projectName) throw new Error("Failed to get Project name. Pass --name <project name>.");
|
|
1902
1908
|
const dirName = toDirName(projectName);
|
|
1903
1909
|
const pkgName = toPackageName(projectName);
|
|
@@ -1912,7 +1918,10 @@ async function findOrCreateProjectDir(projectHash, projectName, explicitDir) {
|
|
|
1912
1918
|
framerProjectName: projectName
|
|
1913
1919
|
};
|
|
1914
1920
|
await fs.writeFile(path.join(projectDir, "package.json"), JSON.stringify(pkg, null, 2));
|
|
1915
|
-
return
|
|
1921
|
+
return {
|
|
1922
|
+
dir: projectDir,
|
|
1923
|
+
created: true
|
|
1924
|
+
};
|
|
1916
1925
|
}
|
|
1917
1926
|
async function findExistingProjectDir(baseDir, projectHash) {
|
|
1918
1927
|
if (await matchesProject(path.join(baseDir, "package.json"), projectHash)) return baseDir;
|
|
@@ -2342,7 +2351,9 @@ async function executeEffect(effect, context) {
|
|
|
2342
2351
|
case "INIT_WORKSPACE":
|
|
2343
2352
|
if (!config.projectDir) {
|
|
2344
2353
|
const projectName = config.explicitName ?? effect.projectInfo.projectName;
|
|
2345
|
-
|
|
2354
|
+
const result = await findOrCreateProjectDir(config.projectHash, projectName, config.explicitDir);
|
|
2355
|
+
config.projectDir = result.dir;
|
|
2356
|
+
config.projectDirCreated = result.created;
|
|
2346
2357
|
config.filesDir = `${config.projectDir}/files`;
|
|
2347
2358
|
debug(`Files directory: ${config.filesDir}`);
|
|
2348
2359
|
await fs.mkdir(config.filesDir, { recursive: true });
|
|
@@ -2494,7 +2505,12 @@ async function executeEffect(effect, context) {
|
|
|
2494
2505
|
resetDisconnectState();
|
|
2495
2506
|
return [];
|
|
2496
2507
|
}
|
|
2497
|
-
|
|
2508
|
+
const relativeDir = config.projectDir ? "./" + (path.relative(process.cwd(), config.projectDir) || ".") : null;
|
|
2509
|
+
if (effect.totalCount === 0 && relativeDir) if (config.projectDirCreated) success(`Created ${relativeDir} folder`);
|
|
2510
|
+
else success(`Syncing to ${relativeDir} folder`);
|
|
2511
|
+
else if (relativeDir && config.projectDirCreated) success(`Synced into ${relativeDir} (${effect.updatedCount} files added)`);
|
|
2512
|
+
else if (relativeDir) success(`Synced into ${relativeDir} (${effect.updatedCount} files updated, ${effect.unchangedCount} unchanged)`);
|
|
2513
|
+
else success(`Synced ${effect.totalCount} files (${effect.updatedCount} updated, ${effect.unchangedCount} unchanged)`);
|
|
2498
2514
|
status("Watching for changes...");
|
|
2499
2515
|
return [];
|
|
2500
2516
|
}
|
|
@@ -2555,6 +2571,8 @@ async function start(config) {
|
|
|
2555
2571
|
return;
|
|
2556
2572
|
}
|
|
2557
2573
|
(async () => {
|
|
2574
|
+
cancelDisconnectMessage();
|
|
2575
|
+
if (!wasRecentlyDisconnected() && !didShowDisconnect()) success(`Connected to ${message.projectName}`);
|
|
2558
2576
|
await processEvent({
|
|
2559
2577
|
type: "HANDSHAKE",
|
|
2560
2578
|
socket: client,
|
|
@@ -2571,8 +2589,6 @@ async function start(config) {
|
|
|
2571
2589
|
await installer.initialize();
|
|
2572
2590
|
startWatcher();
|
|
2573
2591
|
}
|
|
2574
|
-
cancelDisconnectMessage();
|
|
2575
|
-
if (!wasRecentlyDisconnected() && !didShowDisconnect()) success(`Connected to ${message.projectName}`);
|
|
2576
2592
|
})();
|
|
2577
2593
|
});
|
|
2578
2594
|
async function handleMessage(message) {
|