1
1
///<reference path="../.d.ts"/>
2
2
"use strict" ;
3
3
4
- import * as dependencyExtensionsServiceLib from "./dependency- extensions-service-base" ;
4
+ import { ExtensionsServiceBase } from "./extensions-service-base" ;
5
5
import * as path from "path" ;
6
6
import Future = require( "fibers/future" ) ;
7
7
8
- export class AppScaffoldingExtensionsService extends dependencyExtensionsServiceLib . DependencyExtensionsServiceBase implements IAppScaffoldingExtensionsService {
8
+ export class AppScaffoldingExtensionsService extends ExtensionsServiceBase implements IAppScaffoldingExtensionsService {
9
9
private static APP_SCAFFOLDING_NAME = "app-scaffolding" ;
10
+ private static SCREEN_BUILDER_BUCKET_NAME = "http://s3.amazonaws.com/screenbuilder-cli" ;
11
+ private static DEFAULT_CACHED_VERSION = "0.0.0" ;
10
12
11
- constructor ( $fs : IFileSystem ,
12
- $httpClient : Server . IHttpClient ,
13
- $logger : ILogger ,
14
- $progressIndicator : IProgressIndicator ,
15
- $config : IConfiguration ,
16
- protected $childProcess : IChildProcess ,
17
- protected $dependencyConfigService : IDependencyConfigService ,
18
- $options : IOptions ) {
19
- super ( $options . screenBuilderCacheDir , $fs , $httpClient , $logger , $options , $progressIndicator , $config ) ; // We should pass here the correct profileDir
13
+ constructor ( private $childProcess : IChildProcess ,
14
+ private $config : IConfiguration ,
15
+ private $dependencyConfigService : IDependencyConfigService ,
16
+ private $progressIndicator : IProgressIndicator ,
17
+ protected $fs : IFileSystem ,
18
+ protected $httpClient : Server . IHttpClient ,
19
+ protected $logger : ILogger ,
20
+ protected $options : IOptions ) {
21
+ super ( $options . screenBuilderCacheDir , $fs , $httpClient , $logger , $options ) ;
20
22
}
21
23
22
24
public get appScaffoldingPath ( ) : string {
@@ -29,7 +31,11 @@ export class AppScaffoldingExtensionsService extends dependencyExtensionsService
29
31
appScaffoldingConfig . pathToSave = this . $options . screenBuilderCacheDir ;
30
32
let afterPrepareAction = ( ) => {
31
33
return ( ( ) => {
32
- this . npmInstall ( "[email protected] " ) . wait ( ) ; // HACK: With this we are able to make paths shorter with 20 symbols.
34
+ // HACK: Some of screen builder's dependencies generate paths which are too long for Windows OS to handle
35
+ // this is why we pre-install them so that they're at the highest point in the dependency depth.
36
+ // This leads to shortening the paths just enough to be safe about it.
37
+ // Note that if one of these modules' versions is changed this needs to be reflected in the code too!
38
+ [ "[email protected] " , "[email protected] " ] . forEach ( dependency => { this . npmInstall ( dependency ) . wait ( ) ; } ) ;
33
39
34
40
let generatorBaseDependencies = require ( path . join ( this . appScaffoldingPath , "node_modules" , "screen-builder-base-generator" , "package.json" ) ) . dependencies ;
35
41
Future . wait ( _ . map ( generatorBaseDependencies , ( value , key ) => this . npmInstall ( `${ key } @${ value } ` ) ) ) ;
@@ -41,6 +47,30 @@ export class AppScaffoldingExtensionsService extends dependencyExtensionsService
41
47
} ) . future < void > ( ) ( ) ;
42
48
}
43
49
50
+ public prepareDependencyExtension ( dependencyExtensionName : string , dependencyConfig : IDependencyConfig , afterPrepareAction ?: ( ) => IFuture < void > ) : IFuture < void > {
51
+ return ( ( ) => {
52
+ let extensionVersion = this . getExtensionVersion ( dependencyExtensionName ) ;
53
+ let cachedVersion = extensionVersion || AppScaffoldingExtensionsService . DEFAULT_CACHED_VERSION ;
54
+ let downloadUrl = this . $config . ON_PREM ? `${ this . $config . AB_SERVER } /downloads/sb/generators/${ dependencyExtensionName } /${ dependencyConfig . version } ` : `${ AppScaffoldingExtensionsService . SCREEN_BUILDER_BUCKET_NAME } /v${ dependencyConfig . version } /${ dependencyExtensionName } .zip` ;
55
+
56
+ this . $logger . trace ( "prepareDependencyExtension: Download url: %s, cached version: %s" , downloadUrl , cachedVersion ) ;
57
+
58
+ if ( this . shouldUpdatePackage ( cachedVersion , dependencyConfig . version ) ) {
59
+ this . $logger . out ( "Please, wait while Screen Builder and its dependencies are being configured." ) ;
60
+ this . $logger . out ( "Preparing %s" , dependencyExtensionName ) ;
61
+
62
+ let dependencyExtensionData = {
63
+ packageName : dependencyExtensionName ,
64
+ version : dependencyConfig . version ,
65
+ downloadUri : downloadUrl ,
66
+ pathToSave : dependencyConfig . pathToSave
67
+ } ;
68
+
69
+ this . $progressIndicator . showProgressIndicator ( this . prepareExtensionBase ( dependencyExtensionData , cachedVersion , { afterDownloadAction : ( ) => this . $progressIndicator . showProgressIndicator ( afterPrepareAction ( ) , 100 ) } ) , 5000 ) . wait ( ) ;
70
+ }
71
+ } ) . future < void > ( ) ( ) ;
72
+ }
73
+
44
74
protected npmInstall ( packageToInstall ?: string ) : IFuture < void > {
45
75
packageToInstall = packageToInstall || "" ;
46
76
let command = `npm install ${ packageToInstall } --production` ;
0 commit comments