[ https://issues.apache.org/jira/browse/CB-6481?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14058776#comment-14058776 ]
ASF GitHub Bot commented on CB-6481: ------------------------------------ Github user kamrik commented on a diff in the pull request: https://github.com/apache/cordova-lib/pull/55#discussion_r14820487 --- Diff: cordova-lib/src/hooks/ScriptsFinder.js --- @@ -0,0 +1,158 @@ +/** + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + */ + +var path = require('path'), + fs = require('fs'), + cordovaUtil = require('../cordova/util'), + events = require('../events'), + Q = require('q'), + plugin = require('../cordova/plugin'), + PluginInfo = require('../PluginInfo'), + ConfigParser = require('../configparser/ConfigParser'), + CordovaError = require('../CordovaError'), + Context = require('./Context'); + +/** + * Implements logic to retrieve hook script files defined in special folders and configuration + * files: config.xml, hooks/hook_type, plugins/../plugin.xml, etc + */ +module.exports = { + /** + * Returns all script files for the hook type specified. + */ + getHookScripts: function(hook, opts) { + // args check + if (!hook) { + throw new CordovaError('hook type is not specified'); + } + return getApplicationHookScripts(hook, opts) + .concat(getPluginsHookScripts(hook, opts)); + } +}; + +/** + * Returns script files defined on application level. + * They are stored in .cordova/hooks folders and in config.xml. + */ +function getApplicationHookScripts(hook, opts) { + // args check + if (!hook) { + throw new CordovaError('hook type is not specified'); + } + return getApplicationHookScriptsFromDir(path.join(opts.projectRoot, '.cordova', 'hooks', hook)) + .concat(getApplicationHookScriptsFromDir(path.join(opts.projectRoot, 'hooks', hook))) + .concat(getScriptsFromConfigXml(hook, opts)); +} + +/** + * Returns script files defined by plugin developers as part of plugin.xml. + */ +function getPluginsHookScripts(hook, opts) { + // args check + if (!hook) { + throw new CordovaError('hook type is not specified'); --- End diff -- I think this should be Error rather than CordovaError. If we get here, it means something went very wrong, probably it's a but, not a case of bad user input or other problems we expect to happen occasionally. > Add unified hooks support for cordova app and plugins > ----------------------------------------------------- > > Key: CB-6481 > URL: https://issues.apache.org/jira/browse/CB-6481 > Project: Apache Cordova > Issue Type: New Feature > Components: CLI, Plugman > Reporter: Sergey Grebnov > Assignee: Sergey Grebnov > > As per "Proposal: hooks support for plugins" dev mail thread discussion > Hi, I have an idea how we can add more flexibility to plugin developers. > Note, right now we have Application Developers – someone who use Cordova for > developing applications and Plugin Developers – someone who creates plugins > so that Application Developers can use them. For Application Developers we > expose hooks so that they can customize their build/package/etc process. I > want us to provide similar sort of flexibility to Plugin Developers so that > they can go beyond of <source/>, <framework/> tags and get mechanism to add > custom installation, build logic required by a plugin. Example usage will > include: downloading/compiling additional binaries, marking source file to be > copied to output dir, changing target build platform, etc. At present time > the steps described could be only achieved by hooks manually added by > Application Developer, but the right way is to allow Plugin Developer to > expose this as part of plugin definition. > Example configuration could look like > ``` > <script type="postinstall" src="scripts/postinstall.js" /> > <script type="preinstall" src="scripts/preinstall.js" /> > <script type="install" src="scripts/install.js" /> > ``` > beforeinstall/preinstall – run before plugin is installed > install/postinstall/afterinstall – run after plugin is installed > uninstall – run after plugin is uninstalled -- This message was sent by Atlassian JIRA (v6.2#6252)