obsidian-testing-framework 0.4.0 → 0.4.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/lib/index.js +2 -2
- package/lib/internal-util.d.ts +1 -1
- package/lib/internal-util.js +34 -18
- package/package.json +3 -1
package/lib/index.js
CHANGED
|
@@ -14,7 +14,7 @@ export const test = base.extend({
|
|
|
14
14
|
const vaultHash = randomBytes(8).toString("hex").toLocaleLowerCase();
|
|
15
15
|
await run(vaultHash);
|
|
16
16
|
},
|
|
17
|
-
{ auto: true
|
|
17
|
+
{ auto: true },
|
|
18
18
|
],
|
|
19
19
|
electronApp: [
|
|
20
20
|
async ({ ___vaultId: vaultId }, run) => {
|
|
@@ -23,7 +23,7 @@ export const test = base.extend({
|
|
|
23
23
|
const vault = inject("vault");
|
|
24
24
|
const vaultPoolDir = inject("vaultPoolDir");
|
|
25
25
|
console.log("asar located at:", getExe(obsidianPath));
|
|
26
|
-
generateVaultConfig(vault, vaultId, concurrent, vaultPoolDir);
|
|
26
|
+
await generateVaultConfig(vault, vaultId, concurrent, vaultPoolDir);
|
|
27
27
|
const tmp = JSON.parse(readFileSync(path.join(findConfig(), "obsidian.json")).toString());
|
|
28
28
|
console.log("vaultid", vaultId, vaultId in tmp.vaults);
|
|
29
29
|
let uriArg = "";
|
package/lib/internal-util.d.ts
CHANGED
|
@@ -13,4 +13,4 @@ export declare function checkToy(): void;
|
|
|
13
13
|
export declare function getExe(obsidianPath?: string): string;
|
|
14
14
|
export declare function addConsoleListener(app: ElectronApplication): void;
|
|
15
15
|
export declare function findConfig(): any;
|
|
16
|
-
export declare function generateVaultConfig(vault: string, vaultHash: string, concurrent: Concurrency, vaultPoolDir: string): string
|
|
16
|
+
export declare function generateVaultConfig(vault: string, vaultHash: string, concurrent: Concurrency, vaultPoolDir: string): Promise<string>;
|
package/lib/internal-util.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import path from "path";
|
|
2
|
-
import {
|
|
2
|
+
import { existsSync, mkdirSync, writeFileSync } from "fs";
|
|
3
|
+
import { cp, readFile, writeFile } from "fs/promises";
|
|
4
|
+
import { lock } from "proper-lockfile";
|
|
3
5
|
import symlinkDir from "symlink-dir";
|
|
4
6
|
export function checkToy() {
|
|
5
7
|
if (process.platform == "darwin") {
|
|
@@ -57,30 +59,44 @@ export function findConfig() {
|
|
|
57
59
|
}
|
|
58
60
|
return configLocation;
|
|
59
61
|
}
|
|
60
|
-
export function generateVaultConfig(vault, vaultHash, concurrent, vaultPoolDir) {
|
|
62
|
+
export async function generateVaultConfig(vault, vaultHash, concurrent, vaultPoolDir) {
|
|
61
63
|
let configLocation = findConfig();
|
|
62
64
|
console.log("vault is", vault, existsSync(vault));
|
|
63
65
|
const obsidianConfigFile = path.join(configLocation, "obsidian.json");
|
|
64
66
|
if (!existsSync(obsidianConfigFile)) {
|
|
65
67
|
writeFileSync(obsidianConfigFile, JSON.stringify({ vaults: {} }));
|
|
66
68
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
|
|
69
|
+
let releaser;
|
|
70
|
+
releaser = await lock(obsidianConfigFile, {
|
|
71
|
+
retries: 5,
|
|
72
|
+
});
|
|
73
|
+
try {
|
|
74
|
+
const json = JSON.parse((await readFile(obsidianConfigFile)).toString());
|
|
75
|
+
const hasVault = Object.values(json.vaults).some((a) => a.path === vault);
|
|
76
|
+
if (concurrent === "symlink") {
|
|
77
|
+
await symlinkDir(vault, path.join(vaultPoolDir, vaultHash));
|
|
78
|
+
}
|
|
79
|
+
else if (concurrent === "copy") {
|
|
80
|
+
await cp(vault, path.join(vaultPoolDir, vaultHash), { recursive: true });
|
|
81
|
+
}
|
|
82
|
+
if (!hasVault) {
|
|
83
|
+
json.vaults[vaultHash] = {
|
|
84
|
+
path: concurrent ? path.join(vaultPoolDir, vaultHash) : vault,
|
|
85
|
+
ts: Date.now(),
|
|
86
|
+
};
|
|
87
|
+
await writeFile(obsidianConfigFile, JSON.stringify(json, null, "\t"));
|
|
88
|
+
return vaultHash;
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
return Object.entries(json.vaults).find((a) => a[1].path === vault)[0];
|
|
92
|
+
}
|
|
73
93
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
path: concurrent ? path.join(vaultPoolDir, vaultHash) : vault,
|
|
77
|
-
ts: Date.now(),
|
|
78
|
-
};
|
|
79
|
-
writeFileSync(obsidianConfigFile, JSON.stringify(json, null, "\t"));
|
|
80
|
-
writeFileSync(path.join(configLocation, `${vaultHash}.json`), "{}");
|
|
81
|
-
return vaultHash;
|
|
94
|
+
catch (err) {
|
|
95
|
+
console.error("error generating vault config", err);
|
|
82
96
|
}
|
|
83
|
-
|
|
84
|
-
|
|
97
|
+
finally {
|
|
98
|
+
await releaser();
|
|
85
99
|
}
|
|
100
|
+
await writeFile(path.join(configLocation, `${vaultHash}.json`), "{}");
|
|
101
|
+
return vaultHash;
|
|
86
102
|
}
|
package/package.json
CHANGED
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
"electron": "^33.0.2",
|
|
13
13
|
"obsidian": "latest",
|
|
14
14
|
"playwright": "^1.58.2",
|
|
15
|
+
"proper-lockfile": "^4.1.2",
|
|
15
16
|
"symlink-dir": "^9.0.0",
|
|
16
17
|
"tmp": "^0.2.3",
|
|
17
18
|
"typescript": "^5.6.3",
|
|
@@ -28,7 +29,7 @@
|
|
|
28
29
|
".": "./lib/index.js"
|
|
29
30
|
},
|
|
30
31
|
"readme": "",
|
|
31
|
-
"version": "0.4.
|
|
32
|
+
"version": "0.4.2",
|
|
32
33
|
"main": "./lib/index.js",
|
|
33
34
|
"typings": "./lib/index.d.ts",
|
|
34
35
|
"repository": {
|
|
@@ -42,6 +43,7 @@
|
|
|
42
43
|
"prepare": "yarn run build"
|
|
43
44
|
},
|
|
44
45
|
"devDependencies": {
|
|
46
|
+
"@types/proper-lockfile": "^4",
|
|
45
47
|
"@types/tmp": "^0",
|
|
46
48
|
"rimraf": "^6.0.1",
|
|
47
49
|
"vitest": "^4.1.0"
|