Skip to content

Commit

Permalink
Merge pull request #140 from OliverBalfour/patches
Browse files Browse the repository at this point in the history
Use esbuild and obsidian-auto-plugin. Improve relative asset embeds. Update docs.
  • Loading branch information
OliverBalfour committed Sep 25, 2022
2 parents 8229273 + 527f171 commit ead5fcc
Show file tree
Hide file tree
Showing 12 changed files with 113 additions and 81 deletions.
6 changes: 6 additions & 0 deletions .autorc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"plugins": [
"obsidian"
],
"author": "Oliver Balfour <oliver.leo.balfour@gmail.com>"
}
29 changes: 29 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Based on https://github.com/hipstersmoothie/obsidian-plugin-prettier/blob/main/.github/workflows/main.yml
name: Release
on:
push:
branches: [master]
pull_request:
branches: [master]
jobs:
verify:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Prepare repository
run: git fetch --unshallow --tags

- name: Install modules
run: yarn

- name: Run build
run: yarn run build

- name: Create Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
run: |
npm run release
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# npm
node_modules
package-lock.json
yarn.lock

data.json

Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ Note: this plugin is in beta, and there are often minor formatting issues. Make

## [Installation](https://github.com/OliverBalfour/obsidian-pandoc/wiki/Installation)

(Installation instructions are on the wiki, use the above link)
Installation instructions are on the wiki, use the above link

Developer setup instructions are in [development.md](./development.md)

## Basic usage
* Press Ctrl+P/Cmd+P to show the command palette
Expand Down
45 changes: 18 additions & 27 deletions development.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,19 @@

### 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.
- Publish the release.

### Adding your plugin to the community plugin list

- 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.
- `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/`.

### API Documentation

See https://github.com/obsidianmd/obsidian-api
### Setup

* `cd vault/.obsidian/plugins`
* If you already have the plugin, copy the `obsidian-pandoc/data.json` file somewhere safe and delete the plugin
* `git clone https://github.com/OliverBalfour/obsidian-pandoc` (or clone it elsewhere and make a symlink here)
* Copy the data file back in
* `cd obsidian-pandoc`
* `npm install`

### Development

Every time you want to edit the plugin:
* `npm run dev` (keep this running until you're done)
* Commit+push your changes like normal (don't worry about version numbers)
* Make a PR and add the patch/minor/major label depending on how big the change is
* When it's reviewed and merged, a GitHub Actions workflow will
1. Automatically increment all the version numbers in a new commit
2. Build and publish a release
28 changes: 28 additions & 0 deletions esbuild.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
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');

esbuild.build({
banner: {
js: banner,
},
entryPoints: ['main.ts'],
bundle: true,
external: ['obsidian', 'electron', ...builtins],
format: 'cjs',
watch: !prod,
target: 'es2016',
logLevel: "info",
sourcemap: prod ? false : 'inline',
treeShaking: true,
outfile: 'main.js',
}).catch(() => process.exit(1));
6 changes: 4 additions & 2 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ export default class PandocPlugin extends Plugin {
const result = await pandoc(
{
file: 'STDIN', contents: html, format: 'html', metadataFile,
pandoc: this.settings.pandoc, pdflatex: this.settings.pdflatex
pandoc: this.settings.pandoc, pdflatex: this.settings.pdflatex,
directory: path.dirname(inputFile),
},
{ file: outputFile, format },
this.settings.extraArguments.split('\n')
Expand All @@ -133,7 +134,8 @@ export default class PandocPlugin extends Plugin {
const result = await pandoc(
{
file: inputFile, format: 'markdown',
pandoc: this.settings.pandoc, pdflatex: this.settings.pdflatex
pandoc: this.settings.pandoc, pdflatex: this.settings.pdflatex,
directory: path.dirname(inputFile),
},
{ file: outputFile, format },
this.settings.extraArguments.split('\n')
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "obsidian-pandoc",
"name": "Pandoc Plugin",
"version": "0.2.5",
"version": "0.3.0",
"minAppVersion": "0.12.5",
"description": "This is a Pandoc export plugin for Obsidian. It provides commands to export to formats like DOCX, ePub and PDF.",
"author": "Oliver Balfour",
Expand Down
29 changes: 16 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
{
"name": "obsidian-pandoc-plugin",
"version": "0.1.0",
"description": "This is a Pandoc export plugin for Obsidian (https://obsidian.md)",
"version": "0.3.0",
"description": "Document exporting plugin for Obsidian using Pandoc",
"main": "main.js",
"scripts": {
"dev": "rollup --config rollup.config.js -w",
"build": "rollup --config rollup.config.js --environment BUILD:production"
"dev": "node esbuild.config.mjs",
"build": "node esbuild.config.mjs production",
"release": "auto shipit"
},
"keywords": [],
"author": "Oliver Balfour",
"author": "Oliver Balfour <oliver.leo.balfour@gmail.com>",
"license": "MIT",
"devDependencies": {
"@rollup/plugin-commonjs": "^15.1.0",
"@rollup/plugin-node-resolve": "^9.0.0",
"@rollup/plugin-typescript": "^6.0.0",
"@types/node": "^14.14.2",
"obsidian": "https://github.com/obsidianmd/obsidian-api/tarball/master",
"rollup": "^2.32.1",
"tslib": "^2.0.3",
"typescript": "^4.0.3"
"@types/node": "^16.11.6",
"@typescript-eslint/eslint-plugin": "^5.2.0",
"@typescript-eslint/parser": "^5.2.0",
"auto": "^10.37.6",
"auto-plugin-obsidian": "^0.1.4",
"builtin-modules": "^3.2.0",
"esbuild": "0.13.12",
"obsidian": "^0.12.17",
"tslib": "2.3.1",
"typescript": "4.4.4"
},
"dependencies": {
"@types/temp": "^0.9.0",
Expand Down
11 changes: 5 additions & 6 deletions pandoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export interface PandocInput {
metadataFile?: string, // path to YAML file
pandoc?: string, // optional path to Pandoc if it's not in the current PATH variable
pdflatex?: string, // ditto for pdflatex
directory: AbsoluteFilePath, // The working directory (where the original source file is)
}

export interface PandocOutput {
Expand Down Expand Up @@ -146,19 +147,17 @@ export const pandoc = async (input: PandocInput, output: PandocOutput, extraPara
// Spawn a Pandoc child process
// Assumes Pandoc is installed and that the arguments are valid
// The arguments aren't sanitised, so be careful!
const env = Object.assign(process.env);

if (input.pdflatex) {
// Workaround for Windows having different PATH delimiters
// to *every other operating system in existence*
// *sigh*
if (process.platform === 'win32')
env.PATH += ";"
process.env.PATH += ";"
else
env.PATH += ":";
env.PATH += path.dirname(input.pdflatex);
process.env.PATH += ":";
process.env.PATH += path.dirname(input.pdflatex);
}
pandoc = spawn(input.pandoc || 'pandoc', args, { env: process.env });
pandoc = spawn(input.pandoc || 'pandoc', args, { env: process.env, cwd: input.directory });

if (stdin) {
// TODO: strip some unicode characters but not others
Expand Down
30 changes: 0 additions & 30 deletions rollup.config.js

This file was deleted.

3 changes: 2 additions & 1 deletion versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
"0.2.2": "0.12.5",
"0.2.3": "0.12.5",
"0.2.4": "0.12.5",
"0.2.5": "0.12.5"
"0.2.5": "0.12.5",
"0.3.0": "0.12.5"
}

0 comments on commit ead5fcc

Please sign in to comment.