Skip to content

Commit

Permalink
all code refactored, modular, can be user by cli or as node package
Browse files Browse the repository at this point in the history
  • Loading branch information
raphaelluchini committed Oct 29, 2014
1 parent 5552b30 commit 05451cb
Show file tree
Hide file tree
Showing 10 changed files with 151 additions and 254 deletions.
27 changes: 14 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
<h1>samsung smart tv packager (2013)</h1>
by james b. pollack<br>
#Samsung SmartTv Packager (2013)

This script will let you package a folder containing a html5 app and a run a webserver, without touching the samsung SDK.

this script will let you package a folder containing a html5 app without touching the samsung SDK.
##Getting Started

TO USE --
``npm install``

first <code>cd</code> into the folder containting this repo and:
Runing as a Cli
===
``sudo node cli folderToArchive``

<code>npm install </code>
Runing as a node package
===
```
var samsungPackager = module('samsungstv-packager');
samsungPackager.run('your/app/folder');
```

then:

<code>sudo node samsungpackager.js folderToArchive APPID APPTITLE SERVERIP logFolderToDelete</code><br>
---> i.e: <code>node samsungpackager.js ../src GTV GTV 192.168.0.25 ../src/logs</code><br><br>
*the logFolderToDelete parameter is optional<br>
*all paths relative to samsungpackager.js

the app will be served at localhost:80, just boot up your TV, point it at the correct IP address and sync your app.
The app will be served at localhost:80, just boot up your TV, point it at the correct IP address and sync your app.
11 changes: 11 additions & 0 deletions cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
var samsung = require('./index');

/**
1 = Folder to be package
2 = Folder that the server will run (Optional) Default:./pakages
3 = App ID (Optional)
4 = App Tile (Optional)
5 = Port that the server will run (Optional) Default:80
**/

samsung.run(process.argv[1], process.argv[2], process.argv[3], process.argv[4], process.argv[5]);
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('./lib/samsungpackager');
109 changes: 109 additions & 0 deletions lib/samsungpackager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
var mv = require('mv');
var fs = require('fs-extra');
var os = require('os');
var express = require("express");
var zip = require("adm-zip");

var builder = require('xmlbuilder');
var stringlib = require('string');

var childProcess = require('child_process');

var myZip = new zip();

var getNetworkIp = function(){
var ifaces = os.networkInterfaces();
var out = null;
ifaces.en0.forEach(function(details){
if (details.family=='IPv4') {
out = details.address;
}
});
return out;
};

var deleteFolders = function(serverFolder) {
console.log('Clean folders');
fs.removeSync(serverFolder);
};

var makeZip = function(serverFolder, folderToArchive, callback){
if(!folderToArchive){
throw Error('Missing folder path to archive');
}
console.log('Creating zip file');
var zipName = 'samsungpackage.zip';
myZip.addLocalFolder(folderToArchive);
myZip.writeZip('samsungpackage.zip');
fs.move('samsungpackage.zip', serverFolder + '/Widget/samsungpackage.zip', function(err){
if (err) return console.error(err);
if(typeof callback === 'function') callback();
fs.chmod(serverFolder, 0777); //Prevent sudo permissions to delete the folder
});
};

var createXML = function(serverFolder, appId, appTitle, callback){
var xmlFileName = "widgetlist.xml";
var doc = builder.create();
doc.begin('root')
.ele('?xml')
.att('version', '1.0').att('encoding','UTF-8')
.up()
.ele('rsp').att('stat','ok')
.ele('list')
.ele('widget').att('id',appId)
.ele('title').txt(appTitle)
.up()
.ele('compression').att('size','12345').att('type','zip')
.up()
.ele('description').txt('My Samsung Application -- Description')
.up()
.ele('download','http://' + getNetworkIp() + '/Widget/samsungpackage.zip');

var x = doc.toString();
x = stringlib(x).stripTags('root');

fs.writeFile(xmlFileName, x.s, function(err) {
if(err) return console.log(err);
console.log("The file was saved!");
fs.move('widgetlist.xml', serverFolder + '/widgetlist.xml',function(err){
if(err) return console.log(err);
console.log(doc.toString({ pretty: true }));
if(typeof callback === 'function') callback();
});
});


};

var startServer = function(serverFolder, port){
var app = express();

app.all('*', function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "X-Requested-With");
next();
});


app.use(express.static(serverFolder));
app.listen(port);

console.log('Please go to http://' + getNetworkIp() + ' to test your popcorntime server.');
};


exports.run = function(folderToArchive, serverFolder, appID, appTitle, port){
var _folderToArchive = folderToArchive,
_serverFolder = serverFolder || 'packages',
_appID = appID || 'app',
_appTitle = appTitle || 'Custom App',
_port = port || 80;

deleteFolders(_serverFolder);
makeZip(_serverFolder, _folderToArchive, function(){
createXML(_serverFolder, _appID, _appTitle, function(){
startServer(_serverFolder, _port);
});
});
};
21 changes: 13 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
{
"name": "Samsung-SmartTV-Packager",
"version":"0.0.1",
"name": "samsungstv-packager",
"version": "0.0.1",
"description": "Helps you package HTML5 Apps for Samsung Smart TV without touching their SDK.",
"author": "James Pollack <[email protected]>",
"dependencies": {
"author": "Raphael Luchini",
"dependencies": {},
"engine": "node >= 0.8.0",
"devDependencies": {
"adm-zip": "^0.4.4",
"express": "^4.10.0",
"fs-extra": "^0.12.0",
"mv": "0.0.5",
"string": "1.3.0",
"rimraf": "^2.2.8",
"string": "^1.3.0",
"xmlbuilder": "0.4.2"
},
"engine": "node >= 0.8.0"
}
}
}
55 changes: 0 additions & 55 deletions requesthandlers.js

This file was deleted.

15 changes: 0 additions & 15 deletions route.js

This file was deleted.

Loading

0 comments on commit 05451cb

Please sign in to comment.