-
Notifications
You must be signed in to change notification settings - Fork 67
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
[BD-46] feat: add paragon-cli #2460
[BD-46] feat: add paragon-cli #2460
Conversation
Thanks for the pull request, @monteri! When this pull request is ready, tag your edX technical lead. |
✅ Deploy Preview for paragon-openedx ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify site configuration. |
paragon-cli.js
Outdated
|
||
const themes = [ | ||
{ name: '@edx/brand-openedx', value: '' }, | ||
{ name: '@edx/brand-edx.org', value: 'npm:@edx/brand-edx.org@latest' }, |
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.
[suggestion] I believe we may want to avoid hardcoding @brand-edx.org
in this specific case. Take consumers other than edX.org in the community that have their own @edx/brand
packages. The CLI tool should be able to handle any @edx/brand
package provided by the consumer, at the version they specify.
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.
Q: "What @edx/brand
package do you want to install?"
A: @edx/brand-edx.org@latest
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.
Updated to this variant. Also I think it will useful to have commands in own js files. So I updated CLI to use Object
instead of switch case
paragon-cli.js
Outdated
@@ -0,0 +1,57 @@ | |||
#!/usr/bin/env node | |||
|
|||
const inquirer = require('inquirer'); |
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.
Oooh neat, I was looking at inquirer
awhile back. Seems pretty cool, and more powerful than the commander
package we've previously been using to build CLI tools.
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.
😄
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.
This looks like a great start to the foundations of a single Paragon CLI tool that supports multiple commands/features! 😄
A few additional feedback items / thoughts:
- In the
example
app, I noticed that@edx/brand-openedx
is installed / imported from directly rather than the expected@edx/brand
alias. I believe we'll want to install@edx/brand-openedx
in theexample
MFE as follows:"@edx/brand": "npm:@edx/brand-openedx@^1.1.0"
- Similarly, the
example/src/index.scss
file will need to be updated to import from the@edx/brand
alias. - Add a "start:with-theme" NPM script in the
example
MFE's package.json file in order to use the command as if you were an engineer in a consuming MFE, something like:
{
"scripts": {
"install-brand": "../bin/paragon-scripts.js theme",
"start:with-brand": "npm run install-theme && npm start"
}
}
Usage in example
MFE
npm run start:with-theme
package.json
Outdated
@@ -8,6 +8,9 @@ | |||
"publishConfig": { | |||
"access": "public" | |||
}, | |||
"bin": { | |||
"paragon": "paragon-cli.js" |
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.
[suggestion] Might be good to match the folder structure of @edx/frontend-build
regarding its fedx-scripts
, i.e. let's move paragon-cli.js
under a bin
directory (and maybe even rename to paragon-scripts
?) such that this line becomes something more like:
{
"bin": {
"paragon": "./bin/paragon-scripts.js"
}
}
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.
Yes, I agree, updated name and location
paragon-cli.js
Outdated
const [command, ...args] = process.argv.slice(2); | ||
|
||
switch (command) { | ||
case 'theme': |
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.
[suggestion] Perhaps install-theme
to be a bit more explicit/descriptive in the command name?
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.
Agree, changed
paragon-cli.js
Outdated
} | ||
|
||
function installTheme(theme) { | ||
const installCommand = `npm install "@edx/brand@${theme}" --no-save`; |
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.
[suggestion] This can totally be deferred, but an idea: make the --no-save
option configurable/overrideable such that the command can be run where this npm install
does save. The default should be --no-save
, though.
I'm thinking of a possible use case where the Paragon CLI could be used in infrastructure/deployment code to install the @edx/brand
aliases rather than the infrastructure/deployment code needing to do the npm install
themselves (might be easier to simply run paragon install-theme
during the build+deploy process 🤷♂️). Ah, but in this case, the user input wouldn't be possible.
Let's defer on this comment for now but come back to it at some point. I think to support the infrastructure/deployment code use case, we'd need a variant of the paragon install-theme
CLI command that allowed its user to pass --brand
(or similar) as an argument to avoid needing to provide user input.
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.
Yes, I think it is good idea, maybe flag -d
, --deploy
or something will solve the problem and will make it clear for the user. Also I created issue for your three comments that won't be part of this PR. #2483
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.
Thanks for creating the issue!
paragon-cli.js
Outdated
break; | ||
|
||
default: | ||
console.log('Unknown command. Usage: paragon <command>'); |
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.
[suggestion] Take a look at the chalk
JS library: https://github.com/chalk/chalk
I've started to introduce it into @edx/frontend-build
's fedx-scripts
CLI tool and think it's a worthwhile pattern to bring here. Basically, chalk
allows you to draw more attention to console.log
statements such as this by formatting it.
In this case, given it's an error, perhaps its formatted with red and bold, for example.
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.
Added usage of chalk
. For both errors I added red and bold color.
paragon-cli.js
Outdated
break; | ||
|
||
default: | ||
console.log('Unknown command. Usage: paragon <command>'); |
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.
[curious/suggestion] Is there a way to list out all possible CLI commands as a hint for users on what commands are available to use? In a similar vein, is there or should there be a paragon help
type of functionality? This, too, could likely be deferred as a separate feature addition.
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.
Also put this comment as part of the issue #2483
paragon-cli.js
Outdated
(async () => { | ||
const [command, ...args] = process.argv.slice(2); | ||
|
||
switch (command) { |
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.
[suggestion] To have better observability in how consumers make use of these commands, I might recommend we try dispatching a Segment event describing which command is used and how, similar to how we have sendTrackInfo
in the component generator tool.
Speaking of the component generator, we may also want to backlog an issue to migrate its current implementation into this new Paragon CLI as a distinct command (not in scope for this PR).
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.
I put this comment as part of the issue #2483
We are able to use |
@monteri [inform] Looks like there's some linting errors. For the one's related to "should be listed in the project's dependencies, not devDependencies", we may want to ignore this class of errors in the |
Thank you, I fixed linting errors. |
Codecov ReportPatch coverage has no change and project coverage change:
Additional details and impacted files@@ Coverage Diff @@
## master #2460 +/- ##
==========================================
+ Coverage 91.38% 91.65% +0.26%
==========================================
Files 234 236 +2
Lines 4157 4195 +38
Branches 1001 1012 +11
==========================================
+ Hits 3799 3845 +46
+ Misses 351 346 -5
+ Partials 7 4 -3 ☔ View full report in Codecov by Sentry. |
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.
Looks good! Added a minor question, and a comment about the example NPM script not seeming to work without a modification. Once those items are clarified/resolved, ✅
bin/paragon-scripts.js
Outdated
const COMMANDS = { | ||
'install-theme': themeCommand, | ||
// eslint-disable-next-line no-console | ||
test: () => console.log('Executing "paragon test" function...'), |
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.
[curious] Do we intend to keep this as part of the CLI?
example/package.json
Outdated
@@ -10,12 +10,13 @@ | |||
"precommit": "npm run lint", | |||
"snapshot": "fedx-scripts jest --updateSnapshot", | |||
"start": "fedx-scripts webpack-dev-server --progress", | |||
"start:with-theme": "paragon install-theme && npm start", |
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.
When running this, I get the following error:
❯ npm run start:with-theme
> example@1.0.0 start:with-theme
> paragon install-theme && npm start
sh: paragon: command not found
npm ERR! Lifecycle script `start:with-theme` failed with error:
npm ERR! Error: command failed
npm ERR! in workspace: example@1.0.0
npm ERR! at location: /Users/astankiewicz/Desktop/edx/paragon/example
I believe we could resolve this error by changing the line to:
../bin/paragon-scripts.js install-theme && npm start
package.json
Outdated
"chalk": "^4.1.2", | ||
"child_process": "^1.0.2", |
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.
[curious] I have a hunch these dependencies will need to be installed of regular dependencies
, including inquirer
below.
If installed as devDependencies
, their code won't be included in the installed bundle in the consuming application, which could lead to not being able to run the Paragon CLI correctly. It's not a concern within the example
app in the Paragon repo itself, because these packages are installed into the root node_modules
via the devDependencies
. However, for MFEs outside of the Paragon repo, this could be a concern.
I wonder if it's worth a sanity check of trying to run the Paragon CLI outside of the example
MFE app, too? Perhaps installing this branch of Paragon into frontend-template-application
would be a good test (I think the bin
script should work?).
npm install "https://github.com/openedx/paragon.git#raccoongang:zadorozhnii/paragon-cli-for-theming" --save
Note this also related to the // eslint-disable-next-line import/no-extraneous-dependencies
comments.
bin/install-theme.js
Outdated
type: 'input', | ||
name: 'theme', | ||
message: 'What @edx/brand package do you want to install?', | ||
default: '', |
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.
nit: Should this default @edx/brand-openedx@latest
? Or a required field? Worth a sanity check.
@monteri 🎉 Your pull request was merged! Please take a moment to answer a two question survey so we can improve your experience in the future. |
🎉 This PR is included in version 21.1.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Exposes a `paragon` CLI with an `install-theme` command. Example usage in `package.json`: ``` { "scripts": { "start:with-theme": "paragon install-theme && npm start", "build:with-theme": "paragon install-theme && npm run build" } } ``` The Paragon CLI will prompt from which NPM package you wish to install as the `@edx/brand` package (e.g., `@edx/brand-edx.org@latest`), and install it without modifying the `package.json` or `package-lock.json` files. Additional commands will be added to the `paragon` CLI tool in the future.
Description
Add paragon CLI that will provide Paragon consumers with
paragon <command>
. Right now it allows to runparagon install-theme
and specify a custom brand package to install with the--no-save
option (e.g.,@edx/brand-edx.org@latest
) to install custom brands during MFE local development without changingpackage.json
.Deploy Preview
N/A
Merge Checklist
example
app?wittjeff
andadamstankiewicz
as reviewers on this PR.Post-merge Checklist