1.6.1 • Published 16 days ago

@jdpnielsen/uda-to-typescript v1.6.1

Weekly downloads
-
License
MIT
Repository
github
Last release
16 days ago

uda-to-typescript

npm package Build Status Downloads Issues Commitizen Friendly Semantic Release

Command-line tool to convert Umbraco UDA files to Typescript types.

Install

npm install @jdpnielsen/uda-to-typescript

Quick Start

Usage: uda-to-typescript [options]

CLI to convert Umbraco UDA files to typescript definitions

Options:
  -V, --version          output the version number
  -c, --config <string>  Path for config file. Example: --config ./udaconvert.config.ts
  -i, --input <string>   Glob pattern to match. Example: --input ./files/*.uda
  -o, --output <string>  Where to write output file. Example: --output ./file.ts
  -d, --debug            enables verbose logging (default: false)
  -h, --help             display help for command

Examples:

  $ uda-to-typescript --version
  1.0.0

Without config

  $ uda-to-typescript --input ../your-umbraco-project/src/UmbracoProject/umbraco/Deploy/Revision/*.uda --output ./umbraco-sdk/types.ts

With config

 $ uda-to-typescript
 # or
 $ uda-to-typescript --config ./udaconvert.config.ts

Note: uda-to-typescript uses cosmic-config to locate config files.

File udaconvert.config.ts

import { defineConfig } from '@jdpnielsen/uda-to-typescript';

export default defineConfig({
  input: './petstore.yaml',
  output: './src/petstore.ts',
});

Provide custom datatypes

import { factory } from 'typescript';
import { defineConfig, dataTypes, HandlerConfig } from '@jdpnielsen/uda-to-typescript';

export default defineConfig({
	input: '../umbraco-boilerplate/src/UmbracoProject/umbraco/Deploy/Revision/*.uda',
	output: './src/umbraco/output.ts',
	dataTypes: {
		...dataTypes, // Provide default types
		'Custom.StatementEditor': {
			editorAlias: 'Custom.StatementEditor',
			/**
			 * Used to create any shared setup for the propertyEditor
			 */
			init: () => {
				return 'export type Statement = "key" | "val";';
			},
			/**
			 * Used to generate any dataType specifc types
			 * @example ```ts
			 * type MetatitleTextboxType = {
			 * 	statement: Statement;
			 * 	prop: string;
			 * };
			 * ```
			 */
			build: (dataType) => {
				return `type ${pascalCase(dataType.Name)}Type = {
					statement: Statement;
					prop: ${dataType.DatabaseType === 1 ? 'string' : 'unknown'};
				}`;
			},
			/**
			 * Used to generate any usage specific type/reference
			 * @example ```ts
			 * export type Metadata = BaseDocumentType<'metadata', {
			 * 	meta_title?: MetatitleTextboxType;
			 * }>;
			 * ```
			 */
			reference: (dataType) => `${pascalCase(dataType.Name)}Type`,
		},
	},
});
1.6.1

16 days ago

2.2.3

16 days ago

2.2.1

2 months ago

2.2.0

2 months ago

2.2.2

2 months ago

2.1.0

2 months ago

2.0.1

2 months ago

1.6.0

2 months ago

2.0.0

2 months ago

1.5.0

4 months ago

1.4.0

5 months ago

1.3.0

6 months ago

1.2.1

6 months ago

1.2.0

6 months ago

1.1.0

6 months ago

1.0.2

7 months ago

1.0.1

7 months ago

1.0.0

7 months ago