lingo.dev 0.125.1 → 0.125.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 +150 -92
- package/build/cli.cjs.map +1 -1
- package/build/cli.mjs +180 -122
- package/build/cli.mjs.map +1 -1
- package/package.json +1 -1
package/build/cli.cjs
CHANGED
|
@@ -14,7 +14,7 @@ var _ora = require('ora'); var _ora2 = _interopRequireDefault(_ora);
|
|
|
14
14
|
|
|
15
15
|
// src/cli/utils/settings.ts
|
|
16
16
|
var _os = require('os'); var _os2 = _interopRequireDefault(_os);
|
|
17
|
-
var _path = require('path'); var path15 = _interopRequireWildcard(_path); var
|
|
17
|
+
var _path = require('path'); var path15 = _interopRequireWildcard(_path); var path17 = _interopRequireWildcard(_path);
|
|
18
18
|
var _zod = require('zod'); var _zod2 = _interopRequireDefault(_zod);
|
|
19
19
|
var _fs = require('fs'); var fs13 = _interopRequireWildcard(_fs);
|
|
20
20
|
var _ini = require('ini'); var _ini2 = _interopRequireDefault(_ini);
|
|
@@ -11200,6 +11200,134 @@ function checkIfFileExists(filePath) {
|
|
|
11200
11200
|
// src/cli/utils/delta.ts
|
|
11201
11201
|
|
|
11202
11202
|
|
|
11203
|
+
|
|
11204
|
+
// src/cli/utils/lockfile.ts
|
|
11205
|
+
|
|
11206
|
+
|
|
11207
|
+
|
|
11208
|
+
|
|
11209
|
+
|
|
11210
|
+
|
|
11211
|
+
function createLockfileHelper() {
|
|
11212
|
+
return {
|
|
11213
|
+
isLockfileExists: () => {
|
|
11214
|
+
const lockfilePath = _getLockfilePath();
|
|
11215
|
+
return fs13.default.existsSync(lockfilePath);
|
|
11216
|
+
},
|
|
11217
|
+
registerSourceData: (pathPattern, sourceData) => {
|
|
11218
|
+
const lockfile = _loadLockfile();
|
|
11219
|
+
const sectionKey = _objecthash.MD5.call(void 0, pathPattern);
|
|
11220
|
+
const sectionChecksums = _lodash2.default.mapValues(sourceData, (value) => _objecthash.MD5.call(void 0, value));
|
|
11221
|
+
lockfile.checksums[sectionKey] = sectionChecksums;
|
|
11222
|
+
_saveLockfile(lockfile);
|
|
11223
|
+
},
|
|
11224
|
+
registerPartialSourceData: (pathPattern, partialSourceData) => {
|
|
11225
|
+
const lockfile = _loadLockfile();
|
|
11226
|
+
const sectionKey = _objecthash.MD5.call(void 0, pathPattern);
|
|
11227
|
+
const sectionChecksums = _lodash2.default.mapValues(
|
|
11228
|
+
partialSourceData,
|
|
11229
|
+
(value) => _objecthash.MD5.call(void 0, value)
|
|
11230
|
+
);
|
|
11231
|
+
lockfile.checksums[sectionKey] = _lodash2.default.merge(
|
|
11232
|
+
{},
|
|
11233
|
+
_nullishCoalesce(lockfile.checksums[sectionKey], () => ( {})),
|
|
11234
|
+
sectionChecksums
|
|
11235
|
+
);
|
|
11236
|
+
_saveLockfile(lockfile);
|
|
11237
|
+
},
|
|
11238
|
+
extractUpdatedData: (pathPattern, sourceData) => {
|
|
11239
|
+
const lockfile = _loadLockfile();
|
|
11240
|
+
const sectionKey = _objecthash.MD5.call(void 0, pathPattern);
|
|
11241
|
+
const currentChecksums = _lodash2.default.mapValues(sourceData, (value) => _objecthash.MD5.call(void 0, value));
|
|
11242
|
+
const savedChecksums = lockfile.checksums[sectionKey] || {};
|
|
11243
|
+
const updatedData = _lodash2.default.pickBy(
|
|
11244
|
+
sourceData,
|
|
11245
|
+
(value, key) => savedChecksums[key] !== currentChecksums[key]
|
|
11246
|
+
);
|
|
11247
|
+
return updatedData;
|
|
11248
|
+
}
|
|
11249
|
+
};
|
|
11250
|
+
function _loadLockfile() {
|
|
11251
|
+
const lockfilePath = _getLockfilePath();
|
|
11252
|
+
if (!fs13.default.existsSync(lockfilePath)) {
|
|
11253
|
+
return LockfileSchema.parse({});
|
|
11254
|
+
}
|
|
11255
|
+
const content = fs13.default.readFileSync(lockfilePath, "utf-8");
|
|
11256
|
+
const { deduplicatedContent, duplicatesRemoved } = deduplicateLockfileYaml(content);
|
|
11257
|
+
if (duplicatesRemoved > 0) {
|
|
11258
|
+
fs13.default.writeFileSync(lockfilePath, deduplicatedContent);
|
|
11259
|
+
console.log(
|
|
11260
|
+
`Removed ${duplicatesRemoved} duplicate ${duplicatesRemoved === 1 ? "entry" : "entries"} from i18n.lock`
|
|
11261
|
+
);
|
|
11262
|
+
}
|
|
11263
|
+
const parsed = LockfileSchema.parse(_yaml2.default.parse(deduplicatedContent));
|
|
11264
|
+
return parsed;
|
|
11265
|
+
}
|
|
11266
|
+
function _saveLockfile(lockfile) {
|
|
11267
|
+
const lockfilePath = _getLockfilePath();
|
|
11268
|
+
const content = _yaml2.default.stringify(lockfile);
|
|
11269
|
+
fs13.default.writeFileSync(lockfilePath, content);
|
|
11270
|
+
}
|
|
11271
|
+
function _getLockfilePath() {
|
|
11272
|
+
return path15.default.join(process.cwd(), "i18n.lock");
|
|
11273
|
+
}
|
|
11274
|
+
}
|
|
11275
|
+
var LockfileSchema = _zod2.default.object({
|
|
11276
|
+
version: _zod2.default.literal(1).prefault(1),
|
|
11277
|
+
checksums: _zod2.default.record(
|
|
11278
|
+
_zod2.default.string(),
|
|
11279
|
+
// localizable files' keys
|
|
11280
|
+
_zod2.default.record(
|
|
11281
|
+
// checksums hashmap
|
|
11282
|
+
_zod2.default.string(),
|
|
11283
|
+
// key
|
|
11284
|
+
_zod2.default.string()
|
|
11285
|
+
// checksum of the key's value in the source locale
|
|
11286
|
+
).prefault({})
|
|
11287
|
+
).prefault({})
|
|
11288
|
+
});
|
|
11289
|
+
function deduplicateLockfileYaml(yamlContent) {
|
|
11290
|
+
const doc = _yaml2.default.parseDocument(yamlContent);
|
|
11291
|
+
let duplicatesRemoved = 0;
|
|
11292
|
+
if (doc.contents && _yaml2.default.isMap(doc.contents)) {
|
|
11293
|
+
const checksums = doc.contents.get("checksums");
|
|
11294
|
+
if (checksums && _yaml2.default.isMap(checksums)) {
|
|
11295
|
+
for (const pathItem of checksums.items) {
|
|
11296
|
+
if (_yaml2.default.isMap(pathItem.value)) {
|
|
11297
|
+
const keyPositions = /* @__PURE__ */ new Map();
|
|
11298
|
+
for (let i = 0; i < pathItem.value.items.length; i++) {
|
|
11299
|
+
const translationItem = pathItem.value.items[i];
|
|
11300
|
+
const key = String(_yaml2.default.isScalar(translationItem.key) ? translationItem.key.value : translationItem.key);
|
|
11301
|
+
if (!keyPositions.has(key)) {
|
|
11302
|
+
keyPositions.set(key, []);
|
|
11303
|
+
}
|
|
11304
|
+
keyPositions.get(key).push(i);
|
|
11305
|
+
}
|
|
11306
|
+
const indicesToRemove = [];
|
|
11307
|
+
for (const positions of keyPositions.values()) {
|
|
11308
|
+
if (positions.length > 1) {
|
|
11309
|
+
indicesToRemove.push(...positions.slice(0, -1));
|
|
11310
|
+
duplicatesRemoved += positions.length - 1;
|
|
11311
|
+
}
|
|
11312
|
+
}
|
|
11313
|
+
indicesToRemove.sort((a, b) => b - a);
|
|
11314
|
+
for (const index of indicesToRemove) {
|
|
11315
|
+
pathItem.value.items.splice(index, 1);
|
|
11316
|
+
}
|
|
11317
|
+
}
|
|
11318
|
+
}
|
|
11319
|
+
}
|
|
11320
|
+
}
|
|
11321
|
+
const cleanedData = doc.toJSON();
|
|
11322
|
+
const cleanDoc = new _yaml2.default.Document(cleanedData);
|
|
11323
|
+
const deduplicatedContent = cleanDoc.toString();
|
|
11324
|
+
return {
|
|
11325
|
+
deduplicatedContent,
|
|
11326
|
+
duplicatesRemoved
|
|
11327
|
+
};
|
|
11328
|
+
}
|
|
11329
|
+
|
|
11330
|
+
// src/cli/utils/delta.ts
|
|
11203
11331
|
var LockSchema = _zod2.default.object({
|
|
11204
11332
|
version: _zod2.default.literal(1).prefault(1),
|
|
11205
11333
|
checksums: _zod2.default.record(
|
|
@@ -11215,7 +11343,7 @@ var LockSchema = _zod2.default.object({
|
|
|
11215
11343
|
).prefault({})
|
|
11216
11344
|
});
|
|
11217
11345
|
function createDeltaProcessor(fileKey) {
|
|
11218
|
-
const lockfilePath =
|
|
11346
|
+
const lockfilePath = path17.join(process.cwd(), "i18n.lock");
|
|
11219
11347
|
return {
|
|
11220
11348
|
async checkIfLockExists() {
|
|
11221
11349
|
return checkIfFileExists(lockfilePath);
|
|
@@ -11264,12 +11392,21 @@ function createDeltaProcessor(fileKey) {
|
|
|
11264
11392
|
},
|
|
11265
11393
|
async loadLock() {
|
|
11266
11394
|
const lockfileContent = tryReadFile(lockfilePath, null);
|
|
11267
|
-
|
|
11268
|
-
|
|
11269
|
-
|
|
11270
|
-
|
|
11271
|
-
|
|
11272
|
-
|
|
11395
|
+
if (!lockfileContent) {
|
|
11396
|
+
return {
|
|
11397
|
+
version: 1,
|
|
11398
|
+
checksums: {}
|
|
11399
|
+
};
|
|
11400
|
+
}
|
|
11401
|
+
const { deduplicatedContent, duplicatesRemoved } = deduplicateLockfileYaml(lockfileContent);
|
|
11402
|
+
if (duplicatesRemoved > 0) {
|
|
11403
|
+
writeFile(lockfilePath, deduplicatedContent);
|
|
11404
|
+
console.log(
|
|
11405
|
+
`Removed ${duplicatesRemoved} duplicate ${duplicatesRemoved === 1 ? "entry" : "entries"} from i18n.lock`
|
|
11406
|
+
);
|
|
11407
|
+
}
|
|
11408
|
+
const parsed = LockSchema.parse(_yaml2.default.parse(deduplicatedContent));
|
|
11409
|
+
return parsed;
|
|
11273
11410
|
},
|
|
11274
11411
|
async saveLock(lockData) {
|
|
11275
11412
|
const lockfileYaml = _yaml2.default.stringify(lockData);
|
|
@@ -11278,12 +11415,14 @@ function createDeltaProcessor(fileKey) {
|
|
|
11278
11415
|
async loadChecksums() {
|
|
11279
11416
|
const id = md5(fileKey);
|
|
11280
11417
|
const lockfileData = await this.loadLock();
|
|
11281
|
-
|
|
11418
|
+
const checksums = lockfileData.checksums;
|
|
11419
|
+
return checksums[id] || {};
|
|
11282
11420
|
},
|
|
11283
11421
|
async saveChecksums(checksums) {
|
|
11284
11422
|
const id = md5(fileKey);
|
|
11285
11423
|
const lockfileData = await this.loadLock();
|
|
11286
|
-
|
|
11424
|
+
const lockChecksums = lockfileData.checksums;
|
|
11425
|
+
lockChecksums[id] = checksums;
|
|
11287
11426
|
await this.saveLock(lockfileData);
|
|
11288
11427
|
},
|
|
11289
11428
|
async createChecksums(sourceData) {
|
|
@@ -11971,87 +12110,6 @@ Editing value for: ${_chalk2.default.cyan(key)}`);
|
|
|
11971
12110
|
|
|
11972
12111
|
|
|
11973
12112
|
|
|
11974
|
-
// src/cli/utils/lockfile.ts
|
|
11975
|
-
|
|
11976
|
-
|
|
11977
|
-
|
|
11978
|
-
|
|
11979
|
-
|
|
11980
|
-
|
|
11981
|
-
function createLockfileHelper() {
|
|
11982
|
-
return {
|
|
11983
|
-
isLockfileExists: () => {
|
|
11984
|
-
const lockfilePath = _getLockfilePath();
|
|
11985
|
-
return fs13.default.existsSync(lockfilePath);
|
|
11986
|
-
},
|
|
11987
|
-
registerSourceData: (pathPattern, sourceData) => {
|
|
11988
|
-
const lockfile = _loadLockfile();
|
|
11989
|
-
const sectionKey = _objecthash.MD5.call(void 0, pathPattern);
|
|
11990
|
-
const sectionChecksums = _lodash2.default.mapValues(sourceData, (value) => _objecthash.MD5.call(void 0, value));
|
|
11991
|
-
lockfile.checksums[sectionKey] = sectionChecksums;
|
|
11992
|
-
_saveLockfile(lockfile);
|
|
11993
|
-
},
|
|
11994
|
-
registerPartialSourceData: (pathPattern, partialSourceData) => {
|
|
11995
|
-
const lockfile = _loadLockfile();
|
|
11996
|
-
const sectionKey = _objecthash.MD5.call(void 0, pathPattern);
|
|
11997
|
-
const sectionChecksums = _lodash2.default.mapValues(
|
|
11998
|
-
partialSourceData,
|
|
11999
|
-
(value) => _objecthash.MD5.call(void 0, value)
|
|
12000
|
-
);
|
|
12001
|
-
lockfile.checksums[sectionKey] = _lodash2.default.merge(
|
|
12002
|
-
{},
|
|
12003
|
-
_nullishCoalesce(lockfile.checksums[sectionKey], () => ( {})),
|
|
12004
|
-
sectionChecksums
|
|
12005
|
-
);
|
|
12006
|
-
_saveLockfile(lockfile);
|
|
12007
|
-
},
|
|
12008
|
-
extractUpdatedData: (pathPattern, sourceData) => {
|
|
12009
|
-
const lockfile = _loadLockfile();
|
|
12010
|
-
const sectionKey = _objecthash.MD5.call(void 0, pathPattern);
|
|
12011
|
-
const currentChecksums = _lodash2.default.mapValues(sourceData, (value) => _objecthash.MD5.call(void 0, value));
|
|
12012
|
-
const savedChecksums = lockfile.checksums[sectionKey] || {};
|
|
12013
|
-
const updatedData = _lodash2.default.pickBy(
|
|
12014
|
-
sourceData,
|
|
12015
|
-
(value, key) => savedChecksums[key] !== currentChecksums[key]
|
|
12016
|
-
);
|
|
12017
|
-
return updatedData;
|
|
12018
|
-
}
|
|
12019
|
-
};
|
|
12020
|
-
function _loadLockfile() {
|
|
12021
|
-
const lockfilePath = _getLockfilePath();
|
|
12022
|
-
if (!fs13.default.existsSync(lockfilePath)) {
|
|
12023
|
-
return LockfileSchema.parse({});
|
|
12024
|
-
}
|
|
12025
|
-
const content = fs13.default.readFileSync(lockfilePath, "utf-8");
|
|
12026
|
-
const result = LockfileSchema.parse(_yaml2.default.parse(content));
|
|
12027
|
-
return result;
|
|
12028
|
-
}
|
|
12029
|
-
function _saveLockfile(lockfile) {
|
|
12030
|
-
const lockfilePath = _getLockfilePath();
|
|
12031
|
-
const content = _yaml2.default.stringify(lockfile);
|
|
12032
|
-
fs13.default.writeFileSync(lockfilePath, content);
|
|
12033
|
-
}
|
|
12034
|
-
function _getLockfilePath() {
|
|
12035
|
-
return path15.default.join(process.cwd(), "i18n.lock");
|
|
12036
|
-
}
|
|
12037
|
-
}
|
|
12038
|
-
var LockfileSchema = _zod2.default.object({
|
|
12039
|
-
version: _zod2.default.literal(1).prefault(1),
|
|
12040
|
-
checksums: _zod2.default.record(
|
|
12041
|
-
_zod2.default.string(),
|
|
12042
|
-
// localizable files' keys
|
|
12043
|
-
_zod2.default.record(
|
|
12044
|
-
// checksums hashmap
|
|
12045
|
-
_zod2.default.string(),
|
|
12046
|
-
// key
|
|
12047
|
-
_zod2.default.string()
|
|
12048
|
-
// checksum of the key's value in the source locale
|
|
12049
|
-
).prefault({})
|
|
12050
|
-
).prefault({})
|
|
12051
|
-
});
|
|
12052
|
-
|
|
12053
|
-
// src/cli/cmd/lockfile.ts
|
|
12054
|
-
|
|
12055
12113
|
var lockfile_default = new (0, _interactivecommander.Command)().command("lockfile").description(
|
|
12056
12114
|
"Generate or refresh i18n.lock based on the current source locale content"
|
|
12057
12115
|
).helpOption("-h, --help", "Show help").option(
|
|
@@ -15192,7 +15250,7 @@ async function renderHero2() {
|
|
|
15192
15250
|
// package.json
|
|
15193
15251
|
var package_default = {
|
|
15194
15252
|
name: "lingo.dev",
|
|
15195
|
-
version: "0.125.
|
|
15253
|
+
version: "0.125.2",
|
|
15196
15254
|
description: "Lingo.dev CLI",
|
|
15197
15255
|
private: false,
|
|
15198
15256
|
repository: {
|