Integrate the nodejs packaging tool with the right-click Method

Source: Internet
Author: User

The batch file code used for packaging is as follows:

Copy codeThe Code is as follows:
@ Echo off
Title Builder-merging...

Color 03
REM ============================================
REM jsbuilder beta
REM
REM ============================================
SETLOCAL ENABLEEXTENSIONS

Echo.

REM filter file suffix, only combo js files
If "% ~ X1 "NEQ". js "(
Echo.
Echo *** select a 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: Select whether to [compress] the merged js file?
Set input =
Set/p input =-^> select (y/n ):
If/I "% input %" = "n" goto UNZIP
If/I "% input %" = "y" goto ZIP

REM calls build to merge files
: UNZIP
"% NODE_PATH % \ node.exe" "% ~ Dp0build. js "-- unzip" % ~ N1 % ~ X1 ">" % RESULT_FILE %"
Echo.
Echo ****~ O (distinct _ distinct) O ~ [Merge] successfully ****
Echo.
Goto End

 
REM calls build to merge and compress files
: ZIP
"% NODE_PATH % \ node.exe" "% ~ Dp0build. js "" % ~ N1 % ~ X1 ">" % RESULT_FILE %"
Echo.
Echo ****~ O (distinct _ distinct) O ~ Merge and compress ****
Echo.
Goto End

: NoNodePath
Echo.
For echo *****, first install NodeJS and set the NODE_PATH environment variable ****
Echo.

: End
ENDLOCAL
Pause

The build. js code for packaging is as follows:

Copy codeThe Code is as follows:
// Load the configuration
Require ('./config. js ');

// Modules used
Var FS = require ('fs '),
PATH = require ('path '),
Jscombo = require ('./tool/jscombo '),
Util = require ('til ');

 
// Obtain parameters
Var args = process. argv;
Args = []. slice. call (args, 2 );

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

// Set the rootPath according to the relative path of config. js.
If (typeof relativePath! = 'Undefined '){
RootPath = PATH. join (rootPath, relativePath );
}

Var filename; // name of the file to be processed

// Processing Parameters
Out: while (args. length ){

Var v = args. shift ();

Switch (v ){
Case '-uz ':
Case '-- unzip ':
// Compress after combo
Opts. unzip = true;
Break;
Default:
Filename = v;
Break out;
}
}

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

Var fileout = process. stdout;
Fileout. write (str );

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.