(action: ActionState)
| 150 | } |
| 151 | |
| 152 | async #runFileAction(action: ActionState) { |
| 153 | if (action.type !== 'file') { |
| 154 | unreachable('Expected file action'); |
| 155 | } |
| 156 | |
| 157 | const webcontainer = await this.#webcontainer; |
| 158 | |
| 159 | let folder = nodePath.dirname(action.filePath); |
| 160 | |
| 161 | // remove trailing slashes |
| 162 | folder = folder.replace(/\/+$/g, ''); |
| 163 | |
| 164 | if (folder !== '.') { |
| 165 | try { |
| 166 | await webcontainer.fs.mkdir(folder, { recursive: true }); |
| 167 | logger.debug('Created folder', folder); |
| 168 | } catch (error) { |
| 169 | logger.error('Failed to create folder\n\n', error); |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | try { |
| 174 | await webcontainer.fs.writeFile(action.filePath, action.content); |
| 175 | logger.debug(`File written ${action.filePath}`); |
| 176 | } catch (error) { |
| 177 | logger.error('Failed to write file\n\n', error); |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | #updateAction(id: string, newState: ActionStateUpdate) { |
| 182 | const actions = this.actions.get(); |
no test coverage detected