framer-code-link 0.10.0 → 0.11.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 +27 -26
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1877,7 +1877,7 @@ function hashContent(content) {
|
|
|
1877
1877
|
function toPackageName(name) {
|
|
1878
1878
|
return name.toLowerCase().replace(/[^a-z0-9-]/g, "-").replace(/^-+|-+$/g, "").replace(/-+/g, "-");
|
|
1879
1879
|
}
|
|
1880
|
-
function
|
|
1880
|
+
function toDirectoryName(name) {
|
|
1881
1881
|
return name.replace(/[^a-zA-Z0-9- ]/g, "-").replace(/^[-\s]+|[-\s]+$/g, "").replace(/-+/g, "-");
|
|
1882
1882
|
}
|
|
1883
1883
|
async function getProjectHashFromCwd() {
|
|
@@ -1889,27 +1889,27 @@ async function getProjectHashFromCwd() {
|
|
|
1889
1889
|
return null;
|
|
1890
1890
|
}
|
|
1891
1891
|
}
|
|
1892
|
-
async function
|
|
1893
|
-
if (
|
|
1894
|
-
const resolved = path.resolve(
|
|
1892
|
+
async function findOrCreateProjectDirectory(projectHash, projectName, explicitDirectory) {
|
|
1893
|
+
if (explicitDirectory) {
|
|
1894
|
+
const resolved = path.resolve(explicitDirectory);
|
|
1895
1895
|
await fs.mkdir(path.join(resolved, "files"), { recursive: true });
|
|
1896
1896
|
return {
|
|
1897
|
-
|
|
1897
|
+
directory: resolved,
|
|
1898
1898
|
created: false
|
|
1899
1899
|
};
|
|
1900
1900
|
}
|
|
1901
1901
|
const cwd = process.cwd();
|
|
1902
|
-
const existing = await
|
|
1902
|
+
const existing = await findExistingProjectDirectory(cwd, projectHash);
|
|
1903
1903
|
if (existing) return {
|
|
1904
|
-
|
|
1904
|
+
directory: existing,
|
|
1905
1905
|
created: false
|
|
1906
1906
|
};
|
|
1907
1907
|
if (!projectName) throw new Error("Failed to get Project name. Pass --name <project name>.");
|
|
1908
|
-
const
|
|
1908
|
+
const directoryName = toDirectoryName(projectName);
|
|
1909
1909
|
const pkgName = toPackageName(projectName);
|
|
1910
1910
|
const shortId = shortProjectHash(projectHash);
|
|
1911
|
-
const
|
|
1912
|
-
await fs.mkdir(path.join(
|
|
1911
|
+
const projectDirectory = path.join(cwd, directoryName || shortId);
|
|
1912
|
+
await fs.mkdir(path.join(projectDirectory, "files"), { recursive: true });
|
|
1913
1913
|
const pkg = {
|
|
1914
1914
|
name: pkgName || shortId,
|
|
1915
1915
|
version: "1.0.0",
|
|
@@ -1917,19 +1917,19 @@ async function findOrCreateProjectDir(projectHash, projectName, explicitDir) {
|
|
|
1917
1917
|
shortProjectHash: shortId,
|
|
1918
1918
|
framerProjectName: projectName
|
|
1919
1919
|
};
|
|
1920
|
-
await fs.writeFile(path.join(
|
|
1920
|
+
await fs.writeFile(path.join(projectDirectory, "package.json"), JSON.stringify(pkg, null, 2));
|
|
1921
1921
|
return {
|
|
1922
|
-
|
|
1922
|
+
directory: projectDirectory,
|
|
1923
1923
|
created: true
|
|
1924
1924
|
};
|
|
1925
1925
|
}
|
|
1926
|
-
async function
|
|
1927
|
-
if (await matchesProject(path.join(
|
|
1928
|
-
const entries = await fs.readdir(
|
|
1926
|
+
async function findExistingProjectDirectory(baseDirectory, projectHash) {
|
|
1927
|
+
if (await matchesProject(path.join(baseDirectory, "package.json"), projectHash)) return baseDirectory;
|
|
1928
|
+
const entries = await fs.readdir(baseDirectory, { withFileTypes: true });
|
|
1929
1929
|
for (const entry of entries) {
|
|
1930
1930
|
if (!entry.isDirectory()) continue;
|
|
1931
|
-
const
|
|
1932
|
-
if (await matchesProject(path.join(
|
|
1931
|
+
const directory = path.join(baseDirectory, entry.name);
|
|
1932
|
+
if (await matchesProject(path.join(directory, "package.json"), projectHash)) return directory;
|
|
1933
1933
|
}
|
|
1934
1934
|
return null;
|
|
1935
1935
|
}
|
|
@@ -2351,9 +2351,9 @@ async function executeEffect(effect, context) {
|
|
|
2351
2351
|
case "INIT_WORKSPACE":
|
|
2352
2352
|
if (!config.projectDir) {
|
|
2353
2353
|
const projectName = config.explicitName ?? effect.projectInfo.projectName;
|
|
2354
|
-
const
|
|
2355
|
-
config.projectDir =
|
|
2356
|
-
config.projectDirCreated =
|
|
2354
|
+
const directoryInfo = await findOrCreateProjectDirectory(config.projectHash, projectName, config.explicitDirectory);
|
|
2355
|
+
config.projectDir = directoryInfo.directory;
|
|
2356
|
+
config.projectDirCreated = directoryInfo.created;
|
|
2357
2357
|
config.filesDir = `${config.projectDir}/files`;
|
|
2358
2358
|
debug(`Files directory: ${config.filesDir}`);
|
|
2359
2359
|
await fs.mkdir(config.filesDir, { recursive: true });
|
|
@@ -2505,11 +2505,12 @@ async function executeEffect(effect, context) {
|
|
|
2505
2505
|
resetDisconnectState();
|
|
2506
2506
|
return [];
|
|
2507
2507
|
}
|
|
2508
|
-
const
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
else
|
|
2512
|
-
else if (
|
|
2508
|
+
const relative = config.projectDir ? path.relative(process.cwd(), config.projectDir) : null;
|
|
2509
|
+
const relativeDirectory = relative != null ? relative ? "./" + relative : "." : null;
|
|
2510
|
+
if (effect.totalCount === 0 && relativeDirectory) if (config.projectDirCreated) success(`Created ${relativeDirectory} folder`);
|
|
2511
|
+
else success(`Syncing to ${relativeDirectory} folder`);
|
|
2512
|
+
else if (relativeDirectory && config.projectDirCreated) success(`Synced into ${relativeDirectory} (${effect.updatedCount} files added)`);
|
|
2513
|
+
else if (relativeDirectory) success(`Synced into ${relativeDirectory} (${effect.updatedCount} files updated, ${effect.unchangedCount} unchanged)`);
|
|
2513
2514
|
else success(`Synced ${effect.totalCount} files (${effect.updatedCount} updated, ${effect.unchangedCount} unchanged)`);
|
|
2514
2515
|
status("Watching for changes...");
|
|
2515
2516
|
return [];
|
|
@@ -2757,7 +2758,7 @@ program.name("framer-code-link").description("Sync Framer code components to you
|
|
|
2757
2758
|
filesDir: null,
|
|
2758
2759
|
dangerouslyAutoDelete: options.dangerouslyAutoDelete ?? false,
|
|
2759
2760
|
allowUnsupportedNpm: options.unsupportedNpm ?? false,
|
|
2760
|
-
|
|
2761
|
+
explicitDirectory: options.dir,
|
|
2761
2762
|
explicitName: options.name
|
|
2762
2763
|
};
|
|
2763
2764
|
if (config.dangerouslyAutoDelete) warn("Auto-delete mode enabled - files will be deleted without confirmation");
|