framer-code-link 0.12.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 +82 -0
- 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
|
/**
|
|
@@ -1265,6 +1346,7 @@ var Installer = class {
|
|
|
1265
1346
|
this.ensureSkills(),
|
|
1266
1347
|
this.ensureGitignore()
|
|
1267
1348
|
]);
|
|
1349
|
+
tryGitInit(this.projectDir);
|
|
1268
1350
|
Promise.resolve().then(async () => {
|
|
1269
1351
|
await this.ensureReact18Types();
|
|
1270
1352
|
const coreImports = CORE_LIBRARIES.map((lib) => `import "${lib}";`).join("\n");
|