forked from jasonkneen/ti-i18n
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
80 lines (61 loc) · 2.02 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
var fs = require("fs"),
path = require("path"),
fields = require('fields'),
_ = require('underscore'),
exec = require('exec'),
config = require('./config'),
logger = require("./lib/logger");
// Execute a shell command
function execute(executable, params, callback) {
params.unshift(executable);
callback = _.isFunction(callback) ? callback : function() {};
exec(params, callback);
}
// Plug i18n into the Titanium CLI
exports.plug = function() {
config.banner();
exports.plugged(null, function(plugged) {
if (!plugged) {
execute('ti', ['config', '-a', 'paths.commands', __dirname, 'commands']);
}
console.log('You can now use: ' + 'ti i18n'.green);
});
};
// Unplug i18n from the Titanium CLI
exports.unplug = function() {
config.banner();
exports.plugged(null, function(plugged) {
if (plugged) {
execute('ti', ['config', '-r', 'paths.commands', __dirname, 'commands']);
}
console.log('You can now only use: ' + 'ti-i18n'.green);
});
};
// Print or return (via callback) if we're plugged into the Titanium CLI
exports.plugged = function(env, callback) {
execute('ti', ['config', '-o', 'json-object'], function(err, out, code) {
if (err) {
logger.error(err);
} else {
var object = JSON.parse(out),
plugged = _.contains(object.paths.commands, path.join(__dirname, 'commands'));
if (_.isFunction(callback)) {
callback(plugged);
} else {
console.log(plugged ? 'yes'.green : 'no'.red);
}
}
});
};
// Extract strings from source and save to strings.xml file
exports.extract = function(options) {
require('./lib/extract').run(options);
};
// Sync strings between languages
exports.sync = function(options) {
require('./lib/sync').run(options);
};
// Merge (translated) strings back into language
exports.merge = function(options) {
require('./lib/merge').run(options);
}