Newer
Older
CVSS_3.0_GUI / node_modules / nwjs-builder-phoenix / dist / lib / nsis-gen / NsisComposer.js
root on 7 May 2019 12 KB Initial commit
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __generator = (this && this.__generator) || function (thisArg, body) {
    var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
    return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
    function verb(n) { return function (v) { return step([n, v]); }; }
    function step(op) {
        if (f) throw new TypeError("Generator is already executing.");
        while (_) try {
            if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
            if (y = 0, t) op = [0, t.value];
            switch (op[0]) {
                case 0: case 1: t = op; break;
                case 4: _.label++; return { value: op[1], done: false };
                case 5: _.label++; y = op[1]; op = [0]; continue;
                case 7: op = _.ops.pop(); _.trys.pop(); continue;
                default:
                    if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
                    if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
                    if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
                    if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
                    if (t[2]) _.ops.pop();
                    _.trys.pop(); continue;
            }
            op = body.call(thisArg, _);
        } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
        if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
    }
};
Object.defineProperty(exports, "__esModule", { value: true });
var path_1 = require("path");
var util_1 = require("../util");
var NsisComposer = /** @class */ (function () {
    function NsisComposer(options) {
        this.options = options;
        if (!this.options.appName) {
            this.options.appName = 'NO_APPNAME';
        }
        if (!this.options.companyName) {
            this.options.companyName = 'NO_COMPANYNAME';
        }
        if (!this.options.description) {
            this.options.description = 'NO_DESCRIPTION';
        }
        if (!this.options.version) {
            this.options.version = 'NO_VERSION';
        }
        if (!this.options.copyright) {
            this.options.copyright = 'NO_COPYRIGHT';
        }
        this.options.compression = this.options.compression || 'lzma';
        this.options.solid = this.options.solid ? true : false;
        this.options.languages = this.options.languages && this.options.languages.length > 0 ? this.options.languages : ['English'];
        this.fixedVersion = util_1.fixWindowsVersion(this.options.version);
    }
    NsisComposer.prototype.make = function () {
        return __awaiter(this, void 0, void 0, function () {
            var _a, _b, _c, _d, _e, _f, _g;
            return __generator(this, function (_h) {
                switch (_h.label) {
                    case 0:
                        _a = NsisComposer.DIVIDER + "\n#\n# Generated by nsis-gen.\n#\n" + NsisComposer.DIVIDER + "\n\n";
                        return [4 /*yield*/, this.makeStrings()];
                    case 1:
                        _b = _a + (_h.sent()) + "\n\n";
                        return [4 /*yield*/, this.makeGeneral()];
                    case 2:
                        _c = _b + (_h.sent()) + "\n\n";
                        return [4 /*yield*/, this.makeModernUI()];
                    case 3:
                        _d = _c + (_h.sent()) + "\n\n";
                        return [4 /*yield*/, this.makeVersioning()];
                    case 4:
                        _e = _d + (_h.sent()) + "\n\n";
                        return [4 /*yield*/, this.makeHooks()];
                    case 5:
                        _f = _e + (_h.sent()) + "\n\n";
                        return [4 /*yield*/, this.makeInstallSection()];
                    case 6:
                        _g = _f + (_h.sent()) + "\n\n";
                        return [4 /*yield*/, this.makeUninstallSection()];
                    case 7: return [2 /*return*/, _g + (_h.sent())];
                }
            });
        });
    };
    NsisComposer.prototype.makeStrings = function () {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                return [2 /*return*/, NsisComposer.DIVIDER + "\n#\n# Strings\n#\n" + NsisComposer.DIVIDER + "\n\n!define _APPNAME \"" + this.options.appName + "\"\n!define _COMPANYNAME \"" + this.options.companyName + "\"\n!define _DESCRIPTION \"" + this.options.description + "\"\n!define _VERSION \"" + this.fixedVersion + "\"\n!define _COPYRIGHT \"" + this.options.copyright + "\"\n!define _OUTPUT \"" + path_1.win32.normalize(path_1.resolve(this.options.output)) + "\"\n\n" + this.options.languages.map(function (language) {
                        return NsisComposer.STRINGS[language] ? NsisComposer.STRINGS[language] : '';
                    })];
            });
        });
    };
    NsisComposer.prototype.makeGeneral = function () {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                return [2 /*return*/, NsisComposer.DIVIDER + "\n#\n# General\n#\n" + NsisComposer.DIVIDER + "\n\nUnicode true\n\nName \"${_APPNAME}\"\nCaption \"${_APPNAME}\"\nBrandingText \"${_APPNAME} ${_VERSION}\"\n" + (this.options.icon
                        ? "Icon \"" + path_1.win32.normalize(path_1.resolve(this.options.icon)) + "\""
                        : '') + "\n" + (this.options.unIcon
                        ? "UninstallIcon \"" + path_1.win32.normalize(path_1.resolve(this.options.unIcon)) + "\""
                        : '') + "\n\nSetCompressor " + (this.options.solid ? '/SOLID' : '') + " " + this.options.compression + "\nOutFile \"${_OUTPUT}\"\n\nInstallDir \"" + this.options.installDirectory + "\"\nInstallDirRegKey HKCU \"Software\\${_APPNAME}\" \"InstallDir\"\n\nRequestExecutionLevel user\nXPStyle on"];
            });
        });
    };
    NsisComposer.prototype.makeModernUI = function () {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                return [2 /*return*/, NsisComposer.DIVIDER + "\n#\n# Modern UI\n#\n" + NsisComposer.DIVIDER + "\n\n!include \"MUI2.nsh\"\n\nFunction CreateDesktopShortcut\n    CreateShortcut \"$DESKTOP\\${_APPNAME}.lnk\" \"$INSTDIR\\${_APPNAME}.exe\"\nFunctionEnd\n\n!define MUI_STARTMENUPAGE_REGISTRY_ROOT \"HKCU\"\n!define MUI_STARTMENUPAGE_REGISTRY_KEY \"Software\\${_APPNAME}\"\n!define MUI_STARTMENUPAGE_REGISTRY_VALUENAME \"StartMenuFolder\"\n\n!define MUI_FINISHPAGE_SHOWREADME \"\"\n!define MUI_FINISHPAGE_SHOWREADME_TEXT \"$(CREATE_DESKTOP_SHORTCUT)\"\n!define MUI_FINISHPAGE_SHOWREADME_FUNCTION CreateDesktopShortcut\n\nVar StartMenuFolder\n\n!define MUI_FINISHPAGE_RUN \"$INSTDIR\\${_APPNAME}.exe\"\n\n!insertmacro MUI_PAGE_WELCOME\n!insertmacro MUI_PAGE_DIRECTORY\n!insertmacro MUI_PAGE_STARTMENU \"Application\" $StartMenuFolder\n!insertmacro MUI_PAGE_INSTFILES\n!insertmacro MUI_PAGE_FINISH\n\n!insertmacro MUI_UNPAGE_WELCOME\n!insertmacro MUI_UNPAGE_CONFIRM\n!insertmacro MUI_UNPAGE_INSTFILES\n!insertmacro MUI_UNPAGE_FINISH\n\n" + this.options.languages.map(function (language) {
                        return "!insertmacro MUI_LANGUAGE \"" + language + "\"";
                    }).join('\n') + "\n\n" + (this.options.languages.length > 1
                        ? "!insertmacro MUI_RESERVEFILE_LANGDLL"
                        : '')];
            });
        });
    };
    NsisComposer.prototype.makeVersioning = function () {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                return [2 /*return*/, NsisComposer.DIVIDER + "\n#\n# Versioning\n#\n" + NsisComposer.DIVIDER + "\n\nVIProductVersion \"${_VERSION}\"\nVIAddVersionKey /LANG=0 \"ProductName\" \"${_APPNAME}\"\nVIAddVersionKey /LANG=0 \"CompanyName\" \"${_COMPANYNAME}\"\nVIAddVersionKey /LANG=0 \"FileDescription\" \"${_DESCRIPTION}\"\nVIAddVersionKey /LANG=0 \"FileVersion\" \"${_VERSION}\"\nVIAddVersionKey /LANG=0 \"LegalCopyright\" \"${_COPYRIGHT}\""];
            });
        });
    };
    NsisComposer.prototype.makeHooks = function () {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                return [2 /*return*/, NsisComposer.DIVIDER + "\n#\n# Hooks\n#\n" + NsisComposer.DIVIDER + "\n\nFunction .onInit\n\n    " + (this.options.languages.length > 1
                        ? "!insertmacro MUI_LANGDLL_DISPLAY"
                        : '') + "\n\nFunctionEnd"];
            });
        });
    };
    NsisComposer.prototype.makeInstallSection = function () {
        return __awaiter(this, void 0, void 0, function () {
            var _a;
            return __generator(this, function (_b) {
                switch (_b.label) {
                    case 0:
                        _a = NsisComposer.DIVIDER + "\n#\n# Install\n#\n" + NsisComposer.DIVIDER + "\n\nSection -Install\n\nSetShellVarContext current\nSetOverwrite ifnewer\n\nWriteRegStr HKCU \"Software\\${_APPNAME}\" \"InstallDir\" \"$INSTDIR\"\n\n";
                        return [4 /*yield*/, this.makeInstallerFiles()];
                    case 1: return [2 /*return*/, _a + (_b.sent()) + "\n\n!insertmacro MUI_STARTMENU_WRITE_BEGIN \"Application\"\n\n    CreateDirectory \"$SMPROGRAMS\\$StartMenuFolder\"\n    CreateShortcut \"$SMPROGRAMS\\$StartMenuFolder\\${_APPNAME}.lnk\" \"$INSTDIR\\${_APPNAME}.exe\"\n    CreateShortcut \"$SMPROGRAMS\\$StartMenuFolder\\Uninstall.lnk\" \"$INSTDIR\\Uninstall.exe\"\n\n!insertmacro MUI_STARTMENU_WRITE_END\n\n  WriteUninstaller \"$INSTDIR\\Uninstall.exe\"\n\nSectionEnd"];
                }
            });
        });
    };
    NsisComposer.prototype.makeUninstallSection = function () {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                return [2 /*return*/, NsisComposer.DIVIDER + "\n#\n# Uninstall\n#\n" + NsisComposer.DIVIDER + "\n\nSection Uninstall\n\n# FIXME: Remove installed files only.\nRMDir /r \"$INSTDIR\"\n\n!insertmacro MUI_STARTMENU_GETFOLDER \"Application\" $StartMenuFolder\n\nDelete \"$SMPROGRAMS\\$StartMenuFolder\\${_APPNAME}.lnk\"\nDelete \"$SMPROGRAMS\\$StartMenuFolder\\Uninstall.lnk\"\nRMDir \"$SMPROGRAMS\\$StartMenuFolder\"\n\nDelete \"$DESKTOP\\${_APPNAME}.lnk\"\n\nDeleteRegKey HKCU \"Software\\${_APPNAME}\"\n\nSectionEnd"];
            });
        });
    };
    NsisComposer.prototype.makeInstallerFiles = function () {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                return [2 /*return*/, "SetOutPath \"$INSTDIR\"\nFILE /r .\\*.*"];
            });
        });
    };
    NsisComposer.DIVIDER = '################################################################################';
    NsisComposer.STRINGS = {
        'English': "\nLangString CREATE_DESKTOP_SHORTCUT 1033 \"Create Desktop Shortcut\"\nLangString INSTALLING 1033 \"Installing\"\n        ",
        'SimpChinese': "\nLangString CREATE_DESKTOP_SHORTCUT 2052 \"\u521B\u5EFA\u684C\u9762\u5FEB\u6377\u65B9\u5F0F\"\nLangString INSTALLING 2052 \"\u6B63\u5728\u5B89\u88C5\"\n        ",
        'TradChinese': "\nLangString CREATE_DESKTOP_SHORTCUT 1028 \"\u5EFA\u7ACB\u684C\u9762\u6377\u5F91\"\nLangString INSTALLING 1028 \"\u5B89\u88DD\u4E2D\"\n        ",
    };
    return NsisComposer;
}());
exports.NsisComposer = NsisComposer;
//# sourceMappingURL=NsisComposer.js.map