zephyr-agent
Version:
Zephyr plugin agent
119 lines (118 loc) • 5.33 kB
JavaScript
;
var __webpack_require__ = {};
(()=>{
__webpack_require__.d = (exports1, getters, values)=>{
var define = (defs, kind)=>{
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
enumerable: true,
[kind]: defs[key]
});
};
define(getters, "get");
define(values, "value");
};
})();
(()=>{
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
})();
(()=>{
__webpack_require__.r = (exports1)=>{
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
value: 'Module'
});
Object.defineProperty(exports1, '__esModule', {
value: true
});
};
})();
var __webpack_exports__ = {};
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
createSnapshot: ()=>createSnapshot
});
const external_zephyr_edge_contract_namespaceObject = require("zephyr-edge-contract");
const external_ze_basehref_handler_js_namespaceObject = require("./ze-basehref-handler.js");
const index_js_namespaceObject = require("../errors/index.js");
const zephyr_agent_version_js_namespaceObject = require("../version/zephyr-agent-version.js");
const external_node_path_namespaceObject = require("node:path");
async function createSnapshot(zephyr_engine, { mfConfig, mfConfigs, assets, snapshotType, entrypoint }) {
const buildId = await zephyr_engine.build_id;
if (!buildId) {
await zephyr_engine.build_id;
throw new index_js_namespaceObject.ZephyrError(index_js_namespaceObject.ZeErrors.ERR_DEPLOY_LOCAL_BUILD, {
message: 'Cannot create snapshot before getting buildId'
});
}
const options = {
git_branch: zephyr_engine.gitProperties.git.branch,
buildId,
username: (await zephyr_engine.application_configuration).username,
email: (await zephyr_engine.application_configuration).email,
applicationProperties: zephyr_engine.applicationProperties,
edge_url: (await zephyr_engine.application_configuration).EDGE_URL,
gitProperties: zephyr_engine.gitProperties,
mfConfig: mfConfig,
mfConfigs: mfConfigs
};
const version_postfix = zephyr_engine.env.isCI ? `${options.git_branch}.${options.buildId}` : `${options.username}.${options.buildId}`;
const basedAssets = (0, external_ze_basehref_handler_js_namespaceObject.applyBaseHrefToAssets)(assets, zephyr_engine.buildProperties.baseHref);
const normalizedBaseHref = (0, external_ze_basehref_handler_js_namespaceObject.normalizeBasePath)(zephyr_engine.buildProperties.baseHref);
const basedEntrypoint = entrypoint && ('ssr' === snapshotType || zephyr_engine.env.ssr) ? (0, external_ze_basehref_handler_js_namespaceObject.applyBaseHrefToPath)(entrypoint, normalizedBaseHref) : entrypoint;
const snapshot = {
application_uid: (0, external_zephyr_edge_contract_namespaceObject.createApplicationUid)(options.applicationProperties),
version: `${options.applicationProperties.version}-${version_postfix}`,
snapshot_id: (0, external_zephyr_edge_contract_namespaceObject.flatCreateSnapshotId)(Object.assign({}, options.applicationProperties, {
buildId: options.buildId,
username: options.username
})),
domain: options.edge_url,
target: zephyr_engine.env.target ?? 'web',
uid: {
build: options.buildId,
app_name: options.applicationProperties.name,
repo: options.applicationProperties.project,
org: options.applicationProperties.org
},
git: options.gitProperties.git,
creator: {
name: options.username,
email: options.email
},
createdAt: Date.now(),
mfConfig: options.mfConfig,
mfConfigs: options.mfConfigs,
builder: zephyr_engine.builder,
plugin_version: (0, zephyr_agent_version_js_namespaceObject.getZephyrAgentVersion)(),
assets: Object.keys(basedAssets).reduce((memo, hash)=>{
const asset = basedAssets[hash];
const { path, extname, size } = asset;
const normalizedPath = normalizePathSeparators(path);
memo[normalizedPath] = {
path: normalizedPath,
extname,
hash: asset.hash,
size
};
return memo;
}, {}),
...snapshotType && {
type: snapshotType
},
...basedEntrypoint && {
entrypoint: basedEntrypoint
}
};
if (zephyr_engine.env.ssr) snapshot.type = 'ssr';
return snapshot;
}
function normalizePathSeparators(path) {
return path.split(external_node_path_namespaceObject.win32.sep).join(external_node_path_namespaceObject.posix.sep);
}
exports.createSnapshot = __webpack_exports__.createSnapshot;
for(var __rspack_i in __webpack_exports__)if (-1 === [
"createSnapshot"
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
Object.defineProperty(exports, '__esModule', {
value: true
});
//# sourceMappingURL=ze-build-snapshot.js.map