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

feat: support running devkit commands on sub directory. #121

Merged
merged 1 commit into from
Nov 4, 2019
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
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