# vscode-extensions-json-generator

> Define `Config` interface, and add documentation with annotations for additional data for the configuration

Latest version **0.2.2** (published 2024-09-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install vscode-extensions-json-generator
pnpm add vscode-extensions-json-generator
yarn add vscode-extensions-json-generator
bun add vscode-extensions-json-generator
```

Provides the command `update-package-json`.

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; large bundle; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.2 |
| Published | 2024-09-09 |
| First published | 2021-09-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Node | >=14 |
| Dependencies | 6 |
| Unpacked size | 20.7 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | elazarcoh |
| Maintainers | elazarcoh |

## Links

- npm: https://www.npmjs.com/package/vscode-extensions-json-generator
- Repository: https://github.com/elazarcoh/vscode-extension-packagejson-generator
- Homepage: https://github.com/elazarcoh/vscode-extension-packagejson-generator#readme
- Issues: https://github.com/elazarcoh/vscode-extension-packagejson-generator/issues
- npm.io page: https://npm.io/package/vscode-extensions-json-generator

## Dependencies (6)

- [ajv](https://npm.io/package/ajv.md) ^8.6.3
- [json5](https://npm.io/package/json5.md) ^2.2.2
- [commander](https://npm.io/package/commander.md) ^8.1.0
- [deep-equal](https://npm.io/package/deep-equal.md) ^2.0.5
- [better-ajv-errors](https://npm.io/package/better-ajv-errors.md) ^0.8.2
- [ts-json-schema-generator](https://npm.io/package/ts-json-schema-generator.md) ^2.3.0

## Recent versions

- 0.2.2 (latest) — 2024-09-09
- 0.2.1 — 2024-09-08
- 0.1.5 — 2021-12-10
- 0.1.4 — 2021-12-08
- 0.1.3 — 2021-11-09
- 0.1.2 — 2021-11-09
- 0.1.1 — 2021-09-27
- 0.1.0 — 2021-09-27

## README

# VSCode-extensions package.json generator

## Usage

### In code

Define `Config` interface, and add documentation with annotations for additional data for the configuration

```ts
export interface Config {
  /**
   * @default true
   * @description description of boolConfig
   */
  boolConfig: boolean;

  /**
   * @enumDescriptions [
        "Foo description"
        "Bar description"]
   * @default "Bar"
   * @description enumConfig description
   */
  enumConfig: 'Foo' | 'Bar';
}
```

### As cli tool

```bash
update-package-json ts2pjs 'vscode-extension-config.json'
```

The input JSON file may look like this:

```json
{
  "prefix": "myExt",
  "configurations": [
    {
      "filePath": "./src/config.ts",
      "name": "Config"
    }
  ],
  "targetFile": "package.json",
  "tsconfig": "tsconfig.json"
}
```

### As a Webpack plugin

```js
const {
  VSCodeExtensionsPackageJsonGenerator,
} = require('vscode-extensions-json-generator/webpack');

{
  // ...
  plugins: [
    new VSCodeExtensionsPackageJsonGenerator('vscode-extension-config.json'),
  ];
}
```

or with object as the config

```js
{
  // ...
  plugins: [
    new VSCodeExtensionsPackageJsonGenerator({
      prefix: 'myExt',
      configurations: [
        {
          filePath: './src/config.ts',
          name: 'Config',
        },
      ],
      targetFile: 'package.json',
      tsconfig: 'tsconfig.json',
    }),
  ];
}
```

### Bonus - accessing configuration from code utility

```ts
import { configUtils } from 'vscode-extensions-json-generator/utils';

export const getConfiguration =
  configUtils.ConfigurationGetter<Config>('myExt');

// use it to get configuration with auto-complete and automatically type inference
const e = getConfiguration('enumConfig');
```

or as a class
```ts
import { configUtils } from 'vscode-extensions-json-generator/utils';

export const configurations = new configUtils.VSCodeConfigurations<Config>('myExt');

// get
const e = configurations.get('enumConfig');

// update
configurations.update('enumConfig', 'Foo');
```

## Config options

```jsonc
{
  "configurations": [
    {
      "filePath": "./src/config1.json",
      "name": "Config1"
    },
    {
      "filePath": "./src/config2.json",
      "name": "Config2"
    }
    // ...
  ],
  "prefix": "myExt",
  // tags that aren't being used in json schema by default.
  "tags": [
    "markdownDescription",
    "scope",
    "patternErrorMessage",
    "deprecationMessage",
    "enumDescriptions",
    "deprecated"
    // ...
  ],
  "targetFile": "package.json",
  "tsconfig": "tsconfig.ts",
  "sort": true
}
```

## Convert from existing `package.json` to TypeScript interface

Use the cli tool with `pjs2ts`.

```bash
update-package-json pjs2ts 'package.json' -p conf --add-config-class
```

Options:

```bash
Convert the package.json `contributes.configurations` to a TypeScript file     

Arguments:
  inputFile                   input package.json file (default: "package.json")

Options:
  -p, --prefix [prefix]       prefix for the configuration
  -o, --output [outputFile]   output file (default: "config.ts")
  --add-config-class
  --config-class-name [name]  name of the configuration class (default: "Configuration")
  -h, --help                  display help for command
```

---
_Source: https://npm.io/package/vscode-extensions-json-generator · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
