@@ -111,107 +111,105 @@ gulp.task('views-i18n', ['clean-i18n', 'views'], function () {
111111function apifyChallengeFn ( next ) {
112112 return function ( locale ) {
113113
114- //console.log("apify-challenge for locale: '" + locale + "'...");
115-
116- var index ,
117- worldsNum ,
118- //fields that are copied from ./index.json to /world/<world>/index.json
119- copyWorldFields = [
120- 'id' ,
121- 'name' ,
122- 'description' ,
123- 'world_path' ,
124- 'cover' ,
125- 'css_class' ,
126- 'visibility' ,
127- 'dependency' ,
128- 'type' ,
129- 'share_strategy' ,
130- 'sales_popup_after' ,
131- 'certificate_after' ,
132- 'teachers_guide' ,
133- 'updateForm' ,
134- 'socialText'
135- ] ,
136- countNext = 0 ,
137- formattedIndex ,
138- localePath = locale ? 'locales/' + locale + '/' : '' ;
139- function localNext ( ) {
140- if ( ++ countNext === worldsNum + 1 ) {
141- next ( ) ;
114+ var index ,
115+ worldsNum ,
116+ //fields that are copied from ./index.json to /world/<world>/index.json
117+ copyWorldFields = [
118+ 'id' ,
119+ 'name' ,
120+ 'description' ,
121+ 'world_path' ,
122+ 'cover' ,
123+ 'css_class' ,
124+ 'visibility' ,
125+ 'dependency' ,
126+ 'type' ,
127+ 'share_strategy' ,
128+ 'sales_popup_after' ,
129+ 'certificate_after' ,
130+ 'teachers_guide' ,
131+ 'updateForm' ,
132+ 'socialText'
133+ ] ,
134+ countNext = 0 ,
135+ formattedIndex ,
136+ localePath = locale ? 'locales/' + locale + '/' : '' ;
137+ function localNext ( ) {
138+ if ( ++ countNext === worldsNum + 1 ) {
139+ next ( ) ;
140+ }
142141 }
143- }
144- //work with them
145- index = require ( './' + chDescriptorsPath + localePath + 'index.json' ) ;
146- worldsNum = index . worlds . length ;
142+ //work with them
143+ index = require ( './' + chDescriptorsPath + localePath + 'index.json' ) ;
144+ worldsNum = index . worlds . length ;
147145
148- index . worlds . forEach ( function ( world ) {
149- var worldPath = './' + chDescriptorsPath + localePath + world . world_path ,
150- libWorldPath = './' + libPath + localePath + world . world_path ,
151- worldObj = { } ,
152- challenges = [ ] ,
153- formattedJSON ;
146+ index . worlds . forEach ( function ( world ) {
147+ var worldPath = './' + chDescriptorsPath + localePath + world . world_path ,
148+ libWorldPath = './' + libPath + localePath + world . world_path ,
149+ worldObj = { } ,
150+ challenges = [ ] ,
151+ formattedJSON ;
154152
155- worldObj = JSON . parse ( JSON . stringify ( require ( libWorldPath + '/index.json' ) ) ) ;
153+ worldObj = JSON . parse ( JSON . stringify ( require ( libWorldPath + '/index.json' ) ) ) ;
156154
157- copyWorldFields . forEach ( function ( field ) {
158- if ( world [ field ] ) {
159- worldObj [ field ] = world [ field ] ;
160- }
161- } ) ;
155+ copyWorldFields . forEach ( function ( field ) {
156+ if ( world [ field ] ) {
157+ worldObj [ field ] = world [ field ] ;
158+ }
159+ } ) ;
162160
163- //load all the challenges in an array
164- worldObj . challenges . forEach ( function ( ch , idx , arr ) {
165- var chFileName = worldPath + ch . substr ( 1 , ch . length - 1 ) ,
166- challenge = require ( chFileName ) ,
167- index = idx + 1 ,
168- hasNext = index !== ( arr . length ) ,
169- ch_obj = {
170- id : challenge . id ,
171- title : challenge . title ,
172- short_title : challenge . short_title ,
173- cover : challenge . cover ,
174- index : index ,
175- hasNext : hasNext ,
176- start_date : challenge . start_date
177- } ;
178- challenge . index = index ;
179- challenge . hasNext = hasNext ;
161+ //load all the challenges in an array
162+ worldObj . challenges . forEach ( function ( ch , idx , arr ) {
163+ var chFileName = worldPath + ch . substr ( 1 , ch . length - 1 ) ,
164+ challenge = require ( chFileName ) ,
165+ index = idx + 1 ,
166+ hasNext = index !== ( arr . length ) ,
167+ ch_obj = {
168+ id : challenge . id ,
169+ title : challenge . title ,
170+ short_title : challenge . short_title ,
171+ cover : challenge . cover ,
172+ index : index ,
173+ hasNext : hasNext ,
174+ start_date : challenge . start_date
175+ } ;
176+ challenge . index = index ;
177+ challenge . hasNext = hasNext ;
180178
181- fs . writeFile ( chFileName + ".json" , JSON . stringify ( challenge , null , 4 ) , function ( err ) {
182- if ( err ) {
183- throw err ;
184- }
179+ fs . writeFile ( chFileName + ".json" , JSON . stringify ( challenge , null , 4 ) , function ( err ) {
180+ if ( err ) {
181+ throw err ;
182+ }
183+ } ) ;
184+ challenges . push ( ch_obj ) ;
185185 } ) ;
186- challenges . push ( ch_obj ) ;
187- } ) ;
188186
189187
190- worldObj . challenges = challenges ;
188+ worldObj . challenges = challenges ;
191189
192- world . challenges_num = challenges . length ;
190+ world . challenges_num = challenges . length ;
193191
194- formattedJSON = JSON . stringify ( worldObj , null , 4 ) ;
195- //write the challenges with headers
196- fs . writeFile ( worldPath + '/index.json' , formattedJSON , function ( err ) {
192+ formattedJSON = JSON . stringify ( worldObj , null , 4 ) ;
193+ //write the challenges with headers
194+ fs . writeFile ( worldPath + '/index.json' , formattedJSON , function ( err ) {
195+ if ( err ) {
196+ throw err ;
197+ } else {
198+ localNext ( ) ;
199+ }
200+ } ) ;
201+ } ) ;
202+ //copy back the index
203+ formattedIndex = JSON . stringify ( index , null , 4 ) ;
204+ fs . writeFile ( chDescriptorsPath + localePath + 'index.json' , formattedIndex , function ( err ) {
197205 if ( err ) {
198206 throw err ;
199207 } else {
200208 localNext ( ) ;
201209 }
202210 } ) ;
203- } ) ;
204- //copy back the index
205- formattedIndex = JSON . stringify ( index , null , 4 ) ;
206- fs . writeFile ( chDescriptorsPath + localePath + 'index.json' , formattedIndex , function ( err ) {
207- if ( err ) {
208- throw err ;
209- } else {
210- localNext ( ) ;
211- }
212- } ) ;
213-
214- } } ;
211+ }
212+ }
215213
216214gulp . task ( 'apify-challenges' , [ 'copy-challenges' ] , function ( next ) {
217215 var countNext = 0 ;
0 commit comments