locize-cli 10.3.1 → 10.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,11 +1,11 @@
1
1
  const filterNamespaces = (opt, nss) => {
2
2
  if (opt.namespace) {
3
- nss = nss.filter((ns) => ns.namespace === opt.namespace);
3
+ nss = nss.filter((ns) => ns.namespace === opt.namespace)
4
4
  }
5
5
  if (opt.namespaces && opt.namespaces.length > 0) {
6
- nss = nss.filter((ns) => opt.namespaces.indexOf(ns.namespace) > -1);
6
+ nss = nss.filter((ns) => opt.namespaces.indexOf(ns.namespace) > -1)
7
7
  }
8
- return nss;
9
- };
8
+ return nss
9
+ }
10
10
 
11
- module.exports = filterNamespaces;
11
+ module.exports = filterNamespaces
package/format.js CHANGED
@@ -1,205 +1,206 @@
1
- const colors = require('colors');
2
- const fs = require('fs');
3
- const async = require('async');
4
- const path = require('path');
5
- const diff = require('diff');
6
- const convertToFlatFormat = require('./convertToFlatFormat');
7
- const convertToDesiredFormat = require('./convertToDesiredFormat');
8
- const sortFlatResources = require('./sortFlatResources');
9
- const formats = require('./formats');
10
- const fileExtensionsMap = formats.fileExtensionsMap;
11
- const acceptedFileExtensions = formats.acceptedFileExtensions;
12
- const reversedFileExtensionsMap = formats.reversedFileExtensionsMap;
1
+ const colors = require('colors')
2
+ const fs = require('fs')
3
+ const async = require('async')
4
+ const path = require('path')
5
+ const diff = require('diff')
6
+ const convertToFlatFormat = require('./convertToFlatFormat')
7
+ const convertToDesiredFormat = require('./convertToDesiredFormat')
8
+ const sortFlatResources = require('./sortFlatResources')
9
+ const formats = require('./formats')
10
+ const fileExtensionsMap = formats.fileExtensionsMap
11
+ const acceptedFileExtensions = formats.acceptedFileExtensions
12
+ const reversedFileExtensionsMap = formats.reversedFileExtensionsMap
13
13
 
14
14
  const handleError = (err, cb) => {
15
15
  if (!cb && err) {
16
- console.error(colors.red(err.message));
17
- process.exit(1);
16
+ console.error(colors.red(err.message))
17
+ process.exit(1)
18
18
  }
19
- if (cb) cb(err);
20
- };
19
+ if (cb) cb(err)
20
+ }
21
21
 
22
22
  const getFiles = (srcpath) => {
23
- var files = [];
23
+ let files = []
24
24
  fs.readdirSync(srcpath).forEach((file) => {
25
25
  if (fs.statSync(path.join(srcpath, file)).isDirectory()) {
26
- files = files.concat(getFiles(path.join(srcpath, file)));
26
+ files = files.concat(getFiles(path.join(srcpath, file)))
27
27
  } else if (acceptedFileExtensions.indexOf(path.extname(file)) > -1) {
28
- files.push(path.join(srcpath, file));
28
+ files.push(path.join(srcpath, file))
29
29
  }
30
- });
31
- return files;
32
- };
30
+ })
31
+ return files
32
+ }
33
33
 
34
- function readLocalFile(opt, fPath, clb) {
35
- const fExt = path.extname(fPath);
36
- const namespace = path.basename(fPath, fExt);
37
- const splitted = fPath.split(path.sep);
38
- const lng = splitted[splitted.length - 2];
34
+ function readLocalFile (opt, fPath, clb) {
35
+ const fExt = path.extname(fPath)
36
+ const namespace = path.basename(fPath, fExt)
37
+ const splitted = fPath.split(path.sep)
38
+ const lng = splitted[splitted.length - 2]
39
39
 
40
40
  fs.readFile(fPath, (err, data) => {
41
- if (err) return clb(err);
41
+ if (err) return clb(err)
42
42
 
43
43
  fs.stat(fPath, (err, stat) => {
44
- if (err) return clb(err);
44
+ if (err) return clb(err)
45
45
 
46
46
  clb(null, {
47
- namespace: namespace,
47
+ namespace,
48
48
  path: fPath,
49
49
  extension: fExt,
50
50
  original: data.toString(),
51
51
  language: lng,
52
52
  mtime: stat.mtime
53
- });
54
- });
55
- });
53
+ })
54
+ })
55
+ })
56
56
  }
57
57
 
58
- function readLocalFiles(opt, filePaths, clb) {
58
+ function readLocalFiles (opt, filePaths, clb) {
59
59
  async.map(filePaths, (filePath, cb) => {
60
- readLocalFile(opt, filePath, cb);
61
- }, clb);
60
+ readLocalFile(opt, filePath, cb)
61
+ }, clb)
62
62
  }
63
63
 
64
- function convertAllFilesToFlatFormat(opt, files, clb) {
64
+ function convertAllFilesToFlatFormat (opt, files, clb) {
65
65
  async.map(files, (file, cb) => {
66
66
  if (fileExtensionsMap[file.extension].indexOf(opt.format) < 0) {
67
- return cb(new Error(`Format mismatch! Found ${fileExtensionsMap[file.extension][0]} but requested ${opt.format}!`));
67
+ return cb(new Error(`Format mismatch! Found ${fileExtensionsMap[file.extension][0]} but requested ${opt.format}!`))
68
68
  }
69
69
 
70
70
  convertToFlatFormat(opt, file.original, (err, content) => {
71
71
  if (err) {
72
- err.message = 'Invalid content for "' + opt.format + '" format!\n' + (err.message || '');
73
- err.message += '\n' + file.path;
74
- return cb(err);
72
+ err.message = 'Invalid content for "' + opt.format + '" format!\n' + (err.message || '')
73
+ err.message += '\n' + file.path
74
+ return cb(err)
75
75
  }
76
76
 
77
- file.content = sortFlatResources(content);
78
- cb(null, file);
79
- });
80
- }, clb);
77
+ file.content = sortFlatResources(content)
78
+ cb(null, file)
79
+ })
80
+ }, clb)
81
81
  }
82
82
 
83
- function convertAllFilesToDesiredFormat(opt, files, clb) {
83
+ function convertAllFilesToDesiredFormat (opt, files, clb) {
84
84
  async.map(files, (file, cb) => {
85
85
  convertToDesiredFormat(opt, file.namespace, file.language, file.content, file.mtime, (err, res) => {
86
86
  if (err) {
87
- err.message = 'Invalid content for "' + opt.format + '" format!\n' + (err.message || '');
88
- return cb(err);
87
+ err.message = 'Invalid content for "' + opt.format + '" format!\n' + (err.message || '')
88
+ return cb(err)
89
89
  }
90
- file.converted = res;
91
- cb(null, file);
92
- });
93
- }, clb);
90
+ res = (opt.format !== 'xlsx' && !res.endsWith('\n')) ? (res + '\n') : res
91
+ file.converted = res
92
+ cb(null, file)
93
+ })
94
+ }, clb)
94
95
  }
95
96
 
96
- function writeLocalFile(opt, file, clb) {
97
+ function writeLocalFile (opt, file, clb) {
97
98
  if (file.converted === file.original) {
98
- if (opt.noCallback) console.log(colors.grey(`${file.path} unchanged`));
99
- return clb(null);
99
+ if (opt.noCallback) console.log(colors.grey(`${file.path} unchanged`))
100
+ return clb(null)
100
101
  }
101
102
 
102
- const d = diff.diffLines(file.original, file.converted);
103
+ const d = diff.diffLines(file.original, file.converted)
103
104
  d.forEach((part) => {
104
105
  // green for additions, red for deletions
105
106
  // grey for common parts
106
- const color = part.added ? 'green' : part.removed ? 'red' : 'grey';
107
- if (opt.noCallback) console.log(part.value[color]);
108
- });
107
+ const color = part.added ? 'green' : part.removed ? 'red' : 'grey'
108
+ if (opt.noCallback) console.log(part.value[color])
109
+ })
109
110
 
110
- if (opt.noCallback) console.log(colors.yellow(`reformatting ${file.path}...`));
111
+ if (opt.noCallback) console.log(colors.yellow(`reformatting ${file.path}...`))
111
112
  if (opt.dry) {
112
- if (opt.noCallback) console.log(colors.yellow(`would have reformatted ${file.path}...`));
113
- return clb(null, true);
113
+ if (opt.noCallback) console.log(colors.yellow(`would have reformatted ${file.path}...`))
114
+ return clb(null, true)
114
115
  }
115
116
 
116
- const fileContent = (opt.format !== 'xlsx' && !file.converted.endsWith('\n')) ? (file.converted + '\n') : file.converted;
117
+ const fileContent = (opt.format !== 'xlsx' && !file.converted.endsWith('\n')) ? (file.converted + '\n') : file.converted
117
118
 
118
- fs.writeFile(file.path, fileContent, (err) => clb(err, true));
119
+ fs.writeFile(file.path, fileContent, (err) => clb(err, true))
119
120
  }
120
121
 
121
- function writeLocalFiles(opt, files, clb) {
122
+ function writeLocalFiles (opt, files, clb) {
122
123
  async.map(files, (file, cb) => {
123
- writeLocalFile(opt, file, cb);
124
- }, clb);
124
+ writeLocalFile(opt, file, cb)
125
+ }, clb)
125
126
  }
126
127
 
127
- function processFiles(opt, filePaths, clb) {
128
+ function processFiles (opt, filePaths, clb) {
128
129
  readLocalFiles(opt, filePaths, (err, orgFiles) => {
129
- if (err) return clb(err);
130
+ if (err) return clb(err)
130
131
 
131
132
  if (!opt.format) {
132
133
  if (orgFiles.length === 0) {
133
- return clb(new Error('Please provide a format!'));
134
+ return clb(new Error('Please provide a format!'))
134
135
  }
135
136
  // guess format
136
- opt.format = fileExtensionsMap[orgFiles[0].extension][0];
137
- if (opt.noCallback) console.log(colors.bgYellow(`No format argument was passed, so guessing "${opt.format}" format.`));
137
+ opt.format = fileExtensionsMap[orgFiles[0].extension][0]
138
+ if (opt.noCallback) console.log(colors.bgYellow(`No format argument was passed, so guessing "${opt.format}" format.`))
138
139
  }
139
140
 
140
141
  convertAllFilesToFlatFormat(opt, orgFiles, (err, files) => {
141
- if (err) return clb(err);
142
+ if (err) return clb(err)
142
143
 
143
144
  opt.getNamespace = (o, lng, ns, cb) => {
144
- const foundOrgFile = orgFiles.find((f) => f.namespace === ns && f.language === lng);
145
+ const foundOrgFile = orgFiles.find((f) => f.namespace === ns && f.language === lng)
145
146
  if (!foundOrgFile) {
146
- return cb(new Error(`No file found for language "${lng}" and namespace "${ns}" locally!`));
147
+ return cb(new Error(`No file found for language "${lng}" and namespace "${ns}" locally!`))
147
148
  }
148
- cb(null, foundOrgFile.content, foundOrgFile.mtime);
149
- };
149
+ cb(null, foundOrgFile.content, foundOrgFile.mtime)
150
+ }
150
151
 
151
152
  // just the value
152
153
  files.forEach((f) => {
153
154
  if (f.content) {
154
155
  Object.keys(f.content).forEach((k) => {
155
156
  if (f.content[k] && typeof f.content[k] === 'object' && f.content[k].value !== undefined) {
156
- f.content[k] = f.content[k].value;
157
+ f.content[k] = f.content[k].value
157
158
  }
158
- });
159
+ })
159
160
  }
160
- });
161
+ })
161
162
 
162
163
  convertAllFilesToDesiredFormat(opt, files, (err, convertedFiles) => {
163
- if (err) return clb(err);
164
+ if (err) return clb(err)
164
165
 
165
- writeLocalFiles(opt, convertedFiles, clb);
166
- });
167
- });
168
- });
166
+ writeLocalFiles(opt, convertedFiles, clb)
167
+ })
168
+ })
169
+ })
169
170
  }
170
171
 
171
172
  const format = (opt, cb) => {
172
173
  if (opt.format && !reversedFileExtensionsMap[opt.format]) {
173
- return handleError(new Error(`${opt.format} is not a valid format!`), cb);
174
+ return handleError(new Error(`${opt.format} is not a valid format!`), cb)
174
175
  }
175
176
 
176
- opt.noCallback = !cb;
177
+ opt.noCallback = !cb
177
178
 
178
179
  fs.lstat(opt.fileOrDirectory, (err, stat) => {
179
- if (err) return handleError(err, cb);
180
+ if (err) return handleError(err, cb)
180
181
 
181
- const isDirectory = stat.isDirectory();
182
+ const isDirectory = stat.isDirectory()
182
183
 
183
- var filePaths = [];
184
+ let filePaths = []
184
185
  if (isDirectory) {
185
186
  try {
186
- filePaths = getFiles(opt.fileOrDirectory);
187
+ filePaths = getFiles(opt.fileOrDirectory)
187
188
  } catch (err) {}
188
189
  } else {
189
- filePaths = [opt.fileOrDirectory];
190
+ filePaths = [opt.fileOrDirectory]
190
191
  }
191
192
 
192
193
  processFiles(opt, filePaths, (err, writeResults) => {
193
- if (err) return handleError(err, cb);
194
+ if (err) return handleError(err, cb)
194
195
  if (!cb) {
195
- console.log(colors.green('FINISHED'));
196
+ console.log(colors.green('FINISHED'))
196
197
  if (opt.dry && writeResults.find((wr) => !!wr)) {
197
- process.exit(1);
198
+ process.exit(1)
198
199
  }
199
200
  }
200
- if (cb) cb(null);
201
- });
202
- });
203
- };
201
+ if (cb) cb(null)
202
+ })
203
+ })
204
+ }
204
205
 
205
- module.exports = format;
206
+ module.exports = format
package/formats.js CHANGED
@@ -15,19 +15,19 @@ const fileExtensionsMap = {
15
15
  '.php': ['laravel'],
16
16
  '.properties': ['properties'],
17
17
  '.xcstrings': ['xcstrings']
18
- };
18
+ }
19
19
 
20
- const acceptedFileExtensions = Object.keys(fileExtensionsMap);
20
+ const acceptedFileExtensions = Object.keys(fileExtensionsMap)
21
21
 
22
- const reversedFileExtensionsMap = {};
22
+ const reversedFileExtensionsMap = {}
23
23
  acceptedFileExtensions.forEach((ext) => {
24
24
  fileExtensionsMap[ext].forEach((format) => {
25
- reversedFileExtensionsMap[format] = ext;
26
- });
27
- });
25
+ reversedFileExtensionsMap[format] = ext
26
+ })
27
+ })
28
28
 
29
29
  module.exports = {
30
- fileExtensionsMap: fileExtensionsMap,
31
- acceptedFileExtensions: acceptedFileExtensions,
32
- reversedFileExtensionsMap: reversedFileExtensionsMap
33
- };
30
+ fileExtensionsMap,
31
+ acceptedFileExtensions,
32
+ reversedFileExtensionsMap
33
+ }
package/get.js CHANGED
@@ -1,8 +1,9 @@
1
- const colors = require('colors');
2
- const request = require('./request');
3
- const flatten = require('flat');
1
+ const colors = require('colors')
2
+ const request = require('./request')
3
+ const flatten = require('flat')
4
4
 
5
5
  const get = (opt, cb) => {
6
+ if (!opt.getPath) opt.getPath = `${opt.apiPath}/{{projectId}}/{{version}}/{{lng}}/{{ns}}`
6
7
  const url = opt.getPath
7
8
  .replace('{{projectId}}', opt.projectId)
8
9
  .replace('{{ver}}', opt.version)
@@ -10,69 +11,72 @@ const get = (opt, cb) => {
10
11
  .replace('{{language}}', opt.language)
11
12
  .replace('{{lng}}', opt.language)
12
13
  .replace('{{ns}}', opt.namespace)
13
- .replace('{{namespace}}', opt.namespace);
14
+ .replace('{{namespace}}', opt.namespace)
14
15
 
15
16
  // if (!cb) console.log(colors.yellow(`getting ${opt.key} from ${opt.version}/${opt.language}/${opt.namespace}...`));
16
17
 
17
18
  if (opt.key && opt.key.indexOf(',') > 0 && opt.key.indexOf(' ') < 0) {
18
- opt.keys = opt.key.split(',');
19
- delete opt.key;
19
+ opt.keys = opt.key.split(',')
20
+ delete opt.key
20
21
  }
21
22
 
22
- request(url, {
23
+ request(`${url}${opt.cdnType === 'standard' ? '?cache=no' : ''}`, {
23
24
  method: 'get'
24
25
  }, (err, res, obj) => {
25
26
  if (err) {
26
- if (!cb) console.log(colors.red(`get failed for ${opt.key || opt.keys.join(', ')} from ${opt.version}/${opt.language}/${opt.namespace}...`));
27
+ if (!cb) console.log(colors.red(`get failed for ${opt.key || opt.keys.join(', ')} from ${opt.version}/${opt.language}/${opt.namespace}...`))
27
28
  if (err) {
28
- if (!cb) { console.error(colors.red(err.message)); process.exit(1); }
29
- if (cb) cb(err);
30
- return;
29
+ if (!cb) { console.error(colors.red(err.message)); process.exit(1) }
30
+ if (cb) cb(err)
31
+ return
31
32
  }
32
33
  }
33
- if (res.status >= 300) {
34
- if (!cb) { console.error(colors.red(res.statusText + ' (' + res.status + ')')); process.exit(1); }
35
- if (cb) cb(new Error(res.statusText + ' (' + res.status + ')'));
36
- return;
34
+ const ignore404 = res.status === 404 && opt.cdnType === 'standard'
35
+ if (res.status >= 300 && !ignore404) {
36
+ if (!cb) { console.error(colors.red(res.statusText + ' (' + res.status + ')')); process.exit(1) }
37
+ if (cb) cb(new Error(res.statusText + ' (' + res.status + ')'))
38
+ return
37
39
  }
38
40
  // if (!cb) console.log(colors.green(`got ${opt.opt.key || opt.keys.join(', ')} from ${opt.version}/${opt.language}/${opt.namespace}...`));
39
41
 
40
- const flat = flatten(obj);
42
+ if (ignore404) obj = {}
43
+
44
+ const flat = flatten(obj)
41
45
  if (opt.key) {
42
46
  if (!flat[opt.key]) {
43
- if (!cb) { console.error(colors.red(`${opt.key} not found in ${opt.version}/${opt.language}/${opt.namespace} => ${JSON.stringify(obj, null, 2)}`)); process.exit(1); }
44
- if (cb) cb(new Error(`${opt.key} not found in ${opt.version}/${opt.language}/${opt.namespace} => ${JSON.stringify(obj, null, 2)}`));
45
- return;
47
+ if (!cb) { console.error(colors.red(`${opt.key} not found in ${opt.version}/${opt.language}/${opt.namespace} => ${JSON.stringify(obj, null, 2)}`)); process.exit(1) }
48
+ if (cb) cb(new Error(`${opt.key} not found in ${opt.version}/${opt.language}/${opt.namespace} => ${JSON.stringify(obj, null, 2)}`))
49
+ return
46
50
  }
47
- if (!cb) console.log(flat[opt.key]);
51
+ if (!cb) console.log(flat[opt.key])
48
52
  }
49
53
  if (opt.keys) {
50
- const ret = {};
51
- const retWitAllKeys = {};
54
+ const ret = {}
55
+ const retWitAllKeys = {}
52
56
  opt.keys.forEach((k) => {
53
57
  if (flat[k] !== undefined) {
54
- ret[k] = flat[k];
58
+ ret[k] = flat[k]
55
59
  }
56
- retWitAllKeys[k] = flat[k];
57
- });
58
- const retKeys = Object.keys(ret);
60
+ retWitAllKeys[k] = flat[k]
61
+ })
62
+ const retKeys = Object.keys(ret)
59
63
  if (retKeys.length === 0) {
60
- if (!cb) { console.error(colors.red(`${opt.keys.join(', ')} not found in ${opt.version}/${opt.language}/${opt.namespace} => ${JSON.stringify(obj, null, 2)}`)); process.exit(1); }
61
- if (cb) cb(new Error(`${opt.keys.join(', ')} not found in ${opt.version}/${opt.language}/${opt.namespace} => ${JSON.stringify(obj, null, 2)}`));
62
- return;
64
+ if (!cb) { console.error(colors.red(`${opt.keys.join(', ')} not found in ${opt.version}/${opt.language}/${opt.namespace} => ${JSON.stringify(obj, null, 2)}`)); process.exit(1) }
65
+ if (cb) cb(new Error(`${opt.keys.join(', ')} not found in ${opt.version}/${opt.language}/${opt.namespace} => ${JSON.stringify(obj, null, 2)}`))
66
+ return
63
67
  }
64
68
  if (!cb) {
65
69
  if (console.table) {
66
- console.table(retWitAllKeys);
70
+ console.table(retWitAllKeys)
67
71
  } else {
68
72
  opt.keys.forEach((k) => {
69
- console.log(`${k}\t=>\t${ret[k] || ''}`);
70
- });
73
+ console.log(`${k}\t=>\t${ret[k] || ''}`)
74
+ })
71
75
  }
72
76
  }
73
77
  }
74
- if (cb) cb(null);
75
- });
76
- };
78
+ if (cb) cb(null)
79
+ })
80
+ }
77
81
 
78
- module.exports = get;
82
+ module.exports = get
package/getBranches.js CHANGED
@@ -1,40 +1,40 @@
1
- const colors = require('colors');
2
- const request = require('./request');
1
+ const colors = require('colors')
2
+ const request = require('./request')
3
3
 
4
4
  const getBranches = (opt, cb) => {
5
5
  request(opt.apiPath + '/branches/' + opt.projectId, {
6
6
  method: 'get',
7
7
  headers: {
8
- 'Authorization': opt.apiKey
8
+ Authorization: opt.apiKey
9
9
  }
10
10
  }, (err, res, obj) => {
11
11
  if (err || (obj && (obj.errorMessage || obj.message))) {
12
- if (!cb) console.log(colors.red('getting branches failed...'));
12
+ if (!cb) console.log(colors.red('getting branches failed...'))
13
13
 
14
14
  if (err) {
15
- if (!cb) { console.error(colors.red(err.message)); process.exit(1); }
16
- if (cb) cb(err);
17
- return;
15
+ if (!cb) { console.error(colors.red(err.message)); process.exit(1) }
16
+ if (cb) cb(err)
17
+ return
18
18
  }
19
19
  if (obj && (obj.errorMessage || obj.message)) {
20
- if (!cb) { console.error(colors.red((obj.errorMessage || obj.message))); process.exit(1); }
21
- if (cb) cb(new Error((obj.errorMessage || obj.message)));
22
- return;
20
+ if (!cb) { console.error(colors.red((obj.errorMessage || obj.message))); process.exit(1) }
21
+ if (cb) cb(new Error((obj.errorMessage || obj.message)))
22
+ return
23
23
  }
24
24
  }
25
25
  if (res.status === 404) {
26
- if (!cb) { console.error(colors.yellow(res.statusText + ' (' + res.status + ')')); process.exit(1); }
27
- if (cb) cb(null, null);
28
- return;
26
+ if (!cb) { console.error(colors.yellow(res.statusText + ' (' + res.status + ')')); process.exit(1) }
27
+ if (cb) cb(null, null)
28
+ return
29
29
  }
30
30
  if (res.status >= 300) {
31
- if (!cb) { console.error(colors.red(res.statusText + ' (' + res.status + ')')); process.exit(1); }
32
- if (cb) cb(new Error(res.statusText + ' (' + res.status + ')'));
33
- return;
31
+ if (!cb) { console.error(colors.red(res.statusText + ' (' + res.status + ')')); process.exit(1) }
32
+ if (cb) cb(new Error(res.statusText + ' (' + res.status + ')'))
33
+ return
34
34
  }
35
- if (!cb) console.log(colors.green('getting branches successful'));
36
- if (cb) cb(null, obj);
37
- });
38
- };
35
+ if (!cb) console.log(colors.green('getting branches successful'))
36
+ if (cb) cb(null, obj)
37
+ })
38
+ }
39
39
 
40
- module.exports = getBranches;
40
+ module.exports = getBranches
package/getJob.js CHANGED
@@ -1,40 +1,40 @@
1
- const colors = require('colors');
2
- const request = require('./request');
1
+ const colors = require('colors')
2
+ const request = require('./request')
3
3
 
4
4
  const getJob = (opt, jobId, cb) => {
5
5
  request(opt.apiPath + '/jobs/' + opt.projectId + '/' + jobId, {
6
6
  method: 'get',
7
7
  headers: {
8
- 'Authorization': opt.apiKey
8
+ Authorization: opt.apiKey
9
9
  }
10
10
  }, (err, res, obj) => {
11
11
  if (err || (obj && (obj.errorMessage || obj.message))) {
12
- if (!cb) console.log(colors.red('getting job failed...'));
12
+ if (!cb) console.log(colors.red('getting job failed...'))
13
13
 
14
14
  if (err) {
15
- if (!cb) { console.error(colors.red(err.message)); process.exit(1); }
16
- if (cb) cb(err);
17
- return;
15
+ if (!cb) { console.error(colors.red(err.message)); process.exit(1) }
16
+ if (cb) cb(err)
17
+ return
18
18
  }
19
19
  if (obj && (obj.errorMessage || obj.message)) {
20
- if (!cb) { console.error(colors.red((obj.errorMessage || obj.message))); process.exit(1); }
21
- if (cb) cb(new Error((obj.errorMessage || obj.message)));
22
- return;
20
+ if (!cb) { console.error(colors.red((obj.errorMessage || obj.message))); process.exit(1) }
21
+ if (cb) cb(new Error((obj.errorMessage || obj.message)))
22
+ return
23
23
  }
24
24
  }
25
25
  if (res.status === 404) {
26
- if (!cb) { console.error(colors.yellow(res.statusText + ' (' + res.status + ')')); process.exit(1); }
27
- if (cb) cb(null, null);
28
- return;
26
+ if (!cb) { console.error(colors.yellow(res.statusText + ' (' + res.status + ')')); process.exit(1) }
27
+ if (cb) cb(null, null)
28
+ return
29
29
  }
30
30
  if (res.status >= 300) {
31
- if (!cb) { console.error(colors.red(res.statusText + ' (' + res.status + ')')); process.exit(1); }
32
- if (cb) cb(new Error(res.statusText + ' (' + res.status + ')'));
33
- return;
31
+ if (!cb) { console.error(colors.red(res.statusText + ' (' + res.status + ')')); process.exit(1) }
32
+ if (cb) cb(new Error(res.statusText + ' (' + res.status + ')'))
33
+ return
34
34
  }
35
- if (!cb) console.log(colors.green('getting job successful'));
36
- if (cb) cb(null, obj);
37
- });
38
- };
35
+ if (!cb) console.log(colors.green('getting job successful'))
36
+ if (cb) cb(null, obj)
37
+ })
38
+ }
39
39
 
40
- module.exports = getJob;
40
+ module.exports = getJob
@@ -1,40 +1,40 @@
1
- const colors = require('colors');
2
- const request = require('./request');
1
+ const colors = require('colors')
2
+ const request = require('./request')
3
3
 
4
4
  const getProjectStats = (opt, cb) => {
5
5
  request(opt.apiPath + '/stats/project/' + opt.projectId, {
6
6
  method: 'get',
7
7
  headers: {
8
- 'Authorization': opt.apiKey
8
+ Authorization: opt.apiKey
9
9
  }
10
10
  }, (err, res, obj) => {
11
11
  if (err || (obj && (obj.errorMessage || obj.message))) {
12
- if (!cb) console.log(colors.red('getting job failed...'));
12
+ if (!cb) console.log(colors.red('getting job failed...'))
13
13
 
14
14
  if (err) {
15
- if (!cb) { console.error(colors.red(err.message)); process.exit(1); }
16
- if (cb) cb(err);
17
- return;
15
+ if (!cb) { console.error(colors.red(err.message)); process.exit(1) }
16
+ if (cb) cb(err)
17
+ return
18
18
  }
19
19
  if (obj && (obj.errorMessage || obj.message)) {
20
- if (!cb) { console.error(colors.red((obj.errorMessage || obj.message))); process.exit(1); }
21
- if (cb) cb(new Error((obj.errorMessage || obj.message)));
22
- return;
20
+ if (!cb) { console.error(colors.red((obj.errorMessage || obj.message))); process.exit(1) }
21
+ if (cb) cb(new Error((obj.errorMessage || obj.message)))
22
+ return
23
23
  }
24
24
  }
25
25
  if (res.status === 404) {
26
- if (!cb) { console.error(colors.yellow(res.statusText + ' (' + res.status + ')')); process.exit(1); }
27
- if (cb) cb(null, null);
28
- return;
26
+ if (!cb) { console.error(colors.yellow(res.statusText + ' (' + res.status + ')')); process.exit(1) }
27
+ if (cb) cb(null, null)
28
+ return
29
29
  }
30
30
  if (res.status >= 300) {
31
- if (!cb) { console.error(colors.red(res.statusText + ' (' + res.status + ')')); process.exit(1); }
32
- if (cb) cb(new Error(res.statusText + ' (' + res.status + ')'));
33
- return;
31
+ if (!cb) { console.error(colors.red(res.statusText + ' (' + res.status + ')')); process.exit(1) }
32
+ if (cb) cb(new Error(res.statusText + ' (' + res.status + ')'))
33
+ return
34
34
  }
35
- if (!cb) console.log(colors.green('getting project stats successful'));
36
- if (cb) cb(null, obj);
37
- });
38
- };
35
+ if (!cb) console.log(colors.green('getting project stats successful'))
36
+ if (cb) cb(null, obj)
37
+ })
38
+ }
39
39
 
40
- module.exports = getProjectStats;
40
+ module.exports = getProjectStats