-
Notifications
You must be signed in to change notification settings - Fork 1
feat: Command and README to generate bootstrapping configuration #248
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 7 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
4391381
feat: Bootstrap configuration and generation tool
typotter 00c9b9b
wip bootstrapping
typotter 0d1b565
merge main
typotter cd454be
trim down tool script
typotter 50d31d3
refactor node shim process shape
typotter 88ce8bc
chore: more notes
typotter 722282c
reduce PR
typotter 3e099ed
config script updates. Needs to move to node-server
typotter 77852e3
Merge branch 'main' into typo/bootstrap-config-script
typotter f329f4e
allow globals in node script/tools
typotter 78c1212
updates
typotter 8fec577
Merge branch 'main' into typo/bootstrap-config-script
typotter 11921ff
fix readme
typotter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,73 @@ | ||
import * as fs from 'fs'; | ||
|
||
import type { CommandModule } from 'yargs'; | ||
|
||
import { ConfigurationWireHelper } from '../../configuration-wire/configuration-wire-helper'; | ||
import { process } from '../node-shim'; | ||
|
||
export const bootstrapConfigCommand: CommandModule = { | ||
command: 'bootstrap-config', | ||
describe: 'Generate a bootstrap configuration string', | ||
builder: (yargs) => { | ||
return yargs.options({ | ||
key: { | ||
type: 'string', | ||
description: 'SDK key', | ||
alias: 'k', | ||
default: process.env.EPPO_SDK_KEY, | ||
}, | ||
sdk: { | ||
type: 'string', | ||
description: 'Target SDK name', | ||
default: 'android', | ||
}, | ||
'base-url': { | ||
type: 'string', | ||
description: 'Base URL for the API', | ||
}, | ||
output: { | ||
type: 'string', | ||
description: 'Output file path', | ||
alias: 'o', | ||
}, | ||
}); | ||
}, | ||
handler: async (argv) => { | ||
if (!argv.key) { | ||
console.error('Error: SDK key is required'); | ||
console.error('Provide it either as:'); | ||
console.error('- Command line argument: --key <sdkKey> or -k <sdkKey>'); | ||
console.error('- Environment variable: EPPO_SDK_KEY'); | ||
typotter marked this conversation as resolved.
Show resolved
Hide resolved
|
||
process.exit(1); | ||
} | ||
|
||
try { | ||
const helper = ConfigurationWireHelper.build(argv.key as string, { | ||
sdkName: argv.sdk as string, | ||
sdkVersion: 'v5.0.0', | ||
typotter marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
baseUrl: argv['base-url'] as string, | ||
}); | ||
const config = await helper.fetchBootstrapConfiguration(); | ||
|
||
if (!config) { | ||
console.error('Error: Failed to fetch configuration'); | ||
process.exit(1); | ||
} | ||
|
||
const jsonConfig = JSON.stringify(config); | ||
|
||
if (argv.output && typeof argv.output === 'string') { | ||
fs.writeFileSync(argv.output, jsonConfig); | ||
console.log(`Configuration written to ${argv.output}`); | ||
} else { | ||
console.log('Configuration:'); | ||
console.log('--------------------------------'); | ||
console.log(jsonConfig); | ||
console.log('--------------------------------'); | ||
} | ||
} catch (error) { | ||
console.error('Error fetching configuration:', error); | ||
process.exit(1); | ||
} | ||
}, | ||
}; |
This file contains hidden or 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,26 @@ | ||
import yargs from 'yargs'; | ||
import { hideBin } from 'yargs/helpers'; | ||
|
||
import { bootstrapConfigCommand } from './commands/bootstrap-config'; | ||
import { process } from './node-shim'; | ||
|
||
/** | ||
* Script to run the bootstrap-config command directly. | ||
typotter marked this conversation as resolved.
Show resolved
Hide resolved
|
||
*/ | ||
async function main() { | ||
await yargs(hideBin(process.argv)) | ||
.command({ | ||
command: '$0', | ||
describe: bootstrapConfigCommand.describe, | ||
builder: bootstrapConfigCommand.builder, | ||
handler: bootstrapConfigCommand.handler, | ||
}) | ||
.help() | ||
.alias('help', 'h') | ||
.parse(); | ||
} | ||
|
||
main().catch((error) => { | ||
console.error('Error in main:', error); | ||
process.exit(1); | ||
}); |
This file contains hidden or 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,8 @@ | ||
// Required type shape for `process`. | ||
// We don't pin this project to node so eslint complains about the use of `process`. We declare a type shape here to | ||
// appease the linter. | ||
export declare const process: { | ||
exit: (code: number) => void; | ||
env: { [key: string]: string | undefined }; | ||
argv: string[]; | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.