nativescript
Version:
Command-line interface for building NativeScript projects
72 lines • 3.33 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.HooksListPluginCommand = exports.HooksPluginCommand = void 0;
const yok_1 = require("../../common/yok");
const path = require("path");
const constants_1 = require("../../constants");
const helpers_1 = require("../../common/helpers");
const nsHooks = require("@nativescript/hook");
const common_1 = require("./common");
class HooksPluginCommand extends common_1.HooksVerify {
constructor($pluginsService, $projectData, $errors, $fs, $logger) {
super($projectData, $errors, $fs, $logger);
this.$pluginsService = $pluginsService;
this.allowedParameters = [];
}
async execute(args) {
var _a, _b;
const isList = args.length > 0 && args[0] === "list" ? true : false;
const plugins = await this.$pluginsService.getAllInstalledPlugins(this.$projectData);
if (plugins && plugins.length > 0) {
const hooksDir = path.join(this.$projectData.projectDir, constants_1.HOOKS_DIR_NAME);
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);
}
}
if (isList) {
const headers = ["Plugin", "HookName", "HookPath"];
const hookDataData = pluginsWithHooks.flatMap((plugin) => plugin.nativescript.hooks.map((hook) => {
return [plugin.name, hook.type, hook.script];
}));
const hookDataTable = (0, helpers_1.createTable)(headers, hookDataData);
this.$logger.info("Hooks:");
this.$logger.info(hookDataTable.toString());
}
else {
if (this.$fs.exists(path.join(this.$projectData.projectDir, common_1.LOCK_FILE_NAME))) {
await this.verifyHooksLock(pluginsWithHooks, path.join(this.$projectData.projectDir, common_1.LOCK_FILE_NAME));
}
if (pluginsWithHooks.length === 0) {
if (!this.$fs.exists(hooksDir)) {
this.$fs.createDirectory(hooksDir);
}
}
for (const plugin of pluginsWithHooks) {
nsHooks(plugin.fullPath).postinstall();
}
}
}
}
async canExecute(args) {
if (args.length > 0 && args[0] !== "list") {
this.$errors.failWithHelp(`Invalid argument ${args[0]}. Supported argument is "list".`);
}
return true;
}
}
exports.HooksPluginCommand = HooksPluginCommand;
class HooksListPluginCommand extends HooksPluginCommand {
constructor($pluginsService, $projectData, $errors, $fs, $logger) {
super($pluginsService, $projectData, $errors, $fs, $logger);
this.allowedParameters = [];
}
async execute() {
await super.execute(["list"]);
}
}
exports.HooksListPluginCommand = HooksListPluginCommand;
yok_1.injector.registerCommand(["hooks|install"], HooksPluginCommand);
yok_1.injector.registerCommand(["hooks|*list"], HooksListPluginCommand);
//# sourceMappingURL=hooks.js.map