diff --git a/packages/cursorless-cheatsheet/package.json b/packages/cursorless-cheatsheet/package.json new file mode 100644 index 00000000000..6a28a181e85 --- /dev/null +++ b/packages/cursorless-cheatsheet/package.json @@ -0,0 +1,35 @@ +{ + "name": "@cursorless/cursorless-cheatsheet", + "version": "0.1.0", + "description": "Cursorless cheatsheet implementation", + "type": "module", + "main": "./out/index.js", + "types": "./out/index.d.ts", + "scripts": { + "compile:tsc": "tsc --build", + "compile:esbuild": "esbuild ./src/index.ts --sourcemap --format=esm --bundle --packages=external --outfile=./out/index.js", + "compile": "pnpm compile:tsc && pnpm compile:esbuild", + "watch:tsc": "pnpm compile:tsc --watch", + "watch:esbuild": "pnpm compile:esbuild --watch", + "watch": "pnpm run --filter @cursorless/cursorless-cheatsheet --parallel '/^watch:.*/'", + "clean": "rm -rf ./out tsconfig.tsbuildinfo ./dist ./build" + }, + "keywords": [], + "author": "", + "license": "MIT", + "exports": { + ".": { + "cursorless:bundler": "./src/index.ts", + "default": "./out/index.js" + } + }, + "dependencies": { + "@cursorless/common": "workspace:*", + "immer": "^10.0.4", + "lodash-es": "^4.17.21", + "node-html-parser": "^6.1.12" + }, + "devDependencies": { + "@types/lodash-es": "4.17.0" + } +} diff --git a/packages/cursorless-engine/src/core/Cheatsheet.ts b/packages/cursorless-cheatsheet/src/Cheatsheet.ts similarity index 86% rename from packages/cursorless-engine/src/core/Cheatsheet.ts rename to packages/cursorless-cheatsheet/src/Cheatsheet.ts index daa09dd4a23..59f08d09847 100644 --- a/packages/cursorless-engine/src/core/Cheatsheet.ts +++ b/packages/cursorless-cheatsheet/src/Cheatsheet.ts @@ -1,10 +1,9 @@ +import { getCursorlessRepoRoot, type IDE } from "@cursorless/common"; import { readFile, writeFile } from "fs/promises"; -import { parse } from "node-html-parser"; -import { sortBy } from "lodash-es"; -import { ide } from "../singletons/ide.singleton"; -import path from "path"; -import { getCursorlessRepoRoot } from "@cursorless/common"; import { produce } from "immer"; +import { sortBy } from "lodash-es"; +import { parse } from "node-html-parser"; +import * as path from "path"; /** * The argument expected by the cheatsheet command. @@ -27,16 +26,15 @@ interface CheatSheetCommandArg { outputPath: string; } -export async function showCheatsheet({ - version, - spokenFormInfo, - outputPath, -}: CheatSheetCommandArg) { +export async function showCheatsheet( + ide: IDE, + { version, spokenFormInfo, outputPath }: CheatSheetCommandArg, +) { if (version !== 0) { throw new Error(`Unsupported cheatsheet api version: ${version}`); } - const cheatsheetPath = path.join(ide().assetsRoot, "cheatsheet.html"); + const cheatsheetPath = path.join(ide.assetsRoot, "cheatsheet.html"); const cheatsheetContent = (await readFile(cheatsheetPath)).toString(); diff --git a/packages/cursorless-cheatsheet/src/index.ts b/packages/cursorless-cheatsheet/src/index.ts new file mode 100644 index 00000000000..1e3b5b48637 --- /dev/null +++ b/packages/cursorless-cheatsheet/src/index.ts @@ -0,0 +1 @@ +export * from "./Cheatsheet"; diff --git a/packages/cursorless-cheatsheet/tsconfig.json b/packages/cursorless-cheatsheet/tsconfig.json new file mode 100644 index 00000000000..96107efcd71 --- /dev/null +++ b/packages/cursorless-cheatsheet/tsconfig.json @@ -0,0 +1,13 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "outDir": "out", + "rootDir": "src" + }, + "include": ["src/**/*.ts", "src/**/*.json", "../../typings/**/*.d.ts"], + "references": [ + { + "path": "../common" + } + ] +} diff --git a/packages/cursorless-engine/package.json b/packages/cursorless-engine/package.json index 0aa8c4b50ad..3e892b649a9 100644 --- a/packages/cursorless-engine/package.json +++ b/packages/cursorless-engine/package.json @@ -29,7 +29,6 @@ "lodash-es": "^4.17.21", "moo": "0.5.2", "nearley": "2.20.1", - "node-html-parser": "^6.1.12", "sbd": "^1.0.19", "uuid": "^9.0.1", "zod": "3.22.4" diff --git a/packages/cursorless-engine/src/index.ts b/packages/cursorless-engine/src/index.ts index dfe8e57fd93..87a1a6aa2ed 100644 --- a/packages/cursorless-engine/src/index.ts +++ b/packages/cursorless-engine/src/index.ts @@ -1,5 +1,4 @@ export * from "./testUtil/plainObjectToTarget"; -export * from "./core/Cheatsheet"; export * from "./testUtil/takeSnapshot"; export * from "./testCaseRecorder/TestCaseRecorder"; export * from "./core/StoredTargets"; diff --git a/packages/cursorless-vscode/package.json b/packages/cursorless-vscode/package.json index 99a14ddaf41..269ef375ef9 100644 --- a/packages/cursorless-vscode/package.json +++ b/packages/cursorless-vscode/package.json @@ -1240,6 +1240,7 @@ }, "dependencies": { "@cursorless/common": "workspace:*", + "@cursorless/cursorless-cheatsheet": "workspace:*", "@cursorless/cursorless-engine": "workspace:*", "@cursorless/file-system-common": "workspace:*", "@cursorless/vscode-common": "workspace:*", diff --git a/packages/cursorless-vscode/src/registerCommands.ts b/packages/cursorless-vscode/src/registerCommands.ts index 291a5bf4f1b..46ed6683d37 100644 --- a/packages/cursorless-vscode/src/registerCommands.ts +++ b/packages/cursorless-vscode/src/registerCommands.ts @@ -4,13 +4,15 @@ import { isTesting, type CommandHistoryStorage, } from "@cursorless/common"; +import { + showCheatsheet, + updateDefaults, +} from "@cursorless/cursorless-cheatsheet"; import { CommandApi, StoredTargetMap, TestCaseRecorder, analyzeCommandHistory, - showCheatsheet, - updateDefaults, type ScopeTestRecorder, } from "@cursorless/cursorless-engine"; import * as vscode from "vscode"; @@ -57,7 +59,7 @@ export function registerCommands( }, // Cheatsheet commands - ["cursorless.showCheatsheet"]: showCheatsheet, + ["cursorless.showCheatsheet"]: (arg) => showCheatsheet(vscodeIde, arg), ["cursorless.internal.updateCheatsheetDefaults"]: updateDefaults, // Testcase recorder commands diff --git a/packages/cursorless-vscode/tsconfig.json b/packages/cursorless-vscode/tsconfig.json index ac02c0a5886..fe1e0810fba 100644 --- a/packages/cursorless-vscode/tsconfig.json +++ b/packages/cursorless-vscode/tsconfig.json @@ -10,6 +10,9 @@ { "path": "../common" }, + { + "path": "../cursorless-cheatsheet" + }, { "path": "../cursorless-engine" }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 77a93a0cf8d..cfc6c46f460 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -242,6 +242,25 @@ importers: specifier: ^17.0.1 version: 17.0.1 + packages/cursorless-cheatsheet: + dependencies: + '@cursorless/common': + specifier: workspace:* + version: link:../common + immer: + specifier: ^10.0.4 + version: 10.0.4 + lodash-es: + specifier: ^4.17.21 + version: 4.17.21 + node-html-parser: + specifier: ^6.1.12 + version: 6.1.12 + devDependencies: + '@types/lodash-es': + specifier: 4.17.0 + version: 4.17.0 + packages/cursorless-engine: dependencies: '@cursorless/common': @@ -268,9 +287,6 @@ importers: nearley: specifier: 2.20.1 version: 2.20.1(patch_hash=mg2fc7wgvzub3myuz6m74hllma) - node-html-parser: - specifier: ^6.1.12 - version: 6.1.12 sbd: specifier: ^1.0.19 version: 1.0.19 @@ -454,6 +470,9 @@ importers: '@cursorless/common': specifier: workspace:* version: link:../common + '@cursorless/cursorless-cheatsheet': + specifier: workspace:* + version: link:../cursorless-cheatsheet '@cursorless/cursorless-engine': specifier: workspace:* version: link:../cursorless-engine diff --git a/tsconfig.json b/tsconfig.json index 9141f9de2b8..bfb2bbbaf42 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -11,6 +11,9 @@ { "path": "./packages/common" }, + { + "path": "./packages/cursorless-cheatsheet" + }, { "path": "./packages/cursorless-engine" },