Skip to content

Commit

Permalink
feat: support running devkit commands on sub directory. (#121)
Browse files Browse the repository at this point in the history
close #114
  • Loading branch information
cpselvis authored Nov 4, 2019
1 parent a358194 commit bc819f4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
28 changes: 25 additions & 3 deletions src/core/devkit/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
}

Expand Down
3 changes: 2 additions & 1 deletion src/core/devkit/loadDevkits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit bc819f4

Please sign in to comment.