Skip to content
This repository was archived by the owner on Jan 19, 2026. It is now read-only.

Commit 0f47815

Browse files
Merge pull request #39 from towa-digital/feat/speficy-filename-for-pull-components
feat: added option to specify filname to pull-components command
2 parents 1a3d77a + 7794854 commit 0f47815

5 files changed

Lines changed: 14 additions & 10 deletions

File tree

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,15 @@ $ storyblok pull-components --space <SPACE_ID> # Will save files like components
9898
```
9999

100100
```sh
101-
$ storyblok pull-components --space <SPACE_ID> --separate-files # Will save files like feature-1234.json grid-1234.json
101+
$ storyblok pull-components --space <SPACE_ID> --separate-files --file-name production # Will save files like feature-production.json grid-production.json
102102
```
103103

104104
#### Options
105105

106106
* `space`: your space id
107107
* `separate-files`: boolean flag to save components and presets in single files instead a file with all
108108
* `path`: the path to save your components and preset files
109+
* `file-name`(optional): a custom filename used to generate the component and present files, default is the space id
109110

110111
### push-components
111112

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,4 @@
6565
"master"
6666
]
6767
}
68-
}
68+
}

src/cli.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ program
121121
.command(COMMANDS.PULL_COMPONENTS)
122122
.option('--sf, --separate-files [value]', 'Argument to create a single file for each component')
123123
.option('-p, --path <path>', 'Path to save the component files')
124+
.option('-f, --file-name <fileName>', 'custom name to be used in file(s) name instead of space id')
124125
.description("Download your space's components schema as json")
125126
.action(async (options) => {
126127
console.log(`${chalk.blue('-')} Executing pull-components task`)
@@ -131,13 +132,15 @@ program
131132
process.exit(0)
132133
}
133134

135+
const fileName = options.fileName ? options.fileName : space
136+
134137
try {
135138
if (!api.isAuthorized()) {
136139
await api.processLogin()
137140
}
138141

139142
api.setSpaceId(space)
140-
await tasks.pullComponents(api, { space, separateFiles, path })
143+
await tasks.pullComponents(api, { fileName, separateFiles, path })
141144
} catch (e) {
142145
errorHandler(e, COMMANDS.PULL_COMPONENTS)
143146
}

src/tasks/pull-components.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ const getNameFromComponentGroups = (groups, uuid) => {
2020
/**
2121
* @method pullComponents
2222
* @param {Object} api
23-
* @param {Object} options { space: Number, separateFiles: Boolean, path: String }
23+
* @param {Object} options { fileName: string, separateFiles: Boolean, path: String }
2424
* @return {Promise<Object>}
2525
*/
2626
const pullComponents = async (api, options) => {
27-
const { space, separateFiles, path } = options
27+
const { fileName, separateFiles, path } = options
2828

2929
try {
3030
const componentGroups = await api.getComponentGroups()
@@ -43,7 +43,7 @@ const pullComponents = async (api, options) => {
4343

4444
if (separateFiles) {
4545
for (const comp in components) {
46-
const compFileName = `${components[comp].name}-${space}.json`
46+
const compFileName = `${components[comp].name}-${fileName}.json`
4747
const data = JSON.stringify(components[comp], null, 2)
4848
saveFileFactory(compFileName, data, path)
4949
}
@@ -52,15 +52,15 @@ const pullComponents = async (api, options) => {
5252
if (presets.length === 0) return
5353

5454
for (const preset in presets) {
55-
const presetFileName = `${presets[preset].name}-${space}.json`
55+
const presetFileName = `${presets[preset].name}-${fileName}.json`
5656
const data = JSON.stringify(presets[preset], null, 2)
5757
saveFileFactory(presetFileName, data, path)
5858
}
5959
console.log(`${chalk.green('✓')} We've saved your presets in files with the names of each preset`)
6060
return
6161
}
6262

63-
const file = `components.${space}.json`
63+
const file = `components.${fileName}.json`
6464
const data = JSON.stringify({ components }, null, 2)
6565

6666
console.log(`${chalk.green('✓')} We've saved your components in the file: ${file}`)
@@ -69,7 +69,7 @@ const pullComponents = async (api, options) => {
6969

7070
if (presets.length === 0) return
7171

72-
const presetsFile = `presets.${space}.json`
72+
const presetsFile = `presets.${fileName}.json`
7373
const presetsData = JSON.stringify({ presets }, null, 2)
7474

7575
console.log(`${chalk.green('✓')} We've saved your presets in the file: ${presetsFile}`)

tests/units/pull-components.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ describe('testing pullComponents', () => {
4040
}
4141

4242
const options = {
43-
space: SPACE
43+
compFileName: SPACE
4444
}
4545

4646
const expectFileName = `components.${SPACE}.json`

0 commit comments

Comments
 (0)