0.5.0 • Published 8 months ago

vscode-ext-gen v0.5.0

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

vscode-ext-gen

npm version npm downloads bundle JSDocs License

Generate TypeScript meta info and Markdown tables for VS Code extension from package.json

Usage

npx vscode-ext-gen

Under the VS Code extension project root

Continuous Update

We recommend using the Run on Save extension with the following config in your .vscode/settings.json to always generate the meta file on save:

{
  "emeraldwalk.runonsave": {
    "commands": [
      {
        "match": "package.json",
        "isAsync": true,
        "cmd": "npm run update"
      }
    ]
  }
}

Examples

Generates src/generated-meta.ts file with the following content which syncs with your package.json:

export namespace ExtensionMeta {
  // Meta info
  export const publisher = 'antfu'
  export const name = 'iconify'
  export const version = '0.8.1'
  export const displayName = 'Iconify IntelliSense'
  export const description = 'Intelligent Iconify previewing and searching for VS Code'
  export const extensionId = `${publisher}.${name}`

  /**
   * Type union of all commands
   */
  export type CommandKey =
    | 'iconify.toggle-annotations'
    | 'iconify.clear-cache'
    // ...

  /**
   * Commands map registed by `antfu.iconify`
   */
  export const commands = {
    /**
     * Toggle Annotations
     * @value `iconify.toggle-annotations`
     */
    toggleAnnotations: 'iconify.toggle-annotations',
    // ...
  } satisfies Record<string, CommandId>

  /**
   * Type union of all configs
   */
  export type ConfigKey =
    | 'iconify.annotations'
    | 'iconify.position'
    // ...

  export interface ConfigKeyTypeMap {
    'iconify.annotations': boolean
    'iconify.position': ('before' | 'after')
    // ...
  }

  export interface ConfigMeta<T extends keyof ConfigKeyTypeMap> {
    key: T
    default: ConfigKeyTypeMap[T]
  }

  /**
   * Configs map registed by `antfu.iconify`
   */
  export const configs = {
    /**
     * Enabled Iconify inline annotations
     * @key `iconify.annotations`
     * @default `true`
     * @type `boolean`
     */
    annotations: {
      key: 'iconify.annotations',
      default: true,
    } as ConfigMeta<'iconify.annotations'>,
    /**
     * Position the icon before or after the icon name
     * @key `iconify.position`
     * @default `"before"`
     * @type `string`
     */
    position: {
      key: 'iconify.position',
      default: 'before',
    } as ConfigMeta<'iconify.position'>,

    // ...
  }
}

export default ExtensionMeta

On usage:

import { commands, workspace } from 'vscode'
import * as meta from './generated-meta'

export function activate() {
  console.log(meta.displayName, meta.extensionId)

  const config = workspace
    .getConfiguration()
    .get(meta.configs.position.key, meta.configs.position.default)

  commands.registerCommand(meta.commands.toggleAnnontations, () => {
    // ...
  })
}

For a full example, check this file

Generate Docs

Add comments <!-- commands --> and <!-- configs --> as the slots in your README.md:

# Your Extension

## Commands

<!-- commands -->
<!-- commands -->

## Configurations

<!-- configs -->
<!-- configs -->

They will be replaced with the generated tables when you run npx vscode-ext-gen.

Sponsors

License

MIT License © 2023-PRESENT Anthony Fu

0.5.0

8 months ago

0.4.4

8 months ago

0.4.3

10 months ago

0.4.2

10 months ago

0.4.1

10 months ago

0.4.0

10 months ago

0.3.7

10 months ago

0.3.6

10 months ago

0.3.4

10 months ago

0.3.3

11 months ago

0.3.2

11 months ago

0.3.1

11 months ago

0.3.0

11 months ago

0.2.0

11 months ago

0.1.0

11 months ago

0.0.0

11 months ago