Skip to content

Commit

Permalink
Extension Installation CLI Added
Browse files Browse the repository at this point in the history
TSLint Improved
#434
#590
#513
#337
  • Loading branch information
shanalikhan committed Aug 14, 2018
1 parent 8c7ac94 commit e9b263d
Show file tree
Hide file tree
Showing 6 changed files with 271 additions and 237 deletions.
22 changes: 1 addition & 21 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,6 @@
"default": "",
"description": "%ext.config.gist%"
},
"sync.lastUpload": {
"type": "string",
"default": "",
"description": "%ext.config.lastUpload%"
},
"sync.lastDownload": {
"type": "string",
"default": "",
"description": "%ext.config.lastDownload%"
},
"sync.autoDownload": {
"type": "boolean",
"default": false,
Expand All @@ -128,16 +118,6 @@
"default": false,
"description": "%ext.config.forceDownload%"
},
"sync.host": {
"type": "string",
"default": "",
"description": "%ext.config.host%"
},
"sync.pathPrefix": {
"type": "string",
"default": "",
"description": "%ext.config.pathPrefix%"
},
"sync.quietSync": {
"type": "boolean",
"default": false,
Expand Down Expand Up @@ -188,4 +168,4 @@
"lockfile": "^1.0.4",
"temp": "^0.8.3"
}
}
}
17 changes: 1 addition & 16 deletions src/commons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -475,25 +475,10 @@ export default class Commons {

const keys = Object.keys(setting);
keys.forEach(async keyName => {
if (
(keyName === "lastDownload" || keyName === "lastUpload") &&
setting[keyName]
) {
try {
const zz = new Date(setting[keyName]);
setting[keyName] = zz;
} catch (e) {
setting[keyName] = new Date();
}
}
if (setting[keyName] == null) {
setting[keyName] = "";
}
if (keyName.toLowerCase() === "token") {
allKeysUpdated.push(
this.context.globalState.update("synctoken", setting[keyName])
);
} else {
if (keyName.toLowerCase() !== "token") {
allKeysUpdated.push(config.update(keyName, setting[keyName], true));
}
});
Expand Down
119 changes: 92 additions & 27 deletions src/service/pluginService.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"use strict";
import * as fs from 'fs-extra';
import * as path from 'path';
import * as vscode from 'vscode';

import * as fs from "fs-extra";
import * as path from "path";
import * as vscode from "vscode";
import * as util from "../util";
import * as util from '../util';

const apiPath =
"https://marketplace.visualstudio.com/_apis/public/gallery/extensionquery";
Expand Down Expand Up @@ -77,7 +77,7 @@ export class ExtensionMetadata {
public publisherId: string,
public publisherDisplayName: string,
public date: string
) {}
) { }
}

export class PluginService {
Expand Down Expand Up @@ -210,9 +210,9 @@ export class PluginService {
} catch (err) {
console.error(
"Sync : Unable to delete extension " +
selectedExtension.name +
" " +
selectedExtension.version
selectedExtension.name +
" " +
selectedExtension.version
);
console.error(err);
throw deletedExt;
Expand All @@ -224,29 +224,101 @@ export class PluginService {
public static async InstallExtensions(
extensions: string,
extFolder: string,
useCli: boolean,
notificationCallBack: (...data: any[]) => void
): Promise<ExtensionInformation[]> {
const actionList: Array<Promise<void>> = [];
const addedExtensions: ExtensionInformation[] = [];
let actionList: Array<Promise<void>> = [];
let addedExtensions: ExtensionInformation[] = [];
const missingList = PluginService.GetMissingExtensions(extensions);
if (missingList.length === 0) {
notificationCallBack("Sync : No Extensions needs to be installed.");
return [];
}

let totalInstalled: number = 0;
if (useCli) {
addedExtensions = await PluginService.ProcessInstallationCLI(missingList,
notificationCallBack);
return addedExtensions;
} else {
actionList = await this.ProcessInstallation(
extFolder,
notificationCallBack,
missingList
);
try {
await Promise.all(actionList);
return addedExtensions;
} catch (err) {
// always return extension list
return addedExtensions;
}
}
}

public static async ProcessInstallationCLI(
missingList: ExtensionInformation[],
notificationCallBack: (...data: any[]) => void
): Promise<ExtensionInformation[]> {
const addedExtensions: ExtensionInformation[] = [];
const exec = require("child_process").exec;
for (let i = 0; i < missingList.length; i++) {
const missExt = missingList[i];
const name = missExt.publisher + "." + missExt.name;
let myExt: string = process.argv0;
myExt =
'"' +
process.argv0.substr(0, process.argv0.lastIndexOf("Code")) +
'bin\\code"';
myExt = myExt + " --install-extension " + name;
console.log(myExt);
try {
const installed = await new Promise<boolean>((res) => {
exec(myExt, (err, stdout, stderr) => {
if (err || stderr) {
console.log(err || stderr);
res(false);
}
console.log(stdout);
res(true);
});
});
if (installed) {
notificationCallBack(
"Sync : Extension " +
(i + 1) +
" of " +
missingList.length.toString() +
" installed.",
false
);
addedExtensions.push(missExt);
}
} catch (err) {
console.log(err);
}
}
return addedExtensions;
}

public static async ProcessInstallation(
extFolder: string,
notificationCallBack: (...data: any[]) => void,
missingList: ExtensionInformation[]
) {
const actionList: Array<Promise<void>> = [];
const addedExtensions: ExtensionInformation[] = [];
let totalInstalled: number = 0;
for (const element of missingList) {
actionList.push(
PluginService.InstallExtension(element, extFolder).then(
() => {
totalInstalled = totalInstalled + 1;
notificationCallBack(
"Sync : Extension " +
totalInstalled +
" of " +
missingList.length.toString() +
" installed.",
totalInstalled +
" of " +
missingList.length.toString() +
" installed.",
false
);
addedExtensions.push(element);
Expand All @@ -261,14 +333,7 @@ export class PluginService {
)
);
}

try {
await Promise.all(actionList);
return addedExtensions;
} catch (err) {
// always return extension list
return addedExtensions;
}
return actionList;
}

public static async InstallExtension(
Expand Down Expand Up @@ -338,10 +403,10 @@ export class PluginService {
if (error === "NA" || error.message === "NA") {
console.error(
"Sync : Extension : '" +
item.name +
"' - Version : '" +
item.version +
"' Not Found in marketplace. Remove the extension and upload the settings to fix this."
item.name +
"' - Version : '" +
item.version +
"' Not Found in marketplace. Remove the extension and upload the settings to fix this."
);
}
console.error(error);
Expand Down
9 changes: 5 additions & 4 deletions src/setting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,12 @@ import { Environment } from "./environmentPath";

export class ExtensionConfig {
public gist: string = null;
public host: string = null;
public pathPrefix: string = null;
public quietSync: boolean = false;
public askGistName: boolean = false;
public removeExtensions: boolean = true;
public syncExtensions: boolean = true;
public autoDownload: boolean = false;
public autoUpload = false;
public lastUpload: Date = null;
public lastDownload: Date = null;
public forceDownload: boolean = false;
}

Expand Down Expand Up @@ -52,4 +48,9 @@ export class CustomSettings {
public downloadPublicGist: boolean = false;
public supportedFileExtensions: string[] = ["json", "code-snippets"];
public openTokenLink: boolean = true;
public useCliBaseInstallation: boolean = true;
public lastUpload: Date = null;
public lastDownload: Date = null;
public host: string = null;
public pathPrefix: string = null;
}
Loading

0 comments on commit e9b263d

Please sign in to comment.