@shockpkg/ria-packager
Version:
Package for creating Adobe AIR packages
115 lines (106 loc) • 2.64 kB
JavaScript
import { mkdir, utimes, writeFile } from 'node:fs/promises';
import { dirname, join as pathJoin } from 'node:path';
import { quoteSh } from "../../util.mjs";
import { PackagerAdl } from "../adl.mjs";
/**
* PackagerAdlMac object.
*
* @param path Output path.
*/
export class PackagerAdlMac extends PackagerAdl {
/**
* Optionally preserve resource mtime.
* The official packager does not preserve resource mtimes.
*/
preserveResourceMtime = false;
/**
* PackagerAdlMac constructor.
*
* @param path Output path.
*/
constructor(path) {
super(path);
}
/**
* Get app run path.
*
* @returns Resources path.
*/
get appRunPath() {
return 'run';
}
/**
* 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() {
return {
required: [['bin/adl'], ['runtimes/air/mac',
// Old SDK 1.0 and 1.1 location:
'runtime/Adobe AIR.framework']],
optional: [['bin/Contents']]
};
}
/**
* 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 mkdir(dirname(dest), {
recursive: true
});
await writeFile(dest, data, {
mode
});
// Optionally preserve mtime information.
if (this.preserveResourceMtime) {
const {
mtime
} = options;
if (mtime) {
await utimes(dest, mtime, mtime);
}
}
}
/**
* Write the run script.
*/
async _writeRunScript() {
const {
path,
appSdkPath,
appResourcesPath,
_metaResourceApplicationPath
} = this;
await mkdir(path, {
recursive: true
});
await writeFile(pathJoin(path, this.appRunPath), ['#!/bin/sh', '', ['exec', ...[`${appSdkPath}/bin/adl`, ...this._generateOptionArguments(), `${appResourcesPath}/${_metaResourceApplicationPath}`, appResourcesPath].map(quoteSh), '--', '"$@"'].join(' '), ''].join('\n'), {
encoding: 'utf8',
mode: 0o777
});
}
}
//# sourceMappingURL=mac.mjs.map