Skip to content

Commit

Permalink
Extract cheatsheet into separate package (#2482)
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreasArvidsson committed Jul 11, 2024
1 parent 9f70536 commit ee85071
Show file tree
Hide file tree
Showing 11 changed files with 92 additions and 19 deletions.
35 changes: 35 additions & 0 deletions packages/cursorless-cheatsheet/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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();

Expand Down
1 change: 1 addition & 0 deletions packages/cursorless-cheatsheet/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./Cheatsheet";
13 changes: 13 additions & 0 deletions packages/cursorless-cheatsheet/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"outDir": "out",
"rootDir": "src"
},
"include": ["src/**/*.ts", "src/**/*.json", "../../typings/**/*.d.ts"],
"references": [
{
"path": "../common"
}
]
}
1 change: 0 additions & 1 deletion packages/cursorless-engine/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion packages/cursorless-engine/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export * from "./testUtil/plainObjectToTarget";
export * from "./core/Cheatsheet";
export * from "./testUtil/takeSnapshot";
export * from "./testCaseRecorder/TestCaseRecorder";
export * from "./core/StoredTargets";
Expand Down
1 change: 1 addition & 0 deletions packages/cursorless-vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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:*",
Expand Down
8 changes: 5 additions & 3 deletions packages/cursorless-vscode/src/registerCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions packages/cursorless-vscode/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
{
"path": "../common"
},
{
"path": "../cursorless-cheatsheet"
},
{
"path": "../cursorless-engine"
},
Expand Down
25 changes: 22 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
{
"path": "./packages/common"
},
{
"path": "./packages/cursorless-cheatsheet"
},
{
"path": "./packages/cursorless-engine"
},
Expand Down

0 comments on commit ee85071

Please sign in to comment.