@tutorialkit-rb/runtime 1.5.2-rb.0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/README.md +18 -0
  2. package/dist/index.d.ts +3 -0
  3. package/dist/index.js +2 -0
  4. package/dist/lesson-files.d.ts +22 -0
  5. package/dist/lesson-files.js +126 -0
  6. package/dist/store/editor.d.ts +29 -0
  7. package/dist/store/editor.js +127 -0
  8. package/dist/store/index.d.ts +113 -0
  9. package/dist/store/index.js +316 -0
  10. package/dist/store/previews.d.ts +19 -0
  11. package/dist/store/previews.js +80 -0
  12. package/dist/store/terminal.d.ts +24 -0
  13. package/dist/store/terminal.js +128 -0
  14. package/dist/store/tutorial-runner.d.ts +147 -0
  15. package/dist/store/tutorial-runner.js +564 -0
  16. package/dist/tasks.d.ts +22 -0
  17. package/dist/tasks.js +26 -0
  18. package/dist/utils/multi-counter.d.ts +5 -0
  19. package/dist/utils/multi-counter.js +19 -0
  20. package/dist/utils/promises.d.ts +8 -0
  21. package/dist/utils/promises.js +29 -0
  22. package/dist/utils/support.d.ts +1 -0
  23. package/dist/utils/support.js +23 -0
  24. package/dist/utils/terminal.d.ts +17 -0
  25. package/dist/utils/terminal.js +13 -0
  26. package/dist/webcontainer/command.d.ts +28 -0
  27. package/dist/webcontainer/command.js +67 -0
  28. package/dist/webcontainer/editor-config.d.ts +12 -0
  29. package/dist/webcontainer/editor-config.js +60 -0
  30. package/dist/webcontainer/index.d.ts +4 -0
  31. package/dist/webcontainer/index.js +4 -0
  32. package/dist/webcontainer/on-demand-boot.d.ts +15 -0
  33. package/dist/webcontainer/on-demand-boot.js +39 -0
  34. package/dist/webcontainer/port-info.d.ts +6 -0
  35. package/dist/webcontainer/port-info.js +10 -0
  36. package/dist/webcontainer/preview-info.d.ts +21 -0
  37. package/dist/webcontainer/preview-info.js +56 -0
  38. package/dist/webcontainer/shell.d.ts +14 -0
  39. package/dist/webcontainer/shell.js +46 -0
  40. package/dist/webcontainer/steps.d.ts +15 -0
  41. package/dist/webcontainer/steps.js +38 -0
  42. package/dist/webcontainer/terminal-config.d.ts +59 -0
  43. package/dist/webcontainer/terminal-config.js +230 -0
  44. package/dist/webcontainer/utils/files.d.ts +10 -0
  45. package/dist/webcontainer/utils/files.js +76 -0
  46. package/package.json +53 -0
@@ -0,0 +1,147 @@
1
+ import type { CommandsSchema, Files } from '@tutorialkit-rb/types';
2
+ import type { WebContainer } from '@webcontainer/api';
3
+ import { type TaskCancelled } from '../tasks.js';
4
+ import { StepsController } from '../webcontainer/steps.js';
5
+ import type { EditorStore } from './editor.js';
6
+ import type { TerminalStore } from './terminal.js';
7
+ interface LoadFilesOptions {
8
+ /**
9
+ * The list of files to load.
10
+ */
11
+ files: Files | Promise<Files>;
12
+ /**
13
+ * The template to load.
14
+ */
15
+ template?: Files | Promise<Files>;
16
+ /**
17
+ * If true, all files will be removed (except for `node_modules`).
18
+ *
19
+ * @default false
20
+ */
21
+ removeAllFiles?: boolean;
22
+ /**
23
+ * Paths to remove before loading new files.
24
+ */
25
+ removePaths?: string[];
26
+ /**
27
+ * Abort the previous load files operation.
28
+ *
29
+ * @default true
30
+ */
31
+ abortPreviousLoad?: boolean;
32
+ /**
33
+ * A signal to abort this operation.
34
+ */
35
+ signal?: AbortSignal;
36
+ }
37
+ interface RunCommandsOptions {
38
+ /**
39
+ * Abort the previous run commands operation.
40
+ *
41
+ * @default true
42
+ */
43
+ abortPreviousRun?: boolean;
44
+ }
45
+ /**
46
+ * The idea behind this class is that it manages the state of WebContainer and exposes
47
+ * an interface that makes sense to every component of TutorialKit.
48
+ *
49
+ * There should be only a single instance of this class.
50
+ */
51
+ export declare class TutorialRunner {
52
+ private _webcontainer;
53
+ private _terminalStore;
54
+ private _editorStore;
55
+ private _stepController;
56
+ private _currentLoadTask;
57
+ private _currentProcessTask;
58
+ private _currentCommandProcess;
59
+ private _currentTemplate;
60
+ private _currentFiles;
61
+ private _currentRunCommands;
62
+ private _ignoreFileEvents;
63
+ private _watcher;
64
+ private _watchContentFromWebContainer;
65
+ private _readyToWatch;
66
+ private _packageJsonDirty;
67
+ private _commandsChanged;
68
+ private _packageJsonContent;
69
+ private _packageJsonPath;
70
+ constructor(_webcontainer: Promise<WebContainer>, _terminalStore: TerminalStore, _editorStore: EditorStore, _stepController: StepsController);
71
+ setWatchFromWebContainer(value: boolean | string[]): void;
72
+ /**
73
+ * Set the commands to run. This updates the reported `steps` if any have changed.
74
+ *
75
+ * This function is safe to call server side.
76
+ *
77
+ * To actually run them in WebContainer see `runCommands`.
78
+ *
79
+ * @param commands The commands schema.
80
+ */
81
+ setCommands(commands: CommandsSchema): void;
82
+ onTerminalResize(cols: number, rows: number): void;
83
+ createFolder(folderPath: string): void;
84
+ /**
85
+ * Update the content of a single file in WebContainer.
86
+ *
87
+ * @param filePath path of the file
88
+ * @param content new content of the file
89
+ */
90
+ updateFile(filePath: string, content: string): void;
91
+ /**
92
+ * Update the provided files in WebContainer.
93
+ *
94
+ * @param files Files to update.
95
+ */
96
+ updateFiles(files: Files): void;
97
+ fileExists(filepath: string): Promise<boolean>;
98
+ folderExists(folderPath: string): Promise<boolean>;
99
+ private _fsExists;
100
+ /**
101
+ * Load the provided files into WebContainer and remove any other files that had been loaded previously.
102
+ *
103
+ * This function always waits for any previous `prepareFiles` or `updateFile(s)` call to have completed
104
+ * before sending the next one.
105
+ *
106
+ * Previous load operations will be cancelled if `options.abortPreviousLoad` was set to true (which is the default).
107
+ *
108
+ * @see {LoadFilesOptions}
109
+ */
110
+ prepareFiles({ files, template, signal, abortPreviousLoad, removePaths, }: LoadFilesOptions): Promise<void | TaskCancelled>;
111
+ /**
112
+ * Runs the list of commands set with `setCommands`.
113
+ *
114
+ * This function always wait for any previous `runCommands` call to have completed before sending the next one.
115
+ * It will cancel the previous operation if `options.abortPreviousRun` was set to true.
116
+ *
117
+ * Commands are split into two:
118
+ *
119
+ * - `prepareCommands`: For example commands like `npm install`, `mkdir -p src/foobar`, etc.
120
+ * - `mainCommand`: Used to for example run a dev server or equivalent.
121
+ *
122
+ * @see {LoadFilesOptions}
123
+ */
124
+ runCommands({ abortPreviousRun }?: RunCommandsOptions): void;
125
+ /**
126
+ * Restart the last run commands that were submitted.
127
+ */
128
+ restartLastRunCommands(): void;
129
+ /**
130
+ * Get snapshot of runner's current files.
131
+ * Also prepares `package.json`'s `stackblitz.startCommand` with runner's commands.
132
+ *
133
+ * Note that file paths do not contain the leading `/`.
134
+ */
135
+ takeSnapshot(): {
136
+ files: Record<string, string>;
137
+ };
138
+ private _runCommands;
139
+ private _newProcess;
140
+ private _updateDirtyState;
141
+ private _updateCurrentFiles;
142
+ private _stopWatcher;
143
+ private _setupWatcher;
144
+ private _clearDirtyState;
145
+ private _changeDetection;
146
+ }
147
+ export {};