Merge pull request #1 from RavenHogWarts/better-build

Add dotenv support and update VAULT_PATH configuration
This commit is contained in:
Moy 2025-03-23 18:54:25 +08:00 committed by GitHub
commit ed44b9e5f0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 31 additions and 3 deletions

3
.gitignore vendored
View file

@ -26,3 +26,6 @@ Thumbs.db
# Exclude zip
*.zip
# env
.env

14
package-lock.json generated
View file

@ -8,6 +8,9 @@
"name": "obsidian-sample-plugin",
"version": "1.0.0",
"license": "MIT",
"dependencies": {
"dotenv": "^16.4.7"
},
"devDependencies": {
"@types/node": "^16.11.6",
"@typescript-eslint/eslint-plugin": "5.29.0",
@ -1005,6 +1008,17 @@
"node": ">=6.0.0"
}
},
"node_modules/dotenv": {
"version": "16.4.7",
"resolved": "https://registry.npmmirror.com/dotenv/-/dotenv-16.4.7.tgz",
"integrity": "sha512-47qPchRCykZC03FhkYAhrvwU4xDBFIj1QPqaarj6mdM/hgUzfPHcpkHJOn3mJAufFeeAxAzeGsr5X0M4k6fLZQ==",
"engines": {
"node": ">=12"
},
"funding": {
"url": "https://dotenvx.com"
}
},
"node_modules/esbuild": {
"version": "0.17.3",
"resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.17.3.tgz",

View file

@ -22,5 +22,8 @@
"obsidian": "latest",
"tslib": "2.4.0",
"typescript": "4.7.4"
},
"dependencies": {
"dotenv": "^16.4.7"
}
}

View file

@ -3,13 +3,21 @@ import { copyFile, mkdir } from 'fs/promises';
import { existsSync } from 'fs';
import { join, dirname } from 'path';
import { fileURLToPath } from 'url';
import dotenv from 'dotenv';
// 获取当前文件的目录
const __dirname = dirname(fileURLToPath(import.meta.url));
const rootDir = join(__dirname, '..');
// 这里定义你的 Obsidian 库路径
const VAULT_PATH = 'V:\\Code\\CodeRepos\\plugin-dev-vault';
// 加载 .env 文件中的环境变量
dotenv.config();
// 获取 VAULT_PATH 环境变量
const VAULT_PATH = process.env.VAULT_PATH;
if (!VAULT_PATH) {
throw new Error(
'VAULT_PATH is not defined. Please create a .env file in the project root and add the line: VAULT_PATH=/path/to/your/vault'
);
}
const pluginDir = join(VAULT_PATH, '.obsidian', 'plugins', 'easy-copy');
async function copyToVault() {

View file

@ -135,7 +135,7 @@ export default class EasyCopy extends Plugin {
const filename = file.basename;
// 1. 检查是否是标题行
if (curLine.startsWith('#')) {
if (/^#+\s/.test(curLine)) {
this.copyHeadingLink(curLine, filename);
return;
}