UNPKG

1.5 kBJavaScriptView Raw
1#!/usr/bin/env node
2const program = require('commander')
3const { pick } = require('lodash')
4const { rollup } = require('rollup')
5
6const config = require('./lib/cjs')
7const { version } = require('./package.json')
8
9const parseArrayArgs = (curr, prev) => {
10 curr = curr.split(',')
11 return prev ? prev.concat(curr) : curr
12}
13
14program
15 .version(version)
16 .option('-i, --input <filename>', 'input entry file path')
17 .option('-o, --output-dir [output]', 'output destination directory')
18 .option(
19 '-f, --formats <format>',
20 'Type of output (amd, cjs, esm, iife, umd, and es versions like es2015)',
21 parseArrayArgs,
22 )
23 .option(
24 '-m, --monorepo <false | path>',
25 'whether consider the project as a monorepo, or custom the packages path',
26 )
27 .option(
28 '-e, --exports <mode>',
29 'Specify export mode (auto, default, named, none)',
30 )
31 .option(
32 '-x, --externals <package>',
33 'extra external packages, peerDependencies, and dependencies for node by default',
34 parseArrayArgs,
35 )
36 .option(
37 '-g, --globals <json>',
38 'JSON string to be parsed as umd globals map',
39 JSON.stringify,
40 )
41 .option(
42 '-p, --prod [boolean]',
43 'whether to enable production(.min.js) bundle together at the same time',
44 )
45 .parse(process.argv)
46
47config(
48 pick(
49 program,
50 'input',
51 'outputDir',
52 'formats',
53 'monorepo',
54 'exports',
55 'externals',
56 'globals',
57 'prod',
58 ),
59).map(options => rollup(options).then(bundle => bundle.write(options)))