ab346fa66a
* feat(plugins): v5 plugin system * feat(plugins): explorer as community plugin * feat(plugins): graph as community plugin * chore: update package-lock.json * chore: update package-lock.json * docs: updated plugin-specific docs * chore: update package-lock.json * chore: update package-lock.json * chore: update package-lock.json * Implement Git-based plugin system with dogfooding for community plugins - Remove npm dependencies for @quartz-community/* plugins - Add gitLoader.ts for installing plugins from GitHub - Update quartz.layout.ts to import from .quartz/plugins/ - Add install-plugins.ts script for prebuild hook - Add .quartz/ to .gitignore * Add comprehensive Git-based plugin CLI with lockfile support - Create quartz.lock.json format for tracking exact plugin commits - Add 'npx quartz plugin' commands: install, add, remove, update, list, restore - Plugin state is fully reproducible via lockfile - No npm dependencies required for community plugins * Fix TypeScript errors in git-installed plugins - Install @quartz-community/types as devDependency - Fix plugin imports to define types locally - Fix search inline script fetchData bug - Format code with prettier * fix(types): install types from github * docs: updated plugin-specific docs * Update Dockerfile and add CI/CD documentation - Add plugin install step to Dockerfile - Create docs/ci-cd.md with pipeline configuration guide * Update GitHub Actions workflows for v5 branch and Git-based plugins - Change branch references from v4 to v5 - Add plugin caching to speed up builds - Use 'npx quartz plugin install' instead of 'restore' - Update Docker workflow branch trigger * Update quartz.lock.json with fixed plugin versions * fix(docker): install command * docs: add plugin migration analysis document Comprehensive analysis of which Quartz v4 components and plugins can be migrated to separate repositories, including: - Component analysis (25 components) - Plugin analysis (transformers, emitters, filters) - Migration strategies for different plugin types - Lessons learned from Explorer/Graph/Search migrations - Recommended migration order * chore: updated plugins * chore: updated plugins * chore: updated dependencies * chore: updated plugins * chore: updated plugins * chore: updated plugins * chore: updated plugins * chore: updated plugins * chore: updated plugins * chore: updated plugins * chore: updated plugins * chore: updated plugins * chore: tsconfig * feat: build installed plugins * chore: updated plugins * chore: updated plugins * chore: update explorer plugin with duplication fix * docs: Quartz v5 * chore: update graph plugin with navigation fix * fix: update explorer plugin with toggle fix * fix: update explorer plugin - ensure toggle buttons always work * fix: create plugin components once to prevent duplicate script registration * chore: updated plugins * chore: updated plugins * feat: migrate 7 feature components to community plugins (Phase B) Migrate ArticleTitle, TagList, PageTitle, Darkmode, ReaderMode, ContentMeta, and Footer from internal components to community plugins. Update layout to use Plugin.X() pattern, remove internal component files and their styles/scripts. Add MIGRATION_TASKS.md documenting the full migration roadmap. * chore: updated plugins * refactor: delete 6 internal component duplicates (Phase A) Remove Backlinks, Breadcrumbs, RecentNotes, Search, TableOfContents, Comments, and OverflowList — all replaced by community plugins. Delete associated styles (6) and scripts (3). Switch layout to use Plugin.Breadcrumbs() instead of Component.Breadcrumbs(). * refactor: unify QuartzComponent type to structural interface (Phase C) - Changed QuartzComponent from ComponentType<QuartzComponentProps> to callable type ((props: QuartzComponentProps) => any) - Added optional displayName property for better debugging - Removed ComponentType import from preact - Removed all 13 'as QuartzComponent' type casts from quartz.layout.ts - Community plugin components now directly assignable without casts * feat: add PageType plugin infrastructure (Phase D Step 4) * feat: add PageTypePluginEntry for cross-boundary type compatibility Introduce PageTypePluginEntry with never[] parameter types to accept both internal and community PageType plugins in config arrays without casts, working around branded FullSlug contravariance mismatch. * refactor: update dispatcher to cast PageTypePluginEntry at boundary Add getPageTypes() helper that casts config's PageTypePluginEntry[] to QuartzPageTypePluginInstance[] in one place. Cast VirtualPage.slug to FullSlug at emitPage/defaultProcessedContent call sites. * feat: integrate community PageType plugins (Phase D Step 6) Replace old page-rendering emitters with PageTypeDispatcher emitter and pageTypes array. Restructure quartz.layout.ts from three separate exports to unified layout object with defaults and byPageType record. Install content-page, folder-page, tag-page community plugins. * refactor: delete old page-rendering emitters Remove ContentPage, FolderPage, TagPage, and NotFoundPage emitters now replaced by community PageType plugins and the PageTypeDispatcher. * refactor: remove migrated page body components Delete Content, FolderContent, TagContent page components now provided by community PageType plugins. Update components barrel export. * fix: update lockfile to fixed folder-page and tag-page commits Points to commits that remove duplicate PageList/SortFn re-exports, fixing TS2300 duplicate identifier errors in generated plugin index. * chore: updated plugins * fix: populate ctx.trie in PageTypeDispatcher before rendering Components like FolderContent depend on ctx.trie for folder hierarchy. The dispatcher now lazily initializes it via trieFromAllFiles in emit and force-rebuilds it in partialEmit to reflect file changes. * chore: update lockfile to fixed folder-page commit * chore: updated plugins * chore: update explorer plugin to fix SPA folder navigation * feat: extract transformers to community plugins and fix type compatibility - Delete 12 internal transformer files (keep FrontMatter as internal) - Switch quartz.config.ts to use ExternalPlugin.* for all transformers - Align branded types with @quartz-community/types (_brand, FullSlug etc.) - Add vfile DataMap augmentations for fields from extracted transformers - Update all 29 plugins to @quartz-community/types v0.2.1 * Migrate filters to external plugins (remove-draft, explicit-publish) Delete internal RemoveDrafts and ExplicitPublish filter implementations, install them as community plugins, and update quartz.config.ts to use ExternalPlugin.RemoveDrafts(). * Migrate emitters to external plugins (alias-redirects, cname, favicon, content-index, og-image) * refactor: remove inline scripts/styles migrated to plugins Delete dead code: callout, checkbox, mermaid inline scripts and styles are now bundled by the obsidian-flavored-markdown plugin. Clipboard script and styles moved to the syntax-highlighting plugin. listPage.scss was unreferenced. Body.tsx simplified to a pure layout wrapper. * refactor: consolidate utils to re-export from @quartz-community/utils * fix: use dangerouslySetInnerHTML for inline CSS to prevent HTML-escaping Preact was escaping & characters in SCSS-compiled CSS (e.g. & nesting) into &, breaking CSS rules. Using dangerouslySetInnerHTML bypasses the escaping, matching how browsers expect style element content. * chore: update plugins with inline script transpilation fix * chore: updated plugins * docs: update plugin API sections for v5 community plugins * docs: rewrite documentation for v5 plugin system Update feature docs, hosting, CI/CD, getting started, configuration, layout, architecture, creating components, making plugins, and migration guide to reflect the v5 community plugin architecture. * docs: fix outdated v4 references in documentation * chore: remove completed migration planning docs * chore: updated plugins * chore: cleanup * chore: cleanup * chore: bump version to 5.0.0 * chore: updated dependencies * feat: integrate CanvasPage plugin with types, assets, config, layout, and documentation * chore: updated dependencies * chore: updated dependencies * chore: updated linter * chore: update canvas-page plugin to c942fcb * chore: updated plugins * chore: update canvas-page plugin to f88f1b9 * chore: updated plugins * chore: update canvas-page plugin to 079304c * chore: updated plugins * chore: canvas layout * chore: update canvas-page plugin to 38d49e1 * chore: updated plugins * chore: update canvas-page plugin to 505c099 * chore: updated plugins * chore: updated plugins * fix: Obsidian flavored markdown * fix: Obsidian flavored markdown * fix: Obsidian flavored markdown * chore: cleanup * chore: updated plugins * feat: configuration files * feat: Quartz TUI * feat(tui): YAML configuration * chore: tsup * chore: tsup * feat: support array categories in plugin manifests Plugins like note-properties export both transformer and component functionality. Allow PluginManifest.category to be a single value or an array, with config-loader resolving to the first processing category (transformer/filter/emitter/pageType) for dispatch. * refactor: remove built-in FrontMatter transformer Frontmatter processing is now handled by the note-properties plugin, which provides the same YAML/TOML parsing plus link extraction and a visual properties panel. The built-in transformer is no longer needed. * feat: add note-properties plugin to default configuration Register note-properties as the first plugin (order 5) in both the user config and the default config. Placed in beforeBody layout zone with priority 15 (between article-title at 10 and content-meta at 20). * docs: add plugin management strategy and syncer v5 notes Document the plugin management system design decisions and provide implementation guidance for the Quartz Syncer v5 integration. * feat: add bases-page plugin to default configuration Enable Obsidian Bases (.base) file support with bases page type and layout entry in both user and default config. * docs: update syncer notes with bases-page, note-properties, and spacer Add all three new plugins to the quick reference table (40 total). Add content, canvas, and bases page types to byPageType documentation. * chore: updated plugins * fix: update CI to Node 24 and regenerate lockfiles for clean install * fix: resolve type errors for CI checks * chore: updated plugins * chore: updated plugins * fix: plugin mapping from configuration * fix: CI * fix: CI * docs: rewrite Frontmatter documentation for note-properties plugin * chore: updated plugins * docs: Quartz v5 * chore: updated plugins * chore: updated plugins * refactor: extract TUI to standalone plugin repository * chore: linting * docs: Quartz v5 * feat: update and upgrade commands * chore: updated plugins * chore: updated plugins * chore: cleanup * chore: cleanup * chore: cleanup * chore: cleanup * chore: cleanup * fix: layout group priority * fix: view classes * fix: include virtual pages in content index for explorer visibility * docs: add board, gallery, and cards view examples to navigation page * chore: updated plugins * fix: include virtualPages in worker serializable build context * fix: set relativePath on virtual pages to prevent explorer crash * fix: exclude 404 * fix(links): virtual page links * fix(links): virtual page transclusion * docs: architecture overview * fix: only call scripts one per page * fix: type error in component registry instantiate method * fix: left layout order * fix(layout): remove tag-list by default * docs(plugins): updated plugin list defaults * fix(layout): priorities * feat: add PageFrame system for custom page layouts * feat: integrate PageFrame into rendering pipeline * feat: add frame resolution to page type dispatcher and config loader * style: add CSS grid overrides for full-width and minimal page frames * feat: set minimal frame for 404 and update canvas-page plugin * docs: add PageFrame system to architecture overview * fix: wrap frame.render() in array to satisfy Body children type * chore: format * fix: use absolute asset paths for 404 page so it works in subdirectories * fix(layout): priorities * docs: page frames * feat: add FrameRegistry for plugin-provided page frames Plugins can now register custom page frames via their manifest's 'frames' field. Frames are loaded alongside components during plugin initialization and resolved by name at render time with fallback to built-in frames. * feat(layout): page frames * fix(layout): linting * fix: inject frame CSS into page so plugin-provided frames render correctly * chore: updated plugins * chore: updated plugins * chore: updated plugins * chore: updated plugins * docs: canvas * chore: updated plugins * chore: updated plugins * chore: updated plugins * feat: add TreeTransform hook, fix multi-category plugins, and resolve cross-plugin dependencies - Add TreeTransform type and treeTransforms hook to pageType plugins, enabling render-time HAST tree mutations (e.g. bases-page inline codeblock resolution) - Fix config-loader to push multi-category plugins into ALL matching processing buckets instead of only the first match - Add side-effect import for component-only plugins so view registrations (e.g. leaflet-map via globalThis ViewRegistry) execute at load time - Add npm prune --omit=dev and cross-plugin peer dependency symlinking to buildPlugin() to prevent duplicate-singleton issues from nested node_modules * chore: format * chore: test docs * chore: updated plugins * fix: prevent HTML-escaping of inline style and script content in htmlToJsx Add dangerouslySetInnerHTML overrides for <style> and <script> elements so that CSS/JS injected by tree transforms is not HTML-escaped during preact-render-to-string serialization. * chore: update plugin lockfile for htmlToJsx migration * chore: update leaflet-map plugin (fix deferred L.Control) * chore: updated plugins * chore: updated plugins * chore: updated plugins * chore: updated plugins * chore: updated plugins * chore: updated plugins * chore: updated plugins * chore: test npx quartz upgrade * feat(templates): add obsidian, ttrpg, blog templates * docs: move bases * docs: removed leaflet demo * feat(cli): configure baseUrl during create * docs: updated cli commands * docs: updated documentation for v5 * feat(cli): prune and resolve * chore: rebuild lockfile * docs: cli documentation * docs: plugin development and setup guide * chore: deleted redundant files * fix(build): fallback config * chore: updated lockfile * docs: removed outdated v3 setup * feat(cli): allow non-default branch plugins * docs: install branch commands * feat(cli): allow local plugins * docs: install local commands * feat: add render event type and listener for in-place DOM re-initialization * docs: add EncryptedPages plugin documentation * docs: add encrypted pages live demo page - New password-protected demo page (password: quartz) showing the plugin in action - Link to demo from EncryptedPages plugin page with password hint callout * feat: add encrypted-pages plugin to all templates - Enabled by default in default, obsidian, and ttrpg templates - Disabled by default in blog template * chore: updated plugins * chore: updated layouts * chore: updated plugins * feat: stacked pages * feat: added stacked page panes * docs: touch-ups
1030 lines
32 KiB
JavaScript
1030 lines
32 KiB
JavaScript
import fs from "fs"
|
|
import path from "path"
|
|
import { execSync } from "child_process"
|
|
import { styleText } from "util"
|
|
import {
|
|
readPluginsJson,
|
|
writePluginsJson,
|
|
readLockfile,
|
|
writeLockfile,
|
|
extractPluginName,
|
|
readManifestFromPackageJson,
|
|
parseGitSource,
|
|
getGitCommit,
|
|
PLUGINS_DIR,
|
|
LOCKFILE_PATH,
|
|
isLocalSource,
|
|
} from "./plugin-data.js"
|
|
|
|
const INTERNAL_EXPORTS = new Set(["manifest", "default"])
|
|
|
|
function buildPlugin(pluginDir, name) {
|
|
try {
|
|
console.log(styleText("cyan", ` → ${name}: installing dependencies...`))
|
|
execSync("npm install", { cwd: pluginDir, stdio: "ignore" })
|
|
console.log(styleText("cyan", ` → ${name}: building...`))
|
|
execSync("npm run build", { cwd: pluginDir, stdio: "ignore" })
|
|
// Remove devDependencies after build — they are no longer needed and their
|
|
// presence can cause duplicate-singleton issues when a plugin ships its own
|
|
// copy of a shared dependency (e.g. bases-page's ViewRegistry).
|
|
execSync("npm prune --omit=dev", { cwd: pluginDir, stdio: "ignore" })
|
|
// Symlink any peerDependencies that are co-installed Quartz plugins so that
|
|
// Node's module resolution finds the host copy instead of a stale nested one.
|
|
linkPeerPlugins(pluginDir)
|
|
return true
|
|
} catch (error) {
|
|
console.log(styleText("red", ` ✗ ${name}: build failed`))
|
|
return false
|
|
}
|
|
}
|
|
|
|
function needsBuild(pluginDir) {
|
|
const distDir = path.join(pluginDir, "dist")
|
|
return !fs.existsSync(distDir)
|
|
}
|
|
|
|
/**
|
|
* After pruning devDependencies, peerDependencies that reference other Quartz
|
|
* plugins (e.g. @quartz-community/bases-page) won't be installed as npm
|
|
* packages — they're loaded by v5 as sibling plugins. To make Node's module
|
|
* resolution work, we symlink those peers to the co-installed plugin directory.
|
|
*/
|
|
function linkPeerPlugins(pluginDir) {
|
|
const pkgPath = path.join(pluginDir, "package.json")
|
|
if (!fs.existsSync(pkgPath)) return
|
|
|
|
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"))
|
|
const peers = pkg.peerDependencies ?? {}
|
|
|
|
for (const peerName of Object.keys(peers)) {
|
|
// Only handle @quartz-community scoped packages — those are Quartz plugins
|
|
if (!peerName.startsWith("@quartz-community/")) continue
|
|
|
|
// Check if this peer is already satisfied (e.g. installed as a regular dep)
|
|
const peerNodeModulesPath = path.join(pluginDir, "node_modules", ...peerName.split("/"))
|
|
if (fs.existsSync(peerNodeModulesPath)) continue
|
|
|
|
// Find the sibling plugin by its npm package name
|
|
const siblingPlugin = findPluginByPackageName(peerName)
|
|
if (!siblingPlugin) continue
|
|
|
|
// Create the scoped directory if needed
|
|
const scopeDir = path.join(pluginDir, "node_modules", peerName.split("/")[0])
|
|
fs.mkdirSync(scopeDir, { recursive: true })
|
|
|
|
// Create a relative symlink to the sibling plugin
|
|
const target = path.relative(scopeDir, siblingPlugin)
|
|
fs.symlinkSync(target, peerNodeModulesPath, "dir")
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Search installed plugins for one whose package.json "name" matches the given
|
|
* npm package name (e.g. "@quartz-community/bases-page").
|
|
*/
|
|
function findPluginByPackageName(packageName) {
|
|
if (!fs.existsSync(PLUGINS_DIR)) return null
|
|
|
|
const plugins = fs.readdirSync(PLUGINS_DIR).filter((entry) => {
|
|
const entryPath = path.join(PLUGINS_DIR, entry)
|
|
return fs.statSync(entryPath).isDirectory()
|
|
})
|
|
|
|
for (const pluginDirName of plugins) {
|
|
const pkgPath = path.join(PLUGINS_DIR, pluginDirName, "package.json")
|
|
if (!fs.existsSync(pkgPath)) continue
|
|
try {
|
|
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"))
|
|
if (pkg.name === packageName) {
|
|
return path.join(PLUGINS_DIR, pluginDirName)
|
|
}
|
|
} catch {}
|
|
}
|
|
return null
|
|
}
|
|
|
|
function parseExportsFromDts(content) {
|
|
const exports = []
|
|
const exportMatches = content.matchAll(/export\s*{\s*([^}]+)\s*}(?:\s*from\s*['"]([^'"]+)['"])?/g)
|
|
for (const match of exportMatches) {
|
|
const fromModule = match[2]
|
|
if (fromModule?.startsWith("@")) continue
|
|
|
|
const names = match[1]
|
|
.split(",")
|
|
.map((n) => n.trim())
|
|
.filter(Boolean)
|
|
for (const name of names) {
|
|
const cleanName = name.split(" as ").pop()?.trim() || name.trim()
|
|
if (cleanName && !cleanName.startsWith("_") && !INTERNAL_EXPORTS.has(cleanName)) {
|
|
const finalName = cleanName.replace(/^type\s+/, "")
|
|
if (name.includes("type ")) {
|
|
exports.push(`type ${finalName}`)
|
|
} else {
|
|
exports.push(finalName)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return exports
|
|
}
|
|
|
|
async function regeneratePluginIndex() {
|
|
if (!fs.existsSync(PLUGINS_DIR)) return
|
|
|
|
const plugins = fs.readdirSync(PLUGINS_DIR).filter((name) => {
|
|
const pluginPath = path.join(PLUGINS_DIR, name)
|
|
return fs.statSync(pluginPath).isDirectory()
|
|
})
|
|
|
|
const exports = []
|
|
|
|
for (const pluginName of plugins) {
|
|
const pluginDir = path.join(PLUGINS_DIR, pluginName)
|
|
const distIndex = path.join(pluginDir, "dist", "index.d.ts")
|
|
|
|
if (!fs.existsSync(distIndex)) continue
|
|
|
|
const dtsContent = fs.readFileSync(distIndex, "utf-8")
|
|
const exportedNames = parseExportsFromDts(dtsContent)
|
|
|
|
if (exportedNames.length > 0) {
|
|
const namedExports = exportedNames.filter((e) => !e.startsWith("type "))
|
|
const typeExports = exportedNames.filter((e) => e.startsWith("type ")).map((e) => e.slice(5))
|
|
|
|
if (namedExports.length > 0) {
|
|
exports.push(`export { ${namedExports.join(", ")} } from "./${pluginName}"`)
|
|
}
|
|
if (typeExports.length > 0) {
|
|
exports.push(`export type { ${typeExports.join(", ")} } from "./${pluginName}"`)
|
|
}
|
|
}
|
|
}
|
|
|
|
const indexContent = exports.join("\n") + "\n"
|
|
const indexPath = path.join(PLUGINS_DIR, "index.ts")
|
|
fs.writeFileSync(indexPath, indexContent)
|
|
}
|
|
|
|
export async function handlePluginInstall() {
|
|
const lockfile = readLockfile()
|
|
|
|
if (!lockfile) {
|
|
console.log(
|
|
styleText("yellow", "⚠ No quartz.lock.json found. Run 'npx quartz plugin add <repo>' first."),
|
|
)
|
|
return
|
|
}
|
|
|
|
if (!fs.existsSync(PLUGINS_DIR)) {
|
|
fs.mkdirSync(PLUGINS_DIR, { recursive: true })
|
|
}
|
|
|
|
console.log(styleText("cyan", "→ Installing plugins from lockfile..."))
|
|
let installed = 0
|
|
let failed = 0
|
|
const pluginsToBuild = []
|
|
|
|
for (const [name, entry] of Object.entries(lockfile.plugins)) {
|
|
const pluginDir = path.join(PLUGINS_DIR, name)
|
|
|
|
// Local plugin: ensure symlink exists
|
|
if (entry.commit === "local") {
|
|
try {
|
|
if (fs.existsSync(pluginDir)) {
|
|
const stat = fs.lstatSync(pluginDir)
|
|
if (stat.isSymbolicLink() && fs.readlinkSync(pluginDir) === entry.resolved) {
|
|
console.log(styleText("gray", ` ✓ ${name} (local) already linked`))
|
|
installed++
|
|
continue
|
|
}
|
|
// Wrong target or not a symlink — remove and re-link
|
|
if (stat.isSymbolicLink()) fs.unlinkSync(pluginDir)
|
|
else fs.rmSync(pluginDir, { recursive: true })
|
|
}
|
|
if (!fs.existsSync(entry.resolved)) {
|
|
console.log(styleText("red", ` ✗ ${name}: local path missing: ${entry.resolved}`))
|
|
failed++
|
|
continue
|
|
}
|
|
fs.mkdirSync(path.dirname(pluginDir), { recursive: true })
|
|
fs.symlinkSync(entry.resolved, pluginDir, "dir")
|
|
console.log(styleText("green", ` ✓ ${name} (local) linked`))
|
|
pluginsToBuild.push({ name, pluginDir })
|
|
installed++
|
|
} catch {
|
|
console.log(styleText("red", ` ✗ ${name}: failed to link local path`))
|
|
failed++
|
|
}
|
|
continue
|
|
}
|
|
|
|
if (fs.existsSync(pluginDir)) {
|
|
try {
|
|
const currentCommit = getGitCommit(pluginDir)
|
|
if (currentCommit === entry.commit && !needsBuild(pluginDir)) {
|
|
console.log(
|
|
styleText("gray", ` ✓ ${name}@${entry.commit.slice(0, 7)} already installed`),
|
|
)
|
|
installed++
|
|
continue
|
|
}
|
|
if (currentCommit !== entry.commit) {
|
|
console.log(styleText("cyan", ` → ${name}: updating to ${entry.commit.slice(0, 7)}...`))
|
|
const fetchRef = entry.ref ? ` ${entry.ref}` : ""
|
|
execSync(`git fetch --depth 1 origin${fetchRef}`, { cwd: pluginDir, stdio: "ignore" })
|
|
execSync(`git reset --hard ${entry.commit}`, { cwd: pluginDir, stdio: "ignore" })
|
|
}
|
|
pluginsToBuild.push({ name, pluginDir })
|
|
installed++
|
|
} catch {
|
|
console.log(styleText("red", ` ✗ ${name}: failed to update`))
|
|
failed++
|
|
}
|
|
} else {
|
|
try {
|
|
console.log(styleText("cyan", ` → ${name}: cloning...`))
|
|
const branchArg = entry.ref ? ` --branch ${entry.ref}` : ""
|
|
execSync(`git clone --depth 1${branchArg} ${entry.resolved} ${pluginDir}`, {
|
|
stdio: "ignore",
|
|
})
|
|
if (entry.commit !== "unknown") {
|
|
execSync(`git fetch --depth 1 origin ${entry.commit}`, {
|
|
cwd: pluginDir,
|
|
stdio: "ignore",
|
|
})
|
|
execSync(`git checkout ${entry.commit}`, { cwd: pluginDir, stdio: "ignore" })
|
|
}
|
|
console.log(styleText("green", ` ✓ ${name}@${entry.commit.slice(0, 7)}`))
|
|
pluginsToBuild.push({ name, pluginDir })
|
|
installed++
|
|
} catch {
|
|
console.log(styleText("red", ` ✗ ${name}: failed to clone`))
|
|
failed++
|
|
}
|
|
}
|
|
}
|
|
|
|
if (pluginsToBuild.length > 0) {
|
|
console.log()
|
|
console.log(styleText("cyan", "→ Building plugins..."))
|
|
for (const { name, pluginDir } of pluginsToBuild) {
|
|
if (!buildPlugin(pluginDir, name)) {
|
|
failed++
|
|
installed--
|
|
} else {
|
|
console.log(styleText("green", ` ✓ ${name} built`))
|
|
}
|
|
}
|
|
}
|
|
|
|
await regeneratePluginIndex()
|
|
|
|
console.log()
|
|
if (failed === 0) {
|
|
console.log(styleText("green", `✓ Installed ${installed} plugin(s)`))
|
|
} else {
|
|
console.log(styleText("yellow", `⚠ Installed ${installed} plugin(s), ${failed} failed`))
|
|
}
|
|
}
|
|
|
|
export async function handlePluginAdd(sources) {
|
|
let lockfile = readLockfile()
|
|
if (!lockfile) {
|
|
lockfile = { version: "1.0.0", plugins: {} }
|
|
}
|
|
|
|
if (!fs.existsSync(PLUGINS_DIR)) {
|
|
fs.mkdirSync(PLUGINS_DIR, { recursive: true })
|
|
}
|
|
|
|
const addedPlugins = []
|
|
|
|
for (const source of sources) {
|
|
try {
|
|
const { name, url, ref, local } = parseGitSource(source)
|
|
const pluginDir = path.join(PLUGINS_DIR, name)
|
|
|
|
if (fs.existsSync(pluginDir)) {
|
|
console.log(styleText("yellow", `⚠ ${name} already exists. Use 'update' to refresh.`))
|
|
continue
|
|
}
|
|
|
|
if (local) {
|
|
// Local path: create symlink instead of git clone
|
|
const resolvedPath = path.resolve(url)
|
|
if (!fs.existsSync(resolvedPath)) {
|
|
console.log(styleText("red", `✗ Local path does not exist: ${resolvedPath}`))
|
|
continue
|
|
}
|
|
console.log(styleText("cyan", `→ Adding ${name} from local path ${resolvedPath}...`))
|
|
fs.mkdirSync(path.dirname(pluginDir), { recursive: true })
|
|
fs.symlinkSync(resolvedPath, pluginDir, "dir")
|
|
lockfile.plugins[name] = {
|
|
source,
|
|
resolved: resolvedPath,
|
|
commit: "local",
|
|
installedAt: new Date().toISOString(),
|
|
}
|
|
addedPlugins.push({ name, pluginDir, source })
|
|
console.log(styleText("green", `✓ Added ${name} (local symlink)`))
|
|
} else {
|
|
console.log(styleText("cyan", `→ Adding ${name} from ${url}...`))
|
|
|
|
if (ref) {
|
|
execSync(`git clone --depth 1 --branch ${ref} ${url} ${pluginDir}`, { stdio: "ignore" })
|
|
} else {
|
|
execSync(`git clone --depth 1 ${url} ${pluginDir}`, { stdio: "ignore" })
|
|
}
|
|
|
|
const commit = getGitCommit(pluginDir)
|
|
lockfile.plugins[name] = {
|
|
source,
|
|
resolved: url,
|
|
commit,
|
|
...(ref && { ref }),
|
|
installedAt: new Date().toISOString(),
|
|
}
|
|
|
|
addedPlugins.push({ name, pluginDir, source })
|
|
console.log(styleText("green", `✓ Added ${name}@${commit.slice(0, 7)}`))
|
|
}
|
|
} catch (error) {
|
|
console.log(styleText("red", `✗ Failed to add ${source}: ${error}`))
|
|
}
|
|
}
|
|
|
|
if (addedPlugins.length > 0) {
|
|
console.log()
|
|
console.log(styleText("cyan", "→ Building plugins..."))
|
|
for (const { name, pluginDir } of addedPlugins) {
|
|
if (buildPlugin(pluginDir, name)) {
|
|
console.log(styleText("green", ` ✓ ${name} built`))
|
|
}
|
|
}
|
|
await regeneratePluginIndex()
|
|
}
|
|
|
|
writeLockfile(lockfile)
|
|
const pluginsJson = readPluginsJson()
|
|
if (pluginsJson?.plugins) {
|
|
for (const { pluginDir, source } of addedPlugins) {
|
|
const manifest = readManifestFromPackageJson(pluginDir)
|
|
const newEntry = {
|
|
source,
|
|
enabled: manifest?.defaultEnabled ?? true,
|
|
options: manifest?.defaultOptions ?? {},
|
|
order: manifest?.defaultOrder ?? 50,
|
|
}
|
|
|
|
if (manifest?.components) {
|
|
const firstComponentKey = Object.keys(manifest.components)[0]
|
|
const comp = manifest.components[firstComponentKey]
|
|
if (comp?.defaultPosition) {
|
|
newEntry.layout = {
|
|
position: comp.defaultPosition,
|
|
priority: comp.defaultPriority ?? 50,
|
|
display: "all",
|
|
}
|
|
}
|
|
}
|
|
|
|
pluginsJson.plugins.push(newEntry)
|
|
}
|
|
writePluginsJson(pluginsJson)
|
|
}
|
|
console.log()
|
|
console.log(styleText("gray", "Updated quartz.lock.json"))
|
|
}
|
|
|
|
export async function handlePluginRemove(names) {
|
|
const lockfile = readLockfile()
|
|
if (!lockfile) {
|
|
console.log(styleText("yellow", "⚠ No plugins installed"))
|
|
return
|
|
}
|
|
|
|
let removed = false
|
|
for (const name of names) {
|
|
const pluginDir = path.join(PLUGINS_DIR, name)
|
|
|
|
if (!lockfile.plugins[name] && !fs.existsSync(pluginDir)) {
|
|
console.log(styleText("yellow", `⚠ ${name} is not installed`))
|
|
continue
|
|
}
|
|
|
|
console.log(styleText("cyan", `→ Removing ${name}...`))
|
|
|
|
if (fs.existsSync(pluginDir)) {
|
|
fs.rmSync(pluginDir, { recursive: true })
|
|
}
|
|
|
|
delete lockfile.plugins[name]
|
|
console.log(styleText("green", `✓ Removed ${name}`))
|
|
removed = true
|
|
}
|
|
|
|
if (removed) {
|
|
await regeneratePluginIndex()
|
|
}
|
|
|
|
writeLockfile(lockfile)
|
|
const pluginsJson = readPluginsJson()
|
|
if (pluginsJson?.plugins) {
|
|
pluginsJson.plugins = pluginsJson.plugins.filter(
|
|
(plugin) =>
|
|
!names.includes(extractPluginName(plugin.source)) && !names.includes(plugin.source),
|
|
)
|
|
writePluginsJson(pluginsJson)
|
|
}
|
|
console.log()
|
|
console.log(styleText("gray", "Updated quartz.lock.json"))
|
|
}
|
|
|
|
export async function handlePluginEnable(names) {
|
|
const json = readPluginsJson()
|
|
if (!json) {
|
|
console.log(styleText("red", "✗ No quartz.config.yaml found. Cannot enable plugins."))
|
|
return
|
|
}
|
|
|
|
for (const name of names) {
|
|
const entry = json.plugins.find(
|
|
(e) => extractPluginName(e.source) === name || e.source === name,
|
|
)
|
|
if (!entry) {
|
|
console.log(styleText("yellow", `⚠ Plugin "${name}" not found in quartz.config.yaml`))
|
|
continue
|
|
}
|
|
if (entry.enabled) {
|
|
console.log(styleText("gray", `✓ ${name} is already enabled`))
|
|
continue
|
|
}
|
|
entry.enabled = true
|
|
console.log(styleText("green", `✓ Enabled ${name}`))
|
|
}
|
|
|
|
writePluginsJson(json)
|
|
}
|
|
|
|
export async function handlePluginDisable(names) {
|
|
const json = readPluginsJson()
|
|
if (!json) {
|
|
console.log(styleText("red", "✗ No quartz.config.yaml found. Cannot disable plugins."))
|
|
return
|
|
}
|
|
|
|
for (const name of names) {
|
|
const entry = json.plugins.find(
|
|
(e) => extractPluginName(e.source) === name || e.source === name,
|
|
)
|
|
if (!entry) {
|
|
console.log(styleText("yellow", `⚠ Plugin "${name}" not found in quartz.config.yaml`))
|
|
continue
|
|
}
|
|
if (!entry.enabled) {
|
|
console.log(styleText("gray", `✓ ${name} is already disabled`))
|
|
continue
|
|
}
|
|
entry.enabled = false
|
|
console.log(styleText("green", `✓ Disabled ${name}`))
|
|
}
|
|
|
|
writePluginsJson(json)
|
|
}
|
|
|
|
export async function handlePluginConfig(name, options = {}) {
|
|
const json = readPluginsJson()
|
|
if (!json) {
|
|
console.log(styleText("red", "✗ No quartz.config.yaml found."))
|
|
return
|
|
}
|
|
|
|
const entry = json.plugins.find((e) => extractPluginName(e.source) === name || e.source === name)
|
|
if (!entry) {
|
|
console.log(styleText("red", `✗ Plugin "${name}" not found in quartz.config.yaml`))
|
|
return
|
|
}
|
|
|
|
if (options.set) {
|
|
const eqIndex = options.set.indexOf("=")
|
|
if (eqIndex === -1) {
|
|
console.log(styleText("red", "✗ Invalid format. Use: --set key=value"))
|
|
return
|
|
}
|
|
const key = options.set.slice(0, eqIndex)
|
|
let value = options.set.slice(eqIndex + 1)
|
|
|
|
try {
|
|
value = JSON.parse(value)
|
|
} catch {}
|
|
|
|
if (!entry.options) entry.options = {}
|
|
entry.options[key] = value
|
|
writePluginsJson(json)
|
|
console.log(styleText("green", `✓ Set ${name}.${key} = ${JSON.stringify(value)}`))
|
|
} else {
|
|
console.log(styleText("bold", `Plugin: ${name}`))
|
|
console.log(` Source: ${entry.source}`)
|
|
console.log(` Enabled: ${entry.enabled}`)
|
|
console.log(` Order: ${entry.order ?? 50}`)
|
|
if (entry.options && Object.keys(entry.options).length > 0) {
|
|
console.log(` Options:`)
|
|
for (const [k, v] of Object.entries(entry.options)) {
|
|
console.log(` ${k}: ${JSON.stringify(v)}`)
|
|
}
|
|
} else {
|
|
console.log(` Options: (none)`)
|
|
}
|
|
if (entry.layout) {
|
|
console.log(` Layout:`)
|
|
for (const [k, v] of Object.entries(entry.layout)) {
|
|
console.log(` ${k}: ${JSON.stringify(v)}`)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
export async function handlePluginCheck() {
|
|
const lockfile = readLockfile()
|
|
if (!lockfile || Object.keys(lockfile.plugins).length === 0) {
|
|
console.log(styleText("gray", "No plugins installed"))
|
|
return
|
|
}
|
|
|
|
console.log(styleText("bold", "Checking for plugin updates...\n"))
|
|
|
|
const results = []
|
|
for (const [name, entry] of Object.entries(lockfile.plugins)) {
|
|
// Local plugins: show "local" status, skip git checks
|
|
if (entry.commit === "local") {
|
|
results.push({
|
|
name,
|
|
installed: "local",
|
|
latest: "—",
|
|
status: "local",
|
|
})
|
|
continue
|
|
}
|
|
|
|
try {
|
|
const lsRemoteRef = entry.ref ? `refs/heads/${entry.ref}` : "HEAD"
|
|
const latestCommit = execSync(`git ls-remote ${entry.resolved} ${lsRemoteRef}`, {
|
|
encoding: "utf-8",
|
|
})
|
|
.split("\t")[0]
|
|
.trim()
|
|
|
|
const isCurrent = latestCommit === entry.commit
|
|
results.push({
|
|
name,
|
|
installed: entry.commit.slice(0, 7),
|
|
latest: latestCommit.slice(0, 7),
|
|
status: isCurrent ? "up to date" : "update available",
|
|
})
|
|
} catch {
|
|
results.push({
|
|
name,
|
|
installed: entry.commit.slice(0, 7),
|
|
latest: "?",
|
|
status: "check failed",
|
|
})
|
|
}
|
|
}
|
|
|
|
const nameWidth = Math.max(6, ...results.map((r) => r.name.length)) + 2
|
|
const header = `${"Plugin".padEnd(nameWidth)}${"Installed".padEnd(12)}${"Latest".padEnd(12)}Status`
|
|
console.log(styleText("bold", header))
|
|
console.log("─".repeat(header.length))
|
|
|
|
for (const r of results) {
|
|
const color =
|
|
r.status === "up to date" || r.status === "local"
|
|
? "green"
|
|
: r.status === "check failed"
|
|
? "red"
|
|
: "yellow"
|
|
console.log(
|
|
`${r.name.padEnd(nameWidth)}${r.installed.padEnd(12)}${r.latest.padEnd(12)}${styleText(
|
|
color,
|
|
r.status,
|
|
)}`,
|
|
)
|
|
}
|
|
}
|
|
|
|
export async function handlePluginUpdate(names) {
|
|
const lockfile = readLockfile()
|
|
if (!lockfile) {
|
|
console.log(styleText("yellow", "⚠ No plugins installed"))
|
|
return
|
|
}
|
|
|
|
const pluginsToUpdate = names || Object.keys(lockfile.plugins)
|
|
const updatedPlugins = []
|
|
|
|
for (const name of pluginsToUpdate) {
|
|
const entry = lockfile.plugins[name]
|
|
if (!entry) {
|
|
console.log(styleText("yellow", `⚠ ${name} is not installed`))
|
|
continue
|
|
}
|
|
|
|
const pluginDir = path.join(PLUGINS_DIR, name)
|
|
if (!fs.existsSync(pluginDir)) {
|
|
console.log(
|
|
styleText("yellow", `⚠ ${name} directory missing. Run 'npx quartz plugin install'.`),
|
|
)
|
|
continue
|
|
}
|
|
|
|
// Local plugins: just rebuild, no git operations
|
|
if (entry.commit === "local") {
|
|
console.log(styleText("cyan", `→ Rebuilding local plugin ${name}...`))
|
|
updatedPlugins.push({ name, pluginDir })
|
|
continue
|
|
}
|
|
|
|
try {
|
|
console.log(styleText("cyan", `→ Updating ${name}...`))
|
|
const fetchRef = entry.ref || ""
|
|
const resetTarget = entry.ref ? `origin/${entry.ref}` : "origin/HEAD"
|
|
execSync(`git fetch --depth 1 origin${fetchRef ? " " + fetchRef : ""}`, {
|
|
cwd: pluginDir,
|
|
stdio: "ignore",
|
|
})
|
|
execSync(`git reset --hard ${resetTarget}`, { cwd: pluginDir, stdio: "ignore" })
|
|
|
|
const newCommit = getGitCommit(pluginDir)
|
|
if (newCommit !== entry.commit) {
|
|
entry.commit = newCommit
|
|
entry.installedAt = new Date().toISOString()
|
|
updatedPlugins.push({ name, pluginDir })
|
|
console.log(styleText("green", `✓ Updated ${name} to ${newCommit.slice(0, 7)}`))
|
|
} else {
|
|
console.log(styleText("gray", `✓ ${name} already up to date`))
|
|
}
|
|
} catch (error) {
|
|
console.log(styleText("red", `✗ Failed to update ${name}: ${error}`))
|
|
}
|
|
}
|
|
|
|
if (updatedPlugins.length > 0) {
|
|
console.log()
|
|
console.log(styleText("cyan", "→ Rebuilding updated plugins..."))
|
|
for (const { name, pluginDir } of updatedPlugins) {
|
|
if (buildPlugin(pluginDir, name)) {
|
|
console.log(styleText("green", ` ✓ ${name} rebuilt`))
|
|
}
|
|
}
|
|
await regeneratePluginIndex()
|
|
}
|
|
|
|
writeLockfile(lockfile)
|
|
console.log()
|
|
console.log(styleText("gray", "Updated quartz.lock.json"))
|
|
}
|
|
|
|
export async function handlePluginList() {
|
|
const lockfile = readLockfile()
|
|
if (!lockfile || Object.keys(lockfile.plugins).length === 0) {
|
|
console.log(styleText("gray", "No plugins installed"))
|
|
return
|
|
}
|
|
|
|
console.log(styleText("bold", "Installed Plugins:"))
|
|
console.log()
|
|
|
|
for (const [name, entry] of Object.entries(lockfile.plugins)) {
|
|
const pluginDir = path.join(PLUGINS_DIR, name)
|
|
const exists = fs.existsSync(pluginDir)
|
|
|
|
// Local plugins: special display
|
|
if (entry.commit === "local") {
|
|
const isLinked = exists && fs.lstatSync(pluginDir).isSymbolicLink()
|
|
const status = isLinked ? styleText("green", "✓") : styleText("red", "✗")
|
|
console.log(` ${status} ${styleText("bold", name)}`)
|
|
console.log(` Source: ${entry.source}`)
|
|
console.log(` Type: local symlink`)
|
|
console.log(` Target: ${entry.resolved}`)
|
|
console.log(` Installed: ${new Date(entry.installedAt).toLocaleDateString()}`)
|
|
console.log()
|
|
continue
|
|
}
|
|
|
|
let currentCommit = entry.commit
|
|
|
|
if (exists) {
|
|
currentCommit = getGitCommit(pluginDir)
|
|
}
|
|
|
|
const status = exists
|
|
? currentCommit === entry.commit
|
|
? styleText("green", "✓")
|
|
: styleText("yellow", "⚡")
|
|
: styleText("red", "✗")
|
|
|
|
console.log(` ${status} ${styleText("bold", name)}`)
|
|
console.log(` Source: ${entry.source}`)
|
|
console.log(` Commit: ${entry.commit.slice(0, 7)}`)
|
|
if (currentCommit !== entry.commit && exists) {
|
|
console.log(` Current: ${currentCommit.slice(0, 7)} (modified)`)
|
|
}
|
|
console.log(` Installed: ${new Date(entry.installedAt).toLocaleDateString()}`)
|
|
console.log()
|
|
}
|
|
}
|
|
|
|
export async function handlePluginRestore() {
|
|
const lockfile = readLockfile()
|
|
if (!lockfile) {
|
|
console.log(styleText("red", "✗ No quartz.lock.json found. Cannot restore."))
|
|
console.log()
|
|
console.log("Run 'npx quartz plugin add <repo>' to install plugins from scratch.")
|
|
return
|
|
}
|
|
|
|
console.log(styleText("cyan", "→ Restoring plugins from lockfile..."))
|
|
console.log()
|
|
|
|
const pluginsDir = path.join(process.cwd(), ".quartz", "plugins")
|
|
if (!fs.existsSync(pluginsDir)) {
|
|
fs.mkdirSync(pluginsDir, { recursive: true })
|
|
}
|
|
|
|
let installed = 0
|
|
let failed = 0
|
|
const restoredPlugins = []
|
|
|
|
for (const [name, entry] of Object.entries(lockfile.plugins)) {
|
|
const pluginDir = path.join(pluginsDir, name)
|
|
|
|
if (fs.existsSync(pluginDir)) {
|
|
console.log(styleText("yellow", `⚠ ${name}: directory exists, skipping`))
|
|
continue
|
|
}
|
|
|
|
// Local plugin: re-symlink
|
|
if (entry.commit === "local") {
|
|
try {
|
|
if (!fs.existsSync(entry.resolved)) {
|
|
console.log(styleText("red", ` ✗ ${name}: local path missing: ${entry.resolved}`))
|
|
failed++
|
|
continue
|
|
}
|
|
fs.mkdirSync(path.dirname(pluginDir), { recursive: true })
|
|
fs.symlinkSync(entry.resolved, pluginDir, "dir")
|
|
console.log(styleText("green", `✓ ${name} restored (local symlink)`))
|
|
restoredPlugins.push({ name, pluginDir })
|
|
installed++
|
|
} catch {
|
|
console.log(styleText("red", `✗ ${name}: failed to restore local symlink`))
|
|
failed++
|
|
}
|
|
continue
|
|
}
|
|
|
|
try {
|
|
console.log(
|
|
styleText("cyan", `→ ${name}: cloning ${entry.resolved}@${entry.commit.slice(0, 7)}...`),
|
|
)
|
|
const branchArg = entry.ref ? ` --branch ${entry.ref}` : ""
|
|
execSync(`git clone${branchArg} ${entry.resolved} ${pluginDir}`, { stdio: "ignore" })
|
|
execSync(`git checkout ${entry.commit}`, { cwd: pluginDir, stdio: "ignore" })
|
|
console.log(styleText("green", `✓ ${name} restored`))
|
|
restoredPlugins.push({ name, pluginDir })
|
|
installed++
|
|
} catch {
|
|
console.log(styleText("red", `✗ ${name}: failed to restore`))
|
|
failed++
|
|
}
|
|
}
|
|
|
|
if (restoredPlugins.length > 0) {
|
|
console.log()
|
|
console.log(styleText("cyan", "→ Building restored plugins..."))
|
|
for (const { name, pluginDir } of restoredPlugins) {
|
|
if (!buildPlugin(pluginDir, name)) {
|
|
failed++
|
|
installed--
|
|
} else {
|
|
console.log(styleText("green", ` ✓ ${name} built`))
|
|
}
|
|
}
|
|
await regeneratePluginIndex()
|
|
}
|
|
|
|
console.log()
|
|
if (failed === 0) {
|
|
console.log(styleText("green", `✓ Restored ${installed} plugin(s)`))
|
|
} else {
|
|
console.log(styleText("yellow", `⚠ Restored ${installed} plugin(s), ${failed} failed`))
|
|
}
|
|
}
|
|
|
|
export async function handlePluginPrune({ dryRun = false } = {}) {
|
|
const lockfile = readLockfile()
|
|
if (!lockfile || Object.keys(lockfile.plugins).length === 0) {
|
|
console.log(styleText("gray", "No plugins installed"))
|
|
return
|
|
}
|
|
|
|
const pluginsJson = readPluginsJson()
|
|
const configuredNames = new Set(
|
|
(pluginsJson?.plugins ?? []).map((entry) => extractPluginName(entry.source)),
|
|
)
|
|
|
|
const orphans = Object.keys(lockfile.plugins).filter((name) => !configuredNames.has(name))
|
|
|
|
if (orphans.length === 0) {
|
|
console.log(styleText("green", "✓ No orphaned plugins found — nothing to prune"))
|
|
return
|
|
}
|
|
|
|
console.log(`Found ${orphans.length} orphaned plugin(s):\n`)
|
|
for (const name of orphans) {
|
|
console.log(` ${styleText("yellow", name)} — in lockfile but not in config`)
|
|
}
|
|
console.log()
|
|
|
|
if (dryRun) {
|
|
console.log(styleText("cyan", "Dry run — no changes made. Re-run without --dry-run to prune."))
|
|
return
|
|
}
|
|
|
|
let removed = 0
|
|
for (const name of orphans) {
|
|
const pluginDir = path.join(PLUGINS_DIR, name)
|
|
|
|
console.log(styleText("cyan", `→ Removing ${name}...`))
|
|
|
|
if (fs.existsSync(pluginDir)) {
|
|
fs.rmSync(pluginDir, { recursive: true })
|
|
}
|
|
|
|
delete lockfile.plugins[name]
|
|
console.log(styleText("green", `✓ Removed ${name}`))
|
|
removed++
|
|
}
|
|
|
|
if (removed > 0) {
|
|
await regeneratePluginIndex()
|
|
}
|
|
|
|
writeLockfile(lockfile)
|
|
console.log()
|
|
console.log(styleText("green", `✓ Pruned ${removed} plugin(s)`))
|
|
console.log(styleText("gray", "Updated quartz.lock.json"))
|
|
}
|
|
|
|
export async function handlePluginResolve({ dryRun = false } = {}) {
|
|
const pluginsJson = readPluginsJson()
|
|
if (!pluginsJson?.plugins || pluginsJson.plugins.length === 0) {
|
|
console.log(styleText("gray", "No plugins configured"))
|
|
return
|
|
}
|
|
|
|
let lockfile = readLockfile()
|
|
if (!lockfile) {
|
|
lockfile = { version: "1.0.0", plugins: {} }
|
|
}
|
|
|
|
if (!fs.existsSync(PLUGINS_DIR)) {
|
|
fs.mkdirSync(PLUGINS_DIR, { recursive: true })
|
|
}
|
|
|
|
// Find config entries whose source is a git/local-resolvable URL and not yet in lockfile
|
|
const missing = pluginsJson.plugins.filter((entry) => {
|
|
const name = extractPluginName(entry.source)
|
|
if (lockfile.plugins[name]) return false
|
|
// Only attempt sources that parseGitSource can handle (git URLs + local paths)
|
|
const src = entry.source
|
|
return (
|
|
src.startsWith("github:") ||
|
|
src.startsWith("git+") ||
|
|
src.startsWith("https://") ||
|
|
isLocalSource(src)
|
|
)
|
|
})
|
|
|
|
if (missing.length === 0) {
|
|
console.log(styleText("green", "✓ All configured plugins are already installed"))
|
|
return
|
|
}
|
|
|
|
console.log(`Found ${missing.length} uninstalled plugin(s) in config:\n`)
|
|
for (const entry of missing) {
|
|
const name = extractPluginName(entry.source)
|
|
console.log(` ${styleText("yellow", name)} — ${entry.source}`)
|
|
}
|
|
console.log()
|
|
|
|
if (dryRun) {
|
|
console.log(
|
|
styleText("cyan", "Dry run — no changes made. Re-run without --dry-run to resolve."),
|
|
)
|
|
return
|
|
}
|
|
|
|
const installed = []
|
|
let failed = 0
|
|
|
|
for (const entry of missing) {
|
|
try {
|
|
const { name, url, ref, local } = parseGitSource(entry.source)
|
|
const pluginDir = path.join(PLUGINS_DIR, name)
|
|
|
|
if (fs.existsSync(pluginDir)) {
|
|
if (local) {
|
|
console.log(styleText("yellow", `⚠ ${name} directory already exists, updating lockfile`))
|
|
lockfile.plugins[name] = {
|
|
source: entry.source,
|
|
resolved: url,
|
|
commit: "local",
|
|
installedAt: new Date().toISOString(),
|
|
}
|
|
installed.push({ name, pluginDir })
|
|
continue
|
|
}
|
|
console.log(styleText("yellow", `⚠ ${name} directory already exists, updating lockfile`))
|
|
const commit = getGitCommit(pluginDir)
|
|
lockfile.plugins[name] = {
|
|
source: entry.source,
|
|
resolved: url,
|
|
commit,
|
|
...(ref && { ref }),
|
|
installedAt: new Date().toISOString(),
|
|
}
|
|
installed.push({ name, pluginDir })
|
|
continue
|
|
}
|
|
|
|
if (local) {
|
|
// Local path: symlink
|
|
const resolvedPath = path.resolve(url)
|
|
if (!fs.existsSync(resolvedPath)) {
|
|
console.log(styleText("red", `✗ Local path does not exist: ${resolvedPath}`))
|
|
failed++
|
|
continue
|
|
}
|
|
console.log(styleText("cyan", `→ Linking ${name} from ${resolvedPath}...`))
|
|
fs.mkdirSync(path.dirname(pluginDir), { recursive: true })
|
|
fs.symlinkSync(resolvedPath, pluginDir, "dir")
|
|
lockfile.plugins[name] = {
|
|
source: entry.source,
|
|
resolved: resolvedPath,
|
|
commit: "local",
|
|
installedAt: new Date().toISOString(),
|
|
}
|
|
installed.push({ name, pluginDir })
|
|
console.log(styleText("green", `✓ Linked ${name} (local)`))
|
|
} else {
|
|
console.log(styleText("cyan", `→ Cloning ${name} from ${url}...`))
|
|
|
|
if (ref) {
|
|
execSync(`git clone --depth 1 --branch ${ref} ${url} ${pluginDir}`, { stdio: "ignore" })
|
|
} else {
|
|
execSync(`git clone --depth 1 ${url} ${pluginDir}`, { stdio: "ignore" })
|
|
}
|
|
|
|
const commit = getGitCommit(pluginDir)
|
|
lockfile.plugins[name] = {
|
|
source: entry.source,
|
|
resolved: url,
|
|
commit,
|
|
...(ref && { ref }),
|
|
installedAt: new Date().toISOString(),
|
|
}
|
|
|
|
installed.push({ name, pluginDir })
|
|
console.log(styleText("green", `✓ Cloned ${name}@${commit.slice(0, 7)}`))
|
|
}
|
|
} catch (error) {
|
|
console.log(styleText("red", `✗ Failed to resolve ${entry.source}: ${error}`))
|
|
failed++
|
|
}
|
|
}
|
|
|
|
if (installed.length > 0) {
|
|
console.log()
|
|
console.log(styleText("cyan", "→ Building plugins..."))
|
|
for (const { name, pluginDir } of installed) {
|
|
if (!buildPlugin(pluginDir, name)) {
|
|
failed++
|
|
} else {
|
|
console.log(styleText("green", ` ✓ ${name} built`))
|
|
}
|
|
}
|
|
await regeneratePluginIndex()
|
|
}
|
|
|
|
writeLockfile(lockfile)
|
|
console.log()
|
|
if (failed === 0) {
|
|
console.log(styleText("green", `✓ Resolved ${installed.length} plugin(s)`))
|
|
} else {
|
|
console.log(styleText("yellow", `⚠ Resolved ${installed.length} plugin(s), ${failed} failed`))
|
|
}
|
|
console.log(styleText("gray", "Updated quartz.lock.json"))
|
|
}
|