@esgettext/tools 1.0.0 → 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 (113) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +197 -22
  3. package/dist/command.js +2 -0
  4. package/dist/commands/convert.js +286 -0
  5. package/dist/commands/install.js +257 -0
  6. package/dist/commands/msgfmt-all.js +219 -0
  7. package/dist/commands/msgmerge-all.js +230 -0
  8. package/dist/commands/xgettext/file-resolver.js +20 -0
  9. package/dist/commands/xgettext/files-collector.js +39 -0
  10. package/dist/commands/xgettext.js +534 -0
  11. package/dist/configuration.js +277 -0
  12. package/dist/esgettext-package-json.js +2 -0
  13. package/dist/index.js +135 -0
  14. package/dist/package.js +10 -12
  15. package/dist/parser/javascript.js +9 -28
  16. package/dist/parser/parser.js +176 -148
  17. package/dist/parser/po.js +144 -128
  18. package/dist/parser/typescript.js +10 -28
  19. package/dist/pot/catalog.js +134 -83
  20. package/dist/pot/entry.js +173 -115
  21. package/dist/pot/keyword.js +66 -92
  22. package/package.json +38 -25
  23. package/bin/esgettext-install.js +0 -5
  24. package/bin/esgettext-mo2json.js +0 -5
  25. package/bin/esgettext-msgfmt-all.js +0 -5
  26. package/bin/esgettext-msgmerge-all.js +0 -5
  27. package/bin/esgettext-xgettext.js +0 -5
  28. package/dist/cli/getopt.d.ts +0 -34
  29. package/dist/cli/getopt.js +0 -150
  30. package/dist/cli/getopt.js.map +0 -1
  31. package/dist/cli/getopt.spec.d.ts +0 -1
  32. package/dist/cli/getopt.spec.js +0 -164
  33. package/dist/cli/getopt.spec.js.map +0 -1
  34. package/dist/cli/install.d.ts +0 -1
  35. package/dist/cli/install.js +0 -91
  36. package/dist/cli/install.js.map +0 -1
  37. package/dist/cli/mo2json-cli.d.ts +0 -1
  38. package/dist/cli/mo2json-cli.js +0 -48
  39. package/dist/cli/mo2json-cli.js.map +0 -1
  40. package/dist/cli/msgfmt-all.d.ts +0 -1
  41. package/dist/cli/msgfmt-all.js +0 -99
  42. package/dist/cli/msgfmt-all.js.map +0 -1
  43. package/dist/cli/msgmerge-all.d.ts +0 -1
  44. package/dist/cli/msgmerge-all.js +0 -85
  45. package/dist/cli/msgmerge-all.js.map +0 -1
  46. package/dist/cli/xgettext-cli.d.ts +0 -1
  47. package/dist/cli/xgettext-cli.js +0 -303
  48. package/dist/cli/xgettext-cli.js.map +0 -1
  49. package/dist/install/install.d.ts +0 -10
  50. package/dist/install/install.js +0 -157
  51. package/dist/install/install.js.map +0 -1
  52. package/dist/msgfmt-all/msgfmt-all.d.ts +0 -8
  53. package/dist/msgfmt-all/msgfmt-all.js +0 -142
  54. package/dist/msgfmt-all/msgfmt-all.js.map +0 -1
  55. package/dist/msgmerge-all/msgmerge-all.d.ts +0 -9
  56. package/dist/msgmerge-all/msgmerge-all.js +0 -157
  57. package/dist/msgmerge-all/msgmerge-all.js.map +0 -1
  58. package/dist/package.d.ts +0 -4
  59. package/dist/package.js.map +0 -1
  60. package/dist/parser/__snapshots__/javascript.spec.js.snap +0 -56
  61. package/dist/parser/__snapshots__/po.spec.js.snap +0 -176
  62. package/dist/parser/javascript.d.ts +0 -4
  63. package/dist/parser/javascript.js.map +0 -1
  64. package/dist/parser/javascript.spec.d.ts +0 -1
  65. package/dist/parser/javascript.spec.js +0 -436
  66. package/dist/parser/javascript.spec.js.map +0 -1
  67. package/dist/parser/parser.d.ts +0 -45
  68. package/dist/parser/parser.js.map +0 -1
  69. package/dist/parser/po.d.ts +0 -22
  70. package/dist/parser/po.js.map +0 -1
  71. package/dist/parser/po.spec.d.ts +0 -1
  72. package/dist/parser/po.spec.js +0 -296
  73. package/dist/parser/po.spec.js.map +0 -1
  74. package/dist/parser/typescript.d.ts +0 -4
  75. package/dist/parser/typescript.js.map +0 -1
  76. package/dist/parser/typescript.spec.d.ts +0 -1
  77. package/dist/parser/typescript.spec.js +0 -106
  78. package/dist/parser/typescript.spec.js.map +0 -1
  79. package/dist/pot/__snapshots__/catalog.spec.js.snap +0 -591
  80. package/dist/pot/catalog.d.ts +0 -26
  81. package/dist/pot/catalog.js.map +0 -1
  82. package/dist/pot/catalog.spec.d.ts +0 -1
  83. package/dist/pot/catalog.spec.js +0 -240
  84. package/dist/pot/catalog.spec.js.map +0 -1
  85. package/dist/pot/entry.d.ts +0 -35
  86. package/dist/pot/entry.js.map +0 -1
  87. package/dist/pot/entry.spec.d.ts +0 -1
  88. package/dist/pot/entry.spec.js +0 -317
  89. package/dist/pot/entry.spec.js.map +0 -1
  90. package/dist/pot/keyword.d.ts +0 -17
  91. package/dist/pot/keyword.js.map +0 -1
  92. package/dist/pot/keyword.spec.d.ts +0 -1
  93. package/dist/pot/keyword.spec.js +0 -54
  94. package/dist/pot/keyword.spec.js.map +0 -1
  95. package/dist/xgettext/__snapshots__/xgettext.spec.js.snap +0 -462
  96. package/dist/xgettext/file-resolver.d.ts +0 -5
  97. package/dist/xgettext/file-resolver.js +0 -23
  98. package/dist/xgettext/file-resolver.js.map +0 -1
  99. package/dist/xgettext/file-resolver.spec.d.ts +0 -1
  100. package/dist/xgettext/file-resolver.spec.js +0 -22
  101. package/dist/xgettext/file-resolver.spec.js.map +0 -1
  102. package/dist/xgettext/files-collector.d.ts +0 -5
  103. package/dist/xgettext/files-collector.js +0 -41
  104. package/dist/xgettext/files-collector.js.map +0 -1
  105. package/dist/xgettext/files-collector.spec.d.ts +0 -1
  106. package/dist/xgettext/files-collector.spec.js +0 -78
  107. package/dist/xgettext/files-collector.spec.js.map +0 -1
  108. package/dist/xgettext/xgettext.d.ts +0 -16
  109. package/dist/xgettext/xgettext.js +0 -335
  110. package/dist/xgettext/xgettext.js.map +0 -1
  111. package/dist/xgettext/xgettext.spec.d.ts +0 -1
  112. package/dist/xgettext/xgettext.spec.js +0 -743
  113. package/dist/xgettext/xgettext.spec.js.map +0 -1
@@ -1,84 +1,89 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Keyword = void 0;
4
- var runtime_1 = require("@esgettext/runtime");
5
- var gtx = runtime_1.Textdomain.getInstance('tools');
6
- var Keyword = (function () {
7
- function Keyword(method, args) {
8
- var _this = this;
4
+ const runtime_1 = require("@esgettext/runtime");
5
+ const gtx = runtime_1.Textdomain.getInstance('tools');
6
+ /**
7
+ * This is a direct port of Locale::XGettext::Util::Keyword
8
+ * (https://github.com/gflohr/Locale-XGettext/blob/master/lib/Locale/XGettext/Util/Keyword.pm)
9
+ * to JavaScript. See
10
+ * https://github.com/gflohr/Locale-XGettext/blob/master/lib/Locale/XGettext/Util/Keyword.pod
11
+ * for more information!
12
+ */
13
+ class Keyword {
14
+ constructor(method, args) {
15
+ var _a;
9
16
  this._method = method;
10
17
  if (!args) {
11
18
  args = new Array();
12
19
  }
13
- var argRe = new RegExp(/^([1-9][0-9]*)([ct]?)$/);
14
- var commentRe = new RegExp(/"([^"]*)"/);
15
- var seen = new Array();
16
- args.forEach(function (arg) {
20
+ const argRe = new RegExp(/^([1-9][0-9]*)([ct]?)$/);
21
+ const commentRe = new RegExp(/"([^"]*)"/);
22
+ const seen = new Array();
23
+ args.forEach(arg => {
17
24
  if (typeof arg === 'undefined' || arg === '') {
18
25
  arg = '1';
19
26
  }
20
- var argMatch = argRe.exec(arg);
27
+ const argMatch = argRe.exec(arg);
21
28
  if (argMatch) {
22
- var pos = Number.parseInt(argMatch[1], 10);
23
- var isCtx = argMatch[2] === 'c' ? true : false;
24
- var isTotal = argMatch[2] === 't' ? true : false;
29
+ const pos = Number.parseInt(argMatch[1], 10);
30
+ const isCtx = argMatch[2] === 'c' ? true : false;
31
+ const isTotal = argMatch[2] === 't' ? true : false;
25
32
  if (seen.includes(pos) && !isTotal) {
26
33
  throw new Error(gtx._x('Multiple meanings for argument #{num} for function "{function}"!', { function: method, num: pos }));
27
34
  }
28
35
  seen.push(pos);
29
36
  if (isCtx) {
30
- if (_this._context) {
37
+ if (this._context) {
31
38
  throw new Error(gtx._x('Multiple context arguments for function "{function}"!', {
32
39
  function: method,
33
40
  }));
34
41
  }
35
- _this._context = pos;
42
+ this._context = pos;
36
43
  }
37
44
  else if (isTotal) {
38
- if (_this._totalArgs) {
45
+ if (this._totalArgs) {
39
46
  throw new Error(gtx._x('Multiple total arguments for function "{function}"!', {
40
47
  function: method,
41
48
  }));
42
49
  }
43
- _this._totalArgs = pos;
50
+ this._totalArgs = pos;
44
51
  }
45
- else if (_this.plural) {
52
+ else if (this.plural) {
46
53
  throw new Error(gtx._x('Too many forms for function "{function}"!', {
47
54
  function: method,
48
55
  }));
49
56
  }
50
- else if (_this.singular) {
51
- _this._plural = pos;
57
+ else if (this._singular) {
58
+ this._plural = pos;
52
59
  }
53
60
  else {
54
- _this._singular = pos;
61
+ this._singular = pos;
55
62
  }
56
63
  }
57
64
  if (!argMatch) {
58
- var commentMatch = commentRe.exec(arg);
65
+ const commentMatch = commentRe.exec(arg);
59
66
  if (commentMatch) {
60
- if (typeof _this._comment !== 'undefined') {
67
+ if (typeof this._comment !== 'undefined') {
61
68
  throw new Error(gtx._x('Multiple extracted comments for function "{function}"!', {
62
69
  function: method,
63
70
  }));
64
71
  }
65
- _this._comment = commentMatch[1];
72
+ this._comment = commentMatch[1];
66
73
  }
67
74
  else {
68
75
  throw new Error(gtx._x('Invalid argument specification "{spec}" for function "{function}"!', { spec: arg, function: method }));
69
76
  }
70
77
  }
71
78
  });
72
- if (!this._singular) {
73
- this._singular = 1;
74
- }
79
+ (_a = this._singular) !== null && _a !== void 0 ? _a : (this._singular = 1);
75
80
  }
76
- Keyword.from = function (spec) {
77
- var tokens = new Array();
78
- var ready = false;
79
- var _loop_1 = function () {
80
- var modified = false;
81
- var remainder = spec.replace(/([,:])[\s]*([1-9][0-9]*[ct]?)[\s]*$/, function (_, sep, token) {
81
+ static from(spec) {
82
+ const tokens = new Array();
83
+ let ready = false;
84
+ while (spec.length) {
85
+ let modified = false;
86
+ let remainder = spec.replace(/([,:])[\s]*([1-9][0-9]*[ct]?)[\s]*$/, (_, sep, token) => {
82
87
  modified = true;
83
88
  tokens.unshift(token);
84
89
  if (sep === ':') {
@@ -88,9 +93,9 @@ var Keyword = (function () {
88
93
  });
89
94
  spec = remainder;
90
95
  if (ready) {
91
- return "break";
96
+ break;
92
97
  }
93
- remainder = spec.replace(/([,:])[\s]*("[^"]*")[\s]*$/, function (_, sep, token) {
98
+ remainder = spec.replace(/([,:])[\s]*("[^"]*")[\s]*$/, (_, sep, token) => {
94
99
  modified = true;
95
100
  tokens.unshift(token);
96
101
  if (':' === sep) {
@@ -100,18 +105,13 @@ var Keyword = (function () {
100
105
  });
101
106
  spec = remainder;
102
107
  if (ready || !modified) {
103
- return "break";
104
- }
105
- };
106
- while (spec.length) {
107
- var state_1 = _loop_1();
108
- if (state_1 === "break")
109
108
  break;
109
+ }
110
110
  }
111
111
  return new Keyword(spec, tokens);
112
- };
113
- Keyword.prototype.toString = function () {
114
- var dump = this.method + ':';
112
+ }
113
+ toString() {
114
+ let dump = this.method + ':';
115
115
  if (this.context) {
116
116
  dump += this.context + 'c,';
117
117
  }
@@ -123,59 +123,33 @@ var Keyword = (function () {
123
123
  dump += this.totalArgs + 't,';
124
124
  }
125
125
  if (typeof this.comment !== 'undefined') {
126
- dump += "\"".concat(this.comment, "\",");
126
+ dump += `"${this.comment}",`;
127
127
  }
128
128
  dump = dump.substr(0, dump.length - 1);
129
- if (dump === "".concat(this.method, ":1")) {
129
+ if (dump === `${this.method}:1`) {
130
130
  return this.method;
131
131
  }
132
132
  else {
133
133
  return dump;
134
134
  }
135
- };
136
- Object.defineProperty(Keyword.prototype, "method", {
137
- get: function () {
138
- return this._method;
139
- },
140
- enumerable: false,
141
- configurable: true
142
- });
143
- Object.defineProperty(Keyword.prototype, "singular", {
144
- get: function () {
145
- return this._singular;
146
- },
147
- enumerable: false,
148
- configurable: true
149
- });
150
- Object.defineProperty(Keyword.prototype, "plural", {
151
- get: function () {
152
- return this._plural;
153
- },
154
- enumerable: false,
155
- configurable: true
156
- });
157
- Object.defineProperty(Keyword.prototype, "context", {
158
- get: function () {
159
- return this._context;
160
- },
161
- enumerable: false,
162
- configurable: true
163
- });
164
- Object.defineProperty(Keyword.prototype, "comment", {
165
- get: function () {
166
- return this._comment;
167
- },
168
- enumerable: false,
169
- configurable: true
170
- });
171
- Object.defineProperty(Keyword.prototype, "totalArgs", {
172
- get: function () {
173
- return this._totalArgs;
174
- },
175
- enumerable: false,
176
- configurable: true
177
- });
178
- return Keyword;
179
- }());
135
+ }
136
+ get method() {
137
+ return this._method;
138
+ }
139
+ get singular() {
140
+ return this._singular;
141
+ }
142
+ get plural() {
143
+ return this._plural;
144
+ }
145
+ get context() {
146
+ return this._context;
147
+ }
148
+ get comment() {
149
+ return this._comment;
150
+ }
151
+ get totalArgs() {
152
+ return this._totalArgs;
153
+ }
154
+ }
180
155
  exports.Keyword = Keyword;
181
- //# sourceMappingURL=keyword.js.map
package/package.json CHANGED
@@ -1,40 +1,40 @@
1
1
  {
2
2
  "name": "@esgettext/tools",
3
- "version": "1.0.0",
3
+ "version": "1.2.0",
4
4
  "description": "Gettext-like po creation and manipulation",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
8
8
  "main": "dist/index.js",
9
- "types": "dist/index.d.ts",
10
- "repository": "https://github.com/gflohr/esgettext",
9
+ "typings": "dist/index.d.ts",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/gflohr/esgettext.git"
13
+ },
11
14
  "bugs": {
12
15
  "url": "https://github.com/gflohr/esgettext/issues"
13
16
  },
14
17
  "homepage": "https://github.com/gflohr/esgettext/packages/tools",
15
18
  "files": [
16
- "bin/",
17
- "dist/"
19
+ "dist"
18
20
  ],
19
21
  "bin": {
20
- "esgettext-install": "./bin/esgettext-install.js",
21
- "esgettext-mo2json": "./bin/esgettext-mo2json.js",
22
- "esgettext-msgfmt-all": "./bin/esgettext-msgfmt-all.js",
23
- "esgettext-msgmerge-all": "./bin/esgettext-msgmerge-all.js",
24
- "esgettext-xgettext": "./bin/esgettext-xgettext.js"
22
+ "esgettext": "dist/index.js"
25
23
  },
26
24
  "scripts": {
27
- "build": "npm run clean && tsc --project tsconfig-build.json",
28
- "prebuild": "node ./write-package.js >src/package.ts",
25
+ "build": "npm run clean && tsc --project tsconfig-build.json && chmod +x dist/index.js",
26
+ "prebuild": "node ./write-package.mjs >src/package.ts",
27
+ "prepublishOnly": "npm run check:clean && npm run build",
28
+ "check:clean": "../../check-clean",
29
29
  "format": "prettier --write 'src/**/*.ts'",
30
30
  "watch": "tsc --watch",
31
- "prewatch": "node ./write-package.js >src/package.ts",
32
- "clean": "shx rm -rf ./dist",
31
+ "prewatch": "node ./write-package.mjs >src/package.ts",
32
+ "clean": "rimraf ./dist",
33
33
  "lint": "eslint './src/**/*.ts'",
34
34
  "lint:fix": "eslint --fix './src/**/*.ts'",
35
35
  "lint:fix-dry-run": "eslint --fix './src/**/*.ts'",
36
36
  "lint:staged": "lint-staged",
37
- "pretest": "node ./write-package.js >src/package.ts",
37
+ "pretest": "node ./write-package.mjs >src/package.ts",
38
38
  "test": "jest",
39
39
  "test:watch": "jest --watch",
40
40
  "test:cov": "jest --coverage",
@@ -61,28 +61,41 @@
61
61
  "testEnvironment": "node"
62
62
  },
63
63
  "lint-staged": {
64
- "*.{js,ts,json,scss,css,md}": [
64
+ "*.{ts,json,md}": [
65
65
  "prettier --write"
66
66
  ],
67
67
  "src/**/*.ts": [
68
68
  "eslint"
69
69
  ]
70
70
  },
71
+ "devDependencies": {
72
+ "@babel/types": "^7.24.7",
73
+ "@eslint/config-array": "^0.16.0",
74
+ "@humanwhocodes/retry": "^0.3.0",
75
+ "@tsconfig/recommended": "^1.0.6",
76
+ "@types/glob": "^8.1.0",
77
+ "@types/jest": "^29.5.12",
78
+ "@types/jsonfile": "^6.1.4",
79
+ "@types/node": "^20.14.2",
80
+ "@types/yargs": "^17.0.32",
81
+ "eslint": "^8.56.0",
82
+ "jest": "^29.7.0",
83
+ "prettier": "^3.3.2",
84
+ "rimraf": "^5.0.7",
85
+ "tsx": "^4.15.4",
86
+ "typescript": "^5.4.5",
87
+ "typescript-eslint": "^7.13.0"
88
+ },
71
89
  "dependencies": {
72
90
  "@babel/parser": "^7.24.7",
73
91
  "@babel/traverse": "^7.24.7",
74
- "@esgettext/runtime": "^1.0.0",
92
+ "@esgettext/runtime": "^1.2.0",
93
+ "@valibot/i18n": "^0.15.0",
75
94
  "iconv-lite": "^0.6.3",
76
95
  "jsonfile": "^6.1.0",
77
96
  "mkdirp": "^3.0.1",
97
+ "valibot": "^0.31.1",
78
98
  "yargs": "^17.7.2"
79
99
  },
80
- "devDependencies": {
81
- "@babel/types": "^7.24.7",
82
- "@types/jsonfile": "^6.1.4",
83
- "@types/node": "^20.14.2",
84
- "@types/yargs": "^17.0.32",
85
- "shx": "^0.3.4"
86
- },
87
- "gitHead": "1bde315876e4ecc4b1800c3452a4f8bdb210088e"
100
+ "gitHead": "b3027a2934ec19444374e984673099f26cfccff7"
88
101
  }
@@ -1,5 +0,0 @@
1
- #! /usr/bin/env node
2
-
3
- const path = require('path');
4
-
5
- require(path.resolve(__dirname, '../dist/cli/install'));
@@ -1,5 +0,0 @@
1
- #! /usr/bin/env node
2
-
3
- const path = require('path');
4
-
5
- require(path.resolve(__dirname, '../dist/cli/mo2json-cli'));
@@ -1,5 +0,0 @@
1
- #! /usr/bin/env node
2
-
3
- const path = require('path');
4
-
5
- require(path.resolve(__dirname, '../dist/cli/msgfmt-all'));
@@ -1,5 +0,0 @@
1
- #! /usr/bin/env node
2
-
3
- const path = require('path');
4
-
5
- require(path.resolve(__dirname, '../dist/cli/msgmerge-all'));
@@ -1,5 +0,0 @@
1
- #! /usr/bin/env node
2
-
3
- const path = require('path');
4
-
5
- require(path.resolve(__dirname, '../dist/cli/xgettext-cli'));
@@ -1,34 +0,0 @@
1
- import yargs from 'yargs';
2
- export interface Options {
3
- [key: string]: any;
4
- }
5
- export interface OptionFlags {
6
- multiple?: boolean;
7
- }
8
- export interface Option {
9
- name: string;
10
- flags?: OptionFlags;
11
- yargsOptions: yargs.Options;
12
- }
13
- export interface OptionGroup {
14
- description: string;
15
- options: Array<Option>;
16
- }
17
- export interface GetoptOptions {
18
- hasVerboseOption?: boolean;
19
- }
20
- export declare class Getopt {
21
- readonly programName: string;
22
- private cli;
23
- private readonly allowedKeys;
24
- private readonly defaultFlags;
25
- private readonly hasVerboseOption;
26
- constructor(usage: string, description: string, optionGroups: OptionGroup[], options?: GetoptOptions);
27
- argv(args?: {
28
- [x: string]: unknown;
29
- _: string[];
30
- $0: string;
31
- }): Options;
32
- private buildUsage;
33
- private addDefaultOptions;
34
- }
@@ -1,150 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.Getopt = void 0;
7
- var yargs_1 = __importDefault(require("yargs"));
8
- var camelcase_1 = __importDefault(require("camelcase"));
9
- var runtime_1 = require("@esgettext/runtime");
10
- var package_1 = require("../package");
11
- var gtx = runtime_1.Textdomain.getInstance('tools');
12
- var Getopt = (function () {
13
- function Getopt(usage, description, optionGroups, options) {
14
- var _this = this;
15
- this.cli = yargs_1.default;
16
- this.allowedKeys = new Map();
17
- this.defaultFlags = {};
18
- this.programName = process.argv[1].split(/[\\/]/).pop();
19
- this.buildUsage(usage, description);
20
- if (!options) {
21
- options = {};
22
- }
23
- this.hasVerboseOption = options.hasVerboseOption || false;
24
- this.allowedKeys.set('help', this.defaultFlags);
25
- this.allowedKeys.set('h', this.defaultFlags);
26
- this.allowedKeys.set('version', this.defaultFlags);
27
- this.allowedKeys.set('V', this.defaultFlags);
28
- this.allowedKeys.set('_', this.defaultFlags);
29
- this.allowedKeys.set('$0', this.defaultFlags);
30
- if (this.hasVerboseOption) {
31
- this.allowedKeys.set('verbose', this.defaultFlags);
32
- this.allowedKeys.set('v', this.defaultFlags);
33
- }
34
- for (var i = 0; i < optionGroups.length; ++i) {
35
- var group = optionGroups[i];
36
- var options_1 = group.options;
37
- var optionKeys = options_1.map(function (option) { return option.name; });
38
- var _loop_1 = function (j) {
39
- var option = options_1[j];
40
- var flags = option.flags || this_1.defaultFlags;
41
- this_1.allowedKeys.set(option.name, flags);
42
- this_1.allowedKeys.set((0, camelcase_1.default)(option.name), flags);
43
- var alias = typeof option.yargsOptions.alias === 'string'
44
- ? [option.yargsOptions.alias]
45
- : option.yargsOptions.alias;
46
- if (alias) {
47
- alias.map(function (a) { return _this.allowedKeys.set(a, flags); });
48
- }
49
- };
50
- var this_1 = this;
51
- for (var j = 0; j < options_1.length; ++j) {
52
- _loop_1(j);
53
- }
54
- this.cli = this.cli.group(optionKeys, group.description);
55
- for (var j = 0; j < options_1.length; ++j) {
56
- this.cli = this.cli.option(options_1[j].name, options_1[j].yargsOptions);
57
- }
58
- }
59
- this.addDefaultOptions();
60
- }
61
- Getopt.prototype.argv = function (args) {
62
- if (typeof args === 'undefined') {
63
- args = this.cli.argv;
64
- }
65
- var keys = Object.keys(args);
66
- if (keys.includes('help')) {
67
- this.cli.showHelp('log');
68
- }
69
- for (var i = 0; i < keys.length; ++i) {
70
- var key = keys[i];
71
- if (key === '_') {
72
- continue;
73
- }
74
- if (!this.allowedKeys.has(key)) {
75
- if (key.length > 1) {
76
- throw new Error(gtx._x("'{programName}': unrecognized option '--{option}'", {
77
- programName: this.programName,
78
- option: key,
79
- }));
80
- }
81
- else {
82
- throw new Error(gtx._x("'{programName}': invalid option -- '{option}'", {
83
- programName: this.programName,
84
- option: key,
85
- }));
86
- }
87
- }
88
- var flags = this.allowedKeys.get(key);
89
- var value = args[key];
90
- if (Array.isArray(value)) {
91
- if (value.length > 1 && !flags.multiple) {
92
- throw new Error(gtx._x("The option '{option}' can be given only once.", {
93
- option: key,
94
- }));
95
- }
96
- }
97
- else if (flags.multiple) {
98
- args[key] = [value];
99
- }
100
- }
101
- return args;
102
- };
103
- Getopt.prototype.buildUsage = function (usage, description) {
104
- this.cli = this.cli.usage(gtx._x('Usage: {programName}', { programName: this.programName }) +
105
- ' ' +
106
- usage +
107
- '\n' +
108
- '\n' +
109
- description +
110
- '\n' +
111
- '\n' +
112
- gtx._('Mandatory arguments to long options are mandatory for short options too.\n') +
113
- gtx._('Similarly for optional arguments.\n') +
114
- '\n' +
115
- gtx._('Arguments to options are referred to in CAPS in the description.'));
116
- };
117
- Getopt.prototype.addDefaultOptions = function () {
118
- var infoOptions = this.hasVerboseOption
119
- ? ['version', 'help', 'verbose']
120
- : ['version', 'help'];
121
- var version = package_1.Package.getVersion();
122
- var packageName = package_1.Package.getName();
123
- var versionString = "".concat(this.programName, " (").concat(packageName, ") ").concat(version, "\n") +
124
- gtx._('LICENSE: WTFPL <http://www.wtfpl.net/about/>\n') +
125
- gtx._('This is free software. You can do with it whatever you want.\n') +
126
- gtx._('There is NO WARRANTY, to the extent permitted by law.\n') +
127
- gtx._('Written by Guido Flohr.');
128
- this.cli = this.cli.group(infoOptions, gtx._('Informative output'));
129
- this.cli = this.cli
130
- .option('help', {
131
- alias: 'h',
132
- description: gtx._('display this help and exit'),
133
- })
134
- .option('version', {
135
- alias: 'v',
136
- description: gtx._('output version information and exit'),
137
- })
138
- .version(versionString);
139
- if (this.hasVerboseOption) {
140
- this.cli = this.cli.options('verbose', {
141
- alias: 'V',
142
- description: gtx._('enable verbose output'),
143
- });
144
- }
145
- this.cli = this.cli.epilogue(gtx._('Report bugs at https://github.com/gflohr/esgettext/issues'));
146
- };
147
- return Getopt;
148
- }());
149
- exports.Getopt = Getopt;
150
- //# sourceMappingURL=getopt.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getopt.js","sourceRoot":"","sources":["../../src/cli/getopt.ts"],"names":[],"mappings":";;;;;;AAAA,gDAA0B;AAG1B,wDAAkC;AAClC,8CAAgD;AAChD,sCAAqC;AAErC,IAAM,GAAG,GAAG,oBAAU,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;AA0B5C;IAiBC,gBACC,KAAa,EACb,WAAmB,EACnB,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