diff --git a/gulp-haxetool.iml b/gulp-haxetool.iml new file mode 100755 index 0000000..0247a13 --- /dev/null +++ b/gulp-haxetool.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/haxetool/env.js b/haxetool/env.js old mode 100644 new mode 100755 index bbcd251..b14b9cf --- a/haxetool/env.js +++ b/haxetool/env.js @@ -7,6 +7,10 @@ class Env { process.env[key] = value; } + static get(key) { + return process.env[key]; + } + static addPath(value, key='PATH') { if (!process.env[key]) { process.env[key] = value; @@ -17,4 +21,4 @@ class Env { } -module.exports = Env; \ No newline at end of file +module.exports = Env; diff --git a/haxetool/innosetup.js b/haxetool/innosetup.js new file mode 100755 index 0000000..09a0e2b --- /dev/null +++ b/haxetool/innosetup.js @@ -0,0 +1,58 @@ +const fs = require('fs'); +const fse = require('fs-extra'); +const os = require('os'); +const path = require('path'); +const Sdk = require('./sdk'); +const exec = require('./exec'); +const Env = require('./env'); +const template = require('lodash.template'); + +class InnoSetup extends Sdk { + + constructor(version) { + super(InnoSetup.ID, version || InnoSetup.VERSION); + } + + get link() { + return 'http://www.jrsoftware.org/download.php/is.exe'; + } + + prepare(strip = 1) { + let result = super.prepare(strip); + if (!this.prepared) { + result = result.then(() => { + return exec(this.path, 'is.exe /VERYSILENT /SUPPRESSMSGBOXES'); + }); + } + return result; + } + + get isccBin() { + return path.join(Env.get('ProgramFiles(x86)'), `Inno Setup ${this.version}`, 'ISCC.exe') + } + + get prepared() { + try { + return fs.existsSync(this.isccBin); + } catch (e) { + return false; + } + } + + pack(config, source, output) { + const buildDir = path.join(os.tmpdir(), 'build', config.name, 'innosetup'); + const appTemplate = template(fs.readFileSync(path.resolve(__dirname, '..', 'template/windows/app.iss'))); + const app = appTemplate({...config, buildDir: buildDir, output: output}); + + fse.ensureDirSync(buildDir); + fse.copySync(`${source}`, `${buildDir}`); + + fs.writeFileSync(path.resolve(buildDir, 'app.iss'), app); + return exec(buildDir, [`"${this.isccBin}"`, 'app.iss'].join(' ')); + } +} + +InnoSetup.ID = 'innosetup'; +InnoSetup.VERSION = '6'; + +module.exports = InnoSetup; diff --git a/haxetool/project.js b/haxetool/project.js index 00e0c79..5a7ee6f 100755 --- a/haxetool/project.js +++ b/haxetool/project.js @@ -7,6 +7,7 @@ const Haxe = require('./haxe'); const FlashPlayer = require('./flashplayer'); const Android = require('./android'); const Neko = require('./neko'); +const InnoSetup = require('./innosetup'); const Env = require('./env'); const debug = require('./debug'); const webserver = require('gulp-webserver'); @@ -214,7 +215,7 @@ class LinuxDEBPacker extends Packer { 'fi' ], _target: '/', - _out: path.join(target, '..', 'debian'), + _out: this.resolveTargetPath('debian'), _clean: true, _verbose: false })); @@ -248,6 +249,29 @@ LinuxArchivePacker.NAME = 'archive'; Packer.register(Platform.LINUX, LinuxArchivePacker.NAME, LinuxArchivePacker); +/** + * + */ +class WindowsInstallerPacker extends Packer { + + constructor(config) { + super(config, Platform.WINDOWS); + this.innosetup = new InnoSetup(); + } + + prepare() { + return this.innosetup.prepare(); + } + + call() { + return this.innosetup.pack(this.config, this.targetPath, this.resolveTargetPath('installer')); + } +} + +WindowsInstallerPacker.NAME = 'installer'; + +Packer.register(Platform.WINDOWS, WindowsInstallerPacker.NAME, WindowsInstallerPacker); + /** * */ diff --git a/haxetool/sdk.js b/haxetool/sdk.js index 1ff3c08..e9e136f 100755 --- a/haxetool/sdk.js +++ b/haxetool/sdk.js @@ -63,13 +63,15 @@ class Downloader { let stream = got.stream(url); stream = stream .on('request', r => { - bar.start(1, 0); + if (bar) bar.start(1, 0); }) .on('downloadProgress', p => { - bar.setTotal(p.total); - bar.update(p.transferred); - if (p.total === p.transferred) { - Downloader.releaseProgressBar(bar); + if (bar) { + bar.setTotal(p.total); + bar.update(p.transferred); + if (p.total === p.transferred) { + Downloader.releaseProgressBar(bar); + } } }); if (url.endsWith('.zip')) { diff --git a/template/windows/app.iss b/template/windows/app.iss new file mode 100755 index 0000000..6d1d085 --- /dev/null +++ b/template/windows/app.iss @@ -0,0 +1,18 @@ +[Setup] +AppName=<%=meta.title%> +AppVersion=<%=meta.version%> +WizardStyle=modern +DefaultDirName={autopf}\<%=meta.filename%> +DefaultGroupName=<%=meta.title%> +UninstallDisplayIcon={app}\<%=meta.filename%>.exe +Compression=lzma2 +SolidCompression=yes +OutputDir=<%=output%> +OutputBaseFilename=<%=meta.filename%>_<%=meta.version%> + +[Files] +Source: *; Excludes: "*.iss,*.log"; DestDir: "{app}"; Flags: recursesubdirs + +[Icons] +Name: "{group}\<%=meta.title%>"; Filename: "{app}\<%=meta.filename%>.exe" +Name: "{group}\Uninstall <%=meta.title%>"; Filename: "{uninstallexe}"