Skip to content

Commit

Permalink
Add theme creation.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Oct 25, 2015
1 parent 95b8236 commit 7a28d28
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 8 deletions.
5 changes: 4 additions & 1 deletion .bin/idoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ commander
commander
.option("-C, --Create <file>", "Select Directory Makefile.")
.option("-v", "App version information.")
.option('-i, init','init a documentation.')
.option('-i, init','Init a documentation.')
.option('-b, build','Markdown produces static pages document.')
.option('-w, watch','Listener "md" file is automatically generated pages.')
.option('-s, server','Open local static html server.')
.option('-c, clean','Clear the generate static files.')
.option('-t, theme','Choose a theme.')
.option('-d, deploy','Publish to a gh-pages branch on GitHub.')

commander
Expand All @@ -33,6 +34,8 @@ commander
log(' $ idoc server');
log(' $ idoc clean');
log(' $ idoc deploy');
log(' $ idoc theme');
log(' $ idoc -t ~/git/idoc-theme-slate/');


// 图片文字 http://patorjk.com/software/taag/#p=testall&f=Graffiti&t=idoc
Expand Down
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var watch = require('./lib/watch');
var file = require('./lib/file');
var clean = require('./lib/clean');
var deploy = require('./lib/deploy');
var theme = require('./lib/theme');
var color = require('colorful');
var path = require('path');
var server = require('ssr');
Expand Down Expand Up @@ -44,5 +45,8 @@ module.exports = function(commander){
if(commander.deploy){
return deploy(commander);
}
if(commander.theme){
return theme.runTask(commander);
}
commander.outputHelp();
}
14 changes: 12 additions & 2 deletions lib/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,18 @@ function build(commander,changeFile){
// 载入配置文件
var pkg = require(path.resolve('package.json'));

// 模板目录
template = path.dirname(__dirname) + '/theme/' + pkg.idoc.theme;

// 指定模板目录
if(commander.theme && commander.args.length > 0) template = commander.args[0];
else{
// 模板目录
template = path.dirname(__dirname) + '/theme/' + pkg.idoc.theme;
if(!file.isDir(template)){
template = process.cwd()+ '/' +pkg.idoc.theme;
}
}
// 皮肤目录不存在判断
if(!file.isDir(template)) return log(color.red('\nTheme directory does not exist.!\n') )

var name = pkg.name;
var idocmd = pkg.idoc.md;
Expand Down
3 changes: 2 additions & 1 deletion lib/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,14 @@ function isDir(_path){

//获取路径下面的所有dir
function currentDir(_path){
if(exists(_path))
if(!exists(_path)) return [];
return _.filter(fs.readdirSync(_path),function(dirname){
return isDir(_path+dirname);
})
}
//获取路径下面的所有file
function currentFile(_path){
if(!exists(_path)) return [];
return _.filter(fs.readdirSync(_path),function(dirname){
return isFile(_path+dirname);
})
Expand Down
5 changes: 2 additions & 3 deletions lib/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ var _ = require('underscore');
var color = require('colorful');
var copy = require('./copy');
var file = require('./file');
var theme = require('./theme');
var menu_json = require('./menu_json');
var log = console.log;

Expand Down Expand Up @@ -61,9 +62,7 @@ function runTask(commander){
type: "list",
name: "idoctheme",
message: "Choose a theme.",
choices: function(){
return file.currentDir(template + '/theme/');
}
choices: theme.themeList()
},{
message: 'Author',
name: 'author',
Expand Down
56 changes: 55 additions & 1 deletion lib/theme.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,57 @@
/**
* 选择主题命令
*/
*/
var inquirer = require('inquirer');
var file = require('./file');
var path = require('path');
var build = require('./build');
var server = require('ssr');

var template = path.dirname(__dirname);

var theme = module.exports = {
runTask:runTask,
themeList:themeList
}

function runTask(commander){

var pkg = require(path.resolve('package.json'));

if(commander.theme && commander.args.length > 0){
build(commander);
server();
}else{

inquirer.prompt([{
type: "list",
name: "theme",
message: " Choose a theme.",
choices: themeList()
}],function(answers){
pkg.idoc.theme = answers.theme;
file.write(process.cwd() + '/package.json',JSON.stringify(pkg, null, 4));
build(commander);
})

}

}

/**
* [themeList 获取主题列表]
* @return {[type]} [array]
*/
function themeList(){
var _def = file.currentDir(template + '/theme/');

var _m = file.currentDir(process.cwd() + '/')

for (var i = 0; i < _m.length; i++) {
if(/^idoc\-theme./.test(_m[i])){
_def.push(_m[i])
}
};

return _def
}

0 comments on commit 7a28d28

Please sign in to comment.