[TEST] 함수 이름 등록 방식

This commit is contained in:
hihangeol 2025-01-02 00:34:18 +09:00
parent f56457aac5
commit 31df1331a6
3 changed files with 63 additions and 7 deletions

23
build.sh Normal file
View file

@ -0,0 +1,23 @@
#!/bin/bash
# npm build 실행
echo "Building the project..."
npm run build
# 빌드 성공 여부 확인
if [ $? -ne 0 ]; then
echo "Build failed. Exiting."
exit 1
fi
# Python 스크립트 실행
echo "Running Python script to copy files..."
python3 copy_to_obsidian.py
# Python 스크립트 성공 여부 확인
if [ $? -ne 0 ]; then
echo "Python script execution failed. Exiting."
exit 1
fi
echo "Build and copy process completed successfully!"

45
main.ts
View file

@ -1,4 +1,8 @@
import { App, Editor, MarkdownView, Modal, Notice, Plugin, PluginSettingTab, Setting } from 'obsidian';
import {
App, Editor, MarkdownView,
Modal, Notice, Plugin, PluginSettingTab, Setting,
TFile,
} from 'obsidian';
// Remember to rename these classes and interfaces!
@ -13,15 +17,43 @@ const DEFAULT_SETTINGS: CsvPluginSettings = {
export default class CsvPlugin extends Plugin {
settings: CsvPluginSettings;
testFunction(arg: string): string {
return `Test function called with argument: ${arg}`;
// testFunction(arg: string): string {
// return `Test function called with argument: ${arg}`;
// }
// 등록하는 이름 말고 정의한 함수 이름으로 호출됨.
async saveFile(app: App, fileName: string, content: string): Promise<void> {
const vault = app.vault;
await vault.create(fileName, content);
// 파일이 이미 존재하는지 확인
// const existingFile = vault.getAbstractFileByPath(fileName);
// if (existingFile instanceof TFile) {
// // 파일이 존재하면 덮어쓰기
// await vault.modify(existingFile, content);
// } else {
// // 파일이 존재하지 않으면 새로 생성
// await vault.create(fileName, content);
// }
}
async onload() {
await this.loadSettings();
(window as any).testFunction = this.testFunction;
// custom 함수 추가.
// (window as any).testFunction = this.testFunction;
// (window as any).saveFileFromDataview = async (fileName: string, content: string) => {
// if(!this.app || !this.app.vault) {
// console.error('app or vault is not ready');
// return;
// }
// try {
// await this.saveFile(this.app, fileName, content);
// } catch (error) {
// console.error(error);
// }
// };
// This creates an icon in the left ribbon.
const ribbonIconEl = this.addRibbonIcon('dice', 'Sample Plugin', (evt: MouseEvent) => {
// Called when the user clicks the icon.
@ -86,7 +118,8 @@ export default class CsvPlugin extends Plugin {
}
onunload() {
delete (window as any).testFunction;
// delete (window as any).testFunction;
delete (window as any).saveFileFromDataview;
}
async loadSettings() {

View file

@ -1,7 +1,7 @@
{
"id": "csv-allinone",
"name": "CSV All-in-One",
"version": "0.1.0",
"version": "0.1.1",
"minAppVersion": "1.7.7",
"description": "all about csv.",
"author": "hihangeol",