Skip to content

Commit

Permalink
fix: updated usage messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Nishant Mendiratta authored and Nishant Mendiratta committed Sep 23, 2023
1 parent 07109df commit 3c369af
Show file tree
Hide file tree
Showing 4 changed files with 155 additions and 288 deletions.
21 changes: 9 additions & 12 deletions bin/index.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,24 @@
#!/usr/bin/env node
const yargs = require("yargs");
const chalk = require("chalk");
const boxen = require("boxen");
const path = require("path");
const utils = require("./utils.js");

const usage = "\nUsage: uglifymyjs -s '/source.js'";


const options = yargs
.usage(usage)
.option("s", {alias:"source", describe: "Pass absolute path of the source javascript file", type: "string", demandOption: true })
.usage(utils.usage(chalk, boxen))
.option("s", {alias:"source", describe: "Pass absolute path of the source js file", type: "string", demandOption: true })
.help(true)
.argv;
let sourceJSPath = options.s || options.source;
if(options.s=== null && options.source === null){
utils.showHelp();
utils.showHelp(chalk, boxen);
return;
}

async function process(compiler) {
await new Promise((resolve, reject) => {
compiler.run((err, res) => {
console.log('err', err)
console.log('res', res)
if (err) {
return reject(err);
}
Expand All @@ -36,10 +33,10 @@ if(options.s) {
const config = require('./webpack.config.js');
const webpack = require('webpack');

const compiler = webpack({...config, entry: sourceJSPath, output: {path: path.resolve('.'), filename: '[name].bundle.min.js'}});
const compiler = webpack({...config, entry: sourceJSPath, output: {path: path.resolve('.'), filename: 'main.bundle.min.js'}});

(async ()=>{
(async (outputMessage, chalk, console)=>{
const response = await process(compiler);
console.log('response', response);
})();
console.log(outputMessage(chalk));
})(utils.outputMessage, chalk, console);
}
20 changes: 8 additions & 12 deletions bin/utils.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
module.exports = { showHelp: showHelp, parseSentence: parseSentence };
const inputMessage = (chalk) => `${chalk.yellow("Usage:")} ${chalk.red("uglifymyjs -s /absolute-path-to-source-js-file.js")}`
const outputMessage = (chalk) => `${chalk.yellow("\nOutput:")} ${chalk.blue("'main.bundle.min.js' is generated in the same folder.")}`
const usage = (chalk, boxen) => boxen(`${inputMessage(chalk)}${outputMessage(chalk)}`);

const usage = "\nUsage: uglifymyjs -s <absolute-path-to-source-js-file-to-be-minified-and-uglified>";

function showHelp() {
console.log(usage);
function showHelp(chalk, boxen) {
console.log(usage(chalk, boxen));
console.log('\nOptions:\r')
console.log('\t--version\t ' + 'Show version number.' + '\t\t' + '[boolean]\r')
console.log('\t-s, --source\t' + ' ' + 'Absolute path of the source javascript file' + '\t\t' + '[string]\r')
console.log('\t--help\t\t ' + 'Show help.' + '\t\t\t' + '[boolean]\n')
}

function parseSentence(words) {
var sentence = "";
for(var i = 1; i < words.length; i++) {
sentence = sentence + words[i] + " ";
}
}
}

module.exports = { showHelp, usage, outputMessage };
Loading

0 comments on commit 3c369af

Please sign in to comment.