-
Notifications
You must be signed in to change notification settings - Fork 15
/
uic.ts
40 lines (36 loc) · 1.19 KB
/
uic.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
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 = 'uic';
export async function compileForm(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 uiFileWatcher$ = createFileWatcher$('**/*.ui');
export const liveExecution$ = enabled$('uic').pipe(
switchMap(enabled =>
iif(() => enabled, uiFileWatcher$.pipe(watchFileChangedAndCreated()), EMPTY)
),
mergeMap(uri => compileForm(uri))
);