This is a sub-tracking issue of #234
This is a component of Redwood's initiative to add first-class TypeScript support. 🎉
Generators are a part of the CLI package and located in this directory:
https://github.com/redwoodjs/redwood/tree/master/packages/cli/src/commands/generate
The CLI package is built with Yargs. Read more here.
Goal
The intention is to provide a path for a collaborative, incremental transition to having 100% TypeScript generators. This means the scope of a PR can be an individual generator, which can be merged into the master branch on its own when it's ready.
- source templates will be
.ts
- generators should be aware of both
.ts and .js; this applies to 1) refusing to run if files already exist and 2) overwriting existing files using --force
- In the case where existing files are a different language target (e.g. in the case of a hybrid-project), the generator should refuse to run regardless of using the
--force option; a clear explanation message should be given
- templates should be transpiled and formatted when the target language is JS (suggested to use
ts.transpile and prettier, but this needs evaluation)
- need to determine appropriate
ts.ScriptTarget; "ESNext" seems like a candidate
- ⚠️transpilation formatting goal == match existing JS templates so that no updates are required for Redwood Tutorial, either code snippets or images (TBD as needed)
- generators should have CLI options for targeting
--javascript or --typescript
- generators should not require a language target option; instead, the default target will be the project "language default" or a config override in
redwood.toml if given.
- Example: if
tsconfig.json exists and there is no redwood.toml override, the generator will automatically set --typescript to true. Therefore, running yarn rw g [option] will target typescript.
- TODO: create a new Internal package helper for easy access to this config value
- generators need to pass CI tests and the generated
...test.ts|js files need to pass yarn rw test and yarn rw lint
Steps to Convert a Specific Generator
- Rewrite each generator template, including template test file, as TS
- TS files will replace JS files
- Convert corresponding
__tests__ directory files and fixtures to TS
- Add a JS and TS target CLI command option, e.g.
[--javascript|--typescript] to each generator CLI command
- commands should also be aliased
[-js|-ts] respectively
- set the behavior to automatically use the project "language default" (see above) OR a given
--javascript or --typescript option
- When language target=javascript, transpile and format TS templates to JS
- do generated
..test.ts/js files pass yarn rw lint and yarn rw test?
Checklist: Templates and Generators
This is a sub-tracking issue of #234
Generators are a part of the CLI package and located in this directory:
https://github.com/redwoodjs/redwood/tree/master/packages/cli/src/commands/generate
The CLI package is built with Yargs. Read more here.
Goal
The intention is to provide a path for a collaborative, incremental transition to having 100% TypeScript generators. This means the scope of a PR can be an individual generator, which can be merged into the master branch on its own when it's ready.
.ts.tsand.js; this applies to 1) refusing to run if files already exist and 2) overwriting existing files using--force--forceoption; a clear explanation message should be givents.transpileand prettier, but this needs evaluation)ts.ScriptTarget; "ESNext" seems like a candidate--javascriptor--typescriptredwood.tomlif given.tsconfig.jsonexists and there is noredwood.tomloverride, the generator will automatically set--typescripttotrue. Therefore, runningyarn rw g [option]will target typescript....test.ts|jsfiles need to passyarn rw testandyarn rw lintSteps to Convert a Specific Generator
__tests__directory files and fixtures to TS[--javascript|--typescript]to each generator CLI command[-js|-ts]respectively--javascriptor--typescriptoption..test.ts/jsfiles passyarn rw lintandyarn rw test?Checklist: Templates and Generators
PR CLI: Convert helpers and src/lib to ts #557stalled out)__tests__/helpers.test.jsto TShelpers.jsto TSnote: these files are outside generators/, but the functionality that relates to generators should be moved to
src/commands/generatorstemplates/files to TS__tests__/fixtures andtest.jsto TS--javascriptas defaulttemplates/file to TS__tests__/fixtures andtest.jsto TS--javascriptas defaulttemplates/files to TS__tests__/fixtures andtest.jsto TS--javascriptas defaulttemplates/files to TS__tests__/fixtures andtest.jsto TS--javascriptas defaulttemplates/file to TS__tests__/fixtures andtest.jsto TS--javascriptas defaulttemplates/files to TS__tests__/fixtures andtest.jsto TS--javascriptas defaulttemplates/files to TS__tests__/fixtures andtest.jsto TS--javascriptas defaulttemplates/files to TS: components, layouts, and pages__tests__/fixtures andtest.jsto TS--javascriptas default