[misc] run format:fix

This commit is contained in:
Jakob Ackermann 2021-07-07 12:43:33 +01:00
parent d812c86c51
commit d7c641eaf7
3 changed files with 993 additions and 839 deletions

View file

@ -16,254 +16,292 @@
* DS207: Consider shorter variations of null checks
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
const coffee = require("coffee-script");
const fs = require("fs");
const {
spawn
} = require("child_process");
const {
exec
} = require("child_process");
const rimraf = require("rimraf");
const Path = require("path");
const semver = require("semver");
const knox = require("knox");
const crypto = require("crypto");
const async = require("async");
const settings = require("settings-sharelatex");
const _ = require("underscore");
const coffee = require('coffee-script')
const fs = require('fs')
const { spawn } = require('child_process')
const { exec } = require('child_process')
const rimraf = require('rimraf')
const Path = require('path')
const semver = require('semver')
const knox = require('knox')
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) {
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')
grunt.task.loadTasks("./tasks");
const execute = {}
for (service of Array.from(SERVICES)) {
execute[service.name] = { src: `${service.name}/app.js` }
}
const execute = {};
for (service of Array.from(SERVICES)) {
execute[service.name] =
{src: `${service.name}/app.js`};
}
grunt.initConfig({
execute,
grunt.initConfig({
execute,
concurrent: {
all: {
tasks: (() => {
const result = []
for (service of Array.from(SERVICES)) {
result.push(`run:${service.name}`)
}
return result
})(),
options: {
limit: SERVICES.length,
logConcurrentOutput: true,
},
},
},
concurrent: {
all: {
tasks: (((() => {
const result = [];
for (service of Array.from(SERVICES)) { result.push(`run:${service.name}`);
}
return result;
})())),
options: {
limit: SERVICES.length,
logConcurrentOutput: true
availabletasks: {
tasks: {
options: {
filter: 'exclude',
tasks: ['concurrent', 'execute', 'bunyan', 'availabletasks'],
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',
],
},
},
},
},
})
availabletasks: {
tasks: {
options: {
filter: 'exclude',
tasks: [
'concurrent',
'execute',
'bunyan',
'availabletasks'
],
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)) {
;(service =>
grunt.registerTask(
`install:${service.name}`,
`Download and set up the ${service.name} service`,
function () {
const done = this.async()
return Helpers.installService(service, done)
}
))(service)
}
for (service of Array.from(SERVICES)) {
((service => grunt.registerTask(`install:${service.name}`, `Download and set up the ${service.name} service`, function() {
const done = this.async();
return Helpers.installService(service, done);
})))(service);
}
grunt.registerTask(
'install:all',
'Download and set up all ShareLaTeX services',
[]
.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",
[].concat(
((() => {
const result4 = [];
for (service of Array.from(SERVICES)) { result4.push(`install:${service.name}`);
}
return result4;
})())
).concat(['postinstall'])
);
grunt.registerTask('help', 'Display this help list', 'availabletasks')
grunt.registerTask('default', 'run')
grunt.registerTask('install', 'install:all');
grunt.registerTask('postinstall', 'Explain postinstall steps', function() {
return Helpers.postinstallMessage(this.async());
});
grunt.registerTask(
'check:redis',
'Check that redis is installed and running',
function () {
return Helpers.checkRedisConnect(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(
'check:mongo',
'Check that mongo is installed',
function () {
return Helpers.checkMongoConnect(this.async())
}
)
grunt.registerTask('help', 'Display this help list', 'availabletasks');
grunt.registerTask('default', 'run');
grunt.registerTask(
'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() {
return Helpers.checkRedisConnect(this.async());
});
grunt.registerTask('check:make', 'Check that make is installed', function () {
return Helpers.checkMake(this.async())
})
grunt.registerTask("check:mongo", "Check that mongo is installed", function() {
return Helpers.checkMongoConnect(this.async());
});
return (Helpers = {
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() {
return Helpers.checkMake(this.async());
});
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())
},
return Helpers = {
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();
}
});
},
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(`\
postinstallMessage(callback) {
if (callback == null) {
callback = function (error) {}
}
grunt.log.write(`\
Services cloned:
${(() => {
const result6 = [];
for (service of Array.from(SERVICES)) { result6.push(service.name);
}
return result6;
})()}
const result6 = []
for (service of Array.from(SERVICES)) {
result6.push(service.name)
}
return result6
})()}
To install services run:
$ source bin/install-services
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.\
`
);
return callback();
},
`)
return callback()
},
checkMake(callback) {
if (callback == null) { callback = function(error) {}; }
grunt.log.write("Checking make is installed... ");
return exec("make --version", function(error, stdout, stderr) {
if ((error != null) && error.message.match("not found")) {
grunt.log.error("FAIL.");
grunt.log.errorlns(`\
checkMake(callback) {
if (callback == null) {
callback = function (error) {}
}
grunt.log.write('Checking make is installed... ')
return exec('make --version', function (error, stdout, stderr) {
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.
On Ubuntu you can install make with:
sudo apt-get install build-essential
\
`
);
return callback(error);
} else if (error != null) {
return callback(error);
} else {
grunt.log.write("OK.");
return callback();
}
});
},
checkMongoConnect(callback) {
if (callback == null) { callback = function(error) {}; }
grunt.log.write("Checking can connect to mongo");
const mongojs = require("mongojs");
const db = mongojs(settings.mongo.url, ["tags"]);
db.runCommand({ ping: 1 }, function(err, res) {
if (!err && res.ok) {
grunt.log.write("OK.");
}
return callback();
});
return db.on('error', function(err){
err = "Can not connect to mongodb";
grunt.log.error("FAIL.");
grunt.log.errorlns(`\
`)
return callback(error)
} else if (error != null) {
return callback(error)
} else {
grunt.log.write('OK.')
return callback()
}
})
},
checkMongoConnect(callback) {
if (callback == null) {
callback = function (error) {}
}
grunt.log.write('Checking can connect to mongo')
const mongojs = require('mongojs')
const db = mongojs(settings.mongo.url, ['tags'])
db.runCommand({ ping: 1 }, function (err, res) {
if (!err && res.ok) {
grunt.log.write('OK.')
}
return callback()
})
return db.on('error', function (err) {
err = 'Can not connect to mongodb'
grunt.log.error('FAIL.')
grunt.log.errorlns(`\
!!!!!!!!!!!!!! MONGO ERROR !!!!!!!!!!!!!!
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
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\
`
);
throw new Error("Can not connect to Mongodb");
return callback(err);
});
},
`)
throw new Error('Can not connect to Mongodb')
return callback(err)
})
},
checkRedisConnect(callback) {
if (callback == null) { callback = function(error) {}; }
grunt.log.write("Checking can connect to redis\n");
const rclient = require("redis").createClient(settings.redis.web);
checkRedisConnect(callback) {
if (callback == null) {
callback = function (error) {}
}
grunt.log.write('Checking can connect to redis\n')
const rclient = require('redis').createClient(settings.redis.web)
rclient.ping(function(err, res) {
if ((err == null)) {
grunt.log.write("OK.");
} else {
throw new Error("Can not connect to redis");
}
return callback();
});
const errorHandler = _.once(function(err){
err = "Can not connect to redis";
grunt.log.error("FAIL.");
grunt.log.errorlns(`\
rclient.ping(function (err, res) {
if (err == null) {
grunt.log.write('OK.')
} else {
throw new Error('Can not connect to redis')
}
return callback()
})
const errorHandler = _.once(function (err) {
err = 'Can not connect to redis'
grunt.log.error('FAIL.')
grunt.log.errorlns(`\
!!!!!!!!!!!!!! REDIS ERROR !!!!!!!!!!!!!!
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
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\
`
);
throw new Error("Can not connect to redis");
return callback(err);
});
return rclient.on('error', errorHandler);
}
};
};
`)
throw new Error('Can not connect to redis')
return callback(err)
})
return rclient.on('error', errorHandler)
},
})
}
function __guard__(value, transform) {
return (typeof value !== 'undefined' && value !== null) ? transform(value) : undefined;
return typeof value !== 'undefined' && value !== null
? transform(value)
: undefined
}

File diff suppressed because it is too large Load diff

View file

@ -11,75 +11,106 @@
* 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 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);
}
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({
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,
password: require("crypto").randomBytes(32).toString("hex")
}, function(error, user) {
if ((error != null) && ((error != null ? error.message : undefined) !== "EmailAlreadyRegistered")) {
throw error;
password: require('crypto').randomBytes(32).toString('hex'),
},
function (error, user) {
if (
error != null &&
(error != null ? error.message : undefined) !==
'EmailAlreadyRegistered'
) {
throw error
}
user.isAdmin = true;
return user.save(function(error) {
if (error != null) { throw error; }
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); }
user.isAdmin = true
return user.save(function (error) {
if (error != null) {
throw error
}
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.
Please visit the following URL to set a password for ${email} and log in:
${settings.siteUrl}/user/password/set?passwordResetToken=${token}
\
`
);
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 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()
})
})
)
}
)
}