storyblok 3.14.0 → 3.15.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 +12 -0
- package/package.json +1 -1
- package/src/cli.js +25 -0
- package/src/tasks/index.js +1 -0
- package/src/tasks/pull-languages.js +39 -0
- package/src/utils/api.js +9 -0
- package/tests/constants.js +21 -1
- package/tests/units/pull-languages.spec.js +62 -0
package/README.md
CHANGED
|
@@ -28,6 +28,18 @@ Usage to kickstart a boilerplate, fieldtype or theme
|
|
|
28
28
|
$ storyblok select
|
|
29
29
|
```
|
|
30
30
|
|
|
31
|
+
### pull-languages
|
|
32
|
+
|
|
33
|
+
Download your space's languages schema as json. This command will download 1 file.
|
|
34
|
+
|
|
35
|
+
```sh
|
|
36
|
+
$ storyblok pull-languages --space <SPACE_ID>
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
#### Options
|
|
40
|
+
|
|
41
|
+
* `space`: your space id
|
|
42
|
+
|
|
31
43
|
### pull-components
|
|
32
44
|
|
|
33
45
|
Download your space's components schema as json. This command will download 2 files: 1 for the components and 1 for the presets.
|
package/package.json
CHANGED
package/src/cli.js
CHANGED
|
@@ -69,6 +69,31 @@ program
|
|
|
69
69
|
}
|
|
70
70
|
})
|
|
71
71
|
|
|
72
|
+
// pull-languages
|
|
73
|
+
program
|
|
74
|
+
.command('pull-languages')
|
|
75
|
+
.description("Download your space's languages schema as json")
|
|
76
|
+
.action(async () => {
|
|
77
|
+
console.log(`${chalk.blue('-')} Executing pull-languages task`)
|
|
78
|
+
const space = program.space
|
|
79
|
+
if (!space) {
|
|
80
|
+
console.log(chalk.red('X') + ' Please provide the space as argument --space YOUR_SPACE_ID.')
|
|
81
|
+
process.exit(0)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
try {
|
|
85
|
+
if (!api.isAuthorized()) {
|
|
86
|
+
await api.processLogin()
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
api.setSpaceId(space)
|
|
90
|
+
await tasks.pullLanguages(api, { space })
|
|
91
|
+
} catch (e) {
|
|
92
|
+
console.log(chalk.red('X') + ' An error occurred when executing the pull-languages task: ' + e.message)
|
|
93
|
+
process.exit(1)
|
|
94
|
+
}
|
|
95
|
+
})
|
|
96
|
+
|
|
72
97
|
// pull-components
|
|
73
98
|
program
|
|
74
99
|
.command(COMMANDS.PULL_COMPONENTS)
|
package/src/tasks/index.js
CHANGED
|
@@ -3,6 +3,7 @@ module.exports = {
|
|
|
3
3
|
scaffold: require('./scaffold'),
|
|
4
4
|
quickstart: require('./quickstart'),
|
|
5
5
|
pullComponents: require('./pull-components'),
|
|
6
|
+
pullLanguages: require('./pull-languages'),
|
|
6
7
|
pushComponents: require('./push-components'),
|
|
7
8
|
generateMigration: require('./migrations/generate'),
|
|
8
9
|
runMigration: require('./migrations/run'),
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
const fs = require('fs')
|
|
2
|
+
const chalk = require('chalk')
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @method pullLanguages
|
|
6
|
+
* @param {Object} api
|
|
7
|
+
* @param {Object} options { space: Number }
|
|
8
|
+
* @return {Promise<Object>}
|
|
9
|
+
*/
|
|
10
|
+
const pullLanguages = async (api, options) => {
|
|
11
|
+
const { space } = options
|
|
12
|
+
|
|
13
|
+
try {
|
|
14
|
+
const options = await api.getSpaceOptions()
|
|
15
|
+
const languages = {
|
|
16
|
+
default_lang_name: options.default_lang_name,
|
|
17
|
+
languages: options.languages
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const file = `languages.${space}.json`
|
|
21
|
+
const data = JSON.stringify(languages, null, 2)
|
|
22
|
+
|
|
23
|
+
console.log(`${chalk.green('✓')} We've saved your languages in the file: ${file}`)
|
|
24
|
+
|
|
25
|
+
fs.writeFile(`./${file}`, data, (err) => {
|
|
26
|
+
if (err) {
|
|
27
|
+
Promise.reject(err)
|
|
28
|
+
return
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
Promise.resolve(file)
|
|
32
|
+
})
|
|
33
|
+
} catch (e) {
|
|
34
|
+
console.error(`${chalk.red('X')} An error ocurred in pull-languages task when load components data`)
|
|
35
|
+
return Promise.reject(new Error(e))
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
module.exports = pullLanguages
|
package/src/utils/api.js
CHANGED
|
@@ -156,6 +156,15 @@ module.exports = {
|
|
|
156
156
|
.catch(err => Promise.reject(err))
|
|
157
157
|
},
|
|
158
158
|
|
|
159
|
+
getSpaceOptions () {
|
|
160
|
+
const client = this.getClient()
|
|
161
|
+
|
|
162
|
+
return client
|
|
163
|
+
.get(this.getPath(''))
|
|
164
|
+
.then((data) => data.data.space.options || {})
|
|
165
|
+
.catch((err) => Promise.reject(err))
|
|
166
|
+
},
|
|
167
|
+
|
|
159
168
|
getComponents () {
|
|
160
169
|
const client = this.getClient()
|
|
161
170
|
|
package/tests/constants.js
CHANGED
|
@@ -229,11 +229,31 @@ const FAKE_SPACES = () => [
|
|
|
229
229
|
}
|
|
230
230
|
]
|
|
231
231
|
|
|
232
|
+
const FAKE_SPACE_OPTIONS = () => ({
|
|
233
|
+
languages: [
|
|
234
|
+
{
|
|
235
|
+
code: 'pt',
|
|
236
|
+
name: 'Português'
|
|
237
|
+
},
|
|
238
|
+
{
|
|
239
|
+
code: 'nl-be',
|
|
240
|
+
name: 'Dutch (Belgian)'
|
|
241
|
+
}
|
|
242
|
+
],
|
|
243
|
+
hosted_backup: false,
|
|
244
|
+
onboarding_step: '3',
|
|
245
|
+
default_lang_name: 'English',
|
|
246
|
+
rev_share_enabled: true,
|
|
247
|
+
required_assest_fields: [],
|
|
248
|
+
use_translated_stories: false
|
|
249
|
+
})
|
|
250
|
+
|
|
232
251
|
module.exports = {
|
|
233
252
|
EMAIL_TEST,
|
|
234
253
|
TOKEN_TEST,
|
|
235
254
|
FAKE_STORIES,
|
|
236
255
|
PASSWORD_TEST,
|
|
237
256
|
FAKE_COMPONENTS,
|
|
238
|
-
FAKE_SPACES
|
|
257
|
+
FAKE_SPACES,
|
|
258
|
+
FAKE_SPACE_OPTIONS
|
|
239
259
|
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
const fs = require('fs')
|
|
2
|
+
const pullLanguages = require('../../src/tasks/pull-languages')
|
|
3
|
+
const { FAKE_SPACE_OPTIONS } = require('../constants')
|
|
4
|
+
|
|
5
|
+
jest.mock('fs')
|
|
6
|
+
|
|
7
|
+
describe('testing pullLanguages', () => {
|
|
8
|
+
afterEach(() => {
|
|
9
|
+
jest.clearAllMocks()
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
it('api.getSpaceOptions() should be called once time', () => {
|
|
13
|
+
const api = {
|
|
14
|
+
getSpaceOptions: jest.fn(() => Promise.resolve(FAKE_SPACE_OPTIONS()))
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return pullLanguages(api, {})
|
|
18
|
+
.then(() => {
|
|
19
|
+
expect(api.getSpaceOptions.mock.calls.length).toBe(1)
|
|
20
|
+
})
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
it('api.getSpaceOptions() should be call fs.writeFile correctly', async () => {
|
|
24
|
+
const SPACE = 12345
|
|
25
|
+
const BODY = FAKE_SPACE_OPTIONS()
|
|
26
|
+
|
|
27
|
+
const api = {
|
|
28
|
+
getSpaceOptions () {
|
|
29
|
+
return Promise.resolve(BODY)
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const options = {
|
|
34
|
+
space: SPACE
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const expectFileName = `languages.${SPACE}.json`
|
|
38
|
+
const expectData = {
|
|
39
|
+
default_lang_name: BODY.default_lang_name,
|
|
40
|
+
languages: BODY.languages
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return pullLanguages(api, options)
|
|
44
|
+
.then(_ => {
|
|
45
|
+
const [path, data] = fs.writeFile.mock.calls[0]
|
|
46
|
+
|
|
47
|
+
expect(fs.writeFile.mock.calls.length).toBe(1)
|
|
48
|
+
expect(path).toBe(`./${expectFileName}`)
|
|
49
|
+
expect(JSON.parse(data)).toEqual(expectData)
|
|
50
|
+
})
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
it('api.getSpaceOptions() when a error ocurred, catch the body response', async () => {
|
|
54
|
+
const _api = {
|
|
55
|
+
getSpaceOptions (_, fn) {
|
|
56
|
+
return Promise.reject(new Error('Failed'))
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
await expect(pullLanguages(_api, {})).rejects.toThrow('Error: Failed')
|
|
61
|
+
})
|
|
62
|
+
})
|