Automatically transform JSON

This commit is contained in:
Wisani Shilumani 2018-07-20 11:16:50 +02:00
parent 6a8ede1cee
commit bad161405c
6 changed files with 85 additions and 62 deletions

View 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);
}
});

View File

@ -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;

File diff suppressed because one or more lines are too long

View File

@ -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 dont 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
}

View 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 dont 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,
};

View File

@ -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": {