2017-07-26 15:37:14 -04:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
2020-03-02 12:35:30 -05:00
|
|
|
/**
|
|
|
|
* @license
|
2020-05-19 15:08:49 -04:00
|
|
|
* Copyright Google LLC All Rights Reserved.
|
2020-03-02 12:35:30 -05:00
|
|
|
*
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
|
|
* found in the LICENSE file at https://angular.io/license
|
|
|
|
*/
|
|
|
|
|
2017-07-26 15:37:14 -04:00
|
|
|
var json = '';
|
|
|
|
|
|
|
|
if (require.main === module) {
|
|
|
|
process.stdin.setEncoding('utf8');
|
|
|
|
|
|
|
|
process.stdin.on('readable', () => {
|
|
|
|
const chunk = process.stdin.read();
|
|
|
|
if (chunk !== null) {
|
|
|
|
json += chunk;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
process.stdin.on('end', () => {
|
|
|
|
var obj = JSON.parse(json);
|
|
|
|
var argv = process.argv.slice(2);
|
|
|
|
extractPaths(obj, argv).forEach(function(line) {
|
2020-03-02 12:35:30 -05:00
|
|
|
console.info(line);
|
|
|
|
});
|
2017-07-26 15:37:14 -04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function extractPaths(obj, paths) {
|
|
|
|
var lines = [];
|
|
|
|
paths.forEach(function(exp) {
|
|
|
|
var objs = obj instanceof Array ? [].concat(obj) : [obj];
|
|
|
|
exp.split('.').forEach(function(name) {
|
2020-05-05 16:12:39 -04:00
|
|
|
for (var i = 0; i < objs.length; i++) {
|
2017-07-26 15:37:14 -04:00
|
|
|
var o = objs[i];
|
|
|
|
if (o instanceof Array) {
|
|
|
|
// Expand and do over
|
2020-05-05 16:12:39 -04:00
|
|
|
objs = objs.slice(0, i).concat(o).concat(objs.slice(i + 1, objs.length));
|
2017-07-26 15:37:14 -04:00
|
|
|
i--;
|
|
|
|
} else {
|
2020-05-05 16:12:39 -04:00
|
|
|
name.split('=').forEach(function(name, index) {
|
2017-07-26 15:37:14 -04:00
|
|
|
if (index == 0) {
|
|
|
|
objs[i] = o = o[name];
|
|
|
|
} else if (name.charAt(0) == '^') {
|
|
|
|
if (o.indexOf(name.substr(1)) !== 0) {
|
|
|
|
objs.splice(i, 1);
|
|
|
|
i--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2020-05-05 16:12:39 -04:00
|
|
|
lines.push(objs.join('|'));
|
2017-07-26 15:37:14 -04:00
|
|
|
});
|
|
|
|
return lines;
|
|
|
|
}
|
|
|
|
|
2020-03-02 12:35:30 -05:00
|
|
|
exports.extractPaths = extractPaths;
|