Skip to content

refactor: extract duplicated prompt, JSON, file-write, and exec patterns into shared utils - #2

Open
devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1787594673-shared-utils
Open

refactor: extract duplicated prompt, JSON, file-write, and exec patterns into shared utils#2
devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1787594673-shared-utils

Conversation

@devin-ai-integration

Copy link
Copy Markdown

Checklist

  • I have read the Contributor Guide
  • I have read and agree to the Code of Conduct
  • I have added a description of my changes and why I'd like them included in the section below

Description of Changes

Four patterns were copy-pasted across commands/plugins/utils; each is now a single utility. Net -105 lines, no behavior change other than error output now going through the logger (✖ Error: ...) instead of raw console.error.

utils/inquirer/prompts.ts — three duplicated inquirer shapes:

  • selectOption({ message, options, name, invalidMessage }) replaces the identical list-prompt + options.find(o => o.name === answers[name]) + invalid-selection error in deploy.ts, auth.ts, database.ts.
  • confirmPrompt(message, { default, prefix }) replaces four hand-rolled type: 'confirm' prompts (ask-open-page.ts, check-git.ts, and two in kinde.ts).
  • promptRequiredInput({ message, emptyMessage, password }) replaces the two non-empty-validator prompts in mongoose.ts.

deploy.ts and init.ts also drop their .then().catch() promise chains for async/await + a single try/catch, matching auth.ts/database.ts.

utils/fs/json-file.tsreadJsonFile<T> / writeJsonFile replace read+parse+JSON.stringify(x, null, 2)+write blocks in install-plugins.ts, prettier.ts, read-config-file.ts, init.ts.

utils/fs/write-project-file.tswriteProjectFile(relativePath, content, { projectPath, mode }) replaces fs.writeFileSync(path.join(process.cwd() | projectPath, ...), content, { encoding: 'utf8' }) in eslint.ts, prettier.ts, jest.ts, husky.ts, init.ts, selectGitHubTemplate.ts. It mkdir -ps the parent, which subsumes husky's manual .husky dir creation.

utils/exec.tsrunCommand(cmd, options) (defaults stdio: 'inherit') replaces the private runCmd in package-manager.ts and the scattered execSync(cmd, { stdio: 'inherit' }) calls in init.ts, husky.ts, setup-git-repo.ts.

logFailure(text, error) in utils/logger.ts replaces ~8 console.error('Failed to X:', error) sites so CLI errors are formatted consistently.

_template/ and COMMAND_TEMPLATE/ are intentionally untouched — they are standalone scaffolding examples.

Verified with npx tsc --noEmit, npm run lint src, npm run build.

Related Issues

None

Link to Devin session: https://app.devin.ai/sessions/00fcd088d0e545abb8332fc70ef5bb93
Requested by: @lox-bot

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration

Copy link
Copy Markdown
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant