Yesterday, the main nodejs packaging code (simple project packaging tool written by nodejs) was released. Today, the code that is integrated with the right mouse click is released, and environment variables need to be configured for packaging, the code of the batch file used to add NODE_PATH to package the node installation path is as follows:
The 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? 1.1.9 "(
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? 1.1.9 "-- 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? 1.1.9 "" % ~ 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:
The 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 );