From 0caf3f6169954a7270b9131f431b8b48dc93a5cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=90=E6=96=8C?= <1987.tangbin@gmail.com> Date: Sun, 1 Jun 2014 01:28:48 +0800 Subject: [PATCH] bug fix --- LICENSE | 0 README.md | 84 +- bin/node2bat | 2 +- demo/includeHTML/README.md | 39 + .../test => demo/includeHTML/demo}/about.html | 14 +- .../test => demo/includeHTML/demo}/index.html | 14 +- .../test => demo/includeHTML/demo}/news.html | 14 +- demo/includeHTML/demo/public/footer.html | 3 + .../includeHTML/demo}/public/header.html | 1 + demo/includeHTML/includeHTML.bat | 2484 ++++++++++++++++ demo/includeHTML/includeHTML.js | 87 + demo/includeHTML/package.json | 13 + lib/node2bat.runtime.js | 1328 --------- package.json | 13 +- node2bat.js => src/node2bat.js | 8 +- src/runtime.js | 2400 +++++++++++++++ test/README.md | 43 - test/Thumbs.db | Bin 7168 -> 0 bytes test/banner.jpg | Bin 31947 -> 0 bytes test/includeHTML.bat | 1402 --------- test/includeHTML.js | 77 - test/test.bat | 2567 +++++++++++++++++ test/test.js | 171 ++ test/test/public/footer.html | 3 - 24 files changed, 7860 insertions(+), 2907 deletions(-) mode change 100644 => 100755 LICENSE create mode 100755 demo/includeHTML/README.md rename {test/test => demo/includeHTML/demo}/about.html (65%) rename {test/test => demo/includeHTML/demo}/index.html (65%) rename {test/test => demo/includeHTML/demo}/news.html (65%) create mode 100755 demo/includeHTML/demo/public/footer.html rename {test/test => demo/includeHTML/demo}/public/header.html (85%) create mode 100644 demo/includeHTML/includeHTML.bat create mode 100644 demo/includeHTML/includeHTML.js create mode 100644 demo/includeHTML/package.json delete mode 100755 lib/node2bat.runtime.js rename node2bat.js => src/node2bat.js (68%) create mode 100755 src/runtime.js delete mode 100644 test/README.md delete mode 100755 test/Thumbs.db delete mode 100644 test/banner.jpg delete mode 100644 test/includeHTML.bat delete mode 100755 test/includeHTML.js create mode 100644 test/test.bat create mode 100644 test/test.js delete mode 100755 test/test/public/footer.html diff --git a/LICENSE b/LICENSE old mode 100644 new mode 100755 diff --git a/README.md b/README.md index 3efa1e3..69e5a2a 100755 --- a/README.md +++ b/README.md @@ -2,11 +2,15 @@ ## 简介 -node2bat 是一个可以将 NodeJS 脚本编译为 Windows 批处理脚本的工具。编译后的批处理不再依赖 NodeJS,双击可直接运行。你可以使用 NodeJS 的 API 来编写一些轻量级的自动化 Windows 批处理脚本。 +node2bat 是一个可以将 NodeJS 脚本编译为 Windows 批处理脚本的工具。编译后的批处理不再依赖 NodeJS,双击可直接运行。你可以使用 NodeJS 的 API 来编写 Windows 批处理脚本发布给其他人使用,而不需要安装 NodeJS 的环境。借助 js 强大的语法支持,你的批处理将异常强大。 + +## 原理 + +windows 中自带了 javascript 引擎支持 jscript,所以 node2bat 便是使用 jscript 封装了一层 nodejs 的 api,然后巧妙地将 js 包含在 bat 文件中。 ## 安装 -先安装 NodeJS 与 npm,然后执行: +先安装 NodeJS,然后执行: $ npm install node2bat -g @@ -18,52 +22,54 @@ node2bat 是一个可以将 NodeJS 脚本编译为 Windows 批处理脚本的工 ## 运行示例 -源码 test 目录是一个演示例子,其中 includeHTML.js 是基于 NodeJS 编写的自动化脚本,它的用途是给页面制作人员批量更新局部模板的。 +源码 demo 目录是一个演示例子,其中 includeHTML.js 是基于 NodeJS 编写的自动化脚本,它的用途是给页面制作人员批量更新局部模板的。 这个脚本里面用到了 NodeJS 的文件与路径处理,我们可以编译 includeHTML.js 为 bat 文件,这样用户拿到我们的 bat 文件就可以直接双击运行了,无需安装 NodeJS 与学习命令行。 切换到源码目录,运行: - $ node2bat test/includeHTML.js + $ node2bat demo/includeHTML/includeHTML.js 运行完毕后会立刻生成独立的 includeHTML.bat,你也可以双击打开它试用一下。 ## JS API -node2bat v0.0.1 支持的 JS API 是 NodeJS API 的子集,包含基本的文件与路径操作: +node2bat 支持 NodeJS API 的核心 API,并且支持大多数 ECMA5 的 API,这些足可以满足绝大多数任务。 ### 全局变量 -* [require(id)](http://nodejs.org/api/globals.html#globals_require)``(注意:不支持外部模块)`` -* [process.argv](http://nodejs.org/api/process.html#process_process_argv) -* [process.env](http://nodejs.org/api/process.html#process_process_env) -* [process.exit([code])](http://nodejs.org/api/process.html#process_process_env) -* [process.cwd()](http://nodejs.org/api/process.html#process_process_cwd) -* [process.stdout.write(message)](http://nodejs.org/api/process.html#process_process_stdout) -* [console.log(message)](http://nodejs.org/api/console.html#console_console_log_data) * [__filename](http://nodejs.org/api/globals.html#globals_filename) * [__dirname](http://nodejs.org/api/globals.html#globals_dirname) - -> 注:使用 process.argv.slice(2) 可返回拖拽到批处理程序图标上后所有的文件列表 +* [require(id)](http://nodejs.org/api/globals.html#globals_require)``(注意:仅支持 node2bat 内置的系统模块或外部 json 文件)`` +* process + * [process.argv](http://nodejs.org/api/process.html#process_process_argv) + * [process.env](http://nodejs.org/api/process.html#process_process_env) + * [process.exit([code])](http://nodejs.org/api/process.html#process_process_env) + * [process.cwd()](http://nodejs.org/api/process.html#process_process_cwd) + * [process.stdout.write(message)](http://nodejs.org/api/process.html#process_process_stdout) + * [process.stderr.write(message)](http://nodejs.org/api/process.html#process_process_stderr) +* console + * [console.log([data], [...])](http://nodejs.org/api/console.html#console_console_log_data) + * [console.info([data], [...])](http://nodejs.org/api/console.html#console_console_info_data) + * [console.error([data], [...])](http://nodejs.org/api/console.html#console_console_error_data) + * [console.warn([data], [...])](http://nodejs.org/api/console.html#console_console_warn_data) + * [console.dir(obj)](http://nodejs.org/api/console.html#console_console_dir_obj) + * [console.time(label)](http://nodejs.org/api/console.html#console_console_time_label) + * [console.timeEnd(label)](http://nodejs.org/api/console.html#console_console_timeend_label) + * [console.assert(expression, [message])](http://nodejs.org/api/console.html#console_console_assert_expression_message) + +> 注:如果拖拽文件到 bat 图标上执行,process.argv.slice(2) 可以获取这些文件的列表 ### 内置模块 * File System - * [fs.rename(oldPath, newPath, callback)](http://nodejs.org/api/fs.html#fs_fs_rename_oldpath_newpath_callback) * [fs.renameSync(oldPath, newPath)](http://nodejs.org/api/fs.html#fs_fs_renamesync_oldpath_newpath) - * [fs.stat(path, callback)](http://nodejs.org/api/fs.html#fs_fs_stat_path_callback) - * [fs.statSync(path)](http://nodejs.org/api/fs.html#fs_fs_statsync_path) - * [fs.unlink(path, callback)](http://nodejs.org/api/fs.html#fs_fs_unlink_path_callback) + * [fs.statSync(path)](http://nodejs.org/api/fs.html#fs_fs_statsync_path)``只支 isFile()、isDirectory()、size、atime、mtime、ctime`` * [fs.unlinkSync(path)](http://nodejs.org/api/fs.html#fs_fs_unlinksync_path) - * [fs.rmdir(path, callback)](http://nodejs.org/api/fs.html#fs_fs_rmdir_path_callback) * [fs.rmdirSync(path)](http://nodejs.org/api/fs.html#fs_fs_rmdirsync_path) - * [fs.mkdir(path, [mode], callback)](http://nodejs.org/api/fs.html#fs_fs_mkdir_path_mode_callback) * [fs.mkdirSync(path, [mode])](http://nodejs.org/api/fs.html#fs_fs_mkdirsync_path_mode) - * [fs.readFile(filename, [options], callback)](http://nodejs.org/api/fs.html#fs_fs_readfile_filename_options_callback) * [fs.readFileSync(filename, [options])](http://nodejs.org/api/fs.html#fs_fs_readfilesync_filename_options) - * [fs.writeFile(filename, data, [options], callback)](http://nodejs.org/api/fs.html#fs_fs_writefile_filename_data_options_callback) * [fs.writeFileSync(filename, data, [options])](http://nodejs.org/api/fs.html#fs_fs_writefilesync_filename_data_options) - * [fs.exists(path, callback)](http://nodejs.org/api/fs.html#fs_fs_exists_path_callback) * [fs.existsSync(path)](http://nodejs.org/api/fs.html#fs_fs_existssync_path) * Path * [path.normalize(p)](http://nodejs.org/api/path.html#path_path_normalize_p) @@ -75,8 +81,36 @@ node2bat v0.0.1 支持的 JS API 是 NodeJS API 的子集,包含基本的文 * [path.extname(p)](http://nodejs.org/api/path.html#path_path_extname_p) * [path.sep](http://nodejs.org/api/path.html#path_path_sep) * [path.delimiter](http://nodejs.org/api/path.html#path_path_delimiter) + +## 测试用例 + + node2bat test/test.js + start test/test.bat + +## 更新日志 + +v0.0.3 + +* 修复``fs.writeFileSync()``写入``utf-8``文件会插入 bom 的问题 +* 修复``this``指向为``global``对象的问题 +* ``require()``方法支持载入 json 文件 +* ``fs.statSync()``支持``size``、``atime``、``mtime``、``ctime`` +* ``require(id)``支持读取外部 json 文件 +* 完善``console``模块 +* 完善``process.env``模块,完全与 NodeJS 保持一致 +* 鉴于使用场景为批处理,所以取消异步方法的支持 +* 提供测试用例 + +v0.0.2 + +* 修正``process.argv``的 BUG +* ``console.log``方法可以友好的显示``Object``数据结构 + +v0.0.1 + +* 支持 NodeJS 文件与路径操作等基础 API -## 开源节流 +## License -正如您若见,这是一个奇葩的项目,如果有兴趣可参与进来将更多的 NodeJS 特性在 node2bat 上实现。 +MIT diff --git a/bin/node2bat b/bin/node2bat index 648a386..3885d70 100755 --- a/bin/node2bat +++ b/bin/node2bat @@ -2,7 +2,7 @@ 'use strict'; -var node2bat = require('../node2bat.js'); +var node2bat = require('../src/node2bat.js'); var fs = require('fs'); diff --git a/demo/includeHTML/README.md b/demo/includeHTML/README.md new file mode 100755 index 0000000..e79147e --- /dev/null +++ b/demo/includeHTML/README.md @@ -0,0 +1,39 @@ +# HTML 局部模板更新工具 + +## 工具介绍 + +includeHTML 是一个简单易用的 HTML 静态文件局部模板批量更新工具,它通过注释的方式给 HTML 添加类似服务端模板``include``标签的功能,可用来分离页面的头部与底部模板。 + +### 特性 + +1. 无需 js 支持不会破坏 SEO +2. 无需服务端环境运行 +3. 页面可被反复更新 +4. 语法与普通注释无异 +5. 绿色单文件,双击即可运行 + +本工具适用于 web 设计师或者 web 重构工程师。 + +## include 语句 + +编写页面的时候,在需要动态更新的地方按固定格式写好注释即可,例如: + +``` + + + +``` + +运行本工具后则会将内容替换为外部模板。 + +## 工具使用 + +将工具放在模板目录,双击 includeHTML.bat 即可。 + +> 处理单个页面拖拽到 includeHTML.bat 图标上运行即可。 diff --git a/test/test/about.html b/demo/includeHTML/demo/about.html similarity index 65% rename from test/test/about.html rename to demo/includeHTML/demo/about.html index dcf9158..ff62b07 100755 --- a/test/test/about.html +++ b/demo/includeHTML/demo/about.html @@ -1,29 +1,29 @@ - + About - + +

About

- + - + (c) 2014 github.com/aui + \ No newline at end of file diff --git a/test/test/index.html b/demo/includeHTML/demo/index.html similarity index 65% rename from test/test/index.html rename to demo/includeHTML/demo/index.html index d796d6c..255a346 100755 --- a/test/test/index.html +++ b/demo/includeHTML/demo/index.html @@ -1,29 +1,29 @@ - + Home - + +

Home

- + - + (c) 2014 github.com/aui + \ No newline at end of file diff --git a/test/test/news.html b/demo/includeHTML/demo/news.html similarity index 65% rename from test/test/news.html rename to demo/includeHTML/demo/news.html index ad0af84..ea90d28 100755 --- a/test/test/news.html +++ b/demo/includeHTML/demo/news.html @@ -1,29 +1,29 @@ - + News - + +

News

- + - + (c) 2014 github.com/aui + \ No newline at end of file diff --git a/demo/includeHTML/demo/public/footer.html b/demo/includeHTML/demo/public/footer.html new file mode 100755 index 0000000..09a7406 --- /dev/null +++ b/demo/includeHTML/demo/public/footer.html @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/test/test/public/header.html b/demo/includeHTML/demo/public/header.html similarity index 85% rename from test/test/public/header.html rename to demo/includeHTML/demo/public/header.html index 0072f24..cea8ba7 100755 --- a/test/test/public/header.html +++ b/demo/includeHTML/demo/public/header.html @@ -1,4 +1,5 @@