Skip to content
This repository was archived by the owner on Aug 7, 2021. It is now read-only.

Commit 035056f

Browse files
committed
feat: add 'getWebpackConfig' helper function
1 parent 889f5d5 commit 035056f

File tree

1 file changed

+29
-6
lines changed

1 file changed

+29
-6
lines changed

projectHelpers.js

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,28 @@ const getAndroidRuntimeVersion = (projectDir) => {
4444
}
4545
}
4646

47+
const getWebpackConfig = (projectDir, configPath = "webpack.config.js") => {
48+
const configAbsolutePath = path.resolve(projectDir, configPath);
49+
let config;
50+
try {
51+
config = require(configAbsolutePath);
52+
} catch (e) {
53+
throw new Error(
54+
`Couldn't load webpack config from ${configAbsolutePath}. ` +
55+
`Original error:\n${e}`
56+
);
57+
}
58+
if (typeof config === "function") {
59+
config = config();
60+
}
61+
62+
if (!config) {
63+
throw new Error(`Webpack config from ${configAbsolutePath} is empty!`);
64+
}
65+
66+
return config;
67+
};
68+
4769
const getPackageJson = projectDir => {
4870
const packageJsonPath = getPackageJsonPath(projectDir);
4971
return JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
@@ -115,14 +137,15 @@ const resolveAndroidConfigurationsPath = projectDir => {
115137
const getPackageJsonPath = projectDir => path.resolve(projectDir, "package.json");
116138

117139
module.exports = {
118-
isTypeScript,
119-
isAngular,
120-
isSass,
121-
writePackageJson,
140+
getAndroidProjectPath,
141+
getAndroidRuntimeVersion,
122142
getPackageJson,
123143
getProjectDir,
124-
getAndroidRuntimeVersion,
125-
getAndroidProjectPath,
144+
getWebpackConfig,
145+
isAngular,
146+
isSass,
147+
isTypeScript,
126148
resolveAndroidAppPath,
127149
resolveAndroidConfigurationsPath,
150+
writePackageJson,
128151
};

0 commit comments

Comments
 (0)