Skip to content

Commit

Permalink
use fs-extra
Browse files Browse the repository at this point in the history
  • Loading branch information
vishvamsinh28 committed Oct 19, 2024
1 parent 8f2162d commit c2ee924
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 103 deletions.
124 changes: 36 additions & 88 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
"clsx": "^2.1.0",
"cssnano": "^6.0.3",
"dotenv": "^16.4.4",
"fs-extra": "^11.2.0",
"fuse.js": "^7.0.0",
"googleapis": "^133.0.0",
"gray-matter": "^4.0.3",
Expand Down
4 changes: 2 additions & 2 deletions scripts/build-newsroom-videos.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { writeFileSync } = require('fs');
const { writeFileSync } = require('fs-extra');
const { resolve } = require('path');
const fetch = require('node-fetch-2');

Expand All @@ -19,7 +19,7 @@ async function buildNewsroomVideos(writePath) {
}

const data = await response.json();
console.log(data)
console.log(data);

if (!data.items || !Array.isArray(data.items)) {
throw new Error('Invalid data structure received from YouTube API');
Expand Down
7 changes: 2 additions & 5 deletions scripts/build-tools.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
const { getData } = require('./tools/extract-tools-github');
const { convertTools } = require('./tools/tools-object');
const { combineTools } = require('./tools/combine-tools');
const fs = require('fs');
const fs = require('fs-extra');
const { resolve } = require('path');

const buildTools = async (automatedToolsPath, manualToolsPath, toolsPath, tagsPath) => {
try {
let githubExtractData = await getData();
let automatedTools = await convertTools(githubExtractData);

fs.writeFileSync(
automatedToolsPath,
JSON.stringify(automatedTools, null, ' ')
);
await fs.writeFile(automatedToolsPath, JSON.stringify(automatedTools, null, ' '));

await combineTools(automatedTools, require(manualToolsPath), toolsPath, tagsPath);
} catch (err) {
Expand Down
6 changes: 3 additions & 3 deletions tests/build-newsroom-videos.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { readFileSync, rmSync, mkdirSync } = require('fs');
const { readFileSync, removeSync, mkdirpSync } = require('fs-extra');
const { resolve } = require('path');
const { buildNewsroomVideos } = require('../scripts/build-newsroom-videos');
const { mockApiResponse, expectedResult } = require('./fixtures/newsroomData');
Expand All @@ -11,12 +11,12 @@ describe('buildNewsroomVideos', () => {
const testFilePath = resolve(testDir, 'newsroom_videos.json');

beforeAll(() => {
mkdirSync(testDir, { recursive: true });
mkdirpSync(testDir);
process.env.YOUTUBE_TOKEN = 'testkey';
});

afterAll(() => {
rmSync(testDir, { recursive: true, force: true });
removeSync(testDir);
});

beforeEach(() => {
Expand Down
9 changes: 4 additions & 5 deletions tests/build-tools.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const axios = require('axios');
const { resolve } = require('path');
const { buildTools } = require('../scripts/build-tools');
const { tagsData, manualTools, mockConvertedData, mockExtractData } = require('../tests/fixtures/buildToolsData');
const fs = require('fs');
const fs = require('fs-extra');

jest.mock('axios');
jest.mock('../scripts/tools/categorylist', () => ({
Expand Down Expand Up @@ -34,12 +34,12 @@ describe('buildTools', () => {
beforeAll(() => {
consoleErrorMock = jest.spyOn(console, 'error').mockImplementation(() => {});

fs.mkdirSync(testDir, { recursive: true });
fs.writeFileSync(manualToolsPath, JSON.stringify(manualTools));
fs.ensureDirSync(testDir);
fs.outputFileSync(manualToolsPath, JSON.stringify(manualTools));
});

afterAll(() => {
fs.rmSync(testDir, { recursive: true, force: true });
fs.removeSync(testDir);
consoleErrorMock.mockRestore();
});

Expand All @@ -66,7 +66,6 @@ describe('buildTools', () => {
expect(combinedToolsContent["Category2"].description).toEqual(mockConvertedData["Category2"].description);

expect(tagsContent).toEqual(tagsData);

});

it('should handle getData error', async () => {
Expand Down

0 comments on commit c2ee924

Please sign in to comment.