Skip to content

Commit

Permalink
Add startup modules
Browse files Browse the repository at this point in the history
Signed-off-by: William So <polyipseity@gmail.com>
  • Loading branch information
polyipseity committed Sep 30, 2023
1 parent be981c7 commit 45f7560
Show file tree
Hide file tree
Showing 57 changed files with 1,238 additions and 252 deletions.
5 changes: 5 additions & 0 deletions .changeset/early-toys-shave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"obsidian-modules": minor
---

Add startup modules.
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ This file is automatically opened on first install. You can reopen it in setting
## Features

- Load JavaScript and TypeScript modules from the vault and the Internet on all platforms.
- Load modules at startup.
- No configuration needed.
- Resolves relative paths, vault paths, Markdown links, wikilinks, and external links.
- Loads Markdown files as code.
Expand Down Expand Up @@ -125,6 +126,18 @@ module.exports.variable = "string"
module.exports.default = 42
exports.abbreviatedForm = {}
```
- To create a startup module, export a function (supports async) to run at startup using `export default` or assigning to `module.exports` and add the module to plugin settings:
```JavaScript
// ES module-style
export default function() {
console.log("Hello world!")
}

// CommonJS-style
module.exports = function() {
console.log("Hello world!")
}
```
- The full API is available from [`sources/@types/obsidian-modules.ts`](sources/%40types/obsidian-modules.ts).

## Contributing
Expand All @@ -135,7 +148,6 @@ Contributions are welcome!

The todos here, ordered alphabetically, are things planned for the plugin. There are no guarantees that they will be completed. However, we are likely to accept contributions for them.

- Add startup modules.
- User-defined module aliases.
- Add bare module transformation support for more CDNs such as <https://cdn.jsdelivr.net>.
- Faster import analysis and transformation.
Expand Down
25 changes: 20 additions & 5 deletions assets/locales/af/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
"clear-cache": "Clear cache",
"open-documentation-changelog": "$t(generic.open, capitalize) $t(generic.documentations.changelog)",
"open-documentation-donate": "$t(generic.open, capitalize) $t(generic.documentations.donate)",
"open-documentation-readme": "$t(generic.open, capitalize) $t(generic.documentations.readme)"
"open-documentation-readme": "$t(generic.open, capitalize) $t(generic.documentations.readme)",
"reload-startup-modules": "Reload $t(generic.startup-module_other)"
},
"errors": {
"error-loading-module": "Error loading $t(generic.module): {{id}}",
"no-functions-exported": "No functions exported"
},
"generic": {
"case-insensitive": "case-insensitive",
Expand All @@ -17,22 +22,28 @@
"external-link": "$t(generic.external-link_one)",
"external-link_one": "external link",
"external-link_other": "external links",
"name": "name"
"module": "module",
"module_other": "modules",
"name": "name",
"startup-module": "startup $t(generic.module)",
"startup-module_other": "startup $t(generic.module_other)"
},
"name": "Modules",
"name": "$t(generic.module_other, capitalize)",
"settings": {
"Markdown-code-block-languages-to-load": "Markdown code block languages to load",
"Markdown-code-block-languages-to-load-description": "$t(generic.list-description, capitalize)",
"Markdown-code-block-languages-to-load-edit": "$t(generic.edit, capitalize)",
"Markdown-code-block-languages-to-load-edit-description": "$t(generic.case-insensitive, capitalize).",
"auto-reload-startup-modules": "Auto reload $t(generic.startup-module_other)",
"auto-reload-startup-modules-description": "Manually reload $t(generic.startup-module_other) via the $t(generic.command-palette).",
"documentation": "$t(generic.documentation, capitalize)",
"documentations": {
"changelog": "$t(generic.documentations.changelog, capitalize)",
"donate": "$t(generic.documentations.donate, capitalize)",
"readme": "$t(generic.documentations.readme, capitalize)"
},
"enable-external-links": "Enable $t(generic.external-link_other)",
"expose-internal-modules": "Expose internal modules",
"expose-internal-modules": "Expose internal $t(generic.module_other)",
"expose-internal-modules-description-HTML": "<code>obsidian</code>, <code>@codemirror/*</code>, <code>@lezer/*</code>…",
"import-timeout-HTML": "<code>import</code> $t(generic.timeout) (s)",
"import-timeout-description-HTML": "For avoiding <code>import</code> deadlocks. Set to 0 s for no $t(generic.timeout).",
Expand All @@ -45,6 +56,10 @@
"preloading-rules-description-HTML": "Required for using <code>require</code> (but not <code>require.import</code>). $t(generic.list-description, capitalize)",
"preloading-rules-edit": "$t(generic.edit, capitalize)",
"require-name": "Require $t(generic.name)",
"require-name-description-invalid": "Using the default as the specified $t(generic.name) is unavailable."
"require-name-description-invalid": "Using the default as the specified $t(generic.name) is unavailable.",
"startup-modules": "$t(generic.startup-module_other, capitalize)",
"startup-modules-description": "$t(generic.list-description, capitalize)",
"startup-modules-edit": "$t(generic.edit, capitalize)",
"startup-modules-edit-description": "Accepts all $t(generic.module) identifier formats. Loading order is random."
}
}
25 changes: 20 additions & 5 deletions assets/locales/am/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
"clear-cache": "Clear cache",
"open-documentation-changelog": "$t(generic.open, capitalize) $t(generic.documentations.changelog)",
"open-documentation-donate": "$t(generic.open, capitalize) $t(generic.documentations.donate)",
"open-documentation-readme": "$t(generic.open, capitalize) $t(generic.documentations.readme)"
"open-documentation-readme": "$t(generic.open, capitalize) $t(generic.documentations.readme)",
"reload-startup-modules": "Reload $t(generic.startup-module_other)"
},
"errors": {
"error-loading-module": "Error loading $t(generic.module): {{id}}",
"no-functions-exported": "No functions exported"
},
"generic": {
"case-insensitive": "case-insensitive",
Expand All @@ -17,22 +22,28 @@
"external-link": "$t(generic.external-link_one)",
"external-link_one": "external link",
"external-link_other": "external links",
"name": "name"
"module": "module",
"module_other": "modules",
"name": "name",
"startup-module": "startup $t(generic.module)",
"startup-module_other": "startup $t(generic.module_other)"
},
"name": "Modules",
"name": "$t(generic.module_other, capitalize)",
"settings": {
"Markdown-code-block-languages-to-load": "Markdown code block languages to load",
"Markdown-code-block-languages-to-load-description": "$t(generic.list-description, capitalize)",
"Markdown-code-block-languages-to-load-edit": "$t(generic.edit, capitalize)",
"Markdown-code-block-languages-to-load-edit-description": "$t(generic.case-insensitive, capitalize).",
"auto-reload-startup-modules": "Auto reload $t(generic.startup-module_other)",
"auto-reload-startup-modules-description": "Manually reload $t(generic.startup-module_other) via the $t(generic.command-palette).",
"documentation": "$t(generic.documentation, capitalize)",
"documentations": {
"changelog": "$t(generic.documentations.changelog, capitalize)",
"donate": "$t(generic.documentations.donate, capitalize)",
"readme": "$t(generic.documentations.readme, capitalize)"
},
"enable-external-links": "Enable $t(generic.external-link_other)",
"expose-internal-modules": "Expose internal modules",
"expose-internal-modules": "Expose internal $t(generic.module_other)",
"expose-internal-modules-description-HTML": "<code>obsidian</code>, <code>@codemirror/*</code>, <code>@lezer/*</code>…",
"import-timeout-HTML": "<code>import</code> $t(generic.timeout) (s)",
"import-timeout-description-HTML": "For avoiding <code>import</code> deadlocks. Set to 0 s for no $t(generic.timeout).",
Expand All @@ -45,6 +56,10 @@
"preloading-rules-description-HTML": "Required for using <code>require</code> (but not <code>require.import</code>). $t(generic.list-description, capitalize)",
"preloading-rules-edit": "$t(generic.edit, capitalize)",
"require-name": "Require $t(generic.name)",
"require-name-description-invalid": "Using the default as the specified $t(generic.name) is unavailable."
"require-name-description-invalid": "Using the default as the specified $t(generic.name) is unavailable.",
"startup-modules": "$t(generic.startup-module_other, capitalize)",
"startup-modules-description": "$t(generic.list-description, capitalize)",
"startup-modules-edit": "$t(generic.edit, capitalize)",
"startup-modules-edit-description": "Accepts all $t(generic.module) identifier formats. Loading order is random."
}
}
25 changes: 20 additions & 5 deletions assets/locales/ar/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
"clear-cache": "Clear cache",
"open-documentation-changelog": "$t(generic.open, capitalize) $t(generic.documentations.changelog)",
"open-documentation-donate": "$t(generic.open, capitalize) $t(generic.documentations.donate)",
"open-documentation-readme": "$t(generic.open, capitalize) $t(generic.documentations.readme)"
"open-documentation-readme": "$t(generic.open, capitalize) $t(generic.documentations.readme)",
"reload-startup-modules": "Reload $t(generic.startup-module_other)"
},
"errors": {
"error-loading-module": "Error loading $t(generic.module): {{id}}",
"no-functions-exported": "No functions exported"
},
"generic": {
"case-insensitive": "case-insensitive",
Expand All @@ -17,22 +22,28 @@
"external-link": "$t(generic.external-link_one)",
"external-link_one": "external link",
"external-link_other": "external links",
"name": "name"
"module": "module",
"module_other": "modules",
"name": "name",
"startup-module": "startup $t(generic.module)",
"startup-module_other": "startup $t(generic.module_other)"
},
"name": "Modules",
"name": "$t(generic.module_other, capitalize)",
"settings": {
"Markdown-code-block-languages-to-load": "Markdown code block languages to load",
"Markdown-code-block-languages-to-load-description": "$t(generic.list-description, capitalize)",
"Markdown-code-block-languages-to-load-edit": "$t(generic.edit, capitalize)",
"Markdown-code-block-languages-to-load-edit-description": "$t(generic.case-insensitive, capitalize).",
"auto-reload-startup-modules": "Auto reload $t(generic.startup-module_other)",
"auto-reload-startup-modules-description": "Manually reload $t(generic.startup-module_other) via the $t(generic.command-palette).",
"documentation": "$t(generic.documentation, capitalize)",
"documentations": {
"changelog": "$t(generic.documentations.changelog, capitalize)",
"donate": "$t(generic.documentations.donate, capitalize)",
"readme": "$t(generic.documentations.readme, capitalize)"
},
"enable-external-links": "Enable $t(generic.external-link_other)",
"expose-internal-modules": "Expose internal modules",
"expose-internal-modules": "Expose internal $t(generic.module_other)",
"expose-internal-modules-description-HTML": "<code>obsidian</code>, <code>@codemirror/*</code>, <code>@lezer/*</code>…",
"import-timeout-HTML": "<code>import</code> $t(generic.timeout) (s)",
"import-timeout-description-HTML": "For avoiding <code>import</code> deadlocks. Set to 0 s for no $t(generic.timeout).",
Expand All @@ -45,6 +56,10 @@
"preloading-rules-description-HTML": "Required for using <code>require</code> (but not <code>require.import</code>). $t(generic.list-description, capitalize)",
"preloading-rules-edit": "$t(generic.edit, capitalize)",
"require-name": "Require $t(generic.name)",
"require-name-description-invalid": "Using the default as the specified $t(generic.name) is unavailable."
"require-name-description-invalid": "Using the default as the specified $t(generic.name) is unavailable.",
"startup-modules": "$t(generic.startup-module_other, capitalize)",
"startup-modules-description": "$t(generic.list-description, capitalize)",
"startup-modules-edit": "$t(generic.edit, capitalize)",
"startup-modules-edit-description": "Accepts all $t(generic.module) identifier formats. Loading order is random."
}
}
25 changes: 20 additions & 5 deletions assets/locales/be/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
"clear-cache": "Clear cache",
"open-documentation-changelog": "$t(generic.open, capitalize) $t(generic.documentations.changelog)",
"open-documentation-donate": "$t(generic.open, capitalize) $t(generic.documentations.donate)",
"open-documentation-readme": "$t(generic.open, capitalize) $t(generic.documentations.readme)"
"open-documentation-readme": "$t(generic.open, capitalize) $t(generic.documentations.readme)",
"reload-startup-modules": "Reload $t(generic.startup-module_other)"
},
"errors": {
"error-loading-module": "Error loading $t(generic.module): {{id}}",
"no-functions-exported": "No functions exported"
},
"generic": {
"case-insensitive": "case-insensitive",
Expand All @@ -17,22 +22,28 @@
"external-link": "$t(generic.external-link_one)",
"external-link_one": "external link",
"external-link_other": "external links",
"name": "name"
"module": "module",
"module_other": "modules",
"name": "name",
"startup-module": "startup $t(generic.module)",
"startup-module_other": "startup $t(generic.module_other)"
},
"name": "Modules",
"name": "$t(generic.module_other, capitalize)",
"settings": {
"Markdown-code-block-languages-to-load": "Markdown code block languages to load",
"Markdown-code-block-languages-to-load-description": "$t(generic.list-description, capitalize)",
"Markdown-code-block-languages-to-load-edit": "$t(generic.edit, capitalize)",
"Markdown-code-block-languages-to-load-edit-description": "$t(generic.case-insensitive, capitalize).",
"auto-reload-startup-modules": "Auto reload $t(generic.startup-module_other)",
"auto-reload-startup-modules-description": "Manually reload $t(generic.startup-module_other) via the $t(generic.command-palette).",
"documentation": "$t(generic.documentation, capitalize)",
"documentations": {
"changelog": "$t(generic.documentations.changelog, capitalize)",
"donate": "$t(generic.documentations.donate, capitalize)",
"readme": "$t(generic.documentations.readme, capitalize)"
},
"enable-external-links": "Enable $t(generic.external-link_other)",
"expose-internal-modules": "Expose internal modules",
"expose-internal-modules": "Expose internal $t(generic.module_other)",
"expose-internal-modules-description-HTML": "<code>obsidian</code>, <code>@codemirror/*</code>, <code>@lezer/*</code>…",
"import-timeout-HTML": "<code>import</code> $t(generic.timeout) (s)",
"import-timeout-description-HTML": "For avoiding <code>import</code> deadlocks. Set to 0 s for no $t(generic.timeout).",
Expand All @@ -45,6 +56,10 @@
"preloading-rules-description-HTML": "Required for using <code>require</code> (but not <code>require.import</code>). $t(generic.list-description, capitalize)",
"preloading-rules-edit": "$t(generic.edit, capitalize)",
"require-name": "Require $t(generic.name)",
"require-name-description-invalid": "Using the default as the specified $t(generic.name) is unavailable."
"require-name-description-invalid": "Using the default as the specified $t(generic.name) is unavailable.",
"startup-modules": "$t(generic.startup-module_other, capitalize)",
"startup-modules-description": "$t(generic.list-description, capitalize)",
"startup-modules-edit": "$t(generic.edit, capitalize)",
"startup-modules-edit-description": "Accepts all $t(generic.module) identifier formats. Loading order is random."
}
}
25 changes: 20 additions & 5 deletions assets/locales/bg/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
"clear-cache": "Clear cache",
"open-documentation-changelog": "$t(generic.open, capitalize) $t(generic.documentations.changelog)",
"open-documentation-donate": "$t(generic.open, capitalize) $t(generic.documentations.donate)",
"open-documentation-readme": "$t(generic.open, capitalize) $t(generic.documentations.readme)"
"open-documentation-readme": "$t(generic.open, capitalize) $t(generic.documentations.readme)",
"reload-startup-modules": "Reload $t(generic.startup-module_other)"
},
"errors": {
"error-loading-module": "Error loading $t(generic.module): {{id}}",
"no-functions-exported": "No functions exported"
},
"generic": {
"case-insensitive": "case-insensitive",
Expand All @@ -17,22 +22,28 @@
"external-link": "$t(generic.external-link_one)",
"external-link_one": "external link",
"external-link_other": "external links",
"name": "name"
"module": "module",
"module_other": "modules",
"name": "name",
"startup-module": "startup $t(generic.module)",
"startup-module_other": "startup $t(generic.module_other)"
},
"name": "Modules",
"name": "$t(generic.module_other, capitalize)",
"settings": {
"Markdown-code-block-languages-to-load": "Markdown code block languages to load",
"Markdown-code-block-languages-to-load-description": "$t(generic.list-description, capitalize)",
"Markdown-code-block-languages-to-load-edit": "$t(generic.edit, capitalize)",
"Markdown-code-block-languages-to-load-edit-description": "$t(generic.case-insensitive, capitalize).",
"auto-reload-startup-modules": "Auto reload $t(generic.startup-module_other)",
"auto-reload-startup-modules-description": "Manually reload $t(generic.startup-module_other) via the $t(generic.command-palette).",
"documentation": "$t(generic.documentation, capitalize)",
"documentations": {
"changelog": "$t(generic.documentations.changelog, capitalize)",
"donate": "$t(generic.documentations.donate, capitalize)",
"readme": "$t(generic.documentations.readme, capitalize)"
},
"enable-external-links": "Enable $t(generic.external-link_other)",
"expose-internal-modules": "Expose internal modules",
"expose-internal-modules": "Expose internal $t(generic.module_other)",
"expose-internal-modules-description-HTML": "<code>obsidian</code>, <code>@codemirror/*</code>, <code>@lezer/*</code>…",
"import-timeout-HTML": "<code>import</code> $t(generic.timeout) (s)",
"import-timeout-description-HTML": "For avoiding <code>import</code> deadlocks. Set to 0 s for no $t(generic.timeout).",
Expand All @@ -45,6 +56,10 @@
"preloading-rules-description-HTML": "Required for using <code>require</code> (but not <code>require.import</code>). $t(generic.list-description, capitalize)",
"preloading-rules-edit": "$t(generic.edit, capitalize)",
"require-name": "Require $t(generic.name)",
"require-name-description-invalid": "Using the default as the specified $t(generic.name) is unavailable."
"require-name-description-invalid": "Using the default as the specified $t(generic.name) is unavailable.",
"startup-modules": "$t(generic.startup-module_other, capitalize)",
"startup-modules-description": "$t(generic.list-description, capitalize)",
"startup-modules-edit": "$t(generic.edit, capitalize)",
"startup-modules-edit-description": "Accepts all $t(generic.module) identifier formats. Loading order is random."
}
}
Loading

0 comments on commit 45f7560

Please sign in to comment.