This repository has been archived by the owner on Oct 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: extract common tool command function
- Loading branch information
1 parent
148e269
commit e86cb12
Showing
19 changed files
with
323 additions
and
308 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,21 @@ | ||
import { firstValueFrom } from 'rxjs' | ||
import type { CommandDeps } from '../commands' | ||
import { getTargetDocumentUri } from '../commands' | ||
import { run } from '../run' | ||
import { getToolCommand$ } from '../tool-utils' | ||
import { getToolCommandWithTargetDocumentUri } from '../tool-utils' | ||
|
||
export async function editUi({ extensionUri }: CommandDeps, ...args: any[]) { | ||
const targetDocumentUriResult = getTargetDocumentUri(...args) | ||
|
||
if (targetDocumentUriResult.kind !== 'Success') return targetDocumentUriResult | ||
|
||
const uiFile = targetDocumentUriResult.value | ||
|
||
const getToolCommandResult = await firstValueFrom( | ||
getToolCommand$({ | ||
tool: 'designer', | ||
extensionUri, | ||
resource: uiFile, | ||
}), | ||
) | ||
export async function editUi( | ||
{ extensionUri }: CommandDeps, | ||
...args: readonly unknown[] | ||
) { | ||
const result = await getToolCommandWithTargetDocumentUri({ | ||
extensionUri, | ||
argsToGetTargetDocumentUri: args, | ||
tool: 'designer', | ||
}) | ||
if (result.kind !== 'Success') return result | ||
|
||
if (getToolCommandResult.kind !== 'Success') return getToolCommandResult | ||
const { command, options, uri } = result.value | ||
|
||
return run({ | ||
command: [ | ||
...getToolCommandResult.value.command, | ||
...getToolCommandResult.value.options, | ||
uiFile.fsPath, | ||
], | ||
command: [...command, ...options, uri.fsPath], | ||
}) | ||
} |
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,34 +1,19 @@ | ||
import { firstValueFrom } from 'rxjs' | ||
import type { CommandDeps } from '../commands' | ||
import { getTargetDocumentUri } from '../commands' | ||
import { run } from '../run' | ||
import { getToolCommand$ } from '../tool-utils' | ||
import { getToolCommandWithTargetDocumentUri } from '../tool-utils' | ||
|
||
export async function editTranslations( | ||
{ extensionUri }: CommandDeps, | ||
...args: any[] | ||
...args: readonly unknown[] | ||
) { | ||
const targetDocumentUriResult = getTargetDocumentUri(...args) | ||
|
||
if (targetDocumentUriResult.kind !== 'Success') return targetDocumentUriResult | ||
|
||
const translationFile = targetDocumentUriResult.value | ||
|
||
const getToolCommandResult = await firstValueFrom( | ||
getToolCommand$({ | ||
tool: 'linguist', | ||
extensionUri, | ||
resource: translationFile, | ||
}), | ||
) | ||
const result = await getToolCommandWithTargetDocumentUri({ | ||
extensionUri, | ||
argsToGetTargetDocumentUri: args, | ||
tool: 'linguist', | ||
}) | ||
if (result.kind !== 'Success') return result | ||
|
||
if (getToolCommandResult.kind !== 'Success') return getToolCommandResult | ||
const { command, options, uri } = result.value | ||
|
||
return run({ | ||
command: [ | ||
...getToolCommandResult.value.command, | ||
...getToolCommandResult.value.options, | ||
translationFile.fsPath, | ||
], | ||
}) | ||
return run({ command: [...command, ...options, uri.fsPath] }) | ||
} |
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,34 +1,19 @@ | ||
import { firstValueFrom } from 'rxjs' | ||
import type { CommandDeps } from '../commands' | ||
import { getTargetDocumentUri } from '../commands' | ||
import { run } from '../run' | ||
import { getToolCommand$ } from '../tool-utils' | ||
import { getToolCommandWithTargetDocumentUri } from '../tool-utils' | ||
|
||
export async function compileTranslations( | ||
{ extensionUri }: CommandDeps, | ||
...args: any[] | ||
...args: readonly unknown[] | ||
) { | ||
const targetDocumentUriResult = getTargetDocumentUri(...args) | ||
|
||
if (targetDocumentUriResult.kind !== 'Success') return targetDocumentUriResult | ||
|
||
const translationFile = targetDocumentUriResult.value | ||
|
||
const getToolCommandResult = await firstValueFrom( | ||
getToolCommand$({ | ||
tool: 'lrelease', | ||
extensionUri, | ||
resource: translationFile, | ||
}), | ||
) | ||
const result = await getToolCommandWithTargetDocumentUri({ | ||
extensionUri, | ||
argsToGetTargetDocumentUri: args, | ||
tool: 'lrelease', | ||
}) | ||
if (result.kind !== 'Success') return result | ||
|
||
if (getToolCommandResult.kind !== 'Success') return getToolCommandResult | ||
const { command, options, uri } = result.value | ||
|
||
return run({ | ||
command: [ | ||
...getToolCommandResult.value.command, | ||
translationFile.fsPath, | ||
...getToolCommandResult.value.options, | ||
], | ||
}) | ||
return run({ command: [...command, uri.fsPath, ...options] }) | ||
} |
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,34 +1,19 @@ | ||
import { firstValueFrom } from 'rxjs' | ||
import type { CommandDeps } from '../commands' | ||
import { getTargetDocumentUri } from '../commands' | ||
import { run } from '../run' | ||
import { getToolCommand$ } from '../tool-utils' | ||
import { getToolCommandWithTargetDocumentUri } from '../tool-utils' | ||
|
||
export async function extractTranslations( | ||
{ extensionUri }: CommandDeps, | ||
...args: any[] | ||
...args: readonly unknown[] | ||
) { | ||
const targetDocumentUriResult = getTargetDocumentUri(...args) | ||
|
||
if (targetDocumentUriResult.kind !== 'Success') return targetDocumentUriResult | ||
|
||
const sourceFile = targetDocumentUriResult.value | ||
|
||
const getToolCommandResult = await firstValueFrom( | ||
getToolCommand$({ | ||
tool: 'lupdate', | ||
extensionUri, | ||
resource: sourceFile, | ||
}), | ||
) | ||
const result = await getToolCommandWithTargetDocumentUri({ | ||
extensionUri, | ||
argsToGetTargetDocumentUri: args, | ||
tool: 'lupdate', | ||
}) | ||
if (result.kind !== 'Success') return result | ||
|
||
if (getToolCommandResult.kind !== 'Success') return getToolCommandResult | ||
const { command, options, uri } = result.value | ||
|
||
return run({ | ||
command: [ | ||
...getToolCommandResult.value.command, | ||
sourceFile.fsPath, | ||
...getToolCommandResult.value.options, | ||
], | ||
}) | ||
return run({ command: [...command, uri.fsPath, ...options] }) | ||
} |
Oops, something went wrong.