Merge branch 'devel' of https://github.com/VulcanJS/Vulcan into devel

This commit is contained in:
Sacha Greif 2017-10-31 10:19:23 +09:00
commit e025e0ad89
6 changed files with 85 additions and 9 deletions

View file

@ -2,7 +2,7 @@
# Vulcan (formerly Telescope)
[Version 1.6.0](https://github.com/TelescopeJS/Telescope/releases)
[Version 1.8.0](https://github.com/VulcanJS/Vulcan/releases)
This is the Apollo/GraphQL version of Telescope, now known as [Vulcan](http://vulcanjs.org). [You can find the documentation here](http://docs.vulcanjs.org/).

View file

@ -5,11 +5,12 @@
"npm": "^3.0"
},
"scripts": {
"prestart": "sh prestart_vulcan.sh",
"prestart": "node prestart_vulcan.js",
"start": "meteor --settings settings.json",
"lint": "eslint --cache --ext .jsx,js packages"
},
"dependencies": {
"chalk": "2.2.0",
"analytics-node": "^2.1.1",
"apollo-client": "^1.2.2",
"apollo-errors": "^1.4.0",

View file

@ -0,0 +1,3 @@
import Votes from '../modules/votes/collection.js';
Votes._ensureIndex({ "userId": 1, "documentId": 1 });

View file

@ -1,5 +1,6 @@
import './graphql.js';
import './cron.js';
import './scoring.js';
import './indexes.js';
export * from '../modules/index.js';

View file

@ -10,17 +10,18 @@ Returns how many documents have been updated (1 or 0).
export const updateScore = ({collection, item, forceUpdate}) => {
// Age Check
// If for some reason item doesn't have a "postedAt" property, abort
// Or, if post has been scheduled in the future, don't update its score
if (!item.postedAt || postedAt > now)
return 0;
const postedAt = item.postedAt.valueOf();
const postedAt = item && item.postedAt && item.postedAt.valueOf();
const now = new Date().getTime();
const age = now - postedAt;
const ageInHours = age / (60 * 60 * 1000);
// If for some reason item doesn't have a "postedAt" property, abort
// Or, if post has been scheduled in the future, don't update its score
if (postedAt || postedAt > now)
return 0;
// For performance reasons, the database is only updated if the difference between the old score and the new score
// is meaningful enough. To find out, we calculate the "power" of a single vote after n days.
// We assume that after n days, a single vote will not be powerful enough to affect posts' ranking order.

70
prestart_vulcan.js Normal file
View file

@ -0,0 +1,70 @@
#!/usr/bin/env node
//Functions
var fs = require('fs');
function existsSync(filePath){
try{
fs.statSync(filePath);
}catch(err){
if(err.code == 'ENOENT') return false;
}
return true;
}
function copySync(origin,target){
try{
fs.writeFileSync(target, fs.readFileSync(origin));
}catch(err){
if(err.code == 'ENOENT') return false;
}
return true;
}
//Add Definition Colors
const chalk = require('chalk');
//Vulkan letters
console.log(chalk.gray(' ___ ___ '));
console.log(chalk.gray(' '+String.fromCharCode(92))+chalk.redBright(String.fromCharCode(92))+chalk.dim.yellow(String.fromCharCode(92))+chalk.gray(String.fromCharCode(92)+' /')+chalk.dim.yellow('/')+chalk.yellowBright('/')+chalk.gray('/'));
console.log(chalk.gray(' '+String.fromCharCode(92))+chalk.redBright(String.fromCharCode(92))+chalk.dim.yellow(String.fromCharCode(92))+chalk.gray(String.fromCharCode(92))+chalk.gray('/')+chalk.dim.yellow('/')+chalk.yellowBright('/')+chalk.gray('/ Vulcan.js'));
console.log(chalk.gray(' '+String.fromCharCode(92))+chalk.redBright(String.fromCharCode(92))+chalk.dim.yellow(String.fromCharCode(92))+chalk.dim.yellow('/')+chalk.yellowBright('/')+chalk.gray('/ The full-stack React+GraphQL framework'));
console.log(chalk.gray(' ──── '));
var os = require('os');
var exec = require('child_process').execSync;
var options = {
encoding: 'utf8'
};
//Check Meteor and install if not installed
var checker = exec("meteor --version", options);
if (!checker.includes("Meteor ")) {
console.log("Vulcan requires Meteor but it's not installed. Trying to Install...");
//Check platform
if (os.platform()=='darwin') {
//Mac OS platform
console.log("🌋 "+chalk.bold.yellow("Good news you have a Mac and we will install it now! }"));
console.log(exec("curl https://install.meteor.com/ | bash", options));
} else if (os.platform()=='linux') {
//GNU/Linux platform
console.log("🌋 "+chalk.bold.yellow("Good news you are on GNU/Linux platform and we will install Meteor now!"));
console.log(exec("curl https://install.meteor.com/ | bash", options));
} else if (os.platform()=='win32') {
//Windows NT platform
console.log("> "+chalk.bold.yellow("Oh no! you are on a Windows platform and you will need to install Meteor Manually!"));
console.log("> "+chalk.dim.yellow("Meteor for Windows is available at: ")+chalk.redBright("https://install.meteor.com/windows"));
process.exit(-1)
}
} else {
//Check exist file settings and create if not exist
if (!existsSync("settings.json")) {
console.log("> "+chalk.bold.yellow("Creating your own settings.json file...\n"));
if (!copySync("sample_settings.json","settings.json")) {
console.log("> "+chalk.bold.red("Error Creating your own settings.json file...check files and permissions\n"));
process.exit(-1);
}
}
console.log("> "+chalk.bold.yellow("Happy hacking with Vulcan!"));
console.log("> "+chalk.dim.yellow("The docs are available at: ")+chalk.redBright("http://docs.vulcanjs.org"));
}