lingo.dev 0.117.1 → 0.117.3
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 +304 -138
- package/build/cli.cjs.map +1 -1
- package/build/cli.mjs +172 -6
- package/build/cli.mjs.map +1 -1
- package/package.json +3 -3
package/build/cli.mjs
CHANGED
|
@@ -2084,14 +2084,180 @@ 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 outputDoc = YAML.parseDocument(
|
|
2097
|
+
YAML.stringify(payload, {
|
|
2098
|
+
lineWidth: -1,
|
|
2099
|
+
defaultKeyType: "PLAIN"
|
|
2100
|
+
})
|
|
2101
|
+
);
|
|
2102
|
+
const isRootKeyFormat = detectRootKeyFormat(sourceDoc, outputDoc);
|
|
2103
|
+
const metadata = extractQuotingMetadata(sourceDoc, isRootKeyFormat);
|
|
2104
|
+
applyQuotingMetadata(outputDoc, metadata, isRootKeyFormat);
|
|
2105
|
+
return outputDoc.toString({ lineWidth: -1 });
|
|
2106
|
+
} catch (error) {
|
|
2107
|
+
console.warn("Failed to preserve YAML formatting:", error);
|
|
2108
|
+
return YAML.stringify(payload, {
|
|
2109
|
+
lineWidth: -1,
|
|
2110
|
+
defaultKeyType: getKeyType(originalInput),
|
|
2111
|
+
defaultStringType: getStringType(originalInput)
|
|
2112
|
+
});
|
|
2113
|
+
}
|
|
2092
2114
|
}
|
|
2093
2115
|
});
|
|
2094
2116
|
}
|
|
2117
|
+
function detectRootKeyFormat(sourceDoc, outputDoc) {
|
|
2118
|
+
const sourceRoot = sourceDoc.contents;
|
|
2119
|
+
const outputRoot = outputDoc.contents;
|
|
2120
|
+
if (!isYAMLMap(sourceRoot) || !isYAMLMap(outputRoot)) {
|
|
2121
|
+
return false;
|
|
2122
|
+
}
|
|
2123
|
+
const sourceMap = sourceRoot;
|
|
2124
|
+
const outputMap = outputRoot;
|
|
2125
|
+
if (!sourceMap.items || sourceMap.items.length !== 1 || !outputMap.items || outputMap.items.length !== 1) {
|
|
2126
|
+
return false;
|
|
2127
|
+
}
|
|
2128
|
+
const sourceRootKey = getKeyValue(sourceMap.items[0].key);
|
|
2129
|
+
const outputRootKey = getKeyValue(outputMap.items[0].key);
|
|
2130
|
+
if (sourceRootKey !== outputRootKey && typeof sourceRootKey === "string" && typeof outputRootKey === "string") {
|
|
2131
|
+
return true;
|
|
2132
|
+
}
|
|
2133
|
+
return false;
|
|
2134
|
+
}
|
|
2135
|
+
function extractQuotingMetadata(doc, skipRootKey) {
|
|
2136
|
+
const metadata = {
|
|
2137
|
+
keys: /* @__PURE__ */ new Map(),
|
|
2138
|
+
values: /* @__PURE__ */ new Map()
|
|
2139
|
+
};
|
|
2140
|
+
const root = doc.contents;
|
|
2141
|
+
if (!root) return metadata;
|
|
2142
|
+
let startNode = root;
|
|
2143
|
+
if (skipRootKey && isYAMLMap(root)) {
|
|
2144
|
+
const rootMap = root;
|
|
2145
|
+
if (rootMap.items && rootMap.items.length === 1) {
|
|
2146
|
+
startNode = rootMap.items[0].value;
|
|
2147
|
+
}
|
|
2148
|
+
}
|
|
2149
|
+
walkAndExtract(startNode, [], metadata);
|
|
2150
|
+
return metadata;
|
|
2151
|
+
}
|
|
2152
|
+
function walkAndExtract(node, path19, metadata) {
|
|
2153
|
+
if (isScalar(node)) {
|
|
2154
|
+
if (node.type && node.type !== "PLAIN") {
|
|
2155
|
+
metadata.values.set(path19.join("."), node.type);
|
|
2156
|
+
}
|
|
2157
|
+
} else if (isYAMLMap(node)) {
|
|
2158
|
+
if (node.items && Array.isArray(node.items)) {
|
|
2159
|
+
for (const pair of node.items) {
|
|
2160
|
+
if (pair && pair.key) {
|
|
2161
|
+
const key = getKeyValue(pair.key);
|
|
2162
|
+
if (key !== null && key !== void 0) {
|
|
2163
|
+
const keyPath = [...path19, String(key)].join(".");
|
|
2164
|
+
if (pair.key.type && pair.key.type !== "PLAIN") {
|
|
2165
|
+
metadata.keys.set(keyPath, pair.key.type);
|
|
2166
|
+
}
|
|
2167
|
+
if (pair.value) {
|
|
2168
|
+
walkAndExtract(pair.value, [...path19, String(key)], metadata);
|
|
2169
|
+
}
|
|
2170
|
+
}
|
|
2171
|
+
}
|
|
2172
|
+
}
|
|
2173
|
+
}
|
|
2174
|
+
} else if (isYAMLSeq(node)) {
|
|
2175
|
+
if (node.items && Array.isArray(node.items)) {
|
|
2176
|
+
for (let i = 0; i < node.items.length; i++) {
|
|
2177
|
+
if (node.items[i]) {
|
|
2178
|
+
walkAndExtract(node.items[i], [...path19, String(i)], metadata);
|
|
2179
|
+
}
|
|
2180
|
+
}
|
|
2181
|
+
}
|
|
2182
|
+
}
|
|
2183
|
+
}
|
|
2184
|
+
function applyQuotingMetadata(doc, metadata, skipRootKey) {
|
|
2185
|
+
const root = doc.contents;
|
|
2186
|
+
if (!root) return;
|
|
2187
|
+
let startNode = root;
|
|
2188
|
+
if (skipRootKey && isYAMLMap(root)) {
|
|
2189
|
+
const rootMap = root;
|
|
2190
|
+
if (rootMap.items && rootMap.items.length === 1) {
|
|
2191
|
+
startNode = rootMap.items[0].value;
|
|
2192
|
+
}
|
|
2193
|
+
}
|
|
2194
|
+
walkAndApply(startNode, [], metadata);
|
|
2195
|
+
}
|
|
2196
|
+
function walkAndApply(node, path19, metadata) {
|
|
2197
|
+
if (isScalar(node)) {
|
|
2198
|
+
const pathKey = path19.join(".");
|
|
2199
|
+
const quoteType = metadata.values.get(pathKey);
|
|
2200
|
+
if (quoteType) {
|
|
2201
|
+
node.type = quoteType;
|
|
2202
|
+
}
|
|
2203
|
+
} else if (isYAMLMap(node)) {
|
|
2204
|
+
if (node.items && Array.isArray(node.items)) {
|
|
2205
|
+
for (const pair of node.items) {
|
|
2206
|
+
if (pair && pair.key) {
|
|
2207
|
+
const key = getKeyValue(pair.key);
|
|
2208
|
+
if (key !== null && key !== void 0) {
|
|
2209
|
+
const keyPath = [...path19, String(key)].join(".");
|
|
2210
|
+
const keyQuoteType = metadata.keys.get(keyPath);
|
|
2211
|
+
if (keyQuoteType) {
|
|
2212
|
+
pair.key.type = keyQuoteType;
|
|
2213
|
+
}
|
|
2214
|
+
if (pair.value) {
|
|
2215
|
+
walkAndApply(pair.value, [...path19, String(key)], metadata);
|
|
2216
|
+
}
|
|
2217
|
+
}
|
|
2218
|
+
}
|
|
2219
|
+
}
|
|
2220
|
+
}
|
|
2221
|
+
} else if (isYAMLSeq(node)) {
|
|
2222
|
+
if (node.items && Array.isArray(node.items)) {
|
|
2223
|
+
for (let i = 0; i < node.items.length; i++) {
|
|
2224
|
+
if (node.items[i]) {
|
|
2225
|
+
walkAndApply(node.items[i], [...path19, String(i)], metadata);
|
|
2226
|
+
}
|
|
2227
|
+
}
|
|
2228
|
+
}
|
|
2229
|
+
}
|
|
2230
|
+
}
|
|
2231
|
+
function isScalar(node) {
|
|
2232
|
+
if (node?.constructor?.name === "Scalar") {
|
|
2233
|
+
return true;
|
|
2234
|
+
}
|
|
2235
|
+
return node && typeof node === "object" && "value" in node && ("type" in node || "format" in node);
|
|
2236
|
+
}
|
|
2237
|
+
function isYAMLMap(node) {
|
|
2238
|
+
if (node?.constructor?.name === "YAMLMap") {
|
|
2239
|
+
return true;
|
|
2240
|
+
}
|
|
2241
|
+
return node && typeof node === "object" && "items" in node && Array.isArray(node.items) && !("value" in node);
|
|
2242
|
+
}
|
|
2243
|
+
function isYAMLSeq(node) {
|
|
2244
|
+
if (node?.constructor?.name === "YAMLSeq") {
|
|
2245
|
+
return true;
|
|
2246
|
+
}
|
|
2247
|
+
return node && typeof node === "object" && "items" in node && Array.isArray(node.items) && !("type" in node) && !("value" in node);
|
|
2248
|
+
}
|
|
2249
|
+
function getKeyValue(key) {
|
|
2250
|
+
if (key === null || key === void 0) {
|
|
2251
|
+
return null;
|
|
2252
|
+
}
|
|
2253
|
+
if (typeof key === "object" && "value" in key) {
|
|
2254
|
+
return key.value;
|
|
2255
|
+
}
|
|
2256
|
+
if (typeof key === "string" || typeof key === "number") {
|
|
2257
|
+
return key;
|
|
2258
|
+
}
|
|
2259
|
+
return null;
|
|
2260
|
+
}
|
|
2095
2261
|
function getKeyType(yamlString) {
|
|
2096
2262
|
if (yamlString) {
|
|
2097
2263
|
const lines = yamlString.split("\n");
|
|
@@ -13482,7 +13648,7 @@ async function renderHero2() {
|
|
|
13482
13648
|
// package.json
|
|
13483
13649
|
var package_default = {
|
|
13484
13650
|
name: "lingo.dev",
|
|
13485
|
-
version: "0.117.
|
|
13651
|
+
version: "0.117.3",
|
|
13486
13652
|
description: "Lingo.dev CLI",
|
|
13487
13653
|
private: false,
|
|
13488
13654
|
publishConfig: {
|