Comparing version 0.4.5 to 0.4.6
@@ -10,6 +10,2 @@ "use strict"; | ||
var initConfig = { | ||
lifeCycle: ["_awake", "awake"] | ||
}; | ||
var core = exports.core = function core(_ref) { | ||
@@ -21,16 +17,7 @@ var _ = _ref._, | ||
_.hooks = {}; | ||
_.config = initConfig; | ||
_.hooks._hooks = [_plugins._hooks]; | ||
_.hooks._mount = [_plugins._mount]; | ||
_.$use = (0, _plugins.$use)({ _: _ }); | ||
_.$use({ | ||
_hooks: function _hooks() { | ||
return { | ||
_config: _plugins._config, | ||
_command: _plugins._command | ||
}; | ||
} | ||
}); | ||
_.$use(parms); | ||
return _; | ||
}; |
@@ -141,2 +141,3 @@ "use strict"; | ||
var initConfig = { lifeCycle: ["_awake", "awake"] }; | ||
var _config = exports._config = function _config(_ref9) { | ||
@@ -148,4 +149,8 @@ var _ = _ref9._, | ||
if (_.config) { | ||
_.config = initConfig; | ||
} | ||
_.config = (0, _utils.ConfigMerger)(_.config, _val); | ||
}; | ||
var _command = exports._command = function _command(_ref10) { | ||
@@ -152,0 +157,0 @@ var _ = _ref10._, |
{ | ||
"name": "menhera", | ||
"version": "0.4.5", | ||
"version": "0.4.6", | ||
"main": "dist", | ||
@@ -15,2 +15,3 @@ "files": [ | ||
"devDependencies": { | ||
"@types/koa": "^2.0.44", | ||
"@types/minimist": "^1.2.0", | ||
@@ -20,2 +21,4 @@ "babel-cli": "^6.26.0", | ||
"babel-preset-stage-3": "^6.24.1", | ||
"koa": "^2.5.0", | ||
"menhera": "^0.4.5", | ||
"minimist": "^1.2.0", | ||
@@ -22,0 +25,0 @@ "nodemon": "^1.11.0" |
@@ -10,30 +10,32 @@ # Menhera | ||
```js | ||
import { EventEmitter } from "events"; | ||
import Menhera, { _methods, _data } from "menhera"; | ||
import minimist from "minimist"; | ||
import Menhera from "menhera"; | ||
export const CLI = { | ||
name: "CLI", | ||
_data() { | ||
return { | ||
structs: {}, | ||
Event: new EventEmitter() | ||
}; | ||
}, | ||
awake() { | ||
let { _, ...flags } = minimist(process.argv.slice(2)); | ||
let [command = "*", ...inputs] = _; | ||
const { h, help } = flags; | ||
const _data = ({ _key, _val, cp }) => { | ||
const { data } = _val; | ||
console.log(data); | ||
}; | ||
this.Event.emit(command, { inputs, flags }); | ||
}, | ||
const _ = new Menhera({ | ||
_hooks: () => ({ | ||
onCli({ _key, _val, cp }) { | ||
for (let [key, val] of Object.entries(_val)) { | ||
const { exec } = val; | ||
this.structs[key] = val; | ||
if (exec) { | ||
this.Event.on(key, exec.bind(cp)); | ||
} | ||
} | ||
_data | ||
}), | ||
_data: { | ||
data: "foo" | ||
} | ||
}).$use({ | ||
_data: { | ||
data: "bar" | ||
} | ||
}); | ||
``` | ||
```js | ||
import Menhera from "menhera"; | ||
const _data = { | ||
name: "data", | ||
_hooks: () => ({ | ||
_data: ({ _key, _val, cp }) => { | ||
const { data } = _val; | ||
console.log(data); | ||
} | ||
@@ -43,31 +45,14 @@ }) | ||
const cliTest = { | ||
name: "clitest", | ||
onCli: { | ||
"*": { | ||
exec() { | ||
console.log("help"); | ||
} | ||
}, | ||
test: { | ||
exec({ inputs, flags }) { | ||
console.log(inputs, flags); | ||
} | ||
} | ||
} | ||
}; | ||
const _ = new Menhera({ | ||
_hooks: () => ({ | ||
_methods, | ||
_data | ||
}), | ||
_mount: { | ||
cli: [CLI, cliTest] | ||
foo: [_data] | ||
}, | ||
_data: { | ||
data: "foo" | ||
} | ||
}).$use({ | ||
_command: { | ||
run: true | ||
_data: { | ||
data: "bar" | ||
} | ||
}); | ||
``` |
12334
9
306
57