This repository has been archived by the owner on Apr 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f60e779
commit 77740fc
Showing
108 changed files
with
98,393 additions
and
2,432 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,7 @@ fhc-debug.log | |
.DS_Store | ||
.idea/ | ||
node_modules/ | ||
tmp/* | ||
*~ | ||
.fhclocal/ | ||
src/appforms/dist/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,247 @@ | ||
var path = require('path'); | ||
var fs = require("fs"); | ||
var exists = fs.existsSync || path.existsSync; | ||
var async = require("async"); | ||
var through = require('through'); | ||
|
||
module.exports = function(grunt) { | ||
var pkg = grunt.file.readJSON('package.json'); | ||
grunt.initConfig({ | ||
pkg: pkg, | ||
meta: {}, | ||
jshint: { | ||
all: ['src/*.js'], | ||
options: { | ||
curly: true, | ||
eqeqeq: true, | ||
eqnull: true, | ||
sub: true, | ||
loopfunc: true | ||
}, | ||
globals: { | ||
browser: true | ||
} | ||
}, | ||
concat: { | ||
lawnchair: { | ||
src: [ | ||
"libs/lawnchair/lawnchair.js", | ||
"libs/lawnchair/lawnchairWindowNameStorageAdapter.js", | ||
"libs/lawnchair/lawnchairLocalStorageAdapter.js", | ||
"libs/lawnchair/lawnchairWebkitSqlAdapter.js" | ||
], | ||
dest: "libs/generated/lawnchair.js" | ||
}, | ||
crypto: { | ||
src:[ | ||
"libs/cryptojs/cryptojs-core.js", | ||
"libs/cryptojs/cryptojs-enc-base64.js", | ||
"libs/cryptojs/cryptojs-cipher-core.js", | ||
"libs/cryptojs/cryptojs-aes.js", | ||
"libs/cryptojs/cryptojs-md5.js", | ||
"libs/cryptojs/cryptojs-sha1.js", | ||
"libs/cryptojs/cryptojs-x64-core.js", | ||
"libs/cryptojs/cryptojs-sha256.js", | ||
"libs/cryptojs/cryptojs-sha512.js", | ||
"libs/cryptojs/cryptojs-sha3.js" | ||
], | ||
dest: "libs/generated/crypto.js" | ||
}, | ||
forms_core: { | ||
"src": "src/appforms/src/core/*.js", | ||
"dest": "libs/generated/appForms/appForms-core.js" | ||
}, | ||
forms_backbone: { | ||
"src": ["src/appforms/src/backbone/*.js", "!src/appforms/src/backbone/000-closureStartRequireJS.js", "!src/appforms/src/backbone/999-closureEndRequireJS.js"], | ||
"dest": "libs/generated/appForms/appForms-backbone.js" | ||
}, | ||
forms_backboneRequireJS: { | ||
"src": ["src/appforms/src/backbone/*.js", "!src/appforms/src/backbone/000-closureStart.js", "!src/appforms/src/backbone/999-closureEnd.js"], | ||
"dest": "libs/generated/appForms/appForms-backboneRequireJS.js" | ||
}, | ||
forms_sdk :{ | ||
"src": ["dist/feedhenry.js", "libs/generated/appForms/appForms-core.js"], | ||
"dest": "dist/feedhenry-forms.js" | ||
} | ||
}, | ||
'mocha_phantomjs': { | ||
all: { | ||
options: { | ||
urls: [ | ||
"http://127.0.0.1:8200/test/browser/index.html", | ||
"http://127.0.0.1:8200/test/browser/index-require.html" | ||
] | ||
} | ||
} | ||
}, | ||
connect: { | ||
server: { | ||
options: { | ||
hostname: "*", | ||
port: 8200, | ||
base: '.' | ||
} | ||
} | ||
}, | ||
browserify: { | ||
// This browserify build be used by users of the module. It contains a | ||
// UMD (universal module definition) and can be used via an AMD module | ||
// loader like RequireJS or by simply placing a script tag in the page, | ||
// which registers feedhenry as a global var (the module itself registers as $fh as well). | ||
dist:{ | ||
//shim is defined inside package.json | ||
src:['src/feedhenry.js'], | ||
dest: 'dist/feedhenry.js', | ||
options: { | ||
standalone: 'feedhenry', | ||
transform: [function(file){ | ||
var data = ''; | ||
|
||
function write (buf) { data += buf } | ||
function end () { | ||
var t = data; | ||
if(file.indexOf("constants.js") >= 0){ | ||
t = data.replace("BUILD_VERSION", pkg.version); | ||
} | ||
this.queue(t); | ||
this.queue(null); | ||
} | ||
return through(write, end); | ||
}] | ||
} | ||
}, | ||
// This browserify build can be required by other browserify modules that | ||
// have been created with an --external parameter. | ||
require: { | ||
src:['src/feedhenry.js'], | ||
dest: 'test/browser/feedhenry-latest-require.js', | ||
options: { | ||
alias:['./src/feedhenry.js'] | ||
} | ||
}, | ||
// These are the browserified tests. We need to browserify the tests to be | ||
// able to run the mocha tests while writing the tests as clean, simple | ||
// CommonJS mocha tests (that is, without cross-platform boilerplate | ||
// code). This build will also include the testing libs chai, sinon and | ||
// sinon-chai but must not include the module under test. | ||
test: { | ||
src: [ './test/browser/suite.js' ], | ||
dest: './test/browser/browserified_tests.js', | ||
options: { | ||
external: [ './src/feedhenry.js' ], | ||
// Embed source map for tests | ||
debug: true | ||
} | ||
} | ||
}, | ||
watch: { | ||
browserify: { | ||
files: ['src/**/*.js', 'test/tests/*.js'], | ||
tasks: ['browserify'], | ||
options: { | ||
spawn: false | ||
} | ||
} | ||
}, | ||
uglify: { | ||
dist: { | ||
"files": { | ||
'dist/feedhenry.min.js': ['dist/feedhenry.js'], | ||
'dist/feedhenry-forms.min.js': ['dist/feedhenry-forms.js'] | ||
} | ||
} | ||
}, | ||
zip: { | ||
zipall: { | ||
router: function(filepath) { | ||
grunt.log.writeln(filepath); | ||
var filename = path.basename(filepath); | ||
return 'feedhenry-js-sdk/' + filename; | ||
}, | ||
dest: 'dist/fh-starter-project-latest.zip', | ||
src: ['src/index.html', 'src/fhconfig.json', 'dist/feedhenry.min.js'] | ||
} | ||
} | ||
}); | ||
|
||
grunt.loadNpmTasks('grunt-zip'); | ||
grunt.loadNpmTasks('grunt-contrib-qunit'); | ||
grunt.loadNpmTasks('grunt-contrib-jshint'); | ||
grunt.loadNpmTasks('grunt-contrib-concat'); | ||
grunt.loadNpmTasks('grunt-contrib-uglify'); | ||
grunt.loadNpmTasks('grunt-contrib-connect'); | ||
grunt.loadNpmTasks('grunt-browserify'); | ||
grunt.loadNpmTasks('grunt-mocha-phantomjs'); | ||
grunt.loadNpmTasks('grunt-contrib-watch'); | ||
|
||
var spawns = []; | ||
grunt.registerTask('start-local-servers', function () { | ||
var done = this.async(); | ||
var spawn = require('child_process').spawn; | ||
|
||
var spawnTestCloudServer = function (port, script, cb) { | ||
grunt.log.writeln('Spawning server on port ' + port + ' in cwd ' + __dirname + ' using file ' + __dirname + '/' + script); | ||
var env = {}; | ||
env.FH_PORT = port; | ||
var server = spawn('/usr/bin/env', ['node', __dirname + '/' + script], { | ||
cwd: __dirname, | ||
env: env | ||
}).on('exit', function (code) { | ||
grunt.log.writeln('Exiting server on port ' + port + ' with exit code ' + code); | ||
}); | ||
server.stdout.on('data', function (data) { | ||
grunt.log.writeln('Spawned Server port ' + port + ' stdout:' + data); | ||
if(data.toString("utf8").indexOf("started") !== -1){ | ||
cb(null, null); | ||
} | ||
}); | ||
server.stderr.on('data', function (data) { | ||
grunt.log.writeln('Spawned Server port ' + port + ' stderr:' + data); | ||
if(data.toString("utf8").indexOf("Error:") !== -1){ | ||
cb(data.toString("utf8"), null); | ||
} | ||
}); | ||
grunt.log.writeln('Spawned server on port ' + port); | ||
spawns.push(server); | ||
}; | ||
|
||
var servers = [{port: 8100, file:"bin/appinit.js"}, {port: 8101, file:"bin/appcloud.js"}]; | ||
async.map(servers, function(conf, cb){ | ||
spawnTestCloudServer(conf.port, conf.file, cb); | ||
}, function(err){ | ||
if(err) { | ||
grunt.log.writeln("Failed to start server. Error: " + err); | ||
return done(false); | ||
} | ||
return done(); | ||
}); | ||
|
||
}); | ||
|
||
var stopLocalServers = function(){ | ||
spawns.forEach(function (server) { | ||
grunt.log.writeln("Killing process " + server.pid); | ||
server.kill(); | ||
}); | ||
} | ||
|
||
process.on('exit', function() { | ||
console.log('killing spawned servers if there are any'); | ||
stopLocalServers(); | ||
}); | ||
|
||
grunt.registerTask('stop-local-servers', function(){ | ||
stopLocalServers(); | ||
}); | ||
|
||
//use this task for local development. Load example/index.html file in the browser after server started. | ||
//can run grunt watch as well in another terminal to auto generate the combined js file | ||
grunt.registerTask('local', ['start-local-servers', 'connect:server:keepalive']); | ||
|
||
//run tests in phatomjs | ||
grunt.registerTask('test', ['jshint', 'browserify', 'connect:server', 'mocha_phantomjs']); | ||
|
||
grunt.registerTask('concat-core-sdk', ['concat:lawnchair', 'concat:crypto', 'concat:forms_core', 'concat:forms_backbone', 'concat:forms_backboneRequireJS']); | ||
|
||
grunt.registerTask('default', 'jshint concat-core-sdk test concat:forms_sdk uglify:dist zip'); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
var nodeapp = require("fh-nodeapp"); | ||
|
||
console.log('Initing hostapp on port ' + process.env.FH_PORT); | ||
nodeapp.HostApp.init(); | ||
nodeapp.HostApp.serveApp({ | ||
echo: function(params, callback) { | ||
return callback(null, { | ||
echo: params.msg, | ||
echo: params.msg + '-' + process.env.FH_PORT, | ||
hardcoded: 'hardcodedmsg' | ||
}); | ||
} | ||
}); | ||
}); | ||
console.log('Inited hostapp on port ' + process.env.FH_PORT); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
var express = require("express"); | ||
|
||
var app = express(); | ||
|
||
var hosturl = "http://localhost:8101"; | ||
app.use(express.bodyParser()); | ||
app.use(app.router); | ||
|
||
var initData = { | ||
domain: "testing", | ||
firstTime: false, | ||
hosts: { | ||
"url": hosturl | ||
}, | ||
init: { | ||
"trackId": "testtrackid" | ||
} | ||
} | ||
|
||
/*app.all('*', function(req, res, next) { | ||
res.header("Access-Control-Allow-Origin", "*"); | ||
res.header("Access-Control-Allow-Headers", "X-Requested-With, X-Request-With, Content-Type"); | ||
next(); | ||
});*/ | ||
|
||
app.get("/box/:servlet/:version/app/init", function(req, res){ | ||
console.log("Got GET request for app init"); | ||
if(req.query._callback){ | ||
res.send(req.query._callback + "(" + JSON.stringify(initData) + ")"); | ||
} else { | ||
res.send("no callbackId"); | ||
} | ||
}); | ||
|
||
app.post("/box/:servlet/:version/app/init", function(req, res){ | ||
console.log("Got POST request for app init"); | ||
res.send(initData); | ||
}); | ||
|
||
app.listen(8100); | ||
console.log('Server started on port ' + 8100); |
Oops, something went wrong.