Skip to content

Commit

Permalink
Merge pull request #10 from monzo/feature/better-mobile-rules
Browse files Browse the repository at this point in the history
Allow mobile and master rules to work together
  • Loading branch information
Alex Pate authored Oct 17, 2019
2 parents 64ff974 + b52ec8f commit de2ca66
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/cmd/validate-and-fix.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {getPageByName} from '../utils';
import {validateAll} from '../validators';
import {autoAlignArtboards} from '../artboards';
import {markWipRows} from '../wip-rows';
import {REQUIRED_PAGE_NAMES} from '../constants';
import {SCOPED_PAGE_NAMES} from '../constants';

export default async function validateAndFix(context) {
try {
Expand All @@ -12,7 +12,7 @@ export default async function validateAndFix(context) {
UI.message(`‼️ ${error.message}`);
}

REQUIRED_PAGE_NAMES.forEach(pageName => {
SCOPED_PAGE_NAMES.forEach(pageName => {
const page = getPageByName(context, pageName);

// Fix artboard alignment on the page
Expand Down
2 changes: 1 addition & 1 deletion src/constants.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export const REQUIRED_PAGE_NAMES = ['iOS', 'Android'];
export const SCOPED_PAGE_NAMES = ['iOS', 'Android', 'Master'];
export const ALLOWED_PAGE_NAMES = ['iOS', 'Android', 'Master', 'Symbols'];
23 changes: 16 additions & 7 deletions src/validators.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {getPageByName} from './utils';
import {REQUIRED_PAGE_NAMES, ALLOWED_PAGE_NAMES} from './constants';
import {ALLOWED_PAGE_NAMES} from './constants';

const validators = [
validatePagePresence,
Expand All @@ -24,15 +24,24 @@ export function validateAll(context) {
}

/**
* Ensures that there is either a Master page, or an iOS/Android page.
* Ensures that there is either a Master page, or that both iOS and Android exist
*/
export function validatePagePresence(context) {
return new Promise((resolve, reject) => {
REQUIRED_PAGE_NAMES.forEach(pageName => {
if (!getPageByName(context, pageName)) {
reject({message: `Missing page ${pageName}`});
}
});
if (getPageByName(context, 'iOS') && !getPageByName(context, 'Android')) {
reject({message: `Missing page Android`});
}

if (getPageByName(context, 'Android') && !getPageByName(context, 'iOS')) {
reject({message: `Missing page iOS`});
}

if (
!getPageByName(context, 'Master') &&
(!getPageByName(context, 'iOS') || !getPageByName(context, 'Android'))
) {
reject({message: `Missing page Master`});
}

resolve();
});
Expand Down

0 comments on commit de2ca66

Please sign in to comment.