Skip to content

Commit

Permalink
remove maprules-ui from build (#6)
Browse files Browse the repository at this point in the history
* update stale links

ref #1

* fix instructions

ref #1

* fix build script

ref #1

* update readmen

ref #1

* update gitignore to push needed rules dir

ref #1

* remove maprules-ui artifacts

* update stale links,0 bad instructions in readme, messed up package json, and bad build script (#2)

* update stale links

ref #1

* fix instructions

ref #1

* fix build script

ref #1

* update readmen

ref #1

* update gitignore to push needed rules dir

ref #1

* 5 (#7)

* begin circleci setup

ref #5

* hey, don't forget about schemas dir rules!

ref #5

* update build just to see of circle recognizes

ref #5

* pluck fontawesome

ref #4
  • Loading branch information
abalosc1 authored and maxgrossman committed Oct 12, 2018
1 parent 0afe788 commit 6217985
Show file tree
Hide file tree
Showing 26 changed files with 371 additions and 71 deletions.
24 changes: 24 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
version: 2
jobs:
build:
working_directory: ~/maprules
docker:
- image: circleci/node:10.7.0
steps:
- checkout
- run:
name: update-npm
command: 'sudo npm install -g npm@latest'
- run:
name: install dependencies
command: 'npm install --save sqlite3 && npm install'
- run:
name: build
command: 'npm run build'
- run:
name: fixture
command: 'NODE_ENV=testing npm run fixture'
- run:
name: test
command: 'npm test'

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ package-lock.json
doc
spec
rules/
!adapters/rules
!schemas/rules
maprule/
db/*.sqlite
node_modules/
Expand Down
8 changes: 4 additions & 4 deletions ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ The 'API' refers to the API and database that stores the tagging rules and forma

#### Technical details

- the API is written using [hapijs](https://hapijs.com/). For full documentation regarding the API, check out its own [documentation](link.to.api.docs)
- the API is written using [hapijs](https://hapijs.com/). For full documentation regarding the API, check out its own [documentation](https://github.com/radiant-maxar/maprules/blob/master/maprules.apidocs.md)
- each editor/tool integration is made possible by an `adapter` modules and a schema module. These generate files that make presets/validations usable in integrations.
- the schema modules are written using [joi](https://github.com/hapijs/joi). These modules define what is a valid output for a given integration file as well as inputs for the config file.

Expand All @@ -49,12 +49,12 @@ Currently supported integrations and integrations in development are below...

### JOSM

- the JOSM [MapRules Plugin]() provides support for MapRules in JOSM
- the JOSM [MapRules Plugin](https://github.com/radiant-maxar/maprules-josm) provides support for MapRules in JOSM

STATUS: Developed and awaiting integration into the [JOSM Plugins]() repo
STATUS: Developed and awaiting integration into the [JOSM Plugins](https://github.com/openstreetmap/josm-plugins) repo

### iD

- a feature branch brings MapRules support to iD

STATUS: Still just a fork in the MapRules organization
STATUS: Still just a [fork](https://github.com/radiant-maxar/iD/tree/remote-presets)
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# 0.0.1-alpha

##### September 30th, 2018
##### October 9th, 2018

- :tada: first release!
14 changes: 7 additions & 7 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Contributing to MapRules

First off, thanks for considering to contribute! Before heading to file a ticket for a bug you found or an awesome idea, please read the [Code of Conduct](link.to.code.of.conduct).
First off, thanks for considering to contribute! Before heading to file a ticket for a bug you found or an awesome idea, please read the [Code of Conduct](https://github.com/radiant-maxar/maprules/blob/master/CODE_OF_CONDUCT.md).

# File an issue

Expand Down Expand Up @@ -28,18 +28,18 @@ These labels are for issues needing fixing...
| bug-maprules | bug that applies directly to the MapRules service code |
| bug-integration | bug that applies to using MapRules in one of the tools it is integrated with |

## Actionables
## Actionables :hammer:

These labels are for issues to be handled
These labels are applied issues to describe who aught to hammer them out

| type | description |
|------------------|-----------------------------------------------------------------------------------------------------------|
| good first issue | issue for first time contributors |
| help wanted | a heftier task that requires some prior knowledge of or willingness to get to know the MapRules code base |

## features
## Features :squirrel:

These labels are for features to be added
These labels are for features to be added and shipped in the future

| type | description |
|------------------|-----------------------------------------------------------|
Expand All @@ -48,7 +48,7 @@ These labels are for features to be added
| rule | feature that adds a new rule type for MapRules to support |
| performance | feature that makes MapRules more performant |

## discussion
## discussion :telephone_receiver:

These labels should be applied to issues that encapsulate some general discussion

Expand All @@ -57,7 +57,7 @@ These labels should be applied to issues that encapsulate some general discussio
| question | if it's not clear if a new feature should be in MapRules, or perhaps there lacks' clarity on how best to solve a problem, this label applies |
| considering | if an ask is interesting but more consensus is needed before it's all systems go, this label applies |

## housekeeping
## housekeeping :house_with_garden:

These labels should be applied to indicate what developers are doing to address or not address an issues

Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ nvm use

##### install node dependencies
```
yarn install --save sqlite3
yarn install
yarn install -G sqlite3 && yarn install
```

### Development
Expand Down
38 changes: 38 additions & 0 deletions adapters/rules/config/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
'use strict';

const buildTagChecks = require('./tagChecks');
const buildDisabledFeatureChecks = require('../../disabledFeatures');

const translateOsmType = require('../../helpers').translateOsmType;
const flattenElements = require('../../helpers').flattenElements;
const inferJosmGeometries = require('../../josmPresets/helpers').inferJosmGeometries;

/**
* Provided presetConfig, replies rules used to build MapCSS
* replies a single mapcss rule config.
* @param {Object} config presetConfig
* @return {Object} single mapcss rule config.
*/
module.exports = (config) => {
const configRules = config.presets.map((preset) => {
const rules = preset.fields.map((field) => {
return buildTagChecks(field, preset.primary, preset.name, config.name);
});

return inferJosmGeometries(preset.geometry).map((geometry) => {
return {
osmType: geometry,
rules: flattenElements(rules)
};
});
});

if (config.hasOwnProperty('disabledFeatures')) {
const disabledFeatures = ['node', 'way'].map((geom) => {
return buildDisabledFeatureChecks(config.disabledFeatures, geom, config.name);
});
configRules.concat(disabledFeatures);
}

return flattenElements(configRules);
};
34 changes: 34 additions & 0 deletions adapters/rules/config/tagChecks/fieldConditional/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
'use strict';

const adaptEqualityToConditional = require('../../../../helpers').adaptEqualityToConditional;
const escaped = require('../../../../helpers').escaped;

/**
* Provided parameters for rule's truthiness and severity,
* returns config used to build mapcss selector and validation error/warning
* @param {String} key key part of selector's key, value pair
* @param {Boolean} valCondition defines truthiness of rule when equalityValues are present
* @param {Array} equalityValues values, that if present, define the possible values that if coupled / not coupled with key, cause an validation error/warning
* @return {Object} config object used to build mapcss selector and validation error/warning
*/
const _alpha = (key, value) => {
const values = value.values.map(v => `^${escaped(v.split(' - ')[0])}$`).join('|');
const equality = value.valCondition ? '!~' : '=~';
return [`[${key}][${key}${equality}/${values}/]`];
};

/**
* Provided key and numericEquality object,
* replies config used to build mapcss selector and validation error/warning
* @param {String} key key part of the selector's key/val pair
* @param {Object} numericEquality subset of numeric values object
* @return {string} string component of mapcss config
*/
const _numeric = (key, value) => {
return [adaptEqualityToConditional(key, value)];
};

module.exports = {
numeric: _numeric,
alpha: _alpha
};
50 changes: 50 additions & 0 deletions adapters/rules/config/tagChecks/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
'use strict';

const THROW_ERROR = require('../../../constants').THROW_ERROR;
const THROW_WARNING = require('../../../constants').THROW_WARNING;

const message = require('./message');
const fieldConditional = require('./fieldConditional');
const getToThrow = require('../../../helpers').getToThrow;
const impliesEqual = require('../../../helpers').impliesEqual;

/**
* Provided field and primary key,
* replies array of configs defining mapcss selectors
* @param {object} field field config from preset within presetConfig
* @param {object} primary primary tag config from field config
* @return {array} array of configs defining mapcss selectors
*/
module.exports = (field, primary, presetName,) => {
const keyCondition = Number(field.keyCondition);
const values = field.values;
const tagChecks = [];
const tagCheckBase = primary.map(p => `[${p.key}=${p.val}]`).join('');
const conditionalVerb = keyCondition === 0 ? 'must not' : keyCondition === 1 ? 'must' : 'may';

tagChecks.push({
base: tagCheckBase,
fieldConditionals: [keyCondition !== 0 ? `[!${field.key}]` : `[${field.key}]`],
toThrow: keyCondition !== 2 ? THROW_ERROR : THROW_WARNING,
message: `'${presetName}' preset ${conditionalVerb} include ${field.key}`
});

if (keyCondition !== 0) {
values.forEach((value) => {
const checkType = value.valCondition > 2 || impliesEqual(values) ? 'numeric' : 'alpha';

const messageBuilder = message[checkType];
const fieldConditionBuilder = fieldConditional[checkType];

tagChecks.push({
base: tagCheckBase,
toThrow: getToThrow(value),
fieldConditionals: fieldConditionBuilder(field.key, value),
message: messageBuilder(field.key, value)
});
});

}

return tagChecks;
};
33 changes: 33 additions & 0 deletions adapters/rules/config/tagChecks/message/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
'use strict';

const adaptNumericToMessage = require('../../../../helpers').adaptNumericToMessage;

/**
* builds a error message for alpha (so string based) rules
* @param {Array} equalityValues list of equality values to be adapted to error messages
* @param {Number} messageMatch numeric encoding of must/must not/may
* @return {String} error message
*/
const _alpha = (key, value) => {
const valuesString = value.values.map(v => `'${v}'`).join(',');
let conditionalMessage = '';
if (value.valCondition === 0) conditionalMessage += 'must not';
if (value.valCondition === 1) conditionalMessage += 'must';
if (value.valCondition === 2) conditionalMessage += 'may';
return `${key} ${conditionalMessage} be ${valuesString}`;
};

/**
* builds a error message for numeric rules
* @param {Array} equalityValues list of equality values to be adapted to error messages
* @return {String} error message
*/
const _numeric = (key, value) => {
const valueString = adaptNumericToMessage(value.values[0], value.valCondition);
return `${key} must be ${valueString}`;
};

module.exports = {
alpha: _alpha,
numeric: _numeric
};
19 changes: 19 additions & 0 deletions adapters/rules/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
'use strict';

const buildRulesConfig = require('./config');
const buildMapCSS = require('./mapCSS');

/**
* Provided a preset config, adapts/generates
* mapcss string reflecting rules written inside config
* @param {Object} config presetConfig
* @return {String} mapcss string
*/
module.exports = (config) => {
try {
const rulesConfig = buildRulesConfig(config);
return buildMapCSS(rulesConfig);
} catch (error) {
throw error;
}
};
17 changes: 17 additions & 0 deletions adapters/rules/mapCSS/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
'use strict';

const buildRule = require('./rule');
const flattenElements = require('../../helpers').flattenElements;

/**
* Provided mapcss config, replies mapcss string
* @param {Object} config the mapcss config
* @return {String} mapcss string
*/
module.exports = (config) => {
return flattenElements(config.map((configRule) => {
return configRule.rules.map((tagCheck) => {
return buildRule(tagCheck, configRule.osmType);
});
})).join('');
};
34 changes: 34 additions & 0 deletions adapters/rules/mapCSS/rule.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
'use strict';

/**
*
* @param {Object} rule config for mapcss tag selector
* @param {String} osmType osmType that prepends tag selector
* @return {String} mapcss selector
*/
module.exports = (rule, osmType) => {
const isClosed = osmType === 'closedway';
const fieldConditionals = rule.fieldConditionals;
const toThrow = rule.toThrow;

let selectors = '';
if (fieldConditionals !== undefined) {
selectors += fieldConditionals.map(fieldConditional => {

let selector = `${isClosed ? 'way': osmType}${rule.base}${fieldConditional}`;
if (isClosed) {
selector += ':closed';
}

return selector;

}).join(fieldConditionals.length > 1 ? ',\n' : '');

} else {
selectors += `${isClosed ? 'way' : osmType}${rule.base}`;

}
return `${selectors}{
${toThrow}: "${rule.message}";
}\n`;
};
Loading

0 comments on commit 6217985

Please sign in to comment.