HEX
Server: Apache/2.4.41 (Ubuntu)
System: Linux wordpress-ubuntu-s-2vcpu-4gb-fra1-01 5.4.0-169-generic #187-Ubuntu SMP Thu Nov 23 14:52:28 UTC 2023 x86_64
User: root (0)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/tana/frontend/node_modules/concurrently/src/parseCmds.js
'use strict';
const _ = require('lodash');

const pkgInfo = require('./pkgInfo');

module.exports = function(cmds, config) {
    config = config || {};

    const names = (config.names || '').split(config.nameSeparator || ',');
    const prefixColors = config.prefixColors ? config.prefixColors.split(',') : [];

    cmds = cmds.map(stripCmdQuotes);

    cmds = cmds.map((cmd, idx) => ({
        cmd: cmd,
        name: names[idx] || ''
    }));

    cmds = _.flatMap(cmds, expandCmdShortcuts);

    return cmds.map((cmd, idx) => Object.assign(cmd, {
        color: prefixColors[idx]
    }));
};

function stripCmdQuotes(cmd) {
    // Removes the quotes surrounding a command.
    if (cmd[0] === '"' || cmd[0] === '\'') {
        return cmd.substr(1, cmd.length - 2);
    } else {
        return cmd;
    }
}

function expandCmdShortcuts(cmd) {
    const shortcut = cmd.cmd.match(/^npm:(\S+)(.*)/);
    if (shortcut) {
        const cmdName = shortcut[1];
        const args = shortcut[2];

        const wildcard = cmdName.indexOf('*');
        if (wildcard >= 0) {
            return expandNpmWildcard(cmd, cmdName, wildcard, args);
        }

        if (!cmd.name) {
            cmd.name = cmdName;
        }
        cmd.cmd = `npm run ${cmdName}${args}`;
    }
    return [ cmd ];
}

function expandNpmWildcard(cmd, cmdName, wildcardPos, args) {
    const rePre = _.escapeRegExp(cmdName.substr(0, wildcardPos));
    const reSuf = _.escapeRegExp(cmdName.substr(wildcardPos + 1));
    const wildcardRe = new RegExp(`^${rePre}(.*?)${reSuf}$`);

    return pkgInfo.getScripts()
        .filter(script => script.match(wildcardRe))
        .map(script => Object.assign({}, cmd,  {
            cmd: `npm run ${script}${args}`,
            name: cmd.name + script.match(wildcardRe)[1]
        }));
}