Skip to content

Instantly share code, notes, and snippets.

@trulyronak
Last active July 3, 2020 00:20
Show Gist options
  • Save trulyronak/c02b171a6d6812d0a10d5833c173abb7 to your computer and use it in GitHub Desktop.
Save trulyronak/c02b171a6d6812d0a10d5833c173abb7 to your computer and use it in GitHub Desktop.
Adds Optic to Any Existing Strapi Project

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 ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment