mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Merge pull request #6132 from overleaf/jpa-settings-linting
[settings] setup linting and fix all the violations GitOrigin-RevId: 321ecf0e8749a0481d61ad720baffe06089dc5cf
This commit is contained in:
parent
4b308553be
commit
4de9c98d2f
4 changed files with 52 additions and 44 deletions
|
@ -1,50 +1,58 @@
|
||||||
let defaults, possibleConfigFiles, settingsExist;
|
/* eslint-disable no-console */
|
||||||
const fs = require("fs");
|
let defaults, possibleConfigFiles, settingsExist
|
||||||
const path = require("path");
|
const fs = require('fs')
|
||||||
const env = (process.env.NODE_ENV || "development").toLowerCase();
|
const path = require('path')
|
||||||
const { merge } = require('./merge');
|
const env = (process.env.NODE_ENV || 'development').toLowerCase()
|
||||||
|
const { merge } = require('./merge')
|
||||||
|
|
||||||
const defaultSettingsPath = path.normalize(__dirname + "/../../../config/settings.defaults");
|
const defaultSettingsPath = path.join(
|
||||||
|
__dirname,
|
||||||
|
'../../../config/settings.defaults'
|
||||||
|
)
|
||||||
|
|
||||||
if (fs.existsSync(`${defaultSettingsPath}.js`)) {
|
if (fs.existsSync(`${defaultSettingsPath}.js`)) {
|
||||||
console.log(`Using default settings from ${defaultSettingsPath}.js`);
|
console.log(`Using default settings from ${defaultSettingsPath}.js`)
|
||||||
defaults = require(`${defaultSettingsPath}.js`);
|
defaults = require(`${defaultSettingsPath}.js`)
|
||||||
settingsExist = true;
|
settingsExist = true
|
||||||
} else if (fs.existsSync(`${defaultSettingsPath}.coffee`)) {
|
} else if (fs.existsSync(`${defaultSettingsPath}.coffee`)) {
|
||||||
// TODO: remove this in the next major version
|
// TODO: remove this in the next major version
|
||||||
throw new Error(`CoffeeScript settings file ${defaultSettingsPath}.coffee is no longer supported, please convert to JavaScript`);
|
throw new Error(
|
||||||
|
`CoffeeScript settings file ${defaultSettingsPath}.coffee is no longer supported, please convert to JavaScript`
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
defaults = {};
|
defaults = {}
|
||||||
settingsExist = false;
|
settingsExist = false
|
||||||
}
|
}
|
||||||
|
|
||||||
if (process.env.SHARELATEX_CONFIG) {
|
if (process.env.SHARELATEX_CONFIG) {
|
||||||
possibleConfigFiles = [process.env.SHARELATEX_CONFIG];
|
possibleConfigFiles = [process.env.SHARELATEX_CONFIG]
|
||||||
} else {
|
} else {
|
||||||
possibleConfigFiles = [
|
possibleConfigFiles = [
|
||||||
process.cwd() + `/config/settings.${env}.js`,
|
path.join(process.cwd(), `config/settings.${env}.js`),
|
||||||
path.normalize(__dirname + `/../../../config/settings.${env}.js`),
|
path.join(__dirname, `../../../config/settings.${env}.js`),
|
||||||
// TODO: remove these in the next major version
|
// TODO: remove these in the next major version
|
||||||
process.cwd() + `/config/settings.${env}.coffee`,
|
path.join(process.cwd(), `config/settings.${env}.coffee`),
|
||||||
path.normalize(__dirname + `/../../../config/settings.${env}.coffee`)
|
path.join(__dirname, `../../../config/settings.${env}.coffee`),
|
||||||
];
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let file of possibleConfigFiles) {
|
for (const file of possibleConfigFiles) {
|
||||||
if (fs.existsSync(file)) {
|
if (fs.existsSync(file)) {
|
||||||
// TODO: remove this in the next major version
|
// TODO: remove this in the next major version
|
||||||
if (file.endsWith('.coffee')) {
|
if (file.endsWith('.coffee')) {
|
||||||
throw new Error(`CoffeeScript settings file ${file} is no longer supported, please convert to JavaScript`);
|
throw new Error(
|
||||||
}
|
`CoffeeScript settings file ${file} is no longer supported, please convert to JavaScript`
|
||||||
console.log("Using settings from " + file);
|
)
|
||||||
module.exports = merge(require(file), defaults);
|
}
|
||||||
settingsExist = true;
|
console.log('Using settings from ' + file)
|
||||||
break;
|
module.exports = merge(require(file), defaults)
|
||||||
}
|
settingsExist = true
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!settingsExist) {
|
if (!settingsExist) {
|
||||||
console.warn("No settings or defaults found. I'm flying blind.");
|
console.warn("No settings or defaults found. I'm flying blind.")
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = defaults;
|
module.exports = defaults
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
module.exports = require('./Settings');
|
module.exports = require('./Settings')
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
function merge(settings, defaults) {
|
function merge(settings, defaults) {
|
||||||
for (const [key, value] of Object.entries(settings)) {
|
for (const [key, value] of Object.entries(settings)) {
|
||||||
if ((typeof(value) === "object") && !(value instanceof Array)) {
|
if (typeof value === 'object' && !(value instanceof Array)) {
|
||||||
defaults[key] = merge(value, defaults[key] || {});
|
defaults[key] = merge(value, defaults[key] || {})
|
||||||
} else {
|
} else {
|
||||||
defaults[key] = value;
|
defaults[key] = value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return defaults;
|
return defaults
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { merge };
|
module.exports = { merge }
|
||||||
|
|
|
@ -4,10 +4,10 @@
|
||||||
"version": "2.1.1",
|
"version": "2.1.1",
|
||||||
"repository": "overleaf/settings-module",
|
"repository": "overleaf/settings-module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"lint": "echo noop",
|
"lint": "../../node_modules/.bin/eslint --max-warnings 0 --format unix .",
|
||||||
"lint:fix": "echo noop",
|
"lint:fix": "../../node_modules/.bin/eslint --fix .",
|
||||||
"format:fix": "echo noop",
|
"format": "../../node_modules/.bin/prettier --list-different $PWD/'**/*.js'",
|
||||||
"format": "echo noop",
|
"format:fix": "../../node_modules/.bin/prettier --write $PWD/'**/*.js'",
|
||||||
"test": "echo noop",
|
"test": "echo noop",
|
||||||
"test:ci": "echo noop"
|
"test:ci": "echo noop"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue