typework
v0.1.1
Published
Manage And Vendor JSDoc Types. Import Typedefs Into Target Projects.
Downloads
28
Readme
typework
Typework is used to Manage And Vendor JSDoc Types. With the special /* typework */
keyword, JSDoc type declarations can be moved across JS files, and imported files in types (import('../types/context')
) will be copied across to the target project.
yarn add typework
Table Of Contents
CLI
The package works via a CLI by passing the configuration file to it.
typework example/config.json
The config must include 3 properties:
{
"entry": "@typedefs/goa",
"js": "compile/index.js",
"destination": "types"
}
- 🔖 entry This is where the types are coming form. This can be a separate package, e.g.,
@typedefs/goa
- 🎯 js The project source code into where to place the original types into.
- 📂 destination Whenever the types import other files with
import('../types/')
, the target files will be copied to this folder.
Upon run, the types' JSDoc declarations are copied from the entry into the source JS file, so that they become a native part of the project. All other files found under relative import paths, will be placed into the Destination folder.
The example below demonstrates, how types written for the Goa package and published as @typedefs/goa
, were imported into the Goa/Koa project, so that they can be distributed without having to install @typedefs/goa
from NPM as a production dependency. This is a strategy for distribution of JSDoc types.
export {}
/* typework */
/**
* @typedef {import('./vendor/cookies').Keygrip} Keygrip
* @typedef {import('./typedefs/application').Middleware} Middleware
* @typedef {import('./typedefs/application').Application} Application
* @typedef {import('./typedefs/context').KoaContext} Context
* @typedef {import('./typedefs/request').Request} Request
* @typedef {import('./typedefs/request').ContextDelegatedRequest} ContextDelegatedRequest
* @typedef {import('./typedefs/response').Response} Response
* @typedef {import('./typedefs/response').ContextDelegatedResponse} ContextDelegatedResponse
*/
const _Koa = require('./koa')
class Koa extends _Koa {
/**
* Initialize a new `Application`.
*/
constructor() {
super()
}
}
module.exports = Koa
/* typework */
/**
* @typedef {import('types/vendor/cookies').Keygrip} Keygrip
* @typedef {import('types/typedefs/application').Middleware} Middleware
* @typedef {import('types/typedefs/application').Application} Application
* @typedef {import('types/typedefs/context').KoaContext} Context
* @typedef {import('types/typedefs/request').Request} Request
* @typedef {import('types/typedefs/request').ContextDelegatedRequest} ContextDelegatedRequest
* @typedef {import('types/typedefs/response').Response} Response
* @typedef {import('types/typedefs/response').ContextDelegatedResponse} ContextDelegatedResponse
*/
example/types
├── typedefs
│ ├── application.js
│ ├── context.js
│ ├── request.js
│ └── response.js
└── vendor
├── accepts.js
└── cookies.js
Copyright
(c) Art Deco 2019