zhangdocs 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/.bin/idoc.js +65 -0
  2. package/.github/FUNDING.yml +9 -0
  3. package/README.md +108 -0
  4. package/index.js +56 -0
  5. package/lib/build.js +126 -0
  6. package/lib/clean.js +43 -0
  7. package/lib/copy.js +215 -0
  8. package/lib/deploy.js +24 -0
  9. package/lib/file.js +148 -0
  10. package/lib/imgPath.js +20 -0
  11. package/lib/init.js +166 -0
  12. package/lib/menu_json.js +36 -0
  13. package/lib/menu_update.js +73 -0
  14. package/lib/nav.js +108 -0
  15. package/lib/pdf.js +66 -0
  16. package/lib/pk.json +13 -0
  17. package/lib/stylus.js +36 -0
  18. package/lib/theme.js +57 -0
  19. package/lib/toc.js +119 -0
  20. package/lib/watch.js +76 -0
  21. package/lib/whoami.js +23 -0
  22. package/package.json +41 -0
  23. package/theme/default/footer.ejs +3 -0
  24. package/theme/default/gitignore +22 -0
  25. package/theme/default/head.ejs +17 -0
  26. package/theme/default/header.ejs +34 -0
  27. package/theme/default/layout.ejs +16 -0
  28. package/theme/default/source/css/_partial/head_nav.styl +239 -0
  29. package/theme/default/source/css/_partial/highlight.styl +103 -0
  30. package/theme/default/source/css/_partial/markdown.styl +121 -0
  31. package/theme/default/source/css/_partial/reset.styl +101 -0
  32. package/theme/default/source/css/_partial/variables.styl +10 -0
  33. package/theme/default/source/css/main.styl +156 -0
  34. package/theme/default/source/img/forkgithub.png +0 -0
  35. package/theme/doc/footer.ejs +25 -0
  36. package/theme/doc/gitignore +22 -0
  37. package/theme/doc/head.ejs +17 -0
  38. package/theme/doc/header.ejs +34 -0
  39. package/theme/doc/layout.ejs +16 -0
  40. package/theme/doc/source/css/_partial/head_nav.styl +239 -0
  41. package/theme/doc/source/css/_partial/highlight.styl +103 -0
  42. package/theme/doc/source/css/_partial/markdown.styl +121 -0
  43. package/theme/doc/source/css/_partial/reset.styl +101 -0
  44. package/theme/doc/source/css/_partial/variables.styl +10 -0
  45. package/theme/doc/source/css/main.styl +164 -0
  46. package/theme/doc/source/img/forkgithub.png +0 -0
  47. package/theme/handbook/footer.ejs +3 -0
  48. package/theme/handbook/gitignore +22 -0
  49. package/theme/handbook/head.ejs +10 -0
  50. package/theme/handbook/header.ejs +14 -0
  51. package/theme/handbook/layout.ejs +15 -0
  52. package/theme/handbook/source/css/_partial/highlight.styl +103 -0
  53. package/theme/handbook/source/css/_partial/markdown.styl +120 -0
  54. package/theme/handbook/source/css/_partial/reset.styl +101 -0
  55. package/theme/handbook/source/css/_partial/variables.styl +9 -0
  56. package/theme/handbook/source/css/main.styl +175 -0
  57. package/theme/handbook/source/img/background.png +0 -0
  58. package/theme/handbook/source/img/forkgithub.png +0 -0
  59. package/theme/resume/footer.ejs +2 -0
  60. package/theme/resume/gitignore +22 -0
  61. package/theme/resume/head.ejs +16 -0
  62. package/theme/resume/layout.ejs +27 -0
  63. package/theme/resume/source/css/_partial/highlight.styl +103 -0
  64. package/theme/resume/source/css/_partial/markdown.styl +137 -0
  65. package/theme/resume/source/css/_partial/reset.styl +101 -0
  66. package/theme/resume/source/css/_partial/variables.styl +10 -0
  67. package/theme/resume/source/css/main.styl +50 -0
  68. package/theme/resume/source/js/jquery.2.1.4.min.js +5 -0
  69. package/theme/resume/source/js/pdfmake.js +17 -0
  70. package/theme/resume/source/js/vfs_fonts.js +1 -0
package/.bin/idoc.js ADDED
@@ -0,0 +1,65 @@
1
+ #!/usr/bin/env node
2
+
3
+ var commander = require('commander');
4
+ var appInfo = require('../package');
5
+ var idoc = require('..');
6
+ var log = console.log;
7
+ var safe = require('colors-cli/safe');
8
+
9
+ commander
10
+ .usage('[options]')
11
+ .description(' Simple document generation tool! \n version: ' + appInfo.version)
12
+ .version(appInfo.version);
13
+
14
+
15
+ commander
16
+ .option("-C, --Create <file>", "Select Directory Makefile.")
17
+ .option("-v", "App version information.")
18
+ .option('-i, init', 'Init a documentation.')
19
+ .option('-b, build', 'Markdown produces static pages document.')
20
+ .option('-w, watch', 'Listener "md" file is automatically generated pages.')
21
+ .option('-s, server', 'Open local static html server.')
22
+ .option('-c, clean', 'Clear the generate static files.')
23
+ .option('-t, theme', 'Choose a theme.')
24
+ .option('-d, deploy', 'Publish to a gh-pages branch on GitHub.')
25
+ .option('-p, pdf', 'PDF generation.')
26
+
27
+ commander
28
+ .on('--help', function () {
29
+ log(' Examples:'.bold.blue);
30
+ log('')
31
+ log(' $ idoc init');
32
+ log(' $ idoc init [path] ');
33
+ log(' $ idoc init [path] -C ~/idoc/');
34
+ log(' $ idoc watch');
35
+ log(' $ idoc server');
36
+ log(' $ idoc clean');
37
+ log(' $ idoc deploy');
38
+ log(' $ idoc theme');
39
+ log(' $ idoc -t ~/git/idoc-theme-slate/');
40
+
41
+
42
+ // 图片文字 http://patorjk.com/software/taag/#p=testall&f=Graffiti&t=idoc
43
+
44
+ log('')
45
+ log(" ,, ,, ".bold.x241)
46
+ log(" db `7MM ".bold.x241)
47
+ log(" MM ".bold.x241)
48
+ log(" `7MM ,M\"\"bMM ,pW\"Wq. ,p6\"bo ".bold.x241)
49
+ log(" MM ,AP MM 6W' `Wb 6M' OO ".bold.x241)
50
+ log(" MM 8MI MM 8M M8 8M ".bold.x241)
51
+ log(" MM `Mb MM YA. ,A9 YM. , ".bold.x241)
52
+ log(" .JMML.`Wbmd\"MML.`Ybmd9' YMbmd' ".bold.x241)
53
+ log('')
54
+ log('')
55
+
56
+ })
57
+
58
+ commander.parse(process.argv);
59
+
60
+ if (!process.argv[2]) {
61
+ commander.help();
62
+ console.log();
63
+ }
64
+
65
+ idoc(commander)
@@ -0,0 +1,9 @@
1
+ # These are supported funding model platforms
2
+
3
+ github: [jaywcjlove]
4
+ patreon: # Replace with a single Patreon username
5
+ open_collective: # Replace with a single Open Collective username
6
+ ko_fi: # Replace with a single Ko-fi username
7
+ tidelift: npm/idoc
8
+ community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9
+ custom: https://jaywcjlove.github.io/sponsor.html
package/README.md ADDED
@@ -0,0 +1,108 @@
1
+
2
+ # AIP文档生成工具
3
+
4
+ 简单的文档生成工具! [生成的页面预览效果](http://jaywcjlove.github.io/idoc) [Details document](http://jaywcjlove.github.io/idoc)
5
+
6
+ ```
7
+ ,, ,,
8
+ db `7MM
9
+ MM
10
+ `7MM ,M""bMM ,pW"Wq. ,p6"bo
11
+ MM ,AP MM 6W' `Wb 6M' OO
12
+ MM 8MI MM 8M M8 8M
13
+ MM `Mb MM YA. ,A9 YM. ,
14
+ .JMML.`Wbmd"MML.`Ybmd9' YMbmd'
15
+ ```
16
+
17
+ # 全局安装
18
+
19
+ ```bash
20
+ $ sudo npm install idoc -g
21
+ ```
22
+
23
+
24
+ # 收录使用者
25
+
26
+ ## 提交收录
27
+
28
+ 1. 直接在 `README.md` 中添加然后 `Pull requests` 。
29
+
30
+ 2. 在 [issues](https://github.com/jaywcjlove/idoc/issues) 中提交你的连接,我讲收录在此。格式如下:
31
+
32
+ ```bash
33
+ # 我的 xxx 使用 idoc 生成文档
34
+ [文档名称](连接地址)
35
+ ```
36
+
37
+
38
+ ## 收录文档
39
+
40
+ 这些文档是都是使用idoc生成的页面哦,可以提交用idoc生成的文档哦。这里[添加](https://github.com/jaywcjlove/idoc/issues)
41
+
42
+ 1. [JSLite.io - 这个是现代浏览器类似jQuery的库,体积小。](http://jslite.github.io/JSLite/)
43
+ 2. [idoc - 通过markdown生成静态页面的工具](http://jaywcjlove.github.io/idoc)
44
+ 3. [store.js - js本地存储操作](http://jaywcjlove.github.io/store.js)
45
+ 4. [cookie.js - js本地cookie操作](http://jslite.io/cookie.js/)
46
+ 5. [iNotify - 浏览器各种方法通知](http://jaywcjlove.github.io/iNotify)
47
+ 6. [Nodejs教程](http://nodejs.jakeyu.top/)
48
+ 7. [java代码片段](http://java-snippets.javaos.cc/)
49
+
50
+
51
+ # 命令使用
52
+
53
+ 命令使用帮助。
54
+
55
+
56
+ ```sh
57
+ Usage: idoc [options]
58
+
59
+ Simple document generation tool!
60
+
61
+ Options:
62
+
63
+ -h, --help output usage information
64
+ -V, --version output the version number
65
+ -C, --Create <file> Select Directory Makefile.
66
+ -v App version information.
67
+ -i, init Init a documentation.
68
+ -b, build Markdown produces static pages document.
69
+ -w, watch Listener "md" file is automatically generated pages.
70
+ -s, server Open local static html server.
71
+ -c, clean Clear the generate static files.
72
+ -t, theme Choose a theme.
73
+ -d, deploy Publish to a gh-pages branch on GitHub.
74
+
75
+ Examples:
76
+
77
+ $ idoc init
78
+ $ idoc init [path]
79
+ $ idoc init [path] -C ~/idoc/
80
+ $ idoc watch
81
+ $ idoc server
82
+ $ idoc clean
83
+ $ idoc deploy
84
+ $ idoc theme
85
+ $ idoc -t ~/git/idoc-theme-slate/
86
+ ```
87
+
88
+
89
+ # TODO
90
+
91
+ - [x] idoc 基本命令定义
92
+ - [x] 添加 build 命令,markdown生成静态页面
93
+ - [x] 添加 watch 命令,监控markdown文件自动生成HMTL页面
94
+ - [x] 默认模板制作
95
+ - [x] 树形菜单生成
96
+ - [x] 添加 server 命令,预览生成的静态页面
97
+ - [x] 添加多页面导航菜单
98
+ - [x] 添加 clean 命令
99
+ - [x] 静态资源相对路径引用
100
+ - [x] github 连接地址添加
101
+ - [x] `idoc deploy` === `git push -f origin gh-pages`
102
+ - [ ] 配置文件配置下载 md 文件
103
+ - [x] 解决server 端口冲突
104
+ - [ ] 判断是否存在markdown树形导航菜单
105
+ - [x] 第二个模板制作
106
+ - [x] 模板切换命令
107
+ - [ ] api 检索功能
108
+ - [x] 兼容windows路径(cmd工具冒得问题嘞)
package/index.js ADDED
@@ -0,0 +1,56 @@
1
+ var init = require('./lib/init');
2
+ var build = require('./lib/build');
3
+ var watch = require('./lib/watch');
4
+ var file = require('./lib/file');
5
+ var clean = require('./lib/clean');
6
+ var deploy = require('./lib/deploy');
7
+ var pdf = require('./lib/pdf');
8
+ var theme = require('./lib/theme');
9
+ var color = require('colors-cli');
10
+ var path = require('path');
11
+ var server = require('ssr');
12
+
13
+ module.exports = function(commander){
14
+ var pkgurl = path.resolve('package.json');
15
+
16
+ if(commander.V) return console.log('\n'+commander._version+'\n');
17
+
18
+ // 判断是否初始化
19
+ if(!commander.init){
20
+ if(!file.exists(pkgurl)) {
21
+ return console.log( color.red('\n In the project root directory to initialize, '+
22
+ 'run the "idoc init" command. \n') );
23
+ }
24
+ // 载入配置文件
25
+ var pkg = require(pkgurl);
26
+
27
+ if(file.exists(pkgurl)&&!pkg.idoc){
28
+ return console.log( color.red('\n This is not the "idoc" project. \n') );
29
+ }
30
+ }else{
31
+ return init(commander);
32
+ }
33
+ if(commander.build){
34
+ return build(commander);
35
+ }
36
+ if(commander.watch){
37
+ return watch(commander,build);
38
+ }
39
+ if(commander.server){
40
+ server();
41
+ return watch(commander,build);
42
+ }
43
+ if(commander.clean){
44
+ return clean(commander);
45
+ }
46
+ if(commander.deploy){
47
+ return deploy(commander);
48
+ }
49
+ if(commander.theme){
50
+ return theme.runTask(commander);
51
+ }
52
+ // if(commander.pdf){
53
+ // return pdf(commander);
54
+ // }
55
+ commander.outputHelp();
56
+ }
package/lib/build.js ADDED
@@ -0,0 +1,126 @@
1
+ var fs = require("fs");
2
+ var path = require('path');
3
+ var file = require("./file");
4
+ var marked = require('marked');
5
+ var color = require('colors-cli');
6
+ var stylus = require('./stylus');
7
+ var copy = require('./copy');
8
+ var toc = require('./toc');
9
+ var nav = require('./nav');
10
+ var imgPath = require('./imgPath');
11
+ var log = console.log;
12
+
13
+ var template = '';
14
+
15
+ function build(commander,changeFile){
16
+
17
+ require('./menu_update')();
18
+
19
+ // 载入配置文件
20
+ var pkg = require(path.resolve('package.json'));
21
+
22
+
23
+ // 指定模板目录
24
+ if(commander.theme && commander.args.length > 0) template = commander.args[0];
25
+ else{
26
+ // 模板目录
27
+ template = path.dirname(__dirname) + '/theme/' + pkg.idoc.theme;
28
+ if(!file.isDir(template)){
29
+ template = process.cwd()+ '/' +pkg.idoc.theme;
30
+ }
31
+ }
32
+ // 皮肤目录不存在判断
33
+ if(!file.isDir(template)) return log(color.red('\nTheme directory does not exist.!\n') )
34
+
35
+ var name = pkg.name;
36
+ var idocmd = pkg.idoc.md;
37
+ var todir = process.cwd() + '/';
38
+ var html = ''; //
39
+ var markedstr; // markdown 生成HTML
40
+ var _path;
41
+ var tocHTML = '';//单页面导航静态页面
42
+ var navHTML = '';
43
+ var pathArr = file.readMDSync(todir + 'md/');
44
+
45
+
46
+ if(changeFile) pathArr = [changeFile];
47
+
48
+ pathArr.forEach(function(item,idx){
49
+ //菜单层级
50
+ var isIndex = false
51
+ var len = item.replace(process.cwd()+'/md/','').split('/').length;
52
+
53
+ if(path.basename(item) === idocmd[0]) len = 0;
54
+ //导航菜单生成
55
+ var navHTML = nav(idocmd,item,pathArr,len);
56
+
57
+ // markdown 生成HTML
58
+ markedstr = marked(file.read(item));
59
+
60
+ // markdown 增强 及树菜单生成
61
+ markedstr = toc(markedstr,function(_html){
62
+ tocHTML = _html.toc
63
+ });
64
+ item = path.normalize(item)
65
+
66
+ // 获取 md 的相对目录
67
+ item = item.replace(path.normalize(process.cwd() + '/md/'),'');
68
+
69
+ // 是否为首页判断
70
+ idocmd[0] === item ? isIndex = true : isIndex = false;
71
+
72
+ // 指定HTML路径
73
+ _path = idocmd[0] === item ?
74
+ (path.normalize(process.cwd() + '/' + item)).replace(item,"index.html"):
75
+ (path.normalize(process.cwd() + '/html/' + item)).replace('.md',".html");
76
+
77
+ // 图片引用路径处理
78
+ markedstr = imgPath(markedstr,_path);
79
+
80
+ // ejs 模板生成HTML
81
+ html = file.ejs(template + '/layout.ejs',{
82
+ title: pkg.name,//项目工程名字
83
+ index:isIndex,//是否为首页
84
+ pkg:pkg,
85
+ relative_path:file.relativePath(_path,process.cwd()),//相对路径
86
+ menu_html: navHTML,//页面之间的超链接导航
87
+ toc_html: tocHTML,// markdown 导航
88
+ markdown_html: markedstr // markdown 生成字符串
89
+ });
90
+ file.mkdirsSync(path.dirname(_path));
91
+ //写入指定目录中
92
+ file.write(_path,html);
93
+ if(!changeFile) log(color.blue('Generates') + ' "' + item.replace('.html',".md") + '"' + color.blue(" Success ! ") + new Date() );
94
+ })
95
+
96
+ // 复制复制所有静态资源到生产目录里面
97
+ copy( template +'/source/', todir+'static',{
98
+ filter:function(_file){
99
+ if(!/\.(styl)$/.test(_file)) {
100
+ return true;
101
+ }else{
102
+ return false;
103
+ }
104
+ }
105
+ },function(err,_file){
106
+ if(err) return console.error(err);
107
+ })
108
+
109
+ // 复制 gitignore 到项目的根目录中
110
+ if( !file.exists(todir + '.gitignore') ) copy( template +'/gitignore', todir ,function(err,_file){
111
+ if(err) return console.error(err);
112
+ fs.renameSync(todir + 'gitignore', todir + '.gitignore')
113
+ });
114
+
115
+ // css如果是 stylus 生成 css
116
+ stylus(template+'/source/css/',function(err,css,_filename,_extname){
117
+ if(err) return log(err);
118
+ file.write(todir+ 'static/css/'+_filename+'.css',css);
119
+ });
120
+
121
+ log();
122
+ if(!changeFile) log(color.green('Successful build static pages!') );
123
+ }
124
+
125
+
126
+ module.exports = build;
package/lib/clean.js ADDED
@@ -0,0 +1,43 @@
1
+ var fs = require('fs');
2
+ var file = require('./file');
3
+ var log = console.log;
4
+ var color = require('colors-cli');
5
+ // var exec = require('child_process').exec
6
+
7
+ module.exports = clean
8
+
9
+ function clean(commander){
10
+
11
+ var url = process.cwd();
12
+ var arr = fs.readdirSync(url);
13
+ for (var i = 0; i < arr.length; i++) {
14
+ // 使用系统的命令删除文件夹
15
+ // exec('rm -rf '+arr[i],function(err,out) {
16
+ // console.log(out); err && console.log(err);
17
+ // });
18
+ if( file.isDir(url+'/'+arr[i]) && (arr[i] === 'html' || arr[i] === 'static') ){
19
+ deleteFolderRecursive(url+'/'+arr[i])
20
+ log( color.green('delete "/') + arr[i] + color.green('" Success !') );
21
+ }else if( file.isFile(url+'/'+arr[i]) && arr[i] === 'index.html' ){
22
+ fs.unlinkSync( url+'/'+arr[i] );
23
+ log( color.green('delete "/') + arr[i] + color.green('" Success !') );
24
+ }
25
+ };
26
+ }
27
+
28
+ // 使用递归删除文件
29
+ deleteFolderRecursive = function(path) {
30
+ var files = [];
31
+ if( fs.existsSync(path) ) {
32
+ files = fs.readdirSync(path);
33
+ files.forEach(function(file,index){
34
+ var curPath = path + "/" + file;
35
+ if(fs.statSync(curPath).isDirectory()) { // recurse
36
+ deleteFolderRecursive(curPath);
37
+ } else { // delete file
38
+ fs.unlinkSync(curPath);
39
+ }
40
+ });
41
+ fs.rmdirSync(path);
42
+ }
43
+ };
package/lib/copy.js ADDED
@@ -0,0 +1,215 @@
1
+ /*
2
+
3
+ // 调用方法
4
+ copy(source, destination, option, function (err) {
5
+ if (err) {
6
+ return console.error(err);
7
+ }
8
+ console.log('done!');
9
+ });
10
+
11
+
12
+ option.filter 过滤文件是否要复制
13
+
14
+ */
15
+
16
+
17
+ var fs = require('fs'),
18
+ path = require('path'),
19
+ out = process.stdout,
20
+ stat = fs.stat,
21
+ option = null;
22
+
23
+ module.exports = copy;
24
+
25
+
26
+ //检查指定路径的文件或者目录是否存在
27
+ function exists(path){
28
+ return fs.existsSync(path);
29
+ }
30
+
31
+ //判断是不是文件
32
+ function isFile(path){
33
+ return exists(path) && fs.statSync(path).isFile();
34
+ }
35
+
36
+ //判断是不是目录
37
+ function isDir(path){
38
+ return exists(path) && fs.statSync(path).isDirectory();
39
+ }
40
+ // 判断是否为 json
41
+ function isJSON(obj) {
42
+ var isjson = typeof(obj) == "object" &&
43
+ toString.call(obj).toLowerCase() == "[object object]" && !obj.length;
44
+ return isjson;
45
+ }
46
+
47
+ // 循环异步创建所有目录
48
+ function mkdirs(dirPath, mode, callback) {
49
+ //Call the standard fs.mkdir
50
+ fs.mkdir(dirPath, mode, function(error) {
51
+ //When it fail in this way, do the custom steps
52
+ if (error && error.errno === 34) {
53
+ //Create all the parents recursively
54
+ !exists(path.dirname(dirPath))&&mkdirs(path.dirname(dirPath), mode, callback);
55
+ //And then the directory
56
+ !exists(dirPath)&&mkdirs(dirPath, mode, callback);
57
+ }
58
+ //Manually run the callback since we used our own callback to do all these
59
+ !error&&callback && callback(error);
60
+ });
61
+ };
62
+
63
+ // 波浪号的绝对路径
64
+ function resolvePath (string) {
65
+ if (string.substr(0, 2) === '~/')
66
+ string = (process.env.HOME || process.env.HOMEPATH || process.env.HOMEDIR || process.cwd()) + string.substr(1);
67
+ return path.resolve(string)
68
+ }
69
+
70
+ // 同步循环创建所有目录
71
+ function mkdirsSync(dirpath, mode) {
72
+ var _path = dirpath.replace(/\/$/, '').split('/');
73
+ for (var i = 1; i <= _path.length; i++) {
74
+ var segment = resolvePath(_path.slice(0, i).join('/')) ;
75
+ !exists(segment) ? fs.mkdirSync(segment,mode) : null ;
76
+ }
77
+ };
78
+
79
+ // 复制文件 或 文件夹
80
+ function copy(from,to,_option,cb){
81
+
82
+ // 选项设置如果存在,赋值给全局变量
83
+ if(_option&&isJSON(_option)) option = _option;
84
+
85
+ // 回调函数如果不存在 _option 不为参数
86
+ if(!cb && !isJSON(_option)) cb = _option || function(){};
87
+
88
+ // 回调函数如果不存在
89
+ if(!cb && isJSON(_option)) cb = function(){};
90
+
91
+ // 指定文件夹不存在,生文件夹
92
+ if(!exists(to)) mkdirsSync(to,0777,function(err){
93
+ if(err) return console.log("err11",err);
94
+ });
95
+
96
+ if(isFile(from)){
97
+ // 循环创建目录
98
+ mkdirsSync(to,0777,function(err){
99
+ if(err) return console.log("err11",err);
100
+ });
101
+ // 拷贝文件
102
+ copyfile(from,to,cb);
103
+ }else{
104
+ copyDir(from,to,cb)
105
+ }
106
+ }
107
+
108
+ function copyDir(from,to,cb){
109
+ // 异步读取指定目录中的内容
110
+ var paths = fs.readdirSync(from);
111
+ paths.forEach(function(_path){
112
+ var _src = path.normalize(from + '/' + _path),
113
+ _dst = path.normalize(to + '/' + _path);
114
+
115
+ if(isFile(_src)){
116
+ copyfile(_src,_dst,cb)
117
+ }else if(isDir(_src)){
118
+ existDir( _src, _dst, copyDir , cb);
119
+ }
120
+ });
121
+ }
122
+
123
+ // 在复制目录前需要判断该目录是否存在,不存在需要先创建目录
124
+ function existDir( src, dst, copyd ,cb){
125
+ // 循环创建目录
126
+ mkdirsSync(dst,0777,function(err){
127
+ if(err) return console.log("err11",err);
128
+ });
129
+ copyd( src, dst, cb);
130
+ }
131
+
132
+ // 复制文件
133
+ function copyfile(from,to,cb){
134
+
135
+ // 判断是否过滤
136
+ if( option && option.filter && !option.filter(from) ) return;
137
+
138
+ // 复制到目录中没有指定文件名,指定默认的文件名字
139
+ if(isDir(to)) to += path.basename(from);
140
+
141
+ var err = null;
142
+
143
+ // 没有指定的目录判断
144
+ if(!to) return cb('Do not specify a path.');
145
+
146
+ if (!(from && to && exists(from))) return cb('Error: no such file or directory ' + from);
147
+ // console.log("message:",to);
148
+
149
+ // 创建读取流
150
+ var readStream = fs.createReadStream( from ,{
151
+ flags : 'r',
152
+ encoding : null,
153
+ mode : 0666
154
+ });
155
+ // 创建写入流
156
+ var writeStream = fs.createWriteStream( to ,{
157
+ flags: 'a',
158
+ encoding: null,
159
+ mode: 0666
160
+ });
161
+ // // 通过管道来传输流
162
+ // readStream.pipe( writeStream );
163
+
164
+
165
+ // 获取文件的基本信息
166
+ var stats = fs.statSync(from);
167
+
168
+ var totalSize = stats.size;
169
+ var passedLength = 0;
170
+ var lastSize = 0;
171
+ var startTime = Date.now();
172
+
173
+ //回调
174
+ cb = cb || function(){};
175
+
176
+ // 当有数据流出时,写入数据
177
+ readStream.on('data', function(chunk) {
178
+ passedLength += chunk.length;
179
+ // 如果没有写完,暂停读取流
180
+ if (writeStream.write(chunk) === false) {
181
+ readStream.pause();
182
+ }
183
+ });
184
+
185
+ // 当没有数据时,关闭数据流
186
+ readStream.on('end', function() {
187
+ writeStream.end();
188
+ cb(err,from);
189
+ });
190
+
191
+ // 写完后,继续读取
192
+ writeStream.on('drain', function() {
193
+ readStream.resume();
194
+ });
195
+
196
+
197
+
198
+ //大文件复制
199
+ // setTimeout(function show() {
200
+ // var percent = Math.ceil((passedLength / totalSize) * 100);
201
+ // var size = Math.ceil(passedLength / 1000000);
202
+ // var diff = size - lastSize;
203
+ // lastSize = size;
204
+ // out.clearLine();
205
+ // out.cursorTo(0);
206
+ // out.write('Completed:' + size + 'MB, ' + (percent?percent:100) + '%, Speed:' + diff * 2 + 'MB/s' + '; file:' + from);
207
+ // if (passedLength < totalSize) {
208
+ // setTimeout(show, 500);
209
+ // } else {
210
+ // var endTime = Date.now();
211
+ // console.log();
212
+ // console.log('Total:' + (endTime - startTime) / 1000 + 's。');
213
+ // }
214
+ // }, 500);
215
+ }
package/lib/deploy.js ADDED
@@ -0,0 +1,24 @@
1
+ // var ghpages = require('gh-pages');
2
+ var path = require('path');
3
+ var log = console.log;
4
+
5
+
6
+ module.exports = deploy
7
+
8
+
9
+ function deploy(commander){
10
+
11
+ var util = require('util'),
12
+ exec = require('child_process').exec,
13
+ child;
14
+
15
+ child = exec('git add -A && git commit -m "'+new Date()+'" && git push -f origin gh-pages');
16
+
17
+ child.stdout.on('data', function (data) {
18
+ log("commit:",data)
19
+ });
20
+
21
+ child.stderr.on('data', function (data) {
22
+ log(data);
23
+ });
24
+ }