Use git download instead of cookiecutter to add Python module (#333)

* Use git download instead of cookiecutter to add Python module

* Update RepositoryName in tmp folder

* Fix typo

* Fix typo
This commit is contained in:
Jun Han 2019-01-02 15:09:42 +08:00 коммит произвёл GitHub
Родитель 02be095ebb
Коммит 2786557d7d
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
3 изменённых файлов: 57 добавлений и 13 удалений

21
package-lock.json сгенерированный
Просмотреть файл

@ -130,6 +130,12 @@
"integrity": "sha512-7NQmHra/JILCd1QqpSzl8+mJRc8ZHz3uDm8YV1Ks9IhK0epEiTw8aIErbvH9PI+6XbqhyIQy3462nEsn7UVzjQ==",
"dev": true
},
"@types/tmp": {
"version": "0.0.33",
"resolved": "https://registry.npmjs.org/@types/tmp/-/tmp-0.0.33.tgz",
"integrity": "sha1-EHPEvIJHVK49EM+riKsCN7qWTk0=",
"dev": true
},
"@types/tough-cookie": {
"version": "2.3.4",
"resolved": "https://registry.npmjs.org/@types/tough-cookie/-/tough-cookie-2.3.4.tgz",
@ -2223,7 +2229,7 @@
},
"event-stream": {
"version": "3.3.4",
"resolved": "https://registry.npmjs.org/event-stream/-/event-stream-3.3.4.tgz",
"resolved": "http://registry.npmjs.org/event-stream/-/event-stream-3.3.4.tgz",
"integrity": "sha1-SrTJoPWlTbkzi0w02Gv86PSzVXE=",
"dev": true,
"requires": {
@ -5084,6 +5090,11 @@
"mem": "^4.0.0"
}
},
"os-tmpdir": {
"version": "1.0.2",
"resolved": "http://registry.npmjs.org/os-tmpdir/-/os-tmpdir-1.0.2.tgz",
"integrity": "sha1-u+Z0BseaqFxc/sdm/lc0VV36EnQ="
},
"p-defer": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/p-defer/-/p-defer-1.0.0.tgz",
@ -6731,6 +6742,14 @@
"setimmediate": "^1.0.4"
}
},
"tmp": {
"version": "0.0.33",
"resolved": "https://registry.npmjs.org/tmp/-/tmp-0.0.33.tgz",
"integrity": "sha512-jRCJlojKnZ3addtTOjdIqoRuPEKBvNXcGYqzO6zWZX8KfKEpnGY5jfggJQ3EjKuu8D4bJRr0y+cYJFmYbImXGw==",
"requires": {
"os-tmpdir": "~1.0.2"
}
},
"to-absolute-glob": {
"version": "0.1.1",
"resolved": "https://registry.npmjs.org/to-absolute-glob/-/to-absolute-glob-0.1.1.tgz",

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

@ -435,9 +435,10 @@
"@types/mocha": "^2.2.32",
"@types/node": "^6.0.40",
"@types/request-promise": "^4.1.41",
"@types/semver": "^5.5.0",
"@types/sinon": "^5.0.5",
"@types/strip-json-comments": "0.0.30",
"@types/semver": "^5.5.0",
"@types/tmp": "0.0.33",
"azure-arm-resource": "^3.1.1-preview",
"fail-on-errors-webpack-plugin": "^3.0.0",
"mocha": "^5.1.1",
@ -460,8 +461,9 @@
"jsonc-parser": "^1.0.1",
"request": "^2.88.0",
"request-promise": "^4.2.2",
"strip-json-comments": "^2.0.1",
"semver": "^5.6.0",
"strip-json-comments": "^2.0.1",
"tmp": "0.0.33",
"vscode-extension-telemetry": "0.0.18"
},
"extensionDependencies": [

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

@ -7,6 +7,7 @@ import * as fse from "fs-extra";
import * as os from "os";
import * as path from "path";
import * as stripJsonComments from "strip-json-comments";
import * as tmp from "tmp";
import * as vscode from "vscode";
import { Constants } from "../common/constants";
import { Executor } from "../common/executor";
@ -397,12 +398,30 @@ export class EdgeManager {
await Executor.executeCMD(outputChannel, "dotnet", { cwd: `${parent}`, shell: true }, `new aziotedgefunction -n "${name}" -r ${repositoryName}`);
break;
case Constants.LANGUAGE_PYTHON:
const gitHubSource = "https://github.com/Azure/cookiecutter-azure-iot-edge-module";
const branch = Versions.pythonTemplateVersion();
await Executor.executeCMD(outputChannel,
"cookiecutter",
{ cwd: `${parent}`, shell: true },
`--no-input ${gitHubSource} module_name=${name} image_repository=${repositoryName} --checkout ${branch}`);
await new Promise((resolve, reject) => {
tmp.dir({ unsafeCleanup: true }, (err, tmpDir, cleanupCallback) => {
if (err) {
reject(err);
} else {
const moduleContentDirName = "{{cookiecutter.module_name}}";
const moduleContentDir = path.join(tmpDir, moduleContentDirName);
download(`github:Azure/cookiecutter-azure-iot-edge-module#${Versions.pythonTemplateVersion()}`, tmpDir, async (downloadErr) => {
if (downloadErr) {
reject(downloadErr);
} else {
try {
await this.updateRepositoryName(tmpDir, moduleContentDirName, repositoryName);
await fse.move(moduleContentDir, path.join(parent, name));
resolve();
} catch (error) {
reject(error);
}
}
cleanupCallback();
});
}
});
});
break;
case Constants.LANGUAGE_NODE:
if (Versions.installNodeTemplate()) {
@ -432,10 +451,7 @@ export class EdgeManager {
}
});
});
const moduleFile = path.join(parent, name, Constants.moduleManifest);
const moduleJson = await fse.readJson(moduleFile);
moduleJson.image.repository = repositoryName;
await fse.writeFile(moduleFile, JSON.stringify(moduleJson, null, 2), { encoding: "utf8" });
await this.updateRepositoryName(parent, name, repositoryName);
break;
case Constants.LANGUAGE_JAVA:
const groupId = extraProps.get(Constants.groupId);
@ -468,6 +484,13 @@ export class EdgeManager {
}
}
private async updateRepositoryName(parent: string, name: string, repositoryName: string) {
const moduleFile = path.join(parent, name, Constants.moduleManifest);
const moduleJson = await fse.readJson(moduleFile);
moduleJson.image.repository = repositoryName;
await fse.writeFile(moduleFile, JSON.stringify(moduleJson, null, 2), { encoding: "utf8" });
}
private async validateInputName(name: string, parentPath?: string): Promise<string | undefined> {
if (!name) {
return "The name could not be empty";