File tree 5 files changed +31
-9
lines changed
5 files changed +31
-9
lines changed Original file line number Diff line number Diff line change @@ -12,8 +12,25 @@ governing permissions and limitations under the License.
12
12
13
13
const { Command, flags } = require ( '@oclif/command' )
14
14
const fs = require ( 'fs-extra' )
15
+ const chalk = require ( 'chalk' )
16
+ const coreConfig = require ( '@adobe/aio-lib-core-config' )
15
17
16
18
class BaseCommand extends Command {
19
+ getLaunchUrlPrefix ( ) {
20
+ // todo: it might make sense to have a value that defines if this is an ExC hosted app, or otherwise
21
+ // so we can decide what type of url to return here.
22
+ // at some point we could also just delete the .env value and return our expected url here.
23
+
24
+ // note: this is the same value as process.env.AIO_LAUNCH_URL_PREFIX
25
+ let launchPrefix = coreConfig . get ( 'launch.url.prefix' )
26
+ if ( launchPrefix && launchPrefix . search ( '/myapps/' ) ) {
27
+ this . log ( chalk . redBright ( chalk . bold ( 'Warning: your environment variables contains an older version of AIO_LAUNCH_URL_PREFIX' ) ) )
28
+ launchPrefix = launchPrefix . replace ( '/myapps/' , '/apps/' )
29
+ this . log ( chalk . redBright ( chalk . bold ( `You should update your .env file: AIO_LAUNCH_URL_PREFIX='${ launchPrefix } '` ) ) )
30
+ }
31
+ return launchPrefix
32
+ }
33
+
17
34
get pjson ( ) {
18
35
if ( ! this . _pjson ) {
19
36
this . _pjson = fs . readJSONSync ( 'package.json' )
Original file line number Diff line number Diff line change @@ -120,8 +120,9 @@ class Deploy extends BaseCommand {
120
120
}
121
121
if ( deployedFrontendUrl ) {
122
122
this . log ( chalk . blue ( chalk . bold ( `To view your deployed application:\n -> ${ deployedFrontendUrl } ` ) ) )
123
- if ( process . env . AIO_LAUNCH_URL_PREFIX ) {
124
- const launchUrl = process . env . AIO_LAUNCH_URL_PREFIX + deployedFrontendUrl
123
+ const launchPrefix = this . getLaunchUrlPrefix ( )
124
+ if ( launchPrefix ) {
125
+ const launchUrl = launchPrefix + deployedFrontendUrl
125
126
this . log ( chalk . blue ( chalk . bold ( `To view your deployed application in the Experience Cloud shell:\n -> ${ launchUrl } ` ) ) )
126
127
}
127
128
}
Original file line number Diff line number Diff line change @@ -101,9 +101,11 @@ class Run extends BaseCommand {
101
101
if ( frontendUrl ) {
102
102
this . log ( )
103
103
this . log ( chalk . blue ( chalk . bold ( `To view your local application:\n -> ${ frontendUrl } ` ) ) )
104
- if ( process . env . AIO_LAUNCH_URL_PREFIX ) {
105
- const launchUrl = process . env . AIO_LAUNCH_URL_PREFIX + frontendUrl
106
- this . log ( chalk . blue ( chalk . bold ( `To view your local application in the Experience Cloud shell:\n -> ${ launchUrl } ` ) ) )
104
+
105
+ const launchPrefix = this . getLaunchUrlPrefix ( )
106
+ if ( launchPrefix ) {
107
+ const launchUrl = launchPrefix + frontendUrl
108
+ this . log ( chalk . blue ( chalk . bold ( `To view your deployed application in the Experience Cloud shell:\n -> ${ launchUrl } ` ) ) )
107
109
}
108
110
}
109
111
} catch ( error ) {
Original file line number Diff line number Diff line change @@ -17,6 +17,9 @@ const mockFS = require('fs-extra')
17
17
18
18
const mockScripts = require ( '@adobe/aio-app-scripts' ) ( )
19
19
20
+ jest . mock ( '@adobe/aio-lib-core-config' )
21
+ const mockConfig = require ( '@adobe/aio-lib-core-config' )
22
+
20
23
beforeEach ( ( ) => {
21
24
mockScripts . mockReset ( 'deployActions' )
22
25
mockScripts . mockReset ( 'deployUI' )
@@ -268,13 +271,12 @@ describe('run', () => {
268
271
test ( 'deploy should show ui and exc url if AIO_LAUNCH_PREFIX_URL is set' , async ( ) => {
269
272
mockFS . existsSync . mockReturnValue ( true )
270
273
mockScripts . deployUI . mockResolvedValue ( 'https://example.com' )
271
- process . env . AIO_LAUNCH_URL_PREFIX = 'http://prefix?fake='
274
+ mockConfig . get . mockReturnValue ( 'http://prefix?fake=' )
272
275
command . argv = [ ]
273
276
await command . run ( )
274
277
expect ( command . error ) . toHaveBeenCalledTimes ( 0 )
275
278
expect ( command . log ) . toHaveBeenCalledWith ( expect . stringContaining ( 'https://example.com' ) )
276
279
expect ( command . log ) . toHaveBeenCalledWith ( expect . stringContaining ( 'http://prefix?fake=https://example.com' ) )
277
- delete process . env . AIO_LAUNCH_PREFIX_URL
278
280
} )
279
281
280
282
test ( 'deploy should show action urls' , async ( ) => {
Original file line number Diff line number Diff line change @@ -89,7 +89,6 @@ beforeEach(() => {
89
89
90
90
getPort . mockReset ( )
91
91
92
- delete process . env . AIO_LAUNCH_URL_PREFIX
93
92
delete process . env . REMOTE_ACTIONS
94
93
delete process . env . PORT
95
94
} )
@@ -221,6 +220,7 @@ describe('run', () => {
221
220
} )
222
221
223
222
test ( 'run should show ui url' , async ( ) => {
223
+ mockConfig . get . mockReturnValue ( null )
224
224
mockFSExists ( [ 'web-src/' , 'manifest.yml' , PRIVATE_KEY_PATH , PUB_CERT_PATH ] )
225
225
mockScripts . mockResolvedValue ( 'runDev' , 'http://localhost:1111' )
226
226
command . argv = [ ]
@@ -231,7 +231,7 @@ describe('run', () => {
231
231
232
232
test ( 'run should show ui and exc url if AIO_LAUNCH_PREFIX_URL is set' , async ( ) => {
233
233
mockFSExists ( [ 'web-src/' , 'manifest.yml' , PRIVATE_KEY_PATH , PUB_CERT_PATH ] )
234
- process . env . AIO_LAUNCH_URL_PREFIX = 'http://prefix?fake='
234
+ mockConfig . get . mockReturnValue ( 'http://prefix?fake=' )
235
235
mockScripts . mockResolvedValue ( 'runDev' , 'http://localhost:1111' )
236
236
command . argv = [ ]
237
237
await command . run ( )
You can’t perform that action at this time.
0 commit comments