diff --git a/src/core/devkit/config.ts b/src/core/devkit/config.ts index 4cf14183..73a0d059 100644 --- a/src/core/devkit/config.ts +++ b/src/core/devkit/config.ts @@ -11,11 +11,33 @@ export default class Config { this.ctx = ctx; } + getConfigDirectory(): string { + let currDir: string = process.cwd(); + + const isConfigExits = () => { + for (const filename of DEVKIT_CONFIG) { + if (fs.existsSync(path.join(currDir, filename))) { + return true; + } + } + return false; + } + + while (!isConfigExits()) { + currDir = path.join(currDir, '../'); + if (currDir === '/' || /^[a-zA-Z]:\\$/.test(currDir)) { + return ''; + } + } + + return currDir; + } + loadConfig() { - const directoryPath = process.cwd(); + const directoryPath = this.getConfigDirectory(); + for (const filename of DEVKIT_CONFIG) { const filePath = path.join(directoryPath, filename); - if (fs.existsSync(filePath)) { let configData; @@ -36,7 +58,7 @@ export default class Config { } } - this.ctx.logger.debug(`Config file not found on ${directoryPath}`); + this.ctx.logger.debug(`Config file not found.`); return null; } diff --git a/src/core/devkit/loadDevkits.ts b/src/core/devkit/loadDevkits.ts index 1586766a..e6dde705 100644 --- a/src/core/devkit/loadDevkits.ts +++ b/src/core/devkit/loadDevkits.ts @@ -11,13 +11,14 @@ const resolveBuilder = (builderStr: string) => { export default function loadDevkits(ctx: any) { const config = new Config(ctx); const configData = config.loadConfig(); + const directoryPath = config.getConfigDirectory(); if (configData) { const devkit = configData.devkit; ctx.projectConfig = configData; for (const cmd in devkit.commands) { const builderStr = devkit.commands[cmd].builder; const [packageName, builderName] = builderStr.split(':', 2); - const pkgPath = path.join(process.cwd(), 'node_modules', packageName); + const pkgPath = path.join(directoryPath, 'node_modules', packageName); const kitJson = require(path.join(pkgPath, 'devkit.json')); const implementation = kitJson.builders[cmd].implementation; const description = kitJson.builders[cmd].description;