Allow users to specify whether to install Node.js template (#329)

* Leverage npx to do 'npm install' w/o sudo

* Allow install latest and specific Node.js template

* Allow use specify whether to install Node.js template

* Add space-within-parens rule to tslint
This commit is contained in:
Ray Fang 2018-12-20 16:28:54 +08:00 коммит произвёл GitHub
Родитель 8138b45ed3
Коммит 44346b1232
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
6 изменённых файлов: 61 добавлений и 23 удалений

Просмотреть файл

@ -204,17 +204,17 @@
"azure-iot-edge.version.cmodule": {
"type": "string",
"default": "master",
"description": "Set the C module template version, which will be refernced during scaffolding C module."
"description": "Set the C module template version, which will be referenced during scaffolding C module."
},
"azure-iot-edge.version.pythonmodule": {
"type": "string",
"default": "master",
"description": "Set the Python module template version, which will be refernced during scaffolding Python module."
"description": "Set the Python module template version, which will be referenced during scaffolding Python module."
},
"azure-iot-edge.version.csharpmodule": {
"type": "string",
"default": null,
"description": "Set the C# module template version, which will be refernced during scaffolding C# module."
"description": "Set the C# module template version, which will be referenced during scaffolding C# module."
},
"azure-iot-edge.templateInstall.csharpmodule": {
"type": "boolean",
@ -226,15 +226,25 @@
"default": true,
"description": "Switch to install C# function module template before scaffolding. Default is true."
},
"azure-iot-edge.templateInstall.nodemodule": {
"type": "boolean",
"default": true,
"description": "Switch to install Node.js module template before scaffolding. Default is true."
},
"azure-iot-edge.version.csfunctionmodule": {
"type": "string",
"default": null,
"description": "Set the C# fuction module template version, which will be refernced during scaffolding C# function module."
"description": "Set the C# function module template version, which will be referenced during scaffolding C# function module."
},
"azure-iot-edge.version.javamodule": {
"type": "string",
"default": null,
"description": "Set the Java module template version, which will be refernced during scaffolding Java module."
"description": "Set the Java module template version, which will be referenced during scaffolding Java module."
},
"azure-iot-edge.version.nodemodule": {
"type": "string",
"default": null,
"description": "Set the Node.js module template version, which will be referenced during scaffolding Node.js module."
},
"azure-iot-edge.terminalRoot": {
"type": "string",

Просмотреть файл

@ -134,6 +134,7 @@ export class Constants {
public static installCSharpModule = "templateInstall.csharpmodule";
public static installCSFunctionModule = "templateInstall.csfunctionmodule";
public static installNodeModule = "templateInstall.nodemodule";
public static edgeAgentVerPlaceHolder = "VERSION.edgeAgent";
public static edgeHubVerPlaceHolder = "VERSION.edgeHub";

Просмотреть файл

@ -8,7 +8,7 @@ import { Constants } from "./constants";
export class Executor {
public static runInTerminal(command: string, terminal: string = Constants.edgeDisplayName): void {
if (this.terminals[terminal] === undefined ) {
if (this.terminals[terminal] === undefined) {
this.terminals[terminal] = vscode.window.createTerminal(terminal);
}
this.terminals[terminal].show();

Просмотреть файл

@ -18,6 +18,10 @@ export class Versions {
return Versions.getValue(Constants.installCSFunctionModule, true) as boolean;
}
public static installNodeTemplate(): boolean {
return Versions.getValue(Constants.installNodeModule, true) as boolean;
}
public static csTemplateVersion(): string {
return Versions.getValue(Constants.versionCSharpModule) as string;
}
@ -38,6 +42,10 @@ export class Versions {
return Versions.getValue(Constants.versionJavaModule) as string;
}
public static nodeTemplateVersion(): string {
return Versions.getValue(Constants.versionNodeModule) as string;
}
private static edgeAgentVersion(): string {
return Versions.getValue(Constants.versionEdgeAgent) as string;
}

Просмотреть файл

@ -179,7 +179,7 @@ export class EdgeManager {
public async setupIotedgehubdev(deviceItem: IDeviceItem, outputChannel: vscode.OutputChannel) {
deviceItem = await Utility.getInputDevice(deviceItem, outputChannel);
if (deviceItem) {
Executor.runInTerminal(Utility.adjustTerminalCommand(`iotedgehubdev setup -c "${deviceItem.connectionString}"`));
Executor.runInTerminal(Utility.adjustTerminalCommand(`iotedgehubdev setup -c "${deviceItem.connectionString}"`));
}
}
@ -214,20 +214,23 @@ export class EdgeManager {
break;
case Constants.LANGUAGE_NODE:
debugCreateOptions = {
ExposedPorts: { "9229/tcp": {}},
HostConfig: {PortBindings: {"9229/tcp": [{HostPort: "9229"}]}}};
ExposedPorts: { "9229/tcp": {} },
HostConfig: { PortBindings: { "9229/tcp": [{ HostPort: "9229" }] } },
};
break;
case Constants.LANGUAGE_C:
debugCreateOptions = {HostConfig: {Privileged: true}};
debugCreateOptions = { HostConfig: { Privileged: true } };
break;
case Constants.LANGUAGE_JAVA:
debugCreateOptions = {
HostConfig: {PortBindings: {"5005/tcp": [{HostPort: "5005"}]}}};
HostConfig: { PortBindings: { "5005/tcp": [{ HostPort: "5005" }] } },
};
break;
case Constants.LANGUAGE_PYTHON:
debugCreateOptions = {
ExposedPorts: {"5678/tcp": {}},
HostConfig: {PortBindings: {"5678/tcp": [{HostPort: "5678"}]}}};
ExposedPorts: { "5678/tcp": {} },
HostConfig: { PortBindings: { "5678/tcp": [{ HostPort: "5678" }] } },
};
break;
default:
break;
@ -328,10 +331,10 @@ export class EdgeManager {
const needUpdateRegistry: boolean = template !== Constants.STREAM_ANALYTICS;
const {usernameEnv, passwordEnv} = await this.addModuleToDeploymentTemplate(templateJson, templateFile, envFilePath, moduleInfo, needUpdateRegistry, isNewSolution);
const { usernameEnv, passwordEnv } = await this.addModuleToDeploymentTemplate(templateJson, templateFile, envFilePath, moduleInfo, needUpdateRegistry, isNewSolution);
const templateDebugFile = path.join(slnPath, Constants.deploymentDebugTemplate);
const debugTemplateEnv = {usernameEnv: undefined, passwordEnv: undefined};
const debugTemplateEnv = { usernameEnv: undefined, passwordEnv: undefined };
let debugExist = false;
if (await fse.pathExists(templateDebugFile)) {
debugExist = true;
@ -353,7 +356,7 @@ export class EdgeManager {
private async addModuleToDeploymentTemplate(templateJson: any, templateFile: string, envFilePath: string,
moduleInfo: ModuleInfo, updateRegistry: boolean,
isNewSolution: boolean, isDebug: boolean = false): Promise<{usernameEnv: string, passwordEnv: string}> {
isNewSolution: boolean, isDebug: boolean = false): Promise<{ usernameEnv: string, passwordEnv: string }> {
const modules = templateJson.modulesContent.$edgeAgent["properties.desired"].modules;
const routes = templateJson.modulesContent.$edgeHub["properties.desired"].routes;
const runtimeSettings = templateJson.modulesContent.$edgeAgent["properties.desired"].runtime.settings;
@ -369,7 +372,7 @@ export class EdgeManager {
runtimeSettings.registryCredentials = registries;
}
let result = {registries: {}, usernameEnv: undefined, passwordEnv: undefined};
let result = { registries: {}, usernameEnv: undefined, passwordEnv: undefined };
if (updateRegistry) {
result = await this.updateRegistrySettings(address, registries, envFilePath);
}
@ -382,10 +385,10 @@ export class EdgeManager {
status: "running",
restartPolicy: "always",
settings: {
image: imageName,
createOptions,
image: imageName,
createOptions,
},
};
};
modules[moduleInfo.moduleName] = newModuleSection;
const newModuleToUpstream = `${moduleInfo.moduleName}ToIoTHub`;
routes[newModuleToUpstream] = `FROM /messages/modules/${moduleInfo.moduleName}/outputs/* INTO $upstream`;
@ -432,7 +435,22 @@ export class EdgeManager {
`--no-input ${gitHubSource} module_name=${name} image_repository=${repositoryName} --checkout ${branch}`);
break;
case Constants.LANGUAGE_NODE:
await Executor.executeCMD(outputChannel, "yo", { cwd: `${parent}`, shell: true }, `azure-iot-edge-module -n "${name}" -r ${repositoryName}`);
if (Versions.installNodeTemplate()) {
// Have to install Node.js module template and Yeoman in the same space (either global or npx environment)
// https://github.com/Microsoft/vscode-azure-iot-edge/issues/326
const nodeModuleVersion = Versions.nodeTemplateVersion();
const nodeVersionConfig = nodeModuleVersion != null ? `@${nodeModuleVersion}` : "";
if (os.platform() === "win32") {
await Executor.executeCMD(outputChannel, "npm", { cwd: `${parent}`, shell: true },
`i -g generator-azure-iot-edge-module${nodeVersionConfig}`);
await Executor.executeCMD(outputChannel, "yo", { cwd: `${parent}`, shell: true }, `azure-iot-edge-module -n "${name}" -r ${repositoryName}`);
} else {
await Executor.executeCMD(outputChannel, "npx", { cwd: `${parent}`, shell: true },
`-p yo -p generator-azure-iot-edge-module${nodeVersionConfig} -- yo azure-iot-edge-module -n "${name}" -r ${repositoryName}`);
}
} else {
await Executor.executeCMD(outputChannel, "yo", { cwd: `${parent}`, shell: true }, `azure-iot-edge-module -n "${name}" -r ${repositoryName}`);
}
break;
case Constants.LANGUAGE_C:
await new Promise((resolve, reject) => {
@ -778,7 +796,7 @@ export class EdgeManager {
if (!templatePick) {
throw new UserCancelledError();
}
TelemetryClient.sendEvent( `${Constants.addModuleEvent}.selectModuleTemplate`, {
TelemetryClient.sendEvent(`${Constants.addModuleEvent}.selectModuleTemplate`, {
template: templatePick.label,
});
return templatePick.label;

Просмотреть файл

@ -13,6 +13,7 @@
200
],
"no-empty": false,
"object-literal-sort-keys": false
"object-literal-sort-keys": false,
"space-within-parens": true
}
}