Skip to main content

Module init_script

Module init_script 

Source
Expand description

User init.ts support.

At startup Fresh reads ~/.config/fresh/init.ts (if present) and feeds it through the existing plugin pipeline as a plugin named init.ts. This is the same code path as “Load Plugin from Buffer”, so reload, unload, and per-plugin registration tagging are free.

Recovery: a lightweight crash fuse at ~/.config/fresh/logs/init.crashes counts consecutive init.ts failures within a rolling window. After N failures the next launch auto-skips init.ts until the user fixes or removes it. A successful evaluation clears the counter.

Structs§

CheckDiagnostic
CheckReport
Result of fresh --cmd init check.

Enums§

CheckSeverity
InitOutcome
Outcome of [autoload].
LoadDecision
Pre-flight for the caller: check fuse, return either the source to load or an outcome explaining why we’re not loading.

Constants§

INIT_PLUGIN_NAME
Plugin name Fresh uses when loading init.ts — stable so hot-reload works.
STARTER_TEMPLATE
Starter content written by init: Edit init.ts when the file doesn’t exist yet. Every example is commented out — an empty init() body is valid and users un-comment what they want.

Functions§

check
decide_load
describe
Human-readable summary for the status bar / logs.
ensure_starter
Ensure ~/.config/fresh/init.ts exists. If absent, writes the starter template. Also refreshes types/fresh.d.ts + tsconfig.json so the template’s /// <reference path=... directive resolves and getEditor() type-checks in any TS-aware editor. Returns the (possibly newly-created) init.ts path.
init_ts_path
Resolve ~/.config/fresh/init.ts.
read_init_script
Read init.ts from disk. Returns Ok(None) when the file simply doesn’t exist.
record_success
Called after init.ts finishes cleanly. Resets the crash-fuse counter so the next launch starts from zero.
refresh_types_scaffolding
Refresh ~/.config/fresh/types/fresh.d.ts from the embedded copy and write tsconfig.json if it isn’t already present.
should_skip
Decide, without touching disk for the source, whether init.ts loading should run at all.
write_plugin_declarations
Write <config_dir>/types/plugins.d.ts from the .d.ts emit of each loaded plugin. The editor calls this after scanning every plugin directory, so by the time init.ts is evaluated the ambient FreshPluginRegistry is fully populated and editor.getPluginApi("dashboard") resolves to the typed overload.