Skip to content

Commit

Permalink
App framework setup with coffee and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
eddiemoore committed Jan 17, 2014
1 parent 7cd934f commit 929ff76
Show file tree
Hide file tree
Showing 6 changed files with 229 additions and 93 deletions.
68 changes: 44 additions & 24 deletions app/index.js
Expand Up @@ -132,34 +132,47 @@ SmartTVGenerator.prototype.mainStylesheet = function mainStylesheet() {
var css;
if (this.noAppFramework) {
css = 'main.' + (this.includeCompass ? 's' : '') + 'css';
this.copy(css, 'app/stylesheets/' + css);
this.copy(css, 'src/stylesheets/' + css);
} else {
css = 'Main.' + (this.includeCompass ? 's' : '') + 'css';
this.template('af/app/stylesheets/' + css, 'app/stylesheets/' + css);
this.template('af/app/stylesheets/' + css, 'src/app/stylesheets/' + css);
}
};

SmartTVGenerator.prototype.mainJavaScript = function mainJavaScript() {
var js;
if (this.noAppFramework) {
js = 'scripts/main.' + (this.coffee ? 'coffee' : 'js');
this.copy(js, 'app/' + js);
this.copy(js, 'src/' + js);
} else {
js = 'Main.' + (this.coffee ? 'coffee' : 'js');
this.copy('af/app/scenes/' + js, 'app/scenes/' + js);
this.copy('af/app/scenes/' + js, 'src/app/scenes/' + js);
}
};

//Only for use with app framework
SmartTVGenerator.prototype.initFile = function initFile() {
if (!this.noAppFramework) {
this.copy('af/app/init.js', 'app/init.js');
var js = 'init.' + (this.coffee ? 'coffee' : 'js');
this.copy('af/app/' + js, 'src/app/' + js);
}
};

SmartTVGenerator.prototype.appJSON = function appJSON() {
if (!this.noAppFramework) {
this.copy('af/app.json', 'src/app.json');
}
};

SmartTVGenerator.prototype.widgetInfo = function widgetInfo() {
if (!this.noAppFramework) {
this.copy('af/widget.info', 'src/widget.info');
}
};

SmartTVGenerator.prototype.writeHtmls = function() {
if (!this.noAppFramework) {
this.copy('af/app/htmls/Main.html', 'app/htmls/Main.html');
this.copy('af/app/htmls/Main.html', 'src/app/htmls/Main.html');
}
};

Expand All @@ -175,8 +188,8 @@ SmartTVGenerator.prototype.writeIndex = function writeIndex() {

// wire Twitter Bootstrap plugins
if (this.includeBootstrap) {
var bs = 'bower_components/' + (this.includeCompass ? 'sass-' : '') + 'bootstrap/js/';
this.indexFile = this.appendScripts(this.indexFile, 'scripts/plugins.js', [
var bs = (this.noAppFramework ? '' : 'app/') + 'bower_components/' + (this.includeCompass ? 'sass-' : '') + 'bootstrap/js/';
this.indexFile = this.appendScripts(this.indexFile, 'app/vendor/plugins.js', [
bs + 'affix.js',
bs + 'alert.js',
bs + 'dropdown.js',
Expand All @@ -192,35 +205,42 @@ SmartTVGenerator.prototype.writeIndex = function writeIndex() {
]);
}

this.indexFile = this.appendFiles({
html: this.indexFile,
fileType: 'js',
optimizedPath: 'scripts/main.js',
sourceFileList: ['scripts/main.js'],
searchPath: '{app,.tmp}'
});
if (this.noAppFramework) {
this.indexFile = this.appendFiles({
html: this.indexFile,
fileType: 'js',
optimizedPath: 'scripts/main.js',
sourceFileList: ['scripts/main.js'],
searchPath: '{app,.tmp}'
});
}
};

SmartTVGenerator.prototype.writeConfigXML = function jshint() {
this.copy('config.xml', 'app/config.xml');
this.copy('config.xml', 'src/config.xml');
};

SmartTVGenerator.prototype.app = function app() {
this.mkdir('app');
this.mkdir('src');

if (this.noAppFramework) {
this.mkdir('app/scripts');
this.mkdir('src/scripts');
this.mkdir('src/stylesheets');
this.mkdir('src/images');
} else {
this.mkdir('app/scenes');
this.mkdir('app/htmls');
this.mkdir('src/app');
this.mkdir('src/app/scenes');
this.mkdir('src/app/htmls');
this.mkdir('src/app/stylesheets');
this.mkdir('src/app/images');
}
this.mkdir('app/stylesheets');
this.mkdir('app/images');
this.write('app/index.html', this.indexFile);
this.write('src/index.html', this.indexFile);
};

SmartTVGenerator.prototype.imageFiles = function () {
this.sourceRoot(path.join(__dirname, 'templates'));
this.directory('images', 'app/images', true);
var dir = this.noAppFramework ? 'src/' : 'src/app/'
this.directory('images', dir + 'images', true);
};

SmartTVGenerator.prototype.install = function () {
Expand Down
108 changes: 60 additions & 48 deletions app/templates/Gruntfile.js
Expand Up @@ -21,16 +21,20 @@ module.exports = function (grunt) {
// Project settings
yeoman: {
// Configurable paths
app: 'app',
app: 'src',
dist: 'dist'
},

// Watches files for changes and runs tasks based on the changed files
watch: {<% if (coffee) { %>
watch: {<% if (coffee) { if (noAppFramework) { %>
coffee: {
files: ['<%%= yeoman.app %>/scripts/{,*/}*.{coffee,litcoffee,coffee.md}'],
tasks: ['coffee:dist']
},
},<% } else { %>
coffee: {
files: ['<%%= yeoman.app %>/{,*/}*.{coffee,litcoffee,coffee.md}'],
tasks: ['coffee:dist']
},<% } %>
coffeeTest: {
files: ['test/spec/{,*/}*.{coffee,litcoffee,coffee.md}'],
tasks: ['coffee:test', 'test:watch']
Expand All @@ -48,24 +52,31 @@ module.exports = function (grunt) {
},<% } %>
gruntfile: {
files: ['Gruntfile.js']
},<% if (includeCompass) { %>
},<% if (includeCompass) { if (noAppFramework) { %>
compass: {
files: ['<%%= yeoman.app %>/styles/{,*/}*.{scss,sass}'],
files: ['<%%= yeoman.app %>/stylesheets/{,*/}*.{scss,sass}'],
tasks: ['compass:server', 'autoprefixer']
},<% } %>
},<% } else { %>
compass: {
files: ['<%%= yeoman.app %>/app/stylesheets/{,*/}*.{scss,sass}'],
tasks: ['compass:server', 'autoprefixer']
},<% }} %>
styles: {
files: ['<%%= yeoman.app %>/styles/{,*/}*.css'],
files: ['<%%= yeoman.app %>/stylesheets/{,*/}*.css'],
tasks: ['newer:copy:styles', 'autoprefixer']
},
livereload: {
options: {
livereload: '<%%= connect.options.livereload %>'
},
files: [
'<%%= yeoman.app %>/{,*/}*.html',
'.tmp/styles/{,*/}*.css',<% if (coffee) { %>
'<%%= yeoman.app %>/{,*/}*.html',<% if (noAppFramework) { %>
'.tmp/stylesheets/{,*/}*.css',<% if (coffee) { %>
'.tmp/scripts/{,*/}*.js',<% } %>
'<%%= yeoman.app %>/images/{,*/}*.{gif,jpeg,jpg,png,svg,webp}'
'<%%= yeoman.app %>/images/{,*/}*.{gif,jpeg,jpg,png,svg,webp}'<% } else { %>
'.tmp/app/stylesheets/{,*/}*.css',<% if (coffee) { %>
'.tmp/app/**/*.js',<% } %>
'<%%= yeoman.app %>/app/images/{,*/}*.{gif,jpeg,jpg,png,svg,webp}'<% } %>
]
}
},
Expand Down Expand Up @@ -128,9 +139,10 @@ module.exports = function (grunt) {
reporter: require('jshint-stylish')
},
all: [
'Gruntfile.js',
'Gruntfile.js',<% if (noAppFramework) { %>
'<%%= yeoman.app %>/scripts/{,*/}*.js',
'!<%%= yeoman.app %>/scripts/vendor/*',
'!<%%= yeoman.app %>/scripts/vendor/*',<% } else { %>
'<%%= yeoman.app %>/app/**/*.js',<% } %>
'test/spec/{,*/}*.js'
]
},
Expand Down Expand Up @@ -160,9 +172,9 @@ module.exports = function (grunt) {
dist: {
files: [{
expand: true,
cwd: '<%%= yeoman.app %>/scripts',
cwd: '<%%= yeoman.app %>/<% if (!noAppFramework) { %>app/<% } %>scripts',
src: '{,*/}*.{coffee,litcoffee,coffee.md}',
dest: '.tmp/scripts',
dest: '.tmp/<% if (!noAppFramework) { %>app/<% } else { %>scripts<% } %>',
ext: '.js'
}]
},
Expand All @@ -181,22 +193,22 @@ module.exports = function (grunt) {
// Compiles Sass to CSS and generates necessary files if requested
compass: {
options: {
sassDir: '<%%= yeoman.app %>/styles',
cssDir: '.tmp/styles',
generatedImagesDir: '.tmp/images/generated',
imagesDir: '<%%= yeoman.app %>/images',
javascriptsDir: '<%%= yeoman.app %>/scripts',
fontsDir: '<%%= yeoman.app %>/styles/fonts',
importPath: '<%%= yeoman.app %>/bower_components',
httpImagesPath: '/images',
httpGeneratedImagesPath: '/images/generated',
httpFontsPath: '/styles/fonts',
relativeAssets: false,
sassDir: '<%%= yeoman.app %>/<% if (!noAppFramework) { %>app/<% } %>stylesheets',
cssDir: '.tmp/<% if (!noAppFramework) { %>app/<% } %>stylesheets',
generatedImagesDir: '.tmp/<% if (!noAppFramework) { %>app/<% } %>images/generated',
imagesDir: '<%%= yeoman.app %>/<% if (!noAppFramework) { %>app/<% } %>images',
javascriptsDir: '<%%= yeoman.app %>/<% if (!noAppFramework) { %>app/<% } else { %>scripts<% } %>',
fontsDir: '<%%= yeoman.app %>/<% if (!noAppFramework) { %>app/<% } %>stylesheets/fonts',
importPath: '<%%= yeoman.app %>/<% if (!noAppFramework) { %>app/<% } %>bower_components',
httpImagesPath: '/<% if (!noAppFramework) { %>app/<% } %>images',
httpGeneratedImagesPath: '/<% if (!noAppFramework) { %>app/<% } %>images/generated',
httpFontsPath: '/<% if (!noAppFramework) { %>app/<% } %>stylesheets/fonts',
relativeAssets: true,
assetCacheBuster: false
},
dist: {
options: {
generatedImagesDir: '<%%= yeoman.dist %>/images/generated'
generatedImagesDir: '<%%= yeoman.dist %>/<% if (!noAppFramework) { %>app/<% } %>images/generated'
}
},
server: {
Expand All @@ -214,9 +226,9 @@ module.exports = function (grunt) {
dist: {
files: [{
expand: true,
cwd: '.tmp/styles/',
cwd: '.tmp/<% if (!noAppFramework) { %>app/<% } %>stylesheets/',
src: '{,*/}*.css',
dest: '.tmp/styles/'
dest: '.tmp/<% if (!noAppFramework) { %>app/<% } %>stylesheets/'
}]
}
},
Expand All @@ -233,11 +245,12 @@ module.exports = function (grunt) {
rev: {
dist: {
files: {
src: [
'<%%= yeoman.dist %>/scripts/{,*/}*.js',
'<%%= yeoman.dist %>/styles/{,*/}*.css',
'<%%= yeoman.dist %>/images/{,*/}*.{gif,jpeg,jpg,png,webp}',
'<%%= yeoman.dist %>/styles/fonts/{,*/}*.*'
src: [<% if (noAppFramework) { %>
'<%%= yeoman.dist %>/scripts/{,*/}*.js',<% } else { %>
'<%%= yeoman.dist %>/app/{,*/}.*.js',<% } %>
'<%%= yeoman.dist %>/<% if (!noAppFramework) { %>app/<% } %>stylesheets/{,*/}*.css',
'<%%= yeoman.dist %>/<% if (!noAppFramework) { %>app/<% } %>images/{,*/}*.{gif,jpeg,jpg,png,webp}',
'<%%= yeoman.dist %>/<% if (!noAppFramework) { %>app/<% } %>stylesheets/fonts/{,*/}*.*'
]
}
}
Expand All @@ -259,27 +272,27 @@ module.exports = function (grunt) {
assetsDirs: ['<%%= yeoman.dist %>']
},
html: ['<%%= yeoman.dist %>/{,*/}*.html'],
css: ['<%%= yeoman.dist %>/styles/{,*/}*.css']
css: ['<%%= yeoman.dist %>/<% if (!noAppFramework) { %>app/<% } %>stylesheets/{,*/}*.css']
},

// The following *-min tasks produce minified files in the dist folder
imagemin: {
dist: {
files: [{
expand: true,
cwd: '<%%= yeoman.app %>/images',
cwd: '<%%= yeoman.app %>/<% if (!noAppFramework) { %>app/<% } %>images',
src: '{,*/}*.{gif,jpeg,jpg,png}',
dest: '<%%= yeoman.dist %>/images'
dest: '<%%= yeoman.dist %>/<% if (!noAppFramework) { %>app/<% } %>images'
}]
}
},
svgmin: {
dist: {
files: [{
expand: true,
cwd: '<%%= yeoman.app %>/images',
cwd: '<%%= yeoman.app %>/<% if (!noAppFramework) { %>app/<% } %>images',
src: '{,*/}*.svg',
dest: '<%%= yeoman.dist %>/images'
dest: '<%%= yeoman.dist %>/<% if (!noAppFramework) { %>app/<% } %>images'
}]
}
},
Expand Down Expand Up @@ -310,9 +323,9 @@ module.exports = function (grunt) {
// cssmin: {
// dist: {
// files: {
// '<%%= yeoman.dist %>/styles/main.css': [
// '.tmp/styles/{,*/}*.css',
// '<%%= yeoman.app %>/styles/{,*/}*.css'
// '<%%= yeoman.dist %>/stylesheets/main.css': [
// '.tmp/stylesheets/{,*/}*.css',
// '<%%= yeoman.app %>/stylesheets/{,*/}*.css'
// ]
// }
// }
Expand Down Expand Up @@ -340,19 +353,18 @@ module.exports = function (grunt) {
dest: '<%%= yeoman.dist %>',
src: [
'*.{ico,png,txt}',
'.htaccess',
'images/{,*/}*.webp',
'<% if (!noAppFramework) { %>app/<% } %>images/{,*/}*.webp',
'{,*/}*.html',
'styles/fonts/{,*/}*.*'<% if (includeBootstrap) { %>,
'bower_components/' + (this.includeCompass ? 'sass-' : '') + 'bootstrap/' + (this.includeCompass ? 'fonts/' : 'dist/fonts/') +'*.*'<% } %>
'<% if (!noAppFramework) { %>app/<% } %>stylesheets/fonts/{,*/}*.*'<% if (includeBootstrap) { %>,
'<% if (!noAppFramework) { %>app/<% } %>bower_components/' + (this.includeCompass ? 'sass-' : '') + 'bootstrap/' + (this.includeCompass ? 'fonts/' : 'dist/fonts/') +'*.*'<% } %>
]
}]
},
styles: {
expand: true,
dot: true,
cwd: '<%%= yeoman.app %>/styles',
dest: '.tmp/styles/',
cwd: '<%%= yeoman.app %>/<% if (!noAppFramework) { %>app/<% } %>stylesheets',
dest: '.tmp/<% if (!noAppFramework) { %>app/<% } %>stylesheets/',
src: '{,*/}*.css'
}
},
Expand Down Expand Up @@ -438,4 +450,4 @@ module.exports = function (grunt) {
'test',
'build'
]);
};
};
10 changes: 10 additions & 0 deletions app/templates/af/app/init.coffee
@@ -0,0 +1,10 @@
onStart = ->
# TODO : Add your Initialize code here
# NOTE : In order to start your app, call "sf.start()" at the end of this function!!
sf.scene.show "Main"
sf.scene.focus "Main"

onDestroy = ->
#stop your XHR or Ajax operation and put codes to destroy your application here

alert "init.js loaded."
4 changes: 2 additions & 2 deletions app/templates/bowerrc
@@ -1,3 +1,3 @@
{
"directory": "app/bower_components"
}
"directory": "src/<% if (!noAppFramework) { %>app/<% } %>bower_components"
}
5 changes: 3 additions & 2 deletions package.json
@@ -1,13 +1,14 @@
{
"name": "generator-smarttv",
"version": "0.0.4",
"version": "0.0.5",
"description": "Scaffold out a Samsung SmartTV app",
"keywords": [
"yeoman-generator",
"samsung",
"smarttv",
"smart",
"tv"
"tv",
"television"
],
"homepage": "https://github.com/eddiemoore/generator-smarttv",
"bugs": "https://github.com/eddiemoore/generator-smarttv/issues",
Expand Down

0 comments on commit 929ff76

Please sign in to comment.