lingo.dev 0.94.6 → 0.95.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.
package/build/cli.mjs CHANGED
@@ -1855,42 +1855,50 @@ function createAndroidLoader() {
1855
1855
  import { parse } from "csv-parse/sync";
1856
1856
  import { stringify } from "csv-stringify/sync";
1857
1857
  import _11 from "lodash";
1858
+ function detectKeyColumnName(csvString) {
1859
+ const row = parse(csvString)[0];
1860
+ const firstColumn = row?.[0]?.trim();
1861
+ return firstColumn || "KEY";
1862
+ }
1858
1863
  function createCsvLoader() {
1864
+ return composeLoaders(_createCsvLoader(), createPullOutputCleaner());
1865
+ }
1866
+ function _createCsvLoader() {
1859
1867
  return createLoader({
1860
- async pull(locale, _input) {
1861
- const input2 = parse(_input, {
1868
+ async pull(locale, input2) {
1869
+ const keyColumnName = detectKeyColumnName(input2.split("\n").find((l) => l.length));
1870
+ const inputParsed = parse(input2, {
1862
1871
  columns: true,
1863
1872
  skip_empty_lines: true,
1864
1873
  relax_column_count_less: true
1865
1874
  });
1866
- const result = {};
1867
- _11.forEach(input2, (row) => {
1868
- const key = row.id;
1875
+ const items = {};
1876
+ _11.forEach(inputParsed, (row) => {
1877
+ const key = row[keyColumnName];
1869
1878
  if (key && row[locale] && row[locale].trim() !== "") {
1870
- result[key] = row[locale];
1879
+ items[key] = row[locale];
1871
1880
  }
1872
1881
  });
1873
- return result;
1882
+ return {
1883
+ inputParsed,
1884
+ keyColumnName,
1885
+ items
1886
+ };
1874
1887
  },
1875
- async push(locale, data, originalInput) {
1876
- const input2 = parse(originalInput || "", {
1877
- columns: true,
1878
- skip_empty_lines: true,
1879
- relax_column_count_less: true
1880
- });
1881
- const columns = input2.length > 0 ? Object.keys(input2[0]) : ["id", locale];
1888
+ async push(locale, { inputParsed, keyColumnName, items }) {
1889
+ const columns = inputParsed.length > 0 ? Object.keys(inputParsed[0]) : [keyColumnName, locale];
1882
1890
  if (!columns.includes(locale)) {
1883
1891
  columns.push(locale);
1884
1892
  }
1885
- const updatedRows = input2.map((row) => ({
1893
+ const updatedRows = inputParsed.map((row) => ({
1886
1894
  ...row,
1887
- [locale]: data[row.id] || row[locale] || ""
1895
+ [locale]: items[row[keyColumnName]] || row[locale] || ""
1888
1896
  }));
1889
- const existingKeys = new Set(input2.map((row) => row.id));
1890
- Object.entries(data).forEach(([key, value]) => {
1897
+ const existingKeys = new Set(inputParsed.map((row) => row[keyColumnName]));
1898
+ Object.entries(items).forEach(([key, value]) => {
1891
1899
  if (!existingKeys.has(key)) {
1892
1900
  const newRow = {
1893
- id: key,
1901
+ [keyColumnName]: key,
1894
1902
  ...Object.fromEntries(columns.map((column) => [column, ""]))
1895
1903
  };
1896
1904
  newRow[locale] = value;
@@ -1904,6 +1912,16 @@ function createCsvLoader() {
1904
1912
  }
1905
1913
  });
1906
1914
  }
1915
+ function createPullOutputCleaner() {
1916
+ return createLoader({
1917
+ async pull(_locale, input2) {
1918
+ return input2.items;
1919
+ },
1920
+ async push(_locale, data, _oI, _oL, pullInput) {
1921
+ return { ...pullInput, items: data };
1922
+ }
1923
+ });
1924
+ }
1907
1925
 
1908
1926
  // src/cli/loaders/html.ts
1909
1927
  import { JSDOM } from "jsdom";
@@ -7439,7 +7457,7 @@ async function renderHero2() {
7439
7457
  // package.json
7440
7458
  var package_default = {
7441
7459
  name: "lingo.dev",
7442
- version: "0.94.6",
7460
+ version: "0.95.0",
7443
7461
  description: "Lingo.dev CLI",
7444
7462
  private: false,
7445
7463
  publishConfig: {