diff --git a/README.md b/README.md index b1115b5..d234114 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,8 @@ This repository: - holds issues for new and general information for improving existing templates - downloads each template listed in the [data](./data) folder -- deploys an API to https://api.mystmd.org +- implements a lightweight API that serves an index of template metadata + - deploys that API to https://api.mystmd.org - automatically updates the organization readme ## Contributing a LaTeX or Typst Template @@ -32,7 +33,46 @@ However, data-driven options specified by a `template.yml` are still passed to t [Fork this repo](https://github.com/myst-templates/templates/fork), make your change and open a PR. -## Development +## Modifying the Template Index -Install the mini CLI tool using `npm install` and `npm run dev` (puts this in watch mode, so you can kill after the output is complete). -Then call `myst-templates-api index data/tex.yml` from the main folder, which will create an index file and update the organization Readme. +To add, remove or update a template in the index, you need to build and run the CLI tool. + +1. Install the mini CLI tool using `npm install` +2. Run `npm run build:cli` +3. Run `npm run link` + +After you have made your changes to a specific index file(s), call `myst-templates-api index data/tex.yml` from the main folder, which will create an index file and update the organization Readme. + +## Source locations + +- `./cli`: CLI for generating JSON data files from `data/x.yml` and template clone. +- `./src`: Server for JSON data files. + +## Local deployment + +To run the API server locally for development and testing: + +0. `npm install` + +1. `git clone git@github.com:myst-templates/.github.git readme` + +The tool wants to populate a README with a list of templates. Provide +it with an example. + +2. `npm run build` + +- Build CLI into `./dist`. +- Build API server into `./api`. + +2. `node dist/myst-templates-api.cjs index data/*.yml` + +Combine JSON data files in `data/*.yml` with template information, +obtained from cloned template repos. + +3. `npm run copy:data` + +Copy JSON data into `src/data`. + +4. `node server.js` + +Serve data on `https://localhost:10000`. diff --git a/package.json b/package.json index 1c70a87..8aef582 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "dev": "npm run link && esbuild cli/index.ts --bundle --outfile=dist/myst-templates-api.cjs --platform=node --watch", "build:cli": "esbuild cli/index.ts --bundle --outfile=dist/myst-templates-api.cjs --platform=node", "build:api": "esbuild src/index.ts src/utils.ts --outdir=api --platform=node --format=cjs", - "copy:data": "mkdir api && mkdir api/data && copyfiles -f src/data/*.json api/data", + "copy:data": "mkdir -p api/data && copyfiles -f src/data/*.json api/data", "build": "npm-run-all -l clean copy:data -p build:cli build:api", "compile": "tsc --noEmit", "test": "npm run compile", diff --git a/server.js b/server.js new file mode 100644 index 0000000..6aeaa4d --- /dev/null +++ b/server.js @@ -0,0 +1,4 @@ +const app = require('./api/index.js'); + +const PORT = process.env.PORT || 10000; +app.listen(PORT, () => console.log(`Listening on ${PORT}`));