locize-cli 10.3.2 → 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.
package/missing.js CHANGED
@@ -1,169 +1,169 @@
1
- const colors = require('colors');
2
- const async = require('async');
3
- const path = require('path');
4
- const request = require('./request');
5
- const formats = require('./formats');
6
- const reversedFileExtensionsMap = formats.reversedFileExtensionsMap;
7
- const getRemoteLanguages = require('./getRemoteLanguages');
8
- const parseLocalReference = require('./parseLocalReference');
9
- const parseLocalLanguages = require('./parseLocalLanguages');
10
- const getRemoteNamespace = require('./getRemoteNamespace');
1
+ const colors = require('colors')
2
+ const async = require('async')
3
+ const path = require('path')
4
+ const request = require('./request')
5
+ const formats = require('./formats')
6
+ const reversedFileExtensionsMap = formats.reversedFileExtensionsMap
7
+ const getRemoteLanguages = require('./getRemoteLanguages')
8
+ const parseLocalReference = require('./parseLocalReference')
9
+ const parseLocalLanguages = require('./parseLocalLanguages')
10
+ const getRemoteNamespace = require('./getRemoteNamespace')
11
11
 
12
12
  const compareNamespace = (local, remote) => {
13
13
  const diff = {
14
14
  toAdd: []
15
- };
16
- local = local || {};
17
- remote = remote || {};
15
+ }
16
+ local = local || {}
17
+ remote = remote || {}
18
18
  Object.keys(local).forEach((k) => {
19
- if (remote[k] === '' && local[k] === '') return;
19
+ if (remote[k] === '' && local[k] === '') return
20
20
  if (!remote[k]) {
21
- diff.toAdd.push(k);
21
+ diff.toAdd.push(k)
22
22
  }
23
- });
24
- return diff;
25
- };
23
+ })
24
+ return diff
25
+ }
26
26
 
27
27
  const compareNamespaces = (opt, localNamespaces, cb) => {
28
28
  async.map(localNamespaces, (ns, clb) => {
29
29
  getRemoteNamespace(opt, ns.language, ns.namespace, (err, remoteNamespace) => {
30
- if (err) return clb(err);
30
+ if (err) return clb(err)
31
31
 
32
- const diff = compareNamespace(ns.content, remoteNamespace);
33
- ns.diff = diff;
34
- ns.remoteContent = remoteNamespace;
35
- clb(null, ns);
36
- });
37
- }, cb);
38
- };
32
+ const diff = compareNamespace(ns.content, remoteNamespace)
33
+ ns.diff = diff
34
+ ns.remoteContent = remoteNamespace
35
+ clb(null, ns)
36
+ })
37
+ }, cb)
38
+ }
39
39
 
40
40
  const saveMissing = (opt, lng, ns, cb) => {
41
- var data = {};
42
- ns.diff.toAdd.forEach((k) => data[k] = ns.content[k]);
41
+ const data = {}
42
+ ns.diff.toAdd.forEach((k) => { data[k] = ns.content[k] })
43
43
 
44
- if (Object.keys(data).length === 0) return cb(null);
44
+ if (Object.keys(data).length === 0) return cb(null)
45
45
 
46
- if (opt.dry) return cb(null);
46
+ if (opt.dry) return cb(null)
47
47
 
48
- var payloadKeysLimit = 1000;
48
+ const payloadKeysLimit = 1000
49
49
 
50
- function send(d, clb, isRetrying) {
50
+ function send (d, clb, isRetrying) {
51
51
  request(opt.apiPath + '/missing/' + opt.projectId + '/' + opt.version + '/' + lng + '/' + ns.namespace, {
52
52
  method: 'post',
53
53
  body: d,
54
54
  headers: {
55
- 'Authorization': opt.apiKey
55
+ Authorization: opt.apiKey
56
56
  }
57
57
  }, (err, res, obj) => {
58
- if (err) return clb(err);
58
+ if (err) return clb(err)
59
59
  if (res.status === 504 && !isRetrying) {
60
- return setTimeout(() => send(d, clb, true), 3000);
60
+ return setTimeout(() => send(d, clb, true), 3000)
61
61
  }
62
62
  if (res.status >= 300 && res.status !== 412) {
63
63
  if (obj && (obj.errorMessage || obj.message)) {
64
- return clb(new Error((obj.errorMessage || obj.message)));
64
+ return clb(new Error((obj.errorMessage || obj.message)))
65
65
  }
66
- return clb(new Error(res.statusText + ' (' + res.status + ')'));
66
+ return clb(new Error(res.statusText + ' (' + res.status + ')'))
67
67
  }
68
- setTimeout(() => clb(null), 1000);
69
- });
68
+ setTimeout(() => clb(null), 1000)
69
+ })
70
70
  }
71
71
 
72
72
  if (Object.keys(data).length > payloadKeysLimit) {
73
- var tasks = [];
74
- var keysInObj = Object.keys(data);
73
+ const tasks = []
74
+ const keysInObj = Object.keys(data)
75
75
 
76
76
  while (keysInObj.length > payloadKeysLimit) {
77
- (function() {
78
- var pagedData = {};
79
- keysInObj.splice(0, payloadKeysLimit).forEach((k) => pagedData[k] = data[k]);
80
- tasks.push((c) => send(pagedData, c));
81
- })();
77
+ (function () {
78
+ const pagedData = {}
79
+ keysInObj.splice(0, payloadKeysLimit).forEach((k) => { pagedData[k] = data[k] })
80
+ tasks.push((c) => send(pagedData, c))
81
+ })()
82
82
  }
83
83
 
84
- if (keysInObj.length === 0) return cb(null);
84
+ if (keysInObj.length === 0) return cb(null)
85
85
 
86
- var finalPagedData = {};
87
- keysInObj.splice(0, keysInObj.length).forEach((k) => finalPagedData[k] = data[k]);
88
- tasks.push((c) => send(finalPagedData, c));
86
+ const finalPagedData = {}
87
+ keysInObj.splice(0, keysInObj.length).forEach((k) => { finalPagedData[k] = data[k] })
88
+ tasks.push((c) => send(finalPagedData, c))
89
89
 
90
- async.series(tasks, cb);
91
- return;
90
+ async.series(tasks, cb)
91
+ return
92
92
  }
93
93
 
94
- send(data, cb);
95
- };
94
+ send(data, cb)
95
+ }
96
96
 
97
97
  const handleError = (err, cb) => {
98
98
  if (!cb && err) {
99
- console.error(colors.red(err.stack));
100
- process.exit(1);
99
+ console.error(colors.red(err.stack))
100
+ process.exit(1)
101
101
  }
102
- if (cb) cb(err);
103
- };
102
+ if (cb) cb(err)
103
+ }
104
104
 
105
105
  const handleMissing = (opt, localNamespaces, cb) => {
106
106
  if (!localNamespaces || localNamespaces.length === 0) {
107
- return handleError(new Error('No local namespaces found!'));
107
+ return handleError(new Error('No local namespaces found!'))
108
108
  }
109
109
 
110
110
  compareNamespaces(opt, localNamespaces, (err, compared) => {
111
- if (err) return handleError(err);
111
+ if (err) return handleError(err)
112
112
 
113
113
  async.eachLimit(compared, Math.round(require('os').cpus().length / 2), (ns, clb) => {
114
114
  if (!cb) {
115
115
  if (ns.diff.toAdd.length > 0) {
116
- console.log(colors.green(`adding ${ns.diff.toAdd.length} keys in ${ns.language}/${ns.namespace}...`));
117
- if (opt.dry) console.log(colors.green(`would add ${ns.diff.toAdd.join(', ')} in ${ns.language}/${ns.namespace}...`));
116
+ console.log(colors.green(`adding ${ns.diff.toAdd.length} keys in ${ns.language}/${ns.namespace}...`))
117
+ if (opt.dry) console.log(colors.green(`would add ${ns.diff.toAdd.join(', ')} in ${ns.language}/${ns.namespace}...`))
118
118
  }
119
119
  }
120
- saveMissing(opt, ns.language, ns, clb);
120
+ saveMissing(opt, ns.language, ns, clb)
121
121
  }, (err) => {
122
- if (err) return handleError(err);
123
- if (!cb) console.log(colors.green('FINISHED'));
124
- if (cb) cb(null);
125
- });
126
- });
127
- };
122
+ if (err) return handleError(err)
123
+ if (!cb) console.log(colors.green('FINISHED'))
124
+ if (cb) cb(null)
125
+ })
126
+ })
127
+ }
128
128
 
129
129
  const missing = (opt, cb) => {
130
130
  if (!reversedFileExtensionsMap[opt.format]) {
131
- return handleError(new Error(`${opt.format} is not a valid format!`));
131
+ return handleError(new Error(`${opt.format} is not a valid format!`))
132
132
  }
133
133
 
134
134
  if (opt.namespace && opt.namespace.indexOf(',') > 0) {
135
- opt.namespaces = opt.namespace.split(',');
136
- delete opt.namespace;
135
+ opt.namespaces = opt.namespace.split(',')
136
+ delete opt.namespace
137
137
  }
138
138
 
139
- opt.pathMaskInterpolationPrefix = opt.pathMaskInterpolationPrefix || '{{';
140
- opt.pathMaskInterpolationSuffix = opt.pathMaskInterpolationSuffix || '}}';
141
- opt.pathMask = opt.pathMask || `${opt.pathMaskInterpolationPrefix}language${opt.pathMaskInterpolationSuffix}${path.sep}${opt.pathMaskInterpolationPrefix}namespace${opt.pathMaskInterpolationSuffix}`;
142
- opt.languageFolderPrefix = opt.languageFolderPrefix || '';
143
- opt.pathMask = opt.pathMask.replace(`${opt.pathMaskInterpolationPrefix}language${opt.pathMaskInterpolationSuffix}`, `${opt.languageFolderPrefix}${opt.pathMaskInterpolationPrefix}language${opt.pathMaskInterpolationSuffix}`);
139
+ opt.pathMaskInterpolationPrefix = opt.pathMaskInterpolationPrefix || '{{'
140
+ opt.pathMaskInterpolationSuffix = opt.pathMaskInterpolationSuffix || '}}'
141
+ opt.pathMask = opt.pathMask || `${opt.pathMaskInterpolationPrefix}language${opt.pathMaskInterpolationSuffix}${path.sep}${opt.pathMaskInterpolationPrefix}namespace${opt.pathMaskInterpolationSuffix}`
142
+ opt.languageFolderPrefix = opt.languageFolderPrefix || ''
143
+ opt.pathMask = opt.pathMask.replace(`${opt.pathMaskInterpolationPrefix}language${opt.pathMaskInterpolationSuffix}`, `${opt.languageFolderPrefix}${opt.pathMaskInterpolationPrefix}language${opt.pathMaskInterpolationSuffix}`)
144
144
 
145
145
  getRemoteLanguages(opt, (err, remoteLanguages) => {
146
- if (err) return handleError(err);
146
+ if (err) return handleError(err)
147
147
 
148
148
  if (opt.referenceLanguageOnly && opt.language && opt.referenceLanguage !== opt.language) {
149
- opt.referenceLanguage = opt.language;
149
+ opt.referenceLanguage = opt.language
150
150
  }
151
151
 
152
152
  if (opt.referenceLanguageOnly) {
153
153
  parseLocalReference(opt, (err, localNamespaces) => {
154
- if (err) return handleError(err);
154
+ if (err) return handleError(err)
155
155
 
156
- handleMissing(opt, localNamespaces, cb);
157
- });
158
- return;
156
+ handleMissing(opt, localNamespaces, cb)
157
+ })
158
+ return
159
159
  }
160
160
 
161
161
  parseLocalLanguages(opt, remoteLanguages, (err, localNamespaces) => {
162
- if (err) return handleError(err);
162
+ if (err) return handleError(err)
163
163
 
164
- handleMissing(opt, localNamespaces, cb);
165
- });
166
- });
167
- };
164
+ handleMissing(opt, localNamespaces, cb)
165
+ })
166
+ })
167
+ }
168
168
 
169
- module.exports = missing;
169
+ module.exports = missing
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "locize-cli",
3
- "version": "10.3.2",
3
+ "version": "10.4.0",
4
4
  "description": "locize cli to import locales",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -36,7 +36,9 @@
36
36
  },
37
37
  "devDependencies": {
38
38
  "@yao-pkg/pkg": "6.4.0",
39
- "eslint": "8.56.0",
39
+ "eslint": "9.39.1",
40
+ "eslint-plugin-import": "2.32.0",
41
+ "neostandard": "0.12.2",
40
42
  "gh-release": "7.0.2"
41
43
  },
42
44
  "scripts": {
@@ -1,203 +1,203 @@
1
- const fs = require('fs');
2
- const path = require('path');
3
- const async = require('async');
4
- const { mkdirp } = require('mkdirp');
5
- const convertToFlatFormat = require('./convertToFlatFormat');
6
- const formats = require('./formats');
7
- const fileExtensionsMap = formats.fileExtensionsMap;
8
- const acceptedFileExtensions = formats.acceptedFileExtensions;
9
- const xcstrings2locize = require('locize-xcstrings/cjs/xcstrings2locize');
1
+ const fs = require('fs')
2
+ const path = require('path')
3
+ const async = require('async')
4
+ const { mkdirp } = require('mkdirp')
5
+ const convertToFlatFormat = require('./convertToFlatFormat')
6
+ const formats = require('./formats')
7
+ const fileExtensionsMap = formats.fileExtensionsMap
8
+ const acceptedFileExtensions = formats.acceptedFileExtensions
9
+ const xcstrings2locize = require('locize-xcstrings/cjs/xcstrings2locize')
10
10
 
11
11
  const getFiles = (srcpath) => {
12
12
  return fs.readdirSync(srcpath).filter((file) => {
13
- return !fs.statSync(path.join(srcpath, file)).isDirectory();
14
- }).filter((file) => acceptedFileExtensions.indexOf(path.extname(file)) > -1);
15
- };
13
+ return !fs.statSync(path.join(srcpath, file)).isDirectory()
14
+ }).filter((file) => acceptedFileExtensions.indexOf(path.extname(file)) > -1)
15
+ }
16
16
 
17
17
  const getDirectories = (srcpath) => {
18
18
  return fs.readdirSync(srcpath).filter((file) => {
19
- return fs.statSync(path.join(srcpath, file)).isDirectory();
20
- });
21
- };
19
+ return fs.statSync(path.join(srcpath, file)).isDirectory()
20
+ })
21
+ }
22
22
 
23
23
  const parseLocalLanguage = (opt, lng, cb) => {
24
- const hasNamespaceInPath = opt.pathMask.indexOf(`${opt.pathMaskInterpolationPrefix}namespace${opt.pathMaskInterpolationSuffix}`) > -1;
25
- const filledLngMask = opt.pathMask.replace(`${opt.pathMaskInterpolationPrefix}language${opt.pathMaskInterpolationSuffix}`, opt.format === 'xcstrings' ? '' : lng);
26
- var firstPartLngMask, lastPartLngMask;
24
+ const hasNamespaceInPath = opt.pathMask.indexOf(`${opt.pathMaskInterpolationPrefix}namespace${opt.pathMaskInterpolationSuffix}`) > -1
25
+ const filledLngMask = opt.pathMask.replace(`${opt.pathMaskInterpolationPrefix}language${opt.pathMaskInterpolationSuffix}`, opt.format === 'xcstrings' ? '' : lng)
26
+ let firstPartLngMask, lastPartLngMask
27
27
  if (opt.pathMask.indexOf(`${opt.pathMaskInterpolationPrefix}language${opt.pathMaskInterpolationSuffix}`) > opt.pathMask.indexOf(`${opt.pathMaskInterpolationPrefix}namespace${opt.pathMaskInterpolationSuffix}`)) {
28
- const secondPartMask = opt.pathMask.substring(opt.pathMask.lastIndexOf(path.sep) + 1);
29
- firstPartLngMask = secondPartMask.substring(0, secondPartMask.indexOf(`${opt.pathMaskInterpolationPrefix}language${opt.pathMaskInterpolationSuffix}`));
30
- lastPartLngMask = secondPartMask.substring(secondPartMask.indexOf(`${opt.pathMaskInterpolationPrefix}language${opt.pathMaskInterpolationSuffix}`) + `${opt.pathMaskInterpolationPrefix}language${opt.pathMaskInterpolationSuffix}`.length);
28
+ const secondPartMask = opt.pathMask.substring(opt.pathMask.lastIndexOf(path.sep) + 1)
29
+ firstPartLngMask = secondPartMask.substring(0, secondPartMask.indexOf(`${opt.pathMaskInterpolationPrefix}language${opt.pathMaskInterpolationSuffix}`))
30
+ lastPartLngMask = secondPartMask.substring(secondPartMask.indexOf(`${opt.pathMaskInterpolationPrefix}language${opt.pathMaskInterpolationSuffix}`) + `${opt.pathMaskInterpolationPrefix}language${opt.pathMaskInterpolationSuffix}`.length)
31
31
  }
32
- var lngPath;
32
+ let lngPath
33
33
  if (filledLngMask.lastIndexOf(path.sep) > 0) {
34
- lngPath = filledLngMask.substring(0, filledLngMask.lastIndexOf(path.sep));
34
+ lngPath = filledLngMask.substring(0, filledLngMask.lastIndexOf(path.sep))
35
35
  }
36
- if (!opt.dry && lngPath && lngPath.indexOf(`${opt.pathMaskInterpolationPrefix}namespace${opt.pathMaskInterpolationSuffix}`) < 0) mkdirp.sync(path.join(opt.path, lngPath));
37
- var files = [];
36
+ if (!opt.dry && lngPath && lngPath.indexOf(`${opt.pathMaskInterpolationPrefix}namespace${opt.pathMaskInterpolationSuffix}`) < 0) mkdirp.sync(path.join(opt.path, lngPath))
37
+ let files = []
38
38
  try {
39
39
  if (lngPath) {
40
40
  if (lngPath.indexOf(`${opt.pathMaskInterpolationPrefix}namespace${opt.pathMaskInterpolationSuffix}`) > -1) {
41
- const firstPart = lngPath.substring(0, lngPath.indexOf(`${opt.pathMaskInterpolationPrefix}namespace${opt.pathMaskInterpolationSuffix}`));
42
- const lastPart = lngPath.substring(lngPath.indexOf(`${opt.pathMaskInterpolationPrefix}namespace${opt.pathMaskInterpolationSuffix}`) + `${opt.pathMaskInterpolationPrefix}namespace${opt.pathMaskInterpolationSuffix}`.length);
43
- var additionalSubDirsLeft = '';
44
- var additionalSubDirs = '';
45
- var splittedP = lngPath.split(path.sep);
46
- const foundSplitted = splittedP.find((s) => s.indexOf(`${opt.pathMaskInterpolationPrefix}namespace${opt.pathMaskInterpolationSuffix}`) > -1);
47
- const foundSplittedIndex = splittedP.indexOf(foundSplitted);
41
+ const firstPart = lngPath.substring(0, lngPath.indexOf(`${opt.pathMaskInterpolationPrefix}namespace${opt.pathMaskInterpolationSuffix}`))
42
+ const lastPart = lngPath.substring(lngPath.indexOf(`${opt.pathMaskInterpolationPrefix}namespace${opt.pathMaskInterpolationSuffix}`) + `${opt.pathMaskInterpolationPrefix}namespace${opt.pathMaskInterpolationSuffix}`.length)
43
+ let additionalSubDirsLeft = ''
44
+ let additionalSubDirs = ''
45
+ const splittedP = lngPath.split(path.sep)
46
+ const foundSplitted = splittedP.find((s) => s.indexOf(`${opt.pathMaskInterpolationPrefix}namespace${opt.pathMaskInterpolationSuffix}`) > -1)
47
+ const foundSplittedIndex = splittedP.indexOf(foundSplitted)
48
48
  if (splittedP.length > 2) {
49
- additionalSubDirsLeft = splittedP.slice(0, foundSplittedIndex).join(path.sep);
50
- additionalSubDirs = splittedP.slice(foundSplittedIndex + 1).join(path.sep);
49
+ additionalSubDirsLeft = splittedP.slice(0, foundSplittedIndex).join(path.sep)
50
+ additionalSubDirs = splittedP.slice(foundSplittedIndex + 1).join(path.sep)
51
51
  }
52
- var dirs = getDirectories(path.join(opt.path, additionalSubDirsLeft));
52
+ let dirs = getDirectories(path.join(opt.path, additionalSubDirsLeft))
53
53
  if (additionalSubDirs === '') {
54
- dirs = dirs.filter((d) => d.startsWith(firstPart) && d.endsWith(lastPart));
54
+ dirs = dirs.filter((d) => d.startsWith(firstPart) && d.endsWith(lastPart))
55
55
  }
56
56
  dirs.forEach((d) => {
57
57
  if (additionalSubDirs && fs.statSync(path.join(opt.path, additionalSubDirsLeft, d)).isDirectory()) {
58
- var directoryExists = false;
58
+ let directoryExists = false
59
59
  try {
60
- directoryExists = fs.statSync(path.join(opt.path, additionalSubDirsLeft, d, additionalSubDirs)).isDirectory();
60
+ directoryExists = fs.statSync(path.join(opt.path, additionalSubDirsLeft, d, additionalSubDirs)).isDirectory()
61
61
  } catch (e) {}
62
62
  if (directoryExists) {
63
- var subFls = getFiles(path.join(opt.path, additionalSubDirsLeft, d, additionalSubDirs));
64
- if (firstPartLngMask || lastPartLngMask) subFls = subFls.filter((f) => path.basename(f, path.extname(f)) === `${firstPartLngMask}${lng}${lastPartLngMask}`);
63
+ let subFls = getFiles(path.join(opt.path, additionalSubDirsLeft, d, additionalSubDirs))
64
+ if (firstPartLngMask || lastPartLngMask) subFls = subFls.filter((f) => path.basename(f, path.extname(f)) === `${firstPartLngMask}${lng}${lastPartLngMask}`)
65
65
 
66
66
  subFls = subFls.filter((f) => {
67
- const a = path.join(additionalSubDirsLeft, d, additionalSubDirs, path.basename(f, path.extname(f)));
68
- const startIndexOfNs = filledLngMask.indexOf(`${opt.pathMaskInterpolationPrefix}namespace${opt.pathMaskInterpolationSuffix}`);
69
- if (startIndexOfNs === -1) return true;
70
- const afterNs = filledLngMask.substring(startIndexOfNs + `${opt.pathMaskInterpolationPrefix}namespace${opt.pathMaskInterpolationSuffix}`.length);
71
- const nsName = a.substring(startIndexOfNs, a.indexOf(afterNs));
72
- const b = filledLngMask.replace(`${opt.pathMaskInterpolationPrefix}namespace${opt.pathMaskInterpolationSuffix}`, nsName);
73
- return a === b;
74
- });
67
+ const a = path.join(additionalSubDirsLeft, d, additionalSubDirs, path.basename(f, path.extname(f)))
68
+ const startIndexOfNs = filledLngMask.indexOf(`${opt.pathMaskInterpolationPrefix}namespace${opt.pathMaskInterpolationSuffix}`)
69
+ if (startIndexOfNs === -1) return true
70
+ const afterNs = filledLngMask.substring(startIndexOfNs + `${opt.pathMaskInterpolationPrefix}namespace${opt.pathMaskInterpolationSuffix}`.length)
71
+ const nsName = a.substring(startIndexOfNs, a.indexOf(afterNs))
72
+ const b = filledLngMask.replace(`${opt.pathMaskInterpolationPrefix}namespace${opt.pathMaskInterpolationSuffix}`, nsName)
73
+ return a === b
74
+ })
75
75
 
76
- files = files.concat(subFls.map((f) => `${additionalSubDirsLeft ? additionalSubDirsLeft + path.sep : ''}${d}${path.sep}${additionalSubDirs}${path.sep}${f}`));
76
+ files = files.concat(subFls.map((f) => `${additionalSubDirsLeft ? additionalSubDirsLeft + path.sep : ''}${d}${path.sep}${additionalSubDirs}${path.sep}${f}`))
77
77
  }
78
78
  } else {
79
- const fls = getFiles(path.join(opt.path, additionalSubDirsLeft, d)).filter((f) => path.basename(f, path.extname(f)) === `${firstPartLngMask}${lng}${lastPartLngMask}`);
80
- files = files.concat(fls.map((f) => `${additionalSubDirsLeft ? additionalSubDirsLeft + path.sep : ''}${d}${path.sep}${f}`));
79
+ const fls = getFiles(path.join(opt.path, additionalSubDirsLeft, d)).filter((f) => path.basename(f, path.extname(f)) === `${firstPartLngMask}${lng}${lastPartLngMask}`)
80
+ files = files.concat(fls.map((f) => `${additionalSubDirsLeft ? additionalSubDirsLeft + path.sep : ''}${d}${path.sep}${f}`))
81
81
  }
82
- });
82
+ })
83
83
  } else {
84
- files = getFiles(path.join(opt.path, lngPath));
84
+ files = getFiles(path.join(opt.path, lngPath))
85
85
  }
86
86
  } else {
87
- files = getFiles(opt.path);
87
+ files = getFiles(opt.path)
88
88
  // filter lng files...
89
- const lngIndex = filledLngMask.indexOf(lng);
90
- const lngLeftLength = filledLngMask.length - lngIndex;
89
+ const lngIndex = filledLngMask.indexOf(lng)
90
+ const lngLeftLength = filledLngMask.length - lngIndex
91
91
  files = files.filter((f) => { // {{language}} can be left or right of {{namespace}}
92
92
  if (opt.pathMask.indexOf(`${opt.pathMaskInterpolationPrefix}language${opt.pathMaskInterpolationSuffix}`) < opt.pathMask.indexOf(`${opt.pathMaskInterpolationPrefix}namespace${opt.pathMaskInterpolationSuffix}`)) {
93
- return f.indexOf(lng) === lngIndex;
93
+ return f.indexOf(lng) === lngIndex
94
94
  }
95
- return (path.basename(f, path.extname(f)).length - f.indexOf(lng)) === lngLeftLength;
96
- });
95
+ return (path.basename(f, path.extname(f)).length - f.indexOf(lng)) === lngLeftLength
96
+ })
97
97
  }
98
98
  } catch (err) {}
99
99
  async.map(files, (file, clb) => {
100
- var dirPath;
100
+ let dirPath
101
101
  if (file.lastIndexOf(path.sep) > 0) {
102
- dirPath = file.substring(0, file.lastIndexOf(path.sep));
103
- file = file.substring(file.lastIndexOf(path.sep) + 1);
102
+ dirPath = file.substring(0, file.lastIndexOf(path.sep))
103
+ file = file.substring(file.lastIndexOf(path.sep) + 1)
104
104
  }
105
- const fExt = path.extname(file);
106
- var namespace = path.basename(file, fExt);
107
- const nsMask = `${opt.pathMaskInterpolationPrefix}namespace${opt.pathMaskInterpolationSuffix}`;
108
- const filledNsMask = lngPath && lngPath.indexOf(nsMask) > -1 ? filledLngMask : filledLngMask.substring(filledLngMask.lastIndexOf(path.sep) + 1);
109
- const startNsIndex = filledNsMask.indexOf(nsMask);
110
- var restNsMask = filledNsMask.substring((startNsIndex || 0) + nsMask.length);
111
- namespace = namespace.substring(startNsIndex || 0, namespace.lastIndexOf(restNsMask));
105
+ const fExt = path.extname(file)
106
+ let namespace = path.basename(file, fExt)
107
+ const nsMask = `${opt.pathMaskInterpolationPrefix}namespace${opt.pathMaskInterpolationSuffix}`
108
+ const filledNsMask = lngPath && lngPath.indexOf(nsMask) > -1 ? filledLngMask : filledLngMask.substring(filledLngMask.lastIndexOf(path.sep) + 1)
109
+ const startNsIndex = filledNsMask.indexOf(nsMask)
110
+ let restNsMask = filledNsMask.substring((startNsIndex || 0) + nsMask.length)
111
+ namespace = namespace.substring(startNsIndex || 0, namespace.lastIndexOf(restNsMask))
112
112
  if (lngPath && lngPath.indexOf(nsMask) > -1) {
113
- restNsMask = restNsMask.substring(0, restNsMask.lastIndexOf(path.sep));
113
+ restNsMask = restNsMask.substring(0, restNsMask.lastIndexOf(path.sep))
114
114
  if (dirPath.indexOf(restNsMask) > 0) {
115
- namespace = dirPath.substring(filledNsMask.indexOf(nsMask), dirPath.indexOf(restNsMask));
115
+ namespace = dirPath.substring(filledNsMask.indexOf(nsMask), dirPath.indexOf(restNsMask))
116
116
  } else {
117
- namespace = dirPath.substring(filledNsMask.indexOf(nsMask));
117
+ namespace = dirPath.substring(filledNsMask.indexOf(nsMask))
118
118
  }
119
119
  } else if (!hasNamespaceInPath && startNsIndex < 0) {
120
- namespace = opt.namespace;
120
+ namespace = opt.namespace
121
121
  }
122
- var fPath = path.join(opt.path, lngPath || '', file);
122
+ let fPath = path.join(opt.path, lngPath || '', file)
123
123
  if (dirPath && lngPath.indexOf(nsMask) > -1) {
124
- fPath = path.join(opt.path, dirPath.replace(nsMask, namespace), file);
124
+ fPath = path.join(opt.path, dirPath.replace(nsMask, namespace), file)
125
125
  }
126
- if (!namespace) return clb(new Error(`namespace could not be found in ${fPath}`));
127
- if (opt.namespaces && opt.namespaces.indexOf(namespace) < 0) return clb(null);
128
- if (opt.namespace && opt.namespace !== namespace) return clb(null);
126
+ if (!namespace) return clb(new Error(`namespace could not be found in ${fPath}`))
127
+ if (opt.namespaces && opt.namespaces.indexOf(namespace) < 0) return clb(null)
128
+ if (opt.namespace && opt.namespace !== namespace) return clb(null)
129
129
  fs.readFile(fPath, (err, data) => {
130
- if (err) return clb(err);
130
+ if (err) return clb(err)
131
131
 
132
132
  if (fileExtensionsMap[fExt].indexOf(opt.format) < 0) {
133
- return clb(new Error(`Format mismatch! Found ${fileExtensionsMap[fExt][0]} but requested ${opt.format}!`));
133
+ return clb(new Error(`Format mismatch! Found ${fileExtensionsMap[fExt][0]} but requested ${opt.format}!`))
134
134
  }
135
135
 
136
136
  if (opt.namespace) {
137
- let hasNamespaceInPathPask = !opt.pathMask || !opt.pathMaskInterpolationPrefix || !opt.pathMaskInterpolationSuffix;
138
- hasNamespaceInPathPask = !hasNamespaceInPathPask && opt.pathMask.indexOf(`${opt.pathMaskInterpolationPrefix}namespace${opt.pathMaskInterpolationSuffix}`) > -1;
137
+ let hasNamespaceInPathPask = !opt.pathMask || !opt.pathMaskInterpolationPrefix || !opt.pathMaskInterpolationSuffix
138
+ hasNamespaceInPathPask = !hasNamespaceInPathPask && opt.pathMask.indexOf(`${opt.pathMaskInterpolationPrefix}namespace${opt.pathMaskInterpolationSuffix}`) > -1
139
139
  if (!hasNamespaceInPathPask && namespace === lng) {
140
- namespace = opt.namespace;
140
+ namespace = opt.namespace
141
141
  }
142
142
  }
143
143
 
144
144
  if (opt.format === 'xcstrings') { // 1 file per namespace including all languages
145
145
  try {
146
- const content = xcstrings2locize(data);
146
+ const content = xcstrings2locize(data)
147
147
 
148
148
  fs.stat(fPath, (err, stat) => {
149
- if (err) return clb(err);
149
+ if (err) return clb(err)
150
150
 
151
151
  clb(null, Object.keys(content.resources).map((l) => ({
152
- namespace: namespace,
152
+ namespace,
153
153
  path: fPath,
154
154
  extension: fExt,
155
155
  content: content.resources[l],
156
156
  language: l,
157
157
  mtime: stat.mtime
158
- })));
159
- });
158
+ })))
159
+ })
160
160
  } catch (e) {
161
- err.message = 'Invalid content for "' + opt.format + '" format!\n' + (err.message || '');
162
- err.message += '\n' + fPath;
163
- return clb(err);
161
+ err.message = 'Invalid content for "' + opt.format + '" format!\n' + (err.message || '')
162
+ err.message += '\n' + fPath
163
+ return clb(err)
164
164
  }
165
165
  } else { // 1 file per namespace/lng
166
166
  convertToFlatFormat(opt, data, lng, (err, content) => {
167
167
  if (err) {
168
- err.message = 'Invalid content for "' + opt.format + '" format!\n' + (err.message || '');
169
- err.message += '\n' + fPath;
170
- return clb(err);
168
+ err.message = 'Invalid content for "' + opt.format + '" format!\n' + (err.message || '')
169
+ err.message += '\n' + fPath
170
+ return clb(err)
171
171
  }
172
172
 
173
173
  fs.stat(fPath, (err, stat) => {
174
- if (err) return clb(err);
174
+ if (err) return clb(err)
175
175
 
176
176
  clb(null, {
177
- namespace: namespace,
177
+ namespace,
178
178
  path: fPath,
179
179
  extension: fExt,
180
- content: content,
180
+ content,
181
181
  language: lng,
182
182
  mtime: stat.mtime
183
- });
184
- });
185
- });
183
+ })
184
+ })
185
+ })
186
186
  }
187
- });
187
+ })
188
188
  }, (err, ret) => {
189
- if (err) return cb(err);
189
+ if (err) return cb(err)
190
190
  // xcstrings, returns array in array
191
191
  const r = ret.filter((r) => r !== undefined).reduce((prev, cur) => {
192
192
  if (Array.isArray(cur)) {
193
- prev = prev.concat(cur);
193
+ prev = prev.concat(cur)
194
194
  } else {
195
- prev.push(cur);
195
+ prev.push(cur)
196
196
  }
197
- return prev;
198
- }, []);
199
- cb(null, r);
200
- });
201
- };
197
+ return prev
198
+ }, [])
199
+ cb(null, r)
200
+ })
201
+ }
202
202
 
203
- module.exports = parseLocalLanguage;
203
+ module.exports = parseLocalLanguage
@@ -1,22 +1,22 @@
1
- const async = require('async');
2
- const parseLocalLanguage = require('./parseLocalLanguage');
3
- const filterNamespaces = require('./filterNamespaces');
1
+ const async = require('async')
2
+ const parseLocalLanguage = require('./parseLocalLanguage')
3
+ const filterNamespaces = require('./filterNamespaces')
4
4
 
5
5
  const parseLocalLanguages = (opt, lngs, cb) => {
6
- var res = [];
6
+ let res = []
7
7
  async.each(lngs, (lng, clb) => {
8
8
  if (opt.language && (lng !== opt.language && lng !== opt.referenceLanguage)) {
9
- return clb();
9
+ return clb()
10
10
  }
11
11
  parseLocalLanguage(opt, lng, (err, nss) => {
12
- if (err) return clb(err);
13
- res = res.concat(filterNamespaces(opt, nss));
14
- clb();
15
- });
12
+ if (err) return clb(err)
13
+ res = res.concat(filterNamespaces(opt, nss))
14
+ clb()
15
+ })
16
16
  }, (err) => {
17
- if (err) return cb(err);
18
- cb(null, res);
19
- });
20
- };
17
+ if (err) return cb(err)
18
+ cb(null, res)
19
+ })
20
+ }
21
21
 
22
- module.exports = parseLocalLanguages;
22
+ module.exports = parseLocalLanguages
@@ -1,10 +1,10 @@
1
- const parseLocalLanguage = require('./parseLocalLanguage');
2
- const filterNamespaces = require('./filterNamespaces');
1
+ const parseLocalLanguage = require('./parseLocalLanguage')
2
+ const filterNamespaces = require('./filterNamespaces')
3
3
 
4
4
  const parseLocalReference = (opt, cb) => parseLocalLanguage(opt, opt.referenceLanguage, (err, nss) => {
5
- if (err) return cb(err);
5
+ if (err) return cb(err)
6
6
 
7
- cb(err, filterNamespaces(opt, nss).filter((n) => n.language === opt.referenceLanguage));
8
- });
7
+ cb(err, filterNamespaces(opt, nss).filter((n) => n.language === opt.referenceLanguage))
8
+ })
9
9
 
10
- module.exports = parseLocalReference;
10
+ module.exports = parseLocalReference