Skip to content

Commit

Permalink
Replace with coffee script version
Browse files Browse the repository at this point in the history
  • Loading branch information
xelaris committed Sep 17, 2015
1 parent 48a8a0d commit dfcc65f
Show file tree
Hide file tree
Showing 8 changed files with 29,621 additions and 63 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/bower_components/
node_modules/
build/
97 changes: 97 additions & 0 deletions Cakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
{spawn} = require 'child_process'
{ncp} = require 'ncp'
mkdirp = require 'mkdirp'
fs = require 'fs'

file = 'WsseDynamicValue.coffee'
identifier = 'net.xelaris.PawExtensions.WsseDynamicValue'

extensions_dir = "#{ process.env.HOME }/Library/Containers/com.luckymarmot.Paw/Data/Library/Application Support/com.luckymarmot.Paw/Extensions/"
build_root_dir = "build"
build_dir = "#{ build_root_dir }/#{ identifier }"

# compile CoffeeScript
build_coffee = (callback) ->
coffee = spawn 'coffee', ['-c', '-o', build_dir, file]
coffee.stderr.on 'data', (data) ->
process.stderr.write data.toString()
coffee.stdout.on 'data', (data) ->
process.stdout.write data.toString()
coffee.on 'exit', (code) ->
if code is 0
callback?()
else
console.error "Build failed with error: #{ code }"

# copy files to build directory
build_copy = () ->
fs.writeFileSync "#{ build_dir }/README.md", fs.readFileSync("./README.md")
fs.writeFileSync "#{ build_dir }/LICENSE", fs.readFileSync("./LICENSE")
fs.writeFileSync "#{ build_dir }/forge.bundle.js", fs.readFileSync("./forge.bundle.js")

# build: build CoffeeScript and copy files to build directory
build = (callback) ->
# mkdir build dir
mkdirp build_dir, (err) ->
if err
console.error err
else
build_coffee () ->
build_copy()
callback?()

# install: copy files to Extensions directory
install = (callback) ->
ncp build_dir, "#{ extensions_dir }/#{ identifier }", (err) ->
if err
console.error err
else
callback?()

# archive: create a zip archive from the build
archive = (callback) ->
zip_file = "#{ identifier.split('.').pop() }.zip"

# go to build dir
process.chdir "#{ build_root_dir }/"

# delete any previous zip
if fs.existsSync zip_file
fs.unlinkSync zip_file

# zip
zip = spawn 'zip', ["-r", zip_file, "#{ identifier }/"]
zip.stderr.on 'data', (data) ->
process.stderr.write data.toString()
zip.stdout.on 'data', (data) ->
process.stdout.write data.toString()
zip.on 'exit', (code) ->
if code is 0
callback?()
else
console.error "zip returned with error code: #{ code }"

task 'build', ->
build()

task 'test', ->
build () ->
# no test to run

task 'install', ->
build () ->
install()

task 'archive', ->
build () ->
archive()

task 'watch', ->
# find all files in directory
for filename in fs.readdirSync '.'
# only watch non-hidden files
if not filename.match(/^\./) and fs.lstatSync("./#{ filename }").isFile()
fs.watchFile "./#{ filename }", {persistent:true, interval:500}, (_event, _filename) ->
# when a file is changed, build and install
build () ->
install()
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,24 @@

A [Paw Extension](http://luckymarmot.com/paw/extensions/) that generates a dynamic WSSE header value.

## Development

### Build & Install

```shell
npm install
cake build
cake install
```

### Watch

During development, watch for changes:

```shell
cake watch
```

##License

This Paw Extension is released under the [MIT License](LICENSE). Feel free to fork, and modify!
Expand Down
41 changes: 41 additions & 0 deletions WsseDynamicValue.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
require "forge.bundle.js"

WsseDynamicValue = ->
this.username = ""

this.password = ""

this.evaluate = ->
time = (new Date()).toISOString()

nonce = forge.util.bytesToHex forge.random.getBytesSync 10
nonce64 = forge.util.encode64 nonce

md = forge.md.sha1.create()
md.update nonce + time + this.password
digest = forge.util.encode64 md.digest().getBytes()

"UsernameToken " +
"Username=\"#{@username}\", " +
"PasswordDigest=\"#{digest}\", " +
"Nonce=\"#{nonce64}\", " +
"Created=\"#{time}\"";

@title = ->
"WSSE"

@text = ->
@username

return

WsseDynamicValue.identifier = "net.xelaris.PawExtensions.WsseDynamicValue"

WsseDynamicValue.title = "WSSE Dynamic Value"

WsseDynamicValue.inputs = [
DynamicValueInput("username", "Username", "String"),
DynamicValueInput("password", "Password", "String")
]

registerDynamicValueClass WsseDynamicValue
40 changes: 0 additions & 40 deletions WsseDynamicValue.js

This file was deleted.

22 changes: 0 additions & 22 deletions bower.json

This file was deleted.

0 comments on commit dfcc65f

Please sign in to comment.