Skip to content

Commit

Permalink
added preferGlobal, fixes #24
Browse files Browse the repository at this point in the history
  • Loading branch information
tonylukasavage committed Oct 5, 2014
1 parent c205c3c commit 5fcd2be
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 10 deletions.
14 changes: 11 additions & 3 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,17 @@ module.exports = function(grunt) {
command: 'help',
version: true
}
},
should_version_global: {
options: {
command: 'help',
version: true,
preferGlobal: true
}
}
},

// shorthand
ti: {
should_config: {
options: {
Expand Down Expand Up @@ -183,9 +191,9 @@ module.exports = function(grunt) {
// plugin's task(s), then test the result.
grunt.registerTask('test', ['clean', 'ti-version:local', 'ti-version:global',
'env', 'titanium:should_create', 'titanium:should_build', 'titanium:should_project',
'ti:should_config', 'titanium:should_version_local', 'nodeunit:titanium',
'titanium:should_clean', 'titanium_run', 'ti_run', 'nodeunit:titanium_run',
'nodeunit:clean', 'clean']);
'ti:should_config', 'titanium:should_version_local', 'titanium:should_version_global',
'nodeunit:titanium', 'titanium:should_clean', 'titanium_run', 'ti_run',
'nodeunit:titanium_run', 'nodeunit:clean', 'clean']);

// By default, lint and run all tests.
grunt.registerTask('default', ['jshint', 'test']);
Expand Down
17 changes: 11 additions & 6 deletions tasks/titanium.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,8 @@ module.exports = function(grunt) {

// spawn command and output
grunt.log.writeln('titanium ' + args.join(' '));
var ti = spawn(getTitaniumPath(), args,
grunt.log.writeln(getTitaniumPath(preferGlobal));
var ti = spawn(getTitaniumPath(preferGlobal), args,
process.env.GRUNT_TITANIUM_TEST ? {} : {stdio: 'inherit'});
ti.on('close', function(code) {
if (command !== 'build' || options.buildOnly) {
Expand All @@ -223,7 +224,7 @@ module.exports = function(grunt) {
return callback(code);
});
if (process.env.GRUNT_TITANIUM_TEST) {
var testFile = path.resolve('tmp', 'tmp.txt');
var testFile = path.resolve('tmp', preferGlobal ? 'tmp_global.txt' : 'tmp.txt');
grunt.file.mkdir(path.dirname(testFile));
fs.writeFileSync(testFile, '');
ti.stdout.on('data', function(data) {
Expand All @@ -247,10 +248,14 @@ module.exports = function(grunt) {

};

function getTitaniumPath() {
return process.env.GRUNT_TITANIUM_TEST ?
path.resolve('node_modules', '.bin', 'titanium') :
path.resolve('node_modules', 'grunt-titanium', 'node_modules', '.bin', 'titanium');
function getTitaniumPath(preferGlobal) {
if (preferGlobal) {
return 'titanium';
} else {
return process.env.GRUNT_TITANIUM_TEST ?
path.resolve('node_modules', '.bin', 'titanium') :
path.resolve('node_modules', 'grunt-titanium', 'node_modules', '.bin', 'titanium');
}
}

function copyToApp(src, dest, callback) {
Expand Down
10 changes: 9 additions & 1 deletion test/titanium_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,15 @@ exports.titanium = {
test.expect(1);

var v = fs.readFileSync(path.resolve('tmp', 'tmp.txt'), 'utf8').trim();
test.ok(v === process.env.TI_VERSION_LOCAL);
test.equal(v, process.env.TI_VERSION_LOCAL);

test.done();
},
should_version_global: function(test) {
test.expect(1);

var v = fs.readFileSync(path.resolve('tmp', 'tmp_global.txt'), 'utf8').trim();
test.equal(v, process.env.TI_VERSION_GLOBAL);

test.done();
}
Expand Down

0 comments on commit 5fcd2be

Please sign in to comment.