Skip to content

Commit 5a1f108

Browse files
authored
fix(extension): setup CI and minor improvements (#142)
1 parent 2c9c68d commit 5a1f108

File tree

10 files changed

+57
-667
lines changed

10 files changed

+57
-667
lines changed

.github/workflows/ci.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,15 @@ jobs:
4747
run: |
4848
pnpm run docs:build
4949
pnpm run demo:build
50+
51+
extension:
52+
name: VSCode Extension
53+
runs-on: ubuntu-latest
54+
steps:
55+
- name: Checkout
56+
uses: actions/checkout@v4
57+
58+
- uses: ./.github/actions/setup-and-build
59+
- name: Build extension
60+
run: |
61+
pnpm run extension:build

extensions/vscode/.vscode-test.mjs

Lines changed: 0 additions & 5 deletions
This file was deleted.

extensions/vscode/package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,9 @@
109109
"__dev": "pnpm run esbuild-base -- --sourcemap --watch",
110110
"__vscode:prepublish": "pnpm run esbuild-base -- --minify",
111111
"__build": "vsce package",
112-
"compile": "pnpm run check-types && node build.mjs",
113-
"check-types": "tsc --noEmit",
114112
"dev": "node build.mjs --watch",
113+
"build": "pnpm run check-types && node build.mjs",
114+
"check-types": "tsc --noEmit",
115115
"vscode:prepublish": "pnpm run package",
116116
"package": "pnpm run check-types && node build.mjs --production"
117117
},
@@ -123,8 +123,6 @@
123123
"@types/mocha": "^10.0.6",
124124
"@types/node": "20.14.11",
125125
"@types/vscode": "^1.80.0",
126-
"@vscode/test-cli": "^0.0.9",
127-
"@vscode/test-electron": "^2.4.0",
128126
"esbuild": "^0.21.5",
129127
"execa": "^9.2.0",
130128
"typescript": "^5.4.5"

extensions/vscode/src/commands/tutorialkit.add.ts

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@ export async function addLesson(parent: Lesson) {
1919
const lessonFolderPath = await createUnitFolder(parent.path, lessonNumber, lessonName, 'lesson');
2020

2121
await vscode.workspace.fs.createDirectory(vscode.Uri.file(`${lessonFolderPath}/_files`));
22+
await vscode.workspace.fs.createDirectory(vscode.Uri.file(`${lessonFolderPath}/_solution`));
2223

2324
await cmd.refresh();
2425

25-
return navigateToUnit(lessonFolderPath, 'lesson', lessonName);
26+
return navigateToUnit(lessonFolderPath, 'lesson');
2627
}
2728

2829
export async function addChapter(parent: Lesson) {
@@ -32,7 +33,7 @@ export async function addChapter(parent: Lesson) {
3233

3334
const chapterFolderPath = await createUnitFolder(parent.path, chapterNumber, chapterName, 'chapter');
3435

35-
await navigateToUnit(chapterFolderPath, 'chapter', chapterName);
36+
await navigateToUnit(chapterFolderPath, 'chapter');
3637

3738
await cmd.refresh();
3839
}
@@ -57,22 +58,14 @@ async function createUnitFolder(parentPath: string, unitNumber: number, unitName
5758

5859
await vscode.workspace.fs.writeFile(
5960
vscode.Uri.file(`${unitFolderPath}/${metaFile}`),
60-
new TextEncoder().encode(`---\ntitle: ${unitName}\ntype: ${unitType}\n---\n`),
61+
new TextEncoder().encode(`---\ntype: ${unitType}\ntitle: ${unitName}\n---\n`),
6162
);
6263

6364
return unitFolderPath;
6465
}
6566

66-
async function navigateToUnit(path: string, unitType: LessonType, title: string) {
67+
async function navigateToUnit(path: string, unitType: LessonType) {
6768
const metaFile = unitType === 'lesson' ? 'content.mdx' : 'meta.md';
6869

69-
return cmd.goto(
70-
path,
71-
{
72-
_path: `${path}/${metaFile}`,
73-
type: unitType,
74-
title,
75-
},
76-
true,
77-
);
70+
return cmd.goto(`${path}/${metaFile}`);
7871
}
Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,13 @@
11
import * as vscode from 'vscode';
2-
import { Lesson } from '../models/Lesson';
32

4-
export default (path: string, meta: Lesson['metadata'], openFile = false) => {
5-
vscode.commands
6-
.executeCommand('revealInExplorer', vscode.Uri.file(path))
7-
.then(() => {
8-
if (openFile) {
9-
vscode.workspace.openTextDocument(meta!._path).then((document) => {
10-
vscode.window.showTextDocument(document);
11-
});
12-
}
13-
})
14-
.then(() => {
15-
setTimeout(
16-
() => {
17-
vscode.commands.executeCommand('tutorialkit-lessons-tree.focus');
18-
},
19-
meta?.type === 'lesson' ? 30 : 0,
20-
);
21-
});
3+
export default async (path: string | undefined) => {
4+
if (!path) {
5+
return;
6+
}
7+
8+
const document = await vscode.workspace.openTextDocument(path);
9+
10+
await vscode.window.showTextDocument(document, {
11+
preserveFocus: true,
12+
});
2213
};

extensions/vscode/src/test/extension.test.ts

Lines changed: 0 additions & 18 deletions
This file was deleted.

extensions/vscode/src/views/lessonsTree.ts

Lines changed: 3 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ import { cmd } from '../commands';
66
import { Lesson } from '../models/Lesson';
77
import { getIcon } from '../utils/getIcon';
88

9-
// import isTutorialKitWorkspace from '../utils/isTutorialKit';
10-
119
const metadataFiles = ['meta.md', 'meta.mdx', 'content.md', 'content.mdx'];
10+
1211
export const tutorialMimeType = 'application/tutorialkit.unit';
1312

1413
let lessonsTreeDataProvider: LessonsTreeDataProvider;
@@ -22,7 +21,6 @@ export function setLessonsTreeDataProvider(provider: LessonsTreeDataProvider) {
2221

2322
export class LessonsTreeDataProvider implements vscode.TreeDataProvider<Lesson> {
2423
private _lessons: Lesson[] = [];
25-
private _isTutorialKitWorkspace = false;
2624

2725
constructor(
2826
private readonly _workspaceRoot: vscode.Uri,
@@ -34,10 +32,9 @@ export class LessonsTreeDataProvider implements vscode.TreeDataProvider<Lesson>
3432
private _loadLessons(): void {
3533
try {
3634
const tutorialFolderPath = vscode.Uri.joinPath(this._workspaceRoot, 'src', 'content', 'tutorial').fsPath;
37-
this._isTutorialKitWorkspace = true;
3835
this._lessons = this._loadLessonsFromFolder(tutorialFolderPath);
3936
} catch {
40-
this._isTutorialKitWorkspace = false;
37+
// do nothing
4138
}
4239
}
4340

@@ -91,12 +88,10 @@ export class LessonsTreeDataProvider implements vscode.TreeDataProvider<Lesson>
9188

9289
treeItem.contextValue = lesson.metadata?.type;
9390

94-
const shouldOpenFile = lesson.metadata?.type === 'lesson';
95-
9691
treeItem.command = {
9792
command: cmd.goto.command,
9893
title: 'Go to the lesson',
99-
arguments: [lesson.path, lesson.metadata, shouldOpenFile],
94+
arguments: [lesson.metadata?._path],
10095
};
10196

10297
treeItem.iconPath =
@@ -115,52 +110,5 @@ export class LessonsTreeDataProvider implements vscode.TreeDataProvider<Lesson>
115110
}
116111

117112
export async function useLessonTree() {
118-
/**
119-
* `
120-
* vscode.workspace.onDidChangeWorkspaceFolders((event) => {
121-
* event.added.forEach((folder) => {
122-
* if (isTutorialKitWorkspace(folder)) {
123-
* }
124-
* });
125-
* });
126-
*/
127-
128-
// vscode.commands.executeCommand('setContext', 'tutorialkit:tree', true);
129-
130113
cmd.initialize();
131-
132-
/**
133-
* `
134-
* const tutorialWorkpaces = (vscode.workspace.workspaceFolders || []).filter(
135-
* isTutorialKitWorkspace,
136-
* );
137-
* const selectedWorkspace =
138-
* tutorialWorkpaces.length === 1
139-
* ? tutorialWorkpaces[0]
140-
* : await vscode.window
141-
* .showQuickPick(
142-
* tutorialWorkpaces.map((workspace) => workspace.name),
143-
* {
144-
* placeHolder: 'Select a workspace',
145-
* },
146-
* )
147-
* .then((selected) =>
148-
* tutorialWorkpaces.find((workspace) => workspace.name === selected),
149-
* );
150-
*/
151-
152-
/**
153-
* `
154-
* if (selectedWorkspace) {
155-
* setLessonsTreeDataProvider(
156-
* new LessonsTreeDataProvider(selectedWorkspace.uri, context),
157-
* );
158-
* context.subscriptions.push(
159-
* vscode.window.createTreeView('tutorialkit-lessons-tree', {
160-
* treeDataProvider: getLessonsTreeDataProvider(),
161-
* canSelectMany: true,
162-
* }),
163-
* );
164-
* }
165-
*/
166114
}

extensions/vscode/tsconfig.json

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
{
2+
"extends": "../../tsconfig.json",
23
"compilerOptions": {
34
"module": "Node16",
45
"target": "ES2022",
5-
"outDir": "out",
6+
"outDir": "dist",
67
"lib": ["ES2022"],
8+
"verbatimModuleSyntax": false,
79
"sourceMap": true,
8-
"rootDir": "src",
9-
"strict": true /* enable all strict type-checking options */
10-
/* Additional Checks */
11-
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
12-
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
13-
// "noUnusedParameters": true, /* Report errors on unused parameters. */
10+
"rootDir": "src"
1411
}
1512
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"clean": "./scripts/clean.sh",
88
"prepare": "is-ci || husky install",
99
"extension:dev": "pnpm run --filter=tutorialkit-vscode dev",
10+
"extension:build": "pnpm run --filter=tutorialkit-vscode build",
1011
"template:dev": "TUTORIALKIT_DEV=true pnpm run build && pnpm run --filter=tutorialkit-starter dev",
1112
"template:build": "pnpm run build && pnpm run --filter=tutorialkit-starter build",
1213
"cli:build-release": "pnpm run --filter=tutorialkit build-release",

0 commit comments

Comments
 (0)