const scandir = require('./scandir'); var Promise = require('bluebird'); var _ = require('lodash'); function ExampleStore(path) { this.rootPath = path; this.repos = []; } ExampleStore.prototype.init = function() { const loadRepository = this.loadRepository.bind(this); return scandir(this.rootPath, ['.gitkeep']) .then(repositories => Promise.map( repositories, loadRepository )); }; ExampleStore.prototype.loadRepository = function(repoPath) { const loadExample = this.loadExample.bind(this); const fullPath = this.rootPath + '/' + repoPath; const repoConfig = require(fullPath + '/repo-config.json'); const repoDescriptor = { title: repoConfig.title, path: repoPath, fullPath, examples: [] }; this.repos.push(repoDescriptor); return scandir(fullPath, ['.gitkeep', 'repo-config.json']) .then(examples => Promise.map( examples, example => loadExample(repoDescriptor, example) )) .then(() => console.log(this.repos[0])) }; ExampleStore.prototype.loadExample = function(repo, slug) { const exampleConfig = require(repo.fullPath + '/' + slug + '/config.json'); repo.examples.push(Object.assign({ slug }, exampleConfig)); return exampleConfig; }; ExampleStore.prototype.getList = function(path) { return _.find(this.repos, { path }); } ExampleStore.prototype.getRepoMenu = function(path) { return this.repos.map( ({ title, path }) => ({ title, slug: path }) ) }; ExampleStore.prototype.getExampleMenu = function(path) { const repo = _.find(this.repos, { path }); return repo.examples.map( ({ title, slug }) => ({ title, slug: repo.path + '/' + slug }) ); }; ExampleStore.prototype.getMenu = function(path) { const self = this; return '