Skip to content
This repository has been archived by the owner on Feb 16, 2024. It is now read-only.

Commit

Permalink
INT-2340 Intuita Login Command Part 1 (#170)
Browse files Browse the repository at this point in the history
  • Loading branch information
hbjORbj authored Dec 20, 2023
1 parent d922534 commit daef303
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 5 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ The `syncRegistry` command can be used to sync local codemods with the public [C

### Generate codemod from file diff

The `learn` command can be used to send the diff of the latest edited file to Codemod Studio and have it automatically build an explainable and debuggable codemod.
The `learn` command can be used to send the diff of the latest edited file to the Codemod Studio and have it automatically build an explainable and debuggable codemod.

After running this command, if any git diff exists, Intuita will use the diff as before/after snippets in [Codemod Studio](https://codemod.studio).
After running this command, if any git diff exists, Intuita will use the diff as before/after snippets in the [Codemod Studio](https://codemod.studio).

intuita learn

Expand Down
27 changes: 26 additions & 1 deletion src/executeMainThread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
DEFAULT_INPUT_DIRECTORY_PATH,
} from './constants.js';
import { readFile } from 'node:fs/promises';
import { handleLoginCliCommand } from './handleLoginCliCommand.js';

// the build script contains the version
declare const __INTUITA_CLI_VERSION__: string;
Expand Down Expand Up @@ -73,13 +74,18 @@ export const executeMainThread = async () => {
)
.command(
'learn',
'exports the current `git diff` in a file to before/after panels in codemod studio',
'exports the current `git diff` in a file to before/after panels in the Codemod Studio',
(y) =>
buildUseJsonOption(y).option('targetPath', {
type: 'string',
description: 'Input file path',
}),
)
.command(
'login',
'logs in through authentication in the Codemod Studio',
(y) => buildUseJsonOption(y),
)
.help()
.version(__INTUITA_CLI_VERSION__);

Expand Down Expand Up @@ -204,6 +210,25 @@ export const executeMainThread = async () => {
return;
}

if (String(argv._) === 'login') {
const printer = new Printer(argv.useJson);

try {
await handleLoginCliCommand(printer);
} catch (error) {
if (!(error instanceof Error)) {
return;
}

printer.printOperationMessage({
kind: 'error',
message: error.message,
});
}

return;
}

const intuitaDirectoryPath = join(
String(argv._) === 'runOnPreCommit' ? process.cwd() : homedir(),
'.intuita',
Expand Down
5 changes: 3 additions & 2 deletions src/handleLearnCliCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,14 +302,15 @@ export const handleLearnCliCommand = async (

printer.printConsoleMessage(
'info',
'Learning went successful! Opening Codemod Studio...',
'Learning went successful! Opening the Codemod Studio...',
);

const success = openURL(url);
if (!success) {
printer.printOperationMessage({
kind: 'error',
message: 'Unexpected error occurred while opening Codemod Studio.',
message:
'Unexpected error occurred while opening the Codemod Studio.',
});
return;
}
Expand Down
13 changes: 13 additions & 0 deletions src/handleLoginCliCommand.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import terminalLink from 'terminal-link';
import type { PrinterBlueprint } from './printer.js';

const ACCESS_TOKEN_REQUESTED_BY_CLI_KEY = 'accessTokenRequestedByCLI';

export const handleLoginCliCommand = async (printer: PrinterBlueprint) => {
const EXTENSION_LINK = terminalLink(
'Click to sign in to Intuita via the Codemod Studio!',
`https://codemod.studio/${ACCESS_TOKEN_REQUESTED_BY_CLI_KEY}`,
);

printer.printConsoleMessage('log', EXTENSION_LINK);
};

0 comments on commit daef303

Please sign in to comment.