Skip to content
This repository has been archived by the owner on Mar 7, 2023. It is now read-only.

Commit

Permalink
Merge branch 'feature/refactor-plugins' into develop
Browse files Browse the repository at this point in the history
resolve #28
  • Loading branch information
bluemir committed Apr 8, 2016
2 parents 8265a26 + 0e695ed commit 15d9d42
Show file tree
Hide file tree
Showing 13 changed files with 208 additions and 173 deletions.
27 changes: 19 additions & 8 deletions app/pluginLoader.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
var Q = require("q");
var express = require("express");
var wikiFS = require("../app/wikiFS");
var PREFIXS = ["", "../plugins/"];

var plugins = config.plugins.map(load).filter(notNull);
var join = require("path").join;
var PREFIXS = ["", "wikinote-", join(config.wikinotePath, ".app/plugins"), "../plugins/"];

var loader = new Loader();

plugins.forEach(function(plugin){
plugin(loader.Interface);
var plugins = config.plugins.map(normalize).map(load).filter(notNull).forEach(function(plugin){
plugin.init(loader.Interface, plugin.config);
});

exports.menus = function(){
Expand Down Expand Up @@ -40,15 +39,27 @@ exports.assets = function(app){
}
}

function load(name){
function normalize(config){
if(typeof config == "string") {
return {name : config};
}

return config;
}
function load(config){
for(var i = 0; i < PREFIXS.length; i++){
try {
return require(PREFIXS[i] + name);
return {
init : require(PREFIXS[i] + config.name),
name : config.name,
config : config
};
} catch(e) {
continue;
}
}
console.error("cannot find plugin ", name);
console.error("cannot find plugin ", config.name);
return null;
}
function notNull(e){
return e !== null;
Expand Down
20 changes: 0 additions & 20 deletions config/config.template

This file was deleted.

53 changes: 53 additions & 0 deletions config/help.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# WikiNote Configuration File Guide

WikiNote는 commnad line과 Config File 둘다 사용이 가능합니다.
다만 command line의 arguments는 일부 제한될수도 있습니다.
command line 옵션의 설명을 보려면 -h 옵션을 사용하세요.

## Config File Example

```
port : 4000
frontPage : "front-page"
autoBackup : false
security :
salt : 123456789
defaultPermissions :
- read
- write
wikiname : WikiNote
plugins :
- remark
- name : disqus
shortname : <short name>
```

## Plugin 설정

Plugin의 이름은 두가지 방법으로 지정할수 있습니다.
1. 이름 바로 넣기
* plugin에 다른 config정보를 전달하지 못합니다.
2. 객체의 name 에 지정하기
* plugin에 지정된 객체를 넘겨주므로 추가적인 설정이 가능합니다.

Plugin은 다음과 같은 규칙으로 모듈을 찾습니다.

* 이름을 npm package search 방법으로 검색
* 이름에 "wikinote-"라는 prefix를 붙여 npm package search 방법으로 검색
* <wikitnote data dir>/.app/plugins 에서 이름으로 검색
* 소스 폴더의 plugins에서 이름으로 검색(기본 플러그인)

### 기본 plugins

wikinote 에서는 기본적으로 3개의 plugin을 제공합니다.

* comment
* 심플한 comment를 달수 있으며 recaptcha를 사용해서 bot을 막을수 있습니다.
* private key 와 public key를 지정해야 합니다.
* disqus
* disqus를 별도의 코드 없이 바로 붙일수 있습니다.
* shortname을 옵션으로 지정해야 합니다.
* remark
* remark를 presentation 용으로 사용합니다.
* presentation
* deprecated
39 changes: 21 additions & 18 deletions config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,30 @@ var resolve = require("path").resolve;
var dirname = require("path").dirname;
var swig = require("swig");

var wikinotePathOption = {
type : "string",
describe : "wikinote data path",
nargs : 1,
"default" : join(env.HOME, "wiki")
}

var WIKINOTE_PATH = yargs
.option("wikinote-path", wikinotePathOption)
.option("wikinote-path",{
type : "string",
nargs : 1,
"default": join(env.HOME, "wiki")
})
.argv["wikinote-path"] || env.WIKINOTE_PATH;
yargs.reset();

var argv = yargs
.usage("Usage : $0 [options]")
.env("WIKINOTE")
.locale("en")
.help("h").alias("h", "help")
.option("wikinote-path", wikinotePathOption)
.option("wikinote-path",{
type : "string",
describe : " Location of wikinote data",
nargs : 1,
"default" : WIKINOTE_PATH
})
.option("c", {
type : "string",
alias : "config-file",
describe : "config file path",
describe : "Location of config file",
config : true,
nargs : 1,
configParser : function(configPath){
Expand All @@ -48,34 +51,34 @@ var argv = yargs
})
.option("p", {
alias : "port",
describe :"port number",
describe :"Port number",
nargs : 1,
"default" : 3000
})
.option("n", {
type : "string",
alias : ["name", "wikiname"],
nargs : 1,
describe : "wikinote name",
describe : "Set WikiNote name",
"default" : "WikiNote"
})
.option("f", {
alias : "front-page",
type : "string",
describe : "set front page name",
describe : "Front page name & url",
nargs : 1,
"default" : "front-page"
})
.option("b", {
type : "boolean",
alias : "auto-backup",
describe : "auto backup with git",
describe : "Automatic backup with git",
nargs : 1,
"default" : true
})
.option("save", {
type : "boolean",
describe : "save option to file",
describe : "Save option to config file",
})
.argv;

Expand Down Expand Up @@ -114,10 +117,9 @@ function $load(){
}

function $save(){
var data = swig.renderFile(__dirname + "/config.template", argv);
var data = yaml.safeDump(this);
mkdirp.sync(dirname(argv["config-file"]));
console.log("overwrite config");
console.log(data);
console.log("overwrite config to " + argv["config-file"]);
fs.writeFileSync(argv["config-file"], data);
return this;
}
Expand All @@ -137,3 +139,4 @@ function overwrite(dest, src){
}
return dest;
}

2 changes: 1 addition & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ gulp.task('serve', ['less'], function(){

server.start();

gulp.watch(['wikinote.js', 'routes/**/*.js', 'test/**/*.js', 'app/**/*.js', 'config/**/*.js', 'views/**/*.html'], function(){
gulp.watch(['wikinote.js', 'routes/**/*.js', 'test/**/*.js', 'app/**/*.js', 'config/**/*.js', 'views/**/*.html', "plugins/**/*.js"], function(){
server.start.bind(server)();
});

Expand Down
Loading

0 comments on commit 15d9d42

Please sign in to comment.