Skip to content
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

Use relative base path respective to config file #237

Merged
merged 3 commits into from
Oct 15, 2024
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
7 changes: 6 additions & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export function getSqlBasePath(config: Configuration): string {
export async function loadConfig(configFilename: string = CONFIG_FILENAME): Promise<Configuration> {
log('Resolving config file.');
const isAbsolutePath = path.isAbsolute(configFilename);
const filename = isAbsolutePath ? path.parse(configFilename).base : configFilename;
const filename = path.parse(configFilename).base;
const match = filename.match(CONFIG_FILE_CONVENTION) || filename === CONFIG_FILENAME;

if (!match) {
Expand All @@ -63,8 +63,13 @@ export async function loadConfig(configFilename: string = CONFIG_FILENAME): Prom

validate(loaded);

// Resolve the base path relative to the config file location.
const configFileLocation = path.dirname(filepath);
const relativeBasePath = path.join(configFileLocation, loaded.basePath);

const result = {
...loaded,
basePath: relativeBasePath,
injectedConfig: {
...loaded.injectedConfig,
vars: prepareInjectionConfigVars(loaded.injectedConfig.vars)
Expand Down
4 changes: 1 addition & 3 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/* Global Constants */

import * as path from 'path';

import Configuration from './domain/Configuration';

// General constants
Expand All @@ -13,7 +11,7 @@ export const CONNECTIONS_FILENAME = 'connections.sync-db.json';

export const INJECTED_CONFIG_TABLE = '__sync_db_injected_config';
export const DEFAULT_CONFIG: Configuration = {
basePath: path.resolve(process.cwd(), 'src'),
basePath: 'src',
connectionResolver: '',
execution: 'parallel',
sql: [],
Expand Down
Loading