framer-code-link 0.11.0 → 0.14.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/index.mjs +106 -2
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -7,6 +7,8 @@ import { WebSocketServer } from "ws";
|
|
|
7
7
|
import { createHash } from "crypto";
|
|
8
8
|
import { setupTypeAcquisition } from "@typescript/ata";
|
|
9
9
|
import ts from "typescript";
|
|
10
|
+
import { execSync } from "child_process";
|
|
11
|
+
import fs$1 from "fs";
|
|
10
12
|
import { fileURLToPath } from "node:url";
|
|
11
13
|
import chokidar from "chokidar";
|
|
12
14
|
|
|
@@ -1043,6 +1045,85 @@ function extractPackageFromUrl(url) {
|
|
|
1043
1045
|
return /\/(@?[^@/]+(?:\/[^@/]+)?)/.exec(url)?.[1] ?? null;
|
|
1044
1046
|
}
|
|
1045
1047
|
|
|
1048
|
+
//#endregion
|
|
1049
|
+
//#region src/helpers/git.ts
|
|
1050
|
+
/**
|
|
1051
|
+
* Git initialization helper — creates a git repo with an initial commit
|
|
1052
|
+
* in the project directory if one doesn't already exist.
|
|
1053
|
+
*/
|
|
1054
|
+
function isInGitRepository(cwd) {
|
|
1055
|
+
try {
|
|
1056
|
+
execSync("git rev-parse --is-inside-work-tree", {
|
|
1057
|
+
stdio: "ignore",
|
|
1058
|
+
cwd
|
|
1059
|
+
});
|
|
1060
|
+
return true;
|
|
1061
|
+
} catch {
|
|
1062
|
+
return false;
|
|
1063
|
+
}
|
|
1064
|
+
}
|
|
1065
|
+
function isInMercurialRepository(cwd) {
|
|
1066
|
+
try {
|
|
1067
|
+
execSync("hg --cwd . root", {
|
|
1068
|
+
stdio: "ignore",
|
|
1069
|
+
cwd
|
|
1070
|
+
});
|
|
1071
|
+
return true;
|
|
1072
|
+
} catch {
|
|
1073
|
+
return false;
|
|
1074
|
+
}
|
|
1075
|
+
}
|
|
1076
|
+
function isDefaultBranchSet() {
|
|
1077
|
+
try {
|
|
1078
|
+
execSync("git config init.defaultBranch", { stdio: "ignore" });
|
|
1079
|
+
return true;
|
|
1080
|
+
} catch {
|
|
1081
|
+
return false;
|
|
1082
|
+
}
|
|
1083
|
+
}
|
|
1084
|
+
/**
|
|
1085
|
+
* Initialize a git repo in the project directory with an initial commit.
|
|
1086
|
+
* No-ops if already inside a git or mercurial repository.
|
|
1087
|
+
*/
|
|
1088
|
+
function tryGitInit(projectDir) {
|
|
1089
|
+
let didInit = false;
|
|
1090
|
+
try {
|
|
1091
|
+
execSync("git --version", { stdio: "ignore" });
|
|
1092
|
+
if (isInGitRepository(projectDir) || isInMercurialRepository(projectDir)) {
|
|
1093
|
+
debug("Already in a repository, skipping git init");
|
|
1094
|
+
return false;
|
|
1095
|
+
}
|
|
1096
|
+
execSync("git init", {
|
|
1097
|
+
stdio: "ignore",
|
|
1098
|
+
cwd: projectDir
|
|
1099
|
+
});
|
|
1100
|
+
didInit = true;
|
|
1101
|
+
if (!isDefaultBranchSet()) execSync("git checkout -b main", {
|
|
1102
|
+
stdio: "ignore",
|
|
1103
|
+
cwd: projectDir
|
|
1104
|
+
});
|
|
1105
|
+
execSync("git add -A", {
|
|
1106
|
+
stdio: "ignore",
|
|
1107
|
+
cwd: projectDir
|
|
1108
|
+
});
|
|
1109
|
+
execSync("git commit -m \"Initial commit from Framer Code Link\"", {
|
|
1110
|
+
stdio: "ignore",
|
|
1111
|
+
cwd: projectDir
|
|
1112
|
+
});
|
|
1113
|
+
debug("Initialized git repository with initial commit");
|
|
1114
|
+
return true;
|
|
1115
|
+
} catch (e) {
|
|
1116
|
+
if (didInit) try {
|
|
1117
|
+
fs$1.rmSync(path.join(projectDir, ".git"), {
|
|
1118
|
+
recursive: true,
|
|
1119
|
+
force: true
|
|
1120
|
+
});
|
|
1121
|
+
} catch {}
|
|
1122
|
+
debug("Git init failed", e);
|
|
1123
|
+
return false;
|
|
1124
|
+
}
|
|
1125
|
+
}
|
|
1126
|
+
|
|
1046
1127
|
//#endregion
|
|
1047
1128
|
//#region src/helpers/skills.ts
|
|
1048
1129
|
/**
|
|
@@ -1262,8 +1343,10 @@ var Installer = class {
|
|
|
1262
1343
|
this.ensurePrettierConfig(),
|
|
1263
1344
|
this.ensureFramerDeclarations(),
|
|
1264
1345
|
this.ensurePackageJson(),
|
|
1265
|
-
this.ensureSkills()
|
|
1346
|
+
this.ensureSkills(),
|
|
1347
|
+
this.ensureGitignore()
|
|
1266
1348
|
]);
|
|
1349
|
+
tryGitInit(this.projectDir);
|
|
1267
1350
|
Promise.resolve().then(async () => {
|
|
1268
1351
|
await this.ensureReact18Types();
|
|
1269
1352
|
const coreImports = CORE_LIBRARIES.map((lib) => `import "${lib}";`).join("\n");
|
|
@@ -1416,6 +1499,27 @@ declare module "*.json"
|
|
|
1416
1499
|
async ensureSkills() {
|
|
1417
1500
|
await installSkills(this.projectDir);
|
|
1418
1501
|
}
|
|
1502
|
+
async ensureGitignore() {
|
|
1503
|
+
const gitignorePath = path.join(this.projectDir, ".gitignore");
|
|
1504
|
+
try {
|
|
1505
|
+
await fs.access(gitignorePath);
|
|
1506
|
+
debug(".gitignore already exists");
|
|
1507
|
+
return;
|
|
1508
|
+
} catch {}
|
|
1509
|
+
const content = [
|
|
1510
|
+
"node_modules/",
|
|
1511
|
+
"",
|
|
1512
|
+
"# Framer Code Link",
|
|
1513
|
+
".framer-sync-state.json",
|
|
1514
|
+
".skills/",
|
|
1515
|
+
".agents/skills/",
|
|
1516
|
+
".claude/skills/",
|
|
1517
|
+
".cursor/skills/",
|
|
1518
|
+
""
|
|
1519
|
+
].join("\n");
|
|
1520
|
+
await fs.writeFile(gitignorePath, content);
|
|
1521
|
+
debug("Created .gitignore");
|
|
1522
|
+
}
|
|
1419
1523
|
async ensureReact18Types() {
|
|
1420
1524
|
const reactTypesDir = path.join(this.projectDir, "node_modules/@types/react");
|
|
1421
1525
|
const reactFiles = [
|
|
@@ -1878,7 +1982,7 @@ function toPackageName(name) {
|
|
|
1878
1982
|
return name.toLowerCase().replace(/[^a-z0-9-]/g, "-").replace(/^-+|-+$/g, "").replace(/-+/g, "-");
|
|
1879
1983
|
}
|
|
1880
1984
|
function toDirectoryName(name) {
|
|
1881
|
-
return name.replace(/[^a-zA-Z0-9-
|
|
1985
|
+
return name.replace(/[^a-zA-Z0-9-]/g, "-").replace(/^-+|-+$/g, "").replace(/-+/g, "-");
|
|
1882
1986
|
}
|
|
1883
1987
|
async function getProjectHashFromCwd() {
|
|
1884
1988
|
try {
|