@ikas/component-cli 1.4.0-beta.23 → 1.4.0-beta.230

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/dist/build-tools.d.ts +37 -0
  2. package/dist/build-tools.d.ts.map +1 -0
  3. package/dist/build-tools.js +36 -0
  4. package/dist/build-tools.js.map +1 -0
  5. package/dist/commands/add-sections-to-page.d.ts +3 -0
  6. package/dist/commands/add-sections-to-page.d.ts.map +1 -0
  7. package/dist/commands/add-sections-to-page.js +39 -0
  8. package/dist/commands/add-sections-to-page.js.map +1 -0
  9. package/dist/commands/add-to-page.js +1 -1
  10. package/dist/commands/add-to-page.js.map +1 -1
  11. package/dist/commands/add.d.ts.map +1 -1
  12. package/dist/commands/add.js +11 -2
  13. package/dist/commands/add.js.map +1 -1
  14. package/dist/commands/build.d.ts.map +1 -1
  15. package/dist/commands/build.js +23 -170
  16. package/dist/commands/build.js.map +1 -1
  17. package/dist/commands/config-texts.d.ts +39 -0
  18. package/dist/commands/config-texts.d.ts.map +1 -0
  19. package/dist/commands/config-texts.js +192 -0
  20. package/dist/commands/config-texts.js.map +1 -0
  21. package/dist/commands/config.d.ts +45 -0
  22. package/dist/commands/config.d.ts.map +1 -1
  23. package/dist/commands/config.js +1205 -154
  24. package/dist/commands/config.js.map +1 -1
  25. package/dist/commands/create-design-tokens.d.ts +24 -0
  26. package/dist/commands/create-design-tokens.d.ts.map +1 -0
  27. package/dist/commands/create-design-tokens.js +388 -0
  28. package/dist/commands/create-design-tokens.js.map +1 -0
  29. package/dist/commands/create-global-variable.d.ts +3 -0
  30. package/dist/commands/create-global-variable.d.ts.map +1 -0
  31. package/dist/commands/create-global-variable.js +73 -0
  32. package/dist/commands/create-global-variable.js.map +1 -0
  33. package/dist/commands/create-page.d.ts +3 -0
  34. package/dist/commands/create-page.d.ts.map +1 -0
  35. package/dist/commands/create-page.js +31 -0
  36. package/dist/commands/create-page.js.map +1 -0
  37. package/dist/commands/delete-page.d.ts +3 -0
  38. package/dist/commands/delete-page.d.ts.map +1 -0
  39. package/dist/commands/delete-page.js +28 -0
  40. package/dist/commands/delete-page.js.map +1 -0
  41. package/dist/commands/delete-theme-globals.d.ts +4 -0
  42. package/dist/commands/delete-theme-globals.d.ts.map +1 -0
  43. package/dist/commands/delete-theme-globals.js +50 -0
  44. package/dist/commands/delete-theme-globals.js.map +1 -0
  45. package/dist/commands/dev.d.ts.map +1 -1
  46. package/dist/commands/dev.js +328 -39
  47. package/dist/commands/dev.js.map +1 -1
  48. package/dist/commands/enable-builtin-pages.d.ts +3 -0
  49. package/dist/commands/enable-builtin-pages.d.ts.map +1 -0
  50. package/dist/commands/enable-builtin-pages.js +28 -0
  51. package/dist/commands/enable-builtin-pages.js.map +1 -0
  52. package/dist/commands/get-component-props.d.ts +3 -0
  53. package/dist/commands/get-component-props.d.ts.map +1 -0
  54. package/dist/commands/get-component-props.js +32 -0
  55. package/dist/commands/get-component-props.js.map +1 -0
  56. package/dist/commands/get-page-by-type.d.ts +3 -0
  57. package/dist/commands/get-page-by-type.d.ts.map +1 -0
  58. package/dist/commands/get-page-by-type.js +25 -0
  59. package/dist/commands/get-page-by-type.js.map +1 -0
  60. package/dist/commands/get-section-values.d.ts +3 -0
  61. package/dist/commands/get-section-values.d.ts.map +1 -0
  62. package/dist/commands/get-section-values.js +43 -0
  63. package/dist/commands/get-section-values.js.map +1 -0
  64. package/dist/commands/import.js +1 -1
  65. package/dist/commands/import.js.map +1 -1
  66. package/dist/commands/list-builtin-pages.d.ts +3 -0
  67. package/dist/commands/list-builtin-pages.d.ts.map +1 -0
  68. package/dist/commands/list-builtin-pages.js +28 -0
  69. package/dist/commands/list-builtin-pages.js.map +1 -0
  70. package/dist/commands/list-entities.d.ts +3 -0
  71. package/dist/commands/list-entities.d.ts.map +1 -0
  72. package/dist/commands/list-entities.js +32 -0
  73. package/dist/commands/list-entities.js.map +1 -0
  74. package/dist/commands/list-imported.js +1 -1
  75. package/dist/commands/list-imported.js.map +1 -1
  76. package/dist/commands/list-page-sections.d.ts +3 -0
  77. package/dist/commands/list-page-sections.d.ts.map +1 -0
  78. package/dist/commands/list-page-sections.js +31 -0
  79. package/dist/commands/list-page-sections.js.map +1 -0
  80. package/dist/commands/list-pages.js +1 -1
  81. package/dist/commands/list-pages.js.map +1 -1
  82. package/dist/commands/list-theme-globals.d.ts +3 -0
  83. package/dist/commands/list-theme-globals.d.ts.map +1 -0
  84. package/dist/commands/list-theme-globals.js +22 -0
  85. package/dist/commands/list-theme-globals.js.map +1 -0
  86. package/dist/commands/list-translations.d.ts +3 -0
  87. package/dist/commands/list-translations.d.ts.map +1 -0
  88. package/dist/commands/list-translations.js +33 -0
  89. package/dist/commands/list-translations.js.map +1 -0
  90. package/dist/commands/move-page-section.d.ts +3 -0
  91. package/dist/commands/move-page-section.d.ts.map +1 -0
  92. package/dist/commands/move-page-section.js +62 -0
  93. package/dist/commands/move-page-section.js.map +1 -0
  94. package/dist/commands/publish-theme.d.ts +3 -0
  95. package/dist/commands/publish-theme.d.ts.map +1 -0
  96. package/dist/commands/publish-theme.js +29 -0
  97. package/dist/commands/publish-theme.js.map +1 -0
  98. package/dist/commands/publish.d.ts.map +1 -1
  99. package/dist/commands/publish.js +72 -3
  100. package/dist/commands/publish.js.map +1 -1
  101. package/dist/commands/remove-page-section.d.ts +3 -0
  102. package/dist/commands/remove-page-section.d.ts.map +1 -0
  103. package/dist/commands/remove-page-section.js +40 -0
  104. package/dist/commands/remove-page-section.js.map +1 -0
  105. package/dist/commands/search-products.d.ts +3 -0
  106. package/dist/commands/search-products.d.ts.map +1 -0
  107. package/dist/commands/search-products.js +40 -0
  108. package/dist/commands/search-products.js.map +1 -0
  109. package/dist/commands/translation-languages.d.ts +3 -0
  110. package/dist/commands/translation-languages.d.ts.map +1 -0
  111. package/dist/commands/translation-languages.js +43 -0
  112. package/dist/commands/translation-languages.js.map +1 -0
  113. package/dist/commands/update-builtin-page-prop.d.ts +3 -0
  114. package/dist/commands/update-builtin-page-prop.d.ts.map +1 -0
  115. package/dist/commands/update-builtin-page-prop.js +49 -0
  116. package/dist/commands/update-builtin-page-prop.js.map +1 -0
  117. package/dist/commands/update-global-variable.d.ts +3 -0
  118. package/dist/commands/update-global-variable.d.ts.map +1 -0
  119. package/dist/commands/update-global-variable.js +70 -0
  120. package/dist/commands/update-global-variable.js.map +1 -0
  121. package/dist/commands/update-page-sections.d.ts +3 -0
  122. package/dist/commands/update-page-sections.d.ts.map +1 -0
  123. package/dist/commands/update-page-sections.js +42 -0
  124. package/dist/commands/update-page-sections.js.map +1 -0
  125. package/dist/commands/update-section-prop.d.ts +3 -0
  126. package/dist/commands/update-section-prop.d.ts.map +1 -0
  127. package/dist/commands/update-section-prop.js +81 -0
  128. package/dist/commands/update-section-prop.js.map +1 -0
  129. package/dist/commands/update-translations.d.ts +3 -0
  130. package/dist/commands/update-translations.d.ts.map +1 -0
  131. package/dist/commands/update-translations.js +45 -0
  132. package/dist/commands/update-translations.js.map +1 -0
  133. package/dist/commands/upload-image.d.ts +3 -0
  134. package/dist/commands/upload-image.d.ts.map +1 -0
  135. package/dist/commands/upload-image.js +38 -0
  136. package/dist/commands/upload-image.js.map +1 -0
  137. package/dist/commands/upload-images.d.ts +3 -0
  138. package/dist/commands/upload-images.d.ts.map +1 -0
  139. package/dist/commands/upload-images.js +48 -0
  140. package/dist/commands/upload-images.js.map +1 -0
  141. package/dist/index.d.ts.map +1 -1
  142. package/dist/index.js +66 -1
  143. package/dist/index.js.map +1 -1
  144. package/dist/types.d.ts +77 -0
  145. package/dist/types.d.ts.map +1 -1
  146. package/dist/utils/archive-project.d.ts +50 -0
  147. package/dist/utils/archive-project.d.ts.map +1 -0
  148. package/dist/utils/archive-project.js +178 -0
  149. package/dist/utils/archive-project.js.map +1 -0
  150. package/dist/utils/compile.d.ts +17 -2
  151. package/dist/utils/compile.d.ts.map +1 -1
  152. package/dist/utils/compile.js +742 -109
  153. package/dist/utils/compile.js.map +1 -1
  154. package/dist/utils/component-helpers.d.ts +236 -4
  155. package/dist/utils/component-helpers.d.ts.map +1 -1
  156. package/dist/utils/component-helpers.js +656 -37
  157. package/dist/utils/component-helpers.js.map +1 -1
  158. package/dist/utils/css-import-resolver.d.ts +4 -1
  159. package/dist/utils/css-import-resolver.d.ts.map +1 -1
  160. package/dist/utils/css-import-resolver.js +9 -1
  161. package/dist/utils/css-import-resolver.js.map +1 -1
  162. package/dist/utils/dev-server-auth.d.ts +28 -0
  163. package/dist/utils/dev-server-auth.d.ts.map +1 -0
  164. package/dist/utils/dev-server-auth.js +79 -0
  165. package/dist/utils/dev-server-auth.js.map +1 -0
  166. package/dist/utils/editor-action-client.d.ts +20 -3
  167. package/dist/utils/editor-action-client.d.ts.map +1 -1
  168. package/dist/utils/editor-action-client.js +81 -19
  169. package/dist/utils/editor-action-client.js.map +1 -1
  170. package/dist/utils/esm-transform.d.ts +30 -0
  171. package/dist/utils/esm-transform.d.ts.map +1 -1
  172. package/dist/utils/esm-transform.js +169 -2
  173. package/dist/utils/esm-transform.js.map +1 -1
  174. package/dist/utils/find-component-for-file.d.ts +12 -0
  175. package/dist/utils/find-component-for-file.d.ts.map +1 -0
  176. package/dist/utils/find-component-for-file.js +24 -0
  177. package/dist/utils/find-component-for-file.js.map +1 -0
  178. package/dist/utils/forbid-deep-imports.d.ts +3 -0
  179. package/dist/utils/forbid-deep-imports.d.ts.map +1 -0
  180. package/dist/utils/forbid-deep-imports.js +54 -0
  181. package/dist/utils/forbid-deep-imports.js.map +1 -0
  182. package/dist/utils/forbid-external-packages.d.ts +26 -0
  183. package/dist/utils/forbid-external-packages.d.ts.map +1 -0
  184. package/dist/utils/forbid-external-packages.js +99 -0
  185. package/dist/utils/forbid-external-packages.js.map +1 -0
  186. package/dist/utils/i18n.d.ts +98 -0
  187. package/dist/utils/i18n.d.ts.map +1 -0
  188. package/dist/utils/i18n.js +408 -0
  189. package/dist/utils/i18n.js.map +1 -0
  190. package/dist/utils/load-image.d.ts +16 -0
  191. package/dist/utils/load-image.d.ts.map +1 -0
  192. package/dist/utils/load-image.js +50 -0
  193. package/dist/utils/load-image.js.map +1 -0
  194. package/dist/utils/storefront-t.d.ts +17 -0
  195. package/dist/utils/storefront-t.d.ts.map +1 -0
  196. package/dist/utils/storefront-t.js +187 -0
  197. package/dist/utils/storefront-t.js.map +1 -0
  198. package/dist/utils/vendor-storefront.d.ts +13 -0
  199. package/dist/utils/vendor-storefront.d.ts.map +1 -0
  200. package/dist/utils/vendor-storefront.js +91 -0
  201. package/dist/utils/vendor-storefront.js.map +1 -0
  202. package/dist/utils/websocket-server.d.ts +165 -7
  203. package/dist/utils/websocket-server.d.ts.map +1 -1
  204. package/dist/utils/websocket-server.js +326 -45
  205. package/dist/utils/websocket-server.js.map +1 -1
  206. package/package.json +19 -2
  207. package/templates/add/section.css +11 -0
  208. package/dist/commands/create.d.ts +0 -4
  209. package/dist/commands/create.d.ts.map +0 -1
  210. package/dist/commands/create.js +0 -176
  211. package/dist/commands/create.js.map +0 -1
@@ -0,0 +1,408 @@
1
+ import * as fs from "fs";
2
+ import * as path from "path";
3
+ export const I18N_DEFAULT_FILE = "default";
4
+ /** A key's segment: an identifier, so a dotted path stays plain. */
5
+ export const I18N_SEGMENT_PATTERN = /^[A-Za-z_][A-Za-z0-9_]*$/;
6
+ /** A language file's name: a language code (`en`, `pt-BR`); it becomes a path, so nothing else passes. */
7
+ const I18N_LOCALE_PATTERN = /^[a-z]{2,3}(-[A-Za-z0-9]{2,8})*$/;
8
+ const languageNames = new Intl.DisplayNames(["en"], {
9
+ type: "language",
10
+ fallback: "none",
11
+ });
12
+ /** Whether `code` names a real language (`en`, `pt-BR`; not `xx` or `en-XX`). */
13
+ export function isLanguageCode(code) {
14
+ if (!I18N_LOCALE_PATTERN.test(code))
15
+ return false;
16
+ try {
17
+ return languageNames.of(code) !== undefined;
18
+ }
19
+ catch {
20
+ return false;
21
+ }
22
+ }
23
+ /** The project's i18n folder, when its config names one. */
24
+ export function i18nDir(config, root = process.cwd()) {
25
+ return config.i18n ? path.resolve(root, config.i18n) : null;
26
+ }
27
+ /** The `{{param}}` names a text uses, as `t()` fills them (spaces inside the braces allowed). */
28
+ export function textParams(text) {
29
+ return [
30
+ ...new Set([...text.matchAll(/{{\s*([A-Za-z_][A-Za-z0-9_]*)\s*}}/g)].map((match) => match[1])),
31
+ ];
32
+ }
33
+ /** The `{{...}}`s of a text that are no param (`{{na-me}}`, `{{}}`): `t()` would show them as they are. */
34
+ export const malformedParams = (text) => (text.match(/{{.*?}}/g) ?? []).filter((match) => !/^{{\s*[A-Za-z_][A-Za-z0-9_]*\s*}}$/.test(match));
35
+ const isTree = (value) => !!value && typeof value === "object" && !Array.isArray(value);
36
+ /** A tree's texts by dotted path; what is no text or group is reported, not kept. */
37
+ export function flattenI18n(tree, errors = [], prefix = "") {
38
+ return Object.entries(tree).reduce((texts, [segment, value]) => {
39
+ const key = prefix ? `${prefix}.${segment}` : segment;
40
+ if (!I18N_SEGMENT_PATTERN.test(segment))
41
+ errors.push(`"${key}": "${segment}" must be an identifier (letters, digits, _; not starting with a digit).`);
42
+ else if (isTree(value))
43
+ Object.assign(texts, flattenI18n(value, errors, key));
44
+ else if (typeof value !== "string" || !value.trim())
45
+ errors.push(`"${key}" needs a text or a group.`);
46
+ else if (malformedParams(value).length)
47
+ errors.push(`"${key}": ${malformedParams(value).join(", ")} is no {{param}} (letters, digits, _; not starting with a digit).`);
48
+ else
49
+ texts[key] = value;
50
+ return texts;
51
+ }, {});
52
+ }
53
+ /** `tree` less the texts at `keys` (dotted paths), and less the groups left empty; the rest as it is. */
54
+ function withoutKeys(tree, keys) {
55
+ const next = JSON.parse(JSON.stringify(tree));
56
+ keys.forEach((key) => {
57
+ const segments = key.split(".");
58
+ const parents = segments
59
+ .slice(0, -1)
60
+ .reduce((chain, segment) => [...chain, chain[chain.length - 1][segment]], [next]);
61
+ delete parents[parents.length - 1][segments[segments.length - 1]];
62
+ // Groups emptied by it go too, innermost first
63
+ segments
64
+ .slice(0, -1)
65
+ .map((segment, index) => [parents[index], segment])
66
+ .reverse()
67
+ .forEach(([parent, segment]) => {
68
+ if (isTree(parent[segment]) &&
69
+ !Object.keys(parent[segment]).length)
70
+ delete parent[segment];
71
+ });
72
+ });
73
+ return next;
74
+ }
75
+ /** Texts by dotted path back into a tree, keys sorted so a written file is stable. */
76
+ export function unflattenI18n(texts) {
77
+ const tree = {};
78
+ Object.keys(texts)
79
+ .sort()
80
+ .forEach((key) => {
81
+ const segments = key.split(".");
82
+ const parent = segments
83
+ .slice(0, -1)
84
+ .reduce((node, segment) => (node[segment] ??= {}), tree);
85
+ parent[segments[segments.length - 1]] = texts[key];
86
+ });
87
+ return tree;
88
+ }
89
+ // The same rules as editor-core's `code-component-i18n.ts` (a language's texts in the editor): keep them alike.
90
+ /** The plural forms a key ends in (`cart.itemCount_one`), as `Intl.PluralRules` names them; `t(key, { count })` picks one. */
91
+ const PLURAL_FORM = /^(.+)_(zero|one|two|few|many|other)$/;
92
+ const pluralFormsByLocale = new Map();
93
+ /** The plural forms `locale`'s rules use (`Intl.PluralRules`). */
94
+ function pluralForms(locale) {
95
+ if (!pluralFormsByLocale.has(locale)) {
96
+ let forms = [];
97
+ try {
98
+ forms = new Intl.PluralRules(locale).resolvedOptions().pluralCategories;
99
+ }
100
+ catch {
101
+ // Not a language code: no plural forms of its own
102
+ }
103
+ pluralFormsByLocale.set(locale, forms);
104
+ }
105
+ return pluralFormsByLocale.get(locale);
106
+ }
107
+ /** A plural key's stem and form (`cart.itemCount`, `few`): the base holds its `_other` form, not itself. */
108
+ function pluralForm(base, key) {
109
+ const [, stem, form] = key.match(PLURAL_FORM) ?? [];
110
+ return stem && `${stem}_other` in base && !(stem in base)
111
+ ? [stem, form]
112
+ : undefined;
113
+ }
114
+ /**
115
+ * The base text whose `{{param}}`s a text in `locale` keeps: its key's, or for a plural form `locale`'s rules use that
116
+ * the base lacks (Russian's `cart.itemCount_few` of an English base), the key's `_other` form. `undefined`: no text of
117
+ * that language.
118
+ */
119
+ export function localeBaseText(base, key, locale) {
120
+ if (key in base)
121
+ return base[key];
122
+ const [stem, form] = pluralForm(base, key) ?? [];
123
+ // `_zero` is every language's (an optional form): `t()` takes it for a count of 0
124
+ return stem && (form === "zero" || pluralForms(locale).includes(form))
125
+ ? base[`${stem}_other`]
126
+ : undefined;
127
+ }
128
+ /** A language's keys: the base's, then the plural forms its rules use that the base lacks (Russian's `_few`). */
129
+ export function localeKeys(base, locale) {
130
+ const forms = pluralForms(locale);
131
+ const added = Object.keys(pluralKeys(base)).flatMap((stem) => forms.map((form) => `${stem}_${form}`).filter((key) => !(key in base)));
132
+ return [...Object.keys(base), ...added];
133
+ }
134
+ /**
135
+ * What is wrong with a language's texts against the base: a key that is no text of the language (`localeBaseText`),
136
+ * or one whose `{{param}}`s differ from the base text's (`t()` passes the base's). Returns the valid texts too.
137
+ */
138
+ export function checkLocaleTexts(base, texts, locale) {
139
+ const errors = [];
140
+ const valid = {};
141
+ Object.entries(texts).forEach(([key, text]) => {
142
+ const baseText = localeBaseText(base, key, locale);
143
+ if (baseText === undefined)
144
+ return errors.push(`${locale}.json "${key}": not in ${I18N_DEFAULT_FILE}.json${PLURAL_FORM.test(key) ? ` (a plural form needs the key's _other form there, and a form ${locale}'s plural rules use: ${["zero", ...pluralForms(locale)].join(", ")})` : ""}.`);
145
+ const expected = textParams(baseText).sort().join(", ");
146
+ const actual = textParams(text).sort().join(", ");
147
+ if (actual !== expected)
148
+ return errors.push(`${locale}.json "${key}": uses {{${actual || "-"}}}, the base text {{${expected || "-"}}}.`);
149
+ valid[key] = text;
150
+ });
151
+ return { valid, errors };
152
+ }
153
+ /**
154
+ * Reads the i18n folder. A file that is no valid JSON is reported and left out (`unreadable`: the caller keeps what
155
+ * it had); texts that break the rules are reported and left out, so the editor and the store get only valid ones.
156
+ */
157
+ export function readI18n(dir) {
158
+ const errors = [];
159
+ const unreadable = [];
160
+ const read = (file) => {
161
+ try {
162
+ const value = JSON.parse(fs.readFileSync(path.join(dir, file), "utf-8"));
163
+ if (isTree(value))
164
+ return value;
165
+ errors.push(`${file}: must hold an object of texts and groups.`);
166
+ }
167
+ catch (e) {
168
+ errors.push(`${file}: ${e.message}`);
169
+ }
170
+ unreadable.push(file);
171
+ return null;
172
+ };
173
+ const files = fs.existsSync(dir)
174
+ ? fs.readdirSync(dir).filter((file) => file.endsWith(".json"))
175
+ : [];
176
+ const defaultFile = `${I18N_DEFAULT_FILE}.json`;
177
+ if (!files.includes(defaultFile) && files.length > 0)
178
+ errors.push(`${defaultFile} is missing: the languages' texts need base texts.`);
179
+ const base = files.includes(defaultFile)
180
+ ? flattenI18n(read(defaultFile) ?? {}, errors)
181
+ : {};
182
+ const locales = {};
183
+ files
184
+ .filter((file) => file !== defaultFile)
185
+ .forEach((file) => {
186
+ const locale = file.slice(0, -".json".length);
187
+ if (!isLanguageCode(locale))
188
+ return errors.push(`${file}: the name must be a language code (en, de, pt-BR).`);
189
+ const tree = read(file);
190
+ if (!tree)
191
+ return;
192
+ const checked = checkLocaleTexts(base, flattenI18n(tree, errors), locale);
193
+ errors.push(...checked.errors);
194
+ locales[locale] = checked.valid;
195
+ });
196
+ return { base, locales, errors, unreadable };
197
+ }
198
+ /** The types file written next to the texts: what `import { t } from "@ikas/bp-storefront"` takes. */
199
+ export const I18N_TYPES_FILE = "index.d.ts";
200
+ const AUTO_GENERATED = `// This file is auto-generated from ${I18N_DEFAULT_FILE}.json — do not edit manually.`;
201
+ /**
202
+ * The plural keys of the base texts: a key with an `_other` form, mapped to its forms (`cart.itemCount` →
203
+ * `cart.itemCount_one`, `cart.itemCount_other`). A key the base holds as a text of its own is no plural key.
204
+ */
205
+ export function pluralKeys(base) {
206
+ const keys = {};
207
+ Object.keys(base).forEach((key) => {
208
+ const stem = pluralForm(base, key)?.[0];
209
+ if (stem)
210
+ (keys[stem] ??= []).push(key);
211
+ });
212
+ return keys;
213
+ }
214
+ /**
215
+ * The generated `<dir>/index.d.ts`: types only. It fills `UiTexts` of `@ikas/bp-storefront` with the base texts, so
216
+ * its `t` takes only the project's keys and their `{{param}}`s; the build binds that `t` to the project's texts. A
217
+ * plural key (`pluralKeys`) is typed too, with its forms' params and `count`.
218
+ */
219
+ export function generateI18nTypes(base) {
220
+ const plural = Object.entries(pluralKeys(base)).map(([key, forms]) => {
221
+ const text = forms.map((form) => base[form]).join(" | ");
222
+ return [
223
+ key,
224
+ textParams(text).includes("count") ? text : `${text} {{count}}`,
225
+ ];
226
+ });
227
+ const entries = [...Object.entries(base), ...plural]
228
+ .sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))
229
+ .map(([key, text]) => ` ${JSON.stringify(key)}: ${JSON.stringify(text)};`)
230
+ .join("\n");
231
+ return `${AUTO_GENERATED}
232
+ // Types the keys and {{params}} of \`import { t } from "@ikas/bp-storefront"\`.
233
+ declare module "@ikas/bp-storefront" {
234
+ interface UiTexts {
235
+ ${entries}
236
+ }
237
+ }
238
+
239
+ export {};
240
+ `;
241
+ }
242
+ /**
243
+ * The `t` the build gives for `import { t } from "@ikas/bp-storefront"` (never written to the project): the store
244
+ * language's text of the project's `key`, else its base text, else the key (`ikas:<key>`: the store's common text, else
245
+ * the key); its `{{param}}`s filled in one pass. A numeric `count` first picks the key's plural form as i18next does:
246
+ * `key_zero` for 0, the form the store language's rules name (`Intl.PluralRules`: `key_one`, `key_few`, …), `key_other`.
247
+ */
248
+ export function generateI18nRuntime(projectId, base) {
249
+ return `import { I18n } from "@ikas/bp-storefront";
250
+ const texts = ${JSON.stringify(base)};
251
+ const rules = {};
252
+ // The store language's plural form of a count; "other" for a language Intl does not know
253
+ function pluralForm(count) {
254
+ try {
255
+ const locale = I18n.getLocale() || "en";
256
+ return (rules[locale] || (rules[locale] = new Intl.PluralRules(locale))).select(count);
257
+ } catch (error) {
258
+ return "other";
259
+ }
260
+ }
261
+ // The store language's text of a key, else its base text
262
+ function text(key) {
263
+ // ikas:<key>: the store's common texts (a project key never holds ":")
264
+ const store = key.startsWith("ikas:");
265
+ const path = store ? key.slice(5) : ${JSON.stringify(`cc.${projectId}.`)} + key;
266
+ const found = I18n.translate(path);
267
+ return found !== path ? found : store ? undefined : texts[key];
268
+ }
269
+ export function t(key, params) {
270
+ const values = params || {};
271
+ const count = values.count;
272
+ const keys =
273
+ typeof count === "number"
274
+ ? [...(count === 0 ? [key + "_zero"] : []), key + "_" + pluralForm(count), key + "_other", key]
275
+ : [key];
276
+ // The first key with a text: no lookups past it
277
+ let found;
278
+ for (const candidate of keys) if ((found = text(candidate)) !== undefined) break;
279
+ // In one pass: a value holding {{...}} is put in as it is
280
+ return (found ?? key).replace(/{{\\s*([A-Za-z_][A-Za-z0-9_]*)\\s*}}/g, (match, name) =>
281
+ name in values ? String(values[name]) : match,
282
+ );
283
+ }
284
+ `;
285
+ }
286
+ /** Writes a file when its content changed: an unchanged write would wake the watcher for nothing. */
287
+ export function writeIfChanged(filePath, content) {
288
+ try {
289
+ if (fs.readFileSync(filePath, "utf-8") === content)
290
+ return false;
291
+ }
292
+ catch {
293
+ // Not there yet
294
+ }
295
+ fs.mkdirSync(path.dirname(filePath), { recursive: true });
296
+ fs.writeFileSync(filePath, content);
297
+ return true;
298
+ }
299
+ /** Writes a language's texts (`default` for the base), sorted; no texts left removes a language's file. */
300
+ export function writeI18nFile(dir, locale, texts) {
301
+ if (locale !== I18N_DEFAULT_FILE && !isLanguageCode(locale))
302
+ throw new Error(`"${locale}" is not a language code.`);
303
+ const filePath = path.join(dir, `${locale}.json`);
304
+ if (locale !== I18N_DEFAULT_FILE && Object.keys(texts).length === 0) {
305
+ if (!fs.existsSync(filePath))
306
+ return false;
307
+ fs.rmSync(filePath);
308
+ return true;
309
+ }
310
+ return writeIfChanged(filePath, JSON.stringify(unflattenI18n(texts), null, 2) + "\n");
311
+ }
312
+ /**
313
+ * Reads the project's texts for the editor and writes the generated `index.d.ts`; `null` when the config names no
314
+ * folder. Problems are returned to be shown; a file that cannot be read keeps `previous`'s texts.
315
+ */
316
+ export function loadProjectI18n(config, previous, root = process.cwd()) {
317
+ const dir = i18nDir(config, root);
318
+ if (!config.projectId)
319
+ return { data: undefined, errors: [] };
320
+ // No folder: no texts (the editor drops the ones it had)
321
+ if (!dir)
322
+ return {
323
+ data: { projectId: config.projectId, base: {}, locales: {} },
324
+ errors: [],
325
+ };
326
+ const read = readI18n(dir);
327
+ const keep = (file) => read.unreadable.includes(file);
328
+ // The languages are checked against the base: without it, everything stays as it was
329
+ if (keep(`${I18N_DEFAULT_FILE}.json`))
330
+ return { data: previous, errors: read.errors };
331
+ const base = read.base;
332
+ const locales = Object.fromEntries(Object.entries(read.locales).map(([locale, texts]) => [
333
+ locale,
334
+ unflattenI18n(texts),
335
+ ]));
336
+ Object.entries(previous?.locales ?? {}).forEach(([locale, tree]) => {
337
+ if (keep(`${locale}.json`))
338
+ locales[locale] = tree;
339
+ });
340
+ writeIfChanged(path.join(dir, I18N_TYPES_FILE), generateI18nTypes(base));
341
+ // The module earlier versions generated: its t now comes from the build (see \`storefrontTPlugin\`)
342
+ const legacyModule = path.join(dir, "index.ts");
343
+ if (fs.existsSync(legacyModule) &&
344
+ fs.readFileSync(legacyModule, "utf-8").startsWith(AUTO_GENERATED))
345
+ fs.rmSync(legacyModule);
346
+ return {
347
+ data: {
348
+ projectId: config.projectId,
349
+ base: unflattenI18n(base),
350
+ // Sorted: a kept file must not change the order, and with it the texts' hash
351
+ locales: Object.fromEntries(Object.keys(locales)
352
+ .sort()
353
+ .map((locale) => [locale, locales[locale]])),
354
+ },
355
+ errors: read.errors,
356
+ };
357
+ }
358
+ /**
359
+ * Writes the texts the editor saved (the base ones and the sent languages', nested) to the i18n folder: only a file
360
+ * whose texts changed is rewritten, a language with no texts left loses its file. Refused whole when one breaks the
361
+ * rules, so the files never hold what the editor would not show.
362
+ */
363
+ export function writeEditorI18n(config, texts, root = process.cwd()) {
364
+ const dir = i18nDir(config, root);
365
+ if (!dir)
366
+ throw new Error("The project has no UI texts folder (config i18n).");
367
+ const errors = [];
368
+ const base = flattenI18n(texts.base, errors);
369
+ const locales = Object.entries(texts.locales).map(([locale, tree]) => {
370
+ if (!isLanguageCode(locale))
371
+ errors.push(`"${locale}" is not a language code.`);
372
+ const checked = checkLocaleTexts(base, flattenI18n(tree, errors), locale);
373
+ errors.push(...checked.errors);
374
+ return [locale, checked.valid];
375
+ });
376
+ // A language the editor did not send keeps its file as it is, less the texts the base no longer has (as
377
+ // remove-text drops them); a file it cannot read is left alone, its problems are the dev server's to show
378
+ const unsent = (fs.existsSync(dir) ? fs.readdirSync(dir) : [])
379
+ .filter((file) => file.endsWith(".json"))
380
+ .map((file) => file.slice(0, -".json".length))
381
+ .filter((locale) => isLanguageCode(locale) && !(locale in texts.locales))
382
+ .flatMap((locale) => {
383
+ let tree;
384
+ try {
385
+ tree = JSON.parse(fs.readFileSync(path.join(dir, `${locale}.json`), "utf-8"));
386
+ }
387
+ catch {
388
+ return [];
389
+ }
390
+ if (!isTree(tree))
391
+ return [];
392
+ const removed = Object.keys(flattenI18n(tree)).filter((key) => localeBaseText(base, key, locale) === undefined);
393
+ return removed.length
394
+ ? [[locale, withoutKeys(tree, removed)]]
395
+ : [];
396
+ });
397
+ if (errors.length)
398
+ throw new Error(errors.join(" "));
399
+ const written = [
400
+ ...(writeI18nFile(dir, I18N_DEFAULT_FILE, base) ? [I18N_DEFAULT_FILE] : []),
401
+ ...locales.flatMap(([locale, localeTexts]) => writeI18nFile(dir, locale, localeTexts) ? [locale] : []),
402
+ ...unsent.flatMap(([locale, tree]) => writeIfChanged(path.join(dir, `${locale}.json`), JSON.stringify(tree, null, 2) + "\n")
403
+ ? [locale]
404
+ : []),
405
+ ];
406
+ return written;
407
+ }
408
+ //# sourceMappingURL=i18n.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"i18n.js","sourceRoot":"","sources":["../../src/utils/i18n.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM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AO,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,EAAE,WAAW,CAAC,EAAE,EAAE,CAC3C,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,CACxD;QACD,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,EAAE,IAAI,CAAC,EAAE,EAAE,CACnC,cAAc,CACZ,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,MAAM,OAAO,CAAC,EAChC,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,GAAG,IAAI,CACrC;YACC,CAAC,CAAC,CAAC,MAAM,CAAC;YACV,CAAC,CAAC,EAAE,CACP;KACF,CAAC;IACF,OAAO,OAAO,CAAC;AACjB,CAAC"}
@@ -0,0 +1,16 @@
1
+ export declare const VALID_IMAGE_TYPES: string[];
2
+ export interface ImageSource {
3
+ file?: string;
4
+ url?: string;
5
+ }
6
+ export interface LoadedImage {
7
+ base64: string;
8
+ mimeType: string;
9
+ fileName: string;
10
+ }
11
+ /**
12
+ * Read an image from a local file path or URL and return its base64 (raw, no
13
+ * data: prefix), mime type, and a file name. Validates type and the 10MB limit.
14
+ */
15
+ export declare function loadImageSource(src: ImageSource): Promise<LoadedImage>;
16
+ //# sourceMappingURL=load-image.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"load-image.d.ts","sourceRoot":"","sources":["../../src/utils/load-image.ts"],"names":[],"mappings":"AAWA,eAAO,MAAM,iBAAiB,UAA6B,CAAC;AAG5D,MAAM,WAAW,WAAW;IAC1B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;;GAGG;AACH,wBAAsB,eAAe,CAAC,GAAG,EAAE,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,CAsC5E"}
@@ -0,0 +1,50 @@
1
+ import { readFile } from "node:fs/promises";
2
+ import { basename, extname } from "node:path";
3
+ const MIME_BY_EXT = {
4
+ ".png": "image/png",
5
+ ".jpg": "image/jpeg",
6
+ ".jpeg": "image/jpeg",
7
+ ".webp": "image/webp",
8
+ ".gif": "image/gif",
9
+ };
10
+ export const VALID_IMAGE_TYPES = Object.values(MIME_BY_EXT);
11
+ const MAX_SIZE_BYTES = 10 * 1024 * 1024; // 10MB, mirrors the editor's IMAGE_UPLOAD_LIMIT_SIZE
12
+ /**
13
+ * Read an image from a local file path or URL and return its base64 (raw, no
14
+ * data: prefix), mime type, and a file name. Validates type and the 10MB limit.
15
+ */
16
+ export async function loadImageSource(src) {
17
+ if (src.file && src.url) {
18
+ throw new Error("Provide only one of file or url, not both");
19
+ }
20
+ if (src.file) {
21
+ const buffer = await readFile(src.file);
22
+ const ext = extname(src.file).toLowerCase();
23
+ const mimeType = MIME_BY_EXT[ext];
24
+ if (!mimeType) {
25
+ throw new Error(`Unsupported image extension "${ext || "(none)"}" for ${src.file}. Supported: ${Object.keys(MIME_BY_EXT).join(", ")}`);
26
+ }
27
+ if (buffer.byteLength > MAX_SIZE_BYTES) {
28
+ throw new Error(`${src.file} is ${(buffer.byteLength / 1024 / 1024).toFixed(1)}MB; the limit is 10MB`);
29
+ }
30
+ return { base64: buffer.toString("base64"), mimeType, fileName: basename(src.file) };
31
+ }
32
+ if (src.url) {
33
+ const res = await fetch(src.url);
34
+ if (!res.ok) {
35
+ throw new Error(`Failed to fetch ${src.url}: ${res.status} ${res.statusText}`);
36
+ }
37
+ const mimeType = (res.headers.get("content-type") || "").split(";")[0].trim();
38
+ if (!VALID_IMAGE_TYPES.includes(mimeType)) {
39
+ throw new Error(`${src.url} returned content-type "${mimeType || "(none)"}". Supported: ${VALID_IMAGE_TYPES.join(", ")}`);
40
+ }
41
+ const buffer = Buffer.from(await res.arrayBuffer());
42
+ if (buffer.byteLength > MAX_SIZE_BYTES) {
43
+ throw new Error(`${src.url} is ${(buffer.byteLength / 1024 / 1024).toFixed(1)}MB; the limit is 10MB`);
44
+ }
45
+ const urlName = basename(new URL(src.url).pathname) || "image";
46
+ return { base64: buffer.toString("base64"), mimeType, fileName: urlName };
47
+ }
48
+ throw new Error("Provide a file path or url");
49
+ }
50
+ //# sourceMappingURL=load-image.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"load-image.js","sourceRoot":"","sources":["../../src/utils/load-image.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAE9C,MAAM,WAAW,GAA2B;IAC1C,MAAM,EAAE,WAAW;IACnB,MAAM,EAAE,YAAY;IACpB,OAAO,EAAE,YAAY;IACrB,OAAO,EAAE,YAAY;IACrB,MAAM,EAAE,WAAW;CACpB,CAAC;AAEF,MAAM,CAAC,MAAM,iBAAiB,GAAG,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;AAC5D,MAAM,cAAc,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC,CAAC,qDAAqD;AAa9F;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,GAAgB;IACpD,IAAI,GAAG,CAAC,IAAI,IAAI,GAAG,CAAC,GAAG,EAAE,CAAC;QACxB,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;IAC/D,CAAC;IAED,IAAI,GAAG,CAAC,IAAI,EAAE,CAAC;QACb,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACxC,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,CAAC;QAC5C,MAAM,Q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G,CAAC,GAAG,2BAA2B,QAAQ,IAAI,QAAQ,iBAAiB,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAC5H,CAAC;QACD,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,WAAW,EAAE,CAAC,CAAC;QACpD,IAAI,MAAM,CAAC,UAAU,GAAG,cAAc,EAAE,CAAC;YACvC,MAAM,IAAI,KAAK,CAAC,GAAG,GAAG,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,UAAU,GAAG,IAAI,GAAG,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,uBAAuB,CAAC,CAAC;QACxG,CAAC;QACD,MAAM,OAAO,GAAG,QAAQ,CAAC,IAAI,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,IAAI,OAAO,CAAC;QAC/D,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC;IAC5E,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;AAChD,CAAC"}
@@ -0,0 +1,17 @@
1
+ import type { Plugin } from "esbuild";
2
+ import type * as TS from "typescript";
3
+ /**
4
+ * `source` with `t` imported from the project's UI texts module (`i18nModule`) in place of `@ikas/bp-storefront`,
5
+ * whose shared runtime has no `t`: each project reads its own texts. The other imports stay as they are, on the
6
+ * same lines. `null`: nothing to change. Throws on a form that would read `t` from the shared runtime.
7
+ */
8
+ export declare function rewriteStorefrontT(ts: typeof TS, source: string, fileName: string, i18nModule: string | null): string | null;
9
+ /** The module the build gives `t` from: the project's texts and their `t`, made from its i18n files. */
10
+ export declare const UI_TEXTS_MODULE = "@ikas/component-utils/ui-texts";
11
+ /**
12
+ * Binds `import { t } from "@ikas/bp-storefront"` to a `t` reading the project's own UI texts, made from its i18n
13
+ * files (`UI_TEXTS_MODULE`, never written to the project): the storefront runtime is shared by every project on a
14
+ * store, so a `t` there could not tell whose text a key is. The generated `index.d.ts` types that `t`.
15
+ */
16
+ export declare function storefrontTPlugin(root?: string): Plugin;
17
+ //# sourceMappingURL=storefront-t.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storefront-t.d.ts","sourceRoot":"","sources":["../../src/utils/storefront-t.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAU,MAAM,EAAE,MAAM,SAAS,CAAC;AAI9C,OAAO,KAAK,KAAK,EAAE,MAAM,YAAY,CAAC;AAuCtC;;;;GAIG;AACH,wBAAgB,kBAAkB,CAChC,EAAE,EAAE,OAAO,EAAE,EACb,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,GAAG,IAAI,GACxB,MAAM,GAAG,IAAI,CAyIf;AAED,wGAAwG;AAExG,eAAO,MAAM,eAAe,mCAAmC,CAAC;AAEhE;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,SAAgB,GAAG,MAAM,CA0D9D"}