|
@@ -4,23 +4,42 @@ var _ = require('lodash');
|
|
|
var Mustache = require('mustache');
|
|
var Mustache = require('mustache');
|
|
|
var path = require('path');
|
|
var path = require('path');
|
|
|
var fs = require('fs');
|
|
var fs = require('fs');
|
|
|
|
|
+var chokidar = require('chokidar');
|
|
|
var indexTmplPath = path.normalize(__dirname + '/../html/index.mustache.html');
|
|
var indexTmplPath = path.normalize(__dirname + '/../html/index.mustache.html');
|
|
|
-var indexTpml = fs.readFileSync(indexTmplPath).toString();
|
|
|
|
|
|
|
+var indexTpml;
|
|
|
var {
|
|
var {
|
|
|
readFilesAsync
|
|
readFilesAsync
|
|
|
} = require('../lib/fsio');
|
|
} = require('../lib/fsio');
|
|
|
|
|
|
|
|
-function readExampleFiles(repoSlug, exampleSlug, config) {
|
|
|
|
|
- const exampleDir = path.normalize(__dirname + '/../exemples/' + repoSlug + '/' + exampleSlug);
|
|
|
|
|
- const libsCssDir = path.normalize(__dirname + '/../css/vendor');
|
|
|
|
|
- const libsJsDir = path.normalize(__dirname + '/../js/vendor');
|
|
|
|
|
- const { html, js, css } = config; // libsCss, libsJs
|
|
|
|
|
- const files = [].concat(html, js, css);
|
|
|
|
|
- return readFilesAsync(exampleDir, files);
|
|
|
|
|
-}
|
|
|
|
|
|
|
+
|
|
|
|
|
+// One-liner for current directory, ignores .dotfiles
|
|
|
|
|
+chokidar.watch('./html', {ignored: /(^|[\/\\])\../}).on('all', (event, path) => {
|
|
|
|
|
+ // console.log(event, path);
|
|
|
|
|
+ if(path === 'html/index.mustache.html') {
|
|
|
|
|
+ console.log('reload index html');
|
|
|
|
|
+ indexTpml = fs.readFileSync(indexTmplPath).toString();
|
|
|
|
|
+ }
|
|
|
|
|
+});
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+module.exports = function(exStore, exDir) {
|
|
|
|
|
+
|
|
|
|
|
+ function readExampleFiles(repoSlug, exampleSlug, config) {
|
|
|
|
|
+ const exampleDir = exDir + '/' + repoSlug + '/' + exampleSlug;
|
|
|
|
|
+ const libsCssDir = path.normalize(__dirname + '/../css/vendor');
|
|
|
|
|
+ const libsJsDir = path.normalize(__dirname + '/../js/vendor');
|
|
|
|
|
+ const { html, js, css } = config; // libsCss, libsJs
|
|
|
|
|
+
|
|
|
|
|
+ const files = [].concat(html, js, css);
|
|
|
|
|
+ // console.log('#2', exampleDir, html, js, css, files);
|
|
|
|
|
+ return readFilesAsync(exampleDir, files);
|
|
|
|
|
+ // .then(files => {
|
|
|
|
|
+ // console.log('#### files', files);
|
|
|
|
|
+ // return files;
|
|
|
|
|
+ // });
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
|
|
|
-module.exports = function(exStore) {
|
|
|
|
|
|
|
|
|
|
return {
|
|
return {
|
|
|
|
|
|
|
@@ -50,7 +69,7 @@ module.exports = function(exStore) {
|
|
|
const menuRepo = exStore.getRepoMenu();
|
|
const menuRepo = exStore.getRepoMenu();
|
|
|
const menuExample = exStore.getExampleMenu(repo.path);
|
|
const menuExample = exStore.getExampleMenu(repo.path);
|
|
|
// const title = 'Home';
|
|
// const title = 'Home';
|
|
|
- console.log(menuExample);
|
|
|
|
|
|
|
+ // console.log(menuExample);
|
|
|
res.send(Mustache.render(indexTpml, {
|
|
res.send(Mustache.render(indexTpml, {
|
|
|
// title,
|
|
// title,
|
|
|
menuRepo,
|
|
menuRepo,
|
|
@@ -64,6 +83,7 @@ module.exports = function(exStore) {
|
|
|
* Get index with selected repo&example
|
|
* Get index with selected repo&example
|
|
|
*/
|
|
*/
|
|
|
getIndexExample: function(req, res) {
|
|
getIndexExample: function(req, res) {
|
|
|
|
|
+ console.log('getIndexExample', req.params);
|
|
|
const repo = exStore.getRepo(req.params.repoSlug);
|
|
const repo = exStore.getRepo(req.params.repoSlug);
|
|
|
if(! repo) {
|
|
if(! repo) {
|
|
|
return res.status(404).send('Repo ' + req.params.repoSlug + ' not found');
|
|
return res.status(404).send('Repo ' + req.params.repoSlug + ' not found');
|
|
@@ -74,12 +94,13 @@ module.exports = function(exStore) {
|
|
|
if(! example) {
|
|
if(! example) {
|
|
|
return res.status(404).send('Example ' + req.params.repoSlug + '/' + req.params.exampleSlug + ' not found');
|
|
return res.status(404).send('Example ' + req.params.repoSlug + '/' + req.params.exampleSlug + ' not found');
|
|
|
}
|
|
}
|
|
|
|
|
+ // console.log('#1');
|
|
|
// const title = 'Home';
|
|
// const title = 'Home';
|
|
|
- console.log(menuExample);
|
|
|
|
|
|
|
+ // console.log(menuExample);
|
|
|
const { repoSlug, exampleSlug } = req.params;
|
|
const { repoSlug, exampleSlug } = req.params;
|
|
|
readExampleFiles(repoSlug, exampleSlug, example)
|
|
readExampleFiles(repoSlug, exampleSlug, example)
|
|
|
.then(files => {
|
|
.then(files => {
|
|
|
- // console.log('example files', html, js, css);
|
|
|
|
|
|
|
+ console.log('example files', files);
|
|
|
res.send(Mustache.render(indexTpml, {
|
|
res.send(Mustache.render(indexTpml, {
|
|
|
// title,
|
|
// title,
|
|
|
menuRepo,
|
|
menuRepo,
|