MCPcopy Create free account
hub / github.com/GCWing/BitFun / withTemporaryTextFile

Function withTemporaryTextFile

scripts/i18n-contract.test.mjs:55–70  ·  view source on GitHub ↗
(relativePath, content, callback)

Source from the content-addressed store, hash-verified

53}
54
55function withTemporaryTextFile(relativePath, content, callback) {
56 const absolutePath = path.join(root, relativePath);
57 const existed = fs.existsSync(absolutePath);
58 const previous = existed ? fs.readFileSync(absolutePath, 'utf8') : null;
59
60 writeText(relativePath, content);
61 try {
62 return callback();
63 } finally {
64 if (existed) {
65 fs.writeFileSync(absolutePath, previous, 'utf8');
66 } else {
67 fs.rmSync(absolutePath, { force: true });
68 }
69 }
70}
71
72function flattenKeys(value, prefix = '') {
73 if (value == null || typeof value !== 'object' || Array.isArray(value)) {

Callers 1

Calls 2

writeTextFunction · 0.70
joinMethod · 0.45

Tested by

no test coverage detected