nativescript
Version:
Command-line interface for building NativeScript projects
80 lines • 3.33 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.HooksVerify = exports.LOCK_FILE_NAME = void 0;
const path = require("path");
const crypto = require("crypto");
exports.LOCK_FILE_NAME = "nativescript-lock.json";
class HooksVerify {
constructor($projectData, $errors, $fs, $logger) {
this.$projectData = $projectData;
this.$errors = $errors;
this.$fs = $fs;
this.$logger = $logger;
this.allowedParameters = [];
this.$projectData.initializeProjectData();
}
async verifyHooksLock(plugins, hooksLockPath) {
var _a;
let lockFileContent;
let hooksLock;
try {
lockFileContent = this.$fs.readText(hooksLockPath, "utf8");
hooksLock = JSON.parse(lockFileContent);
}
catch (err) {
this.$errors.fail(`❌ Failed to read or parse ${exports.LOCK_FILE_NAME} at ${hooksLockPath}`);
}
const lockMap = new Map(); // pluginName -> hookType -> hash
for (const plugin of hooksLock) {
const hookMap = new Map();
for (const hook of plugin.hooks) {
hookMap.set(hook.type, hook.hash);
}
lockMap.set(plugin.name, hookMap);
}
let isValid = true;
for (const plugin of plugins) {
const pluginLockHooks = lockMap.get(plugin.name);
if (!pluginLockHooks) {
this.$logger.error(`❌ Plugin '${plugin.name}' not found in ${exports.LOCK_FILE_NAME}`);
isValid = false;
continue;
}
for (const hook of ((_a = plugin.nativescript) === null || _a === void 0 ? void 0 : _a.hooks) || []) {
const expectedHash = pluginLockHooks.get(hook.type);
if (!expectedHash) {
this.$logger.error(`❌ Missing hook '${hook.type}' for plugin '${plugin.name}' in ${exports.LOCK_FILE_NAME}`);
isValid = false;
continue;
}
let fileContent;
try {
fileContent = this.$fs.readFile(path.join(plugin.fullPath, hook.script));
}
catch (err) {
this.$logger.error(`❌ Cannot read script file '${hook.script}' for hook '${hook.type}' in plugin '${plugin.name}'`);
isValid = false;
continue;
}
const actualHash = crypto
.createHash("sha256")
.update(fileContent)
.digest("hex");
if (actualHash !== expectedHash) {
this.$logger.error(`❌ Hash mismatch for '${hook.script}' (${hook.type} in ${plugin.name}):`);
this.$logger.error(` Expected: ${expectedHash}`);
this.$logger.error(` Actual: ${actualHash}`);
isValid = false;
}
}
}
if (isValid) {
this.$logger.info("✅ All hooks verified successfully. No issues found.");
}
else {
this.$errors.fail("❌ One or more hooks failed verification.");
}
}
}
exports.HooksVerify = HooksVerify;
//# sourceMappingURL=common.js.map