This is an example of a simple TypeScript program that uses Pkl for configuration.
A summary of each of the files in this directory, and what they do:
index.ts
: contains the source code of the express appConfigSchema.pkl
: contains the schema of the configuration (just the properties and their types, but not any values)config.dev.pkl
: amendsConfigSchema.pkl
, adding the config values that would be used in local developmentconfig.prod.pkl
: amendsConfigSchema.pkl
but with values to be used in production
There is also another directory, generated
, that contains .pkl.ts
files that were generated by pkl-gen-typescript
based on the given schema.
The package.json
has a script, titled gen-config
(but the script name doesn't matter), that executes the following:
pkl-gen-typescript ./ConfigSchema.pkl -o ./generated
This uses the pkl-gen-typescript
CLI, passing in ConfigSchema.pkl
as the Pkl module to be evaluated, and outputting the generated TypeScript files to the ./generated
directory.
- Run
npm install
in this directory to install dependencies (including a local link to thepkl-typescript
project at the root of this repo) - Run
npm run gen-config
to make sure the generated.pkl.ts
files in the./generated
directory are up-to-date - Run
npm run start
to start the local dev server
Then, in another terminal, run curl localhost:3003
to see a response from your Pkl-configured Express server.