To use this, simply run it via curl and sh
cd path/to/existing/strapi/project
curl -L https://gist.github.com/trulyronak/c02b171a6d6812d0a10d5833c173abb7/raw | sh
| #!/bin/bash | |
| # update package.json to use optic | |
| echo "installing optic as a developer dependency" | |
| npm install -D @useoptic/cli | |
| # add to package.json | |
| echo "adding scripts to package.json" | |
| node -e 'const json=require("./package.json");json.scripts=Object.assign(json.scripts,{monitor:"api start",spec:"api spec"});const content=JSON.stringify(json,null,2);fs.writeFile("./package.json",content,"utf8",()=>{console.log("updated package.json")});' | |
| # minified version of | |
| # const json = require('./package.json'); json.scripts = Object.assign(json.scripts, { monitor: "api start", spec: "api spec" }) | |
| # const content = JSON.stringify(json, null, 2) | |
| # fs.writeFile("./package.json", content, 'utf8', () => { | |
| # console.log('updated package.json') | |
| # }) | |
| # https://javascript-minifier.com/ | |
| # add optic.yml | |
| echo "creating optic.yml configuration file" | |
| cat >optic.yml << EOL | |
| name: $(basename "$PWD") | |
| tasks: | |
| # The default task, invoke using \`api run start\` | |
| # Learn how to finish setting up Optic at http://docs.useoptic.com/setup | |
| start: | |
| command: export PORT=\$OPTIC_API_PORT && npm run develop | |
| baseUrl: http://localhost:1337 | |
| ignoreRequests: | |
| - OPTIONS * | |
| - /admin(.*) | |
| EOL | |
| echo "Done! Added 2 New Scripts" | |
| echo " npm run monitor (or yarn monitor)" | |
| echo " Start Strapi with Optic monitoring all requests to automatically generate documentation." | |
| echo "" | |
| echo " npm run spec (or yarn spec)" | |
| echo " Display current documentation specifications." | |
| echo "" |