1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-11-26 22:41:17 +02:00

Chore: Automatically create command index for desktop app

This commit is contained in:
Laurent Cozic
2021-09-04 13:43:25 +01:00
parent e6bff3f2e0
commit c529b972e3
18 changed files with 289 additions and 96 deletions

View File

@@ -166,4 +166,20 @@ utils.setPackagePrivateField = async function(filePath, value) {
await fs.writeFile(filePath, JSON.stringify(obj, null, 2), 'utf8');
};
utils.insertContentIntoFile = async (filePath, marker, contentToInsert, createIfNotExist = false) => {
const fs = require('fs-extra');
const fileExists = await fs.pathExists(filePath);
if (!fileExists) {
if (!createIfNotExist) throw new Error(`File not found: ${filePath}`);
await fs.writeFile(filePath, `${marker}\n${contentToInsert}\n${marker}`);
} else {
let content = await fs.readFile(filePath, 'utf-8');
// [^]* matches any character including new lines
const regex = new RegExp(`${marker}[^]*?${marker}`);
content = content.replace(regex, `${marker}\n${contentToInsert}\n${marker}`);
await fs.writeFile(filePath, content);
}
};
module.exports = utils;