Permalink
Browse files

Add grunt goodness

  • Loading branch information...
1 parent 01782ef commit 1c2bf8b9efab9ef80b75cefac880d7d7a5916b2e @kirsle kirsle committed Dec 23, 2014
Showing with 453 additions and 554 deletions.
  1. +1 −0 .gitignore
  2. +2 −0 Changes.md
  3. +64 −0 Gruntfile.coffee
  4. +32 −8 README.md
  5. +344 −316 lib/rivescript.js
  6. +2 −230 lib/rivescript.min.js
  7. +8 −0 package.json
View
@@ -0,0 +1 @@
+node_modules/
View
@@ -8,6 +8,8 @@
sorted by length of trigger (longest to shortest).
- Fix <bot> tag matching in triggers.
- Allow <bot> interpolation in triggers to support UTF-8.
+ - Use Grunt for minification (instead of the Perl minify.pl script), JS
+ linting, and for running a simple web server for demoing RiveScript.
* 1.0.4 2014-11-25
- Relicense project under the MIT License.
View
@@ -0,0 +1,64 @@
+module.exports = (grunt) ->
+ # Project configuration
+ grunt.initConfig
+ pkg: grunt.file.readJSON("package.json")
+ watch:
+ files: ["lib/<%= pkg.name %>.js"]
+ tasks: ["uglify"]
+ uglify:
+ options:
+ banner: "/* <%= pkg.name %> <%= pkg.version %> -- built on " \
+ + "<%= grunt.template.today('yyyy-mm-dd hh:MM:ss') %> */\n"
+ build:
+ src: "lib/<%= pkg.name %>.js"
+ dest: "lib/<%= pkg.name %>.min.js"
+ nodeunit:
+ all: ["test/test-*.js"]
+ options:
+ reporter: "default"
+ jshint:
+ files: [
+ "Gruntfile.js"
+ "lib/<%= pkg.name %>.js"
+ ]
+ options:
+ curly: true
+ eqnull: true
+ eqeqeq: true
+ undef: true
+ laxbreak: true
+ evil: true, # Don't warn about eval in our JS object handler
+ globals:
+ $: true,
+ require: true,
+ module: true,
+ console: true,
+ window: true
+ connect:
+ server:
+ options:
+ protocol: "http"
+ hostname: "127.0.0.1"
+ port: 8000
+ base: "eg"
+ directory: "eg"
+ keepalive: true
+ open: "http://localhost:8000/chat.html"
+ middleware: (connect, options, middlewares) ->
+ # Allow rivescript.js to be accessed from the web root.
+ middlewares.unshift (req, res, next) ->
+ if req.url is "/lib/rivescript.js"
+ return res.end(grunt.file.read("lib/rivescript.js"))
+ else
+ return next()
+ return middlewares
+
+ # Grunt plugins
+ grunt.loadNpmTasks("grunt-contrib-connect") # Simple web server
+ grunt.loadNpmTasks("grunt-contrib-uglify") # Minify JS
+ grunt.loadNpmTasks("grunt-contrib-jshint") # JSLint
+ grunt.loadNpmTasks("grunt-contrib-watch") # Watch JS for live changes
+ grunt.loadNpmTasks("grunt-contrib-nodeunit") # Unit testing
+
+ # Tasks
+ grunt.registerTask "default", ["uglify"]
View
@@ -2,14 +2,13 @@
## INTRODUCTION
-This is a RiveScript interpreter library for JavaScript.
-RiveScript is a scripting language for chatterbots, making it
-easy to write trigger/response pairs for building up a bot's
-intelligence.
+This is a RiveScript interpreter library for JavaScript. RiveScript is a
+scripting language for chatterbots, making it easy to write trigger/response
+pairs for building up a bot's intelligence.
-This library can be used both in a web browser or as a Node.JS
-module. See the `eg/` folder for a web browser example. There's
-a `node/` folder with a Node.JS example.
+This library can be used both in a web browser or as a Node.JS module.
+See the `eg/` folder for a web browser example. There's a `node/` folder with
+a Node.JS example.
## INSTALLATION
@@ -20,6 +19,19 @@ through npm:
To use on the web, just load `rivescript.js` with a `<script>` tag like usual.
+## GRUNT CONNECT
+
+This project uses [Grunt](http://gruntjs.com) for compiling to minified JS and
+also includes a simple web server for local testing and demoing for RiveScript.
+
+Install `nodejs` and `npm` and then:
+
+```bash
+$ npm install -g grunt # If you don't already have it
+$ npm install # Install dev dependencies
+$ grunt connect:server # Will start a local web server and open eg/chat.html
+```
+
## USAGE
```javascript
@@ -76,14 +88,26 @@ you can't capture a user's e-mail address in a RiveScript reply, because of the
When UTF-8 mode is enabled, these restrictions are lifted. Triggers are only
limited to not contain certain metacharacters like the backslash, and the user's
message is only stripped of backslashes and HTML angled brackets (to protect
-from obvious XSS if you use RiveScript in a web application). The `<star>`` tags
+from obvious XSS if you use RiveScript in a web application). The `<star>` tags
in RiveScript will capture the user's "raw" input, so you can write replies to
get the user's e-mail address or store foreign characters in their name.
This has so far only been tested when run under Node. When served through a
web server, take extra care that your server sends the correct content encoding
with the RiveScript source files (`Content-Type: text/plain; charset=utf-8`).
+## BUILDING
+
+Grunt options:
+
+* `grunt` - Builds the minified `lib/rivescript.min.js`
+* `grunt jshint` - Runs JS linting on `rivescript.js`
+* `grunt watch` - For development - watches `rivescript.js` for changes and
+ automatically minifies it.
+* `grunt connect:server` - Starts a local web server and opens `eg/chat.html`
+ for local testing and demoing.
+* `grunt nodeunit` - Run unit tests.
+
## LICENSE
```
Oops, something went wrong.

0 comments on commit 1c2bf8b

Please sign in to comment.