-
Notifications
You must be signed in to change notification settings - Fork 26
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(api): addition of a new uninstall command #776
Merged
Merged
Changes from 8 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
a015480
feat(api): creation of a new `list` command
erunion 565adf9
Update packages/api/src/commands/list.ts
erunion 1f85dab
Update packages/api/src/commands/list.ts
erunion 890b445
Update packages/api/src/commands/list.ts
erunion 7e8e897
fix: pr feedback
erunion e24510e
Merge branch 'main' into feat/uninstall-command
erunion e97a96f
feat(api): addition of a new `uninstall` command
erunion afbcb06
feat(api): outputting `language` to the `list` command
erunion cdfdda0
docs: cleanup
erunion 3640e60
Update packages/api/src/codegen/codegenerator.ts
erunion 8eb800d
Update docs/how-it-works.md
erunion 9fadfcf
Update docs/how-it-works.md
erunion 118ce03
Update docs/how-it-works.md
erunion 6b07ddd
Merge branch 'main' into feat/uninstall-command
erunion ce379d2
docs: spacing fixes
erunion 4a0fc90
Update docs/how-it-works.md
erunion File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
import installCommand from './install.js'; | ||
import listCommand from './list.js'; | ||
import uninstallCommand from './uninstall.js'; | ||
|
||
export default { | ||
install: installCommand, | ||
list: listCommand, | ||
uninstall: uninstallCommand, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import chalk from 'chalk'; | ||
import { Command } from 'commander'; | ||
|
||
import { SupportedLanguages } from '../codegen/factory.js'; | ||
import logger from '../logger.js'; | ||
import Storage from '../storage.js'; | ||
|
||
|
@@ -14,7 +15,6 @@ cmd | |
Storage.setStorageDir(); | ||
|
||
const lockfile = Storage.getLockfile(); | ||
|
||
if (!lockfile.apis.length) { | ||
logger('😔 You do not have any SDKs installed.'); | ||
return; | ||
|
@@ -30,6 +30,7 @@ cmd | |
logger(`package name (${chalk.red('private')}): ${chalk.grey(`@api/${api.identifier}`)}`); | ||
} | ||
|
||
logger(`language: ${chalk.grey(api.language || SupportedLanguages.JS)}`); | ||
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. |
||
logger(`source: ${chalk.grey(api.source)}`); | ||
logger(`installer version: ${chalk.grey(api.installerVersion)}`); | ||
logger(`created at: ${chalk.grey(api.createdAt || 'n/a')}`); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import path from 'node:path'; | ||
|
||
import chalk from 'chalk'; | ||
import { Command, Option } from 'commander'; | ||
import ora from 'ora'; | ||
|
||
import { SupportedLanguages, uninstallerFactory } from '../codegen/factory.js'; | ||
import promptTerminal from '../lib/prompt.js'; | ||
import logger from '../logger.js'; | ||
import Storage from '../storage.js'; | ||
|
||
interface Options { | ||
yes?: boolean; | ||
} | ||
|
||
const cmd = new Command(); | ||
cmd | ||
.name('uninstall') | ||
.description('uninstall an SDK from your codebase') | ||
.argument('<identifier>', 'the SDK to uninstall') | ||
.addOption(new Option('-y, --yes', 'Automatically answer "yes" to any prompts printed')) | ||
.action(async (identifier: string, options: Options) => { | ||
// We don't know if we have `identifier` in the storage system yet, we just need to preload the | ||
// system so we can access lockfiles. | ||
const storage = new Storage('', SupportedLanguages.JS, identifier); | ||
|
||
const entry = Storage.getFromLockfile(identifier); | ||
if (!entry) { | ||
logger( | ||
`You do not appear to have ${identifier} installed. You can run \`npx api list\` to see what SDKs are present.`, | ||
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. this is great 🫶🏽 |
||
true, | ||
); | ||
process.exit(1); | ||
} | ||
|
||
storage.setLanguage(entry?.language); | ||
storage.setIdentifier(identifier); | ||
|
||
const directory = path.relative(process.cwd(), storage.getIdentifierStorageDir()); | ||
if (!options.yes) { | ||
await promptTerminal({ | ||
type: 'confirm', | ||
name: 'value', | ||
message: `Are you sure you want to uninstall ${chalk.yellow(identifier)}? This will delete the ${chalk.yellow( | ||
directory, | ||
)} directory and potentially any changes you may have made there.`, | ||
initial: true, | ||
}).then(({ value }) => { | ||
if (!value) { | ||
process.exit(1); | ||
} | ||
}); | ||
} | ||
|
||
let spinner = ora(`Uninstalling ${chalk.grey(identifier)}`).start(); | ||
|
||
// If we have a known package name for this then we can uninstall it from within cooresponding | ||
// package manager. | ||
const pkgName = storage.getPackageName(); | ||
if (pkgName) { | ||
const language = storage.getSDKLanguage(); | ||
await uninstallerFactory(language, storage) | ||
.then(() => { | ||
spinner.succeed(spinner.text); | ||
}) | ||
.catch(err => { | ||
spinner.fail(spinner.text); | ||
logger(err.message, true); | ||
process.exit(1); | ||
}); | ||
} | ||
|
||
spinner = ora(`Removing ${chalk.grey(directory)}`).start(); | ||
await storage | ||
.remove() | ||
.then(() => { | ||
spinner.succeed(spinner.text); | ||
}) | ||
.catch(err => { | ||
spinner.fail(spinner.text); | ||
logger(err.message, true); | ||
process.exit(1); | ||
}); | ||
|
||
logger('🚀 All done!'); | ||
}) | ||
.addHelpText( | ||
'after', | ||
` | ||
Examples: | ||
$ npx api uninstall petstore`, | ||
); | ||
|
||
export default cmd; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Keeping track of what language we generated the SDK for will allow us to know how to uninstall it from that languages package manager. And because this didn't exist before this we'll default to
js
everywhere we access this.