1
- import * as childProcess from 'child_process' ;
2
1
import * as fs from 'fs' ;
3
2
import * as os from 'os' ;
4
3
import * as path from 'path' ;
5
4
import * as semver from 'semver' ;
6
-
7
5
import { requestBody , JsonObject , requestBinary } from './utils/http_utils' ;
8
- import { changeFilePermissions , generateConfigFile , getBinaryPathFromConfig , removeFiles , unzipFile } from './utils/file_utils' ;
6
+ import { getBinaryPathFromConfig , removeFiles , unzipFile } from './utils/file_utils' ;
9
7
import { isExpired } from './utils/file_utils' ;
10
8
import { OUT_DIR , ProviderClass , ProviderConfig , ProviderInterface } from './provider' ;
11
- import rimraf = require( 'rimraf' ) ;
12
9
13
10
export class Chromium extends ProviderClass implements ProviderInterface {
14
11
cacheFileName = 'chromium-all.json' ;
@@ -21,7 +18,6 @@ export class Chromium extends ProviderClass implements ProviderInterface {
21
18
osArch = os . arch ( ) ;
22
19
outDir = OUT_DIR ;
23
20
proxy : string = null ;
24
- maxVersion : string = null ;
25
21
26
22
constructor ( config ?: ProviderConfig ) {
27
23
super ( ) ;
@@ -32,7 +28,6 @@ export class Chromium extends ProviderClass implements ProviderInterface {
32
28
this . osType = this . setVar ( 'osType' , this . osType , config ) ;
33
29
this . outDir = this . setVar ( 'outDir' , this . outDir , config ) ;
34
30
this . proxy = this . setVar ( 'proxy' , this . proxy , config ) ;
35
- this . maxVersion = this . setVar ( 'maxVersion' , this . maxVersion , config ) ;
36
31
}
37
32
38
33
private makeDirectory ( fileName : string ) {
@@ -228,69 +223,16 @@ export class Chromium extends ProviderClass implements ProviderInterface {
228
223
}
229
224
}
230
225
}
231
-
232
- if ( this . osType === 'Linux' ) {
233
- unzipFile ( fileName , this . outDir ) ;
234
- changeFilePermissions (
235
- path . resolve ( this . outDir , 'chrome-linux/chrome' ) , '0755' , this . osType ) ;
236
- } else if ( this . osType === 'Darwin' ) {
237
- spawnProcess ( 'unzip' , [ fileName , '-d' , this . outDir ] , 'ignore' ) ;
238
- } else if ( this . osType === 'Windows_NT' ) {
239
- unzipFile ( fileName , this . outDir ) ;
240
- }
226
+ unzipFile ( fileName , this . outDir ) ;
241
227
}
242
228
243
- async updateBinary ( _ : string , majorVersion ?: string ) : Promise < void > {
244
- try {
245
- this . cleanFiles ( ) ;
246
- } catch ( _ ) {
247
- // no-op: best attempt to clean files, there can be only one version.
248
- }
229
+ async updateBinary ( majorVersion ?: string ) : Promise < void > {
249
230
const allJson = await this . downloadAllJson ( ) ;
250
231
const downloadVersionJson = await this . downloadVersionJson (
251
232
allJson , majorVersion ) ;
252
233
const storageObject = await this . downloadStorageObject (
253
234
downloadVersionJson , majorVersion ) ;
254
235
await this . downloadUrl ( storageObject , majorVersion ) ;
255
-
256
- let binaryFolder = ( ) : string => {
257
- if ( this . osType === 'Linux' ) {
258
- return path . resolve ( this . outDir , 'chrome-linux' ) ;
259
- } else if ( this . osType === 'Darwin' ) {
260
- return path . resolve ( this . outDir ,
261
- 'chrome-mac/Chromium.app/Contents/MacOS' ) ;
262
- } else if ( this . osType === 'Windows_NT' ) {
263
- return 'fix me' ;
264
- }
265
- throw new Error ( 'os does not exist' ) ;
266
- }
267
-
268
- let binaryRegex = ( ) : RegExp => {
269
- if ( this . osType === 'Linux' ) {
270
- return / c h r o m e $ / g;
271
- } else if ( this . osType === 'Darwin' ) {
272
- return / C h r o m i u m / g;
273
- } else if ( this . osType === 'Windows_NT' ) {
274
- return / f i x - m e / g;
275
- }
276
- throw new Error ( 'os does not exist' ) ;
277
- } ;
278
-
279
- let binaryFile = ( ) : string => {
280
- if ( this . osType === 'Linux' ) {
281
- return path . resolve ( this . outDir , 'chrome-linux/chrome' ) ;
282
- } else if ( this . osType === 'Darwin' ) {
283
- return path . resolve ( this . outDir ,
284
- 'chrome-mac/Chromium.app/Contents/MacOS/Chromium' ) ;
285
- } else if ( this . osType === 'Windows_NT' ) {
286
- return 'fix me' ;
287
- }
288
- throw new Error ( 'os does not exist' ) ;
289
- }
290
-
291
- generateConfigFile ( binaryFolder ( ) ,
292
- path . resolve ( this . outDir , this . configFileName ) ,
293
- binaryRegex ( ) , binaryFile ( ) ) ;
294
236
}
295
237
296
238
getBinaryPath ( version ?: string ) : string | null {
@@ -303,47 +245,11 @@ export class Chromium extends ProviderClass implements ProviderInterface {
303
245
}
304
246
305
247
getStatus ( ) : string | null {
306
- try {
307
- const existFiles = fs . readdirSync ( this . outDir ) ;
308
- for ( const existFile of existFiles ) {
309
- if ( existFile . match ( / c h r o m i u m \- v e r s i o n \. * / g) ) {
310
- const regex = / c h r o m i u m \- v e r s i o n \- ( \d + ) \. j s o n / g;
311
- const exec = regex . exec ( existFile ) ;
312
- if ( exec ) {
313
- return exec [ 1 ] ;
314
- }
315
- }
316
- }
317
- return null ;
318
- } catch ( _ ) {
319
- return null ;
320
- }
248
+ return '' ;
321
249
}
322
250
323
251
cleanFiles ( ) : string {
324
- let chromiumPath = '' ;
325
- if ( this . osType === 'Darwin' ) {
326
- chromiumPath = 'chrome-mac/' ;
327
- } else if ( this . osType === 'Linux' ) {
328
- chromiumPath = 'chrome-linux/' ;
329
- } else if ( this . osType === 'Windows_NT' ) {
330
- chromiumPath = 'chrome-win/' ;
331
- }
332
-
333
- rimraf . sync ( path . resolve ( this . outDir , chromiumPath ) ) ;
334
- const files = removeFiles ( this . outDir , [ / c h r o m i u m .* / g] ) ;
335
- try {
336
- const fileList = files . split ( '\n' ) ;
337
- if ( files . length === 0 ) {
338
- // No files listed to clean.
339
- return '' ;
340
- }
341
- fileList . push ( chromiumPath ) ;
342
- return ( fileList . sort ( ) ) . join ( '\n' ) ;
343
- } catch ( _ ) {
344
- // If files returns null, catch split error.
345
- return '' ;
346
- }
252
+ return removeFiles ( this . outDir , [ / c h r o m i u m .* / g] ) ;
347
253
}
348
254
}
349
255
@@ -369,21 +275,4 @@ export function osHelper(ostype: string, osarch: string): string {
369
275
}
370
276
}
371
277
return null ;
372
- }
373
-
374
- /**
375
- * A command line to run. Example 'npm start', the task='npm' and the
376
- * opt_arg=['start']
377
- * @param task The task string.
378
- * @param optArg Optional task args.
379
- * @param optIo Optional io arg. By default, it should log to console.
380
- * @returns The child process.
381
- */
382
- export function spawnProcess ( task : string , optArg ?: string [ ] , optIo ?: string ) {
383
- optArg = typeof optArg !== 'undefined' ? optArg : [ ] ;
384
- let stdio : childProcess . StdioOptions = 'inherit' ;
385
- if ( optIo === 'ignore' ) {
386
- stdio = 'ignore' ;
387
- }
388
- return childProcess . spawnSync ( task , optArg , { stdio} ) ;
389
278
}
0 commit comments