feat(sdk): pluginRoot officiel exposé dans activate(ctx) — #285 (src/runtime: champ pluginRoot = racine du package installé; docs activation-context/commands-and-feedback/services/manifest réécrits du constat d'absence vers le contrat d'usage officiel — runCommand reste project-scoped, pluginRoot utilisable dans command/args, substitution manifest ${pluginRoot}/${appDataDir} inchangée pour mcpServers; exemple hello-plugin: script packagé scripts/hello-task.mjs consommé via ctx.pluginRoot, packaging étendu; QA verte: npm run check — build, typecheck:examples, package:hello-plugin, artefact zip vérifié)
This commit is contained in:
@ -16,6 +16,8 @@ It exercises the current plugin primitives end to end:
|
||||
`ctx.services.windows.open(...)` when services are available.
|
||||
- plugin-owned storage: activation count, command run count and initialization flag;
|
||||
- tooling capability: logs the focused workspace project when `ctx.services` is available.
|
||||
- packaged command script: resolves `scripts/hello-task.mjs` from the official
|
||||
`ctx.pluginRoot` and launches it with the project kept as the task working directory.
|
||||
|
||||
The source is intentionally split across multiple TypeScript modules:
|
||||
|
||||
@ -23,6 +25,7 @@ The source is intentionally split across multiple TypeScript modules:
|
||||
- `src/constants.ts` owns shared command/layout identifiers;
|
||||
- `src/core/layout.tsx` and `src/core/workspace.ts` hold feature logic.
|
||||
- `src/core/storage.ts` keeps plugin-owned counters and flags in `ctx.storage`.
|
||||
- `scripts/hello-task.mjs` is a read-only runtime resource included in the archive.
|
||||
|
||||
The build uses plain `tsc`; it does not bundle the plugin into one file. The archive includes all
|
||||
compiled `dist/**/*.js` files so IdeA can load `dist/index.js` and serve its package-relative imports
|
||||
@ -36,8 +39,8 @@ npm run package:hello-plugin
|
||||
```
|
||||
|
||||
The installable archive is emitted at `examples/hello-plugin/build/hello-plugin-0.1.0.zip`.
|
||||
It contains `idea-plugin.json` at the ZIP root and the compiled multi-file ESM output under `dist/`,
|
||||
including `dist/index.js`, matching the manifest `main` field.
|
||||
It contains `idea-plugin.json` at the ZIP root, the compiled multi-file ESM output under `dist/`,
|
||||
including `dist/index.js`, and the packaged handler under `scripts/hello-task.mjs`.
|
||||
|
||||
## Diagnostics
|
||||
|
||||
|
||||
1
examples/hello-plugin/scripts/hello-task.mjs
Normal file
1
examples/hello-plugin/scripts/hello-task.mjs
Normal file
@ -0,0 +1 @@
|
||||
console.log("hello from a script packaged with @idea/plugin-sdk");
|
||||
@ -122,12 +122,13 @@ export async function runHelloCommandTask(ctx: ActivateContext): Promise<HelloCo
|
||||
return feedback;
|
||||
}
|
||||
|
||||
const pluginRoot = ctx.pluginRoot.replace(/[\\/]+$/, "");
|
||||
const task = await ctx.services.tasks.runCommand({
|
||||
projectId: project.id,
|
||||
ownerAgentId,
|
||||
label: "Hello plugin command",
|
||||
command: "echo",
|
||||
args: ["hello from @idea/plugin-sdk"],
|
||||
command: "node",
|
||||
args: [`${pluginRoot}/scripts/hello-task.mjs`],
|
||||
cwd: ".",
|
||||
recordOnly: true
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user