up build process and names

This commit is contained in:
WFH Brian 2024-05-30 10:29:30 -04:00
parent fd926dbbfe
commit f4ae545b3b
3 changed files with 60 additions and 53 deletions

View file

@ -16,6 +16,24 @@ if you want to view the source, please visit the github repository of this plugi
const prod = (process.argv[2] === "production");
const copy_to_plugins = {
name: 'copy_to_plugins',
setup(build) {
build.onEnd(() => {
const plugin_path = path.join(process.env.OBSIDIAN_PLUGINS_PATH, "smart-connections-graph-view");
if (!fs.existsSync(plugin_path)) {
fs.mkdirSync(plugin_path);
}
fs.copyFileSync("./main.js", path.join(plugin_path, "main.js"));
fs.copyFileSync("./manifest.json", path.join(plugin_path, "manifest.json"));
fs.copyFileSync("./styles.css", path.join(plugin_path, "styles.css"));
console.log("Plugin built and copied to obsidian plugins folder");
});
}
};
const context = await esbuild.context({
banner: {
js: banner,
@ -36,26 +54,21 @@ const context = await esbuild.context({
"@lezer/common",
"@lezer/highlight",
"@lezer/lr",
...builtins],
...builtins
],
format: "cjs",
target: "es2018",
logLevel: "info",
sourcemap: prod ? false : "inline",
treeShaking: true,
outfile: "main.js",
plugins: [
copy_to_plugins
]
});
if (prod) {
if(!prod) await context.watch();
else {
await context.rebuild();
process.exit(0);
} else {
await context.watch();
// copy the built plugin to the obsidian plugins folder
if (!fs.existsSync(path.join(process.env.OBSIDIAN_PLUGINS_PATH, "smart-connections-graph-view"))) {
fs.mkdirSync(path.join(process.env.OBSIDIAN_PLUGINS_PATH, "smart-connections-graph-view"));
}
fs.copyFileSync("./main.js", path.join(process.env.OBSIDIAN_PLUGINS_PATH, "smart-connections-graph-view/main.js"));
fs.copyFileSync("./manifest.json", path.join(process.env.OBSIDIAN_PLUGINS_PATH, "smart-connections-graph-view/manifest.json"));
fs.copyFileSync("./styles.css", path.join(process.env.OBSIDIAN_PLUGINS_PATH, "smart-connections-graph-view/styles.css"));
}

28
main.js

File diff suppressed because one or more lines are too long

48
main.ts
View file

@ -3,11 +3,11 @@ import * as d3 from "d3";
import 'bootstrap/dist/css/bootstrap.min.css';
import 'bootstrap/dist/js/bootstrap.bundle.min.js';
interface MyPluginSettings {
interface ScGraphViewSettings {
mySetting: string;
}
const DEFAULT_SETTINGS: MyPluginSettings = {
const DEFAULT_SETTINGS: ScGraphViewSettings = {
mySetting: 'default'
}
@ -66,15 +66,15 @@ class MyItemView extends ItemView {
}
getViewType(): string {
return "My Item View";
return "Smart Graph View";
}
getDisplayText(): string {
return "My Item View";
return "Smart Graph View";
}
getIcon(): string {
return "dice";
return "git-fork";
}
// Function to update node appearance based on selection and highlight state
@ -631,9 +631,7 @@ class MyItemView extends ItemView {
console.log('Update already in progress. Skipping...');
return;
} else {
console.log('Update not in progress . Skipping...');
}
console.log('updating');
@ -676,7 +674,6 @@ class MyItemView extends ItemView {
}
return true;
});
console.log('Validated Links:', this.validatedLinks);
// Safeguard to prevent infinite loop
@ -757,7 +754,7 @@ class MyItemView extends ItemView {
that.app.workspace.trigger("hover-link", {
event,
source: 'D3',
source: 'Smart Graph',
hoverParent: this.parentElement,
targetEl: this,
linktext: d.id,
@ -1378,7 +1375,6 @@ class MyItemView extends ItemView {
}
}
/*
Main Colors
Menu text: #a3aecb
@ -1389,31 +1385,29 @@ class MyItemView extends ItemView {
SliderKnob: #f3ee5d
*/
export default class MyPlugin extends Plugin {
settings: MyPluginSettings;
export default class ScGraphView extends Plugin {
settings: ScGraphViewSettings;
async onload() {
await this.loadSettings();
// Register the new view
this.registerView("My Item View", (leaf: WorkspaceLeaf) => new MyItemView(leaf));
this.registerView("Smart Graph View", (leaf: WorkspaceLeaf) => new MyItemView(leaf));
// Register hover link source
this.registerHoverLinkSource('D3', {
display: 'D3 Hover Link Source',
defaultMod: true
});
// Register hover link source
this.registerHoverLinkSource('Smart Graph', {
display: 'Smart Graph Hover Link Source',
defaultMod: true
});
// This creates an icon in the left ribbon.
const ribbonIconEl = this.addRibbonIcon('dice', 'Smart Graph', (evt: MouseEvent) => {
const ribbonIconEl = this.addRibbonIcon('git-fork', 'Smart Graph', (evt: MouseEvent) => {
// Called when the user clicks the icon.
// Create a new leaf in the current workspace
let leaf = this.app.workspace.getLeaf(true);
// Set the new leaf's view to your custom view
leaf.setViewState({
type: "My Item View",
type: "Smart Graph View",
active: true,
});
})
@ -1434,7 +1428,7 @@ export default class MyPlugin extends Plugin {
// Set the new leaf's view to your custom view
leaf.setViewState({
type: "My Item View",
type: "Smart Graph View",
active: true,
});
}
@ -1449,7 +1443,7 @@ export default class MyPlugin extends Plugin {
// // Set the new leaf's view to your custom view
// leaf.setViewState({
// type: "My Item View",
// type: "Smart Graph View",
// active: true,
// });
// }
@ -1465,7 +1459,7 @@ export default class MyPlugin extends Plugin {
// Set the new leaf's view to your custom view
leaf.setViewState({
type: "My Item View",
type: "Smart Graph View",
active: true,
});
}
@ -1496,9 +1490,9 @@ export default class MyPlugin extends Plugin {
}
// class SampleSettingTab extends PluginSettingTab {
// plugin: MyPlugin;
// plugin: ScGraphView;
// constructor(app: App, plugin: MyPlugin) {
// constructor(app: App, plugin: ScGraphView) {
// super(app, plugin);
// this.plugin = plugin;
// }