@@ -41,11 +41,11 @@ function validateSchema(json) {
41
41
}
42
42
43
43
function readFileAsString ( path ) {
44
- var data = fs . readFileSync ( path ) ;
44
+ const data = fs . readFileSync ( path ) ;
45
45
return data . toString ( ) ;
46
46
}
47
47
48
- var program = require ( 'commander' ) ;
48
+ const program = require ( 'commander' ) ;
49
49
50
50
program
51
51
. version ( pkginfo . version )
@@ -74,7 +74,7 @@ program
74
74
if ( ! arg ) {
75
75
program . outputHelp ( ) ;
76
76
} else {
77
- var command = program . commands . find ( c => c . _name == arg ) ;
77
+ const command = program . commands . find ( c => c . _name == arg ) ;
78
78
if ( ! command ) {
79
79
console . log ( `Could not find a command for ${ arg } ` ) ;
80
80
} else {
@@ -86,7 +86,7 @@ program
86
86
program
87
87
. command ( 'install' )
88
88
. description ( 'Downloads and installs the Sandbox Client software.' )
89
- . action ( async function ( dir , cmd ) {
89
+ . action ( async function ( ) {
90
90
try {
91
91
if ( sandboxClientManager . isAlreadyInstalled ( ) ) {
92
92
console . log ( "Sandbox Client is already installed." ) ;
@@ -100,7 +100,7 @@ program
100
100
101
101
function showLocalSandboxes ( ) {
102
102
console . log ( "Local sandboxes:\n" ) ;
103
- var sandboxes = sandboxClientManager . getAllSandboxes ( ) . map ( sb => {
103
+ const sandboxes = sandboxClientManager . getAllSandboxes ( ) . map ( sb => {
104
104
return {
105
105
current : sb . current ? "YES" : "" ,
106
106
name : sb . name ,
@@ -120,11 +120,11 @@ function showSandboxesTable(sandboxes) {
120
120
121
121
async function showRemoteSandboxes ( ) {
122
122
console . log ( "Loading sandboxes: \n" ) ;
123
- var localIds = new Set ( ) ;
123
+ const localIds = new Set ( ) ;
124
124
sandboxClientManager . getAllSandboxes ( ) . forEach ( sb => localIds . add ( sb . sandboxId ) ) ;
125
125
const allSandboxesResult = await cliUtils . spinner ( sandboxSvc . getAllSandboxes ( ) ) ;
126
126
const quota = allSandboxesResult . quota ;
127
- var sandboxes = allSandboxesResult . result . sandboxes . map ( sb => {
127
+ const sandboxes = allSandboxesResult . result . sandboxes . map ( sb => {
128
128
return {
129
129
has_local : localIds . has ( sb . sandboxId ) ? "Y" : "N" ,
130
130
name : sb . name ,
@@ -154,12 +154,12 @@ program
154
154
} ) ;
155
155
156
156
async function getRulesForSandboxId ( sandboxId : string ) {
157
- var sandbox : any = await cliUtils . spinner ( sandboxSvc . getSandbox ( sandboxId ) ) ;
158
- var pIds = sandbox . properties . map ( p => p . sandboxPropertyId ) ;
159
- var r = [ ] ;
157
+ const sandbox : any = await cliUtils . spinner ( sandboxSvc . getSandbox ( sandboxId ) ) ;
158
+ const pIds = sandbox . properties . map ( p => p . sandboxPropertyId ) ;
159
+ const r = [ ] ;
160
160
161
- for ( var pid of pIds ) {
162
- var obj : any = await cliUtils . spinner ( sandboxSvc . getRules ( sandboxId , pid ) ) ;
161
+ for ( let pid of pIds ) {
162
+ const obj : any = await cliUtils . spinner ( sandboxSvc . getRules ( sandboxId , pid ) ) ;
163
163
r . push ( {
164
164
title : `sandbox_property_id: ${ pid } ` ,
165
165
rules : obj . rules
@@ -189,20 +189,20 @@ function populateOrigins(papiNode, originsList) {
189
189
}
190
190
191
191
function getOriginsForPapiRules ( papiRules ) {
192
- var o = [ ] ;
192
+ const o = [ ] ;
193
193
populateOrigins ( papiRules , o ) ;
194
194
return o ;
195
195
}
196
196
197
197
async function showSandboxOverview ( sandboxId : string ) {
198
- var localSandbox = sandboxClientManager . getSandboxLocalData ( sandboxId ) ;
198
+ const localSandbox = sandboxClientManager . getSandboxLocalData ( sandboxId ) ;
199
199
if ( localSandbox ) {
200
200
cliUtils . logWithBorder ( "Local sandbox information:" ) ;
201
201
console . log ( "sandbox_id: " + sandboxId ) ;
202
202
console . log ( "local directory: " + localSandbox . sandboxFolder ) ;
203
203
console . log ( `current: ${ localSandbox . isCurrent } \n` ) ;
204
204
}
205
- var sandbox = await cliUtils . spinner ( sandboxSvc . getSandbox ( sandboxId ) ) ;
205
+ const sandbox = await cliUtils . spinner ( sandboxSvc . getSandbox ( sandboxId ) ) ;
206
206
207
207
cliUtils . logWithBorder ( "Detailed information for the sandbox:" ) ;
208
208
@@ -222,9 +222,9 @@ async function showSandboxOverview(sandboxId: string) {
222
222
program
223
223
. command ( 'show [sandbox-identifier]' )
224
224
. description ( 'Provides details about a sandbox.' )
225
- . action ( async function ( arg , cmd ) {
225
+ . action ( async function ( arg ) {
226
226
try {
227
- var sandboxIdToUse = null ;
227
+ let sandboxIdToUse = null ;
228
228
if ( ! arg ) {
229
229
if ( sandboxClientManager . hasCurrent ( ) ) {
230
230
sandboxIdToUse = sandboxClientManager . getCurrentSandboxId ( ) ;
@@ -243,9 +243,9 @@ program
243
243
program
244
244
. command ( 'rules [sandbox-identifier]' )
245
245
. description ( 'Shows rule tree for sandbox.' )
246
- . action ( async function ( arg , cmd ) {
246
+ . action ( async function ( arg ) {
247
247
try {
248
- var sandboxIdToUse = null ;
248
+ let sandboxIdToUse = null ;
249
249
if ( ! arg ) {
250
250
if ( sandboxClientManager . hasCurrent ( ) ) {
251
251
sandboxIdToUse = sandboxClientManager . getCurrentSandboxId ( ) ;
@@ -255,7 +255,7 @@ program
255
255
} else {
256
256
sandboxIdToUse = getSandboxIdFromIdentifier ( arg ) ;
257
257
}
258
- var rulesList = await getRulesForSandboxId ( sandboxIdToUse ) ;
258
+ const rulesList = await getRulesForSandboxId ( sandboxIdToUse ) ;
259
259
rulesList . forEach ( o => {
260
260
cliUtils . logWithBorder ( o . title , 'err' ) ;
261
261
console . log ( cliUtils . toJsonPretty ( o . rules ) ) ;
@@ -266,7 +266,7 @@ program
266
266
} ) ;
267
267
268
268
function getLocalSandboxForIdentifier ( identifier : string , failOnNoResult = true ) {
269
- var results = sandboxClientManager . searchLocalSandboxes ( identifier ) ;
269
+ const results = sandboxClientManager . searchLocalSandboxes ( identifier ) ;
270
270
if ( results . length == 0 ) {
271
271
if ( failOnNoResult ) {
272
272
cliUtils . logAndExit ( 1 , `ERROR: Could not find any local sandboxes matching input: ${ identifier } ` )
@@ -291,7 +291,7 @@ function orCurrent(sandboxIdentifier) {
291
291
}
292
292
293
293
function getSandboxIdFromIdentifier ( sandboxIdentifier : string ) {
294
- var sb = getLocalSandboxForIdentifier ( sandboxIdentifier , false ) ;
294
+ const sb = getLocalSandboxForIdentifier ( sandboxIdentifier , false ) ;
295
295
if ( sb ) {
296
296
return sb . sandboxId ;
297
297
} else {
@@ -302,22 +302,22 @@ function getSandboxIdFromIdentifier(sandboxIdentifier: string) {
302
302
program
303
303
. command ( 'use <sandbox-identifier>' )
304
304
. description ( 'Sets the identified sandbox as currently active.' )
305
- . action ( function ( arg , options ) {
306
- var sb = getLocalSandboxForIdentifier ( arg ) ;
305
+ . action ( function ( arg ) {
306
+ const sb = getLocalSandboxForIdentifier ( arg ) ;
307
307
sandboxClientManager . makeCurrent ( sb . sandboxId ) ;
308
308
console . log ( `Sandbox: ${ sb . name } is now active` )
309
309
} ) ;
310
310
311
311
program
312
312
. command ( 'delete <sandbox-id>' )
313
313
. description ( 'Deletes the sandbox.' )
314
- . action ( async function ( sandboxId , options ) {
314
+ . action ( async function ( sandboxId ) {
315
315
try {
316
316
if ( ! await cliUtils . confirm ( 'Are you sure you want to delete this sandbox?' ) ) {
317
317
return ;
318
318
}
319
319
320
- var progressMsg = `Deleting sandboxId: ${ sandboxId } ` ;
320
+ const progressMsg = `Deleting sandboxId: ${ sandboxId } ` ;
321
321
await cliUtils . spinner ( sandboxSvc . deleteSandbox ( sandboxId ) , progressMsg ) ;
322
322
323
323
sandboxClientManager . flushLocalSandbox ( sandboxId ) ;
@@ -331,7 +331,7 @@ function parseToBoolean(str: string) {
331
331
return false ;
332
332
}
333
333
const parsedInput = str . trim ( ) . toLowerCase ( ) ;
334
- var strToBool = new Map ( [
334
+ const strToBool = new Map ( [
335
335
[ 'true' , true ] ,
336
336
[ 't' , true ] ,
337
337
[ 'y' , true ] ,
@@ -354,8 +354,8 @@ program
354
354
. option ( '-r, --rules <file>' , 'JSON file containing a PAPI rule tree.' )
355
355
. option ( '-H, --requesthostnames <string>' , 'Comma-delimited list of request hostnames within the sandbox.' )
356
356
. action ( async function ( sandboxId , sandboxPropertyId , options ) {
357
- var rules = options . rules ;
358
- var requestHostnames = options . requesthostnames ;
357
+ const rules = options . rules ;
358
+ const requestHostnames = options . requesthostnames ;
359
359
try {
360
360
await updateHostnamesAndRules ( requestHostnames , rules , sandboxId , sandboxPropertyId ) ;
361
361
console . log ( `Successfully updated sandbox_id: ${ sandboxId } sandbox_property_id: ${ sandboxPropertyId } ` ) ;
@@ -463,15 +463,15 @@ async function createFromRules(papiFilePath: string, propForRules: string, hostn
463
463
cliUtils . logAndExit ( 1 , `ERROR: File: ${ papiFilePath } does not exist.` ) ;
464
464
}
465
465
const papiJson = getJsonFromFile ( papiFilePath ) ;
466
- const propertySpecObjMsg = `${ JSON . stringify ( propForRules ) } ` ;
466
+ `${ JSON . stringify ( propForRules ) } ` ;
467
467
return await cliUtils . spinner ( sandboxSvc . createFromRules ( papiJson , propForRules , hostnames , name , isClonable , cpcode ) , "creating new sandbox" ) ;
468
468
}
469
469
470
470
function parsePropertySpecifier ( propertySpecifier ) {
471
- var propertySpec ;
472
- var propertyVersion ;
471
+ let propertySpec ;
472
+ let propertyVersion ;
473
473
if ( propertySpecifier . indexOf ( ':' ) > - 1 ) {
474
- var parts = propertySpecifier . split ( ':' ) . map ( s => s . trim ( ) . toLowerCase ( ) ) ;
474
+ const parts = propertySpecifier . split ( ':' ) . map ( s => s . trim ( ) . toLowerCase ( ) ) ;
475
475
propertySpec = parts [ 0 ] ;
476
476
propertyVersion = parts [ 1 ] ;
477
477
} else {
@@ -483,7 +483,7 @@ function parsePropertySpecifier(propertySpecifier) {
483
483
}
484
484
485
485
const propertySpecObj : any = { } ;
486
- var key ;
486
+ let key ;
487
487
if ( validator . isInt ( propertySpec ) ) {
488
488
key = 'propertyId' ;
489
489
} else {
@@ -524,7 +524,7 @@ async function createFromHostname(hostname: string, hostnames: Array<string>, is
524
524
}
525
525
526
526
async function getOriginListForSandboxId(sandboxId: string): Promise<Array<string>> {
527
- var rulesList = await getRulesForSandboxId(sandboxId);
527
+ const rulesList = await getRulesForSandboxId(sandboxId);
528
528
const origins = new Set();
529
529
rulesList.forEach(entry => {
530
530
const originsForRules = getOriginsForPapiRules(entry.rules);
@@ -560,7 +560,7 @@ async function createFromPropertiesRecipe(recipe, cpcode) {
560
560
console.log(` Creating sandbox and property 1 from recipe . `);
561
561
const r = await cliUtils.spinner(createRecipeSandboxAndProperty(firstProp, propForRules, sandboxRecipe, cpcode));
562
562
563
- for (var i = 1; i < properties.length; i++) {
563
+ for (let i = 1; i < properties.length; i++) {
564
564
try {
565
565
console.log(` Creating property $ { i + 1 } from recipe . `);
566
566
await cliUtils.spinner(createRecipeProperty(properties[i], r.sandboxId));
@@ -593,14 +593,14 @@ function validateAndBuildRecipe(recipeFilePath, name, clonable): any {
593
593
cliUtils.logAndExit(1, ` ERROR : File ${recipeFilePath } does not exist . `);
594
594
}
595
595
const recipe = getJsonFromFile(recipeFilePath);
596
- var r = validateSchema(recipe);
596
+ const r = validateSchema(recipe);
597
597
if (r.errors.length > 0) {
598
598
cliUtils.logAndExit(1, ` ERROR : There are issues with your recipe file \n ${r } `);
599
599
}
600
600
const sandboxRecipe = recipe.sandbox;
601
601
sandboxRecipe.clonable = clonable || sandboxRecipe.clonable;
602
602
sandboxRecipe.name = name || sandboxRecipe.name;
603
- var idx = 0;
603
+ let idx = 0;
604
604
605
605
if (sandboxRecipe.properties) {
606
606
sandboxRecipe.properties.forEach(p => {
@@ -647,9 +647,9 @@ async function updateFromRecipe(sandboxId, recipeFilePath, name, clonable) {
647
647
console . log ( `Updating sandbox information for sandbox_id: ${ sandboxId } ` ) ;
648
648
await sandboxSvc . updateSandbox ( sandbox ) ;
649
649
650
- var pIds = sandbox . properties . map ( p => p . sandboxPropertyId ) ;
650
+ const pIds = sandbox . properties . map ( p => p . sandboxPropertyId ) ;
651
651
const first = pIds [ 0 ] ;
652
- for ( var i = 1 ; i < pIds . length ; i ++ ) {
652
+ for ( let i = 1 ; i < pIds . length ; i ++ ) {
653
653
const propertyId = pIds [ i ] ;
654
654
console . log ( `Deleting sandbox_property_id: ${ propertyId } ` ) ;
655
655
await cliUtils . spinner ( sandboxSvc . deleteProperty ( sandboxId , propertyId ) ) ;
@@ -663,7 +663,7 @@ async function updateFromRecipe(sandboxId, recipeFilePath, name, clonable) {
663
663
console . log ( `Updating sandbox_property_id : ${first } `) ;
664
664
await cliUtils . spinner ( sandboxSvc . updateProperty ( sandboxId , propertyObj ) ) ;
665
665
666
- for ( var i = 0 ; i < sandboxRecipe . properties . length ; i ++ ) {
666
+ for ( let i = 0 ; i < sandboxRecipe . properties . length ; i ++ ) {
667
667
const rp = sandboxRecipe . properties [ i ] ;
668
668
console . log ( `Re-building property: ${ i + 1 } ` ) ;
669
669
await cliUtils . spinner ( createRecipeProperty ( rp , sandboxId ) ) ;
@@ -679,7 +679,7 @@ async function createFromRecipe(recipeFilePath, name, clonable, cpcode) {
679
679
680
680
const sandboxRecipe = recipe . sandbox ;
681
681
682
- var res = null ;
682
+ let res = null ;
683
683
if ( sandboxRecipe . properties ) {
684
684
res = await createFromPropertiesRecipe ( recipe , cpcode ) ;
685
685
} else if ( sandboxRecipe . cloneFrom ) {
@@ -719,8 +719,8 @@ function createRecipeSandboxAndProperty(rp, propertyForRules, recipe, cpcode) {
719
719
}
720
720
721
721
function oneOf ( ...args : any [ ] ) {
722
- var r = false ;
723
- for ( var i = 0 ; i < args . length ; i ++ ) {
722
+ let r = false ;
723
+ for ( let i = 0 ; i < args . length ; i ++ ) {
724
724
if ( args [ i ] ) {
725
725
if ( r ) {
726
726
return false ;
@@ -793,7 +793,7 @@ program
793
793
794
794
const hostnames = hostnamesCsv ? parseHostnameCsv ( hostnamesCsv ) : undefined ;
795
795
796
- var r = null ;
796
+ let r = null ;
797
797
if ( papiFilePath ) {
798
798
r = await createFromRules ( papiFilePath , propForRules , hostnames , isClonable , name , cpcode ) ;
799
799
} else if ( propertySpecifier ) {
@@ -811,8 +811,8 @@ program
811
811
812
812
async function registerSandbox ( sandboxId : string , jwt : string , name : string , clientConfig = null ) {
813
813
console . log ( 'building origin list' ) ;
814
- var origins : Array < string > = await getOriginListForSandboxId(sandboxId);
815
- var passThrough = false;
814
+ const origins : Array < string > = await getOriginListForSandboxId(sandboxId);
815
+ let passThrough = false;
816
816
let hasVariableForOrigin = false;
817
817
if (origins.length > 0 ) {
818
818
console . log ( `Detected the following origins: ${ origins . join ( ', ' ) } ` ) ;
@@ -824,7 +824,7 @@ async function registerSandbox(sandboxId: string, jwt: string, name: string, cli
824
824
}
825
825
826
826
console . log ( 'registering sandbox in local datastore' ) ;
827
- var registration = sandboxClientManager . registerNewSandbox ( sandboxId , jwt , name , origins , clientConfig , passThrough ) ;
827
+ const registration = sandboxClientManager . registerNewSandbox ( sandboxId , jwt , name , origins , clientConfig , passThrough ) ;
828
828
829
829
console . info ( `Successfully created sandbox_id ${ sandboxId } Generated sandbox client configuration at ${ registration . configPath } Edit this file to specify the port and host for your dev environment.` ) ;
830
830
if ( hasVariableForOrigin ) {
@@ -847,13 +847,14 @@ async function downloadClientIfNecessary() {
847
847
program
848
848
. command ( 'start' )
849
849
. description ( 'Starts the sandbox client.' )
850
- . action ( async function ( dir , cmd ) {
850
+ . option ( '--print-logs' , 'Print logs to standard output.' )
851
+ . action ( async function ( options ) {
851
852
try {
852
853
if ( sandboxClientManager . getAllSandboxes ( ) . length == 0 ) {
853
854
console . log ( 'there are no sandboxes configured' ) ;
854
855
} else {
855
856
await downloadClientIfNecessary ( ) ;
856
- await sandboxClientManager . executeSandboxClient ( ) ;
857
+ await sandboxClientManager . executeSandboxClient ( ! ! options . printLogs ) ;
857
858
}
858
859
} catch ( e ) {
859
860
cliUtils . logAndExit ( 1 , 'ERROR: got exception during client execution: ' + e ) ;
@@ -888,7 +889,7 @@ program
888
889
const hostnameSpecifier = options . hostname ;
889
890
const hostnamesCsv = options . requesthostnames ;
890
891
891
- let sandboxId = null ;
892
+ let sandboxId ;
892
893
if ( ! arg ) {
893
894
sandboxId = sandboxClientManager . getCurrentSandboxId ( ) ;
894
895
if ( ! sandboxId ) {
@@ -1075,7 +1076,7 @@ program
1075
1076
} ) ;
1076
1077
1077
1078
function helpExitOnNoArgs ( cmd ) {
1078
- var len = process . argv . slice ( 2 ) . length ;
1079
+ const len = process . argv . slice ( 2 ) . length ;
1079
1080
if ( ! len || len <= 1 ) {
1080
1081
cmd . outputHelp ( ) ;
1081
1082
process . exit ( ) ;
0 commit comments