Home >Web Front-end >JS Tutorial >Method to integrate nodejs packaging tool into the right mouse button_json

Method to integrate nodejs packaging tool into the right mouse button_json

WBOY
WBOYOriginal
2016-05-16 17:34:061494browse

The batch file code used for packaging is as follows:

Copy code The code is as follows:

@echo off
title Builder - merging. ..

color 03
REM ==================================== =
REM jsbuilder beta version
REM
REM ================================== ===
SETLOCAL ENABLEEXTENSIONS

echo.

REM filter file suffix, only combo js files
if "%~x1" NEQ ".js" (
echo .
echo **** Please select JS file
echo.
goto End
)

REM Check 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 Choose whether to [compress] the merged js files?
set input=
set /p input= -^> Please select (y/n):
if /i "%input%" ==="n" goto UNZIP
if /i "%input%"=="y" goto ZIP

REM calls build merge file
:UNZIP
"%NODE_PATH%node. exe" "%~dp0build.js" --unzip "%~n1%~x1" > "%RESULT_FILE%"
echo.
echo **** ~O(∩_∩)O~ 【 Merger] Successful****
echo.
goto End


REM calls build to merge and compress the file
:ZIP
"%NODE_PATH%node.exe" " %~dp0build.js" "%~n1%~x1" > "%RESULT_FILE%"
echo.
echo **** ~O(∩_∩)O~ [Merge and compress] Successful* ***
echo.
goto End

:NoNodePath
echo.
echo **** Please install NodeJS first and set the NODE_PATH environment variable****
echo.

:End
ENDLOCAL
pause

The build.js code used for packaging is as follows:

Copy code The code is as follows:

//Load configuration
require('./ config.js');

//Modules used
var FS = require('fs'),
PATH = require('path'),
jscombo = require( './tool/jscombo'),
Util = require('util');


//Get parameters
var args = process.argv;
args = [ ].slice.call(args,2);

var opts = {};//Configuration
var curPath, rootPath = curPath = process.cwd();

// According to the relative path setting of config.js, transform rootPath
if(typeof relativePath!=='undefined'){
rootPath = PATH.join(rootPath,relativePath);
}

var filename;//The name of the file to be processed

//Processing parameters
out: while(args.length){

var v = args.shift();

switch(v){
case '-uz':
case '--unzip':
//Compression after combo
opts.unzip = true;
break;
default:
filename = v;
break out;
}
}

// var filePath = PATH.join(rootPath,filename);
// Convert the js file path to be compressed into a path relative to the rootpath
var rPath = PATH.relative(rootPath,PATH.join(curPath,filename));
var str = jscombo(rPath, rootPath, opts);

var fileout = process.stdout;
fileout.write(str);
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn