Вход Регистрация
Файл: module-assets/admin/plupload/build/BuildTools.js
Строк: 279
<?php
var fs = require("fs");
var 
path = require("path");
var 
exec = require("child_process").exec;
var 
utils = require('../src/moxie/build/utils');

var 
color = function(s,c){return (color[c].toLowerCase()||'')+ color.reset;};
color.reset '33[39m';
color.red '33[31m';
color.yellow '33[33m';
color.green '33[32m';

exports.uglify = function (sourceFilesoutputFileoptions) {
    var 
jsp = require("uglify-js").parser;
    var 
pro = require("uglify-js").uglify;
    var 
code "";

    
options utils.extend({
        
mangle       true,
        
toplevel     false,
        
no_functions false
    
}, options);

    
// Combine JS files
    
if (sourceFiles instanceof Array) {
        
sourceFiles.forEach(function(filePath) {
            if (
options.sourceBase) {
                
filePath path.join(options.sourceBasefilePath);
            }

            
code += fs.readFileSync(filePath);
        });
    }


    
// Compress
    
var ast jsp.parse(code);

    
// Write combined, but not minified version (just strip off the comments)
    /*fs.writeFileSync(outputFile.replace(/.min./, '.full.'), pro.gen_code(ast, {
        beautify: true
    }));*/

    
ast pro.ast_mangle(astoptions);
    
ast pro.ast_squeeze(ast);
    
code pro.gen_code(ast);

    
fs.writeFileSync(outputFile";" code ";");
};

exports.less = function (sourceFileoutputFileoptions) {
    var 
less = require('less');

    
options extend({
        
compresstrue,
        
yuicompresstrue,
        
optimization1,
        
silentfalse,
        
paths: [],
        
colortrue,
        
strictImportsfalse
    
}, options);

    var 
parser = new less.Parser({
        
paths: [path.dirname(sourceFile)],
        
filenamepath.basename(sourceFile),
        
optimizationoptions.optimization,
        
filenamesourceFile,
        
strictImportsoptions.strictImports
    
});

    
// Patch over BOM bug
    // Todo: Remove this when they fix the bug
    
less.Parser.importer = function (filepathscallbackenv) {
        var 
pathname;

        
paths.unshift('.');

        for (var 
0paths.lengthi++) {
            try {
                
pathname path.join(paths[i], file);
                
fs.statSync(pathname);
                break;
            } catch (
e) {
                
pathname null;
            }
        }

        if (
pathname) {
            
fs.readFile(pathname'utf-8', function(edata) {
                if (
e) return callback(e);

                
data data.replace(/^uFEFF/, '');

                new(
less.Parser)({
                    
paths: [path.dirname(pathname)].concat(paths),
                    
filenamepathname
                
}).parse(data, function (eroot) {
                    
callback(erootdata);
                });
            });
        } else {
            if (
typeof(env.errback) === "function") {
                
env.errback(filepathscallback);
            } else {
                
callback({ type'File'message"'" file "' wasn't found.n" });
            }
        }
    }

    
parser.parse(fs.readFileSync(sourceFile).toString(), function (errtree) {
        if (
err) {
            
less.writeError(erroptions);
            return;
        }

        
fs.writeFileSync(outputFiletree.toCSS({
            
compressoptions.compress,
            
yuicompressoptions.yuicompress
        
}));
    });
}

exports.yuidoc = function (sourceDiroutputDiroptions) {
    var 
= require('yuidocjs');

    if (!(
sourceDir instanceof Array)) {
        
sourceDir = [sourceDir];
    }

    
options utils.extend({
        
pathssourceDir,
        
outdiroutputDir,
        
timefalse
    
}, options);

    var 
starttime = new Date().getTime();
    var 
json = (new Y.YUIDoc(options)).run();

    var 
builder = new Y.DocBuilder(optionsjson);
    
builder.compile(function() {
        var 
endtime = new Date().getTime();

        if (
options.time) {
            
Y.log('Completed in ' + ((endtime starttime) / 1000) + ' seconds' 'info''yuidoc');
        }

        
complete();
    });
};

exports.jshint = function (sourceDiroptions) {
    var 
jshint = require('jshint').JSHINT;

    function 
process(filePath) {
        var 
stat fs.statSync(filePath);

        if (
stat.isFile()) {
            if (!
jshint(fs.readFileSync(filePath).toString(), options)) {
                
// Print the errors
                
console.log(color('Errors in file ' filePath'red'));
                var 
out jshint.data(),
                
errors out.errors;
                
Object.keys(errors).forEach(function(error){
                    
error errors[error];

                    
console.log('line: ' error.line ':' error.character' -> ' error.reason );
                    
console.log(color(error.evidence,'yellow'));
                });
            }
        } else if (
stat.isDirectory()) {
            
fs.readdirSync(filePath).forEach(function(fileName) {
                
process(path.join(filePathfileName));
            });
        }
    }

    
options utils.extend({
        
bosstrue,
        
forinfalse,
        
curlytrue,
        
smarttabstrue
    
}, options);

    
process(sourceDir);
}

exports.zip = function (sourceFileszipFilecb) {
    var 
ZipWriter = require("moxie-zip").ZipWriter;
    var 
zip = new ZipWriter();

    var 
files = [];

    function 
processFile(filePathzipFilePath) {
        var 
stat fs.statSync(filePath);

        
zipFilePath zipFilePath || filePath;

        if (
stat.isFile()) {
            
files.push({ namezipFilePathpathfilePath });
        } else if (
stat.isDirectory()) {
            
fs.readdirSync(filePath).forEach(function(fileName) {
                if (/^[^.]/.
test(fileName)) {
                    
processFile(path.join(filePathfileName), path.join(zipFilePathfileName));
                }
            });
        }
    }

    
sourceFiles.forEach(function(filePath) {
        if (
filePath instanceof Array) {
            
processFile(filePath[0], filePath[1]);
        } else {
            
processFile(filePath);            
        }
    });

    
files.forEach(function(file) {
        
zip.addFile(file.namefile.path);
    });

    
zip.saveAs(zipFile, function() {
        
cb();
    });
}

exports.copySync = function(fromto) {
    var 
stat;

    function 
copyFile(srcFiledestFile) {
        var 
BUF_LENGTHbuffbytesReadfdrfdwpos;
        
        
BUF_LENGTH 64 1024;
        
buff = new Buffer(BUF_LENGTH);
        
fdr fs.openSync(srcFile'r');
        
fdw fs.openSync(destFile'w');
        
bytesRead 1;
        
pos 0;
        
        while (
bytesRead 0) {
            
bytesRead fs.readSync(fdrbuff0BUF_LENGTHpos);
            
fs.writeSync(fdwbuff0bytesRead);
            
pos += bytesRead;
        }
        
fs.closeSync(fdr);
        return 
fs.closeSync(fdw);
    }

    try {
        
stat fs.statSync(from);
    } catch (
ex) {
        
console.info("Error: " from " not found.");
        
process.exit(1);
    }

    if (
stat.isFile()) {
        
copyFile(fromto);
    } else if (
stat.isDirectory()) {
        
/*fs.readdirSync(from).forEach(function(fileName) {
            copySync(from, to)
        });*/
        
console.info("Error: " from " is directory");
    } 
}

// recursively delete specified folder
exports.rmDir = function(dirPath) {
    try { var 
files fs.readdirSync(dirPath); }
    catch(
e) { return; }
    if (
files.length 0)
        for (var 
0files.lengthi++) {
            var 
filePath dirPath '/' files[i];
            if (
fs.statSync(filePath).isFile())
                
fs.unlinkSync(filePath);
            else
                
this.rmDir(filePath);
        }
    
fs.rmdirSync(dirPath);
}

// extract version details from chengelog.txt
exports.getReleaseInfo = function (srcPath) {
    if (!
fs.existsSync(srcPath)) {
        
console.info(srcPath " cannot be found.");
        
process.exit(1);
    } 
    
    var 
src fs.readFileSync(srcPath).toString();

    var 
info src.match(/Version ([0-9xabrc.]+)[^(]+(([^)]+))/);
    if (!
info) {
        
console.info("Error: Version cannot be extracted.");
        
process.exit(1);
    }

    return {
        
versioninfo[1],
        
releaseDateinfo[2],
        
fileVersioninfo[1].replace(/./g'_')
    }
}

// inject version details and copyright header if available to all js files in specified directory
exports.addReleaseDetailsTo = function (destPathinfo) {
    var 
self thisheadNoteheadNotePath "./build/headnote.txt";

    function 
processFile(filePath) {

        if (
headNote) {
            
contents headNote "n" fs.readFileSync(filePath);
        }

        
contents contents.replace(/@@([^@]+)@@/g, function($0, $1) {
            switch ($
1) {
                case 
"version": return info.version;
                case 
"releasedate": return info.releaseDate;
            }
        });

        
fs.writeFileSync(filePathcontents);
    }

    function 
isTextFile(filePath) {
        return /.(
js|txt)$/.filePath;
    }
    
    if (
fs.existsSync(headNotePath)) {
        
headNote fs.readFileSync(headNotePath).toString();
    }

    var 
stat fs.statSync(destPath);

    if (
stat.isFile()) {
        
processFile(destPath);
    } else if (
stat.isDirectory()) {
        
fs.readdirSync(destPath).forEach(function(fileName) {
            
self.addReleaseDetailsTo(path.join(destPathfileName), info);
        });
    }
}
?>
Онлайн: 2
Реклама