UNPKG

@azure-tools/extension

Version:

Yarn-Based extension aquisition (for Azure Open Source Projects)

79 lines 2.61 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Extension = void 0; const fs_1 = require("fs"); const path_1 = require("path"); const async_io_1 = require("@azure-tools/async-io"); const package_1 = require("./package"); /** * Extension is an installed Package * @extends Package * */ class Extension extends package_1.Package { /* @internal */ constructor(pkg, installationPath) { super(pkg.resolvedInfo, pkg.packageMetadata, pkg.extensionManager); this.installationPath = installationPath; } /** * The installed location of the package. */ get location() { return (0, path_1.normalize)(`${this.installationPath}/${this.id.replace("/", "_")}`); } /** * The path to the installed npm package (internal to 'location') */ get modulePath() { return (0, path_1.normalize)(`${this.location}/node_modules/${this.name}`); } /** * the path to the package.json file for the npm packge. */ get packageJsonPath() { return (0, path_1.normalize)(`${this.modulePath}/package.json`); } /** * the path to the readme.md configuration file for the extension. */ get configurationPath() { return (async () => { const items = await (0, async_io_1.readdir)(this.modulePath); for (const each of items) { if (/^readme.md$/i.exec(each)) { const fullPath = (0, path_1.normalize)(`${this.modulePath}/${each}`); if (await (0, async_io_1.isFile)(fullPath)) { return fullPath; } } } return ""; })(); } /** the loaded package.json information */ get definition() { const content = (0, fs_1.readFileSync)(this.packageJsonPath).toString(); try { return JSON.parse(content); } catch (e) { throw new Error(`Failed to parse package definition at '${this.packageJsonPath}'. ${e}`); } } get configuration() { return (async () => { const cfgPath = await this.configurationPath; if (cfgPath) { return (0, async_io_1.readFile)(cfgPath); } return ""; })(); } async remove() { return this.extensionManager.removeExtension(this); } async start(enableDebugger = false) { return this.extensionManager.start(this, enableDebugger); } } exports.Extension = Extension; //# sourceMappingURL=extension.js.map