UNPKG

nativescript

Version:

Command-line interface for building NativeScript projects

101 lines 4.21 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.HooksVerifyPluginCommand = exports.HooksLockPluginCommand = void 0; const yok_1 = require("../../common/yok"); const path = require("path"); const crypto = require("crypto"); const common_1 = require("./common"); class HooksLockPluginCommand { constructor($pluginsService, $projectData, $errors, $fs, $logger) { this.$pluginsService = $pluginsService; this.$projectData = $projectData; this.$errors = $errors; this.$fs = $fs; this.$logger = $logger; this.allowedParameters = []; this.$projectData.initializeProjectData(); } async execute() { var _a, _b; const plugins = await this.$pluginsService.getAllInstalledPlugins(this.$projectData); if (plugins && plugins.length > 0) { const pluginsWithHooks = []; for (const plugin of plugins) { if (((_b = (_a = plugin.nativescript) === null || _a === void 0 ? void 0 : _a.hooks) === null || _b === void 0 ? void 0 : _b.length) > 0) { pluginsWithHooks.push(plugin); } } await this.writeHooksLockFile(pluginsWithHooks, this.$projectData.projectDir); } else { this.$logger.info("No plugins with hooks found."); } } async canExecute(args) { return true; } async writeHooksLockFile(plugins, outputDir) { var _a; const output = []; for (const plugin of plugins) { const hooks = []; for (const hook of ((_a = plugin.nativescript) === null || _a === void 0 ? void 0 : _a.hooks) || []) { try { const fileContent = this.$fs.readFile(path.join(plugin.fullPath, hook.script)); const hash = crypto .createHash("sha256") .update(fileContent) .digest("hex"); hooks.push({ type: hook.type, hash, }); } catch (err) { this.$logger.warn(`Warning: Failed to read script '${hook.script}' for plugin '${plugin.name}'. Skipping this hook.`); continue; } } output.push({ name: plugin.name, hooks }); } const filePath = path.resolve(outputDir, common_1.LOCK_FILE_NAME); try { this.$fs.writeFile(filePath, JSON.stringify(output, null, 2), "utf8"); this.$logger.info(`✅ ${common_1.LOCK_FILE_NAME} written to: ${filePath}`); } catch (err) { this.$errors.fail(`❌ Failed to write ${common_1.LOCK_FILE_NAME}: ${err}`); } } } exports.HooksLockPluginCommand = HooksLockPluginCommand; class HooksVerifyPluginCommand extends common_1.HooksVerify { constructor($pluginsService, $projectData, $errors, $fs, $logger) { super($projectData, $errors, $fs, $logger); this.$pluginsService = $pluginsService; this.allowedParameters = []; } async execute() { var _a, _b; const plugins = await this.$pluginsService.getAllInstalledPlugins(this.$projectData); if (plugins && plugins.length > 0) { const pluginsWithHooks = []; for (const plugin of plugins) { if (((_b = (_a = plugin.nativescript) === null || _a === void 0 ? void 0 : _a.hooks) === null || _b === void 0 ? void 0 : _b.length) > 0) { pluginsWithHooks.push(plugin); } } await this.verifyHooksLock(pluginsWithHooks, path.join(this.$projectData.projectDir, common_1.LOCK_FILE_NAME)); } else { this.$logger.info("No plugins with hooks found."); } } async canExecute(args) { return true; } } exports.HooksVerifyPluginCommand = HooksVerifyPluginCommand; yok_1.injector.registerCommand(["hooks|lock"], HooksLockPluginCommand); yok_1.injector.registerCommand(["hooks|verify"], HooksVerifyPluginCommand); //# sourceMappingURL=hooks-lock.js.map