mirror of
https://github.com/Hopiu/jquery-mobile.git
synced 2026-03-16 22:10:25 +00:00
Added amd-stripper.js
This commit is contained in:
parent
e2606bc690
commit
ad98a8f13b
1 changed files with 67 additions and 0 deletions
67
js/amd-stripper.js
Normal file
67
js/amd-stripper.js
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
* Strips output of AMD builder from define
|
||||
*
|
||||
* Usage:
|
||||
*
|
||||
* node amd-stripper.js in out
|
||||
* or
|
||||
* cat in | node amd-stripper.js > out
|
||||
*/
|
||||
|
||||
(function (console, args, readFileFunc) {
|
||||
var env, fs,
|
||||
fileName, content, destFileName,
|
||||
exists,
|
||||
readFile = typeof readFileFunc !== 'undefined' ? readFileFunc : null;
|
||||
|
||||
|
||||
if (typeof process !== 'undefined') {
|
||||
env = 'node';
|
||||
|
||||
//Get the fs module via Node's require before it
|
||||
//gets replaced. Used in require/node.js
|
||||
fs = require('fs');
|
||||
path = require('path');
|
||||
|
||||
readFile = function (path) {
|
||||
return fs.readFileSync(path, 'utf8');
|
||||
};
|
||||
|
||||
exists = function (fileName) {
|
||||
return path.existsSync(fileName);
|
||||
};
|
||||
|
||||
fileName = process.argv[2];
|
||||
|
||||
destFileName = process.argv[3];
|
||||
}
|
||||
|
||||
if ( fileName ) {
|
||||
if ( exists(fileName) ) {
|
||||
content = readFile( fileName );
|
||||
} else {
|
||||
console.log( "Could not find file: " + fileName );
|
||||
if ( env === 'node') {
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
content = fs.readFileSync('/dev/stdin').toString();
|
||||
}
|
||||
|
||||
content = content
|
||||
.replace(/^define\((:?'[^']+'\s*,\s*)?(:?\[[^\]]*\]\s*,\s*)?[);]*\s*function.*\{/mg, "(function() {") // Get rid of the define wrap header
|
||||
.replace(/^}\);?\s*\/\*/mg, "}());\n\n/*") // Get rid of the define wrap footer
|
||||
.replace(/}\);(\s*\/\/ Script:)/g, "}());\n\n$1") // Get rid of the define wrap footer before @Cowboy's plugin
|
||||
.replace(/}\);?\s*\(function\(.*\)\s*\{\s*require\([^\(]*?\)\s*;\s*\}\);/g, "}());\n") // Get rid of require( [init] ) function
|
||||
.replace(/}\);?(\s*}\([^\)]*\)\);?)$/, "}());\n$1")
|
||||
.replace(/\s*\(function\(.*\)\s*\{\s*\}\([^)]*\)\);/g, ""); // Get rid of empty functions
|
||||
|
||||
if ( destFileName ) {
|
||||
fs.writeFileSync(destFileName, content, 'utf-8');
|
||||
} else {
|
||||
console.log( content );
|
||||
}
|
||||
}((typeof console !== 'undefined' ? console : undefined),
|
||||
(typeof Packages !== 'undefined' ? Array.prototype.slice.call(arguments, 0) : []),
|
||||
(typeof readFile !== 'undefined' ? readFile : undefined)));
|
||||
Loading…
Reference in a new issue