Skip to content

Commit 866c65d

Browse files
committed
+ custom.fs.remove
1 parent d6b9845 commit 866c65d

File tree

4 files changed

+53
-4
lines changed

4 files changed

+53
-4
lines changed

patches/@tutorialkit+runtime+1.5.0.patch

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
diff --git a/node_modules/@tutorialkit/runtime/dist/store/index.js b/node_modules/@tutorialkit/runtime/dist/store/index.js
2+
index a0d73ec..b2f2ec2 100644
3+
--- a/node_modules/@tutorialkit/runtime/dist/store/index.js
4+
+++ b/node_modules/@tutorialkit/runtime/dist/store/index.js
5+
@@ -106,7 +106,8 @@ export class TutorialStore {
6+
this._lessonTask = newTask(async (signal) => {
7+
const templatePromise = this._lessonFilesFetcher.getLessonTemplate(lesson);
8+
const filesPromise = this._lessonFilesFetcher.getLessonFiles(lesson);
9+
- const preparePromise = this._runner.prepareFiles({ template: templatePromise, files: filesPromise, signal });
10+
+ const removePaths = lesson?.data?.custom?.fs?.remove;
11+
+ const preparePromise = this._runner.prepareFiles({ template: templatePromise, files: filesPromise, signal, removePaths });
12+
this._runner.runCommands();
13+
const [template, solution, files] = await Promise.all([
14+
templatePromise,
115
diff --git a/node_modules/@tutorialkit/runtime/dist/store/terminal.js b/node_modules/@tutorialkit/runtime/dist/store/terminal.js
216
index 31edbb5..18be6b8 100644
317
--- a/node_modules/@tutorialkit/runtime/dist/store/terminal.js
@@ -11,10 +25,36 @@ index 31edbb5..18be6b8 100644
1125
.catch(() => {
1226
// do nothing
1327
diff --git a/node_modules/@tutorialkit/runtime/dist/store/tutorial-runner.js b/node_modules/@tutorialkit/runtime/dist/store/tutorial-runner.js
14-
index e253906..1efc1db 100644
28+
index e253906..9b1e4ba 100644
1529
--- a/node_modules/@tutorialkit/runtime/dist/store/tutorial-runner.js
1630
+++ b/node_modules/@tutorialkit/runtime/dist/store/tutorial-runner.js
17-
@@ -459,7 +459,7 @@ export class TutorialRunner {
31+
@@ -151,7 +151,7 @@ export class TutorialRunner {
32+
*
33+
* @see {LoadFilesOptions}
34+
*/
35+
- prepareFiles({ files, template, signal, abortPreviousLoad = true }) {
36+
+ prepareFiles({ files, template, signal, abortPreviousLoad = true, removePaths = undefined }) {
37+
const previousLoadPromise = this._currentLoadTask?.promise;
38+
if (abortPreviousLoad) {
39+
this._currentLoadTask?.cancel();
40+
@@ -167,6 +167,16 @@ export class TutorialRunner {
41+
[template, files] = await Promise.all([template, files]);
42+
signal.throwIfAborted();
43+
if (this._currentFiles || this._currentTemplate) {
44+
+ if (removePaths) {
45+
+ for(const path of removePaths) {
46+
+ for(const filePath of Object.keys(this._currentFiles)) {
47+
+ if (filePath.startsWith(path)) {
48+
+ delete this._currentFiles[filePath];
49+
+ }
50+
+ }
51+
+ await webcontainer.fs.rm(path, {recursive: true});
52+
+ }
53+
+ }
54+
await updateFiles(webcontainer, { ...this._currentTemplate, ...this._currentFiles }, { ...template, ...files });
55+
}
56+
else {
57+
@@ -459,7 +469,7 @@ export class TutorialRunner {
1858
clearTimeout(timeoutId);
1959
timeoutId = setTimeout(readFiles, 100);
2060
};
@@ -23,7 +63,7 @@ index e253906..1efc1db 100644
2363
const filePath = `/${filename}`;
2464
// events we should ignore because we caused them in the TutorialRunner
2565
if (!this._ignoreFileEvents.decrement(filePath)) {
26-
@@ -499,7 +499,8 @@ export class TutorialRunner {
66+
@@ -499,7 +509,8 @@ export class TutorialRunner {
2767
}
2868
});
2969
if (!this._editorStore.documents.get()[filePath]) {
@@ -33,7 +73,7 @@ index e253906..1efc1db 100644
3373
}
3474
this._updateCurrentFiles({ [filePath]: '' });
3575
scheduleReadFor(filePath, 'utf-8');
36-
@@ -543,3 +544,12 @@ async function updateFiles(webcontainer, previousFiles, newFiles) {
76+
@@ -543,3 +554,12 @@ async function updateFiles(webcontainer, previousFiles, newFiles) {
3777
}
3878
await webcontainer.mount(toFileTree(addedOrModified));
3979
}

src/content/tutorial/4-database/2-database-migrations/content.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ title: Database Migrations
44
custom:
55
shell:
66
workdir: "/workspace/store"
7+
fs:
8+
remove:
9+
- "/workspace/store"
710
---
811

912
Database Migrations

src/content/tutorial/4-database/3-running-migrations/content.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ title: Running Migrations
44
custom:
55
shell:
66
workdir: "/workspace/store"
7+
fs:
8+
remove:
9+
- "/workspace/store"
710
---
811

912
Running Migrations

src/content/tutorial/5-console/1-rails-console/content.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ title: Rails Console
44
custom:
55
shell:
66
workdir: "/workspace/store"
7+
fs:
8+
remove:
9+
- "/workspace/store"
710
---
811

912
Rails Console

0 commit comments

Comments
 (0)