-
Notifications
You must be signed in to change notification settings - Fork 15
/
rcc.ts
45 lines (41 loc) · 1.24 KB
/
rcc.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { EMPTY, iif } from 'rxjs';
import { mergeMap, switchMap } from 'rxjs/operators';
import * as vscode from 'vscode';
import {
createPathIfNotExist,
getActiveWorkspaceFolderPath,
getFsPathOrActiveDocumentPath,
} from '../utils/paths';
import { PredefinedVariableResolver } from '../utils/predefined-variable-resolver';
import { run } from '../utils/run';
import {
createFileWatcher$,
enabled$,
watchFileChangedAndCreated,
} from '../utils/watcher';
import { Tool } from './tool';
const NAME = 'rcc';
export async function compileResource(fileUri?: vscode.Uri) {
const inPath = getFsPathOrActiveDocumentPath(fileUri);
const tool = new Tool(NAME, new PredefinedVariableResolver(inPath));
const outputPath = tool.getOutputPath();
if (outputPath) createPathIfNotExist(outputPath);
return run({
command:
`${await tool.getPathWithQuotes()} ` +
`${tool.args.join(' ')} ` +
`"${inPath}"`,
cwd: getActiveWorkspaceFolderPath(),
});
}
const qrcFileWatcher$ = createFileWatcher$('**/*.qrc');
export const liveExecution$ = enabled$('rcc').pipe(
switchMap(enabled =>
iif(
() => enabled,
qrcFileWatcher$.pipe(watchFileChangedAndCreated()),
EMPTY
)
),
mergeMap(uri => compileResource(uri))
);