@messagevisor/core 0.0.1 → 0.1.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 (211) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/LICENSE +21 -0
  3. package/README.md +7 -0
  4. package/jest.config.js +8 -0
  5. package/lib/benchmark/index.d.ts +2 -0
  6. package/lib/benchmark/index.js +417 -0
  7. package/lib/benchmark/index.js.map +1 -0
  8. package/lib/builder/index.d.ts +70 -0
  9. package/lib/builder/index.js +831 -0
  10. package/lib/builder/index.js.map +1 -0
  11. package/lib/cli/index.d.ts +28 -0
  12. package/lib/cli/index.js +182 -0
  13. package/lib/cli/index.js.map +1 -0
  14. package/lib/config/index.d.ts +61 -0
  15. package/lib/config/index.js +255 -0
  16. package/lib/config/index.js.map +1 -0
  17. package/lib/create/index.d.ts +2 -0
  18. package/lib/create/index.js +405 -0
  19. package/lib/create/index.js.map +1 -0
  20. package/lib/datasource/filesystemAdapter.d.ts +44 -0
  21. package/lib/datasource/filesystemAdapter.js +424 -0
  22. package/lib/datasource/filesystemAdapter.js.map +1 -0
  23. package/lib/datasource/index.d.ts +39 -0
  24. package/lib/datasource/index.js +96 -0
  25. package/lib/datasource/index.js.map +1 -0
  26. package/lib/error.d.ts +6 -0
  27. package/lib/error.js +49 -0
  28. package/lib/error.js.map +1 -0
  29. package/lib/evaluate/cli.d.ts +8 -0
  30. package/lib/evaluate/cli.js +179 -0
  31. package/lib/evaluate/cli.js.map +1 -0
  32. package/lib/evaluate/index.d.ts +10 -0
  33. package/lib/evaluate/index.js +131 -0
  34. package/lib/evaluate/index.js.map +1 -0
  35. package/lib/examples/coerceExampleIsoDates.d.ts +12 -0
  36. package/lib/examples/coerceExampleIsoDates.js +81 -0
  37. package/lib/examples/coerceExampleIsoDates.js.map +1 -0
  38. package/lib/examples/index.d.ts +63 -0
  39. package/lib/examples/index.js +713 -0
  40. package/lib/examples/index.js.map +1 -0
  41. package/lib/exporter/index.d.ts +60 -0
  42. package/lib/exporter/index.js +610 -0
  43. package/lib/exporter/index.js.map +1 -0
  44. package/lib/find-duplicates/index.d.ts +41 -0
  45. package/lib/find-duplicates/index.js +297 -0
  46. package/lib/find-duplicates/index.js.map +1 -0
  47. package/lib/generate-code/index.d.ts +11 -0
  48. package/lib/generate-code/index.js +157 -0
  49. package/lib/generate-code/index.js.map +1 -0
  50. package/lib/generate-code/typescript.d.ts +14 -0
  51. package/lib/generate-code/typescript.js +307 -0
  52. package/lib/generate-code/typescript.js.map +1 -0
  53. package/lib/importer/index.d.ts +64 -0
  54. package/lib/importer/index.js +1092 -0
  55. package/lib/importer/index.js.map +1 -0
  56. package/lib/index.d.ts +18 -0
  57. package/lib/index.js +35 -0
  58. package/lib/index.js.map +1 -0
  59. package/lib/info/index.d.ts +17 -0
  60. package/lib/info/index.js +132 -0
  61. package/lib/info/index.js.map +1 -0
  62. package/lib/init/index.d.ts +30 -0
  63. package/lib/init/index.js +348 -0
  64. package/lib/init/index.js.map +1 -0
  65. package/lib/lint/index.d.ts +1 -0
  66. package/lib/lint/index.js +6 -0
  67. package/lib/lint/index.js.map +1 -0
  68. package/lib/linter/attributeSchema.d.ts +7 -0
  69. package/lib/linter/attributeSchema.js +36 -0
  70. package/lib/linter/attributeSchema.js.map +1 -0
  71. package/lib/linter/checkLocaleCircularDependency.d.ts +7 -0
  72. package/lib/linter/checkLocaleCircularDependency.js +42 -0
  73. package/lib/linter/checkLocaleCircularDependency.js.map +1 -0
  74. package/lib/linter/conditionSchema.d.ts +3 -0
  75. package/lib/linter/conditionSchema.js +283 -0
  76. package/lib/linter/conditionSchema.js.map +1 -0
  77. package/lib/linter/formatSchema.d.ts +325 -0
  78. package/lib/linter/formatSchema.js +165 -0
  79. package/lib/linter/formatSchema.js.map +1 -0
  80. package/lib/linter/icuStyleLint.d.ts +6 -0
  81. package/lib/linter/icuStyleLint.js +226 -0
  82. package/lib/linter/icuStyleLint.js.map +1 -0
  83. package/lib/linter/index.d.ts +34 -0
  84. package/lib/linter/index.js +557 -0
  85. package/lib/linter/index.js.map +1 -0
  86. package/lib/linter/localeSchema.d.ts +672 -0
  87. package/lib/linter/localeSchema.js +50 -0
  88. package/lib/linter/localeSchema.js.map +1 -0
  89. package/lib/linter/messageSchema.d.ts +35 -0
  90. package/lib/linter/messageSchema.js +115 -0
  91. package/lib/linter/messageSchema.js.map +1 -0
  92. package/lib/linter/printError.d.ts +8 -0
  93. package/lib/linter/printError.js +41 -0
  94. package/lib/linter/printError.js.map +1 -0
  95. package/lib/linter/schema.d.ts +33 -0
  96. package/lib/linter/schema.js +192 -0
  97. package/lib/linter/schema.js.map +1 -0
  98. package/lib/linter/segmentSchema.d.ts +8 -0
  99. package/lib/linter/segmentSchema.js +18 -0
  100. package/lib/linter/segmentSchema.js.map +1 -0
  101. package/lib/linter/targetSchema.d.ts +337 -0
  102. package/lib/linter/targetSchema.js +39 -0
  103. package/lib/linter/targetSchema.js.map +1 -0
  104. package/lib/linter/testSchema.d.ts +71 -0
  105. package/lib/linter/testSchema.js +165 -0
  106. package/lib/linter/testSchema.js.map +1 -0
  107. package/lib/linter/zodHelpers.d.ts +2 -0
  108. package/lib/linter/zodHelpers.js +15 -0
  109. package/lib/linter/zodHelpers.js.map +1 -0
  110. package/lib/list/index.d.ts +8 -0
  111. package/lib/list/index.js +524 -0
  112. package/lib/list/index.js.map +1 -0
  113. package/lib/matrix.d.ts +4 -0
  114. package/lib/matrix.js +66 -0
  115. package/lib/matrix.js.map +1 -0
  116. package/lib/promoter/index.d.ts +65 -0
  117. package/lib/promoter/index.js +1208 -0
  118. package/lib/promoter/index.js.map +1 -0
  119. package/lib/prune/index.d.ts +37 -0
  120. package/lib/prune/index.js +673 -0
  121. package/lib/prune/index.js.map +1 -0
  122. package/lib/sets.d.ts +10 -0
  123. package/lib/sets.js +120 -0
  124. package/lib/sets.js.map +1 -0
  125. package/lib/tester/cliFormat.d.ts +8 -0
  126. package/lib/tester/cliFormat.js +15 -0
  127. package/lib/tester/cliFormat.js.map +1 -0
  128. package/lib/tester/index.d.ts +35 -0
  129. package/lib/tester/index.js +713 -0
  130. package/lib/tester/index.js.map +1 -0
  131. package/lib/tester/matrix.d.ts +14 -0
  132. package/lib/tester/matrix.js +76 -0
  133. package/lib/tester/matrix.js.map +1 -0
  134. package/lib/tester/prettyDuration.d.ts +1 -0
  135. package/lib/tester/prettyDuration.js +30 -0
  136. package/lib/tester/prettyDuration.js.map +1 -0
  137. package/lib/tester/printTestResult.d.ts +2 -0
  138. package/lib/tester/printTestResult.js +32 -0
  139. package/lib/tester/printTestResult.js.map +1 -0
  140. package/lib/tester/types.d.ts +29 -0
  141. package/lib/tester/types.js +3 -0
  142. package/lib/tester/types.js.map +1 -0
  143. package/package.json +41 -13
  144. package/src/benchmark/index.spec.ts +375 -0
  145. package/src/benchmark/index.ts +433 -0
  146. package/src/builder/index.spec.ts +822 -0
  147. package/src/builder/index.ts +920 -0
  148. package/src/cli/index.spec.ts +54 -0
  149. package/src/cli/index.ts +150 -0
  150. package/src/config/index.spec.ts +70 -0
  151. package/src/config/index.ts +259 -0
  152. package/src/create/index.spec.ts +272 -0
  153. package/src/create/index.ts +295 -0
  154. package/src/datasource/filesystemAdapter.ts +313 -0
  155. package/src/datasource/index.ts +135 -0
  156. package/src/error.ts +33 -0
  157. package/src/evaluate/cli.spec.ts +368 -0
  158. package/src/evaluate/cli.ts +130 -0
  159. package/src/evaluate/index.ts +161 -0
  160. package/src/examples/coerceExampleIsoDates.spec.ts +81 -0
  161. package/src/examples/coerceExampleIsoDates.ts +98 -0
  162. package/src/examples/index.spec.ts +453 -0
  163. package/src/examples/index.ts +854 -0
  164. package/src/exporter/index.spec.ts +443 -0
  165. package/src/exporter/index.ts +643 -0
  166. package/src/find-duplicates/index.spec.ts +289 -0
  167. package/src/find-duplicates/index.ts +314 -0
  168. package/src/generate-code/index.ts +92 -0
  169. package/src/generate-code/typescript.spec.ts +241 -0
  170. package/src/generate-code/typescript.ts +284 -0
  171. package/src/importer/index.spec.ts +1101 -0
  172. package/src/importer/index.ts +1190 -0
  173. package/src/index.ts +18 -0
  174. package/src/info/index.ts +67 -0
  175. package/src/init/index.spec.ts +279 -0
  176. package/src/init/index.ts +292 -0
  177. package/src/lint/index.ts +1 -0
  178. package/src/linter/attributeSchema.ts +38 -0
  179. package/src/linter/checkLocaleCircularDependency.ts +51 -0
  180. package/src/linter/conditionSchema.ts +386 -0
  181. package/src/linter/formatSchema.ts +170 -0
  182. package/src/linter/icuStyleLint.ts +312 -0
  183. package/src/linter/index.spec.ts +824 -0
  184. package/src/linter/index.ts +460 -0
  185. package/src/linter/localeSchema.ts +70 -0
  186. package/src/linter/messageSchema.ts +152 -0
  187. package/src/linter/printError.ts +52 -0
  188. package/src/linter/schema.ts +230 -0
  189. package/src/linter/segmentSchema.ts +15 -0
  190. package/src/linter/targetSchema.ts +50 -0
  191. package/src/linter/testSchema.spec.ts +405 -0
  192. package/src/linter/testSchema.ts +239 -0
  193. package/src/linter/zodHelpers.ts +16 -0
  194. package/src/list/index.spec.ts +431 -0
  195. package/src/list/index.ts +463 -0
  196. package/src/matrix.ts +69 -0
  197. package/src/promoter/index.spec.ts +584 -0
  198. package/src/promoter/index.ts +1267 -0
  199. package/src/prune/index.spec.ts +418 -0
  200. package/src/prune/index.ts +693 -0
  201. package/src/sets.ts +74 -0
  202. package/src/tester/cliFormat.ts +11 -0
  203. package/src/tester/featurevisorIntegration.spec.ts +101 -0
  204. package/src/tester/index.spec.ts +577 -0
  205. package/src/tester/index.ts +679 -0
  206. package/src/tester/matrix.ts +106 -0
  207. package/src/tester/prettyDuration.ts +34 -0
  208. package/src/tester/printTestResult.ts +40 -0
  209. package/src/tester/types.ts +32 -0
  210. package/tsconfig.cjs.json +11 -0
  211. package/tsconfig.typecheck.json +4 -0
@@ -0,0 +1,831 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ var desc = Object.getOwnPropertyDescriptor(m, k);
16
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
17
+ desc = { enumerable: true, get: function() { return m[k]; } };
18
+ }
19
+ Object.defineProperty(o, k2, desc);
20
+ }) : (function(o, m, k, k2) {
21
+ if (k2 === undefined) k2 = k;
22
+ o[k2] = m[k];
23
+ }));
24
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
25
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
26
+ }) : function(o, v) {
27
+ o["default"] = v;
28
+ });
29
+ var __importStar = (this && this.__importStar) || (function () {
30
+ var ownKeys = function(o) {
31
+ ownKeys = Object.getOwnPropertyNames || function (o) {
32
+ var ar = [];
33
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
34
+ return ar;
35
+ };
36
+ return ownKeys(o);
37
+ };
38
+ return function (mod) {
39
+ if (mod && mod.__esModule) return mod;
40
+ var result = {};
41
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
42
+ __setModuleDefault(result, mod);
43
+ return result;
44
+ };
45
+ })();
46
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
47
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
48
+ return new (P || (P = Promise))(function (resolve, reject) {
49
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
50
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
51
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
52
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
53
+ });
54
+ };
55
+ var __generator = (this && this.__generator) || function (thisArg, body) {
56
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
57
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
58
+ function verb(n) { return function (v) { return step([n, v]); }; }
59
+ function step(op) {
60
+ if (f) throw new TypeError("Generator is already executing.");
61
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
62
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
63
+ if (y = 0, t) op = [op[0] & 2, t.value];
64
+ switch (op[0]) {
65
+ case 0: case 1: t = op; break;
66
+ case 4: _.label++; return { value: op[1], done: false };
67
+ case 5: _.label++; y = op[1]; op = [0]; continue;
68
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
69
+ default:
70
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
71
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
72
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
73
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
74
+ if (t[2]) _.ops.pop();
75
+ _.trys.pop(); continue;
76
+ }
77
+ op = body.call(thisArg, _);
78
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
79
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
80
+ }
81
+ };
82
+ var __rest = (this && this.__rest) || function (s, e) {
83
+ var t = {};
84
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
85
+ t[p] = s[p];
86
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
87
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
88
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
89
+ t[p[i]] = s[p[i]];
90
+ }
91
+ return t;
92
+ };
93
+ Object.defineProperty(exports, "__esModule", { value: true });
94
+ exports.buildPlugin = void 0;
95
+ exports.mergeFormats = mergeFormats;
96
+ exports.resolveFormats = resolveFormats;
97
+ exports.buildDatafile = buildDatafile;
98
+ exports.buildMessageDatafile = buildMessageDatafile;
99
+ exports.buildProject = buildProject;
100
+ exports.buildProjectSets = buildProjectSets;
101
+ /* eslint-disable @typescript-eslint/no-unused-vars */
102
+ var crypto = __importStar(require("crypto"));
103
+ var path = __importStar(require("path"));
104
+ var config_1 = require("../config");
105
+ var evaluate_1 = require("../evaluate");
106
+ var sets_1 = require("../sets");
107
+ var cliFormat_1 = require("../tester/cliFormat");
108
+ var prettyDuration_1 = require("../tester/prettyDuration");
109
+ function isPlainObject(value) {
110
+ return typeof value === "object" && value !== null && !Array.isArray(value);
111
+ }
112
+ function deepMerge(parent, child) {
113
+ if (typeof parent === "undefined") {
114
+ return child;
115
+ }
116
+ if (typeof child === "undefined") {
117
+ return parent;
118
+ }
119
+ if (!isPlainObject(parent) || !isPlainObject(child)) {
120
+ return child;
121
+ }
122
+ var result = __assign({}, parent);
123
+ for (var _i = 0, _a = Object.keys(child); _i < _a.length; _i++) {
124
+ var key = _a[_i];
125
+ result[key] = deepMerge(result[key], child[key]);
126
+ }
127
+ return result;
128
+ }
129
+ function mergeFormats(parent, child) {
130
+ return deepMerge(parent, child);
131
+ }
132
+ function matchesPattern(key, patterns) {
133
+ if (!patterns || patterns.length === 0) {
134
+ return false;
135
+ }
136
+ return patterns.some(function (pattern) {
137
+ var escaped = pattern.replace(/[.+?^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*");
138
+ return new RegExp("^".concat(escaped, "$")).test(key);
139
+ });
140
+ }
141
+ function isAvailable(entity) {
142
+ return !entity.archived;
143
+ }
144
+ function readAll(keys, read) {
145
+ return __awaiter(this, void 0, void 0, function () {
146
+ var entries;
147
+ var _this = this;
148
+ return __generator(this, function (_a) {
149
+ switch (_a.label) {
150
+ case 0: return [4 /*yield*/, Promise.all(keys.map(function (key) { return __awaiter(_this, void 0, void 0, function () { var _a; return __generator(this, function (_b) {
151
+ switch (_b.label) {
152
+ case 0:
153
+ _a = [key];
154
+ return [4 /*yield*/, read(key)];
155
+ case 1: return [2 /*return*/, _a.concat([_b.sent()])];
156
+ }
157
+ }); }); }))];
158
+ case 1:
159
+ entries = _a.sent();
160
+ return [2 /*return*/, Object.fromEntries(entries)];
161
+ }
162
+ });
163
+ });
164
+ }
165
+ function resolveLocaleChain(localeKey, locales, field) {
166
+ var _a;
167
+ var chain = [];
168
+ var seen = new Set();
169
+ var currentKey = localeKey;
170
+ while (currentKey && !seen.has(currentKey)) {
171
+ seen.add(currentKey);
172
+ chain.unshift(currentKey);
173
+ currentKey = (_a = locales[currentKey]) === null || _a === void 0 ? void 0 : _a[field];
174
+ }
175
+ return chain;
176
+ }
177
+ function resolveFormats(localeKey, locales, target) {
178
+ var _a, _b;
179
+ var chain = resolveLocaleChain(localeKey, locales, "inheritFormatsFrom");
180
+ var formats;
181
+ for (var _i = 0, chain_1 = chain; _i < chain_1.length; _i++) {
182
+ var key = chain_1[_i];
183
+ formats = mergeFormats(formats, (_a = locales[key]) === null || _a === void 0 ? void 0 : _a.formats);
184
+ }
185
+ return mergeFormats(formats, (_b = target === null || target === void 0 ? void 0 : target.formats) === null || _b === void 0 ? void 0 : _b[localeKey]);
186
+ }
187
+ function resolveLocaleValue(values, localeKey, locales) {
188
+ var chain = resolveLocaleChain(localeKey, locales, "inheritTranslationsFrom");
189
+ var candidates = chain.reverse();
190
+ for (var _i = 0, candidates_1 = candidates; _i < candidates_1.length; _i++) {
191
+ var candidate = candidates_1[_i];
192
+ if (values && typeof values[candidate] !== "undefined") {
193
+ return values[candidate];
194
+ }
195
+ }
196
+ }
197
+ function collectSegmentKeys(segments, result) {
198
+ if (!segments || segments === "*") {
199
+ return;
200
+ }
201
+ if (typeof segments === "string") {
202
+ result.add(segments);
203
+ return;
204
+ }
205
+ if (Array.isArray(segments)) {
206
+ for (var _i = 0, segments_1 = segments; _i < segments_1.length; _i++) {
207
+ var segment = segments_1[_i];
208
+ collectSegmentKeys(segment, result);
209
+ }
210
+ return;
211
+ }
212
+ if ("and" in segments) {
213
+ collectSegmentKeys(segments.and, result);
214
+ return;
215
+ }
216
+ if ("or" in segments) {
217
+ collectSegmentKeys(segments.or, result);
218
+ return;
219
+ }
220
+ if ("not" in segments) {
221
+ collectSegmentKeys(segments.not, result);
222
+ }
223
+ }
224
+ function collectConditionSegmentKeys(conditions, result) {
225
+ if (!conditions || conditions === "*") {
226
+ return;
227
+ }
228
+ if (typeof conditions === "string") {
229
+ result.add(conditions);
230
+ return;
231
+ }
232
+ if (Array.isArray(conditions)) {
233
+ for (var _i = 0, conditions_1 = conditions; _i < conditions_1.length; _i++) {
234
+ var condition = conditions_1[_i];
235
+ collectConditionSegmentKeys(condition, result);
236
+ }
237
+ return;
238
+ }
239
+ if ("attribute" in conditions) {
240
+ return;
241
+ }
242
+ if ("and" in conditions) {
243
+ collectConditionSegmentKeys(conditions.and, result);
244
+ return;
245
+ }
246
+ if ("or" in conditions) {
247
+ collectConditionSegmentKeys(conditions.or, result);
248
+ return;
249
+ }
250
+ if ("not" in conditions) {
251
+ collectConditionSegmentKeys(conditions.not, result);
252
+ }
253
+ }
254
+ function resolveTargetDatafileOptions(target) {
255
+ return {
256
+ stringify: (target === null || target === void 0 ? void 0 : target.stringify) !== false,
257
+ pretty: (target === null || target === void 0 ? void 0 : target.pretty) === true,
258
+ revisionFromHash: (target === null || target === void 0 ? void 0 : target.revisionFromHash) === true,
259
+ };
260
+ }
261
+ function getDatafileSizeInBytes(datafile, options) {
262
+ return Buffer.byteLength(options.pretty ? JSON.stringify(datafile, null, 2) : JSON.stringify(datafile));
263
+ }
264
+ function stringifyDatafileExpression(options, value) {
265
+ if (!options.stringify || typeof value === "undefined" || typeof value === "string") {
266
+ return value;
267
+ }
268
+ return JSON.stringify(value);
269
+ }
270
+ function hasContextValue(context, attribute) {
271
+ if (!context) {
272
+ return false;
273
+ }
274
+ var current = context;
275
+ for (var _i = 0, _a = attribute.split("."); _i < _a.length; _i++) {
276
+ var part = _a[_i];
277
+ if (!current ||
278
+ typeof current !== "object" ||
279
+ !Object.prototype.hasOwnProperty.call(current, part)) {
280
+ return false;
281
+ }
282
+ current = current[part];
283
+ }
284
+ return true;
285
+ }
286
+ function simplifyAnd(items, create) {
287
+ if (items.some(function (item) { return item.state === "false"; })) {
288
+ return { state: "false" };
289
+ }
290
+ var partials = items
291
+ .filter(function (item) { return item.state === "partial"; })
292
+ .map(function (item) { return item.value; });
293
+ if (partials.length === 0) {
294
+ return { state: "true" };
295
+ }
296
+ if (partials.length === 1) {
297
+ return { state: "partial", value: partials[0] };
298
+ }
299
+ return { state: "partial", value: create(partials) };
300
+ }
301
+ function simplifyOr(items, create) {
302
+ if (items.some(function (item) { return item.state === "true"; })) {
303
+ return { state: "true" };
304
+ }
305
+ var partials = items
306
+ .filter(function (item) { return item.state === "partial"; })
307
+ .map(function (item) { return item.value; });
308
+ if (partials.length === 0) {
309
+ return { state: "false" };
310
+ }
311
+ if (partials.length === 1) {
312
+ return { state: "partial", value: partials[0] };
313
+ }
314
+ return { state: "partial", value: create(partials) };
315
+ }
316
+ function simplifyNot(items, create) {
317
+ if (items.some(function (item) { return item.state === "false"; })) {
318
+ return { state: "true" };
319
+ }
320
+ var partials = items
321
+ .filter(function (item) { return item.state === "partial"; })
322
+ .map(function (item) { return item.value; });
323
+ if (partials.length === 0) {
324
+ return { state: "false" };
325
+ }
326
+ return { state: "partial", value: create(partials) };
327
+ }
328
+ function createTargetSimplifier(segments, context) {
329
+ var targetedSegments = {};
330
+ var segmentConditionResults = {};
331
+ function simplifyCondition(condition) {
332
+ if (Array.isArray(condition)) {
333
+ return simplifyAnd(condition.map(function (item) { return simplifyCondition(item); }), function (items) { return items; });
334
+ }
335
+ if (typeof condition === "string") {
336
+ return simplifyGroupSegment(condition);
337
+ }
338
+ if ("and" in condition) {
339
+ return simplifyAnd(condition.and.map(function (item) { return simplifyCondition(item); }), function (items) { return ({ and: items }); });
340
+ }
341
+ if ("or" in condition) {
342
+ return simplifyOr(condition.or.map(function (item) { return simplifyCondition(item); }), function (items) { return ({ or: items }); });
343
+ }
344
+ if ("not" in condition) {
345
+ return simplifyNot(condition.not.map(function (item) { return simplifyCondition(item); }), function (items) { return ({ not: items }); });
346
+ }
347
+ if (!("attribute" in condition) || !hasContextValue(context, condition.attribute)) {
348
+ return { state: "partial", value: condition };
349
+ }
350
+ return (0, evaluate_1.evaluateCondition)(condition, { context: context, segments: segments })
351
+ ? { state: "true" }
352
+ : { state: "false" };
353
+ }
354
+ function simplifySegmentCondition(segmentKey) {
355
+ if (segmentConditionResults[segmentKey]) {
356
+ return segmentConditionResults[segmentKey];
357
+ }
358
+ var segment = segments[segmentKey];
359
+ if (!segment || segment.archived) {
360
+ segmentConditionResults[segmentKey] = { state: "false" };
361
+ return segmentConditionResults[segmentKey];
362
+ }
363
+ var result = simplifyCondition(segment.conditions);
364
+ segmentConditionResults[segmentKey] = result;
365
+ if (result.state === "partial") {
366
+ var _key = segment.key, _description = segment.description, _promotable = segment.promotable, segmentForDatafile = __rest(segment, ["key", "description", "promotable"]);
367
+ targetedSegments[segmentKey] = __assign(__assign({}, segmentForDatafile), { conditions: result.value });
368
+ }
369
+ return result;
370
+ }
371
+ function simplifyGroupSegment(groupSegment) {
372
+ if (Array.isArray(groupSegment)) {
373
+ return simplifyAnd(groupSegment.map(function (item) { return simplifyGroupSegment(item); }), function (items) { return items; });
374
+ }
375
+ if (typeof groupSegment === "string") {
376
+ var segmentResult = simplifySegmentCondition(groupSegment);
377
+ if (segmentResult.state !== "partial") {
378
+ return segmentResult;
379
+ }
380
+ return { state: "partial", value: groupSegment };
381
+ }
382
+ if ("and" in groupSegment) {
383
+ return simplifyAnd(groupSegment.and.map(function (item) { return simplifyGroupSegment(item); }), function (items) { return ({ and: items }); });
384
+ }
385
+ if ("or" in groupSegment) {
386
+ return simplifyOr(groupSegment.or.map(function (item) { return simplifyGroupSegment(item); }), function (items) { return ({ or: items }); });
387
+ }
388
+ return simplifyNot(groupSegment.not.map(function (item) { return simplifyGroupSegment(item); }), function (items) { return ({ not: items }); });
389
+ }
390
+ return {
391
+ targetedSegments: targetedSegments,
392
+ simplifyCondition: simplifyCondition,
393
+ simplifyGroupSegment: simplifyGroupSegment,
394
+ };
395
+ }
396
+ function buildDatafileFromMessageKeys(projectConfig, datasource, messageKeys, targetKey, localeKey, revision) {
397
+ return __awaiter(this, void 0, void 0, function () {
398
+ var localeKeys, _a, locales, messages, target, _b, datafileOptions, includedMessages, excludedMessages, datafileMessages, translations, usedSegmentKeys, segmentKeys, segments, targetSimplifier, _i, messageKeys_1, key, message, translation, overrides, datafileSegments, datafileSegmentKeys, _c, datafileSegmentKeys_1, key, segment;
399
+ var _d, _e;
400
+ return __generator(this, function (_f) {
401
+ switch (_f.label) {
402
+ case 0: return [4 /*yield*/, datasource.listLocales()];
403
+ case 1:
404
+ localeKeys = _f.sent();
405
+ return [4 /*yield*/, Promise.all([
406
+ readAll(localeKeys, function (key) { return datasource.readLocale(key); }),
407
+ readAll(messageKeys, function (key) { return datasource.readMessage(key); }),
408
+ ])];
409
+ case 2:
410
+ _a = _f.sent(), locales = _a[0], messages = _a[1];
411
+ if (!targetKey) return [3 /*break*/, 4];
412
+ return [4 /*yield*/, datasource.readTarget(targetKey)];
413
+ case 3:
414
+ _b = _f.sent();
415
+ return [3 /*break*/, 5];
416
+ case 4:
417
+ _b = undefined;
418
+ _f.label = 5;
419
+ case 5:
420
+ target = _b;
421
+ datafileOptions = resolveTargetDatafileOptions(target);
422
+ includedMessages = ((_d = target === null || target === void 0 ? void 0 : target.includeMessages) === null || _d === void 0 ? void 0 : _d.length) ? target.includeMessages : ["*"];
423
+ excludedMessages = (target === null || target === void 0 ? void 0 : target.excludeMessages) || [];
424
+ datafileMessages = {};
425
+ translations = {};
426
+ usedSegmentKeys = new Set();
427
+ return [4 /*yield*/, datasource.listSegments()];
428
+ case 6:
429
+ segmentKeys = _f.sent();
430
+ return [4 /*yield*/, readAll(segmentKeys, function (key) { return datasource.readSegment(key); })];
431
+ case 7:
432
+ segments = _f.sent();
433
+ targetSimplifier = createTargetSimplifier(segments, target === null || target === void 0 ? void 0 : target.context);
434
+ for (_i = 0, messageKeys_1 = messageKeys; _i < messageKeys_1.length; _i++) {
435
+ key = messageKeys_1[_i];
436
+ message = messages[key];
437
+ if (!isAvailable(message)) {
438
+ continue;
439
+ }
440
+ if (!matchesPattern(key, includedMessages) || matchesPattern(key, excludedMessages)) {
441
+ continue;
442
+ }
443
+ translation = resolveLocaleValue(message.translations, localeKey, locales);
444
+ if (typeof translation === "undefined") {
445
+ continue;
446
+ }
447
+ translations[key] = translation;
448
+ overrides = (message.overrides || [])
449
+ .map(function (override) {
450
+ var overrideTranslation = resolveLocaleValue(override.translations, localeKey, locales);
451
+ if (typeof overrideTranslation === "undefined") {
452
+ return undefined;
453
+ }
454
+ var targetedOverride = {
455
+ key: override.key,
456
+ translation: overrideTranslation,
457
+ };
458
+ if (override.conditions) {
459
+ if (override.conditions === "*") {
460
+ targetedOverride.conditions = override.conditions;
461
+ }
462
+ else {
463
+ var targetedConditions = targetSimplifier.simplifyCondition(override.conditions);
464
+ if (targetedConditions.state === "false") {
465
+ return undefined;
466
+ }
467
+ if (targetedConditions.state === "partial") {
468
+ collectConditionSegmentKeys(targetedConditions.value, usedSegmentKeys);
469
+ targetedOverride.conditions = stringifyDatafileExpression(datafileOptions, targetedConditions.value);
470
+ }
471
+ }
472
+ }
473
+ if (override.segments) {
474
+ if (override.segments === "*") {
475
+ targetedOverride.segments = override.segments;
476
+ }
477
+ else {
478
+ var targetedSegments = targetSimplifier.simplifyGroupSegment(override.segments);
479
+ if (targetedSegments.state === "false") {
480
+ return undefined;
481
+ }
482
+ if (targetedSegments.state === "partial") {
483
+ collectSegmentKeys(targetedSegments.value, usedSegmentKeys);
484
+ targetedOverride.segments = stringifyDatafileExpression(datafileOptions, targetedSegments.value);
485
+ }
486
+ }
487
+ }
488
+ return targetedOverride;
489
+ })
490
+ .filter(function (override) { return Boolean(override); });
491
+ if (message.deprecated || message.deprecationWarning || message.meta || overrides.length > 0) {
492
+ datafileMessages[key] = {
493
+ deprecated: message.deprecated || undefined,
494
+ deprecationWarning: message.deprecationWarning,
495
+ meta: message.meta,
496
+ overrides: overrides.length > 0 ? overrides : undefined,
497
+ };
498
+ }
499
+ }
500
+ datafileSegments = {};
501
+ datafileSegmentKeys = Array.from(usedSegmentKeys).sort();
502
+ for (_c = 0, datafileSegmentKeys_1 = datafileSegmentKeys; _c < datafileSegmentKeys_1.length; _c++) {
503
+ key = datafileSegmentKeys_1[_c];
504
+ if (targetSimplifier.targetedSegments[key]) {
505
+ segment = targetSimplifier.targetedSegments[key];
506
+ datafileSegments[key] = __assign(__assign({}, segment), { conditions: stringifyDatafileExpression(datafileOptions, segment.conditions) });
507
+ }
508
+ }
509
+ return [2 /*return*/, {
510
+ schemaVersion: config_1.SCHEMA_VERSION,
511
+ messagevisorVersion: "0.0.1",
512
+ revision: revision,
513
+ target: targetKey || "",
514
+ locale: localeKey,
515
+ direction: (_e = locales[localeKey]) === null || _e === void 0 ? void 0 : _e.direction,
516
+ formats: resolveFormats(localeKey, locales, target),
517
+ segments: datafileSegments,
518
+ messages: datafileMessages,
519
+ translations: translations,
520
+ }];
521
+ }
522
+ });
523
+ });
524
+ }
525
+ function buildDatafile(projectConfig, datasource, targetKey, localeKey, revision) {
526
+ return __awaiter(this, void 0, void 0, function () {
527
+ var messageKeys;
528
+ return __generator(this, function (_a) {
529
+ switch (_a.label) {
530
+ case 0: return [4 /*yield*/, datasource.listMessages()];
531
+ case 1:
532
+ messageKeys = _a.sent();
533
+ return [2 /*return*/, buildDatafileFromMessageKeys(projectConfig, datasource, messageKeys, targetKey, localeKey, revision)];
534
+ }
535
+ });
536
+ });
537
+ }
538
+ function buildMessageDatafile(projectConfig, datasource, messageKey, localeKey, revision, targetKey) {
539
+ return __awaiter(this, void 0, void 0, function () {
540
+ var availableMessageKeys, selectedMessageKeys;
541
+ return __generator(this, function (_a) {
542
+ switch (_a.label) {
543
+ case 0: return [4 /*yield*/, datasource.listMessages()];
544
+ case 1:
545
+ availableMessageKeys = _a.sent();
546
+ selectedMessageKeys = availableMessageKeys.includes(messageKey) ? [messageKey] : [];
547
+ return [2 /*return*/, buildDatafileFromMessageKeys(projectConfig, datasource, selectedMessageKeys, targetKey, localeKey, revision)];
548
+ }
549
+ });
550
+ });
551
+ }
552
+ function buildProject(projectConfig_1, datasource_1) {
553
+ return __awaiter(this, arguments, void 0, function (projectConfig, datasource, options) {
554
+ var startTime, _a, targetKeys, localeKeys, selectedTargetKeys, builtDatafiles, previousRevision, revision, numericRevision, _i, selectedTargetKeys_1, targetKey, target, selectedLocaleKeys, _b, selectedLocaleKeys_1, localeKey, datafile, datafileOptions, content, pretty;
555
+ var _c, _d, _e, _f, _g;
556
+ if (options === void 0) { options = {}; }
557
+ return __generator(this, function (_h) {
558
+ switch (_h.label) {
559
+ case 0:
560
+ startTime = Date.now();
561
+ return [4 /*yield*/, Promise.all([
562
+ datasource.listTargets(),
563
+ datasource.listLocales(),
564
+ ])];
565
+ case 1:
566
+ _a = _h.sent(), targetKeys = _a[0], localeKeys = _a[1];
567
+ selectedTargetKeys = options.target ? [options.target] : targetKeys;
568
+ builtDatafiles = [];
569
+ return [4 /*yield*/, datasource.readRevision()];
570
+ case 2:
571
+ previousRevision = _h.sent();
572
+ revision = options.revision;
573
+ if (!revision) {
574
+ numericRevision = Number(previousRevision);
575
+ revision = Number.isNaN(numericRevision) ? previousRevision : String(numericRevision + 1);
576
+ }
577
+ (_c = options.onProgress) === null || _c === void 0 ? void 0 : _c.call(options, {
578
+ type: "start",
579
+ previousRevision: previousRevision,
580
+ revision: revision,
581
+ targets: selectedTargetKeys,
582
+ });
583
+ _i = 0, selectedTargetKeys_1 = selectedTargetKeys;
584
+ _h.label = 3;
585
+ case 3:
586
+ if (!(_i < selectedTargetKeys_1.length)) return [3 /*break*/, 12];
587
+ targetKey = selectedTargetKeys_1[_i];
588
+ return [4 /*yield*/, datasource.readTarget(targetKey)];
589
+ case 4:
590
+ target = _h.sent();
591
+ selectedLocaleKeys = options.locale
592
+ ? [options.locale]
593
+ : ((_d = target.locales) === null || _d === void 0 ? void 0 : _d.length)
594
+ ? target.locales
595
+ : localeKeys;
596
+ (_e = options.onProgress) === null || _e === void 0 ? void 0 : _e.call(options, {
597
+ type: "targetStart",
598
+ target: targetKey,
599
+ locales: selectedLocaleKeys,
600
+ });
601
+ _b = 0, selectedLocaleKeys_1 = selectedLocaleKeys;
602
+ _h.label = 5;
603
+ case 5:
604
+ if (!(_b < selectedLocaleKeys_1.length)) return [3 /*break*/, 11];
605
+ localeKey = selectedLocaleKeys_1[_b];
606
+ return [4 /*yield*/, buildDatafile(projectConfig, datasource, targetKey, localeKey, revision)];
607
+ case 6:
608
+ datafile = _h.sent();
609
+ datafileOptions = resolveTargetDatafileOptions(target);
610
+ if (datafileOptions.revisionFromHash) {
611
+ content = JSON.stringify(__assign(__assign({}, datafile), { revision: "" }));
612
+ datafile = __assign(__assign({}, datafile), { revision: crypto.createHash("sha1").update(content).digest("hex") });
613
+ }
614
+ if (!options.json) return [3 /*break*/, 7];
615
+ pretty = options.pretty === true || datafileOptions.pretty;
616
+ console.log(pretty ? JSON.stringify(datafile, null, 2) : JSON.stringify(datafile));
617
+ return [3 /*break*/, 9];
618
+ case 7: return [4 /*yield*/, datasource.writeDatafile(datafile, { pretty: datafileOptions.pretty })];
619
+ case 8:
620
+ _h.sent();
621
+ _h.label = 9;
622
+ case 9:
623
+ builtDatafiles.push(datafile);
624
+ (_f = options.onProgress) === null || _f === void 0 ? void 0 : _f.call(options, {
625
+ type: "localeBuilt",
626
+ target: targetKey,
627
+ locale: localeKey,
628
+ datafile: datafile,
629
+ filePath: path.join(projectConfig.datafilesDirectoryPath, (0, config_1.formatDatafilePath)(projectConfig, targetKey, localeKey)),
630
+ sizeInBytes: options.showSize
631
+ ? getDatafileSizeInBytes(datafile, datafileOptions)
632
+ : undefined,
633
+ });
634
+ _h.label = 10;
635
+ case 10:
636
+ _b++;
637
+ return [3 /*break*/, 5];
638
+ case 11:
639
+ _i++;
640
+ return [3 /*break*/, 3];
641
+ case 12:
642
+ if (!(!options.noStateFiles && !options.revision)) return [3 /*break*/, 14];
643
+ return [4 /*yield*/, datasource.writeRevision(revision)];
644
+ case 13:
645
+ _h.sent();
646
+ _h.label = 14;
647
+ case 14:
648
+ (_g = options.onProgress) === null || _g === void 0 ? void 0 : _g.call(options, {
649
+ type: "complete",
650
+ datafiles: builtDatafiles,
651
+ duration: Date.now() - startTime,
652
+ revision: revision,
653
+ });
654
+ return [2 /*return*/, builtDatafiles];
655
+ }
656
+ });
657
+ });
658
+ }
659
+ function buildProjectSets(projectConfig_1, datasource_1) {
660
+ return __awaiter(this, arguments, void 0, function (projectConfig, datasource, options) {
661
+ var startTime, setExecutions, setKeys, builtDatafiles, previousRevision, numericRevision, revision, _loop_1, _i, setExecutions_1, execution;
662
+ var _a, _b, _c;
663
+ if (options === void 0) { options = {}; }
664
+ return __generator(this, function (_d) {
665
+ switch (_d.label) {
666
+ case 0:
667
+ startTime = Date.now();
668
+ return [4 /*yield*/, (0, sets_1.getProjectSetExecutions)(projectConfig, datasource, options.set)];
669
+ case 1:
670
+ setExecutions = _d.sent();
671
+ setKeys = setExecutions.map(function (execution) { return execution.set; });
672
+ builtDatafiles = [];
673
+ return [4 /*yield*/, datasource.readRevision()];
674
+ case 2:
675
+ previousRevision = _d.sent();
676
+ numericRevision = Number(previousRevision);
677
+ revision = Number.isNaN(numericRevision) ? previousRevision : String(numericRevision + 1);
678
+ if (projectConfig.sets) {
679
+ (_a = options.onProjectSetsProgress) === null || _a === void 0 ? void 0 : _a.call(options, {
680
+ type: "setsStart",
681
+ previousRevision: previousRevision,
682
+ revision: revision,
683
+ sets: setKeys,
684
+ });
685
+ }
686
+ _loop_1 = function (execution) {
687
+ var datafiles;
688
+ return __generator(this, function (_e) {
689
+ switch (_e.label) {
690
+ case 0:
691
+ if (projectConfig.sets) {
692
+ (_b = options.onProjectSetsProgress) === null || _b === void 0 ? void 0 : _b.call(options, { type: "setStart", set: execution.set });
693
+ }
694
+ return [4 /*yield*/, buildProject(execution.projectConfig, execution.datasource, __assign(__assign({}, options), { onProgress: options.onProjectSetsProgress
695
+ ? function (event) {
696
+ var _a;
697
+ return (_a = options.onProjectSetsProgress) === null || _a === void 0 ? void 0 : _a.call(options, __assign(__assign({}, event), { set: execution.set }));
698
+ }
699
+ : options.onProgress }))];
700
+ case 1:
701
+ datafiles = _e.sent();
702
+ builtDatafiles.push.apply(builtDatafiles, datafiles);
703
+ return [2 /*return*/];
704
+ }
705
+ });
706
+ };
707
+ _i = 0, setExecutions_1 = setExecutions;
708
+ _d.label = 3;
709
+ case 3:
710
+ if (!(_i < setExecutions_1.length)) return [3 /*break*/, 6];
711
+ execution = setExecutions_1[_i];
712
+ return [5 /*yield**/, _loop_1(execution)];
713
+ case 4:
714
+ _d.sent();
715
+ _d.label = 5;
716
+ case 5:
717
+ _i++;
718
+ return [3 /*break*/, 3];
719
+ case 6:
720
+ if (!(projectConfig.sets && !options.noStateFiles && !options.revision)) return [3 /*break*/, 8];
721
+ return [4 /*yield*/, datasource.writeRevision(revision)];
722
+ case 7:
723
+ _d.sent();
724
+ _d.label = 8;
725
+ case 8:
726
+ if (projectConfig.sets) {
727
+ (_c = options.onProjectSetsProgress) === null || _c === void 0 ? void 0 : _c.call(options, {
728
+ type: "setsComplete",
729
+ duration: Date.now() - startTime,
730
+ revision: revision,
731
+ sets: setKeys,
732
+ datafiles: builtDatafiles,
733
+ });
734
+ }
735
+ return [2 /*return*/, builtDatafiles];
736
+ }
737
+ });
738
+ });
739
+ }
740
+ function printBuildProgress(projectConfig, event) {
741
+ if (event.type === "start") {
742
+ console.log("");
743
+ console.log(cliFormat_1.CLI_FORMAT_BOLD, "Building Messagevisor datafiles");
744
+ console.log(" Starting revision: ".concat(event.previousRevision));
745
+ console.log(" Targets: ".concat(event.targets.join(", ") || "(none)"));
746
+ return;
747
+ }
748
+ if (event.type === "targetStart") {
749
+ console.log("");
750
+ console.log(cliFormat_1.CLI_FORMAT_BOLD, "Target \"".concat(event.target, "\""));
751
+ console.log(" Locales: ".concat(event.locales.join(", ") || "(none)"));
752
+ return;
753
+ }
754
+ if (event.type === "localeBuilt") {
755
+ var relativeFilePath = event.filePath
756
+ ? path.relative(process.cwd(), event.filePath)
757
+ : (0, config_1.formatDatafilePath)(projectConfig, event.target, event.locale);
758
+ var messageCount = Object.keys(event.datafile.translations).length;
759
+ var metadataCount = Object.keys(event.datafile.messages).length;
760
+ var segmentCount = Object.keys(event.datafile.segments).length;
761
+ var size = typeof event.sizeInBytes === "number" ? ", ".concat((event.sizeInBytes / 1024).toFixed(2), " kB") : "";
762
+ console.log(" \u2714 ".concat(event.locale, " -> ").concat(relativeFilePath, " (").concat(messageCount, " translations, ").concat(metadataCount, " metadata entries, ").concat(segmentCount, " segments").concat(size, ")"));
763
+ return;
764
+ }
765
+ console.log("");
766
+ console.log(cliFormat_1.CLI_FORMAT_GREEN, "Built ".concat(event.datafiles.length, " datafile(s) in ").concat(path.relative(process.cwd(), projectConfig.datafilesDirectoryPath) || projectConfig.datafilesDirectoryPath));
767
+ console.log(cliFormat_1.CLI_FORMAT_BOLD, "Revision: ".concat(event.revision));
768
+ console.log(cliFormat_1.CLI_FORMAT_BOLD, "Time: ".concat((0, prettyDuration_1.prettyDuration)(event.duration)));
769
+ }
770
+ function printProjectSetsBuildProgress(projectConfig, event) {
771
+ if (event.type === "setsStart") {
772
+ console.log("");
773
+ console.log(cliFormat_1.CLI_FORMAT_BOLD, "Building Messagevisor sets");
774
+ console.log(" Starting project revision: ".concat(event.previousRevision));
775
+ console.log(" Sets: ".concat(event.sets.join(", ") || "(none)"));
776
+ return;
777
+ }
778
+ if (event.type === "setStart") {
779
+ console.log("");
780
+ console.log(cliFormat_1.CLI_FORMAT_BOLD, "Set \"".concat(event.set, "\""));
781
+ return;
782
+ }
783
+ if (event.type === "setsComplete") {
784
+ console.log("");
785
+ console.log(cliFormat_1.CLI_FORMAT_GREEN, "Built ".concat(event.datafiles.length, " datafile(s) across ").concat(event.sets.length, " set(s) in ").concat(path.relative(process.cwd(), projectConfig.datafilesDirectoryPath) || projectConfig.datafilesDirectoryPath));
786
+ console.log(cliFormat_1.CLI_FORMAT_BOLD, "Project revision: ".concat(event.revision));
787
+ console.log(cliFormat_1.CLI_FORMAT_BOLD, "Time: ".concat((0, prettyDuration_1.prettyDuration)(event.duration)));
788
+ return;
789
+ }
790
+ printBuildProgress(projectConfig.sets
791
+ ? __assign(__assign({}, projectConfig), { datafilesDirectoryPath: path.join(projectConfig.datafilesDirectoryPath, event.set) }) : projectConfig, event);
792
+ }
793
+ exports.buildPlugin = {
794
+ command: "build",
795
+ handler: function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
796
+ var datafiles;
797
+ var projectConfig = _b.projectConfig, datasource = _b.datasource, parsed = _b.parsed;
798
+ return __generator(this, function (_c) {
799
+ switch (_c.label) {
800
+ case 0:
801
+ (0, sets_1.assertProjectSetJsonSelection)(projectConfig, parsed.set, parsed.json);
802
+ return [4 /*yield*/, buildProjectSets(projectConfig, datasource, {
803
+ set: parsed.set,
804
+ target: parsed.target,
805
+ locale: parsed.locale,
806
+ revision: parsed.revision,
807
+ noStateFiles: parsed.json || parsed.stateFiles === false,
808
+ json: parsed.json,
809
+ pretty: parsed.pretty,
810
+ showSize: parsed.showSize,
811
+ onProgress: parsed.json ? undefined : function (event) { return printBuildProgress(projectConfig, event); },
812
+ onProjectSetsProgress: parsed.json
813
+ ? undefined
814
+ : function (event) { return printProjectSetsBuildProgress(projectConfig, event); },
815
+ })];
816
+ case 1:
817
+ datafiles = _c.sent();
818
+ return [2 /*return*/];
819
+ }
820
+ });
821
+ }); },
822
+ examples: [
823
+ { command: "build", description: "build datafiles" },
824
+ {
825
+ command: "build --target=web --locale=en-US",
826
+ description: "build a single target-specific locale datafile",
827
+ },
828
+ { command: "build --showSize", description: "show datafile sizes in the build output" },
829
+ ],
830
+ };
831
+ //# sourceMappingURL=index.js.map