Skip to content

Commit

Permalink
Update merging.
Browse files Browse the repository at this point in the history
  • Loading branch information
petersirka committed Jun 5, 2017
1 parent e73dcd6 commit 59a63da
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 66 deletions.
52 changes: 26 additions & 26 deletions merged/merge.js
@@ -1,41 +1,41 @@
var UglifyJS = require('uglify-js');
var fs = require('fs');
var path = require('path');
var dir = './total.js/';
var license = '// Copyright 2012-2017 (c) Peter Širka <petersirka@gmail.com>\n//\n// Permission is hereby granted, free of charge, to any person obtaining a\n// copy of this software and associated documentation files (the\n// "Software"), to deal in the Software without restriction, including\n// without limitation the rights to use, copy, modify, merge, publish,\n// distribute, sublicense, and/or sell copies of the Software, and to permit\n// persons to whom the Software is furnished to do so, subject to the\n// following conditions:\n//\n// The above copyright notice and this permission notice shall be included\n// in all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS\n// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN\n// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,\n// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR\n// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE\n// USE OR OTHER DEALINGS IN THE SOFTWARE.\n\n';
const Fs = require('fs');
const Path = require('path');
const license = '// Copyright 2012-2017 (c) Peter Širka <petersirka@gmail.com>\n//\n// Permission is hereby granted, free of charge, to any person obtaining a\n// copy of this software and associated documentation files (the\n// "Software"), to deal in the Software without restriction, including\n// without limitation the rights to use, copy, modify, merge, publish,\n// distribute, sublicense, and/or sell copies of the Software, and to permit\n// persons to whom the Software is furnished to do so, subject to the\n// following conditions:\n//\n// The above copyright notice and this permission notice shall be included\n// in all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS\n// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN\n// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,\n// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR\n// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE\n// USE OR OTHER DEALINGS IN THE SOFTWARE.\n\n';
var output;

// COMPRESSION
if (process.argv.indexOf('--minify') !== -1) {
console.log('COMPRESS');
var options = {};
options.fromString = true;
options.mangle = true;
options.quote_style = 1;
output = fs.readFileSync(path.join(process.cwd(), 'total.js')).toString('utf8');
fs.writeFileSync(path.join(process.cwd(), 'total.js'), license + output);
return;
var options = {};
options.mangle = true;
options.output = { quote_style: 1 };
var U = require('uglify-es');
output = Fs.readFileSync(Path.join(process.cwd(), 'total.js')).toString('utf8');
output = U.minify(output, options);
Fs.writeFileSync(Path.join(process.cwd(), 'total.js'), license + output.code);
return;
}

var merge = ['builders.js', 'utils.js', 'image.js', 'mail.js', 'internal.js', 'nosql.js', 'index.js'];
// MERGING
var merge = ['builders.js', 'utils.js', 'image.js', 'mail.js', 'internal.js', 'nosql.js', 'index.js', 'cluster.js', 'debug.js'];
var buffer = [];

for (var i = 0, length = merge.length; i < length; i++) {

var file = merge[i];
var content = fs.readFileSync('../' + file).toString('utf8');
var file = merge[i];
var content = Fs.readFileSync('../' + file).toString('utf8');

content = content.replace("!global.framework && require('./index');", '');
content = content.replace('!global.framework && require(\'./index\');', '');

switch (file) {
case 'index.js':
buffer.push(content);
break;
default:
buffer.push('(function(module){var exports=module.exports;global.framework_' + file.substring(0, file.length - 3) + '=module.exports;\n' + content + 'return module;})({exports:{}});');
break;
}
switch (file) {
case 'index.js':
buffer.push(content);
break;
default:
buffer.push('(function(module){var exports=module.exports;global.framework_' + file.substring(0, file.length - 3) + '=module.exports;\n' + content + 'return module;})({exports:{}});');
break;
}
}

output = buffer.join('');
console.log('---->', output.length / 1024 >> 0, 'kB');
fs.writeFileSync(path.join(process.cwd(), 'total.js'), output);
Fs.writeFileSync(Path.join(process.cwd(), 'total.js'), output);

0 comments on commit 59a63da

Please sign in to comment.