#!/usr/bin/env node 'use strict'; const { resolve } = require('path') const { spawn } = require('child_process') const { Command } = require('commander'); const program = new Command(); const nmBinDir = resolve(`../../node_modules/.bin/`) const shell = { cmd: 'sh', arg: '-c' } const actionCommand = (command) => () => { spawn(shell.cmd, [shell.arg, `${nmBinDir}/${command}`], { env: process.env, cwd: process.cwd(), stdio: 'inherit', }) } const commandMap = { 'build-commonjs': `cross-env BABEL_ENV=commonjs NODE_ENV=production ${nmBinDir}/swc --config-file ../../.swcrc-commonjs --out-dir lib src`, 'build-es': `cross-env BABEL_ENV=es NODE_ENV=production ${nmBinDir}/swc --out-dir es src`, 'build-umd': `cross-env BABEL_ENV=rollup NODE_ENV=production ${nmBinDir}/rollup --config ../../rollup.config.js`, test: `jest`, cover: `jest --config ../../jest.config.js --coverage .`, lint: `eslint .`, bundlesize: `cross-env NODE_ENV=production ${nmBinDir}/bundlesize .` } program.version('1.0.0') for (const [key, command] of Object.entries(commandMap)) { program.command(key).action(actionCommand(command)) } program.parse();