tsyringe#autoInjectable TypeScript Examples
The following examples show how to use
tsyringe#autoInjectable.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: profile.ts From vs-code-conan with MIT License | 6 votes |
@autoInjectable()
export class BuildProfile {
public readonly profile: string | undefined;
public readonly profileHost: string | undefined;
public readonly profileBuild: string | undefined;
public readonly buildFolder: string | undefined;
private readonly system:System;
constructor(name: string,
profile: string | undefined,
profileBuild: string | undefined,
profileHost: string | undefined) {
this.system=container.resolve("System");
this.buildFolder = "build/" + name;
this.profile = this.replaceWorkspaceFolder(profile);
this.profileBuild = this.replaceWorkspaceFolder(profileBuild);
this.profileHost = this.replaceWorkspaceFolder(profileHost);
}
replaceWorkspaceFolder(source: string | undefined): string | undefined {
if (source === undefined) {
return undefined;
}
return source.replace("${workspaceFolder}", this.system.getWorkspaceRootPath()!);
}
static getDefaultValue(value: string | undefined, defaultValue: string): string {
if (value === undefined) {
return defaultValue;
}
return value;
}
}
Example #2
Source File: profile.ts From vs-code-conan with MIT License | 6 votes |
@autoInjectable()
export class Profile extends BuildProfile {
public readonly conanfilePath: string;
public readonly installArg: string;
public readonly buildArg: string;
public readonly createArg: string;
public readonly createUser: string;
public readonly createChannel: string;
constructor(
json: ProfileJson) {
super(json.name, json.profile, json.profileBuild, json.profileHost);
this.installArg = BuildProfile.getDefaultValue(json.installArg, "");
this.buildArg = BuildProfile.getDefaultValue(json.buildArg, "");
this.createArg = BuildProfile.getDefaultValue(json.createArg, "");
this.createUser = BuildProfile.getDefaultValue(json.createUser, "");
this.createChannel = BuildProfile.getDefaultValue(json.createChannel, "");
let conanfilePath = BuildProfile.getDefaultValue(json.conanFile, ".");
this.conanfilePath = <string>this.replaceWorkspaceFolder(conanfilePath);
}
}
Example #3
Source File: profile.ts From vs-code-conan with MIT License | 6 votes |
@autoInjectable()
export class Workspace extends BuildProfile {
public readonly conanworkspacePath: string;
public readonly arg: string;
constructor(json: WorkspaceJson) {
super(json.name, json.profile, json.profileBuild, json.profileHost);
let conanWs = BuildProfile.getDefaultValue(json.conanWs, ".");
this.conanworkspacePath = <string>this.replaceWorkspaceFolder(conanWs);
this.arg = BuildProfile.getDefaultValue(json.arg, "");
}
}
Example #4
Source File: commands.ts From vs-code-conan with MIT License | 5 votes |
@autoInjectable()
export class Commands{
private config:Configurator;
private executor:Executor;
private system:System;
constructor(){
this.config=container.resolve(Configurator);
this.executor = container.resolve("Executor");
this.system = container.resolve("System");
}
install(idName:string){
let installCommand = this.config.isWorkspace(idName) ? "conan workspace install" : "conan install";
let argument : WorkspaceArgument;
if(this.config.isWorkspace(idName)){
argument = this.config.getWorkspace(idName);
}
else{
argument = this.config.getConan(idName);
}
let conanfile = this.executor.normalizePathForExecution(argument.path);
let buildFolder = this.addRootFolder(argument.installFolder);
let installArg = argument.installArguments;
let profile = argument.installProfile;
let profileCommand = `--profile:build ${profile.build} --profile:host ${profile.host}`;
let installFolderArg = `--install-folder ${buildFolder}`;
const stringCommand = `${installCommand} ${profileCommand} ${installArg} ${installFolderArg} ${conanfile}`;
let command = { executionCommand: stringCommand, description: "installing" };
this.executor.pushCommand(command);
}
private addRootFolder(filePath:string|undefined) {
if (filePath === undefined) {
throw Error("InstallFolder needs to be defined!");
}
let folderWithRoot = this.system.addWorkspaceRoot(filePath);
return this.executor.normalizePathForExecution(folderWithRoot);
}
build(idName: any) {
let argument = this.config.getConan(idName);
let conanfile = this.executor.normalizePathForExecution(argument.path);
let buildFolder = this.addRootFolder(argument.buildFolder);
let buildArg = argument.buildArguments;
let buildFolderArg = `--build-folder ${buildFolder}`;
const stringCommand = `conan build ${buildArg} ${buildFolderArg} ${conanfile}`;
let command = { executionCommand: stringCommand, description: "building" };
this.executor.pushCommand(command);
}
create(profileToCreate: any) {
let argument = this.config.getConan(profileToCreate);
let conanfile = this.executor.normalizePathForExecution(argument.path);
let profile = argument.installProfile;
let profileCommand = `--profile:build ${profile.build} --profile:host ${profile.host}`;
let createUser = argument.user;
let createChannel = argument.channel;
let createArg = argument.createArguments;
const stringCommand = `conan create ${profileCommand} ${createArg} ${conanfile} ${createUser}/${createChannel}`;
let command = { executionCommand: stringCommand, description: "creating a package" };
this.executor.pushCommand(command);
}
getAllProfiles():Array<string>{
let stdout : string = this.executor.executeShortCommand("conan profile list");
let profiles = stdout.split("\n");
if((profiles.length-1)===profiles.lastIndexOf("")){
profiles.pop();//Remove empty last line
}
return profiles;
}
}
Example #5
Source File: vscode-control.ts From vs-code-conan with MIT License | 4 votes |
@autoInjectable()
export class CommandController {
private _state: AppState;
private readonly executor: Executor;
private context: vscode.ExtensionContext;
private commands: Commands;
constructor(context: vscode.ExtensionContext,
state: AppState,
@inject("Executor") executor?:Executor) {
if(!executor){
throw Error("executor has to be defined");
}
this.executor = executor;
this.commands=container.resolve(Commands);
this._state = CommandController.updateState(state);
this.context = context;
state.activeProfile = ALL;
}
private static updateState(state: AppState): AppState {
let _state: AppState = state;
_state.profiles.push(ALL);
return _state;
}
setState(state: AppState) {
this._state = CommandController.updateState(state);
}
registerInstallCommand() {
const installCommand = 'vs-code-conan.install';
let command = vscode.commands.registerCommand(installCommand, () => {
if (!this.executor.processIsStillRunning()) {
if (this._state.activeProfile === ALL) {
this._state.config.getAllNames().forEach(item => this.commands.install(item));
} else {
this.commands.install(this._state.activeProfile);
}
} else {
vscode.window.showWarningMessage("Process is already running - Install will not be processed!");
}
});
this.context.subscriptions.push(command);
return installCommand;
}
registerBuildCommand(): string {
const buildCommand = 'vs-code-conan.build';
let command = vscode.commands.registerCommand(buildCommand, () => {
if (!this.executor.processIsStillRunning()) {
if (this._state.activeProfile === ALL) {
this._state.config.getAllNames().forEach(item => {
if (!this._state.config.isWorkspace(item)) { this.commands.build(item); }
});
} else {
this.commands.build(this._state.activeProfile);
}
} else {
vscode.window.showWarningMessage("Process is already running - Build will not be processed!");
}
});
this.context.subscriptions.push(command);
return buildCommand;
}
registerCreateCommand(): string {
const createCommand = 'vs-code-conan.create';
let command = vscode.commands.registerCommand(createCommand, () => {
if (!this.executor.processIsStillRunning()) {
if (this._state.activeProfile === ALL) {
this._state.config.getAllNames().forEach(item => {
if (!this._state.config.isWorkspace(item)) { this.commands.create(item); }
});
} else {
this.commands.create(this._state.activeProfile);
}
} else {
vscode.window.showWarningMessage("Process is already running - Create will not be processed!");
}
});
this.context.subscriptions.push(command);
return createCommand;
}
registerCreateTemplate(createTemplate:()=>any) {
let command = vscode.commands.registerCommand('vs-code-conan.createTemplate',createTemplate)
this.context.subscriptions.push(command);
}
registerProfilePick(barItems: StatusBarItems) {
const myCommandId = 'vs-code-conan.profilePick';
let command = vscode.commands.registerCommand(myCommandId, () => {
let options = <vscode.QuickPickOptions>{
placeHolder: 'Choose your profile to build for conan',
//matchOnDescription: true,
onDidSelectItem: item => {
if (item) {
this._state.activeProfile = item.toString();
CommandController.updateProfile(this._state, barItems, activeProfileStatusBarItem);
}
}
};
vscode.window.showQuickPick(this._state.profiles, options);
});
this.context.subscriptions.push(command);
// create a new status bar item that we can now manage
const activeProfileStatusBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, -100);
activeProfileStatusBarItem.command = myCommandId;
activeProfileStatusBarItem.tooltip = "Set the active conan setting";
CommandController.updateProfile(this._state, barItems, activeProfileStatusBarItem);
this.context.subscriptions.push(command);
}
private static updateProfile(state: AppState, barItems: StatusBarItems, activeProfileStatusBarItem: StatusBarItem) {
activeProfileStatusBarItem.text = state.activeProfile;
activeProfileStatusBarItem.show();
if (isWorkspace(state.activeProfile)) {
barItems.install.show();
barItems.install.tooltip = "Run conan workspace install";
barItems.build.hide();
barItems.create.hide();
}
else {
barItems.install.show();
if (state.activeProfile === ALL) {
barItems.install.tooltip = "Run conan install / conan workspace install";
} else {
barItems.install.tooltip = "Run conan install";
}
barItems.build.show();
barItems.create.show();
}
function isWorkspace(activeProfile: string) {
let onlyHasWorkspaces: boolean = state.config.isWorkspace(activeProfile);
if (activeProfile === ALL) {
onlyHasWorkspaces = true;
for (let currentProfile of state.profiles) {
if (!state.config.isWorkspace(currentProfile) && currentProfile !== ALL) {
onlyHasWorkspaces = false;
break;
}
}
}
return onlyHasWorkspaces;
}
}
}
Example #6
Source File: settings-parser.ts From vs-code-conan with MIT License | 4 votes |
@autoInjectable()
export class SettingsParser {
private profiles: Map<string, Profile> | undefined;
private workspaces: Map<string, Workspace> | undefined;
private system:System|undefined;
constructor(jsonData: string){
this.system=container.resolve("System");
this.update(jsonData);
}
update(jsonData:string){
this.profiles = this.parseProfile(jsonData);
this.workspaces = this.parseWorkspace(jsonData);
}
private static isParameterCorrectlyDefined(parameter: string):boolean {
return parameter.length > 0;
}
private static isParameterNameAlreadyDefined(name: string, map: Map<string, BuildProfile>):boolean {
return !map.has(name);
}
private checkProfile(profile:ConanProfile, profiles : Map<string, BuildProfile> ) : boolean{
if(!SettingsParser.isParameterCorrectlyDefined(profile.name)){
this.showWarningMessage("Profile name has to be defined!, This Profile will be skipped!");
return false;
}
if(!SettingsParser.isParameterNameAlreadyDefined(profile.name,profiles)){
this.showWarningMessage("Profile with name: " + profile.name + " already exist! Use first setting in settings.json.");
return false;
}
return true;
}
private parseProfile(rawJson: string):Map<string, Profile>|undefined{
const jsonObj: { profiles: ProfileJson[] } = JSON.parse(rawJson);
if(!jsonObj.profiles){
return this.profiles;
}
let profiles = new Map<string, Profile>();
for (let profile of jsonObj.profiles){
if(this.checkProfile(profile,profiles)){
profiles.set(profile.name,new Profile(profile));
}
}
return profiles;
}
private parseWorkspace(rawJson: string):Map<string, Workspace> | undefined{
const jsonObj: { workspace: WorkspaceJson[] } = JSON.parse(rawJson);
if(!jsonObj.workspace){
return this.workspaces;
}
let workspaces = new Map<string, Workspace>();
for (let workspace of jsonObj.workspace){
if(this.checkProfile(workspace,workspaces)){
workspaces.set(workspace.name,new Workspace(workspace));
}
}
return workspaces;
}
getProfiles(): Map<string, Profile> | undefined{
return this.profiles;
}
getWorkspaces(): Map<string, Workspace> | undefined{
return this.workspaces;
}
private showWarningMessage(message:string){
if(this.system){
this.system.showWarningMessage(message);
}
else{
throw Error("System is not defined");
}
}
}