Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'node' of github.com:kuon/cappuccino into node

  • Loading branch information...
commit 630c422a55fac7b3875daeb160d29afb0b300bd8 2 parents 4af2cf8 + c0196dd
@kuon authored
View
4 Foundation/CPString.j
@@ -149,7 +149,7 @@ var CPStringUIDs = new CFMutableDictionary(),
[CPException raise:CPInvalidArgumentException
reason:"initWithFormat: the format can't be 'nil'"];
- self = ObjectiveJ.sprintf.apply(this, Array.prototype.slice.call(arguments, 2));
+ self = objj_sprintf.apply(this, Array.prototype.slice.call(arguments, 2));
return self;
}
@@ -165,7 +165,7 @@ var CPStringUIDs = new CFMutableDictionary(),
[CPException raise:CPInvalidArgumentException
reason:"initWithFormat: the format can't be 'nil'"];
- return ObjectiveJ.sprintf.apply(this, Array.prototype.slice.call(arguments, 2));
+ return objj_sprintf.apply(this, Array.prototype.slice.call(arguments, 2));
}
/*!
View
22 Foundation/Jakefile
@@ -1,19 +1,19 @@
-require('../jakelib/utils.js');
-require('../jakelib/framework.js');
+require('Objective-J/Jake');
-var sources = new jake.FileList(),
+var sourcePaths = new jake.FileList(),
BUILD_DIR = '../Build';
-sources.include('*.j');
-sources.include('CPArray/*.j');
-sources.include('CPPredicate/*.j');
-sources.include('CPSet/*.j');
+sourcePaths.include('*.j');
+sourcePaths.include('CPArray/*.j');
+sourcePaths.include('CPPredicate/*.j');
+sourcePaths.include('CPSet/*.j');
-framework('Foundation',
+tasks.makeFramework('Foundation', nil,
{
- cpp: true,
- sources: sources,
- buildDirectory: BUILD_DIR
+ preprocess: true,
+ sourcePaths: sourcePaths,
+ buildDirectory: BUILD_DIR,
+ installNodePackage: true
});
task('default', ['Foundation']);
View
12 Foundation/package.json
@@ -0,0 +1,12 @@
+{
+ "engines" : {
+ "node" : "*"
+ },
+ "version" : "0.1.0",
+ "name" : "Cappuccino-Foundation",
+ "author" : "The Cappuccino project",
+ "description" : "Cappuccino Foundation framework",
+ "devDependencies" : {},
+ "preferGlobal" : true
+}
+
View
16 Jakefile
@@ -1,4 +1,4 @@
-require('./jakelib/utils.js');
+require('./Objective-J/Jake/Base');
file('node_modules/uglify-js', function()
@@ -14,20 +14,10 @@ file('node_modules/uglify-js', function()
task('required-packages', ['node_modules/uglify-js']);
desc('Objective-J runtime');
-subjake('Objective-J', ['required-packages']);
-
-task('npm-objective-j', ['Objective-J'], function()
-{
- var cmd = 'npm link objective-j';
- jake.exec([cmd], function()
- {
- console.log('[NPM LINK] Objective-J');
- complete();
- }, {stdout:true, stderr:true});
-}, {async:true});
+tasks.subjake('Objective-J', ['required-packages']);
desc('Foundation framework');
-subjake('Foundation', ['npm-objective-j']);
+tasks.subjake('Foundation', ['Objective-J']);
desc('Build cappuccino');
task('default', ['Foundation']);
View
2  Objective-J/Environments/Browser/MainBundle.js
@@ -113,6 +113,6 @@ window._mainBundleResolver = function()
});
if (typeof OBJJ_AUTO_BOOTSTRAP === "undefined" || OBJJ_AUTO_BOOTSTRAP)
- resolveMainBundleURL();
+ afterDocumentLoad(resolveMainBundleURL);
return mainBundleURL;
};
View
164 Objective-J/Jake/Base.js
@@ -0,0 +1,164 @@
+/*!
+ Set of base jake tasks. Those tasks do not require objective-j runtime.
+*/
+global.CONFIGURATIONS = ['Debug', 'Release'];
+global.FILE = require('fs');
+global.PATH = require('path');
+
+global.tasks = {};
+
+global.tasks.subjake = function(folder, dependencies)
+{
+ dependencies = dependencies || [];
+
+ task(folder, dependencies, function()
+ {
+ jake.exec(['cd ' + folder + ' && jake'], function()
+ {
+ complete();
+ }, {stdout:true, stderr:true});
+ }, {async: true});
+};
+
+global.tasks.minify = function(/* String */ targetPath, /* String */ sourcePath, /* Array */ dependencies, /* Object */ options)
+{
+ options = options || {};
+ dependencies = dependencies || [];
+
+ var targetDir = PATH.dirname(targetPath);
+ jake.mkdirP(targetDir);
+ dependencies = dependencies.concat([sourcePath]);
+
+ file(targetPath, dependencies, function()
+ {
+ var parser = require("uglify-js").parser,
+ uglify = require("uglify-js").uglify,
+ originalCode,
+ compressedCode;
+
+ originalCode = FILE.readFileSync(sourcePath).toString();
+
+ console.log('[MINIFY] %s', PATH.basename(sourcePath));
+
+ try
+ {
+ compressedCode = parser.parse(originalCode, true);
+ }
+ catch(error)
+ {
+ var errorLines = originalCode.split('\n').slice(error.line - 2, error.line),
+ gutterWidth = error.line.toString().length + 3;
+
+ console.log('\nError while processing ' + sourcePath + '\n');
+
+ for (var i = 0; i < errorLines.length; i++)
+ {
+ var lineNumber = (error.line + i - 1).toString();
+
+ if (lineNumber.length < gutterWidth - 3)
+ lineNumber = ' ' + lineNumber;
+
+ console.log((lineNumber) + ' # ' + errorLines[i]);
+ if (i == 1)
+ console.log(Array(error.col + gutterWidth).join(' ') + '^ ' + error.message);
+ }
+ console.log('\n');
+ throw error;
+ }
+
+ compressedCode = uglify.ast_mangle(compressedCode);
+ compressedCode = uglify.ast_squeeze(compressedCode);
+ compressedCode = uglify.gen_code(compressedCode);
+ FILE.writeFileSync(targetPath, compressedCode);
+ });
+};
+
+global.tasks.copy = function(/* String */ targetPath, /* String */ sourcePath, /* Array */ dependencies, /* Object */ options)
+{
+ options = options || {};
+ dependencies = dependencies || [];
+
+ var targetDir = PATH.dirname(targetPath);
+ jake.mkdirP(targetDir);
+ dependencies = dependencies.concat([targetDir, sourcePath]);
+
+ file(targetPath, dependencies, function()
+ {
+ console.log('[COPY] %s', PATH.basename(targetPath));
+ jake.cpR(sourcePath, targetPath);
+ });
+};
+
+
+global.tasks.preprocess = function(/* String */ targetPath, /* String */ sourcePath, /* Array */ dependencies, /* Object */ options)
+{
+ options = options || {};
+ dependencies = dependencies || [];
+
+ var targetDir = PATH.dirname(targetPath);
+ jake.mkdirP(targetDir);
+ dependencies = dependencies.concat([sourcePath]);
+
+ file(targetPath, dependencies, function()
+ {
+ var flags = ['-I.'],
+ cmd;
+
+ if (options.flags)
+ flags = flags.concat(options.flags);
+
+ cmd = ['gcc', '-w', '-E', '-x c', '-P'].concat(flags).concat([sourcePath, '-o', targetPath]).join(' ');
+
+ jake.exec([cmd], function()
+ {
+ console.log('[CPP] %s', PATH.basename(sourcePath));
+ complete();
+ }, {stdout:true, stderr:true});
+ }, {async: true});
+};
+
+global.tasks.nodePackage = function(taskName, dependencies, options)
+{
+ options = options || {};
+ dependencies = dependencies || [];
+
+ var buildDir = options.buildDirectory || 'Build',
+ productName = options.productName,
+ packagesDir = PATH.join(buildDir, 'Packages'),
+ packageJSON = JSON.parse(FILE.readFileSync('package.json').toString()),
+ packageName = packageJSON.name,
+ packageDir = PATH.join(packagesDir, packageName),
+ packageJSONPath = PATH.join(packageDir, 'package.json');
+
+
+ task(taskName + '-build', dependencies, function()
+ {
+ if (!productName)
+ fail('No product name for ' + taskName);
+
+ if (!packageName)
+ fail('Package.json has no name');
+
+ jake.mkdirP(packageDir);
+ jake.cpR('package.json', packageJSONPath);
+
+ CONFIGURATIONS.forEach(function(configName)
+ {
+ jake.cpR(PATH.join(buildDir, configName, productName), PATH.join(packageDir, configName));
+ });
+ jake.cpR('package.json', packageDir);
+ });
+
+ task(taskName, [taskName + '-build'], function()
+ {
+ if (!options.install)
+ return;
+
+ var cmd = 'npm install -g ' + packageDir;
+ jake.exec([cmd], function()
+ {
+ console.log('[NPM INSTALL] %s', packageName);
+ complete();
+ }, {stdout:true, stderr:true});
+ }, {async:true});
+};
View
142 Objective-J/Jake/ObjectiveJ.js
@@ -0,0 +1,142 @@
+/*!
+ Set of bundle and objective-j related tasks. This file requires objective-j runtime.
+*/
+
+require(require('path').join(__dirname, 'Base'));
+
+global.OBJJ = require('Objective-j/Tools/Utils');
+
+global.tasks.makeInfoPlist = function(/* String */ targetPath, /* Array */ dependencies, /* Object */ options)
+{
+ options = options || {};
+ dependencies = dependencies || [];
+
+ var targetDir = PATH.dirname(targetPath);
+ jake.mkdirP(targetDir);
+
+ if (options.originalPath)
+ dependencies.push(options.originalPath);
+
+ file(targetPath, dependencies, function()
+ {
+ var plist;
+
+ if (options.originalPath)
+ plist = OBJJ.readPropertyList(options.originalPath);
+ else
+ plist = new CFMutableDictionary();
+
+ // FIXME support more options instead of plist file
+ if (!plist.valueForKey('CPBundleIdentifier'))
+ fail('CPBundleIdentifier is required');
+
+ plist.setValueForKey("CPBundleEnvironments", ['ObjJ']);
+ plist.setValueForKey("CPBundleExecutable", options.executableName);
+
+ console.log('[PLIST] %s', PATH.basename(targetPath));
+ OBJJ.writePropertyList(targetPath, plist);
+ });
+};
+
+global.tasks.compile = function(/* String */ targetPath, /* String */ sourcePath, /* Array */ dependencies, /* Object */ options)
+{
+ options = options || {};
+ dependencies = dependencies || [];
+ var targetDir = PATH.dirname(targetPath);
+ jake.mkdirP(targetDir);
+ dependencies = dependencies.concat([sourcePath]);
+
+ file(targetPath, dependencies, function()
+ {
+ console.log('[OBJJC] %s', PATH.basename(sourcePath));
+ OBJJ.compileFile(targetPath, sourcePath);
+ });
+};
+
+global.tasks.makeStaticArchive = function(/* String */ targetPath, /* Array */ sourcePaths, /* Array */ dependencies, /* Object */ options)
+{
+ options = options || {};
+ dependencies = dependencies || [];
+
+ var targetDir = PATH.dirname(targetPath);
+ jake.mkdirP(targetDir);
+ dependencies = dependencies.concat(sourcePaths);
+
+ file(targetPath, dependencies, function()
+ {
+ console.log('[STATIC] %s', PATH.basename(targetPath));
+ OBJJ.makeStaticArchive(targetPath, sourcePaths);
+ });
+
+};
+
+global.tasks.makeBundle = function(/* String */ name, /* Array */ dependencies, /* Object */ options)
+{
+ options = options || {};
+ dependencies = dependencies || [];
+
+ var targets = [],
+ originalPlistPath = options.infoPlistPath || 'Info.plist',
+ sourcePaths = options.sourcePaths.toArray(),
+ buildDir = options.buildDirectory,
+ packageDir;
+
+
+ CONFIGURATIONS.forEach(function(configName)
+ {
+ var intermediateBuildDir = PATH.join(buildDir, name + '.build/', configName),
+ finalBuildDir = PATH.join(buildDir, configName, name),
+ plistPath = PATH.join(finalBuildDir, 'Info.plist'),
+ staticArchiveDir = PATH.join(finalBuildDir, 'ObjJ.environment'),
+ staticArchivePath = PATH.join(staticArchiveDir, name + '.sj'),
+ compiledPaths = [];
+
+ sourcePaths.forEach(function(sourcePath)
+ {
+ var filename = PATH.basename(sourcePath),
+ preprocessPath = PATH.join(intermediateBuildDir, filename),
+ compiledPath = preprocessPath.replace(/\.j$/, '.sj');
+
+
+ // Preprocess (CPP)
+ if (options.preprocess)
+ tasks.preprocess(preprocessPath, sourcePath);
+ else
+ tasks.copy(preprocessPath, sourcePath);
+
+
+ // Compile (OBJJC)
+ tasks.compile(compiledPath, preprocessPath);
+
+ compiledPaths.push(compiledPath);
+ });
+
+ tasks.makeStaticArchive(staticArchivePath, compiledPaths);
+ targets.push(staticArchivePath);
+
+ var infoPlistOptions =
+ {
+ originalPath : originalPlistPath,
+ executableName : PATH.basename(staticArchivePath)
+ };
+ tasks.makeInfoPlist(plistPath, [staticArchivePath], infoPlistOptions);
+ targets.push(plistPath);
+ });
+
+ task(name + '-bundle', targets.concat(dependencies));
+
+ dependencies = [name + '-bundle'];
+
+ if (PATH.existsSync('package.json'))
+ {
+ tasks.nodePackage(name + '-package', dependencies, {buildDirectory: buildDir, productName: name, install: options.installNodePackage});
+ dependencies = [name + '-package'];
+ }
+
+ task(name, dependencies);
+};
+
+global.tasks.makeFramework = function(/* String */ name, /* Array */ dependencies, /* Object */ options)
+{
+ tasks.makeBundle(name, dependencies, options);
+};
View
1  Objective-J/Jake/index.js
@@ -0,0 +1 @@
+require(require('path').join(__dirname, 'ObjectiveJ'));
View
56 Objective-J/Jakefile
@@ -1,4 +1,4 @@
-require('../jakelib/utils.js');
+require('./Jake/Base');
var BUILD_DIR = '../Build',
ENVIRONMENTS = FILE.readdirSync('Environments'),
@@ -13,18 +13,16 @@ sharedSources = sharedSources.toArray();
// Create one set of tasks per environment per configuration
CONFIGURATIONS.forEach(function(configName)
{
- var finalBuildDir = PATH.join(BUILD_DIR, configName, 'Objective-J'),
+ var finalBuildDir = PATH.join(BUILD_DIR, configName, 'Objective-J' );
intermediateBuildDir = PATH.join(BUILD_DIR, 'Objective-J.build', configName);
- recursiveDirectory(finalBuildDir);
- recursiveDirectory(intermediateBuildDir);
ENVIRONMENTS.forEach(function(env)
{
if (!FILE.statSync(PATH.join('Environments', env)).isDirectory())
return;
- var source = PATH.join('Environments', env, 'Objective-J.' + env + '.js'),
+ var sourcePath = PATH.join('Environments', env, 'Objective-J.' + env + '.js'),
envSources = new jake.FileList(),
flags = ['-ISource', '-IEnvironments/' + env],
intermediateTarget = PATH.join(intermediateBuildDir, 'Objective-J.' + env + '.js'),
@@ -36,43 +34,35 @@ CONFIGURATIONS.forEach(function(configName)
envSources.include('Environments/' + env + '/*');
envSources = envSources.toArray();
+ tasks.preprocess(intermediateTarget, sourcePath, sharedSources.concat(envSources), {flags:flags});
- file(intermediateTarget, [intermediateBuildDir].concat(sharedSources).concat(envSources), function()
- {
- cpp(source, intermediateTarget, flags);
- }, {async: true});
-
- file(finalTarget, [intermediateTarget, finalBuildDir], function()
- {
- if (configName === 'Release')
- minify(intermediateTarget, finalTarget);
- else
- jake.cpR(intermediateTarget, finalTarget);
- });
+ if (configName === 'Release')
+ tasks.minify(finalTarget, intermediateTarget);
+ else
+ tasks.copy(finalTarget, intermediateTarget);
targets.push(finalTarget);
});
- task(configName, targets, function()
- {
- jake.cpR('Tools', finalBuildDir);
- jake.cpR('package.json', finalBuildDir);
- });
+
});
-task('npm-link', ['objective-j'], function()
+var packageDir = PATH.join(BUILD_DIR, 'Packages', 'Objective-J'),
+ toolPaths = new jake.FileList();
+
+toolPaths.include('Tools/*.js');
+toolPaths.include('Jake/*.js');
+
+toolPaths.toArray().forEach(function(toolPath)
{
- var cmd = 'cd ' + BUILD_DIR + '/Release/Objective-J/ && npm link';
- jake.exec([cmd], function()
- {
- console.log('[NPM LINK] Objective-J');
- complete();
- }, {stdout:true, stderr:true});
-}, {async:true});
+ var toolTarget = PATH.join(packageDir, PATH.dirname(toolPath), PATH.basename(toolPath));
+ tasks.copy(toolTarget, toolPath);
+ targets.push(toolTarget);
+});
+
+tasks.nodePackage('npm-package', targets, {buildDirectory: BUILD_DIR, productName: 'Objective-J', install: true});
-desc('Build Objective-J');
-task('objective-j', CONFIGURATIONS);
-task('default', ['objective-j', 'npm-link']);
+task('default', ['npm-package']);
View
2  Objective-J/Tools/Compiler.js
@@ -87,7 +87,7 @@ if (!argv.unmarked)
compiledFiles.forEach(function(compiledFile)
{
- var relativePath = PATH.basename(compiledFile.path),
+ var relativePath = PATH.basename(compiledFile.path).replace(/\.sj$/, '.j'),
contents = compiledFile.contents;
if (!argv.unmarked)
View
104 Objective-J/Tools/Utils.js
@@ -0,0 +1,104 @@
+var PATH = require('path'),
+ FILE = require('fs');
+
+require('objective-j');
+
+/*!
+ @defgroup objective-j/tasks Objective-J tasks
+ @{
+*/
+
+/*!
+ Compile objective-j code.
+ @param source a string containing the objective-j code
+ @param options the options object
+ @param options:markedString return a marked js string
+ @param options:minify minify the resulting javascript
+ @param options:filename the filename to use for error message
+ @return compiled javascript source or marked string
+*/
+exports.compile = function(/* String */ source, /* Object */ options)
+{
+ options = options || {};
+
+ var executable = objj_preprocess(source, options.filename);
+
+ if (options.minify)
+ {
+ var parser = require("uglify-js").parser,
+ uglify = require("uglify-js").uglify,
+ compiledCode = executable.code(),
+ compressedCode;
+
+ compressedCode = parser.parse(compiledCode);
+ compressedCode = uglify.ast_mangle(compressedCode);
+ compressedCode = uglify.ast_squeeze(compressedCode);
+ compressedCode = uglify.gen_code(compressedCode);
+ executable.setCode(compressedCode);
+ }
+
+ return options.markedString ? executable.toMarkedString() : executable.code();
+
+};
+
+exports.compileFile = function(/* String */ targetPath, /* String */ sourcePath)
+{
+ var buffer = FILE.readFileSync(sourcePath).toString();
+
+ if (!targetPath)
+ targetPath = sourcePath.replace(/\.j$/, '.sj');
+
+ buffer = exports.compile(buffer, {minify:true, markedString:true});
+ FILE.writeFileSync(targetPath, buffer);
+};
+
+exports.readPropertyList = function(/* String */ plistPath)
+{
+ var plistData = FILE.readFileSync(plistPath).toString(),
+ plist = CFPropertyList.propertyListFromString(plistData);
+
+ if (!plist)
+ throw "Cannot read property list";
+
+ return plist;
+};
+
+exports.writePropertyList = function(/* String */ plistPath, /* CFPropertyList */ plist, /* int */ destinationFormat)
+{
+ if (!destinationFormat)
+ destinationFormat = CFPropertyList.Format280North_v1_0;
+
+ var buffer = CFPropertyList.stringFromPropertyList(plist, destinationFormat);
+ FILE.writeFileSync(plistPath, buffer);
+};
+
+
+exports.makeStaticArchive = function(/* String */ outputPath, /* Array */ codePaths, /* String */ relativeToPath)
+{
+ var buffer = [];
+ buffer.push("@STATIC;1.0;");
+
+ codePaths.forEach(function(codePath)
+ {
+ var relativePath = PATH.basename(codePath).replace(/\.sj$/, '.j'),
+ contents = FILE.readFileSync(codePath).toString();
+
+ buffer.push("p;" + relativePath.length + ";" + relativePath);
+ buffer.push("t;" + contents.length + ";" + contents);
+ });
+ FILE.writeFileSync(outputPath, buffer.join(''));
+};
+
+exports.decompile = function(/* String */ compiledCode, /* Object */ options)
+{
+ // Decompile marked string
+};
+
+exports.decomposeStaticArchive = function(/* String */ outputDirectory, /* String */ archivePath)
+{
+};
+
+
+/*!
+ @}
+*/
View
6 Objective-J/package.json
@@ -3,7 +3,7 @@
"node" : "*"
},
"bin" : {
- "objjc" : "./Tools/Compiler.js"
+ "objjc" : "Tools/Compiler.js"
},
"version" : "0.1.0",
"dependencies" : {
@@ -11,10 +11,10 @@
"xmldom" : ">=0.1.2",
"optimist" : ">=0.3.4"
},
- "name" : "objective-j",
+ "name" : "Objective-J",
"author" : "The Cappuccino project",
"description" : "Objective-J runtime and compiler",
- "main" : "./Objective-J.NodeJS.js",
+ "main" : "Release/Objective-J.NodeJS.js",
"keywords" : [
"compile"
],
View
3  bootstrap.sh
@@ -0,0 +1,3 @@
+# install node and npm, make a windows counterpart of this script
+npm install -g jake
+npm install -g minimatch
View
3  jakelib/bundle.js
@@ -1,3 +0,0 @@
-global.bundle = function(/* String */ name, /* Object */ options)
-{
-};
View
63 jakelib/framework.js
@@ -1,63 +0,0 @@
-require(__dirname + '/bundle.js');
-
-global.framework = function(/* String */ name, /* Object */ options)
-{
- var targets = [],
- infoPlist = 'Info.plist',
- buildDirectory = options.buildDirectory;
-
- sources = options.sources.toArray();
-
- CONFIGURATIONS.forEach(function(configName)
- {
- var intermediateBuildDir = PATH.join(buildDirectory, name + '.build/', configName),
- intermediateTargets = [],
- finalBuildDir = PATH.join(buildDirectory, configName, name),
- staticTarget = PATH.join(finalBuildDir, name + '.sj'),
- infoTarget = PATH.join(finalBuildDir, infoPlist);
-
-
- recursiveDirectory(intermediateBuildDir);
- recursiveDirectory(finalBuildDir);
-
- sources.forEach(function(source)
- {
- var flags = ['-I.'],
- filename = PATH.basename(source),
- intermediateTarget = PATH.join(intermediateBuildDir, filename);
-
-
- file(intermediateTarget, [intermediateBuildDir, source], function()
- {
- if (options.cpp)
- cpp(source, intermediateTarget, flags);
- else
- {
- jake.cpR(source, intermediateTarget);
- complete();
- }
- }, {async: true});
-
- intermediateTargets.push(intermediateTarget);
-
- });
-
- file(staticTarget, [finalBuildDir].concat(intermediateTargets), function()
- {
- compile(intermediateTargets, staticTarget);
- }, {async: true});
-
- targets.push(staticTarget);
-
- // TODO: more to do with the plist
- file(infoTarget, [finalBuildDir, infoPlist], function()
- {
- jake.cpR(infoPlist, infoTarget);
- });
- targets.push(infoTarget);
- });
-
- desc('Build framework ' + name);
- task(name, targets);
-
-};
View
100 jakelib/utils.js
@@ -1,100 +0,0 @@
-global.CONFIGURATIONS = ['Debug', 'Release'];
-global.FILE = require('fs');
-global.PATH = require('path');
-
-global.cpp = function(source, target, flags)
-{
- var cmd = ['gcc', '-w', '-E', '-x c', '-P'].concat(flags).concat([source, '-o', target]).join(' ');
-
- jake.exec([cmd], function()
- {
- console.log('[CPP] %s', source);
- complete();
- }, {stdout:true, stderr:true});
-};
-
-global.compile = function(sources, target)
-{
- if (typeof(sources) === 'string')
- sources = [sources];
-
- var cmd = ['objjc'].concat(sources).concat(['-o', target]).join(' ');
- jake.exec([cmd], function()
- {
- complete();
- }, {stdout:true, stderr:true});
-};
-
-global.subjake = function(folder, deps)
-{
- if (deps === undefined)
- deps = [];
-
- task(folder, deps, function()
- {
- jake.exec(['cd ' + folder + ' && jake'], function()
- {
- complete();
- }, {stdout:true, stderr:true});
- }, {async: true});
-};
-
-global.minify = function(source, target)
-{
- var parser = require("uglify-js").parser,
- uglify = require("uglify-js").uglify,
- originalCode,
- compressedCode;
-
- originalCode = FILE.readFileSync(source).toString();
-
- console.log('[MINIFY] %s', source);
-
- try
- {
- compressedCode = parser.parse(originalCode, true);
- }
- catch(error)
- {
- var errorLines = originalCode.split('\n').slice(error.line - 2, error.line),
- gutterWidth = error.line.toString().length + 3;
-
- console.log('\nError while processing ' + source + '\n');
-
- for (var i = 0; i < errorLines.length; i++)
- {
- var lineNumber = (error.line + i - 1).toString();
-
- if (lineNumber.length < gutterWidth - 3)
- lineNumber = ' ' + lineNumber;
-
- console.log((lineNumber) + ' # ' + errorLines[i]);
- if (i == 1)
- console.log(Array(error.col + gutterWidth).join(' ') + '^ ' + error.message);
- }
- console.log('\n');
- throw error;
- }
-
- compressedCode = uglify.ast_mangle(compressedCode);
- compressedCode = uglify.ast_squeeze(compressedCode);
- compressedCode = uglify.gen_code(compressedCode);
- FILE.writeFileSync(target, compressedCode);
-};
-
-global.recursiveDirectory = function(path)
-{
- var cpmts = path.split('/'),
- paths = [];
-
- for (var i = 0; i < cpmts.length; i++)
- {
- var parentPath = cpmts.slice(0, i).join('/'),
- currentPath = cpmts.slice(0, i+1).join('/');
-
- if (parentPath)
- directory(currentPath, [parentPath]);
- else
- directory(currentPath);
- }
-};
Please sign in to comment.
Something went wrong with that request. Please try again.