2015-10-17 23:49:24 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var fs = require('fs'),
|
|
|
|
path = require('path');
|
|
|
|
|
2015-10-21 23:02:17 +02:00
|
|
|
var StringReplacePlugin = require('string-replace-webpack-plugin');
|
2015-10-17 23:49:24 +02:00
|
|
|
|
|
|
|
module.exports = function(grunt) {
|
|
|
|
require('time-grunt')(grunt);
|
|
|
|
require('load-grunt-tasks')(grunt);
|
2015-11-07 08:55:45 +01:00
|
|
|
grunt.loadTasks('grunt/tasks');
|
2015-10-17 23:49:24 +02:00
|
|
|
|
|
|
|
var webpack = require('webpack');
|
2015-10-22 20:03:44 +02:00
|
|
|
var pkg = require('./package.json');
|
|
|
|
var dt = new Date().toISOString().replace(/T.*/, '');
|
2015-11-07 08:55:45 +01:00
|
|
|
var electronVersion = '0.34.0';
|
2015-10-17 23:49:24 +02:00
|
|
|
|
|
|
|
function replaceFont(css) {
|
|
|
|
css.walkAtRules('font-face', function (rule) {
|
|
|
|
var fontFamily = rule.nodes.filter(function(n) { return n.prop === 'font-family'; })[0];
|
|
|
|
if (!fontFamily) {
|
|
|
|
throw 'Bad font rule: ' + rule.toString();
|
|
|
|
}
|
|
|
|
var value = fontFamily.value.replace(/["']/g, '');
|
|
|
|
var fontFiles = {
|
|
|
|
FontAwesome: 'fontawesome-webfont.woff'
|
|
|
|
};
|
|
|
|
var fontFile = fontFiles[value];
|
|
|
|
if (!fontFile) {
|
|
|
|
throw 'Unsupported font ' + value + ': ' + rule.toString();
|
|
|
|
}
|
|
|
|
var data = fs.readFileSync('tmp/fonts/' + fontFile, 'base64');
|
|
|
|
var src = 'url(data:application/font-woff;charset=utf-8;base64,{data}) format(\'woff\')'
|
|
|
|
.replace('{data}', data);
|
|
|
|
//var src = 'url(\'../fonts/fontawesome-webfont.woff\') format(\'woff\')';
|
|
|
|
rule.nodes = rule.nodes.filter(function(n) { return n.prop !== 'src'; });
|
|
|
|
rule.append({ prop: 'src', value: src });
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
grunt.initConfig({
|
2015-11-07 08:55:45 +01:00
|
|
|
gitinfo: {
|
|
|
|
branch: {
|
|
|
|
current: {
|
|
|
|
SHA: 'Current HEAD SHA',
|
|
|
|
shortSHA: 'Current HEAD short SHA',
|
|
|
|
name: 'Current branch name',
|
|
|
|
lastCommitTime: 'Last commit time'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2015-10-17 23:49:24 +02:00
|
|
|
'bower-install-simple': {
|
|
|
|
install: {
|
|
|
|
}
|
|
|
|
},
|
|
|
|
clean: {
|
2015-11-07 08:55:45 +01:00
|
|
|
dist: ['dist', 'tmp'],
|
|
|
|
desktop_dist: ['dist/desktop'],
|
|
|
|
desktop_tmp: ['tmp/desktop']
|
2015-10-17 23:49:24 +02:00
|
|
|
},
|
|
|
|
copy: {
|
|
|
|
html: {
|
|
|
|
src: 'app/index.html',
|
|
|
|
dest: 'tmp/index.html',
|
|
|
|
nonull: true
|
|
|
|
},
|
|
|
|
favicon: {
|
|
|
|
src: 'app/favicon.png',
|
|
|
|
dest: 'tmp/favicon.png',
|
|
|
|
nonull: true
|
|
|
|
},
|
|
|
|
fonts: {
|
|
|
|
src: 'bower_components/font-awesome/fonts/fontawesome-webfont.*',
|
|
|
|
dest: 'tmp/fonts/',
|
|
|
|
nonull: true,
|
|
|
|
expand: true,
|
|
|
|
flatten: true
|
2015-11-07 08:55:45 +01:00
|
|
|
},
|
|
|
|
'desktop_osx': {
|
|
|
|
src: 'tmp/desktop/KeeWeb.dmg',
|
|
|
|
dest: 'dist/desktop/KeeWeb.mac.dmg',
|
|
|
|
nonull: true
|
|
|
|
},
|
|
|
|
'desktop_win': {
|
|
|
|
src: 'tmp/desktop/KeeWeb Setup.exe',
|
|
|
|
dest: 'dist/desktop/KeeWeb.win32.exe',
|
|
|
|
nonull: true
|
|
|
|
},
|
|
|
|
'desktop_linux': {
|
|
|
|
src: 'tmp/desktop/KeeWeb.linux.x64.zip',
|
|
|
|
dest: 'dist/desktop/KeeWeb.linux.x64.zip',
|
|
|
|
nonull: true
|
2015-10-17 23:49:24 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
jshint: {
|
|
|
|
options: {
|
|
|
|
jshintrc: true
|
|
|
|
},
|
|
|
|
all: ['app/scripts/**/*.js']
|
|
|
|
},
|
|
|
|
sass: {
|
|
|
|
options: {
|
|
|
|
sourceMap: false,
|
|
|
|
includePaths: ['./bower_components']
|
|
|
|
},
|
|
|
|
dist: {
|
|
|
|
files: {
|
|
|
|
'tmp/css/main.css': 'app/styles/main.scss'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
postcss: {
|
|
|
|
options: {
|
|
|
|
processors: [
|
|
|
|
replaceFont,
|
|
|
|
require('cssnano')({discardComments: {removeAll: true}})
|
|
|
|
]
|
|
|
|
},
|
|
|
|
dist: {
|
|
|
|
src: 'tmp/css/main.css',
|
|
|
|
dest: 'tmp/css/main.css'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
inline: {
|
|
|
|
app: {
|
|
|
|
src: 'tmp/index.html',
|
|
|
|
dest: 'tmp/app.html'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
htmlmin: {
|
|
|
|
options: {
|
|
|
|
removeComments: true,
|
|
|
|
collapseWhitespace: true
|
|
|
|
},
|
|
|
|
app: {
|
|
|
|
files: {
|
2015-10-17 23:53:17 +02:00
|
|
|
'dist/index.html': 'tmp/app.html'
|
2015-10-17 23:49:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2015-10-21 23:02:17 +02:00
|
|
|
'string-replace': {
|
|
|
|
manifest: {
|
|
|
|
options: {
|
|
|
|
replacements: [{
|
|
|
|
pattern: '# YYYY-MM-DD:v0.0.0',
|
2015-11-07 08:55:45 +01:00
|
|
|
replacement: '# ' + dt + ':v' + pkg.version
|
2015-10-21 23:02:17 +02:00
|
|
|
}]
|
|
|
|
},
|
|
|
|
files: { 'dist/manifest.appcache': 'app/manifest.appcache' }
|
|
|
|
}
|
|
|
|
},
|
2015-10-17 23:49:24 +02:00
|
|
|
webpack: {
|
|
|
|
js: {
|
|
|
|
entry: {
|
|
|
|
app: 'app',
|
|
|
|
vendor: ['zepto', 'jquery', 'underscore', 'backbone', 'kdbxweb', 'baron', 'dropbox', 'pikaday', 'filesaver']
|
|
|
|
},
|
|
|
|
output: {
|
|
|
|
path: 'tmp/js',
|
|
|
|
filename: 'app.js'
|
|
|
|
},
|
|
|
|
stats: {
|
|
|
|
colors: false,
|
|
|
|
modules: true,
|
|
|
|
reasons: true
|
|
|
|
},
|
|
|
|
progress: false,
|
|
|
|
failOnError: true,
|
|
|
|
resolve: {
|
|
|
|
root: [path.join(__dirname, 'app/scripts'), path.join(__dirname, 'bower_components')],
|
|
|
|
alias: {
|
|
|
|
backbone: 'backbone/backbone-min.js',
|
|
|
|
underscore: 'underscore/underscore-min.js',
|
|
|
|
_: 'underscore/underscore-min.js',
|
|
|
|
zepto: 'zepto/zepto.min.js',
|
|
|
|
jquery: 'zepto/zepto.min.js',
|
|
|
|
kdbxweb: 'kdbxweb/dist/kdbxweb.js',
|
|
|
|
dropbox: 'dropbox/lib/dropbox.min.js',
|
|
|
|
baron: 'baron/baron.min.js',
|
|
|
|
pikaday: 'pikaday/pikaday.js',
|
|
|
|
filesaver: 'FileSaver.js/FileSaver.min.js',
|
|
|
|
templates: path.join(__dirname, 'app/templates')
|
|
|
|
}
|
|
|
|
},
|
|
|
|
module: {
|
|
|
|
loaders: [
|
|
|
|
{ test: /\.html$/, loader: StringReplacePlugin.replace('ejs', { replacements: [{
|
|
|
|
pattern: /\r?\n\s*/g,
|
|
|
|
replacement: function() { return '\n'; }
|
|
|
|
}]})},
|
2015-10-22 20:03:44 +02:00
|
|
|
{ test: /runtime\-info\.js$/, loader: StringReplacePlugin.replace({ replacements: [
|
|
|
|
{ pattern: /@@VERSION/g, replacement: function() { return pkg.version; } },
|
|
|
|
{ pattern: /@@DATE/g, replacement: function() { return dt; } }
|
|
|
|
]})},
|
2015-10-17 23:49:24 +02:00
|
|
|
{ test: /zepto(\.min)?\.js$/, loader: 'exports?Zepto; delete window.$; delete window.Zepto;' },
|
|
|
|
{ test: /baron(\.min)?\.js$/, loader: 'exports?baron; delete window.baron;' },
|
|
|
|
{ test: /pikadat\.js$/, loader: 'uglify' }
|
|
|
|
]
|
|
|
|
},
|
|
|
|
plugins: [
|
|
|
|
new webpack.optimize.CommonsChunkPlugin('vendor', 'vendor.js'),
|
2015-10-18 11:08:55 +02:00
|
|
|
new webpack.BannerPlugin('keeweb v' + pkg.version + ', (c) 2015 ' + pkg.author +
|
2015-10-17 23:49:24 +02:00
|
|
|
', opensource.org/licenses/' + pkg.license),
|
|
|
|
new webpack.optimize.OccurenceOrderPlugin(),
|
|
|
|
new webpack.ProvidePlugin({ _: 'underscore', $: 'jquery' }),
|
|
|
|
new webpack.IgnorePlugin(/^(moment)$/),
|
|
|
|
new StringReplacePlugin()
|
|
|
|
],
|
|
|
|
node: {
|
|
|
|
console: false,
|
|
|
|
process: false,
|
|
|
|
Buffer: false,
|
|
|
|
__filename: false,
|
|
|
|
__dirname: false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
uglify: {
|
|
|
|
options: {
|
|
|
|
preserveComments: false
|
|
|
|
},
|
|
|
|
app: {
|
|
|
|
files: { 'tmp/js/app.js': ['tmp/js/app.js'] }
|
|
|
|
},
|
|
|
|
vendor: {
|
|
|
|
options: {
|
|
|
|
mangle: false,
|
|
|
|
compress: false
|
|
|
|
},
|
|
|
|
files: { 'tmp/js/vendor.js': ['tmp/js/vendor.js'] }
|
|
|
|
}
|
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
options: {
|
|
|
|
interrupt: true,
|
|
|
|
debounceDelay: 500
|
|
|
|
},
|
|
|
|
scripts: {
|
|
|
|
files: ['app/scripts/**/*.js', 'app/templates/**/*.html'],
|
|
|
|
tasks: ['webpack']
|
|
|
|
},
|
|
|
|
styles: {
|
|
|
|
files: 'app/styles/**/*.scss',
|
|
|
|
tasks: ['sass']
|
|
|
|
},
|
|
|
|
indexhtml: {
|
|
|
|
files: 'app/index.html',
|
|
|
|
tasks: ['copy:html']
|
|
|
|
}
|
2015-11-07 08:55:45 +01:00
|
|
|
},
|
|
|
|
electron: {
|
|
|
|
options: {
|
|
|
|
name: 'KeeWeb',
|
|
|
|
dir: 'electron',
|
|
|
|
out: 'tmp/desktop',
|
|
|
|
version: electronVersion,
|
|
|
|
overwrite: true,
|
|
|
|
'app-version': pkg.version,
|
|
|
|
'build-version': '<%= gitinfo.local.branch.current.shortSHA %>'
|
|
|
|
},
|
|
|
|
osx: {
|
|
|
|
options: {
|
|
|
|
platform: 'darwin',
|
|
|
|
arch: 'x64',
|
|
|
|
icon: 'graphics/app.icns'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
linux: {
|
|
|
|
options: {
|
|
|
|
platform: 'linux',
|
|
|
|
arch: 'x64',
|
|
|
|
icon: 'graphics/app.ico'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
win32: {
|
|
|
|
options: {
|
|
|
|
platform: 'win32',
|
|
|
|
arch: 'ia32',
|
|
|
|
icon: 'graphics/app.ico',
|
|
|
|
'version-string': {
|
|
|
|
CompanyName: 'antelle.github.io',
|
|
|
|
LegalCopyright: 'Antelle, MIT license',
|
|
|
|
FileDescription: 'KeeWeb Desktop',
|
|
|
|
OriginalFilename: 'KeeWeb.exe',
|
|
|
|
FileVersion: pkg.version,
|
|
|
|
ProductVersion: pkg.version,
|
|
|
|
ProductName: 'KeeWeb',
|
|
|
|
InternalName: 'KeeWeb'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
'electron_builder': {
|
|
|
|
options: {
|
|
|
|
out: path.join(__dirname, 'tmp/desktop'),
|
|
|
|
basePath: __dirname,
|
|
|
|
config: {
|
|
|
|
osx: {
|
|
|
|
title: 'KeeWeb',
|
|
|
|
background: path.join(__dirname, 'graphics/dmg-bg.png'),
|
|
|
|
icon: path.join(__dirname, 'graphics/app.icns'),
|
|
|
|
'icon-size': 80,
|
|
|
|
contents: [
|
|
|
|
{'x': 438, 'y': 344, 'type': 'link', 'path': '/Applications'},
|
|
|
|
{'x': 192, 'y': 344, 'type': 'file'}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
win: {
|
|
|
|
title: 'KeeWeb',
|
|
|
|
icon: path.join(__dirname, 'graphics/app.ico')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
osx: {
|
|
|
|
options: {
|
|
|
|
platform: 'osx',
|
2015-11-07 09:31:35 +01:00
|
|
|
appPath: path.join(__dirname, 'tmp/desktop/KeeWeb-darwin-x64/KeeWeb.app')
|
2015-11-07 08:55:45 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
win: {
|
|
|
|
options: {
|
|
|
|
platform: 'win32',
|
|
|
|
appPath: path.join(__dirname, 'tmp/desktop/KeeWeb-win32-ia32')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
compress: {
|
|
|
|
linux: {
|
|
|
|
options: {
|
|
|
|
archive: 'tmp/desktop/KeeWeb.linux.x64.zip'
|
|
|
|
},
|
|
|
|
files: [{ cwd: 'tmp/desktop/KeeWeb-linux-x64', src: '**', expand: true }]
|
|
|
|
}
|
2015-10-17 23:49:24 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
grunt.registerTask('default', [
|
|
|
|
'bower-install-simple',
|
|
|
|
'clean',
|
|
|
|
'jshint',
|
|
|
|
'copy:html',
|
|
|
|
'copy:favicon',
|
|
|
|
'copy:fonts',
|
|
|
|
'webpack',
|
|
|
|
'uglify',
|
|
|
|
'sass',
|
|
|
|
'postcss',
|
|
|
|
'inline',
|
2015-10-21 23:02:17 +02:00
|
|
|
'htmlmin',
|
|
|
|
'string-replace'
|
2015-10-17 23:49:24 +02:00
|
|
|
]);
|
2015-11-07 08:55:45 +01:00
|
|
|
|
|
|
|
grunt.registerTask('desktop', [
|
|
|
|
'gitinfo',
|
|
|
|
'clean:desktop_tmp',
|
|
|
|
'clean:desktop_dist',
|
|
|
|
'electron',
|
|
|
|
'electron_builder',
|
|
|
|
'compress:linux',
|
|
|
|
'copy:desktop_osx',
|
|
|
|
'copy:desktop_win',
|
|
|
|
'copy:desktop_linux',
|
|
|
|
'clean:desktop_tmp'
|
|
|
|
]);
|
2015-10-17 23:49:24 +02:00
|
|
|
};
|