From a15dabbb4abdfa9ab2411fcac569e243704ecc58 Mon Sep 17 00:00:00 2001 From: DQNEO Date: Fri, 28 Aug 2015 14:37:46 +0900 Subject: [PATCH] enable to server separated files on node server --- examples/helloworld/web/index.html | 5 ++++ scripts/nodejs/server.js | 38 ++++++++++++++++++++++++++---- 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/examples/helloworld/web/index.html b/examples/helloworld/web/index.html index c26e284..ab93ecb 100644 --- a/examples/helloworld/web/index.html +++ b/examples/helloworld/web/index.html @@ -5,7 +5,12 @@ + + + + + diff --git a/scripts/nodejs/server.js b/scripts/nodejs/server.js index bc234c0..6d8aacb 100644 --- a/scripts/nodejs/server.js +++ b/scripts/nodejs/server.js @@ -54,6 +54,26 @@ function genTemplate(filePath, packageName, callback) { }); } +function listTupaiClass(callback) { + var packagejsHtml = ''; + var tupaiSrcDir = path.join(__dirname, '..', '..', 'src', 'tupai'); + execute(['list', '--classPath', tupaiSrcDir, '--ignoreNotFound'], function(output) { + //if (!output) {return;} + var classes = JSON.parse(output); + //console.log(classes); + var tupaijsfiles = classes.map(function(cls){ + var path = cls.path; + return path.replace(tupaiSrcDir + "/", ""); + }); + + var scripts = tupaijsfiles.map(function(filename){ return '';}); + tupaiFilesHtml = packagejsHtml + "\n" + scripts.join("\n"); + + callback(); + }); + +} + function listClass(callback) { var classPath = mConfig.genConfigs + ';' + mConfig.genTemplates + ';' + mConfig.sources; execute(['list', '--classPath', classPath, '--ignoreNotFound'], function(output) { @@ -191,7 +211,9 @@ function configDebugMode(app) { next(); } else { var content = fs.readFileSync(filePath).toString(); - res.send(content.replace(/[\s\S]*/, classListHtml)); + content = content.replace(/[\s\S]*/, classListHtml); + content = content.replace(/[\s\S]*/, tupaiFilesHtml); + res.send(content); } } else if(p == '/js/tupai.min.js') { /*if(fs.existsSync(path.join(mConfig.web,'js','tupai.min.js'))) { @@ -205,6 +227,10 @@ function configDebugMode(app) { next(); } }); + + var tupaiRootDir = path.join(__dirname, '..', '..'); + app.use('/__tupairoot', express.static(tupaiRootDir)); + app.use('/tupai', express.static(webDir)); app.use('/tupai', express.directory(webDir)); app.use('/templates', express.static(mConfig.templates)); @@ -234,6 +260,8 @@ function startHttpServer(releaseMode, options) { var classListHtml; +var tupaiFilesHtml; + function renderClassListHtml(callback) { listClass(function(cl) { //classListHtml = ''; @@ -348,9 +376,11 @@ exports.start = function(options) { fs.mkdirSync('gen'); genConfigs(); genTemplates(function() { - renderClassListHtml(function() { - watchFs(); - startHttpServer(releaseMode, options); + listTupaiClass(function(){ + renderClassListHtml(function() { + watchFs(); + startHttpServer(releaseMode, options); + }); }); }); }