This script will create stub files and build scripts for a federated wiki plugin.
./mkplugin.sh CoolThing
to make a CoolThing plugin. Learn more at plugins.fed.wiki.org.
This script will create stub files and build scripts for a federated wiki plugin.
./mkplugin.sh CoolThing
to make a CoolThing plugin. Learn more at plugins.fed.wiki.org.
#!/bin/sh | |
# Script to create a stub plugin with stub documentation | |
if [ $# -eq 0 ] | |
then | |
echo "Usage: ./mkplugin.sh <new-plugin-name>" | |
echo "e.g. ./mkplugin.sh CoolThing" | |
exit 0 | |
fi | |
name=`echo $1 | tr '[A-Z]' '[a-z]'` | |
repo="wiki-plugin-$name" | |
date=`date -u +%s` | |
msec=000 | |
if [ "$1" == "$name" ] | |
then | |
echo "Expected capitalized name" | |
echo "e.g. CoolThing" | |
exit 2 | |
fi | |
if [ -e $repo ] | |
then | |
echo "plugin repository directory already exists: $repo" | |
exit 3 | |
fi | |
mkdir $repo | |
mkdir $repo/client | |
cat <<EOF > $repo/client/$name.coffee | |
expand = (text)-> | |
text | |
.replace /&/g, '&' | |
.replace /</g, '<' | |
.replace />/g, '>' | |
.replace /\*(.+?)\*/g, '<i>\$1</i>' | |
emit = (\$item, item) -> | |
\$item.append """ | |
<p style="background-color:#eee;padding:15px;"> | |
#{expand item.text} | |
</p> | |
""" | |
bind = (\$item, item) -> | |
\$item.dblclick -> wiki.textEditor \$item, item | |
window.plugins.$name = {emit, bind} if window? | |
module.exports = {expand} if module? | |
EOF | |
mkdir $repo/test | |
cat <<EOF > $repo/test/test.coffee | |
# build time tests for $name plugin | |
# see http://mochajs.org/ | |
$name = require '../client/$name' | |
expect = require 'expect.js' | |
describe '$name plugin', -> | |
describe 'expand', -> | |
it 'can make itallic', -> | |
result = $name.expand 'hello *world*' | |
expect(result).to.be 'hello <i>world</i>' | |
EOF | |
mkdir $repo/pages | |
title='"About '"$1"' Plugin"' | |
id1=`cat /dev/urandom | env LC_CTYPE=C tr -cd 'a-f0-9' | head -c 16` | |
id2=`cat /dev/urandom | env LC_CTYPE=C tr -cd 'a-f0-9' | head -c 16` | |
read -r -d '' story <<EOF | |
[ | |
{ | |
"type": "paragraph", | |
"id": "$id1", | |
"text": "Here we describe the purpose of the plugin and include a sample." | |
}, | |
{ | |
"type": "$name", | |
"id": "$id2", | |
"text": "This is text in the new plugin. You can *double-click* to edit it too." | |
} | |
] | |
EOF | |
read -r -d '' journal <<EOF | |
[ | |
{ | |
"type": "create", | |
"item": { | |
"title": $title, | |
"story": $story | |
}, | |
"date": $date$msec, | |
"certificate": "from mkplugin.sh" | |
} | |
] | |
EOF | |
cat <<EOF > $repo/pages/about-$name-plugin | |
{ | |
"title": $title, | |
"story": $story, | |
"journal": $journal | |
} | |
EOF | |
cat <<EOF > $repo/gruntfile.js | |
module.exports = function (grunt) { | |
grunt.loadNpmTasks('grunt-contrib-coffee'); | |
grunt.loadNpmTasks('grunt-contrib-watch'); | |
grunt.loadNpmTasks('grunt-mocha-test'); | |
grunt.initConfig({ | |
coffee: { | |
client: { | |
expand: true, | |
options: { | |
sourceMap: true | |
}, | |
src: ['client/*.coffee', 'test/*.coffee'], | |
ext: '.js' | |
} | |
}, | |
mochaTest: { | |
test: { | |
options: { | |
reporter: 'spec' | |
}, | |
src: ['test/**/*.js'] | |
} | |
}, | |
watch: { | |
all: { | |
files: ['client/*.coffee', 'test/*.coffee'], | |
tasks: ['coffee','mochaTest'] | |
} | |
} | |
}); | |
grunt.registerTask('build', ['coffee', 'mochaTest']); | |
grunt.registerTask('default', ['build']); | |
}; | |
EOF | |
cat <<EOF > $repo/package.json | |
{ | |
"name": "wiki-plugin-$name", | |
"version": "0.0.1", | |
"description": "Federated Wiki - $1 Plugin", | |
"keywords": [ | |
"$name", | |
"wiki", | |
"federated wiki", | |
"plugin" | |
], | |
"author": { | |
"name": "Your Name", | |
"email": "you@example.com", | |
"url": "http://example.com" | |
}, | |
"contributors": [], | |
"scripts": { | |
"test": "mocha" | |
}, | |
"devDependencies": { | |
"grunt": "~0.4", | |
"grunt-contrib-coffee": "~0.12", | |
"grunt-contrib-watch": "~0.6", | |
"mocha": "*", | |
"expect.js": "*", | |
"grunt-mocha-test": "~0.12" | |
}, | |
"license": "MIT & GPL", | |
"repository": { | |
"type": "git", | |
"url": "https://github.com/fedwiki/wiki-plugin-$name.git" | |
}, | |
"bugs": { | |
"url": "https://github.com/fedwiki/wiki-plugin-$name/issues" | |
}, | |
"engines": { | |
"node": "0.10" | |
} | |
} | |
EOF | |
cat <<EOF > $repo/factory.json | |
{ | |
"name": "$1", | |
"title": "$1 Plugin", | |
"category": "data|format|other" | |
} | |
EOF | |
cat <<EOF > $repo/ReadMe.md | |
# Federated Wiki - $1 Plugin | |
This plugin, type: $name, extends the markup of the federated wiki. | |
## Build | |
npm install | |
grunt build | |
## License | |
MIT & GPL | |
EOF | |
cat <<EOF > $repo/.gitignore | |
/*/*.js | |
/*/*.map | |
node_modules | |
npm-debug.log | |
EOF | |
cat <<EOF > $repo/.npmignore | |
/**/*.coffee | |
Gruntfile.js | |
EOF | |
echo | |
echo "Package: cd $repo/" | |
echo "Install: npm install" | |
echo "Build: grunt build; grunt watch" | |
echo "Link: npm link; (cd ../wiki-node; npm link $repo)" | |
echo "Serve: (restart once to notice new plugin)" | |
echo "Browse: open localhost:3000/about-$name-plugin.html" | |
echo "Commit: git init; git add .; git commit -m mkplugin" | |
echo "Develop: vi client/$name.coffee" | |
echo |