diff --git a/_images/template-generation.jpeg b/_images/template-generation.jpeg new file mode 100644 index 00000000..c13fda12 Binary files /dev/null and b/_images/template-generation.jpeg differ diff --git a/autoloader/index.md b/autoloader/index.md index 34f62b7a..20c680e0 100644 --- a/autoloader/index.md +++ b/autoloader/index.md @@ -1,8 +1,8 @@ # Autoloader Instantiate entire directories at once with full typing, sibling visibility, and key based access. ```bash -# Create a new autoloader based on a directory -spruce autoloader:create [name] +# Create a new autoloader based on a name, like services or adapters +spruce autoloader:create [namePlural] Options: -p, --pattern Any pattern you want to use for loading files @@ -15,10 +15,36 @@ Options: -rd, --rootDestination Where should I save the root autoloader? +# Update autoloaders based on changes (deleting or adding files) +spruce autoloader:sync + # Create new root autoloader spruce autoloader:root Options: +``` +## Building your first autoloader +You need utilities, admit it! -``` \ No newline at end of file +```bash +spruce autoloader:create utilities +``` + +**** + +## Generated files + +After running `spruce autoloader:create` up to 4 files were created for you. + +1. **Example abstract class:** `.src/{{nameCamelPlural}}/Abstract{{nameCamel}}.ts` + 1. The start of an abstract class that others will extend + 2. Extends `IAutoloadable` + + +### ** 1. Autoloader ** +aououaoe +### ** 1. Root Autoloader ** +satoheusnatoheu + + \ No newline at end of file diff --git a/errors/index.md b/errors/index.md index fa23203a..08426886 100644 --- a/errors/index.md +++ b/errors/index.md @@ -46,7 +46,7 @@ Now review the generated files before we jump into the definition itself. After running `spruce error:create` up to 4 files were created for you. -1. **Definition:** `./src/errors/{{camelName}}.definition.ts` +1. **Definition:** `./src/errors/{{nameCamel}}.definition.ts` * Where the actual definition lives * Extends `ISchemaDefinition`, so you already know how it works! * Make your changes and run `spruce error:sync` to update the interface files diff --git a/schemas/index.md b/schemas/index.md index ca0656e5..e7691de0 100644 --- a/schemas/index.md +++ b/schemas/index.md @@ -158,6 +158,65 @@ spruce schema:create "Soccer ball" spruce schema:create "Vendor" ``` + + +## Generated files + +After running `spruce schema:create` up to 2 files were created for you. +**** +1. **Definition:** `./src/schemas/{{nameCamel}}.definitions.ts` + * Where your new definition lives + * After making changes, run `spruce schema:sync` to update interface files +2. **Types:** `#spruce/schemas/schemas.types.ts` + * Where all interfaces live + * Accessible through `SpruceSchemas` + * `const adidas: SpruceSchemas.Local.IVendor = { name: 'adidas' }` + + +#### ** 1. Definition ** +```ts +// ./src/schemas/vendor.definition.ts + +import Schema, { FieldType, buildSchemaDefinition } from '@sprucelabs/schema' + +const vendorDefinition = buildSchemaDefinition({ + id: 'vendor', + name: 'Vendor', + description: 'A vendor is a company that makes balls', + fields: { + id: { + type: FieldType.Id, + label: 'Id', + isRequired: true, + }, + name: { + type: FieldType.Text, + label: 'Name', + hint: 'How they are incorporated', + } + } +}) + +export default vendorDefinition +``` +#### ** 2. Types ** +Has both Core and Local types and definitions +```ts +// #spruce/schemas/schemas.types.ts + +export namespace SpruceSchemas.Local { + /** Profile images at various helpful sizes and resolutions. */ + export interface IProfileImage { + /** Id. */ + id: string + /** Name. How they are incorporated */ + name?: string | undefined | null + } +} +``` + + + ## Updating definitions We'll start by defining our Vendor schema since it's required for the ball schemas. diff --git a/standards/index.md b/standards/index.md index 6e53803e..50a952a1 100644 --- a/standards/index.md +++ b/standards/index.md @@ -105,19 +105,9 @@ We use singletons for various things like logging and Mercury. 1. `const users = this.store.user.users(...)` 2. `const users = this.store.user.usersById()` -## Generators - -1. Code that writes to “generated” files -2. Templates must be hbs -3. Generators live in CLI as the source of the template (.hbs) -4. Example, SchemaGenerator is in @sprucelabs/schemas -5. Generators in a folder called @sprucelabs/spruce-cli /generators -6. Class name ends in Generator -7. Each method starts with generator -8. Generators must return a string (not write a file) -9. Handling handlebar helpers - 1. helpers are "addons" -10. TODO: define event contracts for mercury for pulling types +## Generating templates + +![Generating templates](../_images/template-generation.jpeg?raw=true "Generating templates") ## **Addons**