Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions lib/plugins/save-resource-to-fs-plugin.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import path from 'path';
import fs from 'fs-extra';
import fs from 'fs';
import { outputFile } from '../utils/fs.js';

class SaveResourceToFileSystemPlugin {
apply (registerAction) {
Expand All @@ -20,13 +21,13 @@ class SaveResourceToFileSystemPlugin {
registerAction('saveResource', async ({resource}) => {
const filename = path.join(absoluteDirectoryPath, resource.getFilename());
const text = resource.getText();
await fs.outputFile(filename, text, { encoding: resource.getEncoding() });
await outputFile(filename, text, resource.getEncoding());
loadedResources.push(resource);
});

registerAction('error', async () => {
if (loadedResources.length > 0) {
await fs.remove(absoluteDirectoryPath);
fs.rmSync(absoluteDirectoryPath, {force: true, recursive: true});
}
});
}
Expand Down
13 changes: 13 additions & 0 deletions lib/utils/fs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import path from 'path';
import fs from 'fs/promises';

async function outputFile (file, data, encoding) {
const dir = path.dirname(file);
await fs.mkdir(dir, { recursive: true});

return fs.writeFile(file, data, { encoding: encoding });
}

export {
outputFile
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
"cheerio": "^1.1.2",
"css-url-parser": "^1.0.0",
"debug": "^4.3.1",
"fs-extra": "^11.1.0",
"got": "^14.4.7",
"normalize-url": "^8.0.0",
"p-queue": "^9.0.0",
Expand All @@ -50,6 +49,7 @@
"devDependencies": {
"c8": "^10.0.0",
"eslint": "^8.5.0",
"fs-extra": "^11.1.0",
"mocha": "^11.0.1",
"nock": "^14.0.0",
"should": "^13.2.3",
Expand Down