Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
eth-p committed Apr 17, 2023
0 parents commit b4b2aad
Show file tree
Hide file tree
Showing 33 changed files with 10,032 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .babelrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
presets: [
['@babel/preset-env', { modules: false, targets: { node: 'current' } }], // Node
['@babel/preset-typescript', { modules: false }], // TypeScript
],
};
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
example
dist
29 changes: 29 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"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-mixed-spaces-and-tabs": ["error", "smart-tabs"]
}
}
15 changes: 15 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Development
node_modules

# Artifacts
/dist

# System
.DS_Store
._*

# IDEs
.vscode
*.code-workspace
.idea
*.iml
22 changes: 22 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Development
node_modules
.*
build.mts
tsconfig.json
*.config.mjs

# Sources
/src

# Examples
/example

# System
.DS_Store
._*

# IDEs
.vscode
*.code-workspace
.idea
*.iml
12 changes: 12 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"printWidth": 120,
"tabWidth": 4,
"useTabs": true,
"trailingComma": "all",
"singleQuote": true,
"semi": true,

"importOrder": ["^((@jest/)|jest)", "^node:", "^(?!\\.)", "^\\.\\./", "^\\./"],
"importOrderSeparation": true,
"importOrderSortSpecifiers": true
}
7 changes: 7 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright 2023 eth-p and contributors

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
75 changes: 75 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# esbuild-plugin-obsidian

An [esbuild](https://esbuild.github.io/) plugin for creating [Obsidian](https://obsidian.md) plugins.

## Usage

Inside your esbuild build script:

```js
import * as esbuild from 'esbuild';
import esbuildObsidian from 'esbuild-plugin-obsidian';

await esbuild.build({
// ...
plugins: [esbuildObsidian(/* options */)],
});
```

Inside your `package.json` file:

```json
{
"name": "my-plugin",
"version": "1.2.3",
"author": "me",
"obsidian": {
"name": "My Plugin Name",
"minAppVersion": "1.0.0",
"isDesktopOnly": false
}
}
```

### Options

```typescript
interface Options {
/**
* The path to the `package.json` file that will be used for creating the plugin manifest.
*/
packageJsonFile?: string;

/**
* A list of plugin build warnings to ignore.
*/
ignoreWarnings?: string[];

/**
* The path to write the `manifest.json` file to.
*
* This is relative to the working directory, and *does not* respect `outDir`.
* Publishing an Obsidian plugin requires that `manifest.json` is in the repository root.
*/
outManifestFile?: string;

/**
* The path to write the `versions.json` file to.
*
* This is relative to the working directory, and *does not* respect `outDir`.
* Publishing an Obsidian plugin requires that `versions.json` is in the repository root.
*/
outVersionsFile?: string;
}
```

## Features

- Automatically generates and updates `versions.json`.
- Generates a `manifest.json` based on the `package.json` file.
- Package name as plugin ID.
- Package version as the plugin version.
- Package description as plugin description.
- Package [author](https://docs.npmjs.com/cli/v9/configuring-npm/package-json#people-fields-author-contributors) for the plugin author name and URL.
- Package [funding field](https://docs.npmjs.com/cli/v9/configuring-npm/package-json#funding) for the plugin funding URL.
- All manifest fields can be overridden in the `obsidian` field.
24 changes: 24 additions & 0 deletions build.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { readFile } from 'node:fs/promises';

import builtins from 'builtin-modules';
import * as esbuild from 'esbuild';
import esbuildPluginDtsBundleGenerator from 'esbuild-plugin-dts-bundle-generator';

const packageJson = JSON.parse(await readFile('package.json', 'utf-8'));

const config: esbuild.BuildOptions = {
entryPoints: { index: 'src/index.ts' },
bundle: true,
outdir: 'dist',
platform: 'node',
target: 'es2017',

external: [...builtins, ...Object.keys(packageJson.dependencies), './node_modules/*'],
};

await esbuild.build({
...config,
format: 'esm',
outExtension: { '.js': '.mjs' },
plugins: [esbuildPluginDtsBundleGenerator({ printPerformanceMessage: true })],
});
8 changes: 8 additions & 0 deletions example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Development
node_modules

# Artifacts
main.js

# Not used for examples.
package-lock.json
53 changes: 53 additions & 0 deletions example/esbuild.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import builtins from 'builtin-modules';
import esbuild from 'esbuild';
import process from 'process';

import esbuildObsidian from 'esbuild-plugin-obsidian';

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',
plugins: [
esbuildObsidian()
]
});

if (prod) {
await context.rebuild();
process.exit(0);
} else {
await context.watch();
}
Loading

0 comments on commit b4b2aad

Please sign in to comment.