-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathconfigure.js
More file actions
70 lines (59 loc) · 2.59 KB
/
configure.js
File metadata and controls
70 lines (59 loc) · 2.59 KB
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
var clc = require('cli-color'),
inquirer = require('inquirer'),
Promise = require('promise'),
util = require('util'),
extend = util._extend,
utils = require('./utils');
var localConfig = utils.getLocalConfiguration();
var globalConfig = utils.getGlobalConfiguration();
var config = extend(globalConfig, localConfig);
module.exports = function(program){
program
.option('-p, --project <project_id>', 'The project ID to use for POEditor translation management')
.option('-a, --apitoken <api_token>', 'The API-Token to use for POEdtior translation management')
.option('-t, --target <target_dir>', 'The target directory the translations should be saved to')
.option('-e, --exporttype <export_type>', 'The filetype the pulled files should be saved as. Currently "json", "json-properties" and "properties" are supported. Default is "properties".')
.option('-s, --single <target_filename>', 'Set this option to export into one single file given and not into multiple')
.option('-l, --languages <languages>', 'The languages that should be pulled (comma separated)', function(val){
return val.split(',');
});
program.parse(process.argv);
var cfg = {};
cfg.targetDir = program.target || config.targetDir || './';
cfg.apiToken = program.apitoken || config.apiToken;
cfg.projectId = program.project || config.projectId;
cfg.projectLanguages = program.languages || config.projectLanguages;
cfg.defaultLanguage = config.defaultLanguage || 'en-us';
cfg.exportType = program.exporttype || config.exportType || 'properties';
cfg.exportSingleFileTarget = program.single || config.exportSingleFileTarget;
return new Promise(function(resolve, reject) {
if (!cfg.apiToken || !cfg.projectId) {
console.log(clc.red("\n>> No API token or project id found for POEditor. Please provide the necessary information in the following steps. <<\n"));
inquirer.prompt([
{
type: "input",
name: "token",
message: "API token"
}
], function (answers) {
cfg.apiToken = answers.token;
utils.setLocalConfiguration("apiToken", cfg.apiToken);
utils.chooseProject(cfg.apiToken).then(function(res){
var projectId = res[0],
languages = res[1];
cfg.projectLanguages = languages;
cfg.projectId = projectId;
utils.setLocalConfiguration("projectId", projectId);
utils.setLocalConfiguration("projectLanguages", languages);
utils.chooseTargetDir().then(function(targetDir){
cfg.targetDir = targetDir;
utils.setLocalConfiguration("targetDir", targetDir);
resolve(cfg);
}, reject);
}, reject);
});
} else {
resolve(cfg);
}
});
};