framer-code-link 0.1.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/README.md +196 -0
- package/dist/index.js +2021 -0
- package/dist/project-DhpsFg77.js +53 -0
- package/package.json +36 -0
- package/src/controller.test.ts +966 -0
- package/src/controller.ts +1212 -0
- package/src/helpers/connection.ts +95 -0
- package/src/helpers/files.test.ts +117 -0
- package/src/helpers/files.ts +378 -0
- package/src/helpers/installer.ts +534 -0
- package/src/helpers/sync-validator.ts +87 -0
- package/src/helpers/user-actions.ts +162 -0
- package/src/helpers/watcher.ts +115 -0
- package/src/index.ts +75 -0
- package/src/types.ts +107 -0
- package/src/utils/file-metadata-cache.ts +121 -0
- package/src/utils/hashing.ts +95 -0
- package/src/utils/imports.ts +62 -0
- package/src/utils/logging.ts +47 -0
- package/src/utils/paths.ts +76 -0
- package/src/utils/project.ts +94 -0
- package/src/utils/state-persistence.ts +138 -0
- package/tsconfig.json +14 -0
- package/vitest.config.ts +8 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import fs from "fs/promises";
|
|
2
|
+
import path from "path";
|
|
3
|
+
|
|
4
|
+
//#region src/utils/project.ts
|
|
5
|
+
function toPackageName(name) {
|
|
6
|
+
return name.toLowerCase().replace(/[^a-z0-9-]/g, "-").replace(/^-+|-+$/g, "").replace(/-+/g, "-");
|
|
7
|
+
}
|
|
8
|
+
async function findOrCreateProjectDir(projectHash, projectName, explicitDir) {
|
|
9
|
+
if (explicitDir) {
|
|
10
|
+
const resolved = path.resolve(explicitDir);
|
|
11
|
+
await fs.mkdir(path.join(resolved, "files"), { recursive: true });
|
|
12
|
+
return resolved;
|
|
13
|
+
}
|
|
14
|
+
const cwd = process.cwd();
|
|
15
|
+
const existing = await findExistingProjectDir(cwd, projectHash);
|
|
16
|
+
if (existing) return existing;
|
|
17
|
+
if (!projectName) throw new Error("Project name is required when creating a new workspace. Pass --name <project name>.");
|
|
18
|
+
const dirName = toPackageName(projectName);
|
|
19
|
+
const projectDir = path.join(cwd, dirName || projectHash.slice(0, 6));
|
|
20
|
+
await fs.mkdir(path.join(projectDir, "files"), { recursive: true });
|
|
21
|
+
const pkg = {
|
|
22
|
+
name: dirName || projectHash,
|
|
23
|
+
version: "1.0.0",
|
|
24
|
+
private: true,
|
|
25
|
+
framerProjectId: projectHash,
|
|
26
|
+
framerProjectName: projectName
|
|
27
|
+
};
|
|
28
|
+
await fs.writeFile(path.join(projectDir, "package.json"), JSON.stringify(pkg, null, 2));
|
|
29
|
+
return projectDir;
|
|
30
|
+
}
|
|
31
|
+
async function findExistingProjectDir(baseDir, projectHash) {
|
|
32
|
+
const candidate = path.join(baseDir, "package.json");
|
|
33
|
+
if (await matchesProject(candidate, projectHash)) return baseDir;
|
|
34
|
+
const entries = await fs.readdir(baseDir, { withFileTypes: true });
|
|
35
|
+
for (const entry of entries) {
|
|
36
|
+
if (!entry.isDirectory()) continue;
|
|
37
|
+
const dir = path.join(baseDir, entry.name);
|
|
38
|
+
if (await matchesProject(path.join(dir, "package.json"), projectHash)) return dir;
|
|
39
|
+
}
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
async function matchesProject(packageJsonPath, projectHash) {
|
|
43
|
+
try {
|
|
44
|
+
const content = await fs.readFile(packageJsonPath, "utf-8");
|
|
45
|
+
const pkg = JSON.parse(content);
|
|
46
|
+
return pkg.framerProjectId === projectHash;
|
|
47
|
+
} catch {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
//#endregion
|
|
53
|
+
export { findOrCreateProjectDir };
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "framer-code-link",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "CLI tool for syncing Framer code components - controller-centric architecture",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"bin": "./dist/index.js",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"dev": "NODE_ENV=development tsx src/index.ts",
|
|
10
|
+
"build": "tsdown src/index.ts",
|
|
11
|
+
"start": "node dist/index.js",
|
|
12
|
+
"test": "vitest run"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [
|
|
15
|
+
"framer",
|
|
16
|
+
"sync",
|
|
17
|
+
"code-components"
|
|
18
|
+
],
|
|
19
|
+
"author": "",
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@typescript/ata": "^0.9.7",
|
|
23
|
+
"chokidar": "^4.0.3",
|
|
24
|
+
"commander": "^12.1.0",
|
|
25
|
+
"prettier": "^3.6.2",
|
|
26
|
+
"typescript": "^5.7.2",
|
|
27
|
+
"ws": "^8.18.0"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@types/node": "^22.10.2",
|
|
31
|
+
"@types/ws": "^8.5.13",
|
|
32
|
+
"tsdown": "^0.2.17",
|
|
33
|
+
"tsx": "^4.19.2",
|
|
34
|
+
"vitest": "^2.1.8"
|
|
35
|
+
}
|
|
36
|
+
}
|