From 140ae4671bb23b98a9ee430c6e0dc2d27771a842 Mon Sep 17 00:00:00 2001 From: Jeffrey Morgan Date: Tue, 9 Jun 2015 17:16:00 -0700 Subject: [PATCH] Installer & dist for windows --- .gitignore | 1 + Gruntfile.js | 101 ++++++++++++++++++++++++++++++++++++---------- package.json | 22 +++------- src/browser.js | 45 +++++++++++++++++++-- src/utils/Util.js | 2 +- 5 files changed, 130 insertions(+), 41 deletions(-) diff --git a/.gitignore b/.gitignore index e51ebc5468..8fe91862fb 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ .swp build dist +installer node_modules coverage npm-debug.log diff --git a/Gruntfile.js b/Gruntfile.js index f52f310a8b..a990ace9f6 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -11,7 +11,9 @@ var BOOT2DOCKER_ISO_URL = 'https://github.com/boot2docker/boot2docker/releases/d module.exports = function (grunt) { require('load-grunt-tasks')(grunt); - // var target = grunt.option('target') || 'development'; + var target = grunt.option('target') || 'development'; + var env = process.env; + env.NODE_ENV = target; var version = function (str) { var match = str.match(/(\d+\.\d+\.\d+)/); @@ -24,7 +26,7 @@ module.exports = function (grunt) { var config = grunt.config('download-binary')[target]; execFile(config.binary, ['--version'], function (err, stdout) { var currentVersion = version(stdout); - if (!currentVersion || currentVersion !== config.version) { + if (!currentVersion || currentVersion !== version(config.version)) { grunt.task.run('curl:' + target); grunt.task.run('chmod'); } @@ -32,7 +34,6 @@ module.exports = function (grunt) { }); }); - grunt.initConfig({ // electron 'download-electron': { @@ -54,19 +55,59 @@ module.exports = function (grunt) { } }, + // electron + electron: { + windows: { + options: { + name: 'Kitematic', + dir: 'build/', + out: 'dist/', + version: packagejson['electron-version'], + platform: 'win32', + arch: 'x64', + asar: true + } + } + }, + + 'create-windows-installer': { + appDirectory: 'dist/Kitematic-win32/', + outputDirectory: 'installer/', + authors: 'Docker Inc.' + }, + // images copy: { - images: { - src: 'images/*', - dest: 'build/' + dev: { + files: [{ + expand: true, + cwd: '.', + src: ['package.json', 'index.html'], + 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 + }] }, - html: { - src: 'index.html', - dest: 'build/' - }, - fonts: { - src: 'fonts/*', - dest: 'build/' + release: { + files: [{ + expand: true, + cwd: 'resources', + src: ['**/*'], + dest: 'dist/Kitematic-win32/resources/resources/' + }] } }, @@ -104,8 +145,10 @@ module.exports = function (grunt) { options: { sourceMapFileInline: true }, - files: { - 'build/main.css': 'styles/main.less' + dist: { + files: { + 'build/main.css': 'styles/main.less' + } } }, @@ -125,12 +168,28 @@ module.exports = function (grunt) { } }, - // electron + shell: { + electron: { + command: path.join('cache', 'electron') + ' ' + 'build', + options: { + async: true, + execOptions: { + env: env + } + } + } + }, + + clean: { + dist: ['dist/'], + build: ['build/'] + }, // livereload - watch: { - options: { - livereload: true + watchChokidar: { + livereload: { + options: {livereload: true}, + files: ['build/**/*'] }, js: { files: ['src/**/*.js'], @@ -146,6 +205,6 @@ module.exports = function (grunt) { } } }); - - grunt.registerTask('default', ['download-electron', 'curl', 'babel', 'less', 'copy', 'watch', 'electron']); + grunt.registerTask('default', ['download-electron', 'download-binary', 'babel', 'less', 'copy:dev', 'shell:electron', 'watchChokidar']); + grunt.registerTask('release', ['clean:dist', 'clean:build', 'download-binary', 'babel', 'less', 'copy:dev', 'electron', 'copy:release']); }; diff --git a/package.json b/package.json index 5db699fb12..fa9eb1f856 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "author": "Kitematic", "description": "Simple Docker Container management for Mac OS X.", "homepage": "https://kitematic.com/", - "main": "build/browser.js", + "main": "browser.js", "repository": { "type": "git", "url": "git@github.com:kitematic/kitematic.git" @@ -71,26 +71,16 @@ "grunt-babel": "^5.0.1", "grunt-chmod": "^1.0.3", "grunt-cli": "^0.1.13", + "grunt-contrib-clean": "^0.6.0", "grunt-contrib-copy": "^0.8.0", "grunt-contrib-less": "^1.0.1", - "grunt-contrib-watch": "^0.6.1", + "grunt-contrib-watch-chokidar": "^1.0.0", "grunt-curl": "^2.2.0", "grunt-download-electron": "^2.1.1", + "grunt-electron": "^1.0.0", "grunt-electron-installer": "^0.33.0", - "gulp": "^3.8.11", - "gulp-babel": "^5.1.0", - "gulp-changed": "^1.2.1", - "gulp-concat": "^2.5.2", - "gulp-cssmin": "^0.1.6", - "gulp-download-electron": "^0.0.5", - "gulp-if": "^1.2.5", - "gulp-insert": "^0.4.0", - "gulp-less": "^3.0.2", - "gulp-livereload": "^3.8.0", - "gulp-plumber": "^1.0.0", - "gulp-shell": "^0.4.1", - "gulp-sourcemaps": "^1.5.2", - "gulp-util": "^3.0.4", + "grunt-shell": "^1.1.2", + "grunt-shell-spawn": "^0.3.8", "jest-cli": "^0.4.5", "jsxhint": "^0.14.0", "load-grunt-tasks": "^3.2.0", diff --git a/src/browser.js b/src/browser.js index 04e3918c71..5a4f8c844f 100644 --- a/src/browser.js +++ b/src/browser.js @@ -5,9 +5,8 @@ var fs = require('fs'); var ipc = require('ipc'); var path = require('path'); -process.env.NODE_PATH = path.join(__dirname, '/../node_modules'); +process.env.NODE_PATH = path.join(__dirname, 'node_modules'); process.env.RESOURCES_PATH = path.join(__dirname, '/../resources'); -process.chdir(path.join(__dirname, '..')); process.env.PATH = '/usr/local/bin:' + process.env.PATH; var size = {}, settingsjson = {}; @@ -18,6 +17,46 @@ try { settingsjson = JSON.parse(fs.readFileSync(path.join(__dirname, '..', 'settings.json'), 'utf8')); } catch (err) {} +var handleStartupEvent = function() { + if (process.platform !== 'win32') { + return false; + } + + var squirrelCommand = process.argv[1]; + switch (squirrelCommand) { + case '--squirrel-install': + case '--squirrel-updated': + + // Optionally do things such as: + // + // - Install desktop and start menu shortcuts + // - Add your .exe to the PATH + // - Write to the registry for things like file associations and + // explorer context menus + + // Always quit when done + app.quit(); + + return true; + case '--squirrel-uninstall': + // Undo anything you did in the --squirrel-install and + // --squirrel-updated handlers + + // Always quit when done + app.quit(); + + return true; + case '--squirrel-obsolete': + // This is called on the outgoing version of your app before + // we update to the new version - it's the opposite of + // --squirrel-updated + app.quit(); + return true; + } +}; + +handleStartupEvent(); + var openURL = null; app.on('open-url', function (event, url) { event.preventDefault(); @@ -36,7 +75,7 @@ app.on('ready', function () { show: false, }); - mainWindow.loadUrl(path.normalize('file://' + path.join(__dirname, '..', 'build/index.html'))); + mainWindow.loadUrl(path.normalize('file://' + path.join(__dirname, 'index.html'))); app.on('activate-with-no-open-windows', function () { if (mainWindow) { diff --git a/src/utils/Util.js b/src/utils/Util.js index fd4524e4e5..c8609e95c9 100644 --- a/src/utils/Util.js +++ b/src/utils/Util.js @@ -56,7 +56,7 @@ module.exports = { .replace(/\/Users\/[^\/]*\//mg, '/Users//'); }, packagejson: function () { - return JSON.parse(fs.readFileSync(path.join(__dirname, '../..', 'package.json'), 'utf8')); + return JSON.parse(fs.readFileSync(path.join(__dirname, '..', 'package.json'), 'utf8')); }, settingsjson: function () { var settingsjson = {};