mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-23 02:41:50 +03:00
Added getBackupFilePath to settings-path-manager module
refs https://linear.app/tryghost/issue/CORE-35/refactor-route-and-redirect-settings - getBackupFilePath is yet another utility function tha's used often with Ghost config files like so: -ca149f2c0e/core/server/services/redirects/settings.js (L147-L151)
-ca149f2c0e/core/server/services/route-settings/route-settings.js (L42-L45)
This commit is contained in:
parent
8f4c4f66b5
commit
98f4f90b19
@ -1,5 +1,6 @@
|
||||
const path = require('path');
|
||||
const tpl = require('@tryghost/tpl');
|
||||
const format = require('date-fns/format');
|
||||
const {IncorrectUsageError} = require('@tryghost/errors');
|
||||
|
||||
const messages = {
|
||||
@ -35,6 +36,12 @@ class SettingsPathManager {
|
||||
const settingsFolder = this.defaultPath;
|
||||
return path.join(settingsFolder, `${this.filename}.${this.defaultExtension}`);
|
||||
}
|
||||
|
||||
getBackupFilePath() {
|
||||
const settingsFolder = this.defaultPath;
|
||||
const dateStamp = format(new Date(), 'yyyy-MM-dd-HH-mm-ss');
|
||||
return path.join(settingsFolder, `${this.filename}-${dateStamp}.${this.defaultExtension}`);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = SettingsPathManager;
|
||||
|
@ -25,6 +25,7 @@
|
||||
"sinon": "11.1.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"date-fns": "^2.24.0",
|
||||
"tpl": "^0.3.0"
|
||||
}
|
||||
}
|
||||
|
@ -54,4 +54,18 @@ describe('Settings Path Manager', function () {
|
||||
path.should.equal('/content/data/redirects.json');
|
||||
});
|
||||
});
|
||||
|
||||
describe('getBackupFilePath', function () {
|
||||
it('returns a path to store a backup', function (){
|
||||
const settingsPathManager = new SettingsPathManager({
|
||||
paths: ['/content/data', '/content/settings'],
|
||||
type: 'routes',
|
||||
extensions: ['yaml']
|
||||
});
|
||||
|
||||
const path = settingsPathManager.getBackupFilePath();
|
||||
|
||||
path.should.match(/\/content\/data\/routes-\d{4}-\d{2}-\d{2}-\d{2}-\d{2}-\d{2}.yaml/);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user