UNPKG

@auto-it/vscode

Version:

Publish an vscode extension

106 lines 4.07 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const core_1 = require("@auto-it/core"); const t = tslib_1.__importStar(require("io-ts")); const semver_1 = require("semver"); const vsce = tslib_1.__importStar(require("vsce")); const package_json_utils_1 = require("@auto-it/package-json-utils"); /** Get the current version from the package.json */ const getVersion = async () => { const { version } = await package_json_utils_1.loadPackageJson(); if (version) { return version; } return "0.0.0"; }; const pluginOptions = t.partial({ /** Prepend all relative links in README.md with this url */ baseContentUrl: t.string, /** Prepend all relative image links in README.md with this url */ baseImagesUrl: t.string, }); /** Publish an vscode extension */ class VscodePlugin { /** Initialize the plugin with it's options */ constructor(options = {}) { /** The name of the plugin */ this.name = "vscode"; this.options = options; } /** Tap into auto plugin points. */ apply(auto) { const isQuiet = auto.logger.logLevel === "quiet"; const isVerbose = auto.logger.logLevel === "verbose" || auto.logger.logLevel === "veryVerbose"; const verboseArgs = isQuiet ? ["--loglevel", "silent"] : isVerbose ? ["--loglevel", "silly"] : []; auto.hooks.validateConfig.tapPromise(this.name, async (name, options) => { // If it's a string thats valid config if (name === this.name && typeof options !== "string") { return core_1.validatePluginConfiguration(this.name, pluginOptions, options); } }); auto.hooks.getAuthor.tapPromise(this.name, async () => { auto.logger.verbose.info(`${this.name}: Getting repo information from package.json`); const author = await package_json_utils_1.getAuthor(); if (author) { return author; } }); auto.hooks.getRepository.tapPromise(this.name, async () => { auto.logger.verbose.info(`${this.name}: getting repo information from package.json`); const repo = await package_json_utils_1.getRepo(); if (repo) { return repo; } }); auto.hooks.getPreviousVersion.tapPromise(this.name, async () => { return auto.prefixRelease(await getVersion()); }); auto.hooks.version.tapPromise(this.name, async ({ bump, dryRun, quiet }) => { const newVersion = semver_1.inc(await getVersion(), bump); if (dryRun) { if (quiet) { console.log(newVersion); } else { auto.logger.log.info(`Would have published: ${newVersion}`); } return; } await core_1.execPromise("npm", [ "version", newVersion, "--no-commit-hooks", "-m", '"Bump version to: %s [skip ci]"', ...verboseArgs, ]); auto.logger.verbose.info("Successfully versioned repo"); }); auto.hooks.publish.tapPromise(this.name, async () => { auto.logger.log.info("Pushing new tag to GitHub"); const version = await getVersion(); await core_1.execPromise("git", [ "push", "--follow-tags", "--set-upstream", auto.remote, auto.baseBranch, ]); await vsce.publish({ // @ts-ignore version, pat: process.env.VSCE_TOKEN, baseContentUrl: this.options.baseContentUrl, baseImagesUrl: this.options.baseImagesUrl, }); }); } } exports.default = VscodePlugin; //# sourceMappingURL=index.js.map