This repository is a basic Schematic implementation that serves to quickly add and configure json-server to an Angular project.
The schematic does four things:
- Installs json-server as a dev dependency into your project
- Creates a directory for your json server files with example
db.json
androutes.json
files - Add a proxy configuration to your Angular project so that http requrests to
/api/*
will be pointed to json server - Adds convienience scripts to the project's
package.json
to start and serve your project with json-server or run it on its own.
Call the schematic with the Angular cli and follow the prompt to tell the Schematic where to create your json-server files.
ng add json-server-schematics
That's all you need to do!
To test locally, install @angular-devkit/schematics-cli
globally and use the schematics
command line tool. That tool acts the same as the generate
command of the Angular CLI, but also has a debug mode.
Check the documentation with
schematics --help
Additionally this project has a sandbox Angular project for ease of use when developing locally. To use the Schematic in the project you must:
- build the Schematic
- link the Schematic to the sandbox project
- navigate into the sandbox project and call the schematic.
- remove created files generated by the schematic between runs
There are a number of convinience scripts included that assist in this process.
# build the project
npm run build
# link the schematic
npm run link:schematic
# execute the schematic in the sandbox
npm test
# clean the sanddbox after the test before running again
npm run clean
To publish, simply do:
npm run build
npm publish
That's it!