@@ -3,7 +3,6 @@ import Q from 'q';
33import mongoose from 'mongoose' ;
44import objectID from 'bson-objectid' ;
55import shortid from 'shortid' ;
6- import eachSeries from 'async/eachSeries' ;
76import User from '../models/user' ;
87import Project from '../models/project' ;
98
@@ -240,112 +239,109 @@ async function createProjectsInP5user(projectsInAllCategories) {
240239 User . findOne ( { username : 'p5' } , ( err , user ) => {
241240 if ( err ) throw err ;
242241
243- eachSeries ( projectsInAllCategories , ( projectsInOneCategory , categoryCallback ) => {
244- eachSeries ( projectsInOneCategory , async ( project , projectCallback ) => {
245- let newProject ;
246- const a = objectID ( ) . toHexString ( ) ;
247- const b = objectID ( ) . toHexString ( ) ;
248- const c = objectID ( ) . toHexString ( ) ;
249- const r = objectID ( ) . toHexString ( ) ;
250- const noNumberprojectName = project . projectName . replace ( / ( \d + ) / g, '' ) ;
251- if ( noNumberprojectName === 'Instance Mode: Instance Container ' ) {
252- newProject = new Project ( {
253- name : project . projectName ,
254- user : user . _id ,
255- files : [
256- {
257- name : 'root' ,
258- id : r ,
259- _id : r ,
260- children : [ a , b , c ] ,
261- fileType : 'folder'
262- } ,
263- {
264- name : 'sketch.js' ,
265- content : '// Instance Mode: Instance Container, please check its index.html file' ,
266- id : a ,
267- _id : a ,
268- fileType : 'file' ,
269- children : [ ]
270- } ,
271- {
272- name : 'index.html' ,
273- content : project . sketchContent ,
274- isSelectedFile : true ,
275- id : b ,
276- _id : b ,
277- fileType : 'file' ,
278- children : [ ]
279- } ,
280- {
281- name : 'style.css' ,
282- content : defaultCSS ,
283- id : c ,
284- _id : c ,
285- fileType : 'file' ,
286- children : [ ]
287- }
288- ] ,
289- _id : shortid . generate ( )
290- } ) ;
291- } else {
292- newProject = new Project ( {
293- name : project . projectName ,
294- user : user . _id ,
295- files : [
296- {
297- name : 'root' ,
298- id : r ,
299- _id : r ,
300- children : [ a , b , c ] ,
301- fileType : 'folder'
302- } ,
303- {
304- name : 'sketch.js' ,
305- content : project . sketchContent ,
306- id : a ,
307- _id : a ,
308- isSelectedFile : true ,
309- fileType : 'file' ,
310- children : [ ]
311- } ,
312- {
313- name : 'index.html' ,
314- content : defaultHTML ,
315- id : b ,
316- _id : b ,
317- fileType : 'file' ,
318- children : [ ]
319- } ,
320- {
321- name : 'style.css' ,
322- content : defaultCSS ,
323- id : c ,
324- _id : c ,
325- fileType : 'file' ,
326- children : [ ]
327- }
328- ] ,
329- _id : shortid . generate ( )
330- } ) ;
331- }
242+ Q . all ( projectsInAllCategories . map ( projectsInOneCategory => Q . all ( projectsInOneCategory . map ( async ( project ) => {
243+ let newProject ;
244+ const a = objectID ( ) . toHexString ( ) ;
245+ const b = objectID ( ) . toHexString ( ) ;
246+ const c = objectID ( ) . toHexString ( ) ;
247+ const r = objectID ( ) . toHexString ( ) ;
248+ const noNumberprojectName = project . projectName . replace ( / ( \d + ) / g, '' ) ;
249+ if ( noNumberprojectName === 'Instance Mode: Instance Container ' ) {
250+ newProject = new Project ( {
251+ name : project . projectName ,
252+ user : user . _id ,
253+ files : [
254+ {
255+ name : 'root' ,
256+ id : r ,
257+ _id : r ,
258+ children : [ a , b , c ] ,
259+ fileType : 'folder'
260+ } ,
261+ {
262+ name : 'sketch.js' ,
263+ content : '// Instance Mode: Instance Container, please check its index.html file' ,
264+ id : a ,
265+ _id : a ,
266+ fileType : 'file' ,
267+ children : [ ]
268+ } ,
269+ {
270+ name : 'index.html' ,
271+ content : project . sketchContent ,
272+ isSelectedFile : true ,
273+ id : b ,
274+ _id : b ,
275+ fileType : 'file' ,
276+ children : [ ]
277+ } ,
278+ {
279+ name : 'style.css' ,
280+ content : defaultCSS ,
281+ id : c ,
282+ _id : c ,
283+ fileType : 'file' ,
284+ children : [ ]
285+ }
286+ ] ,
287+ _id : shortid . generate ( )
288+ } ) ;
289+ } else {
290+ newProject = new Project ( {
291+ name : project . projectName ,
292+ user : user . _id ,
293+ files : [
294+ {
295+ name : 'root' ,
296+ id : r ,
297+ _id : r ,
298+ children : [ a , b , c ] ,
299+ fileType : 'folder'
300+ } ,
301+ {
302+ name : 'sketch.js' ,
303+ content : project . sketchContent ,
304+ id : a ,
305+ _id : a ,
306+ isSelectedFile : true ,
307+ fileType : 'file' ,
308+ children : [ ]
309+ } ,
310+ {
311+ name : 'index.html' ,
312+ content : defaultHTML ,
313+ id : b ,
314+ _id : b ,
315+ fileType : 'file' ,
316+ children : [ ]
317+ } ,
318+ {
319+ name : 'style.css' ,
320+ content : defaultCSS ,
321+ id : c ,
322+ _id : c ,
323+ fileType : 'file' ,
324+ children : [ ]
325+ }
326+ ] ,
327+ _id : shortid . generate ( )
328+ } ) ;
329+ }
332330
333- const assetsInProject = project . sketchContent . match ( / a s s e t s \/ [ \w - ] + \. [ \w ] * / g)
334- || project . sketchContent . match ( / a s s e t \/ [ \w - ] * / g) || [ ] ;
331+ const assetsInProject = project . sketchContent . match ( / a s s e t s \/ [ \w - ] + \. [ \w ] * / g)
332+ || project . sketchContent . match ( / a s s e t \/ [ \w - ] * / g) || [ ] ;
335333
334+ try {
336335 await addAssetsToProject ( assetsInProject , res , newProject ) ;
336+ } catch ( error ) {
337+ throw error ;
338+ }
337339
338- newProject . save ( ( saveErr , savedProject ) => {
339- if ( saveErr ) throw saveErr ;
340- console . log ( `Created a new project in p5 user: ${ savedProject . name } ` ) ;
341- projectCallback ( ) ;
342- } ) ;
343- } , ( categoryErr ) => {
344- categoryCallback ( ) ;
340+ newProject . save ( ( saveErr , savedProject ) => {
341+ if ( saveErr ) throw saveErr ;
342+ console . log ( `Created a new project in p5 user: ${ savedProject . name } ` ) ;
345343 } ) ;
346- } , ( examplesErr ) => {
347- process . exit ( ) ;
348- } ) ;
344+ } ) ) ) ) ;
349345 } ) ;
350346 } catch ( error ) {
351347 throw error ;
0 commit comments