MCPcopy
hub / github.com/lingodotdev/lingo.dev / createLockfileHelper

Function createLockfileHelper

packages/cli/src/cli/utils/lockfile.ts:8–100  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

6import _ from "lodash";
7
8export function createLockfileHelper() {
9 return {
10 isLockfileExists: () => {
11 const lockfilePath = _getLockfilePath();
12 return fs.existsSync(lockfilePath);
13 },
14 hasSourceData: (pathPattern: string): boolean => {
15 const lockfile = _loadLockfile();
16 const sectionKey = MD5(pathPattern);
17 const section = lockfile.checksums[sectionKey];
18 return !!section && Object.keys(section).length > 0;
19 },
20 registerSourceData: (
21 pathPattern: string,
22 sourceData: Record<string, any>,
23 ) => {
24 const lockfile = _loadLockfile();
25
26 const sectionKey = MD5(pathPattern);
27 const sectionChecksums = _.mapValues(sourceData, (value) => MD5(value));
28
29 lockfile.checksums[sectionKey] = sectionChecksums;
30
31 _saveLockfile(lockfile);
32 },
33 registerPartialSourceData: (
34 pathPattern: string,
35 partialSourceData: Record<string, any>,
36 ) => {
37 const lockfile = _loadLockfile();
38
39 const sectionKey = MD5(pathPattern);
40 const sectionChecksums = _.mapValues(partialSourceData, (value) =>
41 MD5(value),
42 );
43
44 lockfile.checksums[sectionKey] = _.merge(
45 {},
46 lockfile.checksums[sectionKey] ?? {},
47 sectionChecksums,
48 );
49
50 _saveLockfile(lockfile);
51 },
52 extractUpdatedData: (
53 pathPattern: string,
54 sourceData: Record<string, any>,
55 ) => {
56 const lockfile = _loadLockfile();
57
58 const sectionKey = MD5(pathPattern);
59 const currentChecksums = _.mapValues(sourceData, (value) => MD5(value));
60
61 const savedChecksums = lockfile.checksums[sectionKey] || {};
62 const updatedData = _.pickBy(
63 sourceData,
64 (value, key) => savedChecksums[key] !== currentChecksums[key],
65 );

Callers 2

lockfile.test.tsFile · 0.90
lockfile.tsFile · 0.90

Calls 3

_getLockfilePathFunction · 0.85
_loadLockfileFunction · 0.85
_saveLockfileFunction · 0.85

Tested by

no test coverage detected