mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-03 23:00:14 -05:00
🔥 remove implementation of validate themes (#7490)
no issue - theme validation is handled by gscan
This commit is contained in:
parent
7dba7b52f8
commit
c4e47c9555
3 changed files with 0 additions and 142 deletions
|
@ -20,7 +20,6 @@ var debug = require('debug')('ghost:boot:init'),
|
|||
i18n = require('./i18n'),
|
||||
api = require('./api'),
|
||||
config = require('./config'),
|
||||
logging = require('./logging'),
|
||||
middleware = require('./middleware'),
|
||||
db = require('./data/schema'),
|
||||
models = require('./models'),
|
||||
|
@ -31,7 +30,6 @@ var debug = require('debug')('ghost:boot:init'),
|
|||
slack = require('./data/slack'),
|
||||
GhostServer = require('./ghost-server'),
|
||||
scheduling = require('./scheduling'),
|
||||
validateThemes = require('./utils/validate-themes'),
|
||||
readDirectory = require('./utils/read-directory'),
|
||||
utils = require('./utils'),
|
||||
dbHash;
|
||||
|
@ -116,19 +114,6 @@ function init(options) {
|
|||
middleware(parentApp);
|
||||
debug('Express done');
|
||||
|
||||
// Log all theme errors and warnings
|
||||
validateThemes(config.getContentPath('themes'))
|
||||
.catch(function (result) {
|
||||
// TODO: change `result` to something better
|
||||
result.errors.forEach(function (err) {
|
||||
logging.error(err);
|
||||
});
|
||||
|
||||
result.warnings.forEach(function (warn) {
|
||||
logging.warn(warn.message);
|
||||
});
|
||||
});
|
||||
|
||||
return auth.init(config.get('auth'))
|
||||
.then(function (response) {
|
||||
parentApp.use(response.auth);
|
||||
|
|
|
@ -1,65 +0,0 @@
|
|||
/**
|
||||
* Dependencies
|
||||
*/
|
||||
|
||||
var readThemes = require('./read-themes'),
|
||||
Promise = require('bluebird'),
|
||||
_ = require('lodash'),
|
||||
i18n = require('../i18n');
|
||||
|
||||
/**
|
||||
* Validate themes:
|
||||
*
|
||||
* 1. Check if theme has package.json
|
||||
*/
|
||||
|
||||
function validateThemes(dir) {
|
||||
var result = {
|
||||
warnings: [],
|
||||
errors: []
|
||||
};
|
||||
|
||||
return readThemes(dir)
|
||||
.tap(function (themes) {
|
||||
_.each(themes, function (theme, name) {
|
||||
var hasPackageJson, warning;
|
||||
|
||||
hasPackageJson = theme['package.json'] !== undefined;
|
||||
|
||||
if (!hasPackageJson) {
|
||||
warning = {
|
||||
message: i18n.t('errors.utils.validatethemes.themeWithNoPackage.message'),
|
||||
context: i18n.t('errors.utils.validatethemes.themeWithNoPackage.context', {name: name}),
|
||||
help: i18n.t('errors.utils.validatethemes.themeWithNoPackage.help', {url: 'http://docs.ghost.org/themes/'})
|
||||
};
|
||||
|
||||
result.warnings.push(warning);
|
||||
}
|
||||
|
||||
// if package.json is `null`, it means that it exists
|
||||
// but JSON.parse failed (invalid json syntax)
|
||||
if (hasPackageJson && theme['package.json'] === null) {
|
||||
warning = {
|
||||
message: i18n.t('errors.utils.validatethemes.malformedPackage.message'),
|
||||
context: i18n.t('errors.utils.validatethemes.malformedPackage.context', {name: name}),
|
||||
help: i18n.t('errors.utils.validatethemes.malformedPackage.help', {url: 'http://docs.ghost.org/themes/'})
|
||||
};
|
||||
|
||||
result.warnings.push(warning);
|
||||
}
|
||||
});
|
||||
})
|
||||
.then(function () {
|
||||
var hasNotifications = result.warnings.length || result.errors.length;
|
||||
|
||||
if (hasNotifications) {
|
||||
return Promise.reject(result);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Expose `validateThemes`
|
||||
*/
|
||||
|
||||
module.exports = validateThemes;
|
|
@ -2,7 +2,6 @@ var should = require('should'),
|
|||
sinon = require('sinon'),
|
||||
nock = require('nock'),
|
||||
parsePackageJson = require('../../server/utils/parse-package-json'),
|
||||
validateThemes = require('../../server/utils/validate-themes'),
|
||||
readDirectory = require('../../server/utils/read-directory'),
|
||||
readThemes = require('../../server/utils/read-themes'),
|
||||
gravatar = require('../../server/utils/gravatar'),
|
||||
|
@ -367,67 +366,6 @@ describe('Server Utilities', function () {
|
|||
});
|
||||
});
|
||||
|
||||
describe('validate-themes', function () {
|
||||
it('should return warnings for themes without package.json', function (done) {
|
||||
var themesPath, pkgJson;
|
||||
|
||||
themesPath = tmp.dirSync({unsafeCleanup: true});
|
||||
pkgJson = JSON.stringify({
|
||||
name: 'casper',
|
||||
version: '1.0.0'
|
||||
});
|
||||
|
||||
fs.mkdirSync(join(themesPath.name, 'casper'));
|
||||
fs.mkdirSync(join(themesPath.name, 'invalid-casper'));
|
||||
|
||||
fs.writeFileSync(join(themesPath.name, 'casper', 'package.json'), pkgJson);
|
||||
|
||||
validateThemes(themesPath.name)
|
||||
.then(function () {
|
||||
done(new Error('validateThemes succeeded, but should\'ve failed'));
|
||||
})
|
||||
.catch(function (result) {
|
||||
result.errors.length.should.equal(0);
|
||||
result.warnings.should.eql([{
|
||||
message: 'Found a theme with no package.json file',
|
||||
context: 'Theme name: invalid-casper',
|
||||
help: 'This will be required in future. Please see http://docs.ghost.org/themes/'
|
||||
}]);
|
||||
|
||||
done();
|
||||
})
|
||||
.catch(done)
|
||||
.finally(themesPath.removeCallback);
|
||||
});
|
||||
|
||||
it('should return warning for theme with invalid package.json', function (done) {
|
||||
var themesPath, pkgJson;
|
||||
|
||||
themesPath = tmp.dirSync({unsafeCleanup: true});
|
||||
pkgJson = '{"name":casper}';
|
||||
|
||||
fs.mkdirSync(join(themesPath.name, 'casper'));
|
||||
fs.writeFileSync(join(themesPath.name, 'casper', 'package.json'), pkgJson);
|
||||
|
||||
validateThemes(themesPath.name)
|
||||
.then(function () {
|
||||
done(new Error('validateThemes succeeded, but should\'ve failed'));
|
||||
})
|
||||
.catch(function (result) {
|
||||
result.errors.length.should.equal(0);
|
||||
result.warnings.should.eql([{
|
||||
message: 'Found a malformed package.json',
|
||||
context: 'Theme name: casper',
|
||||
help: 'Valid package.json will be required in future. Please see http://docs.ghost.org/themes/'
|
||||
}]);
|
||||
|
||||
done();
|
||||
})
|
||||
.catch(done)
|
||||
.finally(themesPath.removeCallback);
|
||||
});
|
||||
});
|
||||
|
||||
describe('gravatar-lookup', function () {
|
||||
var currentEnv = process.env.NODE_ENV;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue