mirror of
https://github.com/status-im/ETHReport.git
synced 2025-02-18 00:46:38 +00:00
Automatically transform JSON
This commit is contained in:
parent
6a8ede1cee
commit
bad161405c
53
bin/transform-json/index.js
Normal file
53
bin/transform-json/index.js
Normal file
@ -0,0 +1,53 @@
|
||||
const fs = require('fs');
|
||||
|
||||
const file = './data/archives/interviews.json';
|
||||
const targetFile = './data/archives/cleanInterviews.json';
|
||||
|
||||
fs.exists(file, (exists) => {
|
||||
if (exists) {
|
||||
// eslint-disable-next-line
|
||||
console.log("File found. Attempting transform");
|
||||
|
||||
fs.readFile(file, (err, data) => {
|
||||
if (err) {
|
||||
// eslint-disable-next-line
|
||||
console.log(err);
|
||||
} else {
|
||||
const interviews = JSON.parse(data);
|
||||
const { length } = Object.keys(interviews);
|
||||
const betterInterviews = [];
|
||||
|
||||
for (let i = 0; i < length; i++) {
|
||||
const interview = interviews[i];
|
||||
const qKeys = Object.keys(interview);
|
||||
const interviewFormatted = [];
|
||||
|
||||
qKeys.forEach((key) => {
|
||||
if (key !== 'name' && interview[key] !== null && interview[key].answer !== null && interview[key].answer !== '') {
|
||||
interviewFormatted.push({
|
||||
question: key,
|
||||
answer: interview[key].answer,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
betterInterviews.push({
|
||||
id: i + 1,
|
||||
name: interview.name,
|
||||
matchedIndex: -1,
|
||||
interview: interviewFormatted,
|
||||
});
|
||||
}
|
||||
|
||||
const json = JSON.stringify(betterInterviews);
|
||||
fs.writeFile(targetFile, json);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// eslint-disable-next-line
|
||||
console.log("File does not exist. Creating empty file and exiting.")
|
||||
const interviewData = {};
|
||||
const json = JSON.stringify(interviewData);
|
||||
fs.writeFile(targetFile, json);
|
||||
}
|
||||
});
|
@ -7,7 +7,8 @@ import TopicsList from '../topicsList';
|
||||
import ProjectsList from '../projectsList';
|
||||
import SearchBar from '../searchBar';
|
||||
import SearchResults from '../searchResults';
|
||||
import { InterviewData, Questions } from '../../data/archives/interviews';
|
||||
import { Questions } from '../../data/archives/questions';
|
||||
import InterviewData from '../../data/archives/cleanInterviews.json';
|
||||
import './style.scss';
|
||||
|
||||
class BrowseArchives extends React.Component {
|
||||
@ -22,7 +23,7 @@ class BrowseArchives extends React.Component {
|
||||
isInterviewsListModalOpen: false,
|
||||
activeSingleInterviewId: 1,
|
||||
isSearchActive: false,
|
||||
interviewData: this.transformInterviews(InterviewData),
|
||||
interviewData: InterviewData,
|
||||
matchedCount: 0,
|
||||
};
|
||||
|
||||
@ -31,7 +32,6 @@ class BrowseArchives extends React.Component {
|
||||
this.toggleInterviewsListModal = this.toggleInterviewsListModal.bind(this);
|
||||
this.setSearchTerm = this.setSearchTerm.bind(this);
|
||||
this.clearSearchInput = this.clearSearchInput.bind(this);
|
||||
this.transformInterviews = this.transformInterviews.bind(this);
|
||||
this.termIsInInterview = this.termIsInInterview.bind(this);
|
||||
this.getSearchResultsDebounce = this.getSearchResultsDebounce.bind(this);
|
||||
}
|
||||
@ -112,36 +112,6 @@ class BrowseArchives extends React.Component {
|
||||
});
|
||||
}
|
||||
|
||||
// used as an intermediary to give us an easy to search through JSON object
|
||||
transformInterviews = (interviews) => {
|
||||
const { length } = Object.keys(interviews);
|
||||
const betterInterviews = [];
|
||||
|
||||
for (let i = 0; i < length; i++) {
|
||||
const interview = interviews[i];
|
||||
const qKeys = Object.keys(interview);
|
||||
const interviewFormatted = [];
|
||||
|
||||
qKeys.forEach((key) => {
|
||||
if (key !== 'name' && interview[key] !== null && interview[key].answer !== null && interview[key].answer !== '') {
|
||||
interviewFormatted.push({
|
||||
question: key,
|
||||
answer: interview[key].answer,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
betterInterviews.push({
|
||||
id: i + 1,
|
||||
name: interview.name,
|
||||
matchedIndex: -1,
|
||||
interview: interviewFormatted,
|
||||
});
|
||||
}
|
||||
|
||||
return betterInterviews;
|
||||
}
|
||||
|
||||
toggleInterviewsListModal = () => {
|
||||
const { isInterviewsListModalOpen } = this.state;
|
||||
|
||||
|
1
data/archives/cleanInterviews.json
Normal file
1
data/archives/cleanInterviews.json
Normal file
File diff suppressed because one or more lines are too long
@ -1,4 +1,4 @@
|
||||
const InterviewData = {
|
||||
{
|
||||
"0": {
|
||||
"name": "Fabio Berger + Remco Bloemen",
|
||||
"who_what": {
|
||||
@ -6730,25 +6730,3 @@ const InterviewData = {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const Questions = [
|
||||
{ id: 'smart_contract', text: 'How do you handle smart contract verification and security?' },
|
||||
{ id: 'bounties', text: 'Other bounties?' },
|
||||
{ id: 'who_what', text: 'Who are you and what are you working on?' },
|
||||
{ id: 'tooling', text: 'What are the tools/libraries/frameworks you use?' },
|
||||
{ id: 'frustrations', text: 'What are your biggest frustrations?' },
|
||||
{ id: 'testing', text: 'How do you handle testing?' },
|
||||
{ id: 'missing_tools', text: 'What tools don’t exist at the moment?' },
|
||||
{ id: 'domain', text: 'Other domain specific questions?' },
|
||||
{ id: 'ethereum', text: 'What was the hardest part about learning to develop with Ethereum?' },
|
||||
{ id: 'short_term', text: 'What are you most excited about in the short term?' },
|
||||
{ id: 'ease', text: 'Was anything easier than expected?' },
|
||||
{ id: 'other_people', text: 'Who are the other people you think we should talk to?' },
|
||||
{ id: 'resources', text: 'What are the best educational resources?' },
|
||||
{ id: 'other_questions', text: 'Are there any other questions we should be asking?' }
|
||||
]
|
||||
|
||||
module.exports = {
|
||||
InterviewData,
|
||||
Questions
|
||||
}
|
20
data/archives/questions.js
Normal file
20
data/archives/questions.js
Normal file
@ -0,0 +1,20 @@
|
||||
const Questions = [
|
||||
{ id: 'smart_contract', text: 'How do you handle smart contract verification and security?' },
|
||||
{ id: 'bounties', text: 'Other bounties?' },
|
||||
{ id: 'who_what', text: 'Who are you and what are you working on?' },
|
||||
{ id: 'tooling', text: 'What are the tools/libraries/frameworks you use?' },
|
||||
{ id: 'frustrations', text: 'What are your biggest frustrations?' },
|
||||
{ id: 'testing', text: 'How do you handle testing?' },
|
||||
{ id: 'missing_tools', text: 'What tools don’t exist at the moment?' },
|
||||
{ id: 'domain', text: 'Other domain specific questions?' },
|
||||
{ id: 'ethereum', text: 'What was the hardest part about learning to develop with Ethereum?' },
|
||||
{ id: 'short_term', text: 'What are you most excited about in the short term?' },
|
||||
{ id: 'ease', text: 'Was anything easier than expected?' },
|
||||
{ id: 'other_people', text: 'Who are the other people you think we should talk to?' },
|
||||
{ id: 'resources', text: 'What are the best educational resources?' },
|
||||
{ id: 'other_questions', text: 'Are there any other questions we should be asking?' },
|
||||
];
|
||||
|
||||
module.exports = {
|
||||
Questions,
|
||||
};
|
13
package.json
13
package.json
@ -4,13 +4,14 @@
|
||||
"description": "ETHPrize website",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"dev": "next",
|
||||
"build": "next build",
|
||||
"start": "next start",
|
||||
"serve": "next build && next start",
|
||||
"prod-build": "next build && next export && touch out/.nojekyll",
|
||||
"dev": "npm run transform && next",
|
||||
"build": "npm run transform && next build",
|
||||
"start": "npm run transform && next start",
|
||||
"serve": "npm run transform && next build && next start",
|
||||
"prod-build": "npm run transform && next build && next export && touch out/.nojekyll",
|
||||
"deploy": "deploy-to-git && rm -rf out",
|
||||
"lint": "eslint \"components/**/*.js\" \"pages/*.js\"\"data/**/*.js\""
|
||||
"lint": "eslint \"components/**/*.js\" \"pages/*.js\"\"data/**/*.js\"",
|
||||
"transform": "node bin/transform-json"
|
||||
},
|
||||
"config": {
|
||||
"deployToGit": {
|
||||
|
Loading…
x
Reference in New Issue
Block a user