Permalink
Browse files

add prototype tool for building out a datasource specific reference, …

…using gyp like variables syntax to handle shared fields
  • Loading branch information...
1 parent bd8bce9 commit 7e59b1b2bdcbdc263f8e8a2e89b5851208fb3f74 @springmeyer springmeyer committed Jan 3, 2013
Showing with 75 additions and 0 deletions.
  1. +31 −0 latest/layers.json
  2. +44 −0 util/make-layer-ref.js
View
31 latest/layers.json
@@ -0,0 +1,31 @@
+{
+ "variables": {
+ "encoding": {
+ "type": "string",
+ "doc": "The encoding value for the datasource attributes",
+ "default-value": "utf-8",
+ "default-meaning": "UTF8 will be the assumed encoding for string attribute values",
+ "required": false
+ },
+ "row_limit": {
+ "type": "integer",
+ "doc": "Max amount of features to read from the datasource",
+ "default-value": "0",
+ "default-meaning": "All features will be read from the datasource (unless row_limit is > 1)",
+ "required": false
+ },
+ "file": {
+ "type": "string",
+ "doc": "Path to the file for the datasource",
+ "default-value": "",
+ "default-meaning": "",
+ "required": true
+ }
+ },
+ "datasources": {
+ "csv": {
+ "file":"<@(file)",
+ "row_limit":"<@(row_limit)"
+ }
+ }
+}
View
44 util/make-layer-ref.js
@@ -0,0 +1,44 @@
+var fs = require('fs');
+var path = require('path');
+var existsSync = require('fs').existsSync || require('path').existsSync
+
+var args = process.argv.slice(1);
+
+var cmd = path.basename(process.argv.slice(1,2));
+
+var input = args[1];
+if (input && input[0] != '/') {
+ input = path.join(process.cwd(), input);
+}
+
+if (!input) {
+ console.log(cmd+": no input file");
+ process.exit(1);
+}
+
+var ext = path.extname(input);
+
+if (!ext) {
+ console.log(cmd+": please pass a layers.json file");
+ process.exit(1);
+}
+
+if (!existsSync(input)) {
+ console.log(cmd+": file does not exist: '" + input + "'");
+ process.exit(1);
+}
+
+var data = JSON.parse(fs.readFileSync(input));
+
+// expand gyp-like variables to build out entire file
+Object.keys(data.datasources).forEach(function(key) {
+ var ds = data.datasources[key];
+ Object.keys(ds).forEach(function(prop) {
+ var match = ds[prop].match(/<@\((.+)\)/);
+ if (match && match[1]) {
+ ds[prop] = data.variables[prop];
+ }
+ });
+});
+
+console.log(JSON.stringify(data,null," "));

0 comments on commit 7e59b1b

Please sign in to comment.