feat: external config loading

+refactor many pieces
This commit is contained in:
Igor Randjelovic
2020-11-21 13:34:09 +01:00
parent b1bc2640db
commit 46853d2c83
15 changed files with 358 additions and 107 deletions

View File

@ -0,0 +1,36 @@
import path from 'path';
import fs from 'fs';
import dedent from 'ts-dedent';
import * as lib from '../index';
import { error, info } from './log';
import { getAllDependencies, getDependencyPath } from './dependencies';
export function applyExternalConfigs() {
getAllDependencies().forEach((dependency) => {
const packagePath = getDependencyPath(dependency);
const configPath = path.join(packagePath, 'nativescript.webpack.js');
if (fs.existsSync(configPath)) {
info(`Discovered config: ${configPath}`);
try {
const externalConfig = require(configPath);
if (typeof externalConfig === 'function') {
externalConfig(lib);
} else {
// todo: warn user
// todo: perhaps support exported objects to merge into config?
}
} catch (err) {
error(
dedent`
Unable to apply config: ${configPath}.
Error is:
`,
err
);
}
}
});
}