Skip to content
This repository has been archived by the owner on Jul 9, 2024. It is now read-only.

Commit

Permalink
feat(cli): add command to export local settings
Browse files Browse the repository at this point in the history
  • Loading branch information
coderbyheart committed Apr 15, 2021
1 parent 99a0280 commit 549b9be
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 1 deletion.
2 changes: 2 additions & 0 deletions arm/resources.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
export const resourceGroupName = (): string =>
process.env.RESOURCE_GROUP ?? 'nrfassettracker'

export const appName = (): string => process.env.APP_NAME ?? 'nrfassettracker'

/**
* Returns the name of the Device Provisioning Service
*/
Expand Down
8 changes: 8 additions & 0 deletions cli/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ import { createCAIntermediateCommand } from './commands/create-ca-intermediate'
import {
iotDeviceProvisioningServiceName,
resourceGroupName,
appName,
} from '../arm/resources'
import { reactConfigCommand } from './commands/react-config'
import { flashCommand } from './commands/flash'
import { ioTHubDPSInfo } from './iot/ioTHubDPSInfo'
import { creds } from './creds'
import { functionsSettingsCommand } from './commands/functions-settings'

const version = JSON.parse(
fs.readFileSync(path.join(process.cwd(), 'package.json'), 'utf-8'),
Expand Down Expand Up @@ -80,6 +82,12 @@ const main = async () => {
reactConfigCommand({
websiteClient: getWebsiteClient,
resourceGroup,
appName: appName(),
}),
functionsSettingsCommand({
websiteClient: getWebsiteClient,
resourceGroup,
appName: appName(),
}),
flashCommand({
certsDir,
Expand Down
36 changes: 36 additions & 0 deletions cli/commands/functions-settings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { CommandDefinition } from './CommandDefinition'
import { WebSiteManagementClient } from '@azure/arm-appservice'

export const functionsSettingsCommand = ({
websiteClient,
appName,
resourceGroup,
}: {
websiteClient: () => Promise<WebSiteManagementClient>
appName: string
resourceGroup: string
}): CommandDefinition => ({
command: 'functions-settings',
action: async () => {
const client = await websiteClient()
const { properties } = await client.webApps.listApplicationSettings(
resourceGroup,
`${appName}API`,
)
console.log(
JSON.stringify(
{
IsEncrypted: false,
Values: properties,
Host: {
CORS: '*',
CORSCredentials: false,
},
},
null,
2,
),
)
},
help: 'Exports the function app setting for local development.',
})
4 changes: 3 additions & 1 deletion cli/commands/react-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@ import { WebSiteManagementClient } from '@azure/arm-appservice'

export const reactConfigCommand = ({
websiteClient,
appName,
resourceGroup,
}: {
websiteClient: () => Promise<WebSiteManagementClient>
appName: string
resourceGroup: string
}): CommandDefinition => ({
command: 'react-config',
action: async () => {
const [{ hostNames }] = await Promise.all([
websiteClient().then(async (client) =>
client.webApps.get(resourceGroup, `${resourceGroup}api`),
client.webApps.get(resourceGroup, `${appName}api`),
),
])

Expand Down

0 comments on commit 549b9be

Please sign in to comment.