Open lxndrdagreat opened 4 years ago
unthink generate resource my-resource-name
By default, the following file(s) will be created from template:
src/server/resources/<resource-name>-resource.ts
name
name: "Hello World"
basePath
/<resource-name>
/hello-world
routes
view
data
src/content/templates/<resource-name>.njk
By default, the following file(s) will be modified:
src/server/resource-definitions.ts
import
export default
Use --view to provide an alternate name for the nunjucks template
--view
Use --no-view to skip generation of a template file and the inclusion of the view(...) example in the routes.
--no-view
view(...)
Use --no-data to skip the inclusion of the JSON data(...) endpoint in the routes.
--no-data
data(...)
Use --base-path to set the basePath of the resource.
--base-path
unthink generate resource hello-world --base-path="/"
Use --entry to have the nunjucks template include a reference to an entry bundle.
--entry
unthink g resource hello-world --entry=hello-world
Would add something like this to the template:
<script src="{{ PUBLIC_FILES_HOST }}/public/js/hello-world.bundle.js?v={{ APP_VERSION }}"></script>
One reason I am pushing for this is because I would like to use it to generate the "hello-world" example included in the template, instead of having that code directly included in the template itself.
Command
Arguments
Default Result
By default, the following file(s) will be created from template:
src/server/resources/<resource-name>-resource.ts
name
will be set to the match the resource name. E.g., "hello-world" would bename: "Hello World"
.basePath
will be set to/<resource-name>
, E.g.,/hello-world
.routes
will contain the following:view
handler serving up the templatedata
handler serving up a JSON endpoint that returns an empty objectsrc/content/templates/<resource-name>.njk
. E.g., "hello-world" would create a template called "hello-world.njk".By default, the following file(s) will be modified:
src/server/resource-definitions.ts
will be modified to include:import
to the new resourceexport default
listOptions
--view
Use
--view
to provide an alternate name for the nunjucks template--no-view
Use
--no-view
to skip generation of a template file and the inclusion of theview(...)
example in the routes.--no-data
Use
--no-data
to skip the inclusion of the JSONdata(...)
endpoint in the routes.--base-path
Use
--base-path
to set thebasePath
of the resource.--entry
Use
--entry
to have the nunjucks template include a reference to an entry bundle.Would add something like this to the template: