@trayai/tray-sync-cli 1.0.3 → 1.0.5
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 +2 -1
- package/dist/commands/pull.js +15 -3
- package/dist/lib/slug.js +3 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -43,7 +43,8 @@ Decide which workspace you're pulling *from* (the source) and which one you're p
|
|
|
43
43
|
- Source: `DEV_ORG`
|
|
44
44
|
- Target: `PROD_ORG`
|
|
45
45
|
|
|
46
|
-
|
|
46
|
+
|
|
47
|
+
You'll need each workspace's ID and region, and a Tray API token with access to it. 📚 Learn how to create tokens for your [workspace (recommended)](https://tray.ai/documentation/platform/enterprise-core/organisation-management/api-users-tokens#enabling-workspace-admins-to-generate-tokens) / [account](https://tray.ai/documentation/platform/enterprise-core/organisation-management/api-users-tokens) here.
|
|
47
48
|
|
|
48
49
|
### 2. Create a local directory for this project
|
|
49
50
|
|
package/dist/commands/pull.js
CHANGED
|
@@ -9,7 +9,7 @@ import { readPullProgress, writePullProgress } from "../config/pullProgress.js";
|
|
|
9
9
|
import { readProjectState, writeProjectState } from "../config/state.js";
|
|
10
10
|
import { readTrayYaml, writeTrayYaml } from "../config/trayYaml.js";
|
|
11
11
|
import { Scopes, TrayTypes, } from "../config/types.js";
|
|
12
|
-
import { entityDirName } from "../lib/slug.js";
|
|
12
|
+
import { entityDirName, findDirsWithStaleSlug } from "../lib/slug.js";
|
|
13
13
|
import { entityDisplayName, parseExportStructure, } from "../lib/exportStructure.js";
|
|
14
14
|
import { extractScripts } from "../lib/scriptExtraction.js";
|
|
15
15
|
import { sha256 } from "../lib/checksum.js";
|
|
@@ -74,10 +74,22 @@ export async function writeExportedProject(projectDirPath, exportStructure, stdo
|
|
|
74
74
|
const resources = {};
|
|
75
75
|
for (const { field, dirName, fileName, trayType } of ASSET_DIRS) {
|
|
76
76
|
const entities = exportStructure[field] ?? [];
|
|
77
|
+
const entityParentDir = path.join(projectDirPath, dirName);
|
|
77
78
|
for (const entity of entities) {
|
|
78
79
|
const entityId = requireUuid(entity.id, `exportProject: ${field}[].id`);
|
|
79
80
|
const entityDirName_ = entityDirName(entityId, entityDisplayName(entity));
|
|
80
|
-
const entityDir = resolveContained(
|
|
81
|
+
const entityDir = resolveContained(entityParentDir, entityDirName_);
|
|
82
|
+
let staleDirNames;
|
|
83
|
+
try {
|
|
84
|
+
staleDirNames = findDirsWithStaleSlug(await fsReaddir(entityParentDir), entityId, entityDirName_);
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
staleDirNames = [];
|
|
88
|
+
}
|
|
89
|
+
for (const staleDirName of staleDirNames) {
|
|
90
|
+
const staleDir = await resolveContainedSafe(entityParentDir, staleDirName);
|
|
91
|
+
await fsRm(staleDir, { recursive: true, force: true });
|
|
92
|
+
}
|
|
81
93
|
const entityJsonPath = path.join(entityDir, fileName);
|
|
82
94
|
await assertNoSymlinkInPath(projectDirPath, entityJsonPath);
|
|
83
95
|
await writeJson(entityJsonPath, entity);
|
|
@@ -195,7 +207,7 @@ export async function runPull(deps, options) {
|
|
|
195
207
|
const dir = await resolveContainedSafe(projectsRoot, newDirName);
|
|
196
208
|
let existingDirName;
|
|
197
209
|
try {
|
|
198
|
-
existingDirName = (await readdir(projectsRoot)
|
|
210
|
+
existingDirName = findDirsWithStaleSlug(await readdir(projectsRoot), validatedProjectId, newDirName)[0];
|
|
199
211
|
}
|
|
200
212
|
catch {
|
|
201
213
|
existingDirName = undefined;
|
package/dist/lib/slug.js
CHANGED
|
@@ -11,4 +11,7 @@ export function slugify(name) {
|
|
|
11
11
|
export function entityDirName(uuid, name) {
|
|
12
12
|
return `${uuid}--${slugify(name)}`;
|
|
13
13
|
}
|
|
14
|
+
export function findDirsWithStaleSlug(dirNames, uuid, currentDirName) {
|
|
15
|
+
return dirNames.filter((name) => name.split("--")[0] === uuid && name !== currentDirName);
|
|
16
|
+
}
|
|
14
17
|
//# sourceMappingURL=slug.js.map
|
package/package.json
CHANGED