Skip to content

Commit e206671

Browse files
skip env var and use config lib (#200)
1 parent 6a6a314 commit e206671

File tree

5 files changed

+31
-9
lines changed

5 files changed

+31
-9
lines changed

src/BaseCommand.js

+17
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,25 @@ governing permissions and limitations under the License.
1212

1313
const { Command, flags } = require('@oclif/command')
1414
const fs = require('fs-extra')
15+
const chalk = require('chalk')
16+
const coreConfig = require('@adobe/aio-lib-core-config')
1517

1618
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+
1734
get pjson () {
1835
if (!this._pjson) {
1936
this._pjson = fs.readJSONSync('package.json')

src/commands/app/deploy.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,9 @@ class Deploy extends BaseCommand {
120120
}
121121
if (deployedFrontendUrl) {
122122
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
125126
this.log(chalk.blue(chalk.bold(`To view your deployed application in the Experience Cloud shell:\n -> ${launchUrl}`)))
126127
}
127128
}

src/commands/app/run.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,11 @@ class Run extends BaseCommand {
101101
if (frontendUrl) {
102102
this.log()
103103
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}`)))
107109
}
108110
}
109111
} catch (error) {

test/commands/app/deploy.test.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ const mockFS = require('fs-extra')
1717

1818
const mockScripts = require('@adobe/aio-app-scripts')()
1919

20+
jest.mock('@adobe/aio-lib-core-config')
21+
const mockConfig = require('@adobe/aio-lib-core-config')
22+
2023
beforeEach(() => {
2124
mockScripts.mockReset('deployActions')
2225
mockScripts.mockReset('deployUI')
@@ -268,13 +271,12 @@ describe('run', () => {
268271
test('deploy should show ui and exc url if AIO_LAUNCH_PREFIX_URL is set', async () => {
269272
mockFS.existsSync.mockReturnValue(true)
270273
mockScripts.deployUI.mockResolvedValue('https://example.com')
271-
process.env.AIO_LAUNCH_URL_PREFIX = 'http://prefix?fake='
274+
mockConfig.get.mockReturnValue('http://prefix?fake=')
272275
command.argv = []
273276
await command.run()
274277
expect(command.error).toHaveBeenCalledTimes(0)
275278
expect(command.log).toHaveBeenCalledWith(expect.stringContaining('https://example.com'))
276279
expect(command.log).toHaveBeenCalledWith(expect.stringContaining('http://prefix?fake=https://example.com'))
277-
delete process.env.AIO_LAUNCH_PREFIX_URL
278280
})
279281

280282
test('deploy should show action urls', async () => {

test/commands/app/run.test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ beforeEach(() => {
8989

9090
getPort.mockReset()
9191

92-
delete process.env.AIO_LAUNCH_URL_PREFIX
9392
delete process.env.REMOTE_ACTIONS
9493
delete process.env.PORT
9594
})
@@ -221,6 +220,7 @@ describe('run', () => {
221220
})
222221

223222
test('run should show ui url', async () => {
223+
mockConfig.get.mockReturnValue(null)
224224
mockFSExists(['web-src/', 'manifest.yml', PRIVATE_KEY_PATH, PUB_CERT_PATH])
225225
mockScripts.mockResolvedValue('runDev', 'http://localhost:1111')
226226
command.argv = []
@@ -231,7 +231,7 @@ describe('run', () => {
231231

232232
test('run should show ui and exc url if AIO_LAUNCH_PREFIX_URL is set', async () => {
233233
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=')
235235
mockScripts.mockResolvedValue('runDev', 'http://localhost:1111')
236236
command.argv = []
237237
await command.run()

0 commit comments

Comments
 (0)