feat: Implement devcenter open and preview commands in oclif v4#46
feat: Implement devcenter open and preview commands in oclif v4#46michaelmalave wants to merge 6 commits intofeat/ruby-to-typescriptfrom
Conversation
k80bowman
left a comment
There was a problem hiding this comment.
The commands work just fine, thank you for all of this. I left quite a few comments, though. Mostly they are smaller pattern/oclif things. I also noticed that there are no bin files.
| static flags = { | ||
| debug: Flags.boolean({ | ||
| description: 'print internal debug messages', | ||
| }), |
There was a problem hiding this comment.
Is this flag necessary? If we're using the CLI, we can just use the debug package and then people can view the debug messages via DEBUG=* or DEBUG=devcenter.
| const host = flags.host ?? '127.0.0.1' | ||
| const port = flags.port ?? 3000 |
There was a problem hiding this comment.
Do we need this if we have flag defaults set? I think we can just expand the flags object.
| debug: Flags.boolean({ | ||
| description: | ||
| 'log preview server activity (HTTP handling, file saves); enables oclif debug for this command (see `DEBUG` e.g. oclif:heroku:devcenter:preview)', | ||
| }), |
There was a problem hiding this comment.
Is this flag in the original? I couldn't find it. Also, I don't think it's necessary. We don't need to specifically enable oclif debug. In other commands, if we want to label specific debug messages, we do that through the debug package itself.
| // oclif Command wires `this.debug` to the `debug` package as `oclif:${bin}:${commandId}` (see @oclif/core getLogger). | ||
| const oclifDebugNs = `oclif:${this.config.bin}:${this.id}` | ||
| if (flags.debug && !debug.enabled(oclifDebugNs)) { | ||
| const existing = process.env.DEBUG?.trim() | ||
| debug.enable(existing ? `${existing},${oclifDebugNs}` : oclifDebugNs) | ||
| } | ||
|
|
||
| const verbose = Boolean(flags.debug || debug.enabled(oclifDebugNs)) | ||
| const debugLog = verbose ? this.debug.bind(this) : () => {} |
There was a problem hiding this comment.
I don't think this is necessary. Especially if we remove the debug flag. It looks like in the runPreview function there's only a couple of debug messages being printed anyway. We can do that directly using the debug package, I don't think we need to have a flag to enable it.
| * Heroku API token for `api.heroku.com` from netrc, same resolution as the Heroku CLI | ||
| * (`netrc-parser`: plain `~/.netrc` or `~/.netrc.gpg` when present, decrypted via `gpg`). | ||
| */ | ||
| export function getHerokuApiToken(): string { |
There was a problem hiding this comment.
I'm ok with this implementation for now, but we should open a work item for updating this to use the credential manager.
| "node": ">=22" | ||
| }, | ||
| "scripts": { | ||
| "build": "npm run clean && tsc && oclif manifest && mv oclif.manifest.json ./dist/oclif.manifest.json", |
There was a problem hiding this comment.
| "build": "npm run clean && tsc && oclif manifest && mv oclif.manifest.json ./dist/oclif.manifest.json", | |
| "build": "npm run clean && tsc && oclif manifest && oclif readme", |
It's better to include the oclif.manifest.json file in the files array rather than move it to the dist directory. Also, we should include the oclif readme command here.
| "yaml": "^2.8.3" | ||
| }, | ||
| "devDependencies": { | ||
| "@oclif/plugin-help": "^6.2.36", |
| "typescript": "^5.4.0" | ||
| }, | ||
| "overrides": { | ||
| "serialize-javascript": "^7.0.3" |
There was a problem hiding this comment.
Is this necessary? Which package is causing the issue?
| $ devcenter push dynos | ||
|
|
||
| This will save the title and content from your local article in Dev Center, using your Heroku credentials from `~/.netrc`, which you can set by doing `heroku auth:login`. | ||
| This will save the title and content from your local article in Dev Center, using your Heroku API credentials from netrc: plain `~/.netrc` or encrypted `~/.netrc.gpg` (decrypted with `gpg` when applicable), the same store as the [Heroku CLI](https://devcenter.heroku.com/articles/heroku-cli) after `heroku login`. |
There was a problem hiding this comment.
We need to update the README so that it can be autogenerated by oclif.
| "module": "Node16", | ||
| "moduleResolution": "Node16", |
There was a problem hiding this comment.
Should these both be set to NodeNext like the CLI?
Summary
This PR introduces
@heroku-cli/heroku-cli-plugin-devcenter, a Node 22+ oclif plugin that implementsheroku devcenter:openandheroku devcenter:previewusing TypeScript, HTTP calls to Dev Center foropen, local markdown/YAML handling and a local Express preview server forpreview.src/→dist/build, ESLint (oclif config), CI (multi-OS, Node 22 and 24), Dependabot for npm, and README/CONTRIBUTING updates for the new workflow.paths, Dev Center HTTP client, article parsing/rendering,~/.netrchelpers for future auth), preview templates and server, plus nock/supertest/unit tests and arunCommandhelper for command tests.DEVCENTER_CLI_CWDandDEVCENTER_CLI_TESTso tests stay isolated and non-interactive (no real browser open in tests).The Ruby
devcentergem andbin/devcenterremain the supported way to runpullandpushuntil a follow-up release.Breaking change (for users of a published npm plugin only): N/A for gem users; installing/linking this package is additive. A later PR that removes the gem will document the full breaking change.
Type of Change
Breaking Changes (major semver update)
!after your change type to denote a change that breaks current behaviorFeature Additions (minor semver update)
Patch Updates (patch semver update)
Testing
Setup:
npm install npm run build heroku plugins:link .Help:
Open a published article in the browser:
Preview a local article:
Related Issues:
GUS work item: W-20888065