Last active
December 11, 2015 00:38
-
-
Save ishiduca/4517619 to your computer and use it in GitHub Desktop.
呼び出されるモジュール側から呼び出し(実行スクリプト)側のパスを取得する
This file contains hidden or 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
#!/usr/bin/env node | |
var path = require('path'); | |
var waf = require('w-a-f'); | |
waf().use(require(path.join(__dirname, 'middleware/wan'))()) | |
.use(require(path.join(__dirname, 'middleware/nyan'))()) | |
.use(require(path.join(__dirname, 'middleware/guu'))()) | |
.resume(); | |
// wan | |
// nyan | |
// guu | |
waf().use('guu').use('nyan').use('wan').resume(); | |
// guu | |
// nyan | |
// wan |
This file contains hidden or 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
module.exports = function () { | |
return funciton (next) { | |
console.log('guu'); | |
next(); | |
}; | |
}; |
This file contains hidden or 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
var path = require('path'); | |
function WAF () { | |
this.middlewares = []; | |
} | |
WAF.prototype.use = function (middleware, arg) { | |
'string' === typeof middleware && | |
(middleware = this.useHelp(middleware, arg)); | |
'function' === typeof middleware && | |
this.middlewares.push(middleware); | |
return this; | |
}; | |
WAF.prototype.useHelp = function (middleware_name, arg) { | |
return require(path.join( path.dirname(process.argv[1]) | |
, 'middleware', middleware_name ))(arg); | |
}; | |
WAF.prototype.resume = function () { | |
var that = this, i = 0, next = function () { | |
var m = that.middlewares[i++]; | |
'function' === typeof m && m(next); | |
}; | |
next(); | |
}; | |
module.exports = function () { | |
return new WAF; | |
}; |
This file contains hidden or 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
module.exports = function () { | |
return funciton (next) { | |
console.log('nyan'); | |
next(); | |
}; | |
}; |
This file contains hidden or 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
. | |
|-- app.js | |
|-- middleware | |
| |-- guu.js | |
| |-- nyan.js | |
| `-- wan.js | |
`-- node_modules | |
`-- w-a-f | |
|-- index.js | |
`-- package.json |
This file contains hidden or 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
module.exports = function () { | |
return funciton (next) { | |
console.log('wan'); | |
next(); | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment