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;
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const env = (process.env.NODE_ENV || "development").toLowerCase();
|
||||
const { merge } = require('./merge');
|
||||
/* eslint-disable no-console */
|
||||
let defaults, possibleConfigFiles, settingsExist
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
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`)) {
|
||||
console.log(`Using default settings from ${defaultSettingsPath}.js`);
|
||||
defaults = require(`${defaultSettingsPath}.js`);
|
||||
settingsExist = true;
|
||||
console.log(`Using default settings from ${defaultSettingsPath}.js`)
|
||||
defaults = require(`${defaultSettingsPath}.js`)
|
||||
settingsExist = true
|
||||
} else if (fs.existsSync(`${defaultSettingsPath}.coffee`)) {
|
||||
// TODO: remove this in the next major version
|
||||
throw new Error(`CoffeeScript settings file ${defaultSettingsPath}.coffee is no longer supported, please convert to JavaScript`);
|
||||
// TODO: remove this in the next major version
|
||||
throw new Error(
|
||||
`CoffeeScript settings file ${defaultSettingsPath}.coffee is no longer supported, please convert to JavaScript`
|
||||
)
|
||||
} else {
|
||||
defaults = {};
|
||||
settingsExist = false;
|
||||
defaults = {}
|
||||
settingsExist = false
|
||||
}
|
||||
|
||||
if (process.env.SHARELATEX_CONFIG) {
|
||||
possibleConfigFiles = [process.env.SHARELATEX_CONFIG];
|
||||
possibleConfigFiles = [process.env.SHARELATEX_CONFIG]
|
||||
} else {
|
||||
possibleConfigFiles = [
|
||||
process.cwd() + `/config/settings.${env}.js`,
|
||||
path.normalize(__dirname + `/../../../config/settings.${env}.js`),
|
||||
// TODO: remove these in the next major version
|
||||
process.cwd() + `/config/settings.${env}.coffee`,
|
||||
path.normalize(__dirname + `/../../../config/settings.${env}.coffee`)
|
||||
];
|
||||
possibleConfigFiles = [
|
||||
path.join(process.cwd(), `config/settings.${env}.js`),
|
||||
path.join(__dirname, `../../../config/settings.${env}.js`),
|
||||
// TODO: remove these in the next major version
|
||||
path.join(process.cwd(), `config/settings.${env}.coffee`),
|
||||
path.join(__dirname, `../../../config/settings.${env}.coffee`),
|
||||
]
|
||||
}
|
||||
|
||||
for (let file of possibleConfigFiles) {
|
||||
if (fs.existsSync(file)) {
|
||||
// TODO: remove this in the next major version
|
||||
if (file.endsWith('.coffee')) {
|
||||
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;
|
||||
break;
|
||||
}
|
||||
for (const file of possibleConfigFiles) {
|
||||
if (fs.existsSync(file)) {
|
||||
// TODO: remove this in the next major version
|
||||
if (file.endsWith('.coffee')) {
|
||||
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
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
for (const [key, value] of Object.entries(settings)) {
|
||||
if ((typeof(value) === "object") && !(value instanceof Array)) {
|
||||
defaults[key] = merge(value, defaults[key] || {});
|
||||
if (typeof value === 'object' && !(value instanceof Array)) {
|
||||
defaults[key] = merge(value, defaults[key] || {})
|
||||
} 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",
|
||||
"repository": "overleaf/settings-module",
|
||||
"scripts": {
|
||||
"lint": "echo noop",
|
||||
"lint:fix": "echo noop",
|
||||
"format:fix": "echo noop",
|
||||
"format": "echo noop",
|
||||
"lint": "../../node_modules/.bin/eslint --max-warnings 0 --format unix .",
|
||||
"lint:fix": "../../node_modules/.bin/eslint --fix .",
|
||||
"format": "../../node_modules/.bin/prettier --list-different $PWD/'**/*.js'",
|
||||
"format:fix": "../../node_modules/.bin/prettier --write $PWD/'**/*.js'",
|
||||
"test": "echo noop",
|
||||
"test:ci": "echo noop"
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue