Skip to content
This repository has been archived by the owner on Mar 14, 2022. It is now read-only.

Commit

Permalink
Make verify-origami-json look for all the different origamiType varia…
Browse files Browse the repository at this point in the history
…tions
  • Loading branch information
JakeChampion committed Apr 12, 2021
1 parent 052c11e commit 3a5d06c
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 10 deletions.
36 changes: 34 additions & 2 deletions lib/tasks/verify-origami-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,37 @@ const isCI = require('is-ci');
const fileExists = file => denodeify(fs.open)(file, 'r').then(() => true).catch(() => false);
const readFile = denodeify(fs.readFile);

// https://origami.ft.com/spec/v1/manifest/#origamitype
// "component" or "module": A front-end component that follows the component specification
// "imageset": A set of images that have an alias on the Origami Image Service
// "service": An HTTP service that follows the service specification
// "cli": A command line tool
// "library": A library that is not a front-end component
// "website": Origami websites that aren’t intended to be services
// "config": Projects that are configuration for other projects
// "example": Example and boilerplate projects
// "meta": Repository-only projects that relate to how Origami works
// null: An Origami project that does not fit any of the named categories
function isValidOrigamiType(origamiType) {
switch (origamiType) {
case "component":
case "module":
case "imageset":
case "service":
case "cli":
case "library":
case "website":
case "config":
case "example":
case "meta":
case null: {
return true;
}
default:
return false;
}
}

function origamiJson(config) {
const result = [];

Expand All @@ -20,8 +51,9 @@ function origamiJson(config) {
.then(file => {
const origamiJson = JSON.parse(file);
const componentDemos = origamiJson.demos;
if (origamiJson.origamiType !== 'imageset' && origamiJson.origamiType !== 'module' && origamiJson.origamiType !== 'service') {
result.push('The origamiType property needs to be set to either "imageset", "module" or "service"');

if (!isValidOrigamiType(origamiJson.origamiType)) {
result.push('The origamiType property needs to be set to either "component", "module", "imageset", "service", "cli", "library", "website", "config", "example", "meta", or null');
}
if (typeof origamiJson.origamiVersion === 'number') {
result.push('The origamiVersion property must be a string.');
Expand Down
16 changes: 8 additions & 8 deletions test/unit/tasks/verify-origami-json.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ describe('verify-origami-json', function () {
proclaim.equal(
verifiedOrigamiJson.message,
'Failed linting:\n\n' +
'The origamiType property needs to be set to either "imageset", "module" or "service"\n' +
'The origamiType property needs to be set to either "component", "module", "imageset", "service", "cli", "library", "website", "config", "example", "meta", or null\n' +
'The origamiVersion property needs to be set to "2.0" or higher, this version of Origami Build tools only supports v2 of the Origami component specification.\n' +
'The support property must be an email or url to an issue tracker for this module\n' +
'The supportStatus property must be set to either "active", "maintained", "deprecated", "dead" or "experimental"\n\n' +
Expand All @@ -120,7 +120,7 @@ describe('verify-origami-json', function () {
proclaim.calledOnce(console.log);
proclaim.calledWithExactly(
console.log,
`::error file=origami.json,line=1,col=1::Failed linting:%0A%0AThe origamiType property needs to be set to either "imageset", "module" or "service"%0AThe origamiVersion property needs to be set to "2.0" or higher, this version of Origami Build tools only supports v2 of the Origami component specification.%0AThe support property must be an email or url to an issue tracker for this module%0AThe supportStatus property must be set to either "active", "maintained", "deprecated", "dead" or "experimental"%0A%0AThe origami.json file does not conform to the specification at http://origami.ft.com/docs/syntax/origamijson/`
`::error file=origami.json,line=1,col=1::Failed linting:%0A%0AThe origamiType property needs to be set to either "component", "module", "imageset", "service", "cli", "library", "website", "config", "example", "meta", or null%0AThe origamiVersion property needs to be set to "2.0" or higher, this version of Origami Build tools only supports v2 of the Origami component specification.%0AThe support property must be an email or url to an issue tracker for this module%0AThe supportStatus property must be set to either "active", "maintained", "deprecated", "dead" or "experimental"%0A%0AThe origami.json file does not conform to the specification at http://origami.ft.com/docs/syntax/origamijson/`
);
}
});
Expand Down Expand Up @@ -180,7 +180,7 @@ describe('verify-origami-json', function () {
proclaim.calledOnce(console.log);
proclaim.calledWithExactly(
console.log,
`::error file=origami.json,line=1,col=1::Failed linting:%0A%0AThe origamiType property needs to be set to either "imageset", "module" or "service"%0A'The origamiVersion property needs to be set to "2.0" or higher, this version of Origami Build tools only supports v2 of the Origami component specification.'%0AThe support property must be an email or url to an issue tracker for this module%0AThe supportStatus property must be set to either "active", "maintained", "deprecated", "dead" or "experimental"%0A%0AThe origami.json file does not conform to the specification at http://origami.ft.com/docs/syntax/origamijson/`
`::error file=origami.json,line=1,col=1::Failed linting:%0A%0AThe origamiType property needs to be set to either "component", "module", "imageset", "service", "cli", "library", "website", "config", "example", "meta", or null%0A'The origamiVersion property needs to be set to "2.0" or higher, this version of Origami Build tools only supports v2 of the Origami component specification.'%0AThe support property must be an email or url to an issue tracker for this module%0AThe supportStatus property must be set to either "active", "maintained", "deprecated", "dead" or "experimental"%0A%0AThe origami.json file does not conform to the specification at http://origami.ft.com/docs/syntax/origamijson/`
);
});
});
Expand All @@ -195,13 +195,13 @@ describe('verify-origami-json', function () {
proclaim.equal(
verifiedOrigamiJson.message,
'Failed linting:\n\n' +
'The origamiType property needs to be set to either "imageset", "module" or "service"\n\n' +
'The origamiType property needs to be set to either "component", "module", "imageset", "service", "cli", "library", "website", "config", "example", "meta", or null\n\n' +
'The origami.json file does not conform to the specification at http://origami.ft.com/docs/syntax/origamijson/'
);
proclaim.calledOnce(console.log);
proclaim.calledWithExactly(
console.log,
`::error file=origami.json,line=1,col=1::Failed linting:%0A%0AThe origamiType property needs to be set to either "imageset", "module" or "service"%0A%0AThe origami.json file does not conform to the specification at http://origami.ft.com/docs/syntax/origamijson/`
`::error file=origami.json,line=1,col=1::Failed linting:%0A%0AThe origamiType property needs to be set to either "component", "module", "imageset", "service", "cli", "library", "website", "config", "example", "meta", or null%0A%0AThe origami.json file does not conform to the specification at http://origami.ft.com/docs/syntax/origamijson/`
);
});
});
Expand All @@ -216,13 +216,13 @@ describe('verify-origami-json', function () {
proclaim.equal(
verifiedOrigamiJson.message,
'Failed linting:\n\n' +
'The origamiType property needs to be set to either "imageset", "module" or "service"\n\n' +
'The origamiType property needs to be set to either "component", "module", "imageset", "service", "cli", "library", "website", "config", "example", "meta", or null\n\n' +
'The origami.json file does not conform to the specification at http://origami.ft.com/docs/syntax/origamijson/'
);
proclaim.calledOnce(console.log);
proclaim.calledWithExactly(
console.log,
`::error file=origami.json,line=1,col=1::Failed linting:%0A%0AThe origamiType property needs to be set to either "imageset", "module" or "service"%0A%0AThe origami.json file does not conform to the specification at http://origami.ft.com/docs/syntax/origamijson/`
`::error file=origami.json,line=1,col=1::Failed linting:%0A%0AThe origamiType property needs to be set to either "component", "module", "imageset", "service", "cli", "library", "website", "config", "example", "meta", or null%0A%0AThe origami.json file does not conform to the specification at http://origami.ft.com/docs/syntax/origamijson/`
);
});
});
Expand Down Expand Up @@ -382,7 +382,7 @@ describe('verify-origami-json', function () {
proclaim.calledOnce(console.log);
proclaim.calledWithExactly(
console.log,
`::error file=origami.json,line=1,col=1::Failed linting:%0A%0AThe origamiType property needs to be set to either "imageset", "module" or "service"%0AThe origamiVersion property needs to be set to "2.0" or higher, this version of Origami Build tools only supports v2 of the Origami component specification.%0AThe support property must be an email or url to an issue tracker for this module%0AThe supportStatus property must be set to either "active", "maintained", "deprecated", "dead" or "experimental"%0A%0AThe origami.json file does not conform to the specification at http://origami.ft.com/docs/syntax/origamijson/`
`::error file=origami.json,line=1,col=1::Failed linting:%0A%0AThe origamiType property needs to be set to either "component", "module", "imageset", "service", "cli", "library", "website", "config", "example", "meta", or null%0AThe origamiVersion property needs to be set to "2.0" or higher, this version of Origami Build tools only supports v2 of the Origami component specification.%0AThe support property must be an email or url to an issue tracker for this module%0AThe supportStatus property must be set to either "active", "maintained", "deprecated", "dead" or "experimental"%0A%0AThe origami.json file does not conform to the specification at http://origami.ft.com/docs/syntax/origamijson/`
);
});
});
Expand Down

0 comments on commit 3a5d06c

Please sign in to comment.