@uxf/scripts 10.0.0-beta.57 → 10.0.0-beta.75

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uxf/scripts",
3
- "version": "10.0.0-beta.57",
3
+ "version": "10.0.0-beta.75",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -9,18 +9,21 @@ module.exports = async () => {
9
9
  })
10
10
  .option("i", { alias: "include", array: true, default: [] })
11
11
  .option("o", { alias: "output", default: "i18n-pages.json" })
12
+ .option("n", { alias: "defaultNamespace", array: true, default: ["common"] })
13
+ .option("p", { alias: "pagesDirectory", default: "src/pages" })
14
+ .option("e", { alias: "fileExtension", array: true, default: ["ts", "tsx"] })
12
15
  .option("h", { alias: "help" })
13
16
  .strict(false)
14
17
  .exitProcess(false);
15
18
 
16
19
  try {
17
- const { help, include, output } = cli.parse(argv.slice(2));
20
+ const { help, include, output, defaultNamespace, pagesDirectory, fileExtension } = cli.parse(argv.slice(2));
18
21
 
19
22
  if (Boolean(help)) {
20
23
  return 0;
21
24
  }
22
25
 
23
- await require("./index")(include, output);
26
+ await require("./index")(include, output, defaultNamespace, pagesDirectory, fileExtension);
24
27
  } catch (e) {
25
28
  console.error(e);
26
29
  return 1;
@@ -7,16 +7,9 @@ const { findTFunctionNamespaces } = require("./utils/find-t-function-namespaces"
7
7
  const { findTransComponentNamespaces } = require("./utils/find-trans-component-namespaces");
8
8
  const join = require("node:path").join;
9
9
 
10
- const INCLUDE = ["src"];
11
- const EXCLUDE = [];
12
-
13
- const FILE_EXTENSIONS = ["ts", "tsx"];
14
-
15
10
  const TS_CONFIG_PATH = path.resolve(process.cwd(), "tsconfig.json");
16
11
  const TS_CONFIG = fs.existsSync(TS_CONFIG_PATH) ? TS_CONFIG_PATH : undefined;
17
12
 
18
- const result = { "*": ["common"] };
19
-
20
13
  function removeTrailingSlash(str) {
21
14
  return str.replace(/\/$/, "");
22
15
  }
@@ -71,17 +64,25 @@ const filePathToRoute = (filePath) => {
71
64
  return removeTrailingSlash(route);
72
65
  };
73
66
 
74
- function main(includes, output) {
67
+ /**
68
+ * @param include string[]
69
+ * @param output string
70
+ * @param defaultNamespaces string[]
71
+ * @param pagesDirectory string
72
+ * @param fileExtensions string[]
73
+ */
74
+ function main(include, output, defaultNamespaces, pagesDirectory, fileExtensions) {
75
+ const result = { "*": defaultNamespaces };
75
76
  // Negative lookahead – ignore searching for any files
76
77
  // that aren't part of our include list
77
- const searchDirs = new RegExp(`^(?!(${[...INCLUDE, includes].join("|")}))`, "i");
78
+ const searchDirs = new RegExp(`^(?!(${include.join("|")}))`, "i");
78
79
 
79
- const pages = walk("src/pages").flat(Number.POSITIVE_INFINITY);
80
+ const pages = walk(pagesDirectory).flat(Number.POSITIVE_INFINITY);
80
81
 
81
82
  madge(process.cwd(), {
82
83
  tsConfig: TS_CONFIG,
83
- excludeRegExp: [searchDirs, ...EXCLUDE],
84
- fileExtensions: FILE_EXTENSIONS,
84
+ excludeRegExp: [searchDirs],
85
+ fileExtensions: fileExtensions,
85
86
  }).then((res) => {
86
87
  const tree = res.obj();
87
88
 
@@ -1,15 +1,11 @@
1
1
  function findTFunctionNamespaces(pageContent) {
2
- const regex = /\bt\("([a-z0-9\-]+):([a-z0-9\-\.]+)"/g;
2
+ const regex = /\bt\("([a-zA-Z0-9\-]+):([a-zA-Z0-9\-\.]+)"/g;
3
3
  const matches = pageContent.matchAll(regex);
4
4
  const namespaces = new Set();
5
5
 
6
6
  for (const match of matches) {
7
- const translationKey = match[0];
8
- const separatorIndex = translationKey.indexOf(":");
9
- if (separatorIndex !== -1) {
10
- const namespace = translationKey.substring(3, separatorIndex);
11
- namespaces.add(namespace);
12
- }
7
+ const namespace = match[1];
8
+ namespaces.add(namespace);
13
9
  }
14
10
 
15
11
  return Array.from(namespaces);
@@ -4,6 +4,8 @@ const content = `
4
4
  <div>
5
5
  <div>
6
6
  {t("basic:title")}
7
+ {t("basic-dash:title-dash")}
8
+ {t("basicCamel:titleCamel")}
7
9
  </div>
8
10
  <div title={
9
11
  condition
@@ -20,6 +22,8 @@ describe("find namespaces in t functions", function () {
20
22
  it("should find namespaces", function () {
21
23
  expect(findTFunctionNamespaces(content)).toStrictEqual([
22
24
  "basic",
25
+ "basic-dash",
26
+ "basicCamel",
23
27
  "multiline-with-parameters",
24
28
  "with-parameters",
25
29
  "in-translation-parameter",
@@ -1,15 +1,11 @@
1
1
  function findTransComponentNamespaces(pageContent) {
2
- const regex = /<Trans[^>]*?i18nKey=(['"])(.*?)\1[^>]*\/>/g;
2
+ const regex = /<Trans[^>]*?i18nKey="([a-zA-Z0-9\-]+):([a-zA-Z0-9\-\.]+)"/g;
3
3
  const matches = pageContent.matchAll(regex);
4
4
  const namespaces = new Set();
5
5
 
6
6
  for (const match of matches) {
7
- const [, , translationKey] = match;
8
- const separatorIndex = translationKey.indexOf(":");
9
- if (separatorIndex !== -1) {
10
- const namespace = translationKey.substring(0, separatorIndex);
11
- namespaces.add(namespace);
12
- }
7
+ const namespace = match[1];
8
+ namespaces.add(namespace);
13
9
  }
14
10
 
15
11
  return Array.from(namespaces);
@@ -3,11 +3,13 @@ const { findTransComponentNamespaces } = require("./find-trans-component-namespa
3
3
  const content = `
4
4
  <div>
5
5
  <Trans i18nKey="basic:title" />
6
+ <Trans i18nKey="basic-dash:title-dash" />
7
+ <Trans i18nKey="basicCamel:titleCamel" />
6
8
  </div>
7
9
  `;
8
10
 
9
11
  describe("find namespaces in trans component", function () {
10
12
  it("should find namespaces", function () {
11
- expect(findTransComponentNamespaces(content)).toStrictEqual(["basic"]);
13
+ expect(findTransComponentNamespaces(content)).toStrictEqual(["basic", "basic-dash", "basicCamel"]);
12
14
  });
13
15
  });