|
| 1 | +const path = require('path') |
| 2 | +const ChildProcess = require('child_process') |
| 3 | +const packager = require('electron-packager') |
| 4 | +const archiver = require('archiver') |
| 5 | +const fs = require('fs') |
| 6 | + |
| 7 | +module.exports = function (grunt) { |
| 8 | + |
| 9 | + // Project configuration. |
| 10 | + grunt.initConfig({ |
| 11 | + pkg: grunt.file.readJSON('package.json'), |
| 12 | + auth_code: grunt.file.readJSON('secret/auth_code.json'), |
| 13 | + 'create-windows-installer': { |
| 14 | + x64: { |
| 15 | + appDirectory: path.join(__dirname, 'dist', 'Boostnote-win32-x64'), |
| 16 | + outputDirectory: path.join(__dirname, 'dist'), |
| 17 | + authors: 'MAISIN&CO., Inc.', |
| 18 | + exe: 'Boostnote.exe', |
| 19 | + loadingGif: path.join(__dirname, 'resources/install.gif'), |
| 20 | + iconUrl: path.join(__dirname, 'resources/app.ico'), |
| 21 | + setupIcon: path.join(__dirname, 'resources/dmg.ico'), |
| 22 | + certificateFile: grunt.config.get('auth_code.win_cert_path'), |
| 23 | + certificatePassword: grunt.config.get('auth_code.win_cert_pw'), |
| 24 | + noMsi: true, |
| 25 | + remoteReleases: 'https://github.com/BoostIO/boost-releases/releases/download/v0.4.10/' |
| 26 | + } |
| 27 | + } |
| 28 | + }) |
| 29 | + grunt.loadNpmTasks('grunt-electron-installer') |
| 30 | + |
| 31 | + grunt.registerTask('compile', function () { |
| 32 | + var done = this.async() |
| 33 | + var execPath = path.join('node_modules', '.bin', 'webpack') + ' --config webpack.config.production.js' |
| 34 | + grunt.log.writeln(execPath) |
| 35 | + var compileProcess = ChildProcess.exec(execPath, |
| 36 | + { |
| 37 | + env: Object.assign({}, process.env, { |
| 38 | + BABEL_ENV: 'production' |
| 39 | + }) |
| 40 | + }, function (err, stdout, stderr) { |
| 41 | + grunt.log.writeln(stdout) |
| 42 | + if (err) { |
| 43 | + grunt.log.writeln(err) |
| 44 | + grunt.log.writeln(stderr) |
| 45 | + done(false) |
| 46 | + return |
| 47 | + } |
| 48 | + done() |
| 49 | + }) |
| 50 | + }) |
| 51 | + |
| 52 | + grunt.registerTask('zip', function (platform) { |
| 53 | + var done = this.async() |
| 54 | + var archive = archiver.create('zip', {}) |
| 55 | + switch (platform) { |
| 56 | + case 'win': |
| 57 | + archive.file(path.join('dist/Setup.exe'), { name:'Boostnote-installer-win32-x64.exe' }) |
| 58 | + default: |
| 59 | + done() |
| 60 | + return |
| 61 | + } |
| 62 | + archive.finalize() |
| 63 | + var writeStream = fs.createWriteStream(path.join('dist/Boostnote-installer-win32-x64.zip')) |
| 64 | + archive.pipe(writeStream) |
| 65 | + writeStream.on('close', function () { |
| 66 | + grunt.log.writeln('Zipped!') |
| 67 | + done() |
| 68 | + }) |
| 69 | + }) |
| 70 | + |
| 71 | + grunt.registerTask('pack', function (platform) { |
| 72 | + grunt.log.writeln(path.join(__dirname, 'dist')) |
| 73 | + var done = this.async() |
| 74 | + var opts = { |
| 75 | + name: 'Boostnote', |
| 76 | + arch: 'x64', |
| 77 | + dir: __dirname, |
| 78 | + version: '0.35.4', |
| 79 | + 'app-version': grunt.config.get('pkg.version'), |
| 80 | + 'app-bundle-id': 'com.maisin.boost', |
| 81 | + asar: true, |
| 82 | + prune: true, |
| 83 | + overwrite: true, |
| 84 | + out: path.join(__dirname, 'dist'), |
| 85 | + ignore: /submodules\/ace\/(?!src-min)|submodules\/ace\/(?=src-min-noconflict)|node_modules\/devicon\/icons|dist|.env/ |
| 86 | + } |
| 87 | + switch (platform) { |
| 88 | + case 'win': |
| 89 | + Object.assign(opts, { |
| 90 | + platform: 'win32', |
| 91 | + icon: path.join(__dirname, 'resources/app.ico'), |
| 92 | + 'version-string': { |
| 93 | + CompanyName: 'MAISIN&CO., Inc.', |
| 94 | + LegalCopyright: '© 2015 MAISIN&CO., Inc. All rights reserved.', |
| 95 | + FileDescription: 'Boostnote', |
| 96 | + OriginalFilename: 'Boostnote', |
| 97 | + FileVersion: grunt.config.get('pkg.version'), |
| 98 | + ProductVersion: grunt.config.get('pkg.version'), |
| 99 | + ProductName: 'Boostnote', |
| 100 | + InternalName: 'Boostnote' |
| 101 | + } |
| 102 | + }) |
| 103 | + packager(opts, function (err, appPath) { |
| 104 | + if (err) { |
| 105 | + grunt.log.writeln(err) |
| 106 | + done(err) |
| 107 | + return |
| 108 | + } |
| 109 | + done() |
| 110 | + }) |
| 111 | + break |
| 112 | + case 'osx': |
| 113 | + Object.assign(opts, { |
| 114 | + platform: 'darwin', |
| 115 | + icon: path.join(__dirname, 'resources/app.icns'), |
| 116 | + 'app-category-type': 'public.app-category.developer-tools' |
| 117 | + }) |
| 118 | + packager(opts, function (err, appPath) { |
| 119 | + if (err) { |
| 120 | + grunt.log.writeln(err) |
| 121 | + done(err) |
| 122 | + return |
| 123 | + } |
| 124 | + done() |
| 125 | + }) |
| 126 | + break |
| 127 | + } |
| 128 | + }) |
| 129 | + |
| 130 | + grunt.registerTask('build', function (platform) { |
| 131 | + if (!platform) { |
| 132 | + platform = process.platform === 'darwin' ? 'osx' : process.platform === 'win32' ? 'win' : null |
| 133 | + } |
| 134 | + switch (platform) { |
| 135 | + case 'win': |
| 136 | + grunt.task.run(['pack:win', 'create-windows-installer', 'zip:win']) |
| 137 | + } |
| 138 | + }) |
| 139 | + // Default task(s). |
| 140 | + grunt.registerTask('default', ['build']) |
| 141 | +} |
0 commit comments