mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-23 03:42:27 +03:00
parent
6d42c391c5
commit
bd3afeb112
@ -1,4 +1,4 @@
|
||||
const PackageJson = require('./package-json');
|
||||
const {i18n} = require('../../common');
|
||||
|
||||
module.exports = new PackageJson(i18n);
|
||||
module.exports = new PackageJson({i18n});
|
||||
|
@ -7,6 +7,11 @@ const errors = require('@tryghost/errors');
|
||||
const notAPackageRegex = /^\.|_messages|README.md|node_modules|bower_components/i;
|
||||
const packageJSONPath = 'package.json';
|
||||
|
||||
/**
|
||||
* @typedef {Object} Ii18n
|
||||
* @prop {(key: string) => string} t
|
||||
*/
|
||||
|
||||
/**
|
||||
* # Package Utils
|
||||
*
|
||||
@ -15,9 +20,15 @@ const packageJSONPath = 'package.json';
|
||||
* - Adapters: replace fundamental pieces like storage, will become npm modules
|
||||
*
|
||||
* These utils facilitate loading, reading, managing etc, packages from the file system.
|
||||
*
|
||||
*/
|
||||
module.exports = class PackageJson {
|
||||
constructor(i18n) {
|
||||
/**
|
||||
* Creates an instance of PackageJson, an util used to read and validate package.json files
|
||||
* @param {Object} dependencies
|
||||
* @param {Ii18n} dependencies.i18n
|
||||
*/
|
||||
constructor({i18n}) {
|
||||
this.i18n = i18n;
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,11 @@
|
||||
const should = require('should');
|
||||
const packageJSON = require('../../../../../core/server/lib/fs/package-json');
|
||||
const PackageJSON = require('../../../../../core/server/lib/fs/package-json/package-json');
|
||||
|
||||
const packageJSON = new PackageJSON({
|
||||
i18n: {
|
||||
t: key => key
|
||||
}
|
||||
});
|
||||
|
||||
describe('lib/fs/package-json', function () {
|
||||
// @TODO: introduce some non-theme package examples
|
||||
|
@ -1,7 +1,13 @@
|
||||
const should = require('should');
|
||||
const tmp = require('tmp');
|
||||
const fs = require('fs-extra');
|
||||
const packageJSON = require('../../../../../core/server/lib/fs/package-json');
|
||||
const PackageJSON = require('../../../../../core/server/lib/fs/package-json/package-json');
|
||||
|
||||
const packageJSON = new PackageJSON({
|
||||
i18n: {
|
||||
t: key => key
|
||||
}
|
||||
});
|
||||
|
||||
describe('lib/fs/package-json: parse', function () {
|
||||
it('should parse valid package.json', function (done) {
|
||||
@ -45,9 +51,9 @@ describe('lib/fs/package-json: parse', function () {
|
||||
done(new Error('packageJSON.parse succeeded, but should\'ve failed'));
|
||||
})
|
||||
.catch(function (err) {
|
||||
err.message.should.equal('"name" or "version" is missing from theme package.json file.');
|
||||
err.message.should.equal('errors.utils.parsepackagejson.nameOrVersionMissing');
|
||||
err.context.should.equal(tmpFile.name);
|
||||
err.help.should.equal('This will be required in future. Please see https://ghost.org/docs/api/handlebars-themes/');
|
||||
err.help.should.equal('errors.utils.parsepackagejson.willBeRequired');
|
||||
|
||||
done();
|
||||
})
|
||||
@ -71,9 +77,9 @@ describe('lib/fs/package-json: parse', function () {
|
||||
done(new Error('packageJSON.parse succeeded, but should\'ve failed'));
|
||||
})
|
||||
.catch(function (err) {
|
||||
err.message.should.equal('"name" or "version" is missing from theme package.json file.');
|
||||
err.message.should.equal('errors.utils.parsepackagejson.nameOrVersionMissing');
|
||||
err.context.should.equal(tmpFile.name);
|
||||
err.help.should.equal('This will be required in future. Please see https://ghost.org/docs/api/handlebars-themes/');
|
||||
err.help.should.equal('errors.utils.parsepackagejson.willBeRequired');
|
||||
|
||||
done();
|
||||
})
|
||||
@ -95,9 +101,9 @@ describe('lib/fs/package-json: parse', function () {
|
||||
done(new Error('packageJSON.parse succeeded, but should\'ve failed'));
|
||||
})
|
||||
.catch(function (err) {
|
||||
err.message.should.equal('Theme package.json file is malformed');
|
||||
err.message.should.equal('errors.utils.parsepackagejson.themeFileIsMalformed');
|
||||
err.context.should.equal(tmpFile.name);
|
||||
err.help.should.equal('This will be required in future. Please see https://ghost.org/docs/api/handlebars-themes/');
|
||||
err.help.should.equal('errors.utils.parsepackagejson.willBeRequired');
|
||||
|
||||
done();
|
||||
})
|
||||
@ -114,7 +120,7 @@ describe('lib/fs/package-json: parse', function () {
|
||||
done(new Error('packageJSON.parse succeeded, but should\'ve failed'));
|
||||
})
|
||||
.catch(function (err) {
|
||||
err.message.should.equal('Could not read package.json file');
|
||||
err.message.should.equal('errors.utils.parsepackagejson.couldNotReadPackage');
|
||||
err.context.should.equal(tmpFile.name);
|
||||
|
||||
done();
|
||||
|
@ -2,7 +2,13 @@ const should = require('should');
|
||||
const tmp = require('tmp');
|
||||
const join = require('path').join;
|
||||
const fs = require('fs-extra');
|
||||
const packageJSON = require('../../../../../core/server/lib/fs/package-json');
|
||||
const PackageJSON = require('../../../../../core/server/lib/fs/package-json/package-json');
|
||||
|
||||
const packageJSON = new PackageJSON({
|
||||
i18n: {
|
||||
t: key => key
|
||||
}
|
||||
});
|
||||
|
||||
describe('lib/fs/package-json: read', function () {
|
||||
describe('all', function () {
|
||||
|
Loading…
Reference in New Issue
Block a user