-
Notifications
You must be signed in to change notification settings - Fork 6
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
b2cab46
12be9ae
2e41028
63916af
9b9e16c
1457b19
441432b
1f936d1
599396d
2f52f91
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -87,7 +87,7 @@ function getProjectManifest(projectDirName) { | |
|
||
exports.main = function main(dirPath) { | ||
if (!dirPath) { | ||
throw new Error("Project directory name is a compulsory argument"); | ||
throw new Error("Project directory name is a mandatory argument"); | ||
} | ||
|
||
const projectPath = path.resolve(dirPath); | ||
|
@@ -106,16 +106,13 @@ exports.main = function main(dirPath) { | |
.then(() => getProjectReadme(projectDirName)) | ||
.then(projectReadme => fs.writeFile(path.join(projectPath, "README.md"), | ||
stripAnsi(projectReadme))) | ||
.then(() => getProjectCreatedMessage(projectPath)) | ||
.then(console.log); | ||
.then(() => getProjectCreatedMessage(projectPath)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @saintsebastian we should probably return a more useful object to the caller, e.g. something like: .then(() => {
const projectCreatedMessage = getProjectCreatedMessage(projectPath);
return {projectPath, projectCreatedMessage};
}); This should also make much more clear what line 16 of the |
||
}, error => { | ||
if (error.code === "EEXIST") { | ||
const msg = `Unable to create a new WebExtension: ${chalk.bold.underline(projectPath)} dir already exist.`; | ||
console.error(`${chalk.red(msg)}\n`); | ||
process.exit(1); | ||
throw new Error(msg); | ||
} | ||
}).catch((error) => { | ||
console.error(error); | ||
process.exit(1); | ||
throw error; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @saintsebastian we can omit this catch, it is basically doing what it is going to happen if we omit it. |
||
}); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@saintsebastian This is definitely better for being able to use the module as a library but we still need to make the following tweaks:
means "anything but an 'EEXIST' error"), and we can do it by just re-throwing the caught error
printed using the color red
To achieve these behaviors we can use the same strategy that we are using in
web-ext
:instanceof
the UsageError and change the behaviorbased on it