Templates

Purpose

Templates are used by the make: command to generate new class scaffolding from the CLI. Unless you have a strong reason or preference for modification we recommend using the defaults, however you are free to edit them however you like.

Using Templates

You can use existing templates to scaffold the following classes:
  • Acts
  • Auditions
  • Commands
  • Providers
  • Scenes
For example:
1
$ msqrd make:act
Copied!
Additionally you can also auto-generate directory index files using the catalog command.
1
$ msqrd catalog
Copied!

Composing Templates

We analysed several popular templating libraries however all were geared toward HTML generation rather than JavaScript generation and added unnecessary weight to the dependencies.
Ultimately, we landed on native ES6 template literals which you can read more about here.

Constructor

A template is simply an exported function with the constructor/return profile of (data: any) => string
We recommend defining specific data shapes for each template to inform intellisense of what to expect.

Example Template

1
/** Export Type **/
2
export type ProviderTemplate = {
3
name: string
4
description: string
5
}
6
7
/** Define Template **/
8
export const providerTemplate = (data: ProviderTemplate): string => `
9
import { Provider } from "@masqueradejs/backstage"
10
11
/**
12
* @class {${data.name}Provider}
13
* @classdesc ${data.description}
14
* @extends {Provider}
15
*/
16
export class ${data.name}Provider extends Provider {
17
public register(): void {
18
// Register your own bindings
19
}
20
21
public async boot(): Promise<void> {
22
// IoC container is ready
23
}
24
}
25
`
26
Copied!