-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathcreateSettings.js
36 lines (30 loc) · 907 Bytes
/
createSettings.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 { join } = require('path');
const pkgDir = require('pkg-dir');
const minimist = require('minimist');
const get = require('lodash/get');
const first = require('lodash/first');
const parseArgs = processArgs => {
const args = minimist(processArgs.slice(2));
return {
entry: first(args._),
esm: !!args.esm
};
};
const resolveEntry = (dir, entry) => {
if (entry) return entry;
// If no entry specified, take the main entry from package.json
// if there's no package.json,either, take './index.js'
try {
const pkg = require(join(dir, './package.json'));
return get(pkg, 'main');
} catch (err) {
return './index.js';
}
};
module.exports = function(processArgs) {
const args = parseArgs(processArgs);
const dir = pkgDir.sync() || process.cwd();
const entry = join(dir, resolveEntry(dir, args.entry));
const { esm } = args;
return { entry, dir, esm };
};