打包用到的批處理文件代碼如下:
復制代碼 代碼如下:
@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);