2021-03-22 00:46:32 +00:00
|
|
|
import {UniversalPath} from '@extollo/util'
|
|
|
|
|
2021-03-23 15:10:23 +00:00
|
|
|
/**
|
|
|
|
* Interface defining a template that can be generated using the TemplateDirective.
|
|
|
|
*/
|
2021-03-22 00:46:32 +00:00
|
|
|
export interface Template {
|
2021-03-23 15:10:23 +00:00
|
|
|
/**
|
|
|
|
* The name of the template as it will be specified from the command line.
|
|
|
|
*
|
|
|
|
* @example
|
|
|
|
* If this is `'mytemplate'`, then the template will be created with:
|
|
|
|
*
|
|
|
|
* ```shell
|
|
|
|
* ./ex new mytemplate some:path
|
|
|
|
* ```
|
|
|
|
*/
|
2021-03-22 00:46:32 +00:00
|
|
|
name: string,
|
2021-03-23 15:10:23 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The suffix of the file generated by this template.
|
|
|
|
* @example `.mytemplate.ts`
|
|
|
|
* @example `.controller.ts`
|
|
|
|
*/
|
2021-03-22 00:46:32 +00:00
|
|
|
fileSuffix: string,
|
2021-03-23 15:10:23 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Brief description of the template displayed on the --help page for the TemplateDirective.
|
|
|
|
* Should be brief (1 sentence).
|
|
|
|
*/
|
2021-03-22 00:46:32 +00:00
|
|
|
description: string,
|
2021-03-23 15:10:23 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Array of path-strings that are resolved relative to the base `app` directory.
|
|
|
|
* @example `['http', 'controllers']`
|
|
|
|
* @example `['units']`
|
|
|
|
*/
|
2021-03-22 00:46:32 +00:00
|
|
|
baseAppPath: string[],
|
2021-03-23 15:10:23 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Render the given template to a string which will be written to the file.
|
|
|
|
* Note: this method should NOT write the contents to `targetFilePath`.
|
|
|
|
*
|
|
|
|
* @example
|
|
|
|
* If the user enters:
|
|
|
|
*
|
|
|
|
* ```shell
|
|
|
|
* ./ex new mytemplate path:to:NewInstance
|
|
|
|
* ```
|
|
|
|
*
|
|
|
|
* Then, the following params are:
|
|
|
|
* ```typescript
|
|
|
|
* {
|
|
|
|
* name: 'NewInstance',
|
|
|
|
* fullCanonicalPath: 'path:to:NewInstance',
|
|
|
|
* targetFilePath: UniversalPath { }
|
|
|
|
* }
|
|
|
|
* ```
|
|
|
|
*
|
|
|
|
* @param name - the singular name of the resource
|
|
|
|
* @param fullCanonicalName - the full canonical name of the resource
|
|
|
|
* @param targetFilePath - the UniversalPath where the file will be written
|
|
|
|
*/
|
2021-03-22 00:46:32 +00:00
|
|
|
render: (name: string, fullCanonicalName: string, targetFilePath: UniversalPath) => string | Promise<string>
|
|
|
|
}
|