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