generated from ryansonshine/typescript-npm-package-template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoptionsBuilderBase.ts
55 lines (52 loc) · 1.66 KB
/
optionsBuilderBase.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
46
47
48
49
50
51
52
53
54
55
import { PackageInfo } from '../types';
import { IOptionsBuilder } from './types';
import * as vscode from 'vscode';
import { OptionsBuilderHelper } from './optionsBuilderHelper';
/**
* Base class to build options for a Python package. Inherit from this class to build options for a specific package.
*/
export class OptionsBuilderBase implements IOptionsBuilder {
private _packageInfo: PackageInfo;
/**
* Information about the package.
*/
get packageInfo(): PackageInfo {
return this._packageInfo;
}
private _optionsBuilderHelper;
/**
* Helper to build options.
*/
protected get optionsBuilderHelper(): OptionsBuilderHelper {
return this._optionsBuilderHelper;
}
/**
* @param packageInfo Information about the package.
*/
constructor(packageInfo: PackageInfo) {
this._packageInfo = packageInfo;
this._optionsBuilderHelper = new OptionsBuilderHelper(
vscode.workspace.getConfiguration(
this._packageInfo.packageConfigurationSection
)
);
}
/**
* Base implementation of build. Override this method to build options for a specific package.
* @param uris File paths and folder paths to run package for.
* @returns Options for the package.
*/
public async build(uris: vscode.Uri[]): Promise<string[]> {
this._optionsBuilderHelper = new OptionsBuilderHelper(
vscode.workspace.getConfiguration(
this._packageInfo.packageConfigurationSection,
uris[0]
)
);
const options = ['-m', this._packageInfo.packageName];
if (uris.length > 0) {
options.push(...uris.map(uri => `${uri.fsPath.replace(/\\/g, '/')}`));
}
return Promise.resolve(options);
}
}