@shockpkg/dir-projector
Version:
Package for creating Shockwave Director projectors
113 lines (81 loc) • 3.31 kB
JavaScript
;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.BundleMacApp = void 0;
var _path = require("path");
var _fsExtra = _interopRequireDefault(require("fs-extra"));
var _util = require("../../util");
var _mac = require("../../util/mac");
var _app = require("../../projector/mac/app");
var _mac2 = require("../mac");
/**
* BundleMacApp constructor.
*
* @param path Output path for the main application.
*/
class BundleMacApp extends _mac2.BundleMac {
/**
* ProjectorMacApp instance.
*/
constructor(path) {
super(path);
this.projector = void 0;
this.projector = this._createProjector();
}
/**
* Get the launcher name.
*
* @returns Launcher name.
*/
_getLauncherName() {
return (0, _util.trimExtension)((0, _path.basename)(this.path), this.extension, true);
}
/**
* Create projector instance for the bundle.
*
* @returns Projector instance.
*/
_createProjector() {
const projName = `${this._getLauncherName()}${this.extension}`;
const projPath = (0, _path.join)(this.path, 'Contents', 'Resources', projName);
return new _app.ProjectorMacApp(projPath);
}
/**
* Write the launcher file.
*/
async _writeLauncher() {
const {
path,
projector
} = this; // Create paths to things to create.
const appContents = (0, _path.join)(path, 'Contents');
const appMacOS = (0, _path.join)(appContents, 'MacOS');
const appResources = (0, _path.join)(appContents, 'Resources');
const appInfoPlist = (0, _path.join)(appContents, 'Info.plist');
const appPkgInfo = (0, _path.join)(appContents, 'PkgInfo'); // Read the projector Info.plist.
const plist = await (0, _mac.plistRead)(projector.infoPlistPath); // Get the binary path and read the types.
const projBinaryPath = projector.binaryPath;
const projBinaryTypes = await (0, _mac.machoTypesFile)(projBinaryPath); // Get the icon path.
const projIconName = (0, _mac.infoPlistBundleIconFileGet)(plist);
const projIconPath = projector.iconPath; // Get the PkgInfo path.
const projPkgInfoPath = projector.pkgInfoPath; // Create the launcher binary with the same types and mode.
const launcherName = this._getLauncherName();
const launcherPath = (0, _path.join)(appMacOS, launcherName);
await _fsExtra.default.outputFile(launcherPath, await (0, _mac.machoAppLauncher)(projBinaryTypes), {
mode: (await _fsExtra.default.stat(projBinaryPath)).mode
}); // Copy the projector icon if present.
const pathIcon = (0, _path.join)(appResources, projIconName);
if (await _fsExtra.default.pathExists(projIconPath)) {
await _fsExtra.default.copyFile(projIconPath, pathIcon);
} // Copy PkgInfo if present.
if (await _fsExtra.default.pathExists(projPkgInfoPath)) {
await _fsExtra.default.copyFile(projPkgInfoPath, appPkgInfo);
} // Update the executable name in the plist for the launcher.
(0, _mac.infoPlistBundleExecutableSet)(plist, launcherName); // Write the updated Info.plist.
await _fsExtra.default.outputFile(appInfoPlist, plist.toXml(), 'utf8');
}
}
exports.BundleMacApp = BundleMacApp;
//# sourceMappingURL=app.js.map