打包用到的批次檔碼如下:
@echo off
title Builder - 正在合併. ..
color 03
REM ==================================== =
REM jsbuilder beta版
REM
REM ==================================== ===
SETLOCAL ENABLEEXTENSIONS
echo.
REM 過濾檔案後綴,只combo js檔案
if "%~x1" NEQ ".js" ( .
echo **** 請選擇JS檔案
echo.
goto End
)
REM 檢查NODE_PATH
)
REM 檢查NODE_PATH
)
REM 檢查NODE_PATH
)
REM 檢查NODE_PATH
"a%NODE== NoNodePath
if not exist "%NODE_PATH%node.exe" goto NoNodePath
set RESULT_FILE=%~n1-combo%~x1
: >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
複製程式碼
程式碼如下:
//載入設定
quirere('. config.js');
//使用的模組
var FS = require('fs'),
PATH = require('path'),
jscombo = require('path'),
jscombo = require( './tool/jscombo'),
Util = require('util');
//取得參數
var args = process.argv;
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 '--unz opts.unzip = true;
break;
default:
filename = v;
// 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);