Permalink
Browse files

feat(package.json): tdoc-V1.0.0强势登场!赶快来体验吧!与其让时间给生命一个界限,不如让空间给生命一个境界!

  • Loading branch information...
HuYuee committed Dec 13, 2017
1 parent e7d7996 commit c9a0ae7057206078df205479db8c1712d1ad9d1c
View
@@ -0,0 +1,45 @@
<a name="0.0.20"></a>
## [0.0.20](https://github.com/iuap-design/tdoc/compare/v0.0.19...v0.0.20) (2017-12-13)
<a name="0.0.19"></a>
## [0.0.19](https://github.com/iuap-design/tdoc/compare/v0.0.18...v0.0.19) (2017-07-13)
<a name="0.0.18"></a>
## [0.0.18](https://github.com/iuap-design/tdoc/compare/v0.0.17...v0.0.18) (2017-07-13)
<a name="0.0.17"></a>
## [0.0.17](https://github.com/iuap-design/tdoc/compare/v0.0.16...v0.0.17) (2017-07-12)
<a name="0.0.16"></a>
## [0.0.16](https://github.com/iuap-design/tdoc/compare/v0.0.14...v0.0.16) (2017-07-12)
<a name="0.0.14"></a>
## [0.0.14](https://github.com/iuap-design/tdoc/compare/v0.0.13...v0.0.14) (2017-07-12)
<a name="0.0.13"></a>
## [0.0.13](https://github.com/iuap-design/tdoc/compare/v0.0.12...v0.0.13) (2017-07-11)
<a name="0.0.12"></a>
## [0.0.12](https://github.com/iuap-design/tdoc/compare/v0.0.11...v0.0.12) (2017-07-11)
<a name="0.0.11"></a>
## 0.0.11 (2017-07-11)
View
@@ -0,0 +1,234 @@
'use strict';
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
var fs = require('fs');
var sysPath = require('path');
var colors = require('colors');
var mkdirp = require('mkdirp');
var artTemplate = require('art-template');
var childProcess = require('child_process');
var marked = require('marked');
var glob = require('glob');
var fse = require('fs-extra');
var parsers = require('../parsers');
artTemplate.config('escape', false);
artTemplate.helper('markdown', function (content) {
return marked(content);
});
artTemplate.helper('anchor', function (name) {
return name ? name.replace(/[\.\:]/g, '-') : '';
});
artTemplate.helper('txt', function (html) {
return html ? html.replace(/\<\/?[^\>]*\>/g, '') : '';
});
function doParser(cwd, filePath, ignore, compile, options, conf) {
var extName = sysPath.extname(filePath),
parser;
if (compile) {
parsers.some(function (p) {
if (p.type == compile) {
parser = p;
return true;
}
});
} else {
parsers.some(function (p) {
if (p.extNames.indexOf(extName) > -1) {
parser = p;
return true;
}
});
}
if (parser) {
var files = glob.sync(filePath, {
cwd: cwd,
ignore: ignore || []
}),
options = _extends({
files: files
}, conf.options[parser.type] || {}, options || {});
if (files.length) {
var contents = files.map(function (fp) {
var content = fs.readFileSync(sysPath.join(cwd, fp), 'UTF-8');
if (options.source) {
var dp = sysPath.join(conf.dest, 'static', sysPath.dirname(fp));
mkdirp.sync(dp);
fs.writeFileSync(sysPath.join(dp, sysPath.basename(fp) + '.html'), 'UTF-8');
console.log(('√ 生成文件: ' + sysPath.join(dp, sysPath.basename(fp) + '.html')).yellow);
}
return content;
});
var ret = parser.parser(contents, options, conf);
return ret;
} else {
console.log(('X ' + filePath + ' 未找到文件。').red);
}
} else {
console.log(('X ' + extName + ' 未找到编译器。').red);
}
return {};
}
module.exports = function (cwd, conf) {
conf.cwd = cwd;
conf.options = conf.options || {};
var render = artTemplate.compile(conf.templateContent);
var resources = conf.resources || {};
// build增加其他静态资源输出
var basePath = sysPath.join(process.cwd(), conf.rootDir);
var outPath = conf.dest;
fse.copySync(basePath, outPath, { filter: function filter(single) {
var fileType = sysPath.extname(single);
if (fileType != '.md') {
return true;
} else {
return false;
}
} });
if (conf.pages) {
conf.pages.forEach(function (page) {
var data = {},
common = conf.common || {};
data.name = conf.name;
data.title = common.title + ' ' + page.title;
data.footer = common.footer;
data.home = common.home;
data.homeUrl = common.homeUrl;
data.navbars = common.navbars.map(function (item) {
return {
name: item.name,
url: item.url,
target: item.target || 'self',
active: item.name == conf.name
};
});
data.tabs = conf.pages.map(function (item) {
return {
name: item.name,
url: item.url,
title: item.title,
active: item.name == page.name
};
});
data.banner = page.banner;
if (page.intro) {
var introPath = sysPath.join(cwd, page.intro);
if (fs.existsSync(introPath)) {
data.intro = marked(fs.readFileSync(introPath, 'UTF-8'));
}
}
if (page.content && (!conf.buildPages.length || conf.buildPages.indexOf(page.name) > -1)) {
if (page.content.multi) {
var navs = page.content.pages.map(function (p) {
return {
name: p.name,
sub: !!p.sub,
blank: !p.content,
url: page.name + '-' + p.name + '.html'
};
});
page.content.pages.forEach(function (p, index) {
if (p.content) {
var curNavs = navs.slice(0);
data.article = doParser(cwd, p.content, p.ignore, p.compile, p.options, conf);
if (data.article.menus) {
curNavs.splice.apply(curNavs, [index + 1, 0].concat(data.article.menus.filter(function (item) {
return !item.sub;
})).map(function (item) {
item.sub = true;
return item;
}));
}
data.article.sidebars = curNavs;
data.article.name = p.name;
fs.writeFileSync(sysPath.join(conf.dest, page.name + '-' + p.name + '.html'), render(data));
console.log(('√ 生成文件: ' + sysPath.join(conf.dest, page.name + '-' + p.name + '.html')).yellow);
}
});
data.article = doParser(cwd, page.content.index, page.indexIngore, page.indexCompile, page.content.indexOptions, conf);
data.article.sidebars = navs;
} else if (typeof page.content == 'string') {
data.article = doParser(cwd, page.content, page.ignore, page.compile, page.options, conf);
if (data.article.menus && data.article.menus.length && !data.article.sidebars) {
data.article.sidebars = data.article.menus;
}
} else {
var navs = [],
blocks = [];
page.content.blocks.forEach(function (block) {
if (block.name) {
navs.push({
name: block.name,
sub: block.sub || false
});
}
if (typeof block.content == 'string') {
var ret = doParser(cwd, block.content, block.ignore, block.compile, block.options, conf);
if (block.name && !block.sub && ret.menus) {
ret.menus.forEach(function (item) {
if (!item.sub) {
navs.push({
name: item.name,
sub: true
});
}
});
}
ret.name = block.name;
ret.sub = block.sub || false;
blocks.push(ret);
} else {
blocks.push({
type: 'html',
name: block.name,
sub: false,
content: ''
});
}
});
data.article = {
type: 'block'
};
if (page.content.sidebar) {
data.article.sidebars = navs;
}
data.article.blocks = blocks;
}
fs.writeFileSync(sysPath.join(conf.dest, page.name + '.html'), render(data));
console.log(('√ 生成文件: ' + sysPath.join(conf.dest, page.name + '.html')).yellow);
}
});
}
for (var key in resources) {
try {
childProcess.execSync('cp -r ' + sysPath.join(cwd, resources[key]) + ' ' + sysPath.join(conf.dest, key));
} catch (e) {
console.log(('X 资源 ' + key + ' 复制失败').red);
console.log(e.toString().red);
}
}
};
module.exports.usage = '构建文档';
module.exports.setOptions = function (optimist) {
optimist.alias('t', 'template');
optimist.describe('t', '模板路径');
optimist.alias('p', 'page');
optimist.describe('p', '选择生成的页面,默认生成所有');
optimist.alias('w', 'watch');
optimist.describe('w', '监控文件更改,自动编译');
optimist.alias('o', 'output');
optimist.describe('o', '指定输出目录');
};
View
@@ -0,0 +1,8 @@
'use strict';
module.exports = {
init: require('./new.js'),
// init: require('./init.js'),
build: require('./build.js'),
server: require('./server.js')
};
View
@@ -0,0 +1,47 @@
'use strict';
var fs = require('fs');
var sysPath = require('path');
var cpr = require('cpr');
var configTPL = {
name: "",
common: "",
pages: []
};
module.exports = function (cwd, conf) {
if (conf.template) {
if (conf.template == true) {
console.log('X 参数为路径!'.red);
} else {
cpr(sysPath.join(__dirname, '../../template'), sysPath.join(cwd, conf.template), {
deleteFirst: true,
overwrite: true,
confirm: false
}, function (err, files) {
if (err) {
console.log('X 资源拷贝失败!'.red);
} else {
console.log('√ 初始化自定义模板成功!'.green);
}
});
}
} else {
var confFilePath = sysPath.join(cwd, 'tdoc.config.json');
if (fs.existsSync(confFilePath)) {
console.log('X 配置文件已经存在!'.red);
} else {
fs.writeFileSync(confFilePath, JSON.stringify(configTPL, {}, 4), 'UTF-8');
console.log('√ 生成 tdoc.config.json 成功!'.green);
console.log('√ 如想快速上手!可以查看配置说明,地址:https://github.com/iuap-design/tdoc/blob/master/doc/config.md#配置内容'.green);
}
}
};
module.exports.usage = '初始化配置文件';
module.exports.setOptions = function (optimist) {
optimist.alias('t', 'template');
optimist.describe('t', '初始化自定义模板');
};
Oops, something went wrong.

0 comments on commit c9a0ae7

Please sign in to comment.