lingo.dev 0.117.1 → 0.117.2
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.cjs +271 -138
- package/build/cli.cjs.map +1 -1
- package/build/cli.mjs +139 -6
- package/build/cli.mjs.map +1 -1
- package/package.json +3 -3
package/build/cli.mjs
CHANGED
|
@@ -2084,14 +2084,147 @@ function createYamlLoader() {
|
|
|
2084
2084
|
return YAML.parse(input2) || {};
|
|
2085
2085
|
},
|
|
2086
2086
|
async push(locale, payload, originalInput) {
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2087
|
+
if (!originalInput || !originalInput.trim()) {
|
|
2088
|
+
return YAML.stringify(payload, {
|
|
2089
|
+
lineWidth: -1,
|
|
2090
|
+
defaultKeyType: "PLAIN",
|
|
2091
|
+
defaultStringType: "PLAIN"
|
|
2092
|
+
});
|
|
2093
|
+
}
|
|
2094
|
+
try {
|
|
2095
|
+
const sourceDoc = YAML.parseDocument(originalInput);
|
|
2096
|
+
const metadata = extractQuotingMetadata(sourceDoc);
|
|
2097
|
+
const outputDoc = YAML.parseDocument(
|
|
2098
|
+
YAML.stringify(payload, {
|
|
2099
|
+
lineWidth: -1,
|
|
2100
|
+
defaultKeyType: "PLAIN"
|
|
2101
|
+
})
|
|
2102
|
+
);
|
|
2103
|
+
applyQuotingMetadata(outputDoc, metadata);
|
|
2104
|
+
return outputDoc.toString({ lineWidth: -1 });
|
|
2105
|
+
} catch (error) {
|
|
2106
|
+
console.warn("Failed to preserve YAML formatting:", error);
|
|
2107
|
+
return YAML.stringify(payload, {
|
|
2108
|
+
lineWidth: -1,
|
|
2109
|
+
defaultKeyType: getKeyType(originalInput),
|
|
2110
|
+
defaultStringType: getStringType(originalInput)
|
|
2111
|
+
});
|
|
2112
|
+
}
|
|
2092
2113
|
}
|
|
2093
2114
|
});
|
|
2094
2115
|
}
|
|
2116
|
+
function extractQuotingMetadata(doc) {
|
|
2117
|
+
const metadata = {
|
|
2118
|
+
keys: /* @__PURE__ */ new Map(),
|
|
2119
|
+
values: /* @__PURE__ */ new Map()
|
|
2120
|
+
};
|
|
2121
|
+
const root = doc.contents;
|
|
2122
|
+
if (!root) return metadata;
|
|
2123
|
+
walkAndExtract(root, [], metadata);
|
|
2124
|
+
return metadata;
|
|
2125
|
+
}
|
|
2126
|
+
function walkAndExtract(node, path19, metadata) {
|
|
2127
|
+
if (isScalar(node)) {
|
|
2128
|
+
if (node.type && node.type !== "PLAIN") {
|
|
2129
|
+
metadata.values.set(path19.join("."), node.type);
|
|
2130
|
+
}
|
|
2131
|
+
} else if (isYAMLMap(node)) {
|
|
2132
|
+
if (node.items && Array.isArray(node.items)) {
|
|
2133
|
+
for (const pair of node.items) {
|
|
2134
|
+
if (pair && pair.key) {
|
|
2135
|
+
const key = getKeyValue(pair.key);
|
|
2136
|
+
if (key !== null && key !== void 0) {
|
|
2137
|
+
const keyPath = [...path19, String(key)].join(".");
|
|
2138
|
+
if (pair.key.type && pair.key.type !== "PLAIN") {
|
|
2139
|
+
metadata.keys.set(keyPath, pair.key.type);
|
|
2140
|
+
}
|
|
2141
|
+
if (pair.value) {
|
|
2142
|
+
walkAndExtract(pair.value, [...path19, String(key)], metadata);
|
|
2143
|
+
}
|
|
2144
|
+
}
|
|
2145
|
+
}
|
|
2146
|
+
}
|
|
2147
|
+
}
|
|
2148
|
+
} else if (isYAMLSeq(node)) {
|
|
2149
|
+
if (node.items && Array.isArray(node.items)) {
|
|
2150
|
+
for (let i = 0; i < node.items.length; i++) {
|
|
2151
|
+
if (node.items[i]) {
|
|
2152
|
+
walkAndExtract(node.items[i], [...path19, String(i)], metadata);
|
|
2153
|
+
}
|
|
2154
|
+
}
|
|
2155
|
+
}
|
|
2156
|
+
}
|
|
2157
|
+
}
|
|
2158
|
+
function applyQuotingMetadata(doc, metadata) {
|
|
2159
|
+
const root = doc.contents;
|
|
2160
|
+
if (!root) return;
|
|
2161
|
+
walkAndApply(root, [], metadata);
|
|
2162
|
+
}
|
|
2163
|
+
function walkAndApply(node, path19, metadata) {
|
|
2164
|
+
if (isScalar(node)) {
|
|
2165
|
+
const pathKey = path19.join(".");
|
|
2166
|
+
const quoteType = metadata.values.get(pathKey);
|
|
2167
|
+
if (quoteType) {
|
|
2168
|
+
node.type = quoteType;
|
|
2169
|
+
}
|
|
2170
|
+
} else if (isYAMLMap(node)) {
|
|
2171
|
+
if (node.items && Array.isArray(node.items)) {
|
|
2172
|
+
for (const pair of node.items) {
|
|
2173
|
+
if (pair && pair.key) {
|
|
2174
|
+
const key = getKeyValue(pair.key);
|
|
2175
|
+
if (key !== null && key !== void 0) {
|
|
2176
|
+
const keyPath = [...path19, String(key)].join(".");
|
|
2177
|
+
const keyQuoteType = metadata.keys.get(keyPath);
|
|
2178
|
+
if (keyQuoteType) {
|
|
2179
|
+
pair.key.type = keyQuoteType;
|
|
2180
|
+
}
|
|
2181
|
+
if (pair.value) {
|
|
2182
|
+
walkAndApply(pair.value, [...path19, String(key)], metadata);
|
|
2183
|
+
}
|
|
2184
|
+
}
|
|
2185
|
+
}
|
|
2186
|
+
}
|
|
2187
|
+
}
|
|
2188
|
+
} else if (isYAMLSeq(node)) {
|
|
2189
|
+
if (node.items && Array.isArray(node.items)) {
|
|
2190
|
+
for (let i = 0; i < node.items.length; i++) {
|
|
2191
|
+
if (node.items[i]) {
|
|
2192
|
+
walkAndApply(node.items[i], [...path19, String(i)], metadata);
|
|
2193
|
+
}
|
|
2194
|
+
}
|
|
2195
|
+
}
|
|
2196
|
+
}
|
|
2197
|
+
}
|
|
2198
|
+
function isScalar(node) {
|
|
2199
|
+
if (node?.constructor?.name === "Scalar") {
|
|
2200
|
+
return true;
|
|
2201
|
+
}
|
|
2202
|
+
return node && typeof node === "object" && "value" in node && ("type" in node || "format" in node);
|
|
2203
|
+
}
|
|
2204
|
+
function isYAMLMap(node) {
|
|
2205
|
+
if (node?.constructor?.name === "YAMLMap") {
|
|
2206
|
+
return true;
|
|
2207
|
+
}
|
|
2208
|
+
return node && typeof node === "object" && "items" in node && Array.isArray(node.items) && !("value" in node);
|
|
2209
|
+
}
|
|
2210
|
+
function isYAMLSeq(node) {
|
|
2211
|
+
if (node?.constructor?.name === "YAMLSeq") {
|
|
2212
|
+
return true;
|
|
2213
|
+
}
|
|
2214
|
+
return node && typeof node === "object" && "items" in node && Array.isArray(node.items) && !("type" in node) && !("value" in node);
|
|
2215
|
+
}
|
|
2216
|
+
function getKeyValue(key) {
|
|
2217
|
+
if (key === null || key === void 0) {
|
|
2218
|
+
return null;
|
|
2219
|
+
}
|
|
2220
|
+
if (typeof key === "object" && "value" in key) {
|
|
2221
|
+
return key.value;
|
|
2222
|
+
}
|
|
2223
|
+
if (typeof key === "string" || typeof key === "number") {
|
|
2224
|
+
return key;
|
|
2225
|
+
}
|
|
2226
|
+
return null;
|
|
2227
|
+
}
|
|
2095
2228
|
function getKeyType(yamlString) {
|
|
2096
2229
|
if (yamlString) {
|
|
2097
2230
|
const lines = yamlString.split("\n");
|
|
@@ -13482,7 +13615,7 @@ async function renderHero2() {
|
|
|
13482
13615
|
// package.json
|
|
13483
13616
|
var package_default = {
|
|
13484
13617
|
name: "lingo.dev",
|
|
13485
|
-
version: "0.117.
|
|
13618
|
+
version: "0.117.2",
|
|
13486
13619
|
description: "Lingo.dev CLI",
|
|
13487
13620
|
private: false,
|
|
13488
13621
|
publishConfig: {
|