storyblok 3.25.1 → 3.25.2
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 +18 -0
- package/package.json +2 -2
- package/src/cli.js +24 -0
- package/src/constants.js +2 -1
- package/src/tasks/delete-components.js +2 -1
- package/src/tasks/delete-datasources.js +42 -0
- package/src/tasks/index.js +2 -1
- package/src/tasks/push-components.js +2 -1
- package/src/tasks/sync-commands/components.js +1 -1
- package/src/utils/api.js +18 -0
package/README.md
CHANGED
|
@@ -409,6 +409,24 @@ For view the CLI version
|
|
|
409
409
|
$ storyblok -V # or --version
|
|
410
410
|
```
|
|
411
411
|
|
|
412
|
+
### delete-datasources
|
|
413
|
+
|
|
414
|
+
The delete-datasources command enables you to remove all datasources within the designated space. By utilizing the `--by-slug` option, you can filter the datasources based on their slugs, selectively deleting specific datasources. Similarly, the `--by-name` option functions in the same way, allowing you to filter and delete datasources based on their names.
|
|
415
|
+
|
|
416
|
+
```sh
|
|
417
|
+
$ storyblok delete-datasources --space-id <SPACE_ID> # Will delete all datasources
|
|
418
|
+
```
|
|
419
|
+
|
|
420
|
+
```sh
|
|
421
|
+
$ storyblok delete-datasources --space-id <SPACE_ID> --by-slug global-translations # Will only delete datasources where the slug starts with global-translations
|
|
422
|
+
```
|
|
423
|
+
|
|
424
|
+
#### Options
|
|
425
|
+
|
|
426
|
+
* `space-id`: your space id
|
|
427
|
+
* `by-slug`: Filter Datasources by slug
|
|
428
|
+
* `by-name`: Filter Datasources by name
|
|
429
|
+
|
|
412
430
|
## Content migrations
|
|
413
431
|
|
|
414
432
|
Content migrations are a convenient way to change fields of your content.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "storyblok",
|
|
3
|
-
"version": "3.25.
|
|
3
|
+
"version": "3.25.2",
|
|
4
4
|
"description": "A simple CLI to start Storyblok from your command line.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"p-series": "^2.1.0",
|
|
43
43
|
"path": "^0.12.7",
|
|
44
44
|
"simple-uuid": "^0.0.1",
|
|
45
|
-
"storyblok-js-client": "^5.
|
|
45
|
+
"storyblok-js-client": "^5.14.0",
|
|
46
46
|
"update-notifier": "^5.1.0",
|
|
47
47
|
"xml-js": "^1.6.11"
|
|
48
48
|
},
|
package/src/cli.js
CHANGED
|
@@ -492,6 +492,30 @@ program
|
|
|
492
492
|
}
|
|
493
493
|
})
|
|
494
494
|
|
|
495
|
+
// delete-datasources
|
|
496
|
+
program
|
|
497
|
+
.command(COMMANDS.DELETE_DATASOURCES)
|
|
498
|
+
.requiredOption('--space-id <SPACE_ID>', 'Space id')
|
|
499
|
+
.option('--by-slug <SLUG>', 'Delete datasources by slug')
|
|
500
|
+
.option('--by-name <name>', 'Delete datasources by name')
|
|
501
|
+
.action(async (options) => {
|
|
502
|
+
console.log(`${chalk.blue('-')} Executing ${COMMANDS.DELETE_DATASOURCES} task`)
|
|
503
|
+
|
|
504
|
+
const { spaceId, bySlug, byName } = options
|
|
505
|
+
|
|
506
|
+
try {
|
|
507
|
+
if (!api.isAuthorized()) {
|
|
508
|
+
await api.processLogin()
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
api.setSpaceId(spaceId)
|
|
512
|
+
|
|
513
|
+
await tasks.deleteDatasources(api, { byName, bySlug })
|
|
514
|
+
} catch (e) {
|
|
515
|
+
errorHandler(e, COMMANDS.DELETE_DATASOURCES)
|
|
516
|
+
}
|
|
517
|
+
})
|
|
518
|
+
|
|
495
519
|
program.parse(process.argv)
|
|
496
520
|
|
|
497
521
|
if (program.rawArgs.length <= 2) {
|
package/src/constants.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const chalk = require('chalk')
|
|
2
2
|
const axios = require('axios')
|
|
3
3
|
const fs = require('fs')
|
|
4
|
+
const isEmpty = require('lodash/isEmpty')
|
|
4
5
|
const deleteComponent = require('./delete-component')
|
|
5
6
|
|
|
6
7
|
const isUrl = source => source.indexOf('http') === 0
|
|
@@ -44,7 +45,7 @@ const getDataFromPath = async (path) => {
|
|
|
44
45
|
const createContentList = (content, key) => {
|
|
45
46
|
if (content[key]) return content[key]
|
|
46
47
|
else if (Array.isArray(content)) return [...content]
|
|
47
|
-
else return [content]
|
|
48
|
+
else return !isEmpty(content) ? [content] : []
|
|
48
49
|
}
|
|
49
50
|
|
|
50
51
|
/**
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
const chalk = require('chalk')
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @method deleteDatasources
|
|
5
|
+
* @param {Object} api
|
|
6
|
+
* @param {Object} options { fileName: string, separateFiles: Boolean, path: String }
|
|
7
|
+
* @return {Promise<Object>}
|
|
8
|
+
*/
|
|
9
|
+
const deleteDatasources = async (api, options) => {
|
|
10
|
+
const { byName, bySlug } = options
|
|
11
|
+
|
|
12
|
+
try {
|
|
13
|
+
let datasources = await api.getDatasources()
|
|
14
|
+
|
|
15
|
+
if (bySlug) {
|
|
16
|
+
datasources = datasources.filter(datasource => datasource.slug.toLowerCase().startsWith(bySlug.toLowerCase()));
|
|
17
|
+
const filteredSlugs = datasources.map(obj => obj.slug);
|
|
18
|
+
const formattedSlugs = filteredSlugs.join(', ');
|
|
19
|
+
|
|
20
|
+
console.log(`${chalk.blue('-')} Datasources where slug starts with ${bySlug}: ${formattedSlugs}`);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (byName) {
|
|
24
|
+
datasources = datasources.filter(datasource => datasource.name.toLowerCase().startsWith(byName.toLowerCase()));
|
|
25
|
+
const filteredNames = datasources.map(obj => obj.name);
|
|
26
|
+
const formattedNames = filteredNames.join(', ');
|
|
27
|
+
|
|
28
|
+
console.log(`${chalk.blue('-')} Datasources where name starts with ${byName}: ${formattedNames}`);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
for (const datasource of datasources) {
|
|
32
|
+
console.log(`${chalk.blue('-')} Deleting ${datasource.name}`)
|
|
33
|
+
await api.deleteDatasource(datasource.id)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
} catch (e) {
|
|
37
|
+
console.error(`${chalk.red('X')} An error ocurred in delete-components task when deleting a datasource`)
|
|
38
|
+
return Promise.reject(new Error(e))
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
module.exports = deleteDatasources
|
package/src/tasks/index.js
CHANGED
|
@@ -11,5 +11,6 @@ module.exports = {
|
|
|
11
11
|
listSpaces: require('./list-spaces'),
|
|
12
12
|
importFiles: require('./import/import'),
|
|
13
13
|
deleteComponent: require('./delete-component'),
|
|
14
|
-
deleteComponents: require('./delete-components')
|
|
14
|
+
deleteComponents: require('./delete-components'),
|
|
15
|
+
deleteDatasources: require('./delete-datasources')
|
|
15
16
|
}
|
|
@@ -2,6 +2,7 @@ const axios = require('axios')
|
|
|
2
2
|
const fs = require('fs')
|
|
3
3
|
const chalk = require('chalk')
|
|
4
4
|
const PresetsLib = require('../utils/presets-lib')
|
|
5
|
+
const isEmpty = require('lodash/isEmpty')
|
|
5
6
|
|
|
6
7
|
const isUrl = source => source.indexOf('http') === 0
|
|
7
8
|
|
|
@@ -58,7 +59,7 @@ const getDataFromPath = async (path) => {
|
|
|
58
59
|
const createContentList = (content, key) => {
|
|
59
60
|
if (content[key]) return content[key]
|
|
60
61
|
else if (Array.isArray(content)) return [...content]
|
|
61
|
-
else return [content]
|
|
62
|
+
else return !isEmpty(content) ? [content] : []
|
|
62
63
|
}
|
|
63
64
|
|
|
64
65
|
module.exports = async (api, { source, presetsSource }) => {
|
|
@@ -112,7 +112,7 @@ class SyncComponents {
|
|
|
112
112
|
await this.presetsLib.createPresets(componentPresets, componentCreated.id)
|
|
113
113
|
}
|
|
114
114
|
} catch (e) {
|
|
115
|
-
if (e.response && e.response.status
|
|
115
|
+
if (e.response && e.response.status || e.status === 422) {
|
|
116
116
|
console.log(
|
|
117
117
|
`${chalk.yellow('-')} Component ${component.name} already exists, updating it...`
|
|
118
118
|
)
|
package/src/utils/api.js
CHANGED
|
@@ -238,6 +238,24 @@ module.exports = {
|
|
|
238
238
|
.catch(err => Promise.reject(err))
|
|
239
239
|
},
|
|
240
240
|
|
|
241
|
+
getDatasources () {
|
|
242
|
+
const client = this.getClient()
|
|
243
|
+
|
|
244
|
+
return client
|
|
245
|
+
.get(this.getPath('datasources'))
|
|
246
|
+
.then(data => data.data.datasources || [])
|
|
247
|
+
.catch(err => Promise.reject(err))
|
|
248
|
+
},
|
|
249
|
+
|
|
250
|
+
deleteDatasource (id) {
|
|
251
|
+
const client = this.getClient()
|
|
252
|
+
|
|
253
|
+
return client
|
|
254
|
+
.delete(this.getPath(`datasources/${id}`))
|
|
255
|
+
.catch(err => Promise.reject(err))
|
|
256
|
+
},
|
|
257
|
+
|
|
258
|
+
|
|
241
259
|
post (path, props) {
|
|
242
260
|
return this.sendRequest(path, 'post', props)
|
|
243
261
|
},
|