From 2e1928ec600aad274c82e60b2de775dba452a352 Mon Sep 17 00:00:00 2001 From: zigholding Date: Mon, 22 Apr 2024 21:27:53 +0800 Subject: [PATCH] export_readme --- .editorconfig | 10 +++ .eslintignore | 3 + .eslintrc | 23 +++++++ .gitignore | 26 ++++++++ .npmrc | 1 + README.md | 96 +++++++++++++++++++++++++++++ data.json | 3 + esbuild.config.mjs | 48 +++++++++++++++ main.js | 142 ++++++++++++++++++++++++++++++++++++++++++ main.ts | 149 +++++++++++++++++++++++++++++++++++++++++++++ manifest.json | 9 +++ package.json | 24 ++++++++ styles.css | 8 +++ tsconfig.json | 24 ++++++++ version-bump.mjs | 14 +++++ versions.json | 3 + 16 files changed, 583 insertions(+) create mode 100644 .editorconfig create mode 100644 .eslintignore create mode 100644 .eslintrc create mode 100644 .gitignore create mode 100644 .npmrc create mode 100644 README.md create mode 100644 data.json create mode 100644 esbuild.config.mjs create mode 100644 main.js create mode 100644 main.ts create mode 100644 manifest.json create mode 100644 package.json create mode 100644 styles.css create mode 100644 tsconfig.json create mode 100644 version-bump.mjs create mode 100644 versions.json diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..81f3ec3 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,10 @@ +# top-most EditorConfig file +root = true + +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +indent_style = tab +indent_size = 4 +tab_width = 4 diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..e019f3c --- /dev/null +++ b/.eslintignore @@ -0,0 +1,3 @@ +node_modules/ + +main.js diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..0807290 --- /dev/null +++ b/.eslintrc @@ -0,0 +1,23 @@ +{ + "root": true, + "parser": "@typescript-eslint/parser", + "env": { "node": true }, + "plugins": [ + "@typescript-eslint" + ], + "extends": [ + "eslint:recommended", + "plugin:@typescript-eslint/eslint-recommended", + "plugin:@typescript-eslint/recommended" + ], + "parserOptions": { + "sourceType": "module" + }, + "rules": { + "no-unused-vars": "off", + "@typescript-eslint/no-unused-vars": ["error", { "args": "none" }], + "@typescript-eslint/ban-ts-comment": "off", + "no-prototype-builtins": "off", + "@typescript-eslint/no-empty-function": "off" + } + } \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d4aeb0a --- /dev/null +++ b/.gitignore @@ -0,0 +1,26 @@ +# vscode +.vscode + +# Intellij +*.iml +.idea + +# npm +node_modules + +# Don't include the compiled main.js file in the repo. +# They should be uploaded to GitHub releases instead. +# main.js + +# Exclude sourcemaps +*.map +tmp* + +# obsidian +# data.json + +# Exclude macOS Finder (System Explorer) View States +.DS_Store + +package-lock.json +otherplugins \ No newline at end of file diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..b973752 --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +tag-version-prefix="" \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..bb0348e --- /dev/null +++ b/README.md @@ -0,0 +1,96 @@ +# Obsidian Sample Plugin + +This is a sample plugin for Obsidian (https://obsidian.md). + +This project uses Typescript to provide type checking and documentation. +The repo depends on the latest plugin API (obsidian.d.ts) in Typescript Definition format, which contains TSDoc comments describing what it does. + +**Note:** The Obsidian API is still in early alpha and is subject to change at any time! + +This sample plugin demonstrates some of the basic functionality the plugin API can do. +- Adds a ribbon icon, which shows a Notice when clicked. +- Adds a command "Open Sample Modal" which opens a Modal. +- Adds a plugin setting tab to the settings page. +- Registers a global click event and output 'click' to the console. +- Registers a global interval which logs 'setInterval' to the console. + +## First time developing plugins? + +Quick starting guide for new plugin devs: + +- Check if [someone already developed a plugin for what you want](https://obsidian.md/plugins)! There might be an existing plugin similar enough that you can partner up with. +- Make a copy of this repo as a template with the "Use this template" button (login to GitHub if you don't see it). +- Clone your repo to a local development folder. For convenience, you can place this folder in your `.obsidian/plugins/your-plugin-name` folder. +- Install NodeJS, then run `npm i` in the command line under your repo folder. +- Run `npm run dev` to compile your plugin from `main.ts` to `main.js`. +- Make changes to `main.ts` (or create new `.ts` files). Those changes should be automatically compiled into `main.js`. +- Reload Obsidian to load the new version of your plugin. +- Enable plugin in settings window. +- For updates to the Obsidian API run `npm update` in the command line under your repo folder. + +## Releasing new releases + +- Update your `manifest.json` with your new version number, such as `1.0.1`, and the minimum Obsidian version required for your latest release. +- Update your `versions.json` file with `"new-plugin-version": "minimum-obsidian-version"` so older versions of Obsidian can download an older version of your plugin that's compatible. +- Create new GitHub release using your new version number as the "Tag version". Use the exact version number, don't include a prefix `v`. See here for an example: https://github.com/obsidianmd/obsidian-sample-plugin/releases +- Upload the files `manifest.json`, `main.js`, `styles.css` as binary attachments. Note: The manifest.json file must be in two places, first the root path of your repository and also in the release. +- Publish the release. + +> You can simplify the version bump process by running `npm version patch`, `npm version minor` or `npm version major` after updating `minAppVersion` manually in `manifest.json`. +> The command will bump version in `manifest.json` and `package.json`, and add the entry for the new version to `versions.json` + +## Adding your plugin to the community plugin list + +- Check https://github.com/obsidianmd/obsidian-releases/blob/master/plugin-review.md +- Publish an initial version. +- Make sure you have a `README.md` file in the root of your repo. +- Make a pull request at https://github.com/obsidianmd/obsidian-releases to add your plugin. + +## How to use + +- Clone this repo. +- Make sure your NodeJS is at least v16 (`node --version`). +- `npm i` or `yarn` to install dependencies. +- `npm run dev` to start compilation in watch mode. + +## Manually installing the plugin + +- Copy over `main.js`, `styles.css`, `manifest.json` to your vault `VaultFolder/.obsidian/plugins/your-plugin-id/`. + +## Improve code quality with eslint (optional) +- [ESLint](https://eslint.org/) is a tool that analyzes your code to quickly find problems. You can run ESLint against your plugin to find common bugs and ways to improve your code. +- To use eslint with this project, make sure to install eslint from terminal: + - `npm install -g eslint` +- To use eslint to analyze this project use this command: + - `eslint main.ts` + - eslint will then create a report with suggestions for code improvement by file and line number. +- If your source code is in a folder, such as `src`, you can use eslint with this command to analyze all files in that folder: + - `eslint .\src\` + +## Funding URL + +You can include funding URLs where people who use your plugin can financially support it. + +The simple way is to set the `fundingUrl` field to your link in your `manifest.json` file: + +```json +{ + "fundingUrl": "https://buymeacoffee.com" +} +``` + +If you have multiple URLs, you can also do: + +```json +{ + "fundingUrl": { + "Buy Me a Coffee": "https://buymeacoffee.com", + "GitHub Sponsor": "https://github.com/sponsors", + "Patreon": "https://www.patreon.com/" + } +} +``` + +## API Documentation + +See https://github.com/obsidianmd/obsidian-api diff --git a/data.json b/data.json new file mode 100644 index 0000000..30b7063 --- /dev/null +++ b/data.json @@ -0,0 +1,3 @@ +{ + "mySetting": "D:/iLanix/isync/test" +} \ No newline at end of file diff --git a/esbuild.config.mjs b/esbuild.config.mjs new file mode 100644 index 0000000..b13282b --- /dev/null +++ b/esbuild.config.mjs @@ -0,0 +1,48 @@ +import esbuild from "esbuild"; +import process from "process"; +import builtins from "builtin-modules"; + +const banner = +`/* +THIS IS A GENERATED/BUNDLED FILE BY ESBUILD +if you want to view the source, please visit the github repository of this plugin +*/ +`; + +const prod = (process.argv[2] === "production"); + +const context = await esbuild.context({ + banner: { + js: banner, + }, + entryPoints: ["main.ts"], + bundle: true, + external: [ + "obsidian", + "electron", + "@codemirror/autocomplete", + "@codemirror/collab", + "@codemirror/commands", + "@codemirror/language", + "@codemirror/lint", + "@codemirror/search", + "@codemirror/state", + "@codemirror/view", + "@lezer/common", + "@lezer/highlight", + "@lezer/lr", + ...builtins], + format: "cjs", + target: "es2018", + logLevel: "info", + sourcemap: prod ? false : "inline", + treeShaking: true, + outfile: "main.js", +}); + +if (prod) { + await context.rebuild(); + process.exit(0); +} else { + await context.watch(); +} \ No newline at end of file diff --git a/main.js b/main.js new file mode 100644 index 0000000..dcf6aa1 --- /dev/null +++ b/main.js @@ -0,0 +1,142 @@ +/* +THIS IS A GENERATED/BUNDLED FILE BY ESBUILD +if you want to view the source, please visit the github repository of this plugin +*/ + +var __defProp = Object.defineProperty; +var __getOwnPropDesc = Object.getOwnPropertyDescriptor; +var __getOwnPropNames = Object.getOwnPropertyNames; +var __hasOwnProp = Object.prototype.hasOwnProperty; +var __export = (target, all) => { + for (var name in all) + __defProp(target, name, { get: all[name], enumerable: true }); +}; +var __copyProps = (to, from, except, desc) => { + if (from && typeof from === "object" || typeof from === "function") { + for (let key of __getOwnPropNames(from)) + if (!__hasOwnProp.call(to, key) && key !== except) + __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); + } + return to; +}; +var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); + +// main.ts +var main_exports = {}; +__export(main_exports, { + default: () => VaultExpoterPlugin +}); +module.exports = __toCommonJS(main_exports); +var import_obsidian = require("obsidian"); +var fs = require("fs"); +var DEFAULT_SETTINGS = { + mySetting: "default" +}; +var VaultExpoterPlugin = class extends import_obsidian.Plugin { + async onload() { + await this.loadSettings(); + this.app.vt = this; + this.fs = fs; + this.root = this.app.vault.adapter.basePath; + this.addSettingTab(new VExporterSettingTab(this.app, this)); + } + onunload() { + } + async loadSettings() { + this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData()); + } + async saveSettings() { + await this.saveData(this.settings); + } + /** + * 附件 src 到 dst,不在 vault 中,需要绝对路径 + * overwrite,复盖;mtime,新文件; + */ + copy_file_by_path(src, dst, mode = "overwrite>mtime>pass") { + mode = mode.split(">")[0]; + if (!fs.existsSync(src)) { + return; + } + if (fs.existsSync(dst)) { + if (mode === "overwrite") { + fs.unlinkSync(dst); + fs.copyFileSync(src, dst); + } else if (mode === "mtime") { + if (fs.statSync(dst).mtimeMs < fs.statSync(src).mtimeMs) { + fs.unlinkSync(dst); + fs.copyFileSync(src, dst); + } + } + } else { + fs.copyFileSync(src, dst); + } + } + abspath(tfile) { + if (tfile) { + return this.root + "/" + tfile.path; + } else { + return null; + } + } + copy_tfile(tfile, dst) { + if (tfile) { + let src = this.abspath(tfile); + src && this.copy_file_by_path(src, dst); + } + } + async export_readme(tfile, dst, as_readme = true, assets = "assets") { + let nc = this.app.plugins.getPlugin("note-chain"); + if (!tfile) { + tfile = nc.chain.current_note; + } + if (!dst) { + dst = "LocalGitProject"; + } + if (!dst.contains("/")) { + dst = nc.editor.get_frontmatter(tfile, dst); + } + if (!dst) { + dst = await nc.chain.tp_prompt("Path of LocalGitProject"); + if (!dst) { + return; + } + } + dst = dst.replace(/\\/g, "/"); + if (!fs.existsSync(dst)) { + console.log("No Dir:", dst); + } + console.log(dst); + let olinks = nc.chain.get_outlinks(tfile); + let tmp; + if (as_readme) { + tmp = dst + "/readMe.md"; + } else { + tmp = dst + "/" + tfile.basename + ".md"; + } + this.copy_tfile(tfile, tmp); + let adir = dst + "/" + assets; + if (!fs.existsSync(adir)) { + fs.mkdirSync(adir); + } + for (let f of olinks) { + if (!(f.extension === "md")) { + this.copy_tfile(f, adir + "/" + f.basename + "." + f.extension); + } + } + } +}; +var VExporterSettingTab = class extends import_obsidian.PluginSettingTab { + constructor(app, plugin) { + super(app, plugin); + this.plugin = plugin; + } + display() { + const { containerEl } = this; + containerEl.empty(); + new import_obsidian.Setting(containerEl).setName("Setting #1").setDesc("It's a secret").addTextArea((text) => text.setPlaceholder("Enter your secret").setValue(this.plugin.settings.mySetting).onChange(async (value) => { + this.plugin.settings.mySetting = value; + await this.plugin.saveSettings(); + })); + } +}; +//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsibWFpbi50cyJdLAogICJzb3VyY2VzQ29udGVudCI6IFsiaW1wb3J0ICogYXMgTW9kdWxlIGZyb20gJ21vZHVsZSc7XHJcbmltcG9ydCB7IEFwcCwgRWRpdG9yLCBNYXJrZG93blZpZXcsIE1vZGFsLCBOb3RpY2UsIFBsdWdpbiwgUGx1Z2luU2V0dGluZ1RhYiwgU2V0dGluZywgVEZpbGUgfSBmcm9tICdvYnNpZGlhbic7XHJcblxyXG4vLyBSZW1lbWJlciB0byByZW5hbWUgdGhlc2UgY2xhc3NlcyBhbmQgaW50ZXJmYWNlcyFcclxuXHJcbmNvbnN0IGZzID0gcmVxdWlyZSgnZnMnKTtcclxuXHJcbm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ts b/main.ts new file mode 100644 index 0000000..03e3a7d --- /dev/null +++ b/main.ts @@ -0,0 +1,149 @@ +import * as Module from 'module'; +import { App, Editor, MarkdownView, Modal, Notice, Plugin, PluginSettingTab, Setting, TFile } from 'obsidian'; + +// Remember to rename these classes and interfaces! + +const fs = require('fs'); + +interface VExporterSettings { + mySetting: string; +} + +const DEFAULT_SETTINGS: VExporterSettings = { + mySetting: 'default' +} + +export default class VaultExpoterPlugin extends Plugin { + settings: VExporterSettings; + root : string; + + async onload() { + await this.loadSettings(); + this.app.vt = this; + this.fs = fs; + this.root = this.app.vault.adapter.basePath; + // This adds a settings tab so the user can configure various aspects of the plugin + this.addSettingTab(new VExporterSettingTab(this.app, this)); + } + + onunload() { + + } + + async loadSettings() { + this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData()); + } + + async saveSettings() { + await this.saveData(this.settings); + } + + /** + * 附件 src 到 dst,不在 vault 中,需要绝对路径 + * overwrite,复盖;mtime,新文件; + */ + copy_file_by_path(src:string, dst:string,mode='overwrite>mtime>pass') { + mode = mode.split('>')[0] + if(!fs.existsSync(src)){ + return; + } + if(fs.existsSync(dst)){ + if(mode==='overwrite'){ + fs.unlinkSync(dst); + fs.copyFileSync(src,dst); + }else if(mode==='mtime'){ + // dst 更新时间小于 src + if(fs.statSync(dst).mtimeMs text + .setPlaceholder('Enter your secret') + .setValue(this.plugin.settings.mySetting) + .onChange(async (value) => { + this.plugin.settings.mySetting = value; + await this.plugin.saveSettings(); + })); + } +} diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..fb2ecd5 --- /dev/null +++ b/manifest.json @@ -0,0 +1,9 @@ +{ + "id": "vault-exporter", + "name": "Vault Exporter", + "version": "1.0.0", + "minAppVersion": "0.15.0", + "description": "Export current note to another Vault.", + "author": "ZigHolding", + "isDesktopOnly": true +} \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..6a00766 --- /dev/null +++ b/package.json @@ -0,0 +1,24 @@ +{ + "name": "obsidian-sample-plugin", + "version": "1.0.0", + "description": "This is a sample plugin for Obsidian (https://obsidian.md)", + "main": "main.js", + "scripts": { + "dev": "node esbuild.config.mjs", + "build": "tsc -noEmit -skipLibCheck && node esbuild.config.mjs production", + "version": "node version-bump.mjs && git add manifest.json versions.json" + }, + "keywords": [], + "author": "", + "license": "MIT", + "devDependencies": { + "@types/node": "^16.11.6", + "@typescript-eslint/eslint-plugin": "5.29.0", + "@typescript-eslint/parser": "5.29.0", + "builtin-modules": "3.3.0", + "esbuild": "0.17.3", + "obsidian": "latest", + "tslib": "2.4.0", + "typescript": "4.7.4" + } +} diff --git a/styles.css b/styles.css new file mode 100644 index 0000000..71cc60f --- /dev/null +++ b/styles.css @@ -0,0 +1,8 @@ +/* + +This CSS file will be included with your plugin, and +available in the app when your plugin is enabled. + +If your plugin does not need CSS, delete this file. + +*/ diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..2d6fbdf --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "baseUrl": ".", + "inlineSourceMap": true, + "inlineSources": true, + "module": "ESNext", + "target": "ES6", + "allowJs": true, + "noImplicitAny": true, + "moduleResolution": "node", + "importHelpers": true, + "isolatedModules": true, + "strictNullChecks": true, + "lib": [ + "DOM", + "ES5", + "ES6", + "ES7" + ] + }, + "include": [ + "**/*.ts" + ] +} diff --git a/version-bump.mjs b/version-bump.mjs new file mode 100644 index 0000000..d409fa0 --- /dev/null +++ b/version-bump.mjs @@ -0,0 +1,14 @@ +import { readFileSync, writeFileSync } from "fs"; + +const targetVersion = process.env.npm_package_version; + +// read minAppVersion from manifest.json and bump version to target version +let manifest = JSON.parse(readFileSync("manifest.json", "utf8")); +const { minAppVersion } = manifest; +manifest.version = targetVersion; +writeFileSync("manifest.json", JSON.stringify(manifest, null, "\t")); + +// update versions.json with target version and minAppVersion from manifest.json +let versions = JSON.parse(readFileSync("versions.json", "utf8")); +versions[targetVersion] = minAppVersion; +writeFileSync("versions.json", JSON.stringify(versions, null, "\t")); diff --git a/versions.json b/versions.json new file mode 100644 index 0000000..26382a1 --- /dev/null +++ b/versions.json @@ -0,0 +1,3 @@ +{ + "1.0.0": "0.15.0" +}