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

Commit 8019b46

Browse files
author
Thiago Saife
authored
Merge pull request #877 from storyblok/feat-int-728-cli-china-region
feat(int 728): china region
2 parents 327f2cf + 7ad7d8d commit 8019b46

8 files changed

Lines changed: 94 additions & 70 deletions

File tree

README.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,13 @@ You found an issue?<br>Tell us about it - <a href="https://github.com/storyblok/
1010
[![GitHub issues](https://img.shields.io/github/issues/storyblok/storyblok.svg?style=flat-square&v=1)](https://github.com/storyblok/storyblok/issues?q=is%3Aopen+is%3Aissue)
1111
[![GitHub closed issues](https://img.shields.io/github/issues-closed/storyblok/storyblok.svg?style=flat-square&v=1)](https://github.com/storyblok/storyblok/issues?q=is%3Aissue+is%3Aclosed)
1212

13+
## BREAKING CHANGE
14+
15+
We added the `region` option upon login. If you are using the CLI, please `logout` and `login` again providing your user region.
16+
1317
## Installation
1418

15-
Make sure you've node `>= 9.11.0` installed.
19+
Make sure you have Node `>= 9.11.0` installed.
1620

1721
```sh
1822
$ npm i storyblok -g
@@ -51,7 +55,6 @@ $ storyblok pull-components --space <SPACE_ID> --region <REGION>
5155
#### Options
5256

5357
* `space`: your space id
54-
* `region`: your space region (default: `eu`). If your space was created under US region, you should use `us` instead.
5558

5659
### push-components
5760

@@ -64,7 +67,6 @@ $ storyblok push-components <SOURCE> --space <SPACE_ID> --region <REGION> --pres
6467
#### Parameters
6568

6669
* `source`: can be a URL or path to JSON file.
67-
* `region`: your space region (default: `eu`). If your space was created under US region, you should use `us` instead.
6870

6971
Using an **URL**
7072

@@ -81,7 +83,6 @@ $ storyblok push-components ./components.json --space 67819
8183
#### Options
8284

8385
* `space`: your space id
84-
* `region`: your space region (default: `eu`). If your space was created under US region, you should use `us` instead.
8586
* `presets-source` (optional): it can be a URL or path to JSON file with the presets
8687

8788
#### Examples
@@ -170,7 +171,6 @@ $ storyblok sync --type <COMMAND> --source <SPACE_ID> --target <SPACE_ID>
170171
* `type`: describe the command type to execute. Can be: `folders`, `components`, `stories`, `datasources` or `roles`. It's possible pass multiple types separated by comma (`,`).
171172
* `source`: the source space to use to sync
172173
* `target`: the target space to use to sync
173-
* `region`: your space region (default: `eu`). If your space was created under US region, you should use `us` instead.
174174

175175
#### Examples
176176

@@ -205,6 +205,11 @@ Login to the Storyblok cli
205205
```sh
206206
$ storyblok login
207207
```
208+
#### Options
209+
210+
* `email`: your user's email address
211+
* `password`: your user's password
212+
* `region`: your user's region (default: `eu`). You can use `us`, `cn` or `eu`. This region will be used for the other cli's commands.
208213

209214
### user
210215

@@ -228,7 +233,6 @@ It's important to note that the `component` and `field` parameters are required
228233
* `space`: space where the component is
229234
* `component`: component name. It needs to be a valid component
230235
* `field`: name of field
231-
* `region`: your space region (default: `eu`). If your space was created under US region, you should use `us` instead.
232236

233237
### run-migration
234238

@@ -255,7 +259,6 @@ $ storyblok run-migration --publish published --space 1234 --component article -
255259
* `published`: only publish stories that already are published and don't have unpublished changes
256260
* `published-with-changes`: publish stories that are published and have unpublished changes
257261
* `publish-languages` (optional): publish specific languages. You can publish more than one language at a time by separating the languages by `,`
258-
* `region`: your space region (default: `eu`). If your space was created under US region, you should use `us` instead.
259262

260263
### rollback-migration
261264

@@ -275,6 +278,7 @@ $ storyblok rollback-migration --space 1234 --component Product --field title
275278

276279
### spaces
277280

281+
278282
List all spaces of the logged account
279283

280284
```sh

src/cli.js

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ program
3939
program
4040
.command(COMMANDS.LOGIN)
4141
.description('Login to the Storyblok cli')
42-
.action(async () => {
42+
.action(async (options) => {
4343
if (api.isAuthorized()) {
4444
console.log(chalk.green('✓') + ' The user has been already logged. If you want to change the logged user, you must logout and login again')
4545
return
@@ -63,8 +63,11 @@ program
6363
try {
6464
const user = await api.getUser()
6565
console.log(chalk.green('✓') + ` Hi ${user.friendly_name}, you current logged in with: ${creds.get().email}`)
66-
} catch (e) {}
67-
return
66+
} catch (e) {
67+
console.log(chalk.red('X') + ` Please check if your current region matches your user's region: ${e.message}.`)
68+
} finally {
69+
process.exit(0)
70+
}
6871
}
6972
console.log(chalk.red('X') + ' There is currently no user logged.')
7073
})
@@ -112,9 +115,8 @@ program
112115
// pull-components
113116
program
114117
.command(COMMANDS.PULL_COMPONENTS)
115-
.option('-r, --region [value]', 'region', 'eu')
116118
.description("Download your space's components schema as json")
117-
.action(async (source) => {
119+
.action(async () => {
118120
console.log(`${chalk.blue('-')} Executing pull-components task`)
119121
const space = program.space
120122
if (!space) {
@@ -127,11 +129,6 @@ program
127129
await api.processLogin()
128130
}
129131

130-
const { region } = source
131-
if (program.args.length > 0) {
132-
api.setRegion(region)
133-
}
134-
135132
api.setSpaceId(space)
136133
await tasks.pullComponents(api, { space })
137134
} catch (e) {
@@ -143,7 +140,6 @@ program
143140
program
144141
.command(COMMANDS.PUSH_COMPONENTS + ' <source>')
145142
.option('-p, --presets-source <presetsSource>', 'Path to presets file')
146-
.option('-r, --region [value]', 'region', 'eu')
147143
.description("Download your space's components schema as json. The source parameter can be a URL to your JSON file or a path to it")
148144
.action(async (source, options) => {
149145
console.log(`${chalk.blue('-')} Executing push-components task`)
@@ -160,11 +156,6 @@ program
160156
await api.processLogin()
161157
}
162158

163-
const { region } = options
164-
if (program.args.length > 0) {
165-
api.setRegion(region)
166-
}
167-
168159
api.setSpaceId(space)
169160
await tasks.pushComponents(api, { source, presetsSource })
170161
} catch (e) {
@@ -176,7 +167,7 @@ program
176167
program
177168
.command('delete-component <component>')
178169
.description('Delete a single component on your space.')
179-
.action(async (component, options) => {
170+
.action(async (component) => {
180171
console.log(`${chalk.blue('-')} Executing delete-component task`)
181172
const space = program.space
182173
if (!space) {
@@ -187,6 +178,7 @@ program
187178
if (!api.isAuthorized()) {
188179
await api.processLogin()
189180
}
181+
190182
api.setSpaceId(space)
191183
await tasks.deleteComponent(api, { comp: component })
192184
} catch (e) {
@@ -212,6 +204,7 @@ program
212204
if (!api.isAuthorized()) {
213205
await api.processLogin()
214206
}
207+
215208
api.setSpaceId(space)
216209
await tasks.deleteComponents(api, { source, dryRun: !!options.dryrun, reversed: !!options.reverse })
217210
} catch (e) {
@@ -268,7 +261,6 @@ program
268261
.requiredOption('--type <TYPE>', 'Define what will be sync. Can be components, folders, stories, datasources or roles')
269262
.requiredOption('--source <SPACE_ID>', 'Source space id')
270263
.requiredOption('--target <SPACE_ID>', 'Target space id')
271-
.option('-r, --region [value]', 'region', 'eu')
272264
.action(async (options) => {
273265
console.log(`${chalk.blue('-')} Sync data between spaces\n`)
274266

@@ -280,12 +272,9 @@ program
280272
const {
281273
type,
282274
source,
283-
target,
284-
region
275+
target
285276
} = options
286277

287-
api.setRegion(region)
288-
289278
const _types = type.split(',') || []
290279
_types.forEach(_type => {
291280
if (!SYNC_TYPES.includes(_type)) {
@@ -314,6 +303,10 @@ program
314303
.description('Start a project quickly')
315304
.action(async () => {
316305
try {
306+
if (!api.isAuthorized()) {
307+
await api.processLogin()
308+
}
309+
317310
const space = program.space
318311
const questions = getQuestions('quickstart', { space }, api)
319312
const answers = await inquirer.prompt(questions)
@@ -327,7 +320,6 @@ program
327320
program
328321
.command(COMMANDS.GENERATE_MIGRATION)
329322
.description('Generate a content migration file')
330-
.option('-r, --region [value]', 'region', 'eu')
331323
.requiredOption('-c, --component <COMPONENT_NAME>', 'Name of the component')
332324
.requiredOption('-f, --field <FIELD_NAME>', 'Name of the component field')
333325
.action(async (options) => {
@@ -347,9 +339,6 @@ program
347339
await api.processLogin()
348340
}
349341

350-
const { region } = options
351-
api.setRegion(region)
352-
353342
api.setSpaceId(space)
354343
await tasks.generateMigration(api, component, field)
355344
} catch (e) {
@@ -363,7 +352,6 @@ program
363352
.description('Run a migration file')
364353
.requiredOption('-c, --component <COMPONENT_NAME>', 'Name of the component')
365354
.requiredOption('-f, --field <FIELD_NAME>', 'Name of the component field')
366-
.option('-r, --region [value]', 'region', 'eu')
367355
.option('--dryrun', 'Do not update the story content')
368356
.option('--publish <PUBLISH_OPTION>', 'Publish the content. It can be: all, published or published-with-changes')
369357
.option('--publish-languages <LANGUAGES>', 'Publish specific languages')
@@ -450,7 +438,7 @@ program
450438

451439
await tasks.listSpaces(api)
452440
} catch (e) {
453-
console.log(chalk.red('X') + ' An error ocurred to listing sapces : ' + e.message)
441+
console.log(chalk.red('X') + ' An error ocurred to listing spaces: ' + e.message)
454442
process.exit(1)
455443
}
456444
})
@@ -496,7 +484,7 @@ if (program.rawArgs.length <= 2) {
496484

497485
function errorHandler (e, command) {
498486
if (/404/.test(e.message)) {
499-
console.log(chalk.yellow('/!\\') + ' If your space was created under US region, you must provide the region as argument --region us. Otherwise, you can use the default --region eu or omit this flag.')
487+
console.log(chalk.yellow('/!\\') + ' If your space was created under US or CN region, you must provide the region us or cn upon login.')
500488
} else {
501489
console.log(chalk.red('X') + ' An error occurred when executing the ' + command + ' task: ' + e || e.message)
502490
}

src/constants.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
const API_URL = 'https://api.storyblok.com/v1/'
22
const US_API_URL = 'https://api-us.storyblok.com/v1/'
3+
const CN_API_URL = 'https://api.storyblokchina.cn/v1/'
34
const LOGIN_URL = `${API_URL}users/login`
45
const SIGNUP_URL = `${API_URL}users/signup`
5-
const USER_INFO = `${API_URL}users/me`
66

77
const SYNC_TYPES = [
88
'folders',
@@ -33,7 +33,7 @@ module.exports = {
3333
SIGNUP_URL,
3434
API_URL,
3535
SYNC_TYPES,
36-
USER_INFO,
3736
US_API_URL,
37+
CN_API_URL,
3838
COMMANDS
3939
}

0 commit comments

Comments
 (0)