xcstrings-cli 1.1.1 → 1.2.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.
Files changed (3) hide show
  1. package/README.md +41 -26
  2. package/dist/index.js +307 -286
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -22,13 +22,13 @@ Check it out here: [xcstrings-cli Helper](https://chatgpt.com/g/g-69365945f8bc81
22
22
  npm install -g xcstrings-cli
23
23
  ```
24
24
 
25
- 2. Initialize xcstrings-cli
25
+ 2. Initialize xcstrings-cli:
26
26
 
27
27
  ```bash
28
28
  xcstrings init
29
29
  ```
30
30
 
31
- This will ask you some questions and create a `xcstrings-cli.json` file in the current directory.
31
+ This will ask you some questions and create an `xcstrings-cli.json` file in the current directory.
32
32
 
33
33
  ## Usage
34
34
 
@@ -40,9 +40,9 @@ xcstrings add \
40
40
  --comment "Hello, World" \
41
41
  --strings << EOF
42
42
  {
43
- "ja": "こんにちは、世界.",
43
+ "ja": "こんにちは、世界。",
44
44
  "en": "Hello, World.",
45
- "zh-Hans": "你好,世界."
45
+ "zh-Hans": "你好,世界。"
46
46
  }
47
47
  EOF
48
48
  ```
@@ -53,9 +53,9 @@ EOF
53
53
  xcstrings remove --key greeting
54
54
  ```
55
55
 
56
- List supported languages:**
56
+ **List supported languages:**
57
57
 
58
- This command lists all languages by checking xcstrings files and your Xcode project settings (`.pbxproj` specified in the config files as `xcodeprojPaths`).
58
+ This command lists all languages by checking xcstrings files and your Xcode project settings (`.pbxproj` specified in the config file as `xcodeprojPaths`).
59
59
 
60
60
  ```bash
61
61
  xcstrings languages
@@ -66,28 +66,35 @@ You can use `xcstrings --help` or `xcstrings <sub-command> --help` to see the li
66
66
 
67
67
  ## Command options
68
68
 
69
- - `--help, -h`: `boolean` (Optional)
70
- - Show help.
71
- - `--version, -v`: `boolean` (Optional)
72
- - Show version.
73
- - `--config`: `string` (Optional)
74
- - The custom config file path. If not specified, xcstrings-cli will look for `xcstrings-cli.json` or `xcstrings-cli.json5` in the current folder or its parent folders until the root.
69
+ * `--help, -h`: `boolean` (Optional)
70
+
71
+ * Show help.
72
+ * `--version, -v`: `boolean` (Optional)
73
+
74
+ * Show version.
75
+ * `--config`: `string` (Optional)
76
+
77
+ * The custom config file path. If not specified, xcstrings-cli will look for `xcstrings-cli.json` or `xcstrings-cli.json5` in the current folder or its parent folders until the root.
75
78
 
76
79
  ### `add` command options
77
80
 
78
- - `--strings, -s`: `string | string[] | { [key: string]: string }` (Required)
79
- - The strings to add/remove.
80
- - If only one string is provided, xcstrings-cli will use it as a default string.
81
- - `--comment, -c`: `string` (Optional)
82
- - The comment of the string to add for translators.
83
- - `--extractionState, -e`: `string` (Optional, default: `manual`)
84
- - The extraction state of the string to add. `translated` or `manual`.
85
- - `--help`: `boolean` (Optional)
86
- - Show help.
81
+ * `--strings, -s`: `string | string[] | { [key: string]: string }` (Required)
82
+
83
+ * The strings to add or update.
84
+ * If only one string is provided, xcstrings-cli will use it as the default string.
85
+ * `--comment, -c`: `string` (Optional)
86
+
87
+ * The comment for the string to add, intended for translators.
88
+ * `--extractionState, -e`: `string` (Optional, default: `manual`)
89
+
90
+ * The extraction state of the string to add: `translated` or `manual`.
91
+ * `--help`: `boolean` (Optional)
92
+
93
+ * Show help.
87
94
 
88
95
  ## Config file
89
96
 
90
- Put a `xcstrings-cli.json5` or `xcstrings-cli.json` file in the project root, then xcstrings-cli will use it as a config file.
97
+ Put an `xcstrings-cli.json5` or `xcstrings-cli.json` file in the project root, and xcstrings-cli will use it as the config file.
91
98
 
92
99
  ```json5
93
100
  {
@@ -106,10 +113,18 @@ Put a `xcstrings-cli.json5` or `xcstrings-cli.json` file in the project root, th
106
113
 
107
114
  These are the options for the config file:
108
115
 
109
- - xcstringsPaths: `string[] | { alias: string, path: string }[]`
110
- - The path to the xcstrings file.
111
- - If only one path is provided, xcstrings-cli will use it as a default xcstrings file.
112
- - If multiple paths are provided, xcstrings-cli will ask you to select a xcstrings file.
116
+ * **xcstringsPaths**: `string[] | { alias: string, path: string }[]`
117
+
118
+ * If only one path is provided, xcstrings-cli will use it as the default xcstrings file.
119
+ * If multiple paths are provided, xcstrings-cli will ask you to select an xcstrings file.
120
+ * **xcodeprojPaths**: `string[]` (Optional)
121
+
122
+ * Paths to Xcode project files used to detect supported languages.
123
+ * If not specified, xcstrings-cli will not check the supported languages in your Xcode project.
124
+ * **missingLanguagePolicy**: `string` (Optional, default: `ignore`)
125
+ * How to handle translations for languages that are not included in the `xcstrings languages` output when adding strings. Options are:
126
+ * `ignore`: Only add translations for languages included in the `xcstrings languages` output.
127
+ * `add`: Add translations anyway.
113
128
 
114
129
  ## LICENSE
115
130
 
package/dist/index.js CHANGED
@@ -1,32 +1,32 @@
1
1
  #!/usr/bin/env node
2
- import we from "yargs";
3
- import { hideBin as ve } from "yargs/helpers";
4
- import { readFile as je, writeFile as ie, readdir as ae } from "node:fs/promises";
5
- import { relative as X, resolve as D } from "node:path";
2
+ import ve from "yargs";
3
+ import { hideBin as je } from "yargs/helpers";
4
+ import { readFile as Oe, writeFile as ae, readdir as ce } from "node:fs/promises";
5
+ import { cosmiconfig as xe } from "cosmiconfig";
6
+ import Se from "json5";
7
+ import { XcodeProject as ke } from "@bacons/xcode";
8
+ import { resolve as X, relative as V } from "node:path";
6
9
  import d from "chalk";
7
- import { checkbox as te, confirm as Oe, select as xe } from "@inquirer/prompts";
8
- import { XcodeProject as Se } from "@bacons/xcode";
9
- import { cosmiconfig as ke } from "cosmiconfig";
10
- import ze from "json5";
10
+ import { checkbox as ne, confirm as ze, select as Ee } from "@inquirer/prompts";
11
11
  async function U(t) {
12
- const r = await je(t, "utf-8");
12
+ const r = await Oe(t, "utf-8");
13
13
  return JSON.parse(r);
14
14
  }
15
- async function ce(t, r) {
16
- const n = JSON.stringify(r, null, 2), s = Ee(n);
17
- await ie(t, s + `
15
+ async function le(t, r) {
16
+ const n = JSON.stringify(r, null, 2), o = _e(n);
17
+ await ae(t, o + `
18
18
  `, "utf-8");
19
19
  }
20
- function Ee(t) {
21
- let r = "", n = !1, s = !1;
20
+ function _e(t) {
21
+ let r = "", n = !1, o = !1;
22
22
  for (let c = 0; c < t.length; c++) {
23
23
  const l = t[c];
24
- if (n && l === "\\" && !s) {
25
- s = !0, r += l;
24
+ if (n && l === "\\" && !o) {
25
+ o = !0, r += l;
26
26
  continue;
27
27
  }
28
- if (s) {
29
- s = !1, r += l;
28
+ if (o) {
29
+ o = !1, r += l;
30
30
  continue;
31
31
  }
32
32
  if (l === '"') {
@@ -41,73 +41,120 @@ function Ee(t) {
41
41
  }
42
42
  return r;
43
43
  }
44
- async function _e(t, r, n, s) {
45
- const c = await U(t);
46
- c.strings || (c.strings = {});
47
- const l = {
48
- ...c.strings[r],
44
+ const M = "xcstrings-cli", re = xe(M, {
45
+ searchPlaces: [
46
+ `${M}.json`,
47
+ `${M}.json5`
48
+ ],
49
+ loaders: {
50
+ ".json5": async (t, r) => Se.parse(r)
51
+ },
52
+ cache: !1
53
+ });
54
+ async function H(t) {
55
+ if (t) {
56
+ const n = await re.load(t);
57
+ return n ? n.config : null;
58
+ }
59
+ const r = await re.search();
60
+ return r ? r.config : null;
61
+ }
62
+ function Le(t) {
63
+ const r = X(t, "project.pbxproj");
64
+ return ke.open(r).rootObject.props.knownRegions ?? [];
65
+ }
66
+ async function Pe(t) {
67
+ const r = await U(t), n = /* @__PURE__ */ new Set();
68
+ for (const o of Object.keys(r.strings)) {
69
+ const c = r.strings[o];
70
+ if (c.localizations)
71
+ for (const l of Object.keys(c.localizations))
72
+ n.add(l);
73
+ }
74
+ return Array.from(n).sort();
75
+ }
76
+ async function fe(t, r) {
77
+ const n = await H(r);
78
+ if (n?.xcodeprojPaths && n.xcodeprojPaths.length > 0) {
79
+ const o = /* @__PURE__ */ new Set();
80
+ for (const c of n.xcodeprojPaths)
81
+ Le(c).forEach((v) => o.add(v));
82
+ return Array.from(o).sort();
83
+ }
84
+ return await Pe(t);
85
+ }
86
+ async function Fe(t, r, n, o, c) {
87
+ const l = await U(t);
88
+ l.strings || (l.strings = {});
89
+ const v = {
90
+ ...l.strings[r],
49
91
  extractionState: "manual"
50
92
  };
51
- if (n && (l.comment = n), s) {
52
- l.localizations = l.localizations || {};
53
- for (const [x, z] of Object.entries(s))
54
- l.localizations[x] = {
55
- stringUnit: {
56
- state: "translated",
57
- value: z
58
- }
59
- };
93
+ if (n && (v.comment = n), o) {
94
+ const E = (await H(c))?.missingLanguagePolicy || "skip", w = await fe(t, c), m = [];
95
+ for (const [b, p] of Object.entries(o))
96
+ (w.includes(b) || E === "include") && m.push([b, p]);
97
+ if (m.length > 0) {
98
+ v.localizations = v.localizations || {};
99
+ for (const [b, p] of m)
100
+ v.localizations[b] = {
101
+ stringUnit: {
102
+ state: "translated",
103
+ value: p
104
+ }
105
+ };
106
+ }
60
107
  }
61
- c.strings[r] = l, await ce(t, c);
108
+ l.strings[r] = v, await le(t, l);
62
109
  }
63
- async function Le(t, r) {
110
+ async function Ce(t, r) {
64
111
  const n = await U(t);
65
- n.strings && n.strings[r] && (delete n.strings[r], await ce(t, n));
112
+ n.strings && n.strings[r] && (delete n.strings[r], await le(t, n));
66
113
  }
67
- const I = "xcstrings-cli.json5";
68
- async function Pe(t) {
114
+ const B = "xcstrings-cli.json5";
115
+ async function Te(t) {
69
116
  const r = [];
70
- async function n(s) {
117
+ async function n(o) {
71
118
  try {
72
- const c = await ae(s, { withFileTypes: !0 });
119
+ const c = await ce(o, { withFileTypes: !0 });
73
120
  for (const l of c) {
74
- const x = D(s, l.name);
75
- l.isDirectory() ? !l.name.startsWith(".") && l.name !== "node_modules" && await n(x) : l.name.endsWith(".xcstrings") && r.push(x);
121
+ const v = X(o, l.name);
122
+ l.isDirectory() ? !l.name.startsWith(".") && l.name !== "node_modules" && await n(v) : l.name.endsWith(".xcstrings") && r.push(v);
76
123
  }
77
124
  } catch {
78
125
  }
79
126
  }
80
127
  return await n(t), r;
81
128
  }
82
- async function Fe(t) {
129
+ async function $e(t) {
83
130
  const r = [];
84
131
  let n = t;
85
132
  try {
86
- const s = await ae(n, { withFileTypes: !0 });
87
- for (const c of s)
88
- c.isDirectory() && c.name.endsWith(".xcodeproj") && r.push(D(n, c.name));
133
+ const o = await ce(n, { withFileTypes: !0 });
134
+ for (const c of o)
135
+ c.isDirectory() && c.name.endsWith(".xcodeproj") && r.push(X(n, c.name));
89
136
  } catch {
90
137
  }
91
138
  return r;
92
139
  }
93
- async function Ce() {
140
+ async function Ae() {
94
141
  const t = process.cwd();
95
142
  console.log(), console.log(d.bold.cyan("🚀 xcstrings-cli Configuration Setup")), console.log(d.dim("─".repeat(40))), console.log(), console.log(d.yellow("🔍 Searching for .xcstrings files..."));
96
- const r = await Pe(t);
143
+ const r = await Te(t);
97
144
  console.log(d.yellow("🔍 Searching for .xcodeproj directories..."));
98
- const n = await Fe(t);
145
+ const n = await $e(t);
99
146
  console.log();
100
- let s = [];
147
+ let o = [];
101
148
  if (r.length > 0) {
102
149
  console.log(d.green(`✓ Found ${r.length} .xcstrings file(s)`));
103
- const b = r.map((h) => ({
104
- name: d.white(X(t, h)) + d.dim(` (${h})`),
105
- value: X(t, h),
150
+ const w = r.map((m) => ({
151
+ name: d.white(V(t, m)) + d.dim(` (${m})`),
152
+ value: V(t, m),
106
153
  checked: !0
107
154
  }));
108
- s = await te({
155
+ o = await ne({
109
156
  message: d.bold("Select .xcstrings files to manage:"),
110
- choices: b
157
+ choices: w
111
158
  });
112
159
  } else
113
160
  console.log(d.dim(" No .xcstrings files found in current directory"));
@@ -115,88 +162,48 @@ async function Ce() {
115
162
  let c = [];
116
163
  if (n.length > 0) {
117
164
  console.log(d.green(`✓ Found ${n.length} .xcodeproj director${n.length === 1 ? "y" : "ies"}`));
118
- const b = n.map((h) => ({
119
- name: d.white(X(t, h) || h) + d.dim(` (${h})`),
120
- value: X(t, h) || h,
165
+ const w = n.map((m) => ({
166
+ name: d.white(V(t, m) || m) + d.dim(` (${m})`),
167
+ value: V(t, m) || m,
121
168
  checked: !0
122
169
  }));
123
- c = await te({
170
+ c = await ne({
124
171
  message: d.bold("Select .xcodeproj directories for language detection:"),
125
- choices: b
172
+ choices: w
126
173
  });
127
174
  } else
128
175
  console.log(d.dim(" No .xcodeproj directories found"));
129
- if (console.log(), console.log(d.dim("─".repeat(40))), console.log(), console.log(d.bold("📋 Configuration Summary:")), console.log(), console.log(d.cyan(" xcstringsPaths:")), s.length > 0 ? s.forEach((b) => console.log(d.white(` • ${b}`))) : console.log(d.dim(" (none)")), console.log(), console.log(d.cyan(" xcodeprojPaths:")), c.length > 0 ? c.forEach((b) => console.log(d.white(` • ${b}`))) : console.log(d.dim(" (none)")), console.log(), !await Oe({
130
- message: d.bold(`Create ${d.yellow(I)}?`),
176
+ if (console.log(), console.log(d.dim("─".repeat(40))), console.log(), console.log(d.bold("📋 Configuration Summary:")), console.log(), console.log(d.cyan(" xcstringsPaths:")), o.length > 0 ? o.forEach((w) => console.log(d.white(` • ${w}`))) : console.log(d.dim(" (none)")), console.log(), console.log(d.cyan(" xcodeprojPaths:")), c.length > 0 ? c.forEach((w) => console.log(d.white(` • ${w}`))) : console.log(d.dim(" (none)")), console.log(), !await ze({
177
+ message: d.bold(`Create ${d.yellow(B)}?`),
131
178
  default: !0
132
179
  })) {
133
180
  console.log(d.dim(" Configuration cancelled."));
134
181
  return;
135
182
  }
136
- const x = s.map((b) => ` "${b}"`).join(`,
137
- `), z = c.map((b) => ` "${b}"`).join(`,
138
- `), _ = `{
183
+ const v = o.map((w) => ` "${w}"`).join(`,
184
+ `), z = c.map((w) => ` "${w}"`).join(`,
185
+ `), E = `{
139
186
  // Array of paths to .xcstrings files to manage. Specify relative or absolute paths.
140
187
  xcstringsPaths: [
141
- ${x}
188
+ ${v}
142
189
  ],
143
190
  // Array of paths to .xcodeproj directories. Used for discovering supported languages.
144
191
  xcodeprojPaths: [
145
192
  ${z}
146
- ]
193
+ ],
194
+ // Behavior for handling missing languages when adding strings.
195
+ missingLanguagePolicy: "skip",
147
196
  }
148
197
  `;
149
- await ie(I, _, "utf-8"), console.log(), console.log(d.bold.green(`✓ Created ${I}`)), console.log(d.dim(` Run ${d.cyan("xcstrings --help")} to see available commands.`)), console.log();
150
- }
151
- const M = "xcstrings-cli", ne = ke(M, {
152
- searchPlaces: [
153
- `${M}.json`,
154
- `${M}.json5`
155
- ],
156
- loaders: {
157
- ".json5": async (t, r) => ze.parse(r)
158
- },
159
- cache: !1
160
- });
161
- async function le(t) {
162
- if (t) {
163
- const n = await ne.load(t);
164
- return n ? n.config : null;
165
- }
166
- const r = await ne.search();
167
- return r ? r.config : null;
168
- }
169
- function Te(t) {
170
- const r = D(t, "project.pbxproj");
171
- return Se.open(r).rootObject.props.knownRegions ?? [];
172
- }
173
- async function $e(t) {
174
- const r = await U(t), n = /* @__PURE__ */ new Set();
175
- for (const s of Object.keys(r.strings)) {
176
- const c = r.strings[s];
177
- if (c.localizations)
178
- for (const l of Object.keys(c.localizations))
179
- n.add(l);
180
- }
181
- return Array.from(n).sort();
182
- }
183
- async function Ae(t, r) {
184
- const n = await le(r);
185
- if (n?.xcodeprojPaths && n.xcodeprojPaths.length > 0) {
186
- const s = /* @__PURE__ */ new Set();
187
- for (const c of n.xcodeprojPaths)
188
- Te(c).forEach((x) => s.add(x));
189
- return Array.from(s).sort();
190
- }
191
- return await $e(t);
198
+ await ae(B, E, "utf-8"), console.log(), console.log(d.bold.green(`✓ Created ${B}`)), console.log(d.dim(` Run ${d.cyan("xcstrings --help")} to see available commands.`)), console.log();
192
199
  }
193
200
  function Ne(t) {
194
201
  return t && t.__esModule && Object.prototype.hasOwnProperty.call(t, "default") ? t.default : t;
195
202
  }
196
- var C = { exports: {} }, W, re;
197
- function Ve() {
198
- if (re) return W;
199
- re = 1;
203
+ var C = { exports: {} }, I, se;
204
+ function Re() {
205
+ if (se) return I;
206
+ se = 1;
200
207
  function t(n) {
201
208
  try {
202
209
  return JSON.stringify(n);
@@ -204,77 +211,77 @@ function Ve() {
204
211
  return '"[Circular]"';
205
212
  }
206
213
  }
207
- W = r;
208
- function r(n, s, c) {
209
- var l = c && c.stringify || t, x = 1;
214
+ I = r;
215
+ function r(n, o, c) {
216
+ var l = c && c.stringify || t, v = 1;
210
217
  if (typeof n == "object" && n !== null) {
211
- var z = s.length + x;
218
+ var z = o.length + v;
212
219
  if (z === 1) return n;
213
- var _ = new Array(z);
214
- _[0] = l(n);
215
- for (var b = 1; b < z; b++)
216
- _[b] = l(s[b]);
217
- return _.join(" ");
220
+ var E = new Array(z);
221
+ E[0] = l(n);
222
+ for (var w = 1; w < z; w++)
223
+ E[w] = l(o[w]);
224
+ return E.join(" ");
218
225
  }
219
226
  if (typeof n != "string")
220
227
  return n;
221
- var h = s.length;
222
- if (h === 0) return n;
223
- for (var w = "", y = 1 - x, g = -1, k = n && n.length || 0, f = 0; f < k; ) {
228
+ var m = o.length;
229
+ if (m === 0) return n;
230
+ for (var b = "", p = 1 - v, h = -1, k = n && n.length || 0, f = 0; f < k; ) {
224
231
  if (n.charCodeAt(f) === 37 && f + 1 < k) {
225
- switch (g = g > -1 ? g : 0, n.charCodeAt(f + 1)) {
232
+ switch (h = h > -1 ? h : 0, n.charCodeAt(f + 1)) {
226
233
  case 100:
227
234
  // 'd'
228
235
  case 102:
229
- if (y >= h || s[y] == null) break;
230
- g < f && (w += n.slice(g, f)), w += Number(s[y]), g = f + 2, f++;
236
+ if (p >= m || o[p] == null) break;
237
+ h < f && (b += n.slice(h, f)), b += Number(o[p]), h = f + 2, f++;
231
238
  break;
232
239
  case 105:
233
- if (y >= h || s[y] == null) break;
234
- g < f && (w += n.slice(g, f)), w += Math.floor(Number(s[y])), g = f + 2, f++;
240
+ if (p >= m || o[p] == null) break;
241
+ h < f && (b += n.slice(h, f)), b += Math.floor(Number(o[p])), h = f + 2, f++;
235
242
  break;
236
243
  case 79:
237
244
  // 'O'
238
245
  case 111:
239
246
  // 'o'
240
247
  case 106:
241
- if (y >= h || s[y] === void 0) break;
242
- g < f && (w += n.slice(g, f));
243
- var T = typeof s[y];
248
+ if (p >= m || o[p] === void 0) break;
249
+ h < f && (b += n.slice(h, f));
250
+ var T = typeof o[p];
244
251
  if (T === "string") {
245
- w += "'" + s[y] + "'", g = f + 2, f++;
252
+ b += "'" + o[p] + "'", h = f + 2, f++;
246
253
  break;
247
254
  }
248
255
  if (T === "function") {
249
- w += s[y].name || "<anonymous>", g = f + 2, f++;
256
+ b += o[p].name || "<anonymous>", h = f + 2, f++;
250
257
  break;
251
258
  }
252
- w += l(s[y]), g = f + 2, f++;
259
+ b += l(o[p]), h = f + 2, f++;
253
260
  break;
254
261
  case 115:
255
- if (y >= h)
262
+ if (p >= m)
256
263
  break;
257
- g < f && (w += n.slice(g, f)), w += String(s[y]), g = f + 2, f++;
264
+ h < f && (b += n.slice(h, f)), b += String(o[p]), h = f + 2, f++;
258
265
  break;
259
266
  case 37:
260
- g < f && (w += n.slice(g, f)), w += "%", g = f + 2, f++, y--;
267
+ h < f && (b += n.slice(h, f)), b += "%", h = f + 2, f++, p--;
261
268
  break;
262
269
  }
263
- ++y;
270
+ ++p;
264
271
  }
265
272
  ++f;
266
273
  }
267
- return g === -1 ? n : (g < k && (w += n.slice(g)), w);
274
+ return h === -1 ? n : (h < k && (b += n.slice(h)), b);
268
275
  }
269
- return W;
276
+ return I;
270
277
  }
271
278
  var oe;
272
- function Xe() {
279
+ function Ve() {
273
280
  if (oe) return C.exports;
274
281
  oe = 1;
275
- const t = Ve();
276
- C.exports = h;
277
- const r = pe().console || {}, n = {
282
+ const t = Re();
283
+ C.exports = m;
284
+ const r = be().console || {}, n = {
278
285
  mapHttpRequest: A,
279
286
  mapHttpResponse: A,
280
287
  wrapRequestSerializer: q,
@@ -282,13 +289,13 @@ function Xe() {
282
289
  wrapErrorSerializer: q,
283
290
  req: A,
284
291
  res: A,
285
- err: H,
286
- errWithCause: H
292
+ err: G,
293
+ errWithCause: G
287
294
  };
288
- function s(e, o) {
289
- return e === "silent" ? 1 / 0 : o.levels.values[e];
295
+ function o(e, s) {
296
+ return e === "silent" ? 1 / 0 : s.levels.values[e];
290
297
  }
291
- const c = Symbol("pino.logFuncs"), l = Symbol("pino.hierarchy"), x = {
298
+ const c = Symbol("pino.logFuncs"), l = Symbol("pino.hierarchy"), v = {
292
299
  error: "log",
293
300
  fatal: "error",
294
301
  warn: "error",
@@ -296,101 +303,101 @@ function Xe() {
296
303
  debug: "log",
297
304
  trace: "log"
298
305
  };
299
- function z(e, o) {
306
+ function z(e, s) {
300
307
  const a = {
301
- logger: o,
308
+ logger: s,
302
309
  parent: e[l]
303
310
  };
304
- o[l] = a;
311
+ s[l] = a;
305
312
  }
306
- function _(e, o, a) {
313
+ function E(e, s, a) {
307
314
  const u = {};
308
- o.forEach((m) => {
309
- u[m] = a[m] ? a[m] : r[m] || r[x[m] || "log"] || F;
315
+ s.forEach((g) => {
316
+ u[g] = a[g] ? a[g] : r[g] || r[v[g] || "log"] || F;
310
317
  }), e[c] = u;
311
318
  }
312
- function b(e, o) {
319
+ function w(e, s) {
313
320
  return Array.isArray(e) ? e.filter(function(u) {
314
321
  return u !== "!stdSerializers.err";
315
- }) : e === !0 ? Object.keys(o) : !1;
322
+ }) : e === !0 ? Object.keys(s) : !1;
316
323
  }
317
- function h(e) {
324
+ function m(e) {
318
325
  e = e || {}, e.browser = e.browser || {};
319
- const o = e.browser.transmit;
320
- if (o && typeof o.send != "function")
326
+ const s = e.browser.transmit;
327
+ if (s && typeof s.send != "function")
321
328
  throw Error("pino: transmit option must have a send function");
322
329
  const a = e.browser.write || r;
323
330
  e.browser.write && (e.browser.asObject = !0);
324
- const u = e.serializers || {}, m = b(e.browser.serialize, u);
325
- let j = e.browser.serialize;
326
- Array.isArray(e.browser.serialize) && e.browser.serialize.indexOf("!stdSerializers.err") > -1 && (j = !1);
327
- const E = Object.keys(e.customLevels || {}), p = ["error", "fatal", "warn", "info", "debug", "trace"].concat(E);
328
- typeof a == "function" && p.forEach(function(O) {
329
- a[O] = a;
331
+ const u = e.serializers || {}, g = w(e.browser.serialize, u);
332
+ let O = e.browser.serialize;
333
+ Array.isArray(e.browser.serialize) && e.browser.serialize.indexOf("!stdSerializers.err") > -1 && (O = !1);
334
+ const _ = Object.keys(e.customLevels || {}), y = ["error", "fatal", "warn", "info", "debug", "trace"].concat(_);
335
+ typeof a == "function" && y.forEach(function(x) {
336
+ a[x] = a;
330
337
  }), (e.enabled === !1 || e.browser.disabled) && (e.level = "silent");
331
- const v = e.level || "info", i = Object.create(a);
332
- i.log || (i.log = F), _(i, p, a), z({}, i), Object.defineProperty(i, "levelVal", {
338
+ const j = e.level || "info", i = Object.create(a);
339
+ i.log || (i.log = F), E(i, y, a), z({}, i), Object.defineProperty(i, "levelVal", {
333
340
  get: N
334
341
  }), Object.defineProperty(i, "level", {
335
342
  get: L,
336
- set: be
343
+ set: ye
337
344
  });
338
345
  const S = {
339
- transmit: o,
340
- serialize: m,
346
+ transmit: s,
347
+ serialize: g,
341
348
  asObject: e.browser.asObject,
342
349
  formatters: e.browser.formatters,
343
- levels: p,
350
+ levels: y,
344
351
  timestamp: me(e)
345
352
  };
346
- i.levels = w(e), i.level = v, i.setMaxListeners = i.getMaxListeners = i.emit = i.addListener = i.on = i.prependListener = i.once = i.prependOnceListener = i.removeListener = i.removeAllListeners = i.listeners = i.listenerCount = i.eventNames = i.write = i.flush = F, i.serializers = u, i._serialize = m, i._stdErrSerialize = j, i.child = ye, o && (i._logEvent = R());
353
+ i.levels = b(e), i.level = j, i.setMaxListeners = i.getMaxListeners = i.emit = i.addListener = i.on = i.prependListener = i.once = i.prependOnceListener = i.removeListener = i.removeAllListeners = i.listeners = i.listenerCount = i.eventNames = i.write = i.flush = F, i.serializers = u, i._serialize = g, i._stdErrSerialize = O, i.child = we, s && (i._logEvent = D());
347
354
  function N() {
348
- return s(this.level, this);
355
+ return o(this.level, this);
349
356
  }
350
357
  function L() {
351
358
  return this._level;
352
359
  }
353
- function be(O) {
354
- if (O !== "silent" && !this.levels.values[O])
355
- throw Error("unknown level " + O);
356
- this._level = O, k(this, S, i, "error"), k(this, S, i, "fatal"), k(this, S, i, "warn"), k(this, S, i, "info"), k(this, S, i, "debug"), k(this, S, i, "trace"), E.forEach((P) => {
360
+ function ye(x) {
361
+ if (x !== "silent" && !this.levels.values[x])
362
+ throw Error("unknown level " + x);
363
+ this._level = x, k(this, S, i, "error"), k(this, S, i, "fatal"), k(this, S, i, "warn"), k(this, S, i, "info"), k(this, S, i, "debug"), k(this, S, i, "trace"), _.forEach((P) => {
357
364
  k(this, S, i, P);
358
365
  });
359
366
  }
360
- function ye(O, P) {
361
- if (!O)
367
+ function we(x, P) {
368
+ if (!x)
362
369
  throw new Error("missing bindings for child Pino");
363
- P = P || {}, m && O.serializers && (P.serializers = O.serializers);
364
- const K = P.serializers;
365
- if (m && K) {
366
- var V = Object.assign({}, u, K), Y = e.browser.serialize === !0 ? Object.keys(V) : m;
367
- delete O.serializers, $([O], Y, V, this._stdErrSerialize);
370
+ P = P || {}, g && x.serializers && (P.serializers = x.serializers);
371
+ const Y = P.serializers;
372
+ if (g && Y) {
373
+ var R = Object.assign({}, u, Y), Z = e.browser.serialize === !0 ? Object.keys(R) : g;
374
+ delete x.serializers, $([x], Z, R, this._stdErrSerialize);
368
375
  }
369
- function Z(ee) {
370
- this._childLevel = (ee._childLevel | 0) + 1, this.bindings = O, V && (this.serializers = V, this._serialize = Y), o && (this._logEvent = R(
371
- [].concat(ee._logEvent.bindings, O)
376
+ function ee(te) {
377
+ this._childLevel = (te._childLevel | 0) + 1, this.bindings = x, R && (this.serializers = R, this._serialize = Z), s && (this._logEvent = D(
378
+ [].concat(te._logEvent.bindings, x)
372
379
  ));
373
380
  }
374
- Z.prototype = this;
375
- const J = new Z(this);
381
+ ee.prototype = this;
382
+ const J = new ee(this);
376
383
  return z(this, J), J.level = this.level, J;
377
384
  }
378
385
  return i;
379
386
  }
380
- function w(e) {
381
- const o = e.customLevels || {}, a = Object.assign({}, h.levels.values, o), u = Object.assign({}, h.levels.labels, y(o));
387
+ function b(e) {
388
+ const s = e.customLevels || {}, a = Object.assign({}, m.levels.values, s), u = Object.assign({}, m.levels.labels, p(s));
382
389
  return {
383
390
  values: a,
384
391
  labels: u
385
392
  };
386
393
  }
387
- function y(e) {
388
- const o = {};
394
+ function p(e) {
395
+ const s = {};
389
396
  return Object.keys(e).forEach(function(a) {
390
- o[e[a]] = a;
391
- }), o;
397
+ s[e[a]] = a;
398
+ }), s;
392
399
  }
393
- h.levels = {
400
+ m.levels = {
394
401
  values: {
395
402
  fatal: 60,
396
403
  error: 50,
@@ -407,90 +414,90 @@ function Xe() {
407
414
  50: "error",
408
415
  60: "fatal"
409
416
  }
410
- }, h.stdSerializers = n, h.stdTimeFunctions = Object.assign({}, { nullTime: G, epochTime: Q, unixTime: he, isoTime: ge });
411
- function g(e) {
412
- const o = [];
413
- e.bindings && o.push(e.bindings);
417
+ }, m.stdSerializers = n, m.stdTimeFunctions = Object.assign({}, { nullTime: Q, epochTime: K, unixTime: he, isoTime: pe });
418
+ function h(e) {
419
+ const s = [];
420
+ e.bindings && s.push(e.bindings);
414
421
  let a = e[l];
415
422
  for (; a.parent; )
416
- a = a.parent, a.logger.bindings && o.push(a.logger.bindings);
417
- return o.reverse();
423
+ a = a.parent, a.logger.bindings && s.push(a.logger.bindings);
424
+ return s.reverse();
418
425
  }
419
- function k(e, o, a, u) {
426
+ function k(e, s, a, u) {
420
427
  if (Object.defineProperty(e, u, {
421
- value: s(e.level, a) > s(u, a) ? F : a[c][u],
428
+ value: o(e.level, a) > o(u, a) ? F : a[c][u],
422
429
  writable: !0,
423
430
  enumerable: !0,
424
431
  configurable: !0
425
- }), !o.transmit && e[u] === F)
432
+ }), !s.transmit && e[u] === F)
426
433
  return;
427
- e[u] = T(e, o, a, u);
428
- const m = g(e);
429
- m.length !== 0 && (e[u] = f(m, e[u]));
434
+ e[u] = T(e, s, a, u);
435
+ const g = h(e);
436
+ g.length !== 0 && (e[u] = f(g, e[u]));
430
437
  }
431
- function f(e, o) {
438
+ function f(e, s) {
432
439
  return function() {
433
- return o.apply(this, [...e, ...arguments]);
440
+ return s.apply(this, [...e, ...arguments]);
434
441
  };
435
442
  }
436
- function T(e, o, a, u) {
437
- return /* @__PURE__ */ (function(m) {
443
+ function T(e, s, a, u) {
444
+ return /* @__PURE__ */ (function(g) {
438
445
  return function() {
439
- const E = o.timestamp(), p = new Array(arguments.length), v = Object.getPrototypeOf && Object.getPrototypeOf(this) === r ? r : this;
440
- for (var i = 0; i < p.length; i++) p[i] = arguments[i];
441
- if (o.serialize && !o.asObject && $(p, this._serialize, this.serializers, this._stdErrSerialize), o.asObject || o.formatters ? m.call(v, ue(this, u, p, E, o.formatters)) : m.apply(v, p), o.transmit) {
442
- const S = o.transmit.level || e._level, N = a.levels.values[S], L = a.levels.values[u];
446
+ const _ = s.timestamp(), y = new Array(arguments.length), j = Object.getPrototypeOf && Object.getPrototypeOf(this) === r ? r : this;
447
+ for (var i = 0; i < y.length; i++) y[i] = arguments[i];
448
+ if (s.serialize && !s.asObject && $(y, this._serialize, this.serializers, this._stdErrSerialize), s.asObject || s.formatters ? g.call(j, de(this, u, y, _, s.formatters)) : g.apply(j, y), s.transmit) {
449
+ const S = s.transmit.level || e._level, N = a.levels.values[S], L = a.levels.values[u];
443
450
  if (L < N) return;
444
- de(this, {
445
- ts: E,
451
+ ge(this, {
452
+ ts: _,
446
453
  methodLevel: u,
447
454
  methodValue: L,
448
- transmitValue: a.levels.values[o.transmit.level || e._level],
449
- send: o.transmit.send,
450
- val: s(e._level, a)
451
- }, p);
455
+ transmitValue: a.levels.values[s.transmit.level || e._level],
456
+ send: s.transmit.send,
457
+ val: o(e._level, a)
458
+ }, y);
452
459
  }
453
460
  };
454
461
  })(e[c][u]);
455
462
  }
456
- function ue(e, o, a, u, m = {}) {
463
+ function de(e, s, a, u, g = {}) {
457
464
  const {
458
- level: j = () => e.levels.values[o],
459
- log: E = (L) => L
460
- } = m;
465
+ level: O = () => e.levels.values[s],
466
+ log: _ = (L) => L
467
+ } = g;
461
468
  e._serialize && $(a, e._serialize, e.serializers, e._stdErrSerialize);
462
- const p = a.slice();
463
- let v = p[0];
469
+ const y = a.slice();
470
+ let j = y[0];
464
471
  const i = {};
465
- u && (i.time = u), i.level = j(o, e.levels.values[o]);
472
+ u && (i.time = u), i.level = O(s, e.levels.values[s]);
466
473
  let S = (e._childLevel | 0) + 1;
467
- if (S < 1 && (S = 1), v !== null && typeof v == "object") {
468
- for (; S-- && typeof p[0] == "object"; )
469
- Object.assign(i, p.shift());
470
- v = p.length ? t(p.shift(), p) : void 0;
471
- } else typeof v == "string" && (v = t(p.shift(), p));
472
- return v !== void 0 && (i.msg = v), E(i);
473
- }
474
- function $(e, o, a, u) {
475
- for (const m in e)
476
- if (u && e[m] instanceof Error)
477
- e[m] = h.stdSerializers.err(e[m]);
478
- else if (typeof e[m] == "object" && !Array.isArray(e[m]))
479
- for (const j in e[m])
480
- o && o.indexOf(j) > -1 && j in a && (e[m][j] = a[j](e[m][j]));
481
- }
482
- function de(e, o, a) {
483
- const u = o.send, m = o.ts, j = o.methodLevel, E = o.methodValue, p = o.val, v = e._logEvent.bindings;
474
+ if (S < 1 && (S = 1), j !== null && typeof j == "object") {
475
+ for (; S-- && typeof y[0] == "object"; )
476
+ Object.assign(i, y.shift());
477
+ j = y.length ? t(y.shift(), y) : void 0;
478
+ } else typeof j == "string" && (j = t(y.shift(), y));
479
+ return j !== void 0 && (i.msg = j), _(i);
480
+ }
481
+ function $(e, s, a, u) {
482
+ for (const g in e)
483
+ if (u && e[g] instanceof Error)
484
+ e[g] = m.stdSerializers.err(e[g]);
485
+ else if (typeof e[g] == "object" && !Array.isArray(e[g]))
486
+ for (const O in e[g])
487
+ s && s.indexOf(O) > -1 && O in a && (e[g][O] = a[O](e[g][O]));
488
+ }
489
+ function ge(e, s, a) {
490
+ const u = s.send, g = s.ts, O = s.methodLevel, _ = s.methodValue, y = s.val, j = e._logEvent.bindings;
484
491
  $(
485
492
  a,
486
493
  e._serialize || Object.keys(e.serializers),
487
494
  e.serializers,
488
495
  e._stdErrSerialize === void 0 ? !0 : e._stdErrSerialize
489
- ), e._logEvent.ts = m, e._logEvent.messages = a.filter(function(i) {
490
- return v.indexOf(i) === -1;
491
- }), e._logEvent.level.label = j, e._logEvent.level.value = E, u(j, e._logEvent, p), e._logEvent = R(v);
496
+ ), e._logEvent.ts = g, e._logEvent.messages = a.filter(function(i) {
497
+ return j.indexOf(i) === -1;
498
+ }), e._logEvent.level.label = O, e._logEvent.level.value = _, u(O, e._logEvent, y), e._logEvent = D(j);
492
499
  }
493
- function R(e) {
500
+ function D(e) {
494
501
  return {
495
502
  ts: 0,
496
503
  messages: [],
@@ -498,18 +505,18 @@ function Xe() {
498
505
  level: { label: "", value: 0 }
499
506
  };
500
507
  }
501
- function H(e) {
502
- const o = {
508
+ function G(e) {
509
+ const s = {
503
510
  type: e.constructor.name,
504
511
  msg: e.message,
505
512
  stack: e.stack
506
513
  };
507
514
  for (const a in e)
508
- o[a] === void 0 && (o[a] = e[a]);
509
- return o;
515
+ s[a] === void 0 && (s[a] = e[a]);
516
+ return s;
510
517
  }
511
518
  function me(e) {
512
- return typeof e.timestamp == "function" ? e.timestamp : e.timestamp === !1 ? G : Q;
519
+ return typeof e.timestamp == "function" ? e.timestamp : e.timestamp === !1 ? Q : K;
513
520
  }
514
521
  function A() {
515
522
  return {};
@@ -519,21 +526,21 @@ function Xe() {
519
526
  }
520
527
  function F() {
521
528
  }
522
- function G() {
529
+ function Q() {
523
530
  return !1;
524
531
  }
525
- function Q() {
532
+ function K() {
526
533
  return Date.now();
527
534
  }
528
535
  function he() {
529
536
  return Math.round(Date.now() / 1e3);
530
537
  }
531
- function ge() {
538
+ function pe() {
532
539
  return new Date(Date.now()).toISOString();
533
540
  }
534
- function pe() {
535
- function e(o) {
536
- return typeof o < "u" && o;
541
+ function be() {
542
+ function e(s) {
543
+ return typeof s < "u" && s;
537
544
  }
538
545
  try {
539
546
  return typeof globalThis < "u" || Object.defineProperty(Object.prototype, "globalThis", {
@@ -546,13 +553,13 @@ function Xe() {
546
553
  return e(self) || e(window) || e(this) || {};
547
554
  }
548
555
  }
549
- return C.exports.default = h, C.exports.pino = h, C.exports;
556
+ return C.exports.default = m, C.exports.pino = m, C.exports;
550
557
  }
551
- var De = Xe();
552
- const Re = /* @__PURE__ */ Ne(De), B = Re({
558
+ var Xe = Ve();
559
+ const De = /* @__PURE__ */ Ne(Xe), W = De({
553
560
  level: process.env.LOG_LEVEL || "info"
554
561
  });
555
- async function fe() {
562
+ async function ue() {
556
563
  return new Promise((t) => {
557
564
  let r = "";
558
565
  process.stdin.setEncoding("utf8"), process.stdin.on("data", (n) => {
@@ -562,7 +569,7 @@ async function fe() {
562
569
  }), process.stdin.readableEnded && t("");
563
570
  });
564
571
  }
565
- async function qe(t, r = fe) {
572
+ async function qe(t, r = ue) {
566
573
  if (t !== void 0) {
567
574
  if (t === "") {
568
575
  const n = await r();
@@ -572,8 +579,8 @@ async function qe(t, r = fe) {
572
579
  return JSON.parse(t);
573
580
  if (Array.isArray(t)) {
574
581
  const n = {};
575
- for (const s of t)
576
- typeof s == "string" && Object.assign(n, JSON.parse(s));
582
+ for (const o of t)
583
+ typeof o == "string" && Object.assign(n, JSON.parse(o));
577
584
  return n;
578
585
  }
579
586
  if (typeof t == "boolean" && t === !0) {
@@ -582,32 +589,39 @@ async function qe(t, r = fe) {
582
589
  }
583
590
  }
584
591
  }
585
- async function Je(t, r, n, s, c = fe) {
586
- const l = await qe(s, c);
587
- await _e(t, r, n, l);
592
+ async function Je({
593
+ path: t,
594
+ key: r,
595
+ comment: n,
596
+ stringsArg: o,
597
+ stdinReader: c = ue,
598
+ configPath: l
599
+ }) {
600
+ const v = await qe(o, c);
601
+ await Fe(t, r, n, v, l);
588
602
  }
589
- const se = D(process.cwd(), "Localizable.xcstrings");
590
- we(ve(process.argv)).scriptName("xcstrings").usage("$0 <cmd> [args]").option("config", {
603
+ const ie = X(process.cwd(), "Localizable.xcstrings");
604
+ ve(je(process.argv)).scriptName("xcstrings").usage("$0 <cmd> [args]").option("config", {
591
605
  type: "string",
592
606
  describe: "Path to config file"
593
607
  }).option("path", {
594
608
  type: "string",
595
609
  describe: "Path to xcstrings file",
596
- default: se
610
+ default: ie
597
611
  }).middleware(async (t) => {
598
- if (t.path !== se)
612
+ if (t.path !== ie)
599
613
  return;
600
- const r = await le(t.config);
614
+ const r = await H(t.config);
601
615
  if (!(!r || !r.xcstringsPaths || r.xcstringsPaths.length === 0))
602
616
  if (r.xcstringsPaths.length === 1) {
603
617
  const n = r.xcstringsPaths[0];
604
618
  t.path = typeof n == "string" ? n : n.path;
605
619
  } else {
606
- const n = r.xcstringsPaths.map((c) => typeof c == "string" ? { name: c, value: c } : { name: `${c.alias} (${c.path})`, value: c.path }), s = await xe({
620
+ const n = r.xcstringsPaths.map((c) => typeof c == "string" ? { name: c, value: c } : { name: `${c.alias} (${c.path})`, value: c.path }), o = await Ee({
607
621
  message: "Select xcstrings file:",
608
622
  choices: n
609
623
  });
610
- t.path = s;
624
+ t.path = o;
611
625
  }
612
626
  }).command(
613
627
  "add",
@@ -624,7 +638,14 @@ we(ve(process.argv)).scriptName("xcstrings").usage("$0 <cmd> [args]").option("co
624
638
  describe: "The strings JSON"
625
639
  }),
626
640
  async (t) => {
627
- await Je(t.path, t.key, t.comment, t.strings), B.info(d.green(`✓ Added key "${t.key}"`));
641
+ await Je({
642
+ path: t.path,
643
+ key: t.key,
644
+ comment: t.comment,
645
+ stringsArg: t.strings,
646
+ stdinReader: void 0,
647
+ configPath: t.config
648
+ }), W.info(d.green(`✓ Added key "${t.key}"`));
628
649
  }
629
650
  ).command(
630
651
  "remove",
@@ -635,22 +656,22 @@ we(ve(process.argv)).scriptName("xcstrings").usage("$0 <cmd> [args]").option("co
635
656
  demandOption: !0
636
657
  }),
637
658
  async (t) => {
638
- await Le(t.path, t.key), B.info(d.green(`✓ Removed key "${t.key}"`));
659
+ await Ce(t.path, t.key), W.info(d.green(`✓ Removed key "${t.key}"`));
639
660
  }
640
661
  ).command(
641
662
  "init",
642
663
  "Initialize configuration file",
643
664
  (t) => t,
644
665
  async () => {
645
- await Ce();
666
+ await Ae();
646
667
  }
647
668
  ).command(
648
669
  "languages",
649
670
  "List supported languages from xcodeproj or xcstrings",
650
671
  (t) => t,
651
672
  async (t) => {
652
- const r = await Ae(t.path, t.config);
653
- B.info(r.join(" "));
673
+ const r = await fe(t.path, t.config);
674
+ W.info(r.join(" "));
654
675
  }
655
676
  ).demandCommand(1, "").strictCommands().recommendCommands().showHelpOnFail(!0).fail((t, r, n) => {
656
677
  if (r)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xcstrings-cli",
3
- "version": "1.1.1",
3
+ "version": "1.2.0",
4
4
  "description": "A command line tool for handling xcstrings files.",
5
5
  "type": "module",
6
6
  "bin": {