@trayai/tray-sync-cli 1.0.6 → 1.0.7

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.
@@ -59,6 +59,25 @@ export async function listProjectIds(client, workspaceId) {
59
59
  const result = (await client.request("GET", `/v2/projects/workspaces/${workspaceId}`));
60
60
  return result.projects.map((p) => requireUuid(p.id, "listProjects: projects[].id"));
61
61
  }
62
+ async function removeOrphanedEntityDirs(projectDirPath, entityParentDir, currentIds) {
63
+ await assertNoSymlinkInPath(projectDirPath, entityParentDir);
64
+ let existingDirNames;
65
+ try {
66
+ existingDirNames = await fsReaddir(entityParentDir);
67
+ }
68
+ catch {
69
+ existingDirNames = [];
70
+ }
71
+ for (const dirName_ of existingDirNames) {
72
+ const prefix = dirName_.split("--")[0];
73
+ if (!isUuid(prefix) || currentIds.has(prefix)) {
74
+ continue;
75
+ }
76
+ const staleDir = resolveContained(entityParentDir, dirName_);
77
+ await assertNoSymlinkInPath(projectDirPath, staleDir);
78
+ await fsRm(staleDir, { recursive: true, force: true });
79
+ }
80
+ }
62
81
  export async function writeExportedProject(projectDirPath, exportStructure, stdout) {
63
82
  const project = exportStructure.projects[0];
64
83
  const projectJsonPath = path.join(projectDirPath, "project.json");
@@ -75,6 +94,7 @@ export async function writeExportedProject(projectDirPath, exportStructure, stdo
75
94
  for (const { field, dirName, fileName, trayType } of ASSET_DIRS) {
76
95
  const entities = exportStructure[field] ?? [];
77
96
  const entityParentDir = path.join(projectDirPath, dirName);
97
+ const currentIds = new Set(entities.map((entity) => entity.id));
78
98
  for (const entity of entities) {
79
99
  const entityId = requireUuid(entity.id, `exportProject: ${field}[].id`);
80
100
  const entityDirName_ = entityDirName(entityId, entityDisplayName(entity));
@@ -113,6 +133,7 @@ export async function writeExportedProject(projectDirPath, exportStructure, stdo
113
133
  }
114
134
  }
115
135
  }
136
+ await removeOrphanedEntityDirs(projectDirPath, entityParentDir, currentIds);
116
137
  }
117
138
  const solutionDropped = Boolean(exportStructure.solution);
118
139
  if (solutionDropped) {
@@ -252,6 +273,10 @@ export async function runPull(deps, options) {
252
273
  }
253
274
  }
254
275
  if (unchanged) {
276
+ for (const { field, dirName } of ASSET_DIRS) {
277
+ const entities = exportStructure[field] ?? [];
278
+ await removeOrphanedEntityDirs(dir, path.join(dir, dirName), new Set(entities.map((e) => e.id)));
279
+ }
255
280
  await writeProjectState(dir, { ...existingState, last_sync: new Date().toISOString() });
256
281
  if (asJson) {
257
282
  events.push({ project_id: projectId, project_name: projectName, action: "pulled_unchanged", renamed_dir: renamedDir });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trayai/tray-sync-cli",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "description": "CLI tool to clone Tray projects and related assets to a local directory, and promote them between Tray environments",
5
5
  "bin": {
6
6
  "tray": "dist/cli.js"