@@ -20,23 +20,46 @@ export async function createApiData({ props, state }) {
2020 const { contents } = props ;
2121 const sandboxId = state . get ( 'editor.currentId' ) ;
2222 const sandbox = state . get ( `editor.sandboxes.${ sandboxId } ` ) ;
23- let apiData = { } ;
23+ let apiData = {
24+ files : [ ] ,
25+ } ;
2426 const filePaths = Object . keys ( contents . files ) ;
27+
28+ let packageJSON = { } ;
29+ const projectPackage = contents . files [ 'package.json' ] ;
30+
31+ if ( projectPackage ) {
32+ const data = await projectPackage . async ( 'text' ) ; // eslint-disable-line no-await-in-loop
33+
34+ const parsed = JSON . parse ( data ) ;
35+ packageJSON = parsed ;
36+ }
37+ packageJSON = omitHomepage ( packageJSON ) ;
38+
39+ // We force the sandbox id, so ZEIT will always group the deployments to a
40+ // single sandbox
41+ packageJSON . name = `csb-${ sandbox . id } ` ;
42+
43+ apiData . name = `csb-${ sandbox . id } ` ;
44+ apiData . deploymentType = 'NPM' ;
45+ apiData . public = true ;
46+
47+ apiData . files . push ( {
48+ file : 'package.json' ,
49+ data : JSON . stringify ( packageJSON , null , 2 ) ,
50+ } ) ;
51+
2552 for ( let i = 0 ; i < filePaths . length ; i += 1 ) {
2653 const filePath = filePaths [ i ] ;
2754 const file = contents . files [ filePath ] ;
2855
29- if ( ! file . dir ) {
30- apiData [ filePath ] = await file . async ( 'text' ) ; // eslint-disable-line no-await-in-loop
56+ if ( ! file . dir && filePath !== 'package.json' ) {
57+ const data = await file . async ( 'text' ) ; // eslint-disable-line no-await-in-loop
58+
59+ apiData . files . push ( { file : filePath , data } ) ;
3160 }
3261 }
3362
34- apiData . package = omitHomepage ( JSON . parse ( apiData [ 'package.json' ] ) ) ;
35- // We force the sandbox id, so ZEIT will always group the deployments to a
36- // single sandbox
37- apiData . package . name = `csb-${ sandbox . id } ` ;
38- delete apiData [ 'package.json' ] ;
39-
4063 const template = getTemplate ( sandbox . template ) ;
4164
4265 if ( template . alterDeploymentData ) {
@@ -53,7 +76,7 @@ export function postToZeit({ http, path, props, state }) {
5376 return http
5477 . request ( {
5578 method : 'POST' ,
56- url : 'https://api.zeit.co/now/deployments' ,
79+ url : 'https://api.zeit.co/v3/ now/deployments' ,
5780 body : apiData ,
5881 headers : { Authorization : `bearer ${ token } ` } ,
5982 } )
0 commit comments