storyblok 3.22.0 → 3.24.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/README.md +21 -2
- package/package.json +1 -1
- package/src/cli.js +4 -1
- package/src/tasks/delete-components.js +33 -14
- package/src/tasks/pull-components.js +6 -6
- package/tests/units/pull-components.spec.js +1 -1
package/README.md
CHANGED
|
@@ -98,7 +98,7 @@ $ storyblok pull-components --space <SPACE_ID> # Will save files like components
|
|
|
98
98
|
```
|
|
99
99
|
|
|
100
100
|
```sh
|
|
101
|
-
$ storyblok pull-components --space <SPACE_ID> --separate-files # Will save files like feature-
|
|
101
|
+
$ storyblok pull-components --space <SPACE_ID> --separate-files --file-name production # Will save files like feature-production.json grid-production.json
|
|
102
102
|
```
|
|
103
103
|
|
|
104
104
|
#### Options
|
|
@@ -106,6 +106,7 @@ $ storyblok pull-components --space <SPACE_ID> --separate-files # Will save file
|
|
|
106
106
|
* `space`: your space id
|
|
107
107
|
* `separate-files`: boolean flag to save components and presets in single files instead a file with all
|
|
108
108
|
* `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
|
|
109
110
|
|
|
110
111
|
### push-components
|
|
111
112
|
|
|
@@ -191,7 +192,25 @@ storyblok delete-components <SOURCE> --space <SPACE_ID>
|
|
|
191
192
|
```
|
|
192
193
|
|
|
193
194
|
#### Parameters
|
|
194
|
-
* `source`: can be a URL or path to JSON file.
|
|
195
|
+
* `source`: can be a URL or path to JSON file, the path to a json file could be to a single or multiple files separated by comma, like `./pages-1234.json,../User/components/grid-1234.json`
|
|
196
|
+
|
|
197
|
+
Using an **URL**
|
|
198
|
+
|
|
199
|
+
```sh
|
|
200
|
+
$ storyblok push-components https://raw.githubusercontent.com/storyblok/nuxtdoc/master/seed.components.json --space 67819
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
Using a **path** to a single file
|
|
204
|
+
|
|
205
|
+
```sh
|
|
206
|
+
$ storyblok push-components ./components.json --space 67819
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
Using a **path** to a multiple files
|
|
210
|
+
|
|
211
|
+
```sh
|
|
212
|
+
$ storyblok push-components ./page.json,../grid.json,./feature.json --space 67819
|
|
213
|
+
```
|
|
195
214
|
|
|
196
215
|
#### Options
|
|
197
216
|
* `space_id`: the space where the command should be executed.
|
package/package.json
CHANGED
package/src/cli.js
CHANGED
|
@@ -121,6 +121,7 @@ program
|
|
|
121
121
|
.command(COMMANDS.PULL_COMPONENTS)
|
|
122
122
|
.option('--sf, --separate-files [value]', 'Argument to create a single file for each component')
|
|
123
123
|
.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')
|
|
124
125
|
.description("Download your space's components schema as json")
|
|
125
126
|
.action(async (options) => {
|
|
126
127
|
console.log(`${chalk.blue('-')} Executing pull-components task`)
|
|
@@ -131,13 +132,15 @@ program
|
|
|
131
132
|
process.exit(0)
|
|
132
133
|
}
|
|
133
134
|
|
|
135
|
+
const fileName = options.fileName ? options.fileName : space
|
|
136
|
+
|
|
134
137
|
try {
|
|
135
138
|
if (!api.isAuthorized()) {
|
|
136
139
|
await api.processLogin()
|
|
137
140
|
}
|
|
138
141
|
|
|
139
142
|
api.setSpaceId(space)
|
|
140
|
-
await tasks.pullComponents(api, {
|
|
143
|
+
await tasks.pullComponents(api, { fileName, separateFiles, path })
|
|
141
144
|
} catch (e) {
|
|
142
145
|
errorHandler(e, COMMANDS.PULL_COMPONENTS)
|
|
143
146
|
}
|
|
@@ -7,26 +7,46 @@ const isUrl = source => source.indexOf('http') === 0
|
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Get the data from a local or remote JSON file
|
|
10
|
-
* @param {string}
|
|
10
|
+
* @param {string} path the local path or remote url of the file
|
|
11
11
|
* @returns {Promise<Object>} return the data from the source or an error
|
|
12
12
|
*/
|
|
13
|
-
const
|
|
14
|
-
if (!
|
|
13
|
+
const getDataFromPath = async (path) => {
|
|
14
|
+
if (!path) {
|
|
15
15
|
return {}
|
|
16
16
|
}
|
|
17
|
+
const sources = path.split(',')
|
|
18
|
+
const isList = sources.length > 1
|
|
17
19
|
|
|
18
20
|
try {
|
|
19
|
-
if (isUrl(
|
|
20
|
-
return (await axios.get(
|
|
21
|
+
if (isUrl(path)) {
|
|
22
|
+
return (await axios.get(path)).data
|
|
21
23
|
} else {
|
|
22
|
-
return JSON.parse(fs.readFileSync(
|
|
24
|
+
if (!isList) return JSON.parse(fs.readFileSync(sources[0], 'utf8'))
|
|
25
|
+
|
|
26
|
+
const data = []
|
|
27
|
+
sources.forEach((source) => {
|
|
28
|
+
data.push(JSON.parse(fs.readFileSync(source, 'utf8')))
|
|
29
|
+
})
|
|
30
|
+
return data
|
|
23
31
|
}
|
|
24
32
|
} catch (err) {
|
|
25
|
-
console.error(`${chalk.red('X')} Can not load json file from ${
|
|
33
|
+
console.error(`${chalk.red('X')} Can not load json file from ${path}`)
|
|
26
34
|
return Promise.reject(err)
|
|
27
35
|
}
|
|
28
36
|
}
|
|
29
37
|
|
|
38
|
+
/**
|
|
39
|
+
* Creat an array based in the content parameter and the key provided
|
|
40
|
+
* @param {object} content the data to create a list
|
|
41
|
+
* @param {string} key key to serch in the content
|
|
42
|
+
* @returns {Array} return the data from the source or an error
|
|
43
|
+
*/
|
|
44
|
+
const createContentList = (content, key) => {
|
|
45
|
+
if (content[key]) return content[key]
|
|
46
|
+
else if (Array.isArray(content)) return [...content]
|
|
47
|
+
else return [content]
|
|
48
|
+
}
|
|
49
|
+
|
|
30
50
|
/**
|
|
31
51
|
* Delete all components from your Space that occur in your Local JSON.
|
|
32
52
|
* @param api {Object}
|
|
@@ -37,7 +57,8 @@ const getDataFromSource = async (source) => {
|
|
|
37
57
|
*/
|
|
38
58
|
const deleteComponents = async (api, { source, reversed = false, dryRun = false }) => {
|
|
39
59
|
try {
|
|
40
|
-
const
|
|
60
|
+
const rawComponents = (await getDataFromPath(source)) || []
|
|
61
|
+
const sourceComponents = createContentList(rawComponents, 'components')
|
|
41
62
|
if (!reversed) {
|
|
42
63
|
return deleteAllComponents(api, sourceComponents, dryRun)
|
|
43
64
|
}
|
|
@@ -71,19 +92,17 @@ const deleteAllComponents = async (api, components, dryrun) => {
|
|
|
71
92
|
* @returns {Promise<void>}
|
|
72
93
|
*/
|
|
73
94
|
const deleteComponentsReversed = async (api, components, spaceComponents, dryrun) => {
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
-
.filter((value, index, self) =>
|
|
77
|
-
self.findIndex((o, i) => o.id === value.id && i !== index) < 0)
|
|
95
|
+
const toDeleteSpaceComponents = spaceComponents
|
|
96
|
+
.filter(spaceComponent => components.findIndex(o => o.name === spaceComponent.name) < 0)
|
|
78
97
|
console.log(chalk.blue('-') + ' Deleting all components which do not appear in the given source.')
|
|
79
|
-
for (const c of
|
|
98
|
+
for (const c of toDeleteSpaceComponents) {
|
|
80
99
|
await deleteComponentAndSkip(api, c, dryrun)
|
|
81
100
|
}
|
|
82
101
|
}
|
|
83
102
|
|
|
84
103
|
const deleteComponentAndSkip = async (api, c, dryrun) => {
|
|
85
104
|
try {
|
|
86
|
-
return await deleteComponent(api, { comp: c.
|
|
105
|
+
return await deleteComponent(api, { comp: c.name, dryrun: dryrun })
|
|
87
106
|
} catch (e) {
|
|
88
107
|
console.log(chalk.red('-') + ' Error deleting component ' + chalk.blue(c.name) + '! Skipped...')
|
|
89
108
|
}
|
|
@@ -20,11 +20,11 @@ const getNameFromComponentGroups = (groups, uuid) => {
|
|
|
20
20
|
/**
|
|
21
21
|
* @method pullComponents
|
|
22
22
|
* @param {Object} api
|
|
23
|
-
* @param {Object} options {
|
|
23
|
+
* @param {Object} options { fileName: string, separateFiles: Boolean, path: String }
|
|
24
24
|
* @return {Promise<Object>}
|
|
25
25
|
*/
|
|
26
26
|
const pullComponents = async (api, options) => {
|
|
27
|
-
const {
|
|
27
|
+
const { fileName, separateFiles, path } = options
|
|
28
28
|
|
|
29
29
|
try {
|
|
30
30
|
const componentGroups = await api.getComponentGroups()
|
|
@@ -43,7 +43,7 @@ const pullComponents = async (api, options) => {
|
|
|
43
43
|
|
|
44
44
|
if (separateFiles) {
|
|
45
45
|
for (const comp in components) {
|
|
46
|
-
const compFileName = `${components[comp].name}-${
|
|
46
|
+
const compFileName = `${components[comp].name}-${fileName}.json`
|
|
47
47
|
const data = JSON.stringify(components[comp], null, 2)
|
|
48
48
|
saveFileFactory(compFileName, data, path)
|
|
49
49
|
}
|
|
@@ -52,7 +52,7 @@ const pullComponents = async (api, options) => {
|
|
|
52
52
|
if (presets.length === 0) return
|
|
53
53
|
|
|
54
54
|
for (const preset in presets) {
|
|
55
|
-
const presetFileName = `${presets[preset].name}-${
|
|
55
|
+
const presetFileName = `${presets[preset].name}-${fileName}.json`
|
|
56
56
|
const data = JSON.stringify(presets[preset], null, 2)
|
|
57
57
|
saveFileFactory(presetFileName, data, path)
|
|
58
58
|
}
|
|
@@ -60,7 +60,7 @@ const pullComponents = async (api, options) => {
|
|
|
60
60
|
return
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
const file = `components.${
|
|
63
|
+
const file = `components.${fileName}.json`
|
|
64
64
|
const data = JSON.stringify({ components }, null, 2)
|
|
65
65
|
|
|
66
66
|
console.log(`${chalk.green('✓')} We've saved your components in the file: ${file}`)
|
|
@@ -69,7 +69,7 @@ const pullComponents = async (api, options) => {
|
|
|
69
69
|
|
|
70
70
|
if (presets.length === 0) return
|
|
71
71
|
|
|
72
|
-
const presetsFile = `presets.${
|
|
72
|
+
const presetsFile = `presets.${fileName}.json`
|
|
73
73
|
const presetsData = JSON.stringify({ presets }, null, 2)
|
|
74
74
|
|
|
75
75
|
console.log(`${chalk.green('✓')} We've saved your presets in the file: ${presetsFile}`)
|