framer-code-link 0.12.0 → 0.15.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.
Files changed (2) hide show
  1. package/dist/index.mjs +84 -0
  2. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -5,6 +5,8 @@ import fs from "fs/promises";
5
5
  import path from "path";
6
6
  import { WebSocketServer } from "ws";
7
7
  import { createHash } from "crypto";
8
+ import { execSync } from "child_process";
9
+ import fs$1 from "fs";
8
10
  import { setupTypeAcquisition } from "@typescript/ata";
9
11
  import ts from "typescript";
10
12
  import { fileURLToPath } from "node:url";
@@ -1000,6 +1002,85 @@ function isSupportedExtension(fileName) {
1000
1002
  return SUPPORTED_EXTENSIONS.some((ext) => lower.endsWith(ext));
1001
1003
  }
1002
1004
 
1005
+ //#endregion
1006
+ //#region src/helpers/git.ts
1007
+ /**
1008
+ * Git initialization helper — creates a git repo with an initial commit
1009
+ * in the project directory if one doesn't already exist.
1010
+ */
1011
+ function isInGitRepository(cwd) {
1012
+ try {
1013
+ execSync("git rev-parse --is-inside-work-tree", {
1014
+ stdio: "ignore",
1015
+ cwd
1016
+ });
1017
+ return true;
1018
+ } catch {
1019
+ return false;
1020
+ }
1021
+ }
1022
+ function isInMercurialRepository(cwd) {
1023
+ try {
1024
+ execSync("hg --cwd . root", {
1025
+ stdio: "ignore",
1026
+ cwd
1027
+ });
1028
+ return true;
1029
+ } catch {
1030
+ return false;
1031
+ }
1032
+ }
1033
+ function isDefaultBranchSet() {
1034
+ try {
1035
+ execSync("git config init.defaultBranch", { stdio: "ignore" });
1036
+ return true;
1037
+ } catch {
1038
+ return false;
1039
+ }
1040
+ }
1041
+ /**
1042
+ * Initialize a git repo in the project directory with an initial commit.
1043
+ * No-ops if already inside a git or mercurial repository.
1044
+ */
1045
+ function tryGitInit(projectDir) {
1046
+ let didInit = false;
1047
+ try {
1048
+ execSync("git --version", { stdio: "ignore" });
1049
+ if (isInGitRepository(projectDir) || isInMercurialRepository(projectDir)) {
1050
+ debug("Already in a repository, skipping git init");
1051
+ return false;
1052
+ }
1053
+ execSync("git init", {
1054
+ stdio: "ignore",
1055
+ cwd: projectDir
1056
+ });
1057
+ didInit = true;
1058
+ if (!isDefaultBranchSet()) execSync("git checkout -b main", {
1059
+ stdio: "ignore",
1060
+ cwd: projectDir
1061
+ });
1062
+ execSync("git add -A", {
1063
+ stdio: "ignore",
1064
+ cwd: projectDir
1065
+ });
1066
+ execSync("git commit -m \"Initial commit from Framer Code Link\"", {
1067
+ stdio: "ignore",
1068
+ cwd: projectDir
1069
+ });
1070
+ debug("Initialized git repository with initial commit");
1071
+ return true;
1072
+ } catch (e) {
1073
+ if (didInit) try {
1074
+ fs$1.rmSync(path.join(projectDir, ".git"), {
1075
+ recursive: true,
1076
+ force: true
1077
+ });
1078
+ } catch {}
1079
+ debug("Git init failed", e);
1080
+ return false;
1081
+ }
1082
+ }
1083
+
1003
1084
  //#endregion
1004
1085
  //#region src/utils/imports.ts
1005
1086
  /**
@@ -1426,6 +1507,8 @@ declare module "*.json"
1426
1507
  } catch {}
1427
1508
  const content = [
1428
1509
  "node_modules/",
1510
+ ".DS_Store",
1511
+ "*.local",
1429
1512
  "",
1430
1513
  "# Framer Code Link",
1431
1514
  ".framer-sync-state.json",
@@ -2534,6 +2617,7 @@ async function executeEffect(effect, context) {
2534
2617
  else if (relativeDirectory && config.projectDirCreated) success(`Synced into ${relativeDirectory} (${effect.updatedCount} files added)`);
2535
2618
  else if (relativeDirectory) success(`Synced into ${relativeDirectory} (${effect.updatedCount} files updated, ${effect.unchangedCount} unchanged)`);
2536
2619
  else success(`Synced ${effect.totalCount} files (${effect.updatedCount} updated, ${effect.unchangedCount} unchanged)`);
2620
+ if (config.projectDirCreated && config.projectDir) tryGitInit(config.projectDir);
2537
2621
  status("Watching for changes...");
2538
2622
  return [];
2539
2623
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "framer-code-link",
3
- "version": "0.12.0",
3
+ "version": "0.15.0",
4
4
  "description": "CLI tool for syncing Framer code components - controller-centric architecture",
5
5
  "main": "dist/index.mjs",
6
6
  "type": "module",