复制代码 代码如下:
@echo off
title builder - 正在合并 ...
color 03
rem =====================================
rem jsbuilder beta版
rem
rem =====================================
setlocal enableextensions
echo.
rem 过滤文件后缀,只combo js文件
if %~x1 neq .js (
echo.
echo **** 请选择js文件
echo.
goto end
)
rem 检查node_path
if %node_path% == goto nonodepath
if not exist %node_path%\node.exe goto nonodepath
set result_file=%~n1-combo%~x1
:zip_choice
echo 选择是否【压缩】合并后的js文件?
set input=
set /p input= -^> 请选择(y/n):
if /i %input%==n goto unzip
if /i %input%==y goto zip
rem 调用build合并文件
:unzip
%node_path%\node.exe %~dp0build.js --unzip %~n1%~x1 > %result_file%
echo.
echo **** ~o(∩_∩)o~ 【合并】成功 ****
echo.
goto end
rem 调用build合并并且压缩文件
:zip
%node_path%\node.exe %~dp0build.js %~n1%~x1 > %result_file%
echo.
echo **** ~o(∩_∩)o~ 【合并并压缩】成功 ****
echo.
goto end
:nonodepath
echo.
echo **** 请先安装nodejs并设置node_path环境变量 ****
echo.
:end
endlocal
pause
打包用的build.js代码如下:
复制代码 代码如下:
//加载配置
require('./config.js');
//用到的模块
var fs = require('fs'),
path = require('path'),
jscombo = require('./tool/jscombo'),
util = require('util');
//获取参数
var args = process.argv;
args = [].slice.call(args,2);
var opts = {};//配置
var curpath, rootpath = curpath = process.cwd();
//根据config.js的相对路径设置,变换rootpath
if(typeof relativepath!=='undefined'){
rootpath = path.join(rootpath,relativepath);
}
var filename;//要处理的文件名字
//处理参数
out: while(args.length){
var v = args.shift();
switch(v){
case '-uz':
case '--unzip':
//combo后压缩
opts.unzip = true;
break;
default:
filename = v;
break out;
}
}
// var filepath = path.join(rootpath,filename);
//将要压缩的js文件路径 转化为相对rootpath的路径
var rpath = path.relative(rootpath,path.join(curpath,filename));
var str = jscombo(rpath, rootpath, opts);
var fileout = process.stdout;
fileout.write(str);
