11import fs from 'fs'
22import moment from 'moment'
33// @ts -ignore
4- import * as git from 'isomorphic-git/dist'
4+ import * as git from 'isomorphic-git/dist/for-node/isomorphic-git '
55import Model from './model'
66
7- const { http } = require ( 'isomorphic-git/dist/http' )
8-
97export default class Deploy extends Model {
108 outputDir : string = `${ this . appDir } /output`
119
@@ -19,9 +17,14 @@ export default class Deploy extends Model {
1917 const { setting } = this . db
2018 this . platformAddress = ( {
2119 github : 'github.com' ,
22- coding : 'git.coding.net' ,
20+ coding : 'e.coding.net' ,
21+ } as any ) [ setting . platform || 'github' ]
22+ const preUrl = ( {
23+ github : `${ setting . username } :${ setting . token } ` ,
24+ coding : `${ setting . tokenUsername } :${ setting . token } ` ,
2325 } as any ) [ setting . platform || 'github' ]
24- this . remoteUrl = `https://${ setting . username } :${ setting . token } @${ this . platformAddress } /${ setting . username } /${ setting . repository } .git`
26+
27+ this . remoteUrl = `https://${ preUrl } @${ this . platformAddress } /${ setting . username } /${ setting . repository } .git`
2528 }
2629
2730 /**
@@ -50,13 +53,13 @@ export default class Deploy extends Model {
5053 }
5154 if ( ! isRepo ) {
5255 await git . init ( { fs, dir : this . outputDir } )
53- await git . setConfig ( {
56+ await git . config ( {
5457 fs,
5558 dir : this . outputDir ,
5659 path : 'user.name' ,
5760 value : setting . username ,
5861 } )
59- await git . setConfig ( {
62+ await git . config ( {
6063 fs,
6164 dir : this . outputDir ,
6265 path : 'user.email' ,
@@ -67,7 +70,10 @@ export default class Deploy extends Model {
6770 await git . addRemote ( {
6871 fs, dir : this . outputDir , remote : 'origin' , url : this . remoteUrl , force : true ,
6972 } )
70- await git . listRemotes ( { fs, dir : this . outputDir } )
73+ const info = await git . getRemoteInfo ( {
74+ core : 'default' ,
75+ url : this . remoteUrl ,
76+ } )
7177 } catch ( e ) {
7278 console . log ( 'Test Remote Error: ' , e . message )
7379 result . success = false
@@ -105,13 +111,13 @@ export default class Deploy extends Model {
105111
106112 try {
107113 await git . init ( { fs, dir : this . outputDir } )
108- await git . setConfig ( {
114+ await git . config ( {
109115 fs,
110116 dir : this . outputDir ,
111117 path : 'user.name' ,
112118 value : setting . username ,
113119 } )
114- await git . setConfig ( {
120+ await git . config ( {
115121 fs,
116122 dir : this . outputDir ,
117123 path : 'user.email' ,
@@ -126,19 +132,18 @@ export default class Deploy extends Model {
126132 await git . addRemote ( {
127133 fs, dir : this . outputDir , remote : 'origin' , url : this . remoteUrl , force : true ,
128134 } )
129- // await git.fastCheckout({ fs, dir: this.outputDir, ref: setting.branch })
135+
130136 await this . checkCurrentBranch ( )
131- // const pushRes = await git.push({
132- // fs,
133- // dir: this.outputDir,
134- // remote: 'origin',
135- // ref: setting.branch,
136- // force: true,
137- // http,
138- // })
137+ const pushRes = await git . push ( {
138+ fs,
139+ dir : this . outputDir ,
140+ remote : 'origin' ,
141+ ref : setting . branch ,
142+ force : true ,
143+ } )
139144 return {
140145 success : true ,
141- // data: pushRes,
146+ data : pushRes ,
142147 message : '' ,
143148 localBranchs,
144149 }
@@ -175,18 +180,17 @@ export default class Deploy extends Model {
175180
176181 await this . checkCurrentBranch ( )
177182
178- // const pushRes = await git.push({
179- // fs,
180- // dir: this.outputDir,
181- // remote: 'origin',
182- // ref: setting.branch,
183- // force: true,
184- // http,
185- // })
186- // console.log('pushRes', pushRes)
183+ const pushRes = await git . push ( {
184+ fs,
185+ dir : this . outputDir ,
186+ remote : 'origin' ,
187+ ref : setting . branch ,
188+ force : true ,
189+ } )
190+ console . log ( 'pushRes' , pushRes )
187191 return {
188192 success : true ,
189- // data: pushRes,
193+ data : pushRes ,
190194 message : '' ,
191195 localBranchs,
192196 }
@@ -215,7 +219,7 @@ export default class Deploy extends Model {
215219 await git . branch ( { fs, dir : this . outputDir , ref : setting . branch } )
216220 }
217221
218- await git . checkout ( { fs, dir : this . outputDir , ref : setting . branch } )
222+ await git . fastCheckout ( { fs, dir : this . outputDir , ref : setting . branch } )
219223 }
220224 }
221225}
0 commit comments