@shockpkg/ria-packager
Version:
Package for creating Adobe AIR packages
137 lines (126 loc) • 3.31 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.PackagerAdlWindows = void 0;
var _promises = require("node:fs/promises");
var _nodePath = require("node:path");
var _util = require("../../util.js");
var _adl = require("../adl.js");
/**
* Convert forward slashes to back slashes.
*
* @param s String with forward slashes.
* @returns String with back slaches.
*/
const bs = s => s.replace(/\//g, '\\');
/**
* PackagerAdlWindows object.
*
* @param path Output path.
*/
class PackagerAdlWindows extends _adl.PackagerAdl {
/**
* Optionally preserve resource mtime.
* The official packager does not preserve resource mtimes.
*/
preserveResourceMtime = false;
/**
* Optionally use specific architecture.
*/
architecture = null;
/**
* PackagerAdlWindows constructor.
*
* @param path Output path.
*/
constructor(path) {
super(path);
}
/**
* Get app run path.
*
* @returns Resources path.
*/
get appRunPath() {
return 'run.bat';
}
/**
* Get file mode value.
*
* @param executable Is the entry executable.
* @returns File mode.
*/
_getFileMode(executable) {
return executable ? 0b111100100 : 0b110100100;
}
/**
* The SDK components to be copied.
*
* @returns Required and optional components.
*/
_sdkComponents() {
const arch = this.architecture === 'x64' ? '64' : '';
return {
required: [[`bin/adl${arch}.exe`], [`runtimes/air/win${arch}`,
// Old SDK 1.0 and 1.1 location:
'runtime/Adobe AIR']],
optional: []
};
}
/**
* Close implementation.
*/
async _close() {
await this._writeRunScript();
}
/**
* Write resource with data implementation.
*
* @param destination Packaged file relative destination.
* @param data Resource data.
* @param options Resource options.
*/
async _writeResource(destination, data, options) {
// Write resource to file.
const mode = this._getFileMode(options.executable || false);
const dest = this._getResourcePath(destination);
await (0, _promises.mkdir)((0, _nodePath.dirname)(dest), {
recursive: true
});
await (0, _promises.writeFile)(dest, data, {
mode
});
// Optionally preserve mtime information.
if (this.preserveResourceMtime) {
const {
mtime
} = options;
if (mtime) {
await (0, _promises.utimes)(dest, mtime, mtime);
}
}
}
/**
* Write the run script.
*/
async _writeRunScript() {
const {
path,
appSdkPath,
appResourcesPath,
_metaResourceApplicationPath
} = this;
const arch = this.architecture === 'x64' ? '64' : '';
const metaPath = `${appResourcesPath}/${_metaResourceApplicationPath}`;
await (0, _promises.mkdir)((0, _nodePath.dirname)(path), {
recursive: true
});
await (0, _promises.writeFile)((0, _nodePath.join)(path, this.appRunPath), ['@ECHO OFF', '', [...[bs(`${appSdkPath}/bin/adl${arch}`), ...this._generateOptionArguments(), bs(metaPath), bs(appResourcesPath)].map(_util.quoteCmd), '--', '%*'].join(' '), ''].join('\r\n'), {
encoding: 'utf8',
mode: 0o777
});
}
}
exports.PackagerAdlWindows = PackagerAdlWindows;
//# sourceMappingURL=windows.js.map