將nodejs打包工具整合到滑鼠右鍵的方法

來源:互聯網
上載者:User

打包用到的批次檔代碼如下:

複製代碼 代碼如下:
@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);

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.