Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: pass argument to main function #5

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
11 changes: 10 additions & 1 deletion bin/create-webextension
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
#!/usr/bin/env node
const chalk = require("chalk");

require("..").main();
const USAGE_MSG = `Usage: create-webextension project_dir_name`;

if (!process.argv[2]) {
console.error(`${chalk.red("Missing project dir name.")}\n`);
console.log(USAGE_MSG);
process.exit(1);
}

require("..").main(process.argv[2]);
12 changes: 4 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ const chalk = require("chalk");
const fs = require("mz/fs");
const stripAnsi = require("strip-ansi");

const USAGE_MSG = `Usage: create-webextension project_dir_name`;

const README = `
This project contains a blank WebExtension addon, a "white canvas" for your new experiment of
extending and remixing the Web.
Expand Down Expand Up @@ -87,14 +85,12 @@ function getProjectManifest(projectDirName) {
};
}

exports.main = function main() {
if (!process.argv[2]) {
console.error(`${chalk.red("Missing project dir name.")}\n`);
console.log(USAGE_MSG);
process.exit(1);
exports.main = function main(dirPath) {
if (!dirPath) {
throw new Error("Project directory name is a compulsory argument");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit, how about mandatory instead of compulsory?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's the word i was looking for!

}

const projectPath = path.resolve(process.argv[2]);
const projectPath = path.resolve(dirPath);
const projectDirName = path.basename(projectPath);

return fs.mkdir(projectPath).then(() => {
Expand Down