-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Created plugin boilerplate and new-plugin script #4
Open
kael-shipman
wants to merge
7
commits into
shockey:master
Choose a base branch
from
kael-shipman:boilerplate
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b7c99f8
Created plugin boilerplate and new-plugin script
kael-shipman 17132d5
Bugfixes and improvements
kael-shipman a1e6b49
Improvements to boilerplate
kael-shipman b394f90
Fix typo in prompt
kael-shipman f83f6ef
Added @babel/preset-react dependency to boilerplate
kael-shipman 2623099
Used tput for terminal bold and improved prompts
kael-shipman 9276fed
Fixed bug that produced files with single-quotes at the end of their …
kael-shipman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"presets": [ | ||
[ | ||
"@babel/preset-env", | ||
{ | ||
"targets": { | ||
"ie": "11" | ||
} | ||
} | ||
] | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
node_modules | ||
build | ||
*.sw[op] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
Swagger UI '{proper-name}' Plugin | ||
================================================================== | ||
|
||
|
||
|
||
## Usage | ||
|
||
### Require | ||
|
||
First, install the module with npm: | ||
``` | ||
$ npm install --save swagger-ui-plugin-{name-kebab-case} | ||
``` | ||
|
||
Next, require it in your client-side application: | ||
|
||
```js | ||
const {name-pascal-case}Plugin = require('swagger-ui-plugin-{name-kebab-case}'); | ||
|
||
SwaggerUI({ | ||
// your options here... | ||
plugins: [ | ||
{name-pascal-case}Plugin | ||
] | ||
}) | ||
``` | ||
|
||
### `<script>` | ||
|
||
```html | ||
<!-- Load Swagger UI and related --> | ||
<link rel="stylesheet" type="text/css" href="https://unpkg.com/swagger-ui-dist/swagger-ui.css"></link> | ||
<script src="https://unpkg.com/react@17/umd/react.production.min.js"></script> | ||
<script src="https://unpkg.com/swagger-ui-dist/swagger-ui-bundle.js"> </script> | ||
|
||
<!-- Load the {name-pascal-case} Plugin --> | ||
<script src="https://unpkg.com/swagger-ui-plugin-{name-kebab-case}"> </script> | ||
|
||
<script> | ||
window.onload = function() { | ||
SwaggerUIBundle({ | ||
url: "https://petstore.swagger.io/v2/swagger.json", | ||
dom_id: "#swagger-ui", | ||
|
||
// your options here... | ||
|
||
plugins: [ | ||
{name-pascal-case}Plugin | ||
], | ||
}); | ||
} | ||
</script> | ||
``` | ||
|
7 changes: 7 additions & 0 deletions
7
packages/.boilerplate/__tests__/swagger-ui-plugin-{name-kebab-case}.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
'use strict'; | ||
|
||
const swaggerUiPlugin{name-pascal-case} = require('..'); | ||
|
||
describe('swagger-ui-plugin-{name-kebab-case}', () => { | ||
it('needs tests'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<!-- Load React (if necessary) --> | ||
<!-- <script src="https://unpkg.com/react@17/umd/react.production.min.js"></script>--> | ||
|
||
<!-- Load Swagger UI --> | ||
<link rel="stylesheet" type="text/css" href="https://unpkg.com/swagger-ui-dist/swagger-ui.css"></link> | ||
<script src="https://unpkg.com/swagger-ui-dist/swagger-ui-bundle.js"></script> | ||
|
||
<!-- Load your plugin --> | ||
<script src="./plugin.js"></script> | ||
|
||
<!-- Set it up on-load --> | ||
<script> | ||
window.onload = function() { | ||
window.ui = SwaggerUIBundle({ | ||
url: "https://petstore.swagger.io/v2/swagger.json", | ||
dom_id: "#swagger-ui", | ||
presets: [ | ||
SwaggerUIBundle.presets.apis, | ||
SwaggerUIBundle.SwaggerUIStandalonePreset | ||
], | ||
plugins: [ | ||
{name-pascal-case}Plugin | ||
] | ||
}); | ||
} | ||
</script> | ||
</head> | ||
|
||
<body> | ||
<div id="swagger-ui"></div> | ||
</body> | ||
</html> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{ | ||
"name": "swagger-ui-plugin-{name-kebab-case}", | ||
"version": "1.0.0", | ||
"description": "{short-desc}", | ||
"author": "{author}", | ||
"homepage": "https://github.com/shockey/swagger-ui-plugins#readme", | ||
"license": "MIT", | ||
"main": "build/index.js", | ||
"directories": { | ||
"build": "build", | ||
"test": "__tests__" | ||
}, | ||
"files": [ | ||
"build" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/shockey/swagger-ui-plugins.git" | ||
}, | ||
"scripts": { | ||
"start": "npx http-server example/", | ||
"build": "npx babel src -d build && cp build/index.js example/plugin.js", | ||
"prepublishOnly": "npm run build", | ||
"test": "echo \"Error: run tests from root\" && exit 1" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/shockey/swagger-ui-plugins/issues" | ||
}, | ||
"devDependencies": { | ||
"@babel/cli": "^7.12.10", | ||
"@babel/core": "^7.12.10", | ||
"@babel/preset-env": "^7.12.11" | ||
}, | ||
"dependencies": { | ||
"@babel/preset-react": "^7.12.13" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// From: https://raw.githubusercontent.com/chilts/umd-template/master/template.js | ||
; ((f) => { | ||
// module name and requires | ||
var name = '{name-pascal-case}Plugin'; | ||
var requires = []; | ||
|
||
// CommonJS | ||
if (typeof exports === "object" && typeof module !== "undefined") { | ||
module.exports = f.apply(null, requires.map(function (r) { return require(r); })); | ||
|
||
// RequireJS | ||
} else if (typeof define === "function" && define.amd) { | ||
define(requires, f); | ||
|
||
// <script> | ||
} else { | ||
var g; | ||
if (typeof window !== "undefined") { | ||
g = window; | ||
} else if (typeof global !== "undefined") { | ||
g = global; | ||
} else if (typeof self !== "undefined") { | ||
g = self; | ||
} else { | ||
// works providing we're not in "use strict"; | ||
// needed for Java 8 Nashorn | ||
// see https://github.com/facebook/react/issues/3037 | ||
g = this; | ||
} | ||
g[name] = f.apply(null, requires.map(function (r) { return g[r]; })); | ||
} | ||
|
||
})(() => { | ||
// Module source | ||
return (system) => { | ||
return { | ||
|
||
|
||
|
||
/** | ||
* | ||
* | ||
* | ||
* | ||
* Your plugin here | ||
* | ||
* | ||
* | ||
* | ||
*/ | ||
|
||
|
||
|
||
} | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
SUCCESS=0 | ||
|
||
# Get bold/plain variables using tput, if available | ||
if command -v tput &>/dev/null; then | ||
bold="$(tput bold)" | ||
reset="$(tput sgr0)" | ||
fi | ||
|
||
function bold() { | ||
echo "${bold}$@${reset}" | ||
} | ||
|
||
function revert() { | ||
if [ "$SUCCESS" -eq 0 ]; then | ||
if [ -n "$PLUGIN_KEBAB_CASE" ]; then | ||
if [ -e "packages/$PLUGIN_KEBAB_CASE" ]; then | ||
rm -Rf "packages/$PLUGIN_KEBAB_CASE" | ||
fi | ||
fi | ||
fi | ||
} | ||
|
||
function gather_info() { | ||
echo "$(bold "Plugin Name")" | ||
echo "What should the name of your plugin be? Some examples are 'Hide Empty Tags' and 'Disable Try-It-Out Without Servers'." | ||
echo | ||
read -p "Name: " PLUGIN_NAME | ||
echo | ||
echo "$(bold "Plugin Author")" | ||
echo "Who should be listed as the plugin author. This is usually something like 'Your Name<your.name@example.com>'." | ||
echo | ||
read -p "Author: " PLUGIN_AUTHOR | ||
echo | ||
echo "$(bold "Plugin Description")" | ||
echo "Come up with a short description for package.json so others know what this plugin is for." | ||
echo | ||
read -p "Description: " PLUGIN_SHORT_DESC | ||
echo | ||
|
||
# Generate derivative name values | ||
PLUGIN_PROPER_NAME="$([ -n "$PLUGIN_PROPER_NAME" ] && echo "$PLUGIN_PROPER_NAME" || echo "$PLUGIN_NAME" | sed 's/ +/ /g' | sed 's/.*/\L&/g' | sed 's/[a-z]*/\u&/g' | sed "s/'[ST]/\\L&/g")" | ||
|
||
echo "$(bold "Good. Now we're going to generate a few name derivatives for you.") Make sure they look ok, or change them if they don't." | ||
echo | ||
echo "$(bold "Proper Name")" | ||
echo "This will be your plugin's name in the Readme" | ||
echo | ||
read -p "Proper name: [${PLUGIN_PROPER_NAME}] " ANS | ||
if [ -n "$ANS" ]; then | ||
PLUGIN_PROPER_NAME="$ANS" | ||
fi | ||
PLUGIN_KEBAB_CASE="$([ -n "$PLUGIN_KEBAB_CASE" ] && echo "$PLUGIN_KEBAB_CASE" || echo "$PLUGIN_PROPER_NAME" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9 ]//g' | sed -r 's/ +/-/g')" | ||
echo | ||
echo "$(bold "Kebab-Case Name")" | ||
echo "There are a variety of places where your plugin will be referenced by a 'kebab-case' variant. Enter that here or accept the default." | ||
echo | ||
read -p "Kebab-case name: [${PLUGIN_KEBAB_CASE}] " ANS | ||
if [ -n "$ANS" ]; then | ||
PLUGIN_KEBEB_CASE="$ANS" | ||
fi | ||
echo | ||
PLUGIN_PASCAL_CASE="$([ -n "$PLUGIN_PASCAL_CASE" ] && echo "$PLUGIN_PASCAL_CASE" || echo "$PLUGIN_PROPER_NAME" | sed 's/[^a-zA-Z0-9 ]//g' | sed -r 's/ +//g')" | ||
echo "$(bold "PascalCase Name")" | ||
echo "There are a variety of places where your plugin will be referenced by a 'PascalCase' variant. Enter that here or accept the default." | ||
echo | ||
read -p "PascalCase name: [${PLUGIN_PASCAL_CASE}] " ANS | ||
if [ -n "$ANS" ]; then | ||
PLUGIN_PASCAL_CASE="$ANS" | ||
fi | ||
echo | ||
} | ||
|
||
function gather_loop() { | ||
while true; do | ||
# Gather | ||
gather_info | ||
|
||
# Then validate | ||
local MISSING= | ||
if [ -z "$PLUGIN_NAME" ]; then MISSING="$MISSING,name"; fi | ||
if [ -z "$PLUGIN_AUTHOR" ]; then MISSING="$MISSING,author"; fi | ||
if [ -z "$PLUGIN_SHORT_DESC" ]; then MISSING="$MISSING,short-description"; fi | ||
if [ -n "$MISSING" ]; then | ||
echo "Hm... Looks like we didn't get all the info we needed. We're missing the following fields: $(bold "$(echo "$MISSING" | sed s/^,//)"). Please try again." | ||
else | ||
return 0 | ||
fi | ||
done | ||
} | ||
|
||
trap "revert" EXIT | ||
|
||
# Intro | ||
echo "Hi! Sounds like you want to make a new Swagger UI plugin. Please fill in the following information and we'll get you set up." | ||
echo | ||
|
||
while true; do | ||
# Gather info | ||
gather_loop | ||
|
||
# Now generate from boilerplate | ||
echo "$(bold "REVIEW") - Here's what we got:" | ||
echo | ||
echo "$(bold "Name:") $PLUGIN_PROPER_NAME" | ||
echo "$(bold "Author:") $PLUGIN_AUTHOR" | ||
echo "$(bold "Short Description:") $PLUGIN_SHORT_DESC" | ||
echo "$(bold "Kebab-Case Name:") $PLUGIN_KEBAB_CASE" | ||
echo "$(bold "PascalCase Name:") $PLUGIN_PASCAL_CASE" | ||
echo | ||
read -p "Does that look right? (Y/n) " ANS | ||
ANS="$(echo "$ANS" | tr '[:upper:]' '[:lower:]')" | ||
if [ "$ANS" == "n" ]; then | ||
echo "Ok, let's try again" | ||
sleep 1 | ||
else | ||
echo "$(bold "Great!") generating a new plugin from the boilerplate...." | ||
sleep 1 | ||
break | ||
fi | ||
done | ||
|
||
|
||
cp -R packages/.boilerplate "packages/${PLUGIN_KEBAB_CASE}" | ||
|
||
sed -i'.delete' s/'{author}'/"$PLUGIN_AUTHOR"/g $(find packages/${PLUGIN_KEBAB_CASE} -type f) | ||
sed -i'.delete' s/'{proper-name}'/"$PLUGIN_PROPER_NAME"/g $(find packages/${PLUGIN_KEBAB_CASE} -type f) | ||
sed -i'.delete' s/'{name-kebab-case}'/"$PLUGIN_KEBAB_CASE"/g $(find packages/${PLUGIN_KEBAB_CASE} -type f) | ||
sed -i'.delete' s/'{name-pascal-case}'/"$PLUGIN_PASCAL_CASE"/g $(find packages/${PLUGIN_KEBAB_CASE} -type f) | ||
sed -i'.delete' s/'{short-desc}'/"$PLUGIN_SHORT_DESC"/g $(find packages/${PLUGIN_KEBAB_CASE} -type f) | ||
find "packages/${PLUGIN_KEBAB_CASE}" -name '*.delete' -delete | ||
|
||
while read f; do | ||
NEW_NAME="$(echo "$f" | sed s/'{name-kebab-case}'/"$PLUGIN_KEBAB_CASE"/g)" | ||
mv "$f" "$NEW_NAME" | ||
done < <(find "packages/${PLUGIN_KEBAB_CASE}" -name '*{name-kebab-case}*') | ||
|
||
echo "$(bold "Ok! Your new plugin is ready for development at ./packages/$PLUGIN_KEBAB_CASE".)" | ||
|
||
SUCCESS=1 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
running this locally shows a couple of weird behaviors (shown is two runs, with names
Kyle Plugin
andTest Plugin
):There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, looks like this was a bad sed line. Frustratingly, mac sed requires you to supply a backup prefix. I tried to get around that by just supplying an empty string, which I think would normally work, but I did it in a weird way.
Anyway, I believe it's now fixed. Grab a look and see what you think.