Skip to content

Commit db46db1

Browse files
authored
Merge pull request #154 from geometricpanda/feature/add-starts-with-to-folder-sync
fix: adds startsWith logic to sync for folders
2 parents 3225a6d + bba6d24 commit db46db1

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

src/tasks/sync.js

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,16 +140,31 @@ const SyncSpaces = {
140140
async syncFolders () {
141141
console.log(chalk.green('✓') + ' Syncing folders...')
142142

143-
const sourceFolders = await this.client.getAll(`spaces/${this.sourceSpaceId}/stories`, {
143+
const sourceFolderParams = {
144144
folder_only: 1,
145145
sort_by: 'slug:asc'
146-
})
146+
};
147+
148+
if (this.startsWith) {
149+
sourceFolderParams.starts_with = this.startsWith;
150+
}
151+
152+
const sourceFolders = await this.client.getAll(`spaces/${this.sourceSpaceId}/stories`, sourceFolderParams)
147153
const syncedFolders = {}
148154

149155
for (const folder of sourceFolders) {
150156
try {
157+
158+
const targetFolderParams = {
159+
with_slug: folder.full_slug,
160+
};
161+
162+
if (this.startsWith) {
163+
targetFolderParams.starts_with = this.startsWith;
164+
}
165+
151166
const folderResult = await this.client.get(`spaces/${this.sourceSpaceId}/stories/${folder.id}`)
152-
const { data } = await this.client.get(`spaces/${this.targetSpaceId}/stories`, { with_slug: folder.full_slug })
167+
const { data } = await this.client.get(`spaces/${this.targetSpaceId}/stories`, targetFolderParams)
153168
const existingFolder = data.stories[0] || null
154169
const folderData = await this.getStoryWithTranslatedSlugs(folderResult.data.story, existingFolder)
155170
delete folderData.id
@@ -236,7 +251,7 @@ const SyncSpaces = {
236251
componentsGroups: this.componentsGroups,
237252
componentsFullSync: this.componentsFullSync
238253
})
239-
254+
240255
try {
241256
await syncComponentsInstance.sync()
242257
} catch (e) {

0 commit comments

Comments
 (0)