cli: allow running with no configuration files
Co-authored-by: Patrik Oldsberg <poldsberg@gmail.com> Signed-off-by: MT Lewis <mtlewis@users.noreply.github.com>
This commit is contained in:
@@ -21,6 +21,7 @@ export type AsyncConfigSourceGenerator = AsyncGenerator<
|
||||
|
||||
// @public
|
||||
export interface BaseConfigSourcesOptions {
|
||||
allowMissingDefaultConfig?: boolean;
|
||||
// (undocumented)
|
||||
remote?: Pick<RemoteConfigSourceOptions, 'reloadInterval'>;
|
||||
// (undocumented)
|
||||
|
||||
@@ -69,13 +69,18 @@ describe('ConfigSources', () => {
|
||||
});
|
||||
|
||||
it('should create default sources for targets', () => {
|
||||
const fsSpy = jest.spyOn(fs, 'pathExistsSync').mockImplementation(path => {
|
||||
return path === `${root}app-config.yaml`;
|
||||
});
|
||||
|
||||
expect(
|
||||
mergeSources(
|
||||
ConfigSources.defaultForTargets({ rootDir: '/', targets: [] }),
|
||||
),
|
||||
).toEqual([{ name: 'FileConfigSource', path: `${root}app-config.yaml` }]);
|
||||
|
||||
const fsSpy = jest.spyOn(fs, 'pathExistsSync').mockReturnValue(true);
|
||||
fsSpy.mockReturnValue(true);
|
||||
|
||||
expect(
|
||||
mergeSources(
|
||||
ConfigSources.defaultForTargets({ rootDir: '/', targets: [] }),
|
||||
@@ -159,6 +164,10 @@ describe('ConfigSources', () => {
|
||||
});
|
||||
|
||||
it('should create a default source', () => {
|
||||
const fsSpy = jest.spyOn(fs, 'pathExistsSync').mockImplementation(path => {
|
||||
return path === `${root}app-config.yaml`;
|
||||
});
|
||||
|
||||
expect(
|
||||
mergeSources(
|
||||
ConfigSources.default({
|
||||
@@ -184,6 +193,8 @@ describe('ConfigSources', () => {
|
||||
{ name: 'FileConfigSource', path: resolvePath('b.yaml') },
|
||||
{ name: 'EnvConfigSource', env: { HOME: '/' } },
|
||||
]);
|
||||
|
||||
fsSpy.mockRestore();
|
||||
});
|
||||
|
||||
it('should merge sources', () => {
|
||||
|
||||
@@ -74,6 +74,11 @@ export interface BaseConfigSourcesOptions {
|
||||
watch?: boolean;
|
||||
rootDir?: string;
|
||||
remote?: Pick<RemoteConfigSourceOptions, 'reloadInterval'>;
|
||||
/**
|
||||
* Allow the default app-config.yaml to be missing, in which case the source
|
||||
* will not be created.
|
||||
*/
|
||||
allowMissingDefaultConfig?: boolean;
|
||||
|
||||
/**
|
||||
* A custom substitution function that overrides the default one.
|
||||
@@ -177,14 +182,19 @@ export class ConfigSources {
|
||||
if (argSources.length === 0) {
|
||||
const defaultPath = resolvePath(rootDir, 'app-config.yaml');
|
||||
const localPath = resolvePath(rootDir, 'app-config.local.yaml');
|
||||
const alwaysIncludeDefaultConfigSource =
|
||||
!options.allowMissingDefaultConfig;
|
||||
|
||||
if (alwaysIncludeDefaultConfigSource || fs.pathExistsSync(defaultPath)) {
|
||||
argSources.push(
|
||||
FileConfigSource.create({
|
||||
watch: options.watch,
|
||||
path: defaultPath,
|
||||
substitutionFunc: options.substitutionFunc,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
argSources.push(
|
||||
FileConfigSource.create({
|
||||
watch: options.watch,
|
||||
path: defaultPath,
|
||||
substitutionFunc: options.substitutionFunc,
|
||||
}),
|
||||
);
|
||||
if (fs.pathExistsSync(localPath)) {
|
||||
argSources.push(
|
||||
FileConfigSource.create({
|
||||
|
||||
Reference in New Issue
Block a user