Merge pull request #5 from overleaf/ae-throw-coffee

Remove CoffeeScript
This commit is contained in:
Jakob Ackermann 2021-07-06 15:42:48 +02:00 committed by GitHub
commit ef6d86a2cd
6 changed files with 69 additions and 67 deletions

View file

@ -1,6 +1,6 @@
The MIT License (MIT) The MIT License (MIT)
Copyright (c) 2014 ShareLaTeX Copyright (c) 2014-2021 Overleaf
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal

View file

@ -1,4 +1,4 @@
overleaf/settings-module @overleaf/settings
=================== ===================
A small module to allow global config settings to be set for all services A small module to allow global config settings to be set for all services
@ -10,10 +10,10 @@ Settings file location
You can specify a custom location for the settings file by setting the You can specify a custom location for the settings file by setting the
`SHARELATEX_CONFIG` environment variable. E.g. `SHARELATEX_CONFIG` environment variable. E.g.
$ export SHARELATEX_CONFIG=/home/james/config/settings.development.coffee $ export SHARELATEX_CONFIG=/home/james/config/settings.development.js
Otherwise, the settings will be loaded from `config/settings.NODE_ENV.coffee`, Otherwise, the settings will be loaded from `config/settings.NODE_ENV.js`,
where `NODE_ENV` is another evnironment variable, or defaults to `development`. where `NODE_ENV` is another environment variable, or defaults to `development`.
The config directory is first looked for in the current directory, and then relative The config directory is first looked for in the current directory, and then relative
to the settings module directory. to the settings module directory.

View file

@ -1,50 +0,0 @@
fs = require "fs"
path = require "path"
env = (process.env.NODE_ENV or "development").toLowerCase()
merge = (settings, defaults) ->
for key, value of settings
if typeof(value) == "object" and value not instanceof Array
defaults[key] = merge(settings[key], defaults[key] or {})
else
defaults[key] = value
return defaults
defaultSettingsPath = path.normalize(__dirname + "/../../config/settings.defaults")
if fs.existsSync("#{defaultSettingsPath}.js")
console.log "Using default settings from #{defaultSettingsPath}.js"
defaults = require("#{defaultSettingsPath}.js")
settingsExist = true
else if fs.existsSync("#{defaultSettingsPath}.coffee")
console.warn "CoffeeScript settings file #{defaultSettingsPath}.coffee is deprecated, please convert to JavaScript"
console.log "Using default settings from #{defaultSettingsPath}.coffee"
defaults = require("#{defaultSettingsPath}.coffee")
settingsExist = true
else
defaults = {}
settingsExist = false
if process.env.SHARELATEX_CONFIG?
possibleConfigFiles = [process.env.SHARELATEX_CONFIG]
else
possibleConfigFiles = [
process.cwd() + "/config/settings.#{env}.js"
path.normalize(__dirname + "/../../config/settings.#{env}.js")
process.cwd() + "/config/settings.#{env}.coffee"
path.normalize(__dirname + "/../../config/settings.#{env}.coffee")
]
for file in possibleConfigFiles
if fs.existsSync(file)
if file.endsWith('.coffee')
console.warn "CoffeeScript settings file #{file} is deprecated, 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."
module.exports = defaults

View file

@ -0,0 +1,60 @@
let defaults, possibleConfigFiles, settingsExist;
const fs = require("fs");
const path = require("path");
const env = (process.env.NODE_ENV || "development").toLowerCase();
const merge = function(settings, defaults) {
for (const [key, value] of Object.entries(settings)) {
if ((typeof(value) === "object") && !(value instanceof Array)) {
defaults[key] = merge(value, defaults[key] || {});
} else {
defaults[key] = value;
}
}
return defaults;
};
const defaultSettingsPath = path.normalize(__dirname + "/../../config/settings.defaults");
if (fs.existsSync(`${defaultSettingsPath}.js`)) {
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`);
} else {
defaults = {};
settingsExist = false;
}
if (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`)
];
}
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;
}
}
if (!settingsExist) {
console.warn("No settings or defaults found. I'm flying blind.");
}
module.exports = defaults;

View file

@ -1,2 +1 @@
require("coffee-script")
module.exports = require('./Settings'); module.exports = require('./Settings');

View file

@ -1,13 +1,6 @@
{ {
"name": "settings-sharelatex", "name": "@overleaf/settings",
"homepage": "www.sharelatex.com", "description": "A centralised settings system for Overleaf",
"description": "A centralised settings system for ShareLaTeX", "version": "2.0.0",
"version": "1.3.0", "repository": "overleaf/settings-module"
"repository": {
"type": "git",
"url": "https://github.com/sharelatex/settings-sharelatex.git"
},
"dependencies": {
"coffee-script": "1.6.0"
}
} }