kitematic/Gruntfile.js

338 строки
10 KiB
JavaScript
Исходник Обычный вид История

var path = require('path');
var fs = require('fs');
var execFile = require('child_process').execFile;
var packagejson = require('./package.json');
2015-06-10 03:56:08 +03:00
var electron = require('electron-prebuilt');
var WINDOWS_DOCKER_URL = 'https://get.docker.com/builds/Windows/x86_64/docker-1.6.2.exe';
var DARWIN_DOCKER_URL = 'https://get.docker.com/builds/Darwin/x86_64/docker-' + packagejson['docker-version'];
var WINDOWS_DOCKER_MACHINE_URL = 'https://github.com/docker/machine/releases/download/v' + packagejson['docker-machine-version'] + '/docker-machine_windows-amd64.exe';
var DARWIN_DOCKER_MACHINE_URL = 'https://github.com/docker/machine/releases/download/v' + packagejson['docker-machine-version'] + '/docker-machine_darwin-amd64';
var DARWIN_COMPOSE_URL = 'https://github.com/docker/compose/releases/download/' + packagejson['docker-compose-version'] + '/docker-compose-Darwin-x86_64';
var BOOT2DOCKER_ISO_URL = 'https://github.com/boot2docker/boot2docker/releases/download/v' + packagejson['docker-version'] + '/boot2docker.iso';
module.exports = function (grunt) {
require('load-grunt-tasks')(grunt);
2015-06-10 03:16:00 +03:00
var target = grunt.option('target') || 'development';
2015-06-10 09:17:49 +03:00
var beta = grunt.option('beta') || false;
2015-06-18 10:15:47 +03:00
var alpha = grunt.option('alpha') || false;
2015-06-10 03:16:00 +03:00
var env = process.env;
2015-06-12 09:32:13 +03:00
env.NODE_PATH = '..:' + env.NODE_PATH;
2015-06-10 03:16:00 +03:00
env.NODE_ENV = target;
2015-06-18 10:15:47 +03:00
var certificateFile = grunt.option('certificateFile');
var certificatePassword = grunt.option('certificatePassword');
var version = function (str) {
var match = str.match(/(\d+\.\d+\.\d+)/);
return match ? match[1] : null;
};
grunt.registerTask('download-boot2docker-iso', 'Downloads provided boot2docker version', function () {
var version = grunt.config('version');
try {
var data = fs.readFileSync(path);
var match = data.match(/Boot2Docker-v(\d+\.\d+\.\d+)/);
if (match && match[1] !== version) {
grunt.task.run('curl:boot2docker-iso');
}
} catch (err) {
grunt.task.run('curl:boot2docker-iso');
}
});
grunt.registerMultiTask('download-binary', 'Downloads binary unless version up to date', function () {
var target = grunt.task.current.target;
var done = this.async();
var config = grunt.config('download-binary')[target];
execFile(config.binary, ['--version'], function (err, stdout) {
var currentVersion = version(stdout);
2015-06-10 03:16:00 +03:00
if (!currentVersion || currentVersion !== version(config.version)) {
grunt.task.run('curl:' + target);
grunt.task.run('chmod');
}
done();
});
});
2015-06-18 10:15:47 +03:00
var BASENAME = 'Kitematic';
var APPNAME = BASENAME;
if (alpha) {
APPNAME += ' (Alpha)';
} else if (beta) {
APPNAME += ' (Beta)';
}
2015-06-10 09:17:49 +03:00
var OSX_OUT = './dist/osx';
var OSX_FILENAME = OSX_OUT + '/' + APPNAME + '.app';
grunt.initConfig({
2015-06-10 09:17:49 +03:00
IDENTITY: 'Developer ID Application: Docker Inc',
APPNAME: APPNAME,
OSX_OUT: OSX_OUT,
OSX_FILENAME: OSX_FILENAME,
OSX_FILENAME_ESCAPED: OSX_FILENAME.replace(' ', '\\ ').replace('(','\\(').replace(')','\\)'),
2015-06-10 08:27:27 +03:00
2015-06-10 03:16:00 +03:00
// electron
electron: {
windows: {
options: {
2015-06-18 21:38:34 +03:00
name: BASENAME,
2015-06-10 03:16:00 +03:00
dir: 'build/',
out: 'dist/',
version: packagejson['electron-version'],
platform: 'win32',
arch: 'x64',
2015-06-12 09:32:13 +03:00
asar: true,
icon: 'util/kitematic.ico'
2015-06-10 03:16:00 +03:00
}
2015-06-10 03:56:08 +03:00
},
osx: {
options: {
2015-06-18 10:15:47 +03:00
name: APPNAME,
2015-06-10 03:56:08 +03:00
dir: 'build/',
2015-06-10 08:27:27 +03:00
out: '<%= OSX_OUT %>',
2015-06-10 03:56:08 +03:00
version: packagejson['electron-version'],
platform: 'darwin',
arch: 'x64',
2015-06-10 07:54:11 +03:00
asar: true,
'app-bundle-id': 'com.kitematic.kitematic'
2015-06-10 03:56:08 +03:00
}
2015-06-10 03:16:00 +03:00
}
},
2015-06-16 08:06:47 +03:00
rcedit: {
exes: {
files: [{
expand: true,
2015-06-18 21:38:34 +03:00
cwd: 'dist/' + BASENAME + '-win32',
src: [BASENAME + '.exe']
2015-06-16 08:06:47 +03:00
}],
options: {
icon: 'util/kitematic.ico',
'file-version': packagejson.version,
'product-version': packagejson.version,
'version-string': {
2015-06-18 21:38:34 +03:00
'CompanyName': 'Docker Inc',
2015-06-16 08:06:47 +03:00
'ProductVersion': packagejson.version,
2015-06-18 10:15:47 +03:00
'ProductName': APPNAME,
'FileDescription': APPNAME,
2015-06-18 21:38:34 +03:00
'InternalName': BASENAME + '.exe',
'OriginalFilename': BASENAME + '.exe',
2015-06-16 08:06:47 +03:00
'LegalCopyright': 'Copyright 2015 Docker Inc. All rights reserved.'
}
}
}
},
2015-06-10 03:16:00 +03:00
'create-windows-installer': {
2015-06-18 21:38:34 +03:00
appDirectory: 'dist/' + BASENAME + '-win32/',
2015-06-12 09:32:13 +03:00
authors: 'Docker Inc.',
loadingGif: 'util/loading.gif',
2015-06-16 08:06:47 +03:00
setupIcon: 'util/kitematic.ico',
2015-06-18 10:15:47 +03:00
description: APPNAME,
title: APPNAME,
2015-06-18 21:38:34 +03:00
exe: BASENAME + '.exe',
version: packagejson.version,
2015-06-18 21:38:34 +03:00
signWithParams: '/f ' + certificateFile + ' /p ' + certificatePassword + ' /tr http://timestamp.comodoca.com/rfc3161'
2015-06-10 03:16:00 +03:00
},
2015-06-10 03:56:08 +03:00
// docker binaries
'download-binary': {
docker: {
version: packagejson['docker-version'],
binary: path.join('resources', 'docker'),
download: 'curl:docker'
},
'docker-machine': {
version: packagejson['docker-machine-version'],
binary: path.join('resources', 'docker-machine'),
download: 'curl:docker-machine'
}
},
// images
copy: {
2015-06-10 03:16:00 +03:00
dev: {
files: [{
expand: true,
cwd: '.',
2015-06-10 06:49:26 +03:00
src: ['package.json', 'settings.json', 'index.html'],
2015-06-10 03:16:00 +03:00
dest: 'build/'
}, {
expand: true,
cwd: 'images/',
src: ['**/*'],
dest: 'build/'
}, {
expand: true,
cwd: 'fonts/',
src: ['**/*'],
dest: 'build/'
}, {
cwd: 'node_modules/',
src: Object.keys(packagejson.dependencies).map(function (dep) { return dep + '/**/*';}),
dest: 'build/node_modules/',
expand: true
}]
},
2015-06-10 03:56:08 +03:00
windows: {
2015-06-10 03:16:00 +03:00
files: [{
expand: true,
cwd: 'resources',
2015-06-17 07:10:50 +03:00
src: ['docker*', 'boot2docker.iso', 'ssh.exe', 'OPENSSH_LICENSE', 'msys-*'],
2015-06-18 21:38:34 +03:00
dest: 'dist/' + BASENAME + '-win32/resources/resources/'
2015-06-10 06:35:46 +03:00
}],
options: {
mode: true
}
2015-06-10 03:56:08 +03:00
},
osx: {
files: [{
expand: true,
cwd: 'resources',
src: ['docker*', 'boot2docker.iso', 'macsudo', 'terminal'],
2015-06-10 08:27:27 +03:00
dest: '<%= OSX_FILENAME %>/Contents/Resources/resources/'
2015-06-10 07:54:11 +03:00
}, {
src: 'util/kitematic.icns',
2015-06-10 08:27:27 +03:00
dest: '<%= OSX_FILENAME %>/Contents/Resources/atom.icns'
2015-06-10 06:35:46 +03:00
}],
options: {
mode: true
}
}
},
2015-06-12 09:32:13 +03:00
rename: {
installer: {
src: 'installer/Setup.exe',
2015-06-18 10:15:47 +03:00
dest: 'installer/' + BASENAME + 'Setup-' + packagejson.version + '.exe'
2015-06-12 09:32:13 +03:00
}
},
// download binaries
curl: {
docker: {
src: process.platform === 'win32' ? WINDOWS_DOCKER_URL : DARWIN_DOCKER_URL,
dest: process.platform === 'win32' ? path.join('resources', 'docker.exe') : path.join('resources', 'docker')
},
'docker-machine': {
src: process.platform === 'win32' ? WINDOWS_DOCKER_MACHINE_URL : DARWIN_DOCKER_MACHINE_URL,
dest: process.platform === 'win32' ? path.join('resources', 'docker-machine.exe') : path.join('resources', 'docker-machine')
},
'docker-compose': {
src: DARWIN_COMPOSE_URL,
dest: 'resources/docker-compose'
},
'boot2docker-iso': {
src: BOOT2DOCKER_ISO_URL,
dest: path.join('resources', 'boot2docker.iso')
}
},
chmod: {
binaries: {
options: {
mode: '755'
},
src: ['resources/docker*']
}
},
// styles
less: {
options: {
sourceMapFileInline: true
},
2015-06-10 03:16:00 +03:00
dist: {
files: {
'build/main.css': 'styles/main.less'
}
}
},
// javascript
babel: {
options: {
sourceMap: 'inline',
blacklist: 'regenerator'
},
dist: {
files: [{
expand: true,
cwd: 'src/',
src: ['**/*.js'],
dest: 'build/',
}]
}
},
2015-06-10 03:16:00 +03:00
shell: {
electron: {
2015-06-10 03:56:08 +03:00
command: electron + ' ' + 'build',
2015-06-10 03:16:00 +03:00
options: {
async: true,
execOptions: {
env: env
}
}
2015-06-10 08:27:27 +03:00
},
sign: {
options: {
failOnError: false,
},
command: [
2015-06-10 09:17:49 +03:00
'codesign --deep -v -f -s "<%= IDENTITY %>" <%= OSX_FILENAME_ESCAPED %>/Contents/Frameworks/*',
'codesign -v -f -s "<%= IDENTITY %>" <%= OSX_FILENAME_ESCAPED %>',
'codesign -vvv --display <%= OSX_FILENAME_ESCAPED %>',
'codesign -v --verify <%= OSX_FILENAME_ESCAPED %>',
2015-06-10 08:27:27 +03:00
].join(' && '),
2015-06-10 09:17:49 +03:00
},
zip: {
2015-06-18 10:15:47 +03:00
command: 'ditto -c -k --sequesterRsrc --keepParent <%= OSX_FILENAME_ESCAPED %> <%= OSX_OUT %>/' + BASENAME + '-' + packagejson.version + '.zip',
2015-06-10 03:16:00 +03:00
}
},
clean: {
2015-06-12 09:32:13 +03:00
release: ['build/', 'dist/', 'installer/'],
isos: ['resources/boot2docker*']
2015-06-10 03:16:00 +03:00
},
// livereload
2015-06-10 03:16:00 +03:00
watchChokidar: {
options: {
2015-06-12 09:32:13 +03:00
spawn: true
},
2015-06-10 03:16:00 +03:00
livereload: {
options: {livereload: true},
files: ['build/**/*']
},
js: {
files: ['src/**/*.js'],
2015-06-12 09:32:13 +03:00
tasks: ['newer:babel']
},
less: {
files: ['styles/**/*.less'],
2015-06-16 20:07:56 +03:00
tasks: ['less']
},
copy: {
files: ['images/*', 'index.html', 'fonts/*'],
2015-06-12 09:32:13 +03:00
tasks: ['newer:copy:dev']
}
}
});
grunt.registerTask('default', ['download-binary', 'if-missing:curl:boot2docker-iso', 'newer:babel', 'less', 'newer:copy:dev', 'shell:electron', 'watchChokidar']);
2015-06-10 06:35:46 +03:00
if (process.platform === 'win32') {
grunt.registerTask('release', ['clean', 'download-binary', 'if-missing:curl:boot2docker-iso', 'babel', 'less', 'copy:dev', 'electron:windows', 'copy:windows', 'rcedit:exes', 'create-windows-installer', 'rename:installer']);
2015-06-10 06:35:46 +03:00
} else {
grunt.registerTask('release', ['clean', 'download-binary', 'if-missing:curl:boot2docker-iso', 'babel', 'less', 'copy:dev', 'electron:osx', 'copy:osx', 'shell:sign', 'shell:zip']);
2015-06-10 06:35:46 +03:00
}
process.on('SIGINT', function () {
grunt.task.run(['shell:electron:kill']);
process.exit(1);
});
};