Files
Igor Randjelovic de5f67f7c8 chore: add JSDocs
2020-12-08 12:07:42 +01:00

50 lines
1.2 KiB
TypeScript

import path from 'path';
import fs from 'fs';
import { getAllDependencies, getDependencyPath } from './dependencies';
import { info, warn } from './log';
import * as lib from '../index';
import { clearCurrentPlugin, setCurrentPlugin } from '../index';
/**
* @internal
*/
export function applyExternalConfigs() {
getAllDependencies().forEach((dependency) => {
const packagePath = getDependencyPath(dependency);
if (!packagePath) {
return;
}
const configPath = path.join(packagePath, 'nativescript.webpack.js');
if (fs.existsSync(configPath)) {
info(`Discovered config: ${configPath}`);
setCurrentPlugin(dependency);
try {
const externalConfig = require(configPath);
if (typeof externalConfig === 'function') {
info('Applying external config...');
externalConfig(lib);
} else if (externalConfig) {
info('Merging external config...');
lib.mergeWebpack(externalConfig);
} else {
warn(
'Unsupported external config. The config must export a function or an object.'
);
}
} catch (err) {
warn(`
Unable to apply config: ${configPath}.
Error is: ${err}
`);
}
}
});
clearCurrentPlugin();
}