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

Tools: Moved lib-specific tests under lib package

This commit is contained in:
Laurent Cozic
2021-05-21 15:17:21 +02:00
parent 6ff560f22f
commit 2806aa1b19
86 changed files with 1145 additions and 1196 deletions

View File

@@ -1,4 +1,5 @@
import * as fs from 'fs-extra';
import { readCredentialFile } from '@joplin/lib/utils/credentialFiles';
const fetch = require('node-fetch');
const execa = require('execa');
@@ -222,36 +223,6 @@ export async function setPackagePrivateField(filePath: string, value: any) {
await fs.writeFile(filePath, JSON.stringify(obj, null, 2), 'utf8');
}
export async function credentialDir() {
const username = require('os').userInfo().username;
const toTry = [
`c:/Users/${username}/joplin-credentials`,
`/mnt/c/Users/${username}/joplin-credentials`,
`/home/${username}/joplin-credentials`,
`/Users/${username}/joplin-credentials`,
];
for (const dirPath of toTry) {
if (await fs.pathExists(dirPath)) return dirPath;
}
throw new Error(`Could not find credential directory in any of these paths: ${JSON.stringify(toTry)}`);
}
export async function credentialFile(filename: string) {
const rootDir = await credentialDir();
const output = `${rootDir}/${filename}`;
if (!(await fs.pathExists(output))) throw new Error(`No such file: ${output}`);
return output;
}
export async function readCredentialFile(filename: string) {
const filePath = await credentialFile(filename);
const r = await fs.readFile(filePath);
return r.toString();
}
export async function downloadFile(url: string, targetPath: string) {
const https = require('https');
const fs = require('fs');