mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
[misc] run format:fix
This commit is contained in:
parent
c0dd3df094
commit
1b63336d36
3 changed files with 993 additions and 839 deletions
537
Gruntfile.js
537
Gruntfile.js
|
@ -16,254 +16,292 @@
|
||||||
* DS207: Consider shorter variations of null checks
|
* DS207: Consider shorter variations of null checks
|
||||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||||
*/
|
*/
|
||||||
const coffee = require("coffee-script");
|
const coffee = require('coffee-script')
|
||||||
const fs = require("fs");
|
const fs = require('fs')
|
||||||
const {
|
const { spawn } = require('child_process')
|
||||||
spawn
|
const { exec } = require('child_process')
|
||||||
} = require("child_process");
|
const rimraf = require('rimraf')
|
||||||
const {
|
const Path = require('path')
|
||||||
exec
|
const semver = require('semver')
|
||||||
} = require("child_process");
|
const knox = require('knox')
|
||||||
const rimraf = require("rimraf");
|
const crypto = require('crypto')
|
||||||
const Path = require("path");
|
const async = require('async')
|
||||||
const semver = require("semver");
|
const settings = require('settings-sharelatex')
|
||||||
const knox = require("knox");
|
const _ = require('underscore')
|
||||||
const crypto = require("crypto");
|
|
||||||
const async = require("async");
|
|
||||||
const settings = require("settings-sharelatex");
|
|
||||||
const _ = require("underscore");
|
|
||||||
|
|
||||||
|
const SERVICES = require('./config/services')
|
||||||
|
|
||||||
const SERVICES = require("./config/services");
|
module.exports = function (grunt) {
|
||||||
|
let Helpers
|
||||||
|
let service
|
||||||
|
grunt.loadNpmTasks('grunt-bunyan')
|
||||||
|
grunt.loadNpmTasks('grunt-execute')
|
||||||
|
grunt.loadNpmTasks('grunt-available-tasks')
|
||||||
|
grunt.loadNpmTasks('grunt-concurrent')
|
||||||
|
grunt.loadNpmTasks('grunt-contrib-coffee')
|
||||||
|
grunt.loadNpmTasks('grunt-shell')
|
||||||
|
|
||||||
module.exports = function(grunt) {
|
grunt.task.loadTasks('./tasks')
|
||||||
let Helpers;
|
|
||||||
let service;
|
|
||||||
grunt.loadNpmTasks('grunt-bunyan');
|
|
||||||
grunt.loadNpmTasks('grunt-execute');
|
|
||||||
grunt.loadNpmTasks('grunt-available-tasks');
|
|
||||||
grunt.loadNpmTasks('grunt-concurrent');
|
|
||||||
grunt.loadNpmTasks("grunt-contrib-coffee");
|
|
||||||
grunt.loadNpmTasks("grunt-shell");
|
|
||||||
|
|
||||||
grunt.task.loadTasks("./tasks");
|
const execute = {}
|
||||||
|
for (service of Array.from(SERVICES)) {
|
||||||
|
execute[service.name] = { src: `${service.name}/app.js` }
|
||||||
|
}
|
||||||
|
|
||||||
const execute = {};
|
grunt.initConfig({
|
||||||
for (service of Array.from(SERVICES)) {
|
execute,
|
||||||
execute[service.name] =
|
|
||||||
{src: `${service.name}/app.js`};
|
|
||||||
}
|
|
||||||
|
|
||||||
grunt.initConfig({
|
concurrent: {
|
||||||
execute,
|
all: {
|
||||||
|
tasks: (() => {
|
||||||
|
const result = []
|
||||||
|
for (service of Array.from(SERVICES)) {
|
||||||
|
result.push(`run:${service.name}`)
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
})(),
|
||||||
|
options: {
|
||||||
|
limit: SERVICES.length,
|
||||||
|
logConcurrentOutput: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
concurrent: {
|
availabletasks: {
|
||||||
all: {
|
tasks: {
|
||||||
tasks: (((() => {
|
options: {
|
||||||
const result = [];
|
filter: 'exclude',
|
||||||
for (service of Array.from(SERVICES)) { result.push(`run:${service.name}`);
|
tasks: ['concurrent', 'execute', 'bunyan', 'availabletasks'],
|
||||||
}
|
groups: {
|
||||||
return result;
|
'Run tasks': ['run', 'run:all', 'default'].concat(
|
||||||
})())),
|
(() => {
|
||||||
options: {
|
const result1 = []
|
||||||
limit: SERVICES.length,
|
for (service of Array.from(SERVICES)) {
|
||||||
logConcurrentOutput: true
|
result1.push(`run:${service.name}`)
|
||||||
|
}
|
||||||
|
return result1
|
||||||
|
})()
|
||||||
|
),
|
||||||
|
Misc: ['help'],
|
||||||
|
'Install tasks': (() => {
|
||||||
|
const result2 = []
|
||||||
|
for (service of Array.from(SERVICES)) {
|
||||||
|
result2.push(`install:${service.name}`)
|
||||||
|
}
|
||||||
|
return result2
|
||||||
|
})().concat(['install:all', 'install']),
|
||||||
|
'Update tasks': (() => {
|
||||||
|
const result3 = []
|
||||||
|
for (service of Array.from(SERVICES)) {
|
||||||
|
result3.push(`update:${service.name}`)
|
||||||
|
}
|
||||||
|
return result3
|
||||||
|
})().concat(['update:all', 'update']),
|
||||||
|
Checks: [
|
||||||
|
'check',
|
||||||
|
'check:redis',
|
||||||
|
'check:latexmk',
|
||||||
|
'check:s3',
|
||||||
|
'check:make',
|
||||||
|
'check:mongo',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
availabletasks: {
|
for (service of Array.from(SERVICES)) {
|
||||||
tasks: {
|
;(service =>
|
||||||
options: {
|
grunt.registerTask(
|
||||||
filter: 'exclude',
|
`install:${service.name}`,
|
||||||
tasks: [
|
`Download and set up the ${service.name} service`,
|
||||||
'concurrent',
|
function () {
|
||||||
'execute',
|
const done = this.async()
|
||||||
'bunyan',
|
return Helpers.installService(service, done)
|
||||||
'availabletasks'
|
}
|
||||||
],
|
))(service)
|
||||||
groups: {
|
}
|
||||||
"Run tasks": [
|
|
||||||
"run",
|
|
||||||
"run:all",
|
|
||||||
"default"
|
|
||||||
].concat(((() => {
|
|
||||||
const result1 = [];
|
|
||||||
for (service of Array.from(SERVICES)) { result1.push(`run:${service.name}`);
|
|
||||||
}
|
|
||||||
return result1;
|
|
||||||
})())),
|
|
||||||
"Misc": [
|
|
||||||
"help"
|
|
||||||
],
|
|
||||||
"Install tasks": ((() => {
|
|
||||||
const result2 = [];
|
|
||||||
for (service of Array.from(SERVICES)) { result2.push(`install:${service.name}`);
|
|
||||||
}
|
|
||||||
return result2;
|
|
||||||
})()).concat(["install:all", "install"]),
|
|
||||||
"Update tasks": ((() => {
|
|
||||||
const result3 = [];
|
|
||||||
for (service of Array.from(SERVICES)) { result3.push(`update:${service.name}`);
|
|
||||||
}
|
|
||||||
return result3;
|
|
||||||
})()).concat(["update:all", "update"]),
|
|
||||||
"Checks": ["check", "check:redis", "check:latexmk", "check:s3", "check:make", "check:mongo"]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}});
|
|
||||||
|
|
||||||
for (service of Array.from(SERVICES)) {
|
grunt.registerTask(
|
||||||
((service => grunt.registerTask(`install:${service.name}`, `Download and set up the ${service.name} service`, function() {
|
'install:all',
|
||||||
const done = this.async();
|
'Download and set up all ShareLaTeX services',
|
||||||
return Helpers.installService(service, done);
|
[]
|
||||||
})))(service);
|
.concat(
|
||||||
}
|
(() => {
|
||||||
|
const result4 = []
|
||||||
|
for (service of Array.from(SERVICES)) {
|
||||||
|
result4.push(`install:${service.name}`)
|
||||||
|
}
|
||||||
|
return result4
|
||||||
|
})()
|
||||||
|
)
|
||||||
|
.concat(['postinstall'])
|
||||||
|
)
|
||||||
|
|
||||||
|
grunt.registerTask('install', 'install:all')
|
||||||
|
grunt.registerTask('postinstall', 'Explain postinstall steps', function () {
|
||||||
|
return Helpers.postinstallMessage(this.async())
|
||||||
|
})
|
||||||
|
|
||||||
|
grunt.registerTask(
|
||||||
|
'update:all',
|
||||||
|
'Checkout and update all ShareLaTeX services',
|
||||||
|
['check:make'].concat(
|
||||||
|
(() => {
|
||||||
|
const result5 = []
|
||||||
|
for (service of Array.from(SERVICES)) {
|
||||||
|
result5.push(`update:${service.name}`)
|
||||||
|
}
|
||||||
|
return result5
|
||||||
|
})()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
grunt.registerTask('update', 'update:all')
|
||||||
|
grunt.registerTask('run', 'Run all of the sharelatex processes', [
|
||||||
|
'concurrent:all',
|
||||||
|
])
|
||||||
|
grunt.registerTask('run:all', 'run')
|
||||||
|
|
||||||
grunt.registerTask('install:all', "Download and set up all ShareLaTeX services",
|
grunt.registerTask('help', 'Display this help list', 'availabletasks')
|
||||||
[].concat(
|
grunt.registerTask('default', 'run')
|
||||||
((() => {
|
|
||||||
const result4 = [];
|
|
||||||
for (service of Array.from(SERVICES)) { result4.push(`install:${service.name}`);
|
|
||||||
}
|
|
||||||
return result4;
|
|
||||||
})())
|
|
||||||
).concat(['postinstall'])
|
|
||||||
);
|
|
||||||
|
|
||||||
grunt.registerTask('install', 'install:all');
|
grunt.registerTask(
|
||||||
grunt.registerTask('postinstall', 'Explain postinstall steps', function() {
|
'check:redis',
|
||||||
return Helpers.postinstallMessage(this.async());
|
'Check that redis is installed and running',
|
||||||
});
|
function () {
|
||||||
|
return Helpers.checkRedisConnect(this.async())
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
grunt.registerTask('update:all', "Checkout and update all ShareLaTeX services",
|
grunt.registerTask(
|
||||||
["check:make"].concat(
|
'check:mongo',
|
||||||
((() => {
|
'Check that mongo is installed',
|
||||||
const result5 = [];
|
function () {
|
||||||
for (service of Array.from(SERVICES)) { result5.push(`update:${service.name}`);
|
return Helpers.checkMongoConnect(this.async())
|
||||||
}
|
}
|
||||||
return result5;
|
)
|
||||||
})())
|
|
||||||
)
|
|
||||||
);
|
|
||||||
grunt.registerTask('update', 'update:all');
|
|
||||||
grunt.registerTask('run', "Run all of the sharelatex processes", ['concurrent:all']);
|
|
||||||
grunt.registerTask('run:all', 'run');
|
|
||||||
|
|
||||||
grunt.registerTask('help', 'Display this help list', 'availabletasks');
|
grunt.registerTask(
|
||||||
grunt.registerTask('default', 'run');
|
'check',
|
||||||
|
'Check that you have the required dependencies installed',
|
||||||
|
['check:redis', 'check:mongo', 'check:make']
|
||||||
|
)
|
||||||
|
|
||||||
grunt.registerTask("check:redis", "Check that redis is installed and running", function() {
|
grunt.registerTask('check:make', 'Check that make is installed', function () {
|
||||||
return Helpers.checkRedisConnect(this.async());
|
return Helpers.checkMake(this.async())
|
||||||
});
|
})
|
||||||
|
|
||||||
grunt.registerTask("check:mongo", "Check that mongo is installed", function() {
|
return (Helpers = {
|
||||||
return Helpers.checkMongoConnect(this.async());
|
installService(service, callback) {
|
||||||
});
|
if (callback == null) {
|
||||||
|
callback = function (error) {}
|
||||||
|
}
|
||||||
|
console.log(`Installing ${service.name}`)
|
||||||
|
return Helpers.cloneGitRepo(service, function (error) {
|
||||||
|
if (error != null) {
|
||||||
|
return callback(error)
|
||||||
|
} else {
|
||||||
|
return callback()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
grunt.registerTask("check", "Check that you have the required dependencies installed", ["check:redis", "check:mongo", "check:make"]);
|
cloneGitRepo(service, callback) {
|
||||||
|
if (callback == null) {
|
||||||
|
callback = function (error) {}
|
||||||
|
}
|
||||||
|
const repo_src = service.repo
|
||||||
|
const dir = service.name
|
||||||
|
if (!fs.existsSync(dir)) {
|
||||||
|
const proc = spawn('git', ['clone', repo_src, dir], {
|
||||||
|
stdio: 'inherit',
|
||||||
|
})
|
||||||
|
return proc.on('close', () =>
|
||||||
|
Helpers.checkoutVersion(service, callback)
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
console.log(`${dir} already installed, skipping.`)
|
||||||
|
return callback()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
grunt.registerTask("check:make", "Check that make is installed", function() {
|
checkoutVersion(service, callback) {
|
||||||
return Helpers.checkMake(this.async());
|
if (callback == null) {
|
||||||
});
|
callback = function (error) {}
|
||||||
|
}
|
||||||
|
const dir = service.name
|
||||||
|
grunt.log.write(`checking out ${service.name} ${service.version}`)
|
||||||
|
const proc = spawn('git', ['checkout', service.version], {
|
||||||
|
stdio: 'inherit',
|
||||||
|
cwd: dir,
|
||||||
|
})
|
||||||
|
return proc.on('close', () => callback())
|
||||||
|
},
|
||||||
|
|
||||||
|
postinstallMessage(callback) {
|
||||||
return Helpers = {
|
if (callback == null) {
|
||||||
installService(service, callback) {
|
callback = function (error) {}
|
||||||
if (callback == null) { callback = function(error) {}; }
|
}
|
||||||
console.log(`Installing ${service.name}`);
|
grunt.log.write(`\
|
||||||
return Helpers.cloneGitRepo(service, function(error) {
|
|
||||||
if (error != null) {
|
|
||||||
return callback(error);
|
|
||||||
} else {
|
|
||||||
return callback();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
cloneGitRepo(service, callback) {
|
|
||||||
if (callback == null) { callback = function(error) {}; }
|
|
||||||
const repo_src = service.repo;
|
|
||||||
const dir = service.name;
|
|
||||||
if (!fs.existsSync(dir)) {
|
|
||||||
const proc = spawn("git", [
|
|
||||||
"clone",
|
|
||||||
repo_src,
|
|
||||||
dir
|
|
||||||
], {stdio: "inherit"});
|
|
||||||
return proc.on("close", () => Helpers.checkoutVersion(service, callback));
|
|
||||||
} else {
|
|
||||||
console.log(`${dir} already installed, skipping.`);
|
|
||||||
return callback();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
checkoutVersion(service, callback) {
|
|
||||||
if (callback == null) { callback = function(error) {}; }
|
|
||||||
const dir = service.name;
|
|
||||||
grunt.log.write(`checking out ${service.name} ${service.version}`);
|
|
||||||
const proc = spawn("git", ["checkout", service.version], {stdio: "inherit", cwd: dir});
|
|
||||||
return proc.on("close", () => callback());
|
|
||||||
},
|
|
||||||
|
|
||||||
postinstallMessage(callback) {
|
|
||||||
if (callback == null) { callback = function(error) {}; }
|
|
||||||
grunt.log.write(`\
|
|
||||||
Services cloned:
|
Services cloned:
|
||||||
${(() => {
|
${(() => {
|
||||||
const result6 = [];
|
const result6 = []
|
||||||
for (service of Array.from(SERVICES)) { result6.push(service.name);
|
for (service of Array.from(SERVICES)) {
|
||||||
}
|
result6.push(service.name)
|
||||||
return result6;
|
}
|
||||||
})()}
|
return result6
|
||||||
|
})()}
|
||||||
To install services run:
|
To install services run:
|
||||||
$ source bin/install-services
|
$ source bin/install-services
|
||||||
This will install the required node versions and run \`npm install\` for each service.
|
This will install the required node versions and run \`npm install\` for each service.
|
||||||
See https://github.com/sharelatex/sharelatex/pull/549 for more info.\
|
See https://github.com/sharelatex/sharelatex/pull/549 for more info.\
|
||||||
`
|
`)
|
||||||
);
|
return callback()
|
||||||
return callback();
|
},
|
||||||
},
|
|
||||||
|
|
||||||
checkMake(callback) {
|
checkMake(callback) {
|
||||||
if (callback == null) { callback = function(error) {}; }
|
if (callback == null) {
|
||||||
grunt.log.write("Checking make is installed... ");
|
callback = function (error) {}
|
||||||
return exec("make --version", function(error, stdout, stderr) {
|
}
|
||||||
if ((error != null) && error.message.match("not found")) {
|
grunt.log.write('Checking make is installed... ')
|
||||||
grunt.log.error("FAIL.");
|
return exec('make --version', function (error, stdout, stderr) {
|
||||||
grunt.log.errorlns(`\
|
if (error != null && error.message.match('not found')) {
|
||||||
|
grunt.log.error('FAIL.')
|
||||||
|
grunt.log.errorlns(`\
|
||||||
Either make is not installed or is not in your path.
|
Either make is not installed or is not in your path.
|
||||||
|
|
||||||
On Ubuntu you can install make with:
|
On Ubuntu you can install make with:
|
||||||
|
|
||||||
sudo apt-get install build-essential
|
sudo apt-get install build-essential
|
||||||
\
|
\
|
||||||
`
|
`)
|
||||||
);
|
return callback(error)
|
||||||
return callback(error);
|
} else if (error != null) {
|
||||||
} else if (error != null) {
|
return callback(error)
|
||||||
return callback(error);
|
} else {
|
||||||
} else {
|
grunt.log.write('OK.')
|
||||||
grunt.log.write("OK.");
|
return callback()
|
||||||
return callback();
|
}
|
||||||
}
|
})
|
||||||
});
|
},
|
||||||
},
|
checkMongoConnect(callback) {
|
||||||
checkMongoConnect(callback) {
|
if (callback == null) {
|
||||||
if (callback == null) { callback = function(error) {}; }
|
callback = function (error) {}
|
||||||
grunt.log.write("Checking can connect to mongo");
|
}
|
||||||
const mongojs = require("mongojs");
|
grunt.log.write('Checking can connect to mongo')
|
||||||
const db = mongojs(settings.mongo.url, ["tags"]);
|
const mongojs = require('mongojs')
|
||||||
db.runCommand({ ping: 1 }, function(err, res) {
|
const db = mongojs(settings.mongo.url, ['tags'])
|
||||||
if (!err && res.ok) {
|
db.runCommand({ ping: 1 }, function (err, res) {
|
||||||
grunt.log.write("OK.");
|
if (!err && res.ok) {
|
||||||
}
|
grunt.log.write('OK.')
|
||||||
return callback();
|
}
|
||||||
});
|
return callback()
|
||||||
return db.on('error', function(err){
|
})
|
||||||
err = "Can not connect to mongodb";
|
return db.on('error', function (err) {
|
||||||
grunt.log.error("FAIL.");
|
err = 'Can not connect to mongodb'
|
||||||
grunt.log.errorlns(`\
|
grunt.log.error('FAIL.')
|
||||||
|
grunt.log.errorlns(`\
|
||||||
!!!!!!!!!!!!!! MONGO ERROR !!!!!!!!!!!!!!
|
!!!!!!!!!!!!!! MONGO ERROR !!!!!!!!!!!!!!
|
||||||
|
|
||||||
ShareLaTeX can not talk to the mongodb instance
|
ShareLaTeX can not talk to the mongodb instance
|
||||||
|
@ -271,30 +309,31 @@ ShareLaTeX can not talk to the mongodb instance
|
||||||
Check the mongodb instance is running and accessible on env var SHARELATEX_MONGO_URL
|
Check the mongodb instance is running and accessible on env var SHARELATEX_MONGO_URL
|
||||||
|
|
||||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\
|
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\
|
||||||
`
|
`)
|
||||||
);
|
throw new Error('Can not connect to Mongodb')
|
||||||
throw new Error("Can not connect to Mongodb");
|
return callback(err)
|
||||||
return callback(err);
|
})
|
||||||
});
|
},
|
||||||
},
|
|
||||||
|
|
||||||
checkRedisConnect(callback) {
|
checkRedisConnect(callback) {
|
||||||
if (callback == null) { callback = function(error) {}; }
|
if (callback == null) {
|
||||||
grunt.log.write("Checking can connect to redis\n");
|
callback = function (error) {}
|
||||||
const rclient = require("redis").createClient(settings.redis.web);
|
}
|
||||||
|
grunt.log.write('Checking can connect to redis\n')
|
||||||
|
const rclient = require('redis').createClient(settings.redis.web)
|
||||||
|
|
||||||
rclient.ping(function(err, res) {
|
rclient.ping(function (err, res) {
|
||||||
if ((err == null)) {
|
if (err == null) {
|
||||||
grunt.log.write("OK.");
|
grunt.log.write('OK.')
|
||||||
} else {
|
} else {
|
||||||
throw new Error("Can not connect to redis");
|
throw new Error('Can not connect to redis')
|
||||||
}
|
}
|
||||||
return callback();
|
return callback()
|
||||||
});
|
})
|
||||||
const errorHandler = _.once(function(err){
|
const errorHandler = _.once(function (err) {
|
||||||
err = "Can not connect to redis";
|
err = 'Can not connect to redis'
|
||||||
grunt.log.error("FAIL.");
|
grunt.log.error('FAIL.')
|
||||||
grunt.log.errorlns(`\
|
grunt.log.errorlns(`\
|
||||||
!!!!!!!!!!!!!! REDIS ERROR !!!!!!!!!!!!!!
|
!!!!!!!!!!!!!! REDIS ERROR !!!!!!!!!!!!!!
|
||||||
|
|
||||||
ShareLaTeX can not talk to the redis instance
|
ShareLaTeX can not talk to the redis instance
|
||||||
|
@ -302,19 +341,17 @@ ShareLaTeX can not talk to the redis instance
|
||||||
Check the redis instance is running and accessible on env var SHARELATEX_REDIS_HOST
|
Check the redis instance is running and accessible on env var SHARELATEX_REDIS_HOST
|
||||||
|
|
||||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\
|
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\
|
||||||
`
|
`)
|
||||||
);
|
throw new Error('Can not connect to redis')
|
||||||
throw new Error("Can not connect to redis");
|
return callback(err)
|
||||||
return callback(err);
|
})
|
||||||
});
|
return rclient.on('error', errorHandler)
|
||||||
return rclient.on('error', errorHandler);
|
},
|
||||||
}
|
})
|
||||||
};
|
}
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function __guard__(value, transform) {
|
function __guard__(value, transform) {
|
||||||
return (typeof value !== 'undefined' && value !== null) ? transform(value) : undefined;
|
return typeof value !== 'undefined' && value !== null
|
||||||
|
? transform(value)
|
||||||
|
: undefined
|
||||||
}
|
}
|
||||||
|
|
1142
settings.js
1142
settings.js
File diff suppressed because it is too large
Load diff
|
@ -11,75 +11,106 @@
|
||||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||||
*/
|
*/
|
||||||
|
|
||||||
module.exports = function(grunt) {
|
module.exports = function (grunt) {
|
||||||
|
grunt.registerTask(
|
||||||
|
'user:create-admin',
|
||||||
|
'Create a user with the given email address and make them an admin. Update in place if the user already exists. Usage: grunt user:create-admin --email joe@example.com',
|
||||||
|
function () {
|
||||||
|
const done = this.async()
|
||||||
|
const email = grunt.option('email')
|
||||||
|
if (email == null) {
|
||||||
|
console.error('Usage: grunt user:create-admin --email=joe@example.com')
|
||||||
|
process.exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
grunt.registerTask('user:create-admin', "Create a user with the given email address and make them an admin. Update in place if the user already exists. Usage: grunt user:create-admin --email joe@example.com", function() {
|
const settings = require('settings-sharelatex')
|
||||||
const done = this.async();
|
const mongodb = require('../web/app/src/infrastructure/mongodb')
|
||||||
const email = grunt.option("email");
|
const UserRegistrationHandler = require('../web/app/src/Features/User/UserRegistrationHandler')
|
||||||
if ((email == null)) {
|
const OneTimeTokenHandler = require('../web/app/src/Features/Security/OneTimeTokenHandler')
|
||||||
console.error("Usage: grunt user:create-admin --email=joe@example.com");
|
return mongodb.waitForDb().then(() =>
|
||||||
process.exit(1);
|
UserRegistrationHandler.registerNewUser(
|
||||||
}
|
{
|
||||||
|
|
||||||
const settings = require("settings-sharelatex");
|
|
||||||
const mongodb = require("../web/app/src/infrastructure/mongodb");
|
|
||||||
const UserRegistrationHandler = require("../web/app/src/Features/User/UserRegistrationHandler");
|
|
||||||
const OneTimeTokenHandler = require("../web/app/src/Features/Security/OneTimeTokenHandler");
|
|
||||||
return mongodb.waitForDb().then(() => UserRegistrationHandler.registerNewUser({
|
|
||||||
email,
|
email,
|
||||||
password: require("crypto").randomBytes(32).toString("hex")
|
password: require('crypto').randomBytes(32).toString('hex'),
|
||||||
}, function(error, user) {
|
},
|
||||||
if ((error != null) && ((error != null ? error.message : undefined) !== "EmailAlreadyRegistered")) {
|
function (error, user) {
|
||||||
throw error;
|
if (
|
||||||
|
error != null &&
|
||||||
|
(error != null ? error.message : undefined) !==
|
||||||
|
'EmailAlreadyRegistered'
|
||||||
|
) {
|
||||||
|
throw error
|
||||||
}
|
}
|
||||||
user.isAdmin = true;
|
user.isAdmin = true
|
||||||
return user.save(function(error) {
|
return user.save(function (error) {
|
||||||
if (error != null) { throw error; }
|
if (error != null) {
|
||||||
const ONE_WEEK = 7 * 24 * 60 * 60; // seconds
|
throw error
|
||||||
return OneTimeTokenHandler.getNewToken("password", { expiresIn: ONE_WEEK, email:user.email, user_id: user._id.toString() }, function(err, token){
|
}
|
||||||
if (err != null) { return next(err); }
|
const ONE_WEEK = 7 * 24 * 60 * 60 // seconds
|
||||||
|
return OneTimeTokenHandler.getNewToken(
|
||||||
|
'password',
|
||||||
|
{
|
||||||
|
expiresIn: ONE_WEEK,
|
||||||
|
email: user.email,
|
||||||
|
user_id: user._id.toString(),
|
||||||
|
},
|
||||||
|
function (err, token) {
|
||||||
|
if (err != null) {
|
||||||
|
return next(err)
|
||||||
|
}
|
||||||
|
|
||||||
console.log("");
|
console.log('')
|
||||||
console.log(`\
|
console.log(`\
|
||||||
Successfully created ${email} as an admin user.
|
Successfully created ${email} as an admin user.
|
||||||
|
|
||||||
Please visit the following URL to set a password for ${email} and log in:
|
Please visit the following URL to set a password for ${email} and log in:
|
||||||
|
|
||||||
${settings.siteUrl}/user/password/set?passwordResetToken=${token}
|
${settings.siteUrl}/user/password/set?passwordResetToken=${token}
|
||||||
\
|
\
|
||||||
`
|
`)
|
||||||
);
|
return done()
|
||||||
return done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}));
|
|
||||||
});
|
|
||||||
|
|
||||||
return grunt.registerTask('user:delete', "deletes a user and all their data, Usage: grunt user:delete --email joe@example.com", function() {
|
|
||||||
const done = this.async();
|
|
||||||
const email = grunt.option("email");
|
|
||||||
if ((email == null)) {
|
|
||||||
console.error("Usage: grunt user:delete --email=joe@example.com");
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
const settings = require("settings-sharelatex");
|
|
||||||
const mongodb = require("../web/app/src/infrastructure/mongodb");
|
|
||||||
const UserGetter = require("../web/app/src/Features/User/UserGetter");
|
|
||||||
const UserDeleter = require("../web/app/src/Features/User/UserDeleter");
|
|
||||||
return mongodb.waitForDb().then(() => UserGetter.getUser({email}, function(error, user) {
|
|
||||||
if (error != null) {
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
if ((user == null)) {
|
|
||||||
console.log(`user ${email} not in database, potentially already deleted`);
|
|
||||||
return done();
|
|
||||||
}
|
|
||||||
return UserDeleter.deleteUser(user._id, function(err){
|
|
||||||
if (err != null) {
|
|
||||||
throw err;
|
|
||||||
}
|
}
|
||||||
return done();
|
)
|
||||||
});
|
})
|
||||||
}));
|
}
|
||||||
});
|
)
|
||||||
};
|
)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
return grunt.registerTask(
|
||||||
|
'user:delete',
|
||||||
|
'deletes a user and all their data, Usage: grunt user:delete --email joe@example.com',
|
||||||
|
function () {
|
||||||
|
const done = this.async()
|
||||||
|
const email = grunt.option('email')
|
||||||
|
if (email == null) {
|
||||||
|
console.error('Usage: grunt user:delete --email=joe@example.com')
|
||||||
|
process.exit(1)
|
||||||
|
}
|
||||||
|
const settings = require('settings-sharelatex')
|
||||||
|
const mongodb = require('../web/app/src/infrastructure/mongodb')
|
||||||
|
const UserGetter = require('../web/app/src/Features/User/UserGetter')
|
||||||
|
const UserDeleter = require('../web/app/src/Features/User/UserDeleter')
|
||||||
|
return mongodb.waitForDb().then(() =>
|
||||||
|
UserGetter.getUser({ email }, function (error, user) {
|
||||||
|
if (error != null) {
|
||||||
|
throw error
|
||||||
|
}
|
||||||
|
if (user == null) {
|
||||||
|
console.log(
|
||||||
|
`user ${email} not in database, potentially already deleted`
|
||||||
|
)
|
||||||
|
return done()
|
||||||
|
}
|
||||||
|
return UserDeleter.deleteUser(user._id, function (err) {
|
||||||
|
if (err != null) {
|
||||||
|
throw err
|
||||||
|
}
|
||||||
|
return done()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue