Skip to content

Commit

Permalink
refactor: get value by key, prepare for #5
Browse files Browse the repository at this point in the history
  • Loading branch information
shaunthegeek committed May 28, 2019
1 parent 01d8808 commit 4d43a15
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
3 changes: 2 additions & 1 deletion build-docs.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/bash

rm -rf docs
mkdir -p docs
cp README.md docs/
echo "site_name: 'Laravel Socialite Providers'
Expand All @@ -8,7 +9,7 @@ nav:
- index: 'README.md'" > mkdocs.yml

for file in `ls */composer.json`; do
package_id=`node getValueFromJsonFile.js $file`
package_id=`node getValueFromJsonFile.js $file extra.component.id`
echo $package_id
dir_name=`dirname $file`
cp $dir_name/README.md docs/$package_id.md
Expand Down
12 changes: 9 additions & 3 deletions getValueFromJsonFile.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
'use strict';

const fs = require('fs');
const getValue = (object, path) => path.split('.').reduce((o, k) => (o || {})[k], object),
data = { key: { subKey: 'value' } },
theString = 'key.subKey';

const args = process.argv;
const file = args[2];
const key = args[3];

let rawdata = fs.readFileSync(args[2]);
let data = JSON.parse(rawdata);
console.log(data.extra.component.id);
const raw = fs.readFileSync(file);
const obj = JSON.parse(raw);
console.log(getValue(obj, key));

0 comments on commit 4d43a15

Please sign in to comment.