This repository was archived by the owner on Jan 19, 2026. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -145,6 +145,14 @@ $ storyblok run-migration --space <SPACE_ID> --component <COMPONENT_NAME> --fiel
145145* ` field ` : name of field
146146* ` dryrun ` : when passed as an argument, does not perform the migration
147147
148+ ### spaces
149+
150+ List all spaces of the logged account
151+
152+ ``` sh
153+ $ storyblok spaces
154+ ```
155+
148156### Help
149157
150158For global help
Original file line number Diff line number Diff line change @@ -283,6 +283,23 @@ program
283283 }
284284 } )
285285
286+ // list spaces
287+ program
288+ . command ( 'spaces' )
289+ . description ( 'List all spaces of the logged account' )
290+ . action ( async ( ) => {
291+ try {
292+ if ( ! api . isAuthorized ( ) ) {
293+ await api . processLogin ( )
294+ }
295+
296+ await tasks . listSpaces ( api )
297+ } catch ( e ) {
298+ console . log ( chalk . red ( 'X' ) + ' An error ocurred to listing sapces : ' + e . message )
299+ process . exit ( 1 )
300+ }
301+ } )
302+
286303program . parse ( process . argv )
287304
288305if ( program . rawArgs . length <= 2 ) {
Original file line number Diff line number Diff line change @@ -5,5 +5,6 @@ module.exports = {
55 pullComponents : require ( './pull-components' ) ,
66 pushComponents : require ( './push-components' ) ,
77 generateMigration : require ( './migrations/generate' ) ,
8- runMigration : require ( './migrations/run' )
8+ runMigration : require ( './migrations/run' ) ,
9+ listSpaces : require ( './list-spaces' )
910}
Original file line number Diff line number Diff line change 1+ const chalk = require ( 'chalk' )
2+
3+ /**
4+ * @method listSpaces
5+ * @param api - Pass the api instance as a parameter
6+ * @return {Promise }
7+ */
8+
9+ const listSpaces = async ( api ) => {
10+ console . log ( )
11+ console . log ( chalk . green ( '✓' ) + ' Loading spaces...' )
12+ console . log ( )
13+
14+ if ( ! api ) {
15+ console . log ( chalk . red ( 'X' ) + 'Api instance is required to make the request' )
16+ return [ ]
17+ }
18+
19+ const spaces = await api . getAllSpaces ( )
20+ . then ( res => res )
21+ . catch ( err => Promise . reject ( err ) )
22+
23+ if ( ! spaces ) {
24+ console . log ( chalk . red ( 'X' ) + ' No spaces were found for this user ' )
25+ return [ ]
26+ }
27+
28+ spaces . map ( space => {
29+ console . log ( `${ space . name } (id: ${ space . id } )` )
30+ } )
31+
32+ return spaces
33+ }
34+
35+ module . exports = listSpaces
Original file line number Diff line number Diff line change @@ -189,5 +189,12 @@ module.exports = {
189189 const _path = this . getPath ( path )
190190
191191 return client [ method ] ( _path , props )
192+ } ,
193+
194+ async getAllSpaces ( ) {
195+ return await this . getClient ( )
196+ . get ( 'spaces/' , { } )
197+ . then ( res => res . data . spaces || [ ] )
198+ . catch ( err => Promise . reject ( err ) )
192199 }
193200}
Original file line number Diff line number Diff line change @@ -126,10 +126,34 @@ const FAKE_STORIES = () => [
126126 }
127127]
128128
129+ const FAKE_SPACES = ( ) => [
130+ {
131+ name : 'Example Space' ,
132+ domain : 'https://example.storyblok.com' ,
133+ uniq_domain : null ,
134+ plan : 'starter' ,
135+ plan_level : 0 ,
136+ limits : { } ,
137+ created_at : '2018-11-10T15:33:18.402Z' ,
138+ id : 0
139+ } ,
140+ {
141+ name : 'Example Space Two' ,
142+ domain : 'https://example-two.storyblok.com' ,
143+ uniq_domain : null ,
144+ plan : 'starter' ,
145+ plan_level : 0 ,
146+ limits : { } ,
147+ created_at : '2018-11-10T15:33:18.402Z' ,
148+ id : 1
149+ }
150+ ]
151+
129152module . exports = {
130153 EMAIL_TEST ,
131154 TOKEN_TEST ,
132155 FAKE_STORIES ,
133156 PASSWORD_TEST ,
134- FAKE_COMPONENTS
157+ FAKE_COMPONENTS ,
158+ FAKE_SPACES
135159}
Original file line number Diff line number Diff line change 1+ const { listSpaces } = require ( '../../src/tasks/' )
2+ const { FAKE_SPACES } = require ( '../constants' )
3+
4+ describe ( 'Test spaces method' , ( ) => {
5+ it ( 'Testing list-spaces funtion without api instance' , async ( ) => {
6+ try {
7+ const spaces = await listSpaces ( )
8+ expect ( spaces ) . toStrictEqual ( [ ] )
9+ } catch ( e ) {
10+ console . error ( e )
11+ }
12+ } )
13+ it ( 'Testing list-spaces funtion with api instance' , async ( ) => {
14+ const FAKE_API = {
15+ getAllSpaces : jest . fn ( ( ) => Promise . resolve ( FAKE_SPACES ( ) ) )
16+ }
17+ expect (
18+ await listSpaces ( FAKE_API )
19+ ) . toEqual ( FAKE_SPACES ( ) )
20+ expect ( FAKE_API . getAllSpaces ) . toHaveBeenCalled ( )
21+ } )
22+ } )
You can’t perform that action at this time.
0 commit comments