From a737f1d03f0ca14d41584310abeefcf8207fbef7 Mon Sep 17 00:00:00 2001 From: hello-smile6 <73048226+hello-smile6@users.noreply.github.com> Date: Mon, 6 Dec 2021 20:31:00 -0800 Subject: [PATCH] Revert "formatting" This reverts commit 7b066a4291cdcabd4a9d885ebaaea056052d07b6. --- scripts/ProjectSet.js | 8 +- scripts/add-project.js | 35 +++--- scripts/collate-projects.js | 30 +++--- scripts/save-project.js | 21 ++-- scripts/update-projects.js | 18 ++-- src/App.js | 178 ++++++++++++++----------------- src/components/Footer/index.js | 16 +-- src/components/Header/index.scss | 2 +- src/components/Layout/index.js | 14 ++- src/components/Main/index.js | 16 +-- src/components/Main/index.scss | 2 +- src/index.js | 10 +- src/scss/main.scss | 7 +- 13 files changed, 170 insertions(+), 187 deletions(-) diff --git a/scripts/ProjectSet.js b/scripts/ProjectSet.js index 72c0e6c4d..8ed3f7673 100644 --- a/scripts/ProjectSet.js +++ b/scripts/ProjectSet.js @@ -6,7 +6,7 @@ const PROJECTS_PATH = resolve(__dirname, "..", "projects.json"); class ProjectSet { hasRead = false; - projectSet = new Set(); + projectSet = new Set() read() { // If the program has already read from the projects file... @@ -23,11 +23,11 @@ class ProjectSet { } toArray() { - return [...this.projectSet].sort((a, b) => a - b); + return [...this.projectSet].sort((a, b) => a - b) } has(id) { - return this.projectSet.has(id); + return this.projectSet.has(id) } add(id) { @@ -36,7 +36,7 @@ class ProjectSet { save() { // The "null, 2" part prettifies the JSON file - writeFileSync(PROJECTS_PATH, JSON.stringify(this.toArray(), null, 2)); + writeFileSync(PROJECTS_PATH, JSON.stringify(this.toArray(), null, 2)) } } diff --git a/scripts/add-project.js b/scripts/add-project.js index e98d3e321..00ba5fdda 100644 --- a/scripts/add-project.js +++ b/scripts/add-project.js @@ -1,21 +1,20 @@ -import fetch from "node-fetch"; -import { read, has, add, save } from "./ProjectSet"; -import saveProject from "./save-project"; -import collateProjects from "./collate-projects"; +const fetch = require("node-fetch") +const projectSet = require("./ProjectSet") +const saveProject = require("./save-project"); +const collateProjects = require('./collate-projects'); -read(); +projectSet.read() -const id = process.env.PROJECT_ID || process.argv.slice(2)[0]; -if (!id) throw new Error("A project ID was not provided to the client."); -if (has(id)) - throw new Error("This project already is being listened to"); +const id = process.env.PROJECT_ID || process.argv.slice(2)[0] +if (!id) throw new Error('A project ID was not provided to the client.') +if (projectSet.has(id)) throw new Error("This project already is being listened to") -fetch(`https://api.scratch.mit.edu/projects/${id}/`).then((res) => { - if (!res.ok) - throw new Error(`Cannot fetch ${res.url} because of error ${res.status}`); - console.log("Archiving: ", id); - saveProject(id); - add(id); - save(); - collateProjects(); -}); +fetch(`https://api.scratch.mit.edu/projects/${id}/`) + .then((res) => { + if (!res.ok) throw new Error(`Cannot fetch ${res.url} because of error ${res.status}`) + console.log("Archiving: ", id); + saveProject(id) + projectSet.add(id) + projectSet.save() + collateProjects() + }) diff --git a/scripts/collate-projects.js b/scripts/collate-projects.js index 5540441ef..08f47cbdb 100644 --- a/scripts/collate-projects.js +++ b/scripts/collate-projects.js @@ -1,26 +1,24 @@ -import { readdirSync, existsSync, readFileSync, writeFileSync } from "fs"; -import { resolve } from "path"; +const fs = require("fs"); +const path = require("path"); -const DIST_PROJECT_FILE = resolve(__dirname, "..", "dist", "projects.json"); -const DIST_PATH = resolve(__dirname, "..", "dist"); -const PROJECTS_FOLDER = resolve(DIST_PATH, "projects"); +const DIST_PROJECT_FILE = path.resolve(__dirname, "..", "dist", "projects.json"); +const DIST_PATH = path.resolve(__dirname, '..', 'dist') +const PROJECTS_FOLDER = path.resolve(DIST_PATH, 'projects') const jsons = []; const collateProjects = () => { - const nodes = readdirSync(PROJECTS_FOLDER); + const nodes = fs.readdirSync(PROJECTS_FOLDER); for (const node of nodes) { - const jsonLocation = resolve(PROJECTS_FOLDER, node, "metadata.json"); - if (existsSync(jsonLocation)) { - const file = readFileSync(jsonLocation, { encoding: "utf-8" }); - jsons.push(JSON.parse(file)); - jsons.sort(function (a, b) { - return b + a; - }); + const jsonLocation = path.resolve(PROJECTS_FOLDER, node, 'metadata.json'); + if (fs.existsSync(jsonLocation)) { + const file = fs.readFileSync(jsonLocation, { encoding: 'utf-8' }) + jsons.push(JSON.parse(file)) + jsons.sort(function(a, b){return b + a}) } } - writeFileSync(DIST_PROJECT_FILE, JSON.stringify(jsons)); -}; + fs.writeFileSync(DIST_PROJECT_FILE, JSON.stringify(jsons)) +} -export default collateProjects; +module.exports = collateProjects diff --git a/scripts/save-project.js b/scripts/save-project.js index c6e856600..f843737b3 100644 --- a/scripts/save-project.js +++ b/scripts/save-project.js @@ -60,22 +60,19 @@ const saveProject = async (id) => { filename = "project.sb"; fs.writeFileSync(path.resolve(PROJECT_FOLDER, filename), buffer); - return "1.4"; + return "1.4" } const text = buffer.toString(); const parsed = JSON.parse(text); - + if (parsed.info) { version = "2.0"; } else if (parsed.meta) { version = "3.0"; } - fs.writeFileSync( - path.resolve(PROJECT_FOLDER, filename), - JSON.stringify(parsed, null, 2) - ); + fs.writeFileSync(path.resolve(PROJECT_FOLDER, filename), JSON.stringify(parsed, null, 2)); return version; }; @@ -96,17 +93,17 @@ const saveProject = async (id) => { ); const ocularStats = await saveJSON( `https://my-ocular.jeffalo.net/api/user/${metadata.author.username}`, - "status.json" - ); + 'status.json' + ) fs.writeFileSync( path.resolve(PROJECT_FOLDER, "metadata.json"), JSON.stringify( { id: metadata.id, - title: metadata.title || `Untitled Project ${metadata.id}`, - author: metadata.author.username || "Unknown", - pfp: metadata.author.profile.images["60x60"], - color: ocularStats.color || false, + title: (metadata.title || `Untitled Project ${metadata.id}`), + author: (metadata.author.username || 'Unknown'), + pfp: metadata.author.profile.images['60x60'], + color: (ocularStats.color || false), created: metadata.history.created, modified: metadata.history.modified, version, diff --git a/scripts/update-projects.js b/scripts/update-projects.js index bd988534a..0bf901d79 100644 --- a/scripts/update-projects.js +++ b/scripts/update-projects.js @@ -1,20 +1,20 @@ -import { read, toArray } from "./ProjectSet"; -import saveProject from "./save-project"; -import collateProjects from "./collate-projects"; +const projectSet = require("./ProjectSet") +const saveProject = require("./save-project"); +const collateProjects = require('./collate-projects'); -read(); +projectSet.read() const updateProjects = async () => { console.log("Updating Projects..."); - for (const id of toArray()) { + for (const id of projectSet.toArray()) { try { await saveProject(id); - console.log(`Saved ${id}!`); - } catch (e) { - console.error(`Failed to save ${id} because of an error: ${e}`); + console.log(`Saved ${id}!`) + } catch(e) { + console.error(`Failed to save ${id} because of an error: ${e}`) } } - console.log("Collating Projects..."); + console.log('Collating Projects...') collateProjects(); console.log("Updates Completed!"); }; diff --git a/src/App.js b/src/App.js index e487eba40..c926df956 100644 --- a/src/App.js +++ b/src/App.js @@ -4,15 +4,15 @@ import { Header } from "./components/Header"; import { Layout } from "./components/Layout"; import { Main } from "./components/Main"; function preventTags(str) { - return str.replace(/&/g, "&").replace(//g, ">"); + return str.replace(/&/g,'&').replace(//g,'>') ; } -var showID = true; +var showID = true function toggleID() { - if (showID == true) { - showID = false; - } else { - showID = true; - } + if (showID == true) { + showID = false + } else { + showID = true + } } class App extends Component { constructor(props) { @@ -42,8 +42,7 @@ class App extends Component { project.title .toLowerCase() .includes(this.state.nameSearch.toLowerCase()) - ) - .sort(); + ).sort() return ( @@ -85,11 +84,8 @@ class App extends Component { >
- - -
+ +

Results

@@ -118,95 +114,80 @@ class App extends Component { )} - {projects.map((project) => { - const created = new Date(project.created); - const modified = new Date(project.modified); - const author = project.author; + { + projects.map((project) => { + const created = new Date(project.created); + const modified = new Date(project.modified); + const author = project.author; - return ( - - {showID ? project.id : "-"} - {project.title} - - - {" "} - - | {project.author} - - - - - {created.toLocaleDateString()}{" "} - {created.toLocaleTimeString()} - - - {modified.toLocaleDateString()}{" "} - {modified.toLocaleTimeString()} - - -
- {project.version === "1.4" ? ( - + {showID ? project.id : "-"} + {project.title} + + {" "} | {project.author} + + {created.toLocaleDateString()}{" "} + {created.toLocaleTimeString()} + + + {modified.toLocaleDateString()}{" "} + {modified.toLocaleTimeString()} + + +
+ {project.version === "1.4" ? ( + + project.sb + + ) : ( + + project.json + + )} + {project.version === "2.0" && ( + + + )} + {project.version === "3.0" && ( + + + )} +
+ + +
+ - project.sb + view on scratch - ) : ( - - project.json + view full metadata - )} - {project.version === "2.0" && ( - - )} - {project.version === "3.0" && ( - - )} -
- - -
- - view on scratch - - - view full metadata - -
- - - ); - })} +
+ + + ); + })} )} @@ -218,10 +199,7 @@ class App extends Component {

ScratchBackup is a website unrelated to Scratch and/or MIT. We're open source at{" "} - + GitHub . diff --git a/src/components/Footer/index.js b/src/components/Footer/index.js index 75bf6d1ee..2ccd5f0c9 100644 --- a/src/components/Footer/index.js +++ b/src/components/Footer/index.js @@ -1,11 +1,15 @@ -import React from "react"; -import { Container } from "../Container"; -import "./index.scss"; +import React from "react" +import { Container } from "../Container" +import './index.scss'; const Footer = ({ children }) => (

-); +) -export { Footer }; +export { + Footer +} diff --git a/src/components/Header/index.scss b/src/components/Header/index.scss index 54ca68dfb..375e8fc0d 100644 --- a/src/components/Header/index.scss +++ b/src/components/Header/index.scss @@ -1,6 +1,6 @@ .header { background-color: #9000e3; font-size: 2.5em; - font-weight: bolder; + font-weight:bolder; color: white; } diff --git a/src/components/Layout/index.js b/src/components/Layout/index.js index 1a89246f9..01a9fa59f 100644 --- a/src/components/Layout/index.js +++ b/src/components/Layout/index.js @@ -1,6 +1,12 @@ -import React from "react"; -import "./index.scss"; +import React from "react" +import './index.scss'; -const Layout = ({ children }) =>
{children}
; +const Layout = ({ children }) => ( +
+ { children } +
+) -export { Layout }; +export { + Layout +} diff --git a/src/components/Main/index.js b/src/components/Main/index.js index 72f4ca11b..1fa59341d 100644 --- a/src/components/Main/index.js +++ b/src/components/Main/index.js @@ -1,11 +1,15 @@ -import React from "react"; -import { Container } from "../Container"; -import "./index.scss"; +import React from "react" +import { Container } from "../Container" +import './index.scss'; const Main = ({ children }) => (
- {children} + + { children } +
-); +) -export { Main }; +export { + Main +} diff --git a/src/components/Main/index.scss b/src/components/Main/index.scss index 93060aa49..f8105ec96 100644 --- a/src/components/Main/index.scss +++ b/src/components/Main/index.scss @@ -1,3 +1,3 @@ .main { - flex-grow: 1; + flex-grow: 1 } diff --git a/src/index.js b/src/index.js index 7b4d68496..04236b85c 100644 --- a/src/index.js +++ b/src/index.js @@ -1,7 +1,7 @@ -import React from "react"; -import ReactDOM from "react-dom"; -import { App } from "./App"; +import React from 'react'; +import ReactDOM from 'react-dom'; +import { App } from './App'; -import "./scss/main.scss"; +import './scss/main.scss' -ReactDOM.render(, document.querySelector("#entrypoint")); +ReactDOM.render(, document.querySelector('#entrypoint')) diff --git a/src/scss/main.scss b/src/scss/main.scss index 0af092b25..aecf56d66 100644 --- a/src/scss/main.scss +++ b/src/scss/main.scss @@ -13,10 +13,7 @@ a { color: black; text-decoration: none; font-weight: bold; -} -a:hover { - cursor: pointer; -} +} a:hover {cursor: pointer;} .table { td { padding: 0.25em 0.5em; @@ -58,7 +55,7 @@ a:hover { color: white; overflow-x: auto; } - + button { border-radius: 0.5em; padding: 0.5em;