# Wix Code Types Generator

This package includes scripts that generate Typescript declarations for use in wix-code's auto-completion.

Scripts:
- `full-wix-code-types`: generates a single JSON file with all the wix-code Typescript declarations for runtime consumption. E.g. `$w` definitions, The `@types/node` package for backend code, `ES2020` declarations, various `@wix` module declarations etc.
- `generate-model-packages-dts`: generates `.d.ts` files for each `@wix` module from the _`auto-velo`_ flow
  - Creates declarations for the 3 contexts (backend, public, page) via `index.d.ts` files using [triple slash directives](https://www.typescriptlang.org/docs/handbook/triple-slash-directives.html).
  - The output is merged into `fullCorvidTypes.json`.
- `generate-model-docworks-dts`: generates `.d.ts` files for each `@wix` module from the _`docworks`_ flow
  - The source of the script are JSDocs from [`@wix/wix-code-docs`](https://github.com/wix/wix-code-docs) repo.
  - Uses [docworks](https://github.com/wix-private/corvid-docworks).
- `components-handlers`: generates a JSON file with components event handlers data
- `wix-module-list`: generates a JSON file that includes all wix-modules names
- Various ast-patches: post processing of types that orginally were generated by docworks

## Build Script

The build scripts runs the scripts in the following order.
```
"build": "
  npm run generate-model-docworks-dts &&
  npm run generate-model-packages-dts &&
  npm run patch-declarations &&
  npm run generate-full-wix-code-types &&
  npm run generate-module-list &&
  npm run generate-components-data &&
  npm run typescript
",
```

The output is eventually:
```
dist
├── jsons
│  ├── eventHandlers.json
│  ├── fullWixCodeTypes.json
│  └── wixModules.json
└── types
   ├── backend
   │  ├── $w.d.ts
   │  ├── docworks-packages.d.ts
   │  ├── index.d.ts
   │  ├── wix-alarm-backend.d.ts
   │  ├── wix-core-services-dev.d.ts
   │  ├── ...
   ├── common
   │  ├── $w.d.ts
   │  ├── anyProperties.d.ts
   │  ├── docworks-packages.d.ts
   │  ├── emptyBuffer.d.ts
   │  ├── wix-animations.d.ts
   │  ├── ...
   ├── page
   │  ├── $w.d.ts
   │  ├── docworks-packages.d.ts
   │  ├── index.d.ts
   │  └── wix-packages.d.ts
   └── public
      ├── $w.d.ts
      ├── docworks-packages.d.ts
      ├── index.d.ts
      └── wix-packages.d.ts
```

## Getting Started

```shell
yarn install
yarn build
```

## Release Process
- `wix-code-types` is **updated automatically** by [@wix/wix-code-types-service](https://github.com/wix-private/wix-code-devex/tree/master/serverless/wix-code-types-service) which opens PRs and lands them once they pass CI.
- On every master change (landed PR), Falcon bumps the patch version on NPM
- If you want to break the contract between `wix-code-types` and `wix-code-editor-types` you will need to manually bump the major version
  - By breaking the contract we mean modifying the generated JSONs structure in a way that the consumers can't handle
  - To do this, manually change the `package.json` version field to next major or run `npm version major`.
- Falcon will pick this up and release the new major version

## Override wix-code-types

`wix-code-types` can be overridden for dev needs. To do this, simply use the query parameter *wix-code-types-override*. Note that `wix-code-editor-types` looks for the Json files in the following relative paths:

- **<your-override-url>**dist/jsons/fullWixCodeTypes.beta.json
- **<your-override-url>**dist/jsons/componentsData.json
- **<your-override-url>**dist/jsons/wixModules.beta.json

### Using Local Build of wix-code-types

To make it easier, if you are interested in using a local build of wix-code-types, just run the following command from your local wix-code-types package:

`yarn serve`

Then, use this query parameter:

`&wix-code-types-override=http://localhost:8080/`
