cordova-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kamrik <...@git.apache.org>
Subject [GitHub] cordova-lib pull request: CB-6481 Add unified hooks support for co...
Date Fri, 11 Jul 2014 14:02:43 GMT
Github user kamrik commented on a diff in the pull request:

    https://github.com/apache/cordova-lib/pull/55#discussion_r14821829
  
    --- 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 --
    
    Not really a guideline but: CordovaError is only printed as the message while Error results
in a full stack trace. So I would say, use CordovaError for errors that you expect to happen
due to bad user input. If it's happening because of bad code that we wrote, it should be an
Error().


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message