### Publish to Specific Platforms (CLI) Source: https://context7.com/jinghaihan/vsxpub/llms.txt Control which platforms to publish to using `--include` or `--exclude` flags. This example skips marketplace registries. ```sh npx vsxpub --exclude vsce --exclude ovsx ``` ```sh npx vsxpub --include vsce ``` -------------------------------- ### Skip Dependency Packaging (CLI) Source: https://context7.com/jinghaihan/vsxpub/llms.txt Prevent `vsxpub` from installing dependencies during the packaging process. Use when dependencies are already managed or not required in the package. ```sh npx vsxpub --no-dependencies ``` -------------------------------- ### GitHub Actions Workflow for Extension Publishing Source: https://context7.com/jinghaihan/vsxpub/llms.txt A GitHub Actions workflow that automates the extension publishing process on tag pushes. It checks out code, sets up Node.js and pnpm, installs dependencies, generates a changelog, builds the .vsix package, and publishes to VS Code Marketplace, OpenVSX, and GitHub Releases. ```yaml # .github/workflows/publish.yml name: Publish Extension permissions: contents: write on: push: tags: - 'v*' jobs: release: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 with: fetch-depth: 0 - name: Set Node.js uses: actions/setup-node@v4 with: node-version: lts/* - name: Install pnpm uses: pnpm/action-setup@v3 - run: pnpm install # Create GitHub Release page with auto-generated changelog - run: npx changelogithub env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Build the .vsix package - run: npx vsce package --no-dependencies # Publish to VS Code Marketplace, OpenVSX, and upload to GitHub Release - name: Publish Extension run: npx vsxpub --no-dependencies env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} VSCE_PAT: ${{ secrets.VSCE_PAT }} OVSX_PAT: ${{ secrets.OVSX_PAT }} ``` -------------------------------- ### Run vsxpub CLI Source: https://github.com/jinghaihan/vsxpub/blob/main/README.md Execute the vsxpub CLI tool to publish extensions. Use --include or --exclude flags to control publishing to specific platforms. ```sh npx vsxpub ``` -------------------------------- ### Publish to All Platforms (CLI) Source: https://context7.com/jinghaihan/vsxpub/llms.txt Publish to VS Code Marketplace, OpenVSX, and GitHub Releases. Requires authentication tokens as environment variables. ```sh GITHUB_TOKEN=ghp_xxx VSCE_PAT=vsce_xxx OVSX_PAT=ovsx_xxx npx vsxpub ``` -------------------------------- ### Define Configuration (vsxpub.config.ts) Source: https://context7.com/jinghaihan/vsxpub/llms.txt Use `defineConfig` to create a typed configuration file for `vsxpub`. Options here are merged with CLI flags, with CLI flags taking precedence. ```typescript import { defineConfig } from 'vsxpub' export default defineConfig({ // Target only specific platforms by default include: ['vsce', 'ovsx'], // GitHub Enterprise support baseUrl: 'github.mycompany.com', baseUrlApi: 'api.github.mycompany.com', // Hardcode repo if git remote auto-detection fails repo: 'my-org/my-extension', // Retry up to 5 times with a 2-second delay between attempts retry: 5, retryDelay: 2000, // Skip packaging dependencies dependencies: false, }) ``` -------------------------------- ### Dry Run Mode (CLI) Source: https://context7.com/jinghaihan/vsxpub/llms.txt Preview all commands that would be executed without actually publishing. Useful for verifying configuration and intended actions. ```sh npx vsxpub --dry ``` -------------------------------- ### runWithRetry Utility Source: https://context7.com/jinghaihan/vsxpub/llms.txt The `runWithRetry` utility wraps each publish step with spinner feedback and automatic retries using `p-retry`. It returns `true` on success and `false` after all retries are exhausted. ```APIDOC ## `runWithRetry` — Retry Utility `runWithRetry` is the internal utility that wraps each publish step with spinner feedback and automatic retries using `p-retry`. It returns `true` on success and `false` after all retries are exhausted without throwing, allowing the CLI to aggregate failures and report them together. ```ts import { runWithRetry } from 'vsxpub/cli' import type { Options } from 'vsxpub' const config: Options = { retry: 3, retryDelay: 1000, dry: false, // ...other required fields } // Wrap any async operation with retry + spinner const success = await runWithRetry({ config, message: 'Uploading artifact...', successMessage: 'Artifact uploaded successfully.', errorMessage: 'Failed to upload artifact.', fn: async () => { // Throw to trigger a retry await uploadArtifact() }, // Optional: executed instead of fn when config.dry === true dryFn: () => { console.log('npx ovsx publish my-extension-1.0.0.vsix') }, }) if (!success) { console.error('Upload failed after all retries.') } ``` ``` -------------------------------- ### GitHub Actions Workflow for Publishing Source: https://github.com/jinghaihan/vsxpub/blob/main/README.md This YAML workflow automates the publishing of VS Code extensions. It checks out code, sets up Node.js and pnpm, generates a .vsix file, and publishes to all platforms using environment variables for authentication. ```yaml name: Publish Extension permissions: contents: write on: push: tags: - 'v*' jobs: release: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 with: fetch-depth: 0 - name: Set node uses: actions/setup-node@v4 with: node-version: lts/* - name: Install pnpm uses: pnpm/action-setup@v3 - run: pnpm install # Create release page with changelog - run: npx changelogithub env: GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} # Generate .vsix file - name: Generate .vsix file run: npx vsce package --no-dependencies # Publish extension to all platforms # Or skip CI publishing and run `npx vsxpub` locally without configuring secrets - name: Publish Extension run: npx vsxpub --no-dependencies env: GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} VSCE_PAT: ${{secrets.VSCE_PAT}} OVSX_PAT: ${{secrets.OVSX_PAT}} ``` -------------------------------- ### Specify Working Directory (CLI) Source: https://context7.com/jinghaihan/vsxpub/llms.txt Explicitly set the directory containing the extension's source code and `package.json`. ```sh npx vsxpub --cwd ./my-extension ``` -------------------------------- ### vsxpub Constants for Platforms and Default Options Source: https://context7.com/jinghaihan/vsxpub/llms.txt Exports constants `PLATFORM_CHOICES` listing supported publishing platforms and `DEFAULT_PUBLISH_OPTIONS` for default configuration values. These can be used to programmatically configure publishing targets. ```ts import { DEFAULT_PUBLISH_OPTIONS, PLATFORM_CHOICES } from 'vsxpub' console.log(PLATFORM_CHOICES) // ['git', 'vsce', 'ovsx'] as const console.log(DEFAULT_PUBLISH_OPTIONS) // { // baseUrl: 'github.com', // baseUrlApi: 'api.github.com', // include: ['git', 'vsce', 'ovsx'], // exclude: [], // retry: 3, // retryDelay: 1000, // } // Use to build typed platform arrays programmatically import type { Platform } from 'vsxpub' const targets: Platform[] = PLATFORM_CHOICES.filter(p => p !== 'ovsx') // ['git', 'vsce'] ``` -------------------------------- ### Git Utility Functions Source: https://context7.com/jinghaihan/vsxpub/llms.txt vsxpub exposes several Git helpers used internally to auto-detect repository metadata. They can be used independently in custom publish scripts. ```APIDOC ## Git Utility Functions vsxpub exposes several Git helpers used internally to auto-detect repository metadata. They can be used independently in custom publish scripts. ```ts import { getGitHubRepo, getGitTag, getVersionByGitTag, readTokenFromGitHubCli, } from 'vsxpub/cli' // Detect GitHub repo (owner/name) from git remote.origin.url const repo = await getGitHubRepo('github.com') console.log(repo) // 'my-org/my-extension' // Get git tag pointing at HEAD (or from GITHUB_REF in CI) const tag = await getGitTag() console.log(tag) // 'v1.4.2' // Strip leading 'v' from tag to get a plain semver string const version = await getVersionByGitTag() console.log(version) // '1.4.2' // Read a GitHub token from the GitHub CLI (`gh auth token`) const token = await readTokenFromGitHubCli() console.log(token) // 'ghp_xxxxxxxxxxxx' ``` ``` -------------------------------- ### Constants: PLATFORM_CHOICES and DEFAULT_PUBLISH_OPTIONS Source: https://context7.com/jinghaihan/vsxpub/llms.txt These exported constants define the supported platforms and the default configuration values applied before any user options are merged. ```APIDOC ## `PLATFORM_CHOICES` and `DEFAULT_PUBLISH_OPTIONS` — Constants These exported constants define the supported platforms and the default configuration values applied before any user options are merged. ```ts import { DEFAULT_PUBLISH_OPTIONS, PLATFORM_CHOICES } from 'vsxpub' console.log(PLATFORM_CHOICES) // ['git', 'vsce', 'ovsx'] as const console.log(DEFAULT_PUBLISH_OPTIONS) // { // baseUrl: 'github.com', // baseUrlApi: 'api.github.com', // include: ['git', 'vsce', 'ovsx'], // exclude: [], // retry: 3, // retryDelay: 1000, // } // Use to build typed platform arrays programmatically import type { Platform } from 'vsxpub' const targets: Platform[] = PLATFORM_CHOICES.filter(p => p !== 'ovsx') // ['git', 'vsce'] ``` ``` -------------------------------- ### Custom Retry Settings (CLI) Source: https://context7.com/jinghaihan/vsxpub/llms.txt Configure the number of retry attempts and the delay between retries in milliseconds. ```sh npx vsxpub --retry 5 --retry-delay 2000 ``` -------------------------------- ### Override Extension Metadata (CLI) Source: https://context7.com/jinghaihan/vsxpub/llms.txt Manually specify the extension name and version, overriding values from `package.json`. ```sh npx vsxpub --name my-extension --version 1.2.3 ``` -------------------------------- ### Programmatic Configuration Resolution (Node.js) Source: https://context7.com/jinghaihan/vsxpub/llms.txt Use `resolveConfig` to programmatically merge configuration from various sources (config file, CLI options, environment variables) into a single options object. It auto-detects extension metadata from `package.json` and git. ```typescript import { resolveConfig } from 'vsxpub/cli' const config = await resolveConfig({ cwd: '/path/to/my-extension', dry: true, exclude: ['ovsx'], }) console.log(config) // { // cwd: '/path/to/my-extension', // name: 'my-extension', // from package.json // version: '1.4.2', // from package.json or git tag // repo: 'my-org/my-extension', // from git remote.origin.url // tag: 'v1.4.2', // from git tag or GITHUB_REF env // include: ['git', 'vsce'], // 'ovsx' excluded // exclude: ['ovsx'], // retry: 3, // retryDelay: 1000, // githubToken: 'ghp_...', // from GITHUB_TOKEN or `gh auth token` // vscePat: 'vsce_...', // from VSCE_PAT // ovsxPat: '', // dry: true, // dependencies: true, // baseUrl: 'github.com', // baseUrlApi: 'api.github.com', // } ``` -------------------------------- ### Git Utility Functions for Metadata Detection Source: https://context7.com/jinghaihan/vsxpub/llms.txt Provides functions to extract repository information like GitHub owner/name, Git tags, and version from tags. It can also read GitHub tokens from the CLI. Ensure Git is configured correctly for these functions to work. ```ts import { getGitHubRepo, getGitTag, getVersionByGitTag, readTokenFromGitHubCli, } from 'vsxpub/cli' // Detect GitHub repo (owner/name) from git remote.origin.url const repo = await getGitHubRepo('github.com') console.log(repo) // 'my-org/my-extension' // Get git tag pointing at HEAD (or from GITHUB_REF in CI) const tag = await getGitTag() console.log(tag) // 'v1.4.2' // Strip leading 'v' from tag to get a plain semver string const version = await getVersionByGitTag() console.log(version) // '1.4.2' // Read a GitHub token from the GitHub CLI (`gh auth token`) const token = await readTokenFromGitHubCli() console.log(token) // 'ghp_xxxxxxxxxxxx' ``` -------------------------------- ### Run Async Operation with Retry and Spinner Source: https://context7.com/jinghaihan/vsxpub/llms.txt Wraps an asynchronous operation with automatic retries and spinner feedback. Configure retry count and delay via the `config` object. The `dryFn` option can be used for dry runs. ```ts import { runWithRetry } from 'vsxpub/cli' import type { Options } from 'vsxpub' const config: Options = { retry: 3, retryDelay: 1000, dry: false, // ...other required fields } // Wrap any async operation with retry + spinner const success = await runWithRetry({ config, message: 'Uploading artifact...', successMessage: 'Artifact uploaded successfully.', errorMessage: 'Failed to upload artifact.', fn: async () => { // Throw to trigger a retry await uploadArtifact() }, // Optional: executed instead of fn when config.dry === true dryFn: () => { console.log('npx ovsx publish my-extension-1.0.0.vsix') }, }) if (!success) { console.error('Upload failed after all retries.') } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.