Skip to content
This repository has been archived by the owner on Dec 31, 2020. It is now read-only.

Commit

Permalink
Replacing meow with cli
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian Walter committed May 4, 2019
1 parent f0a5e08 commit 25b37a2
Showing 1 changed file with 19 additions and 41 deletions.
60 changes: 19 additions & 41 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,58 +3,36 @@
const fs = require('fs')
const { dirname } = require('path')
const { writeFile } = require('@ianwalter/fs')
const meow = require('meow')
const cli = require('@ianwalter/cli')
const pSettle = require('p-settle')
const { print, chalk } = require('@ianwalter/print')
const dist = require('.')

async function run () {
const cli = meow(
`
Usage
dist
Option
--name, -n Name to use for files and global variable (defaults to
name in package.json)
--input, -i Filename of source/entry file (defaults to
{cwd}/index.js)
--output, -o Output filename or directory path (defaults to ./dist)
--cjs, -c Path for / whether to create a CommonJS dist file
(defaults to false or main in package.json)
--esm, -e Path for / whether to create a ESM dist file (defaults
to false or module in package.json)
--browser , -b Path for / whether to create a browser-specific (ESM)
dist file (defaults to false or browser in package.json)
--inline, -l Inline/bundle imported modules (defaults to false)
--babel Transpile output with Babel (defaults to false)
--plugins, -p Specify a path for a Rollup plugins file to include
Example
❯ yarn dist
💿 Writing CommonJS file: /myProject/dist/someName.js
📦 Writing ES Module file: /myProject/dist/someName.m.js
🌎 Writing Browser file: /myProject/dist/someName.browser.js
`,
{
flags: {
name: { type: 'string', alias: 'n' },
input: { type: 'string', alias: 'i' },
output: { type: 'string', alias: 'o' },
cjs: { type: 'string', alias: 'c' },
esm: { type: 'string', alias: 'e' },
browser: { type: 'string', alias: 'b' },
inline: { type: 'string', alias: 'l' },
babel: { type: 'boolean' },
plugins: { type: 'string', alias: 'p' }
const config = cli({
name: 'dist',
opts: {
alias: {
name: 'n',
output: 'o',
cjs: 'c',
esm: 'e',
browser: 'b',
inline: 'i',
babel: 'B',
plugins: 'p'
}
}
)
})

// TODO: comment
config.input = config._.length ? config._ : config.input
delete config._

try {
// Perform distribution file generation and get back a map of files to be
// written to the filesystme.
const files = Object.entries(await dist(cli.flags))
const files = Object.entries(await dist(config))
if (files.length) {
const writes = []
files.forEach(([moduleType, [path, code]]) => {
Expand Down

0 comments on commit 25b37a2

Please sign in to comment.