[Sweetspot]update Sweetspot(tizen_2.1)
[samples/web/Sweetspot.git] / Gruntfile.js
1 module.exports = function (grunt) {
2
3   grunt.loadNpmTasks('grunt-contrib-clean');
4   grunt.loadNpmTasks('grunt-contrib-uglify');
5   grunt.loadNpmTasks('grunt-contrib-copy');
6   grunt.loadNpmTasks('grunt-contrib-cssmin');
7   grunt.loadTasks('tools/grunt-tasks');
8
9   grunt.initConfig({
10     packageInfo: grunt.file.readJSON('package.json'),
11
12     clean: ['build'],
13
14     // minify and concat JS
15     uglify: {
16       dist: {
17         files: {
18           'build/app/js/main.js': ['app/js/main.js'],
19           'build/app/js/help.js': ['app/js/help.js'],
20           'build/app/js/license.js': ['app/js/license.js'],
21           'build/app/js/run.js': ['app/js/run.js']
22         }
23       }
24     },
25
26     // minify and concat CSS
27     cssmin: {
28       dist: {
29         files: {
30           'build/app/css/all.css': [
31             'app/css/main.css',
32             'app/css/license.css',
33             'app/css/help.css'
34           ]
35         }
36       }
37     },
38
39     // copy assets and the index.html file to build/app/;
40     // NB we rewrite index.html during copy to point at the
41     // minified/concated js file all.js and minified/concated CSS file
42     // all.css
43     copy: {
44       dist: {
45         files: [
46           { expand: true, cwd: '.', src: ['config.xml'], dest: 'build/app/' },
47           { expand: true, cwd: '.', src: ['icon*.png'], dest: 'build/app/' },
48           { expand: true, cwd: '.', src: ['README.txt'], dest: 'build/app/' },
49           { expand: true, cwd: '.', src: ['app/**.html'], dest: 'build/' },
50           { expand: true, cwd: '.', src: ['app/audio/**'], dest: 'build/' },
51           { expand: true, cwd: '.', src: ['app/fonts/**'], dest: 'build/' },
52           { expand: true, cwd: '.', src: ['app/images/**'], dest: 'build/' },
53           { expand: true, cwd: '.', src: ['app/lib/**'], dest: 'build/' },
54           { expand: true, cwd: '.', src: ['app/_locales/**'], dest: 'build/' }
55         ],
56         options: {
57           // this rewrites the <script> tag in the index.html file
58           // to point at the minified/concated js file all.js;
59           // and the stylesheet tags to point at all.css;
60           // it additionally strips out as much space and as many newlines
61           // as possible from HTML files (NB this may be dangerous if
62           // files are space-sensitive, but most HTML shouldn't be)
63           processContent: function (content) {
64             if (content.match(/DOCTYPE/)) {
65               // remove comments
66               content = content.replace(/.+\/\/.+?\n/g, '');
67               content = content.replace(/<!--[\s\S]+?-->/g, '');
68
69               // CSS
70               content = content.replace(/main\.css/, '!!!all.css!!!');
71               content = content.replace(/<link rel="stylesheet" href="[^\!]+?">\n/g, '');
72
73               // fix CSS resources
74               content = content.replace(/!!!/g, '');
75
76               // whitespace reduction
77               content = content.replace(/[ ]{2,}/g, ' ');
78               content = content.replace(/\n{2,}/g, '\n');
79             }
80
81             return content;
82           },
83
84           // if you have other resources which you don't want to have
85           // treated as text, add them here
86           processContentExclude: [
87             'app/images/**',
88             'app/audio/**',
89             'app/_locales/**',
90             'app/fonts/**',
91             'app/lib/**',
92             '*.png',
93             'README.txt'
94           ]
95         }
96       }
97     },
98
99     // make wgt package in build/ directory
100     package: {
101       appName: '<%= packageInfo.name %>',
102       version: '<%= packageInfo.version %>',
103       files: 'build/app/**',
104       stripPrefix: 'build/app/',
105       outDir: 'build',
106       suffix: '.wgt',
107       addGitCommitId: false
108     },
109
110     sdb: {
111       prepare: {
112         action: 'push',
113         localFiles: './tools/grunt-tasks/tizen-app.sh',
114         remoteDestDir: '/opt/home/developer/',
115         chmod: '+x',
116         overwrite: true
117       },
118
119       pushwgt: {
120         action: 'push',
121         localFiles: {
122           pattern: 'build/*.wgt',
123           filter: 'latest'
124         },
125         remoteDestDir: '/opt/home/developer/'
126       },
127
128       stop: {
129         action: 'stop',
130         remoteScript: '/opt/home/developer/tizen-app.sh'
131       },
132
133       uninstall: {
134         action: 'uninstall',
135         remoteScript: '/opt/home/developer/tizen-app.sh'
136       },
137
138       install: {
139         action: 'install',
140         remoteFiles: {
141           pattern: '/opt/home/developer/*.wgt',
142           filter: 'latest'
143         },
144         remoteScript: '/opt/home/developer/tizen-app.sh'
145       },
146
147       debug: {
148         action: 'debug',
149         remoteScript: '/opt/home/developer/tizen-app.sh',
150         localPort: '8888',
151         openBrowser: 'google-chrome %URL%'
152       },
153
154       start: {
155         action: 'start',
156         remoteScript: '/opt/home/developer/tizen-app.sh'
157       }
158     }
159   });
160
161   grunt.registerTask('dist', ['clean', 'cssmin:dist', 'uglify:dist', 'copy:dist']);
162
163   grunt.registerTask('pkg', 'Create package; call with pkg:STR to append STR to package name', function (identifier) {
164     grunt.task.run('dist');
165
166     var packageTask = (identifier ? 'package:' + identifier : 'package');
167     grunt.task.run(packageTask);
168   });
169
170   grunt.registerTask('reinstall', ['pkg', 'sdb:prepare', 'sdb:pushwgt', 'sdb:stop', 'sdb:uninstall', 'sdb:install', 'sdb:debug']);
171   grunt.registerTask('install', ['pkg', 'sdb:prepare', 'sdb:pushwgt', 'sdb:install', 'sdb:debug']);
172   grunt.registerTask('restart', ['sdb:stop', 'sdb:start']);
173   grunt.registerTask('default', 'dist');
174 };