supports typescript configs

This commit is contained in:
James
2020-11-23 20:36:28 -05:00
parent 09f267c378
commit 352f70a9e4
2 changed files with 21 additions and 7 deletions

View File

@@ -20,13 +20,24 @@ const findConfig = (): string => {
return defaultPath;
}
// Check for config in current working directory
const cwdPath = path.resolve(process.cwd(), 'payload.config.js');
if (fs.existsSync(cwdPath)) {
return cwdPath;
const defaultTSPath = path.resolve(__dirname, '../../../payload.config.ts');
if (fs.existsSync(defaultTSPath)) {
return defaultTSPath;
}
throw new Error('Error: cannot find Payload config. Please create a configuration file located at the root of your current working directory called "payload.config.js".');
// Check for config in current working directory
const cwdJSPath = path.resolve(process.cwd(), 'payload.config.js');
if (fs.existsSync(cwdJSPath)) {
return cwdJSPath;
}
const cwdTSPath = path.resolve(process.cwd(), 'payload.config.ts');
if (fs.existsSync(cwdTSPath)) {
return cwdTSPath;
}
throw new Error('Error: cannot find Payload config. Please create a configuration file located at the root of your current working directory called "payload.config.js" or "payload.config.ts".');
};
export default findConfig;

View File

@@ -7,12 +7,15 @@ import findConfig from './find';
const configPath = findConfig();
const loadConfig = (): Config => {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const publicConfig = require(configPath);
let publicConfig = require(configPath);
if (publicConfig.default) publicConfig = publicConfig.default;
return {
...publicConfig,
paths: {
configDir: path.dirname(configPath),
...(publicConfig.paths || {}),
configDir: path.dirname(configPath),
config: configPath,
},
};