-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): dev mode to write host.json
- Loading branch information
1 parent
923971a
commit 70cdcb2
Showing
16 changed files
with
107 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { createDebugger } from '../utils'; | ||
|
||
export const debug = createDebugger('nammatham:build'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import type { EnvVariables } from './load-env-vars'; | ||
import type { HostConfigV2, LocalSettings, NammathamConfigs } from '../config-loader'; | ||
|
||
import { getExecutablePath } from '../build'; | ||
|
||
export function constructHostConfig(config: NammathamConfigs, mode: 'dev' | 'build'): string { | ||
let description: NonNullable<HostConfigV2['customHandler']>['description'] = {}; | ||
let watchDirectories: HostConfigV2['watchDirectories']; | ||
if (mode === 'build') { | ||
description = { | ||
defaultExecutablePath: getExecutablePath(config.buildOptions?.target), | ||
}; | ||
} else if (mode === 'dev') { | ||
description = { | ||
defaultExecutablePath: '../node_modules/.bin/tsx', | ||
arguments: ['watch', '../src/main.ts'], | ||
}; | ||
watchDirectories = ['../src', '.']; | ||
} | ||
return JSON.stringify( | ||
{ | ||
customHandler: { | ||
description, | ||
enableForwardingHttpRequest: true, | ||
}, | ||
watchDirectories, | ||
...config.hostConfig, | ||
} as HostConfigV2, | ||
null, | ||
2 | ||
); | ||
} | ||
|
||
export function constructLocalSettings(envVars?: EnvVariables): string { | ||
return JSON.stringify( | ||
{ | ||
IsEncrypted: false, | ||
Values: { | ||
...envVars, | ||
FUNCTIONS_WORKER_RUNTIME: 'custom', | ||
AzureWebJobsStorage: envVars?.AzureWebJobsStorage ?? 'UseDevelopmentStorage=true', | ||
}, | ||
} satisfies LocalSettings, | ||
null, | ||
2 | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export * from './load-env-vars'; | ||
export * from './config-writer'; | ||
export * from './config'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import fs from 'node:fs'; | ||
import path from 'node:path'; | ||
|
||
import type { EnvVariables } from '../config'; | ||
import type { NammathamConfigs } from '../config-loader'; | ||
|
||
import { createDebugger } from '../utils'; | ||
import { constructHostConfig, constructLocalSettings } from '../config'; | ||
|
||
const debug = createDebugger('nammatham:dev'); | ||
|
||
export async function writeConfig(config: NammathamConfigs, envVars: EnvVariables, tmpPath = '') { | ||
fs.mkdirSync(path.resolve(config.buildPath ?? './nmt', tmpPath), { recursive: true }); | ||
const targetPath = path.resolve(config.buildPath ?? './nmt', tmpPath); | ||
const result = await Promise.allSettled([ | ||
fs.promises.writeFile(path.join(targetPath, 'host.json'), constructHostConfig(config, 'dev'), 'utf-8'), | ||
fs.promises.writeFile(path.join(targetPath, 'local.settings.json'), constructLocalSettings(envVars), 'utf-8'), | ||
]); | ||
result.forEach((r) => { | ||
if (r.status === 'rejected') { | ||
throw new Error(r.reason); | ||
} | ||
}); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './dev'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './config-loader'; | ||
export * from './build'; | ||
export * from './dev'; |