Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/cli/src/cli-hosting.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ const setup = async () => {
.description('Configure hosting parameters')
.option('-c, --cname <domain_name>', 'add CNAME to hosting')
.option('-d, --remove-cname <domain_name>', 'remove CNAME from hosting')
.option('-b, --browser_router', 'turn on BrowserRouter support')
.option('-b, --browser-router <true|false>', 'turn on/off the BrowserRouter support')
.action(async (...options) => {
session.isAuthenticated()
session.hasProject()
Expand Down
16 changes: 14 additions & 2 deletions packages/cli/src/commands/hosting-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,21 @@ import format from 'chalk'
import inquirer from 'inquirer'
import { p, echo, error, warning } from '../utils/print-tools'
import Hosting from '../utils/hosting'
import HostingListCmd from './hosting-list'

class HostingConfig {
constructor (context) {
this.context = context
this.hosting = null
}

static toggleBrowserRouter (command, responses) {
if (responses.browser_router) {
return responses.browser_router
}
return command === 'true'
}

async run ([hostingName, cmd]) {
this.cname = cmd.cname
this.fullPath = null
Expand All @@ -28,19 +36,23 @@ class HostingConfig {
}

let responses = {}
if (!(cmd.removeCname || cmd.cname || cmd.browser_router)) {
if (!(cmd.removeCname || cmd.cname || cmd.browserRouter)) {
responses = await inquirer.prompt(this.getQuestions()) || {}
}

const paramsToUpdate = {
cname: this.cname || responses.CNAME,
removeCNAME: cmd.removeCname,
browser_router: cmd.browser_router || responses.browser_router
browser_router: HostingConfig.toggleBrowserRouter(cmd.browserRouter, responses)
}

await this.hosting.configure(paramsToUpdate)

echo()
echo(4)(format.green('Configuration successfully updated!'))
echo()
HostingListCmd.printHosting(this.hosting)
echo()
} catch (err) {
try {
error(4)(err.response.data.detail)
Expand Down
22 changes: 21 additions & 1 deletion packages/cli/tests/e2e/hosting.test-e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,33 @@ describe('[E2E] CLI Hosting', function () {
.end(done)
})

it('can sync again local hosting', function (done) {
it('can sync local hosting again', function (done) {
testNixt()
.run(`${cliLocation} hosting sync ${hostingName}`)
.stdout(/files synchronized/)
.end(done)
})

it('can set hosting config with prompt', function (done) {
testNixt()
.run(`${cliLocation} hosting config ${hostingName}`)
.on(/Set CNAME now/)
.respond('my.dom.ain\n')
.on(/Do you want to use BrowserRouter for this hosting?/)
.respond('Y\n')
.stdout(/CNAME: http:\/\/my.dom.ain/)
.stdout(/BrowserRouter: ✓/)
.end(done)
})

it('can set hosting config with flags', function (done) {
testNixt()
.run(`${cliLocation} hosting config ${hostingName} --browser-router false --remove-cname my.dom.ain`)
.stdout(/^((?!CNAME: http:\/\/my.dom.ain)[\s\S])*$/)
.stdout(/BrowserRouter: x/)
.end(done)
})

it('can delete hosting container 1', function (done) {
testNixt()
.run(`${cliLocation} hosting delete ${hostingName}`)
Expand Down
1 change: 0 additions & 1 deletion packages/cli/tests/unit/utils-session.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,6 @@ describe('[utils] Session', function () {

describe('without parameter', function () {
it('should print proper error message and exit process when instance does not exists', async function () {

await session.checkConnection()

sinon.assert.calledWith(interEcho, `Instance ${format.cyan(instanceName)} was not found on your account!`)
Expand Down