forked from cncsc/semantic-release-config
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.js
36 lines (30 loc) · 1013 Bytes
/
utils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
const fs = require('fs');
const path = require('path');
function findPlugin(plugins, pluginName) {
// plugins can be a string (just the name) or a tuple of string and configuration object
const index = plugins.findIndex(plugin =>
// eslint-disable-next-line comma-dangle
Array.isArray(plugin) ? plugin[0] === pluginName : plugin === pluginName
);
if (index >= 0) {
return plugins[index];
}
}
function findPackageJson() {
if (process.env.npm_package_json && fs.existsSync(process.env.npm_package_json)) {
// from npx
return process.env.npm_package_json;
}
// assume that we are executing in the base of the repo
const packageJson = path.resolve(process.env.PWD, 'package.json');
if (fs.existsSync(packageJson)) {
return packageJson;
}
}
function getPackageConfig() {
const packageJson = findPackageJson();
return require(packageJson);
}
exports.findPackageJson = findPackageJson;
exports.findPlugin = findPlugin;
exports.getPackageConfig = getPackageConfig;