prettier: convert test/acceptance decaffeinated files to Prettier format

This commit is contained in:
mserranom
2020-02-19 12:16:14 +01:00
parent 7996f44942
commit 71a50dd11f
10 changed files with 1105 additions and 771 deletions

View File

@@ -12,143 +12,197 @@
* DS207: Consider shorter variations of null checks
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
let Client;
const request = require("request");
const fs = require("fs");
const Settings = require("settings-sharelatex");
let Client
const request = require('request')
const fs = require('fs')
const Settings = require('settings-sharelatex')
const host = "localhost";
const host = 'localhost'
module.exports = (Client = {
host: Settings.apis.clsi.url,
module.exports = Client = {
host: Settings.apis.clsi.url,
randomId() {
return Math.random().toString(16).slice(2);
},
randomId() {
return Math.random()
.toString(16)
.slice(2)
},
compile(project_id, data, callback) {
if (callback == null) { callback = function(error, res, body) {}; }
return request.post({
url: `${this.host}/project/${project_id}/compile`,
json: {
compile: data
}
}, callback);
},
compile(project_id, data, callback) {
if (callback == null) {
callback = function(error, res, body) {}
}
return request.post(
{
url: `${this.host}/project/${project_id}/compile`,
json: {
compile: data
}
},
callback
)
},
clearCache(project_id, callback) {
if (callback == null) { callback = function(error, res, body) {}; }
return request.del(`${this.host}/project/${project_id}`, callback);
},
clearCache(project_id, callback) {
if (callback == null) {
callback = function(error, res, body) {}
}
return request.del(`${this.host}/project/${project_id}`, callback)
},
getOutputFile(response, type) {
for (const file of Array.from(response.compile.outputFiles)) {
if ((file.type === type) && file.url.match(`output.${type}`)) {
return file;
}
}
return null;
},
getOutputFile(response, type) {
for (const file of Array.from(response.compile.outputFiles)) {
if (file.type === type && file.url.match(`output.${type}`)) {
return file
}
}
return null
},
runServer(port, directory) {
const express = require("express");
const app = express();
app.use(express.static(directory));
console.log("starting test server on", port, host);
return app.listen(port, host).on("error", (error) => {
console.error("error starting server:", error.message);
return process.exit(1);
});
},
runServer(port, directory) {
const express = require('express')
const app = express()
app.use(express.static(directory))
console.log('starting test server on', port, host)
return app.listen(port, host).on('error', error => {
console.error('error starting server:', error.message)
return process.exit(1)
})
},
syncFromCode(project_id, file, line, column, callback) {
if (callback == null) {
callback = function(error, pdfPositions) {}
}
return request.get(
{
url: `${this.host}/project/${project_id}/sync/code`,
qs: {
file,
line,
column
}
},
(error, response, body) => {
if (error != null) {
return callback(error)
}
return callback(null, JSON.parse(body))
}
)
},
syncFromCode(project_id, file, line, column, callback) {
if (callback == null) { callback = function(error, pdfPositions) {}; }
return request.get({
url: `${this.host}/project/${project_id}/sync/code`,
qs: {
file,
line,
column
}
}, (error, response, body) => {
if (error != null) { return callback(error); }
return callback(null, JSON.parse(body));
});
},
syncFromPdf(project_id, page, h, v, callback) {
if (callback == null) {
callback = function(error, pdfPositions) {}
}
return request.get(
{
url: `${this.host}/project/${project_id}/sync/pdf`,
qs: {
page,
h,
v
}
},
(error, response, body) => {
if (error != null) {
return callback(error)
}
return callback(null, JSON.parse(body))
}
)
},
syncFromPdf(project_id, page, h, v, callback) {
if (callback == null) { callback = function(error, pdfPositions) {}; }
return request.get({
url: `${this.host}/project/${project_id}/sync/pdf`,
qs: {
page,
h, v
}
}, (error, response, body) => {
if (error != null) { return callback(error); }
return callback(null, JSON.parse(body));
});
},
compileDirectory(project_id, baseDirectory, directory, serverPort, callback) {
if (callback == null) {
callback = function(error, res, body) {}
}
const resources = []
let entities = fs.readdirSync(`${baseDirectory}/${directory}`)
let rootResourcePath = 'main.tex'
while (entities.length > 0) {
var entity = entities.pop()
const stat = fs.statSync(`${baseDirectory}/${directory}/${entity}`)
if (stat.isDirectory()) {
entities = entities.concat(
fs
.readdirSync(`${baseDirectory}/${directory}/${entity}`)
.map(subEntity => {
if (subEntity === 'main.tex') {
rootResourcePath = `${entity}/${subEntity}`
}
return `${entity}/${subEntity}`
})
)
} else if (stat.isFile() && entity !== 'output.pdf') {
const extension = entity.split('.').pop()
if (
[
'tex',
'bib',
'cls',
'sty',
'pdf_tex',
'Rtex',
'ist',
'md',
'Rmd'
].indexOf(extension) > -1
) {
resources.push({
path: entity,
content: fs
.readFileSync(`${baseDirectory}/${directory}/${entity}`)
.toString()
})
} else if (
['eps', 'ttf', 'png', 'jpg', 'pdf', 'jpeg'].indexOf(extension) > -1
) {
resources.push({
path: entity,
url: `http://${host}:${serverPort}/${directory}/${entity}`,
modified: stat.mtime
})
}
}
}
compileDirectory(project_id, baseDirectory, directory, serverPort, callback) {
if (callback == null) { callback = function(error, res, body) {}; }
const resources = [];
let entities = fs.readdirSync(`${baseDirectory}/${directory}`);
let rootResourcePath = "main.tex";
while (entities.length > 0) {
var entity = entities.pop();
const stat = fs.statSync(`${baseDirectory}/${directory}/${entity}`);
if (stat.isDirectory()) {
entities = entities.concat(fs.readdirSync(`${baseDirectory}/${directory}/${entity}`).map((subEntity) => {
if (subEntity === "main.tex") {
rootResourcePath = `${entity}/${subEntity}`;
}
return `${entity}/${subEntity}`;
})
);
} else if (stat.isFile() && (entity !== "output.pdf")) {
const extension = entity.split(".").pop();
if (["tex", "bib", "cls", "sty", "pdf_tex", "Rtex", "ist", "md", "Rmd"].indexOf(extension) > -1) {
resources.push({
path: entity,
content: fs.readFileSync(`${baseDirectory}/${directory}/${entity}`).toString()
});
} else if (["eps", "ttf", "png", "jpg", "pdf", "jpeg"].indexOf(extension) > -1) {
resources.push({
path: entity,
url: `http://${host}:${serverPort}/${directory}/${entity}`,
modified: stat.mtime
});
}
}
}
return fs.readFile(
`${baseDirectory}/${directory}/options.json`,
(error, body) => {
const req = {
resources,
rootResourcePath
}
return fs.readFile(`${baseDirectory}/${directory}/options.json`, (error, body) => {
const req = {
resources,
rootResourcePath
};
if (error == null) {
body = JSON.parse(body)
req.options = body
}
if ((error == null)) {
body = JSON.parse(body);
req.options = body;
}
return this.compile(project_id, req, callback)
}
)
},
return this.compile(project_id, req, callback);
});
},
wordcount(project_id, file, callback) {
if (callback == null) { callback = function(error, pdfPositions) {}; }
return request.get({
url: `${this.host}/project/${project_id}/wordcount`,
qs: {
file
}
}, (error, response, body) => {
if (error != null) { return callback(error); }
return callback(null, JSON.parse(body));
});
}
});
wordcount(project_id, file, callback) {
if (callback == null) {
callback = function(error, pdfPositions) {}
}
return request.get(
{
url: `${this.host}/project/${project_id}/wordcount`,
qs: {
file
}
},
(error, response, body) => {
if (error != null) {
return callback(error)
}
return callback(null, JSON.parse(body))
}
)
}
}

View File

@@ -12,40 +12,53 @@
* DS207: Consider shorter variations of null checks
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
const app = require('../../../../app');
require("logger-sharelatex").logger.level("info");
const logger = require("logger-sharelatex");
const Settings = require("settings-sharelatex");
const app = require('../../../../app')
require('logger-sharelatex').logger.level('info')
const logger = require('logger-sharelatex')
const Settings = require('settings-sharelatex')
module.exports = {
running: false,
initing: false,
callbacks: [],
ensureRunning(callback) {
if (callback == null) { callback = function(error) {}; }
if (this.running) {
return callback();
} else if (this.initing) {
return this.callbacks.push(callback);
} else {
this.initing = true;
this.callbacks.push(callback);
return app.listen(__guard__(Settings.internal != null ? Settings.internal.clsi : undefined, x => x.port), "localhost", error => {
if (error != null) { throw error; }
this.running = true;
logger.log("clsi running in dev mode");
running: false,
initing: false,
callbacks: [],
ensureRunning(callback) {
if (callback == null) {
callback = function(error) {}
}
if (this.running) {
return callback()
} else if (this.initing) {
return this.callbacks.push(callback)
} else {
this.initing = true
this.callbacks.push(callback)
return app.listen(
__guard__(
Settings.internal != null ? Settings.internal.clsi : undefined,
x => x.port
),
'localhost',
error => {
if (error != null) {
throw error
}
this.running = true
logger.log('clsi running in dev mode')
return (() => {
const result = [];
for (callback of Array.from(this.callbacks)) {
result.push(callback());
}
return result;
})();
});
}
}
};
return (() => {
const result = []
for (callback of Array.from(this.callbacks)) {
result.push(callback())
}
return result
})()
}
)
}
}
}
function __guard__(value, transform) {
return (typeof value !== 'undefined' && value !== null) ? transform(value) : undefined;
}
return typeof value !== 'undefined' && value !== null
? transform(value)
: undefined
}