@shockpkg/ria-packager
Version:
Package for creating Adobe AIR packages
240 lines (218 loc) • 4.8 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.PackagerAdl = void 0;
var _nodePath = require("node:path");
var _archiveFiles = require("@shockpkg/archive-files");
var _util = require("../util.js");
var _packager = require("../packager.js");
/**
* PackagerAdl object.
*/
class PackagerAdl extends _packager.Packager {
/**
* Path to the SDK, an archive or directory.
*/
sdkPath = null;
/**
* Application pubid.
*/
pubid = null;
/**
* Application profile.
*/
profile = null;
/**
* Application screensize.
*/
screensize = null;
/**
* Application nodebug.
*/
nodebug = false;
/**
* Application atlogin.
*/
atlogin = false;
/**
* PackagerAdl constructor.
*
* @param path Output path.
*/
constructor(path) {
super(path);
}
/**
* Package mimetype.
*
* @returns Mimetype string.
*/
get mimetype() {
return 'application/vnd.adobe.air-application-installer-package+zip';
}
/**
* Package signed.
*
* @returns Boolean for if package is signed or not.
*/
get signed() {
return false;
}
/**
* Get app sdk path.
*
* @returns Resources path.
*/
get appSdkPath() {
return 'sdk';
}
/**
* Get app resources path.
*
* @returns Resources path.
*/
get appResourcesPath() {
return 'app';
}
/**
* Get app run path.
*
* @returns Resources path.
*/
/**
* Generate aruments.
*
* @returns Argument options.
*/
_generateOptionArguments() {
const {
pubid,
profile,
screensize,
nodebug,
atlogin
} = this;
const r = [];
if (pubid !== null) {
r.push('-pubid', pubid);
}
if (profile !== null) {
r.push('-profile', profile);
}
if (screensize !== null) {
r.push('-screensize', screensize);
}
if (nodebug) {
r.push('-nodebug');
}
if (atlogin) {
r.push('-atlogin');
}
return r;
}
/**
* Open implementation.
*/
async _open() {
const {
sdkPath
} = this;
if (!sdkPath) {
throw new Error('SDK path not set');
}
const {
required,
optional
} = this._sdkComponents();
const components = [...required.map(paths => ({
paths,
required: true,
found: false
})), ...optional.map(paths => ({
paths,
required: false,
found: false
}))];
/**
* Search function.
*
* @param volumePath Volume path.
* @returns A boolean or null.
*/
const component = volumePath => {
// Default to not searching any subpaths.
let r = false;
for (const component of components) {
for (const path of component.paths) {
// If extracting, mark found, return true.
if ((0, _util.pathRelativeBaseMatch)(volumePath, path, true)) {
component.found = true;
return true;
}
// If a parent path, remember to search down.
if ((0, _util.pathRelativeBaseMatch)(path, volumePath, true)) {
r = null;
}
}
}
return r;
};
// Extract everything needed from the SDK.
const sdk = await (0, _archiveFiles.createArchiveByFileStatOrThrow)(sdkPath, {
nobrowse: this.nobrowse
});
await sdk.read(async entry => {
// Ignore any resource forks.
if (entry.type === _archiveFiles.PathType.RESOURCE_FORK) {
return true;
}
const path = entry.volumePath;
const action = component(path);
if (action === true) {
const dest = this._getSdkPath(path);
await entry.extract(dest);
return true;
}
// Optimization to avoid walking unrelated directories if possible.
return action === null ? true : null;
});
// Check that everything necessary was extracted.
for (const {
found,
required,
paths
} of components) {
if (found || !required) {
continue;
}
const info = paths.map(s => JSON.stringify(s)).join(' | ');
throw new Error(`Failed to locate component in SDK: ${info}`);
}
}
/**
* Get path to a resource file.
*
* @param parts Path parts.
* @returns Full path.
*/
_getSdkPath(...parts) {
return (0, _nodePath.join)(this.path, this.appSdkPath, ...parts);
}
/**
* Get path to a resource file.
*
* @param parts Path parts.
* @returns Full path.
*/
_getResourcePath(...parts) {
return (0, _nodePath.join)(this.path, this.appResourcesPath, ...parts);
}
/**
* The SDK components to be copied.
*
* @returns Required and optional components.
*/
}
exports.PackagerAdl = PackagerAdl;
//# sourceMappingURL=adl.js.map