2
0
Fork 0

prepare 0.3.0, moved example to main package.json and move

options.error/debug to options.boot
This commit is contained in:
Willem 2016-11-17 19:05:26 +01:00
parent a9798d05b6
commit 7b94313f90
11 changed files with 208 additions and 122 deletions

View file

@ -11,6 +11,7 @@ var UglifyJS = require("uglify-js");
var Hashes = require('jshashes');
var minify = require('minify');
var appPath = '/test'; // dynamic context path for version or proxy/etc of server app.
var clientResourcesWeb = [];
var clientResources = {
js: [],
@ -23,10 +24,11 @@ var addClientResource = function(clientResource, resourceType) {
};
var fetchHashResource = function(fetchEntry,cb) {
var serverUrl = 'http://localhost:'+httpPort;
var serverUrl = 'http://localhost:'+httpPort+appPath;
var hashDigest = new Hashes.SHA1;
fetch.fetchUrl(serverUrl + fetchEntry.url,function(err, meta, data) {
if (err !== null) { return cb(err); }
if (meta.status !== 200) { return cb('wrong status: '+meta.status); }
var assetHash = hashDigest.hex(''+data);
clientResourcesWeb.push({
url: fetchEntry.url,
@ -39,7 +41,8 @@ var fetchHashResource = function(fetchEntry,cb) {
var fetchHashResources = function(fetchList, cb) {
var resourceStack = fetchList;
var resourceLoader = function() {
var resourceLoader = function(err) {
if (err !== null) { return cb(err); }
resourceStack = resourceStack.slice(1);
if (resourceStack.length === 0) {
cb(null);
@ -83,7 +86,7 @@ function renderIndex() {
var inlineScript = UglifyJS.minify(__dirname+'/../../es5-ff-spa-loader.js');
minify(__dirname+'/../../es5-ff-spa-loader.css', {}, function(err, data) {
res.render('index', {
inlineScript: inlineScript.code,
inlineScript: 'console.log(\'test\');'+inlineScript.code,
inlineStyle: data
});
});
@ -102,8 +105,9 @@ addClientResource('/static/js/example-app.js','js'); // deps: jquery,angular
addClientResource('/static/js/controller/page-bar.js','js'); // deps: example-app.js
addClientResource('/static/js/controller/page-foo.js','js');
addClientResource('/static/js/controller/page-index.js','js');
// NOTE: appPath should be done as request parameter which auto prefixes the data, as only the client knows the true context path of a http application.
var appPath = '/test';
var server = express();
server.use(morgan('dev'));
server.use(cors({credentials: true, origin: '*', exposedHeaders: ['X-My-Api']}));
@ -111,10 +115,10 @@ server.set('view engine', 'ejs');
server.set('views', path.join(__dirname,'www_views'));
server.use(function(req, res, next) { res.header('X-My-Api', 'noknok');next(); });
server.use(appPath+'/static', express.static(path.join(__dirname,'www_static')));
server.use(appPath+'/static/module/bootstrap', express.static(path.join(__dirname,'../node_modules/bootstrap/dist')));
server.use(appPath+'/static/module/jquery', express.static(path.join(__dirname,'../node_modules/jquery/dist')));
server.use(appPath+'/static/module/angular', express.static(path.join(__dirname,'../node_modules/angular')));
server.use(appPath+'/static/module/angular-route', express.static(path.join(__dirname,'../node_modules/angular-route')));
server.use(appPath+'/static/module/bootstrap', express.static(path.join(__dirname,'../../node_modules/bootstrap/dist')));
server.use(appPath+'/static/module/jquery', express.static(path.join(__dirname,'../../node_modules/jquery/dist')));
server.use(appPath+'/static/module/angular', express.static(path.join(__dirname,'../../node_modules/angular')));
server.use(appPath+'/static/module/angular-route', express.static(path.join(__dirname,'../../node_modules/angular-route')));
server.get(appPath+'/static/spa-client-resources', function (req,res) {res.json({data: {resources: clientResourcesWeb}});});
server.get(appPath+'/static/spa-loader.css', function (req,res) {res.sendFile('es5-ff-spa-loader.css', { root: path.join(__dirname, '/../../') });});
server.get(appPath+'/', function (req, res) {res.redirect(appPath+'/example-ui');});
@ -125,9 +129,12 @@ server.get('/', function (req, res) {res.redi
server.listen(httpPort);
console.info('Server started on port '+httpPort);
var res = createClientResourceFetchList();
fetchHashResources(res, function(err) {
if (err !== null) {console.log(err);}
console.log('Total assets build: '+clientResourcesWeb.length);
fetchHashResources(createClientResourceFetchList(), function(err) {
if (err !== null) {
console.log('Fatal error '+err);
process.exit(1);
} else {
console.log('Total assets build: '+clientResourcesWeb.length);
}
});

View file

@ -4,7 +4,7 @@ document.title = 'FFSpaLoader Example';
var serverUrl = window.FFServerUrl;
console.log('FFExample provided serverUrl \"'+serverUrl+'\"');
// TODO for 0.2.1
// TODO for 0.4.0
//var tplCache = FFSpaLoader.factory.cache.websql({table: 'angular_tpl'});
//tplCache.cacheOpen(function(err) {
// tplCache.cacheSetValue('key123','value456',function(err) {
@ -30,6 +30,6 @@ var exampleUI = angular.module('exampleUI', ['ngRoute']).config(
exampleUI.controller('ApplicationController',function($scope,$http,$location) {
$scope.goLink = function ( path ) {
$location.path( path );
$location.path( path );
};
});

View file

@ -3,12 +3,12 @@
<head>
<meta charset="UTF-8"/>
<title>Loading</title>
<script id="ffCleanupScript"><%- inlineScript %></script>
<style id="ffCleanupStyle"><%- inlineStyle %></style>
<script id="ffCleanupScript" type="text/javascript"><%- inlineScript %></script>
<style id="ffCleanupStyle" type="text/css"><%- inlineStyle %></style>
</head>
<body>
<script id="ffCleanupConfig">
FFSpaLoader.options.debug.enable = true;
<script id="ffCleanupConfig" type="text/javascript">
FFSpaLoader.options.boot.debug.enable = true;
FFSpaLoader.options.boot.angular.modules.push('exampleUI');
FFSpaLoader.options.boot.cleanup.tags.push('ffCleanupStyle');
FFSpaLoader.options.boot.cleanup.tags.push('ffCleanupScript');