Skip to content

Commit 8cc8dc6

Browse files
trangdoan982claudedevin-ai-integration[bot]graphite-app[bot]
authored
ENG-1536 Support multiple vault paths in Obsidian build script (#891)
* ENG-1536 Support multiple vault paths in Obsidian build script Allow OBSIDIAN_PLUGIN_PATH to accept a comma-separated list of vault paths, so devs can build once and mirror output to multiple vaults simultaneously. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * change to array format * Update apps/obsidian/.env.example Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com> * Update apps/obsidian/scripts/compile.ts Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com> * lint * lint2 * Update apps/obsidian/scripts/compile.ts Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com> Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>
1 parent 1b9581b commit 8cc8dc6

2 files changed

Lines changed: 44 additions & 25 deletions

File tree

apps/obsidian/.env.example

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
# OBSIDIAN_PLUGIN_PATH="path/to/your/obsidian/plugins/folder"
1+
# OBSIDIAN_PLUGIN_PATH="path/to/your/obsidian/vault/.obsidian/plugins/discourse-graph"
2+
# For multiple vaults, use a JSON array:
3+
# OBSIDIAN_PLUGIN_PATH='["/vault one/plugins/discourse-graph","/vault two/plugins/discourse-graph"]'
4+
# OBSIDIAN_PLUGIN_REPO_TOKEN=your-github-pat-here

apps/obsidian/scripts/compile.ts

Lines changed: 40 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ import autoprefixer from "autoprefixer";
1212
dotenv.config();
1313

1414
// For local dev: Set SUPABASE_USE_DB=local and run `pnpm run genenv` in packages/database
15-
let envContents: (() => Record<string, string>) | null = null;
15+
let envContents: () => Partial<Record<string, string>>;
1616
try {
1717
const dbDotEnv = require("@repo/database/dbDotEnv");
18+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
1819
envContents = dbDotEnv.envContents;
1920
} catch (error) {
2021
if ((error as Error).message.includes("Cannot find module")) {
@@ -139,7 +140,7 @@ export const compile = ({
139140
},
140141
{
141142
name: "combineStyles",
142-
setup(build) {
143+
setup: (build): void => {
143144
build.onEnd(async () => {
144145
const rootStylesPath = path.join(root, "styles.css");
145146
if (fs.existsSync(rootStylesPath)) {
@@ -181,8 +182,8 @@ export const compile = ({
181182
},
182183
{
183184
name: "copyDefaultFiles",
184-
setup(build) {
185-
build.onEnd(async () => {
185+
setup: (build): void => {
186+
build.onEnd(() => {
186187
DEFAULT_FILES_INCLUDED.map((f) => path.join(root, f))
187188
.filter((f) => fs.existsSync(f))
188189
.forEach((f) => {
@@ -193,29 +194,44 @@ export const compile = ({
193194
},
194195
{
195196
name: "mirrorFiles",
196-
setup(build) {
197-
build.onEnd(async () => {
197+
setup: (build): void => {
198+
build.onEnd(() => {
198199
if (!mirror) return;
199200

200-
const normalizedMirrorPath = path.normalize(mirror);
201-
const resolvedMirrorPath = path.resolve(
202-
root,
203-
normalizedMirrorPath,
204-
);
205-
206-
if (!fs.existsSync(resolvedMirrorPath)) {
207-
fs.mkdirSync(resolvedMirrorPath, { recursive: true });
201+
let mirrorPaths: string[];
202+
try {
203+
const parsed: unknown = JSON.parse(mirror);
204+
mirrorPaths = Array.isArray(parsed)
205+
? (parsed as string[])
206+
: [parsed as string];
207+
} catch {
208+
mirrorPaths = [mirror];
208209
}
210+
mirrorPaths = mirrorPaths.map((p) => p.trim()).filter(Boolean);
209211

210-
readDir(outdir)
211-
.filter((file) => fs.existsSync(appPath(file)))
212-
.forEach((file) => {
213-
const destinationPath = path.join(
214-
resolvedMirrorPath,
215-
path.relative(outdir, file),
216-
);
217-
fs.cpSync(appPath(file), destinationPath);
218-
});
212+
for (const mirrorPath of mirrorPaths) {
213+
const normalizedMirrorPath = path.normalize(mirrorPath);
214+
const resolvedMirrorPath = path.resolve(
215+
root,
216+
normalizedMirrorPath,
217+
);
218+
219+
if (!fs.existsSync(resolvedMirrorPath)) {
220+
fs.mkdirSync(resolvedMirrorPath, { recursive: true });
221+
}
222+
223+
readDir(outdir)
224+
.filter((file) => fs.existsSync(appPath(file)))
225+
.forEach((file) => {
226+
const destinationPath = path.join(
227+
resolvedMirrorPath,
228+
path.relative(outdir, file),
229+
);
230+
fs.cpSync(appPath(file), destinationPath);
231+
});
232+
233+
console.log(`mirrored to ${resolvedMirrorPath}`);
234+
}
219235
});
220236
},
221237
},
@@ -234,4 +250,4 @@ const main = async () => {
234250
process.exit(1);
235251
}
236252
};
237-
if (require.main === module) main();
253+
if (require.main === module) void main();

0 commit comments

Comments
 (0)