add lint-fix task, fix linting errors in fetching examples code

This commit is contained in:
Cassie Tarakajian 2017-01-11 15:17:10 -05:00
parent 8120fdd7db
commit 1d6e59ada3
3 changed files with 25 additions and 25 deletions

View file

@ -6,6 +6,7 @@
"start": "BABEL_DISABLE_CACHE=1 NODE_ENV=development nodemon index.js",
"start:prod": "NODE_ENV=production node index.js",
"lint": "eslint client server",
"lint-fix": "eslint client server --fix",
"build": "NODE_ENV=production webpack --config webpack.config.prod.js --progress",
"test": "echo \"Error: no test specified\" && exit 1",
"fetch-examples": "node fetch-examples.js",

View file

@ -1,7 +1,7 @@
import rp from 'request-promise';
import Q from 'q';
import mongoose from 'mongoose';
import objectID from 'bson-objectid'
import objectID from 'bson-objectid';
import shortid from 'shortid';
import User from './models/user';
import Project from './models/project';
@ -39,7 +39,7 @@ const r = objectID().toHexString();
const client_id = process.env.GITHUB_ID;
const client_secret = process.env.GITHUB_SECRET;
const headers = {'User-Agent': 'p5js-web-editor/0.0.1'};
const headers = { 'User-Agent': 'p5js-web-editor/0.0.1' };
mongoose.connect(process.env.MONGO_URL);
mongoose.connection.on('error', () => {
@ -50,7 +50,7 @@ mongoose.connection.on('error', () => {
getp5User();
function getp5User() {
User.findOne({username: 'p5'}, (err, user) => {
User.findOne({ username: 'p5' }, (err, user) => {
if (err) throw err;
if (!user) {
@ -65,11 +65,11 @@ function getp5User() {
});
}
Project.find({user: user._id}, (err, projects) => {
Project.find({ user: user._id }, (err, projects) => {
// if there are already some sketches, delete them
console.log('Deleting old projects...');
projects.forEach(project => {
Project.remove({_id: project._id}, err => {
Project.remove({ _id: project._id }, err => {
if (err) throw err;
});
});
@ -85,10 +85,10 @@ function getp5User() {
function getCategories() {
let categories = [];
const options = {
url: 'https://api.github.com/repos/processing/p5.js-website/contents/dist/assets/examples/en?client_id='+
client_id+'&client_secret='+client_secret,
url: 'https://api.github.com/repos/processing/p5.js-website/contents/dist/assets/examples/en?client_id=' +
client_id + '&client_secret=' + client_secret,
method: 'GET',
headers: headers
headers
};
return rp(options).then(res => {
const json = JSON.parse(res);
@ -98,7 +98,7 @@ function getCategories() {
for (let j = 1; j < metadata.name.split('_').length; j++) {
category += metadata.name.split('_')[j] + ' ';
}
categories.push({url: metadata.url, name: category});
categories.push({ url: metadata.url, name: category });
});
return categories;
@ -110,9 +110,9 @@ function getCategories() {
function getSketchesInCategories(categories) {
return Q.all(categories.map(category => {
const options = {
url: category.url.replace('?ref=master', '')+'?client_id='+client_id+'&client_secret='+client_secret,
url: category.url.replace('?ref=master', '') + '?client_id=' + client_id + '&client_secret=' + client_secret,
method: 'GET',
headers: headers
headers
};
return rp(options).then(res => {
@ -123,32 +123,31 @@ function getSketchesInCategories(categories) {
if (example.name === '02_Instance_Container.js') {
for (let i = 1; i < 5; i++) {
const instanceProjectName = category.name + ': ' + 'Instance Container ' + i;
projectsInOneCategory.push({sketchUrl: example.download_url, projectName: instanceProjectName});
projectsInOneCategory.push({ sketchUrl: example.download_url, projectName: instanceProjectName });
}
} else {
if (example.name.split('_')[1]) {
projectName = category.name + ': '+ example.name.split('_').slice(1).join(' ').replace('.js', '');
projectName = category.name + ': ' + example.name.split('_').slice(1).join(' ').replace('.js', '');
} else {
projectName = category.name + ': '+ example.name.replace('.js', '');
projectName = category.name + ': ' + example.name.replace('.js', '');
}
projectsInOneCategory.push({sketchUrl: example.download_url, projectName: projectName});
projectsInOneCategory.push({ sketchUrl: example.download_url, projectName });
}
});
return projectsInOneCategory;
}).catch(err => {
throw err;
});
}));
}
function getSketchContent(projectsInAllCategories) {
return Q.all(projectsInAllCategories.map(projectsInOneCategory => {
return Q.all(projectsInOneCategory.map(project => {
return Q.all(projectsInOneCategory.map(project => {
const options = {
url: project.sketchUrl.replace('?ref=master', '')+'?client_id='+client_id+'&client_secret='+client_secret,
url: project.sketchUrl.replace('?ref=master', '') + '?client_id=' + client_id + '&client_secret=' + client_secret,
method: 'GET',
headers: headers
headers
};
return rp(options).then(res => {
@ -172,16 +171,16 @@ function getSketchContent(projectsInAllCategories) {
function createProjectsInP5user(projectsInAllCategories) {
let assetsfiles = [];
const options = {
url: 'https://api.github.com/repos/processing/p5.js-website/contents/dist/assets/examples/assets?client_id='+
client_id+'&client_secret='+client_secret,
url: 'https://api.github.com/repos/processing/p5.js-website/contents/dist/assets/examples/assets?client_id=' +
client_id + '&client_secret=' + client_secret,
method: 'GET',
headers: headers
headers
};
rp(options).then(res => {
const assets = JSON.parse(res);
User.findOne({username: 'p5'}, (err, user) => {
User.findOne({ username: 'p5' }, (err, user) => {
if (err) throw err;
async.eachSeries(projectsInAllCategories, (projectsInOneCategory, categoryCallback) => {
@ -310,7 +309,7 @@ function createProjectsInP5user(projectsInAllCategories) {
}
});
newProject.save( (err, newProject) => {
newProject.save((err, newProject) => {
if (err) throw err;
console.log('Created a new project in p5 user: ' + newProject.name);
projectCallback();
@ -322,7 +321,6 @@ function createProjectsInP5user(projectsInAllCategories) {
process.exit();
});
});
}).catch(err => {
throw err;
});

View file

@ -1,3 +1,4 @@
/* eslint-disable */
import mongoose from 'mongoose';
import path from 'path';
import { uniqWith, isEqual } from 'lodash';