mirror of
https://github.com/stablyai/orca.git
synced 2026-11-16 02:47:34 +00:00
orca plugin create --template editor wrote an inline-script HTML editor whose extension came from the folder name squashed to 12 letters. It now writes the recipe: editor/main.ts (the view), editor/sync.ts (the document session with a stand-in text merge), editor/sync.test.ts (a mockEditorHost test of an outside write merged during a save), a tsconfig on the generated typings, frame isolated, engines.orca >=1.4.248, and extension .<id>. It passes plugin check and plugin test as generated.
69 lines
2.2 KiB
TypeScript
69 lines
2.2 KiB
TypeScript
/** File helpers shared by the `orca plugin create` templates. */
|
|
|
|
import { localPluginPublisher } from '../../shared/plugins/installation/plugin-publisher-derivation'
|
|
import { PLUGIN_DERIVED_PUBLISHER_SINCE } from '../../shared/plugins/manifest/plugin-schema-field-docs'
|
|
|
|
/** `publisher` is deprecated: set only for authors who still support Orca that requires it. */
|
|
export type PluginTemplateInput = { publisher?: string; id: string; name: string }
|
|
|
|
export type PluginTemplate = {
|
|
description: string
|
|
/** Manifest-relative path (always `/`) to file text. */
|
|
files: Record<string, string>
|
|
}
|
|
|
|
/** Every template targets the release that reads publisher-less manifests and TSX entries. */
|
|
const ENGINE = `>=${PLUGIN_DERIVED_PUBLISHER_SINCE}`
|
|
|
|
export function pluginTemplateKey(input: PluginTemplateInput): string {
|
|
return `${localPluginPublisher(input.publisher)}.${input.id}`
|
|
}
|
|
|
|
export function json(value: unknown): string {
|
|
return `${JSON.stringify(value, null, 2)}\n`
|
|
}
|
|
|
|
/** `engine`: a newer `engines.orca` floor, for templates that use newer fields. */
|
|
export function manifest(
|
|
input: PluginTemplateInput,
|
|
description: string,
|
|
fields: Record<string, unknown>,
|
|
engine = ENGINE
|
|
): string {
|
|
return json({
|
|
manifestVersion: 2,
|
|
id: input.id,
|
|
...(input.publisher ? { publisher: input.publisher } : {}),
|
|
name: input.name,
|
|
version: '0.1.0',
|
|
description,
|
|
engines: { orca: engine },
|
|
...fields
|
|
})
|
|
}
|
|
|
|
export function readme(input: PluginTemplateInput, body: string): string {
|
|
return `# ${input.name}
|
|
|
|
${body}
|
|
|
|
## Develop
|
|
|
|
\`\`\`sh
|
|
orca plugin validate .
|
|
orca plugin dev watch . # loads this folder into Orca and prints its logs and reloads; Ctrl-C unloads it
|
|
\`\`\`
|
|
|
|
Orca names the publisher after where the plugin is installed from: the GitHub or GitLab owner of
|
|
its repository, or \`local\` for a folder. See
|
|
https://github.com/stablyai/orca/blob/main/docs/reference/plugin-authoring.md.
|
|
`
|
|
}
|
|
|
|
// Why -text: Git must not rewrite line endings, or the content hash differs per checkout.
|
|
// `.orca/` holds the typings `orca plugin types` writes; they are regenerated, never committed.
|
|
export const COMMON_FILES = {
|
|
'.gitattributes': '* -text\n',
|
|
'.gitignore': 'node_modules/\n.orca/\n'
|
|
}
|