-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api): addition of a new uninstall command (#776)
* feat(api): creation of a new `list` command * Update packages/api/src/commands/list.ts Co-authored-by: Kanad Gupta <[email protected]> * Update packages/api/src/commands/list.ts Co-authored-by: Kanad Gupta <[email protected]> * Update packages/api/src/commands/list.ts Co-authored-by: Kanad Gupta <[email protected]> * fix: pr feedback * feat(api): addition of a new `uninstall` command * feat(api): outputting `language` to the `list` command * docs: cleanup * Update packages/api/src/codegen/codegenerator.ts Co-authored-by: Kanad Gupta <[email protected]> * Update docs/how-it-works.md Co-authored-by: Kanad Gupta <[email protected]> * Update docs/how-it-works.md Co-authored-by: Kanad Gupta <[email protected]> * Update docs/how-it-works.md Co-authored-by: Kanad Gupta <[email protected]> * docs: spacing fixes * Update docs/how-it-works.md Co-authored-by: Kanad Gupta <[email protected]> --------- Co-authored-by: Kanad Gupta <[email protected]>
- Loading branch information
1 parent
3bbb7a8
commit e44461a
Showing
12 changed files
with
379 additions
and
103 deletions.
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
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
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.`, | ||
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.