Skip to content

Commit

Permalink
initial version
Browse files Browse the repository at this point in the history
  • Loading branch information
theotheo committed Mar 5, 2024
0 parents commit 6183314
Show file tree
Hide file tree
Showing 25 changed files with 30,485 additions and 0 deletions.
24 changes: 24 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# 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

# obsidian
data.json

# Exclude macOS Finder (System Explorer) View States
.DS_Store

dist
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 ibelyalov

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.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Belyalov Commander

This is a plugin for [Obsidian](https://obsidian.md/) that note preview and management.

## Installation

- `Belyalov Commander` is not available on [the official Community Plugins repository](https://obsidian.md/plugins) yet.
- Beta releases can be installed through [BRAT](https://github.com/TfTHacker/obsidian42-brat)

## License

© [ibelyalov](https://github.com/theotheo/)
116 changes: 116 additions & 0 deletions esbuild.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import esbuild from "esbuild";
import process from "process";
import builtins from "builtin-modules";
import { existsSync, renameSync } from "fs";
import {
cp,
mkdir,
readFile,
rm
} from "fs/promises";

interface NpmPackage {
name: string;
}



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 isProductionBuild = (process.argv[2] === "production");

const distDir = isProductionBuild ? "dist/build" : "dist/dev";
if (existsSync(distDir)) {
await rm(distDir, { recursive: true });
}
await mkdir(distDir, { recursive: true });

const distFileNames = ["manifest.json", "styles.css"];
if (!isProductionBuild) {
distFileNames.push(".hotreload");
}

const renamePlugin = () => ({
name: 'rename-plugin',
setup(build: any) {
build.onEnd(async () => {
try {
renameSync(`${distDir}/main.css`, `${distDir}/styles.css`);
} catch (e) {
console.error('Failed to rename file:', e);
}
});
},
});

for (const fileName of distFileNames) {
const localFile = `./${fileName}`;
const distFile = `${distDir}/${fileName}`;

if (existsSync(localFile)) {
await cp(localFile, distFile);
}
}

const context = await esbuild.context({
banner: {
js: banner,
},
entryPoints: ["src/BelyalovCommanderPlugin.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: isProductionBuild ? false : "inline",
treeShaking: true,
outfile: `${distDir}/main.js`,
plugins: [
renamePlugin(),
{
name: "copy-to-obsidian-plugins-folder",
setup: (build): void => {
build.onEnd(async () => {
if (isProductionBuild || !process.env["OBSIDIAN_CONFIG_DIR"]) {
return;
}

const npmPackage = JSON.parse(await readFile("./package.json", "utf8")) as NpmPackage;
const pluginName = npmPackage.name;
const pluginDir = `${process.env["OBSIDIAN_CONFIG_DIR"]}/plugins/${pluginName}`;
if (!existsSync(pluginDir)) {
await mkdir(pluginDir);
}

await cp(distDir, pluginDir, { recursive: true });
});
}
}
]
});

if (isProductionBuild) {
await context.rebuild();
process.exit(0);
} else {
await context.watch();
}
30 changes: 30 additions & 0 deletions eslint.config.fix.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
declare module "@typescript-eslint/eslint-plugin" {
import type {
ESLint,
Linter
} from "eslint";

type Config = {
overrides: Config[];
rules: Linter.RulesRecord;
}

const plugin: ESLint.Plugin & {
configs: Record<string, Config>
};
export default plugin;
}

declare module "eslint-plugin-import" {
}

declare module "eslint-plugin-modules-newlines" {
}

declare module "globals" {
const globals: {
browser: object;
node: object;
};
export default globals;
}
62 changes: 62 additions & 0 deletions eslint.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// eslint-disable-next-line import/no-namespace
import * as typescriptEslintParser from "@typescript-eslint/parser";
// eslint-disable-next-line import/no-namespace
import * as eslintPluginImport from "eslint-plugin-import";

import typescriptEslintPlugin from "@typescript-eslint/eslint-plugin";
import stylisticEslintPlugin from "@stylistic/eslint-plugin";
import eslintPluginModulesNewlines from "eslint-plugin-modules-newlines";
import globals from "globals";
import "eslint-import-resolver-typescript";
import type {
ESLint,
Linter
} from "eslint";

const configs: Linter.FlatConfig[] = [
{
files: ["**/*.ts"],
ignores: ["dist/**"],
languageOptions: {
parser: typescriptEslintParser as Linter.ParserModule,
sourceType: "module",
globals: {
...globals.browser,
...globals.node
},
parserOptions: {
project: "./tsconfig.json"
}
},
plugins: {
"@typescript-eslint": typescriptEslintPlugin,
"import": eslintPluginImport,
"modules-newlines": eslintPluginModulesNewlines,
"@stylistic": stylisticEslintPlugin as ESLint.Plugin
},
rules: {
...typescriptEslintPlugin.configs["eslint-recommended"]!.overrides[0]!.rules,
...typescriptEslintPlugin.configs["recommended"]!.rules,
...typescriptEslintPlugin.configs["recommended-type-checked"]!.rules,
"import/no-unresolved": "error",
"import/no-namespace": "error",
"modules-newlines/import-declaration-newline": "error",
"modules-newlines/export-declaration-newline": "error",
"@typescript-eslint/explicit-function-return-type": "error",
"@stylistic/indent": ["error", 2],
"@stylistic/quotes": ["error", "double"],
semi: "error",
"no-extra-semi": "error",
"@typescript-eslint/explicit-member-accessibility": "error"
},
settings: {
"import/resolver": {
typescript: {
alwaysTryTypes: true
}
}
}
}
];

export default configs;
10 changes: 10 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"id": "belyalov-commander",
"name": "Belyalov Commander",
"version": "0.1.0",
"minAppVersion": "0.15.0",
"description": "Note preview and management",
"author": "theotheo",
"authorUrl": "https://github.com/theotheo/",
"isDesktopOnly": false
}
Loading

0 comments on commit 6183314

Please sign in to comment.