Исправление Gruntfile.js после обновления версии - PullRequest
0 голосов
/ 24 апреля 2019

У меня есть приложение Sails.js с устаревшим кодом. Первоначальный разработчик приложения следовал этому ответу Stackoverflow, чтобы организовать рабочие задачи и структуру каталогов для них. Однако с Grunt ^ 1.0.4 Gruntfile.js выдает следующую ошибку при сборке:

Loading "Gruntfile.js" tasks...ERROR
>> TypeError: tasks[taskName] is not a function

Я использую пряжу для сборки проекта Sails.js также с:

yarn && grunt buildProd && pm2 start production.config.js

Есть идеи, как это исправить? Нужно ли мне удалять этот код и загружать каждую задачу вручную в зависимости от пути? Любая помощь будет принята с благодарностью!

Gruntfile.js:

/**
 * Gruntfile
 *
 * This Node script is executed when you run `grunt` or `sails lift`.
 * It's purpose is to load the Grunt tasks in your project's `tasks`
 * folder, and allow you to add and remove tasks as you see fit.
 * For more information on how this works, check out the `README.md`
 * file that was generated in your `tasks` folder.
 *
 * WARNING:
 * Unless you know what you're doing, you shouldn't change this file.
 * Check out the `tasks` directory instead.
 */

module.exports = function(grunt) {

    // Load the include-all library in order to require all of our grunt
    // configurations and task registrations dynamically.
    var includeAll;
    try {
        includeAll = require('include-all');
    } catch (e0) {
        try {
            includeAll = require('sails/node_modules/include-all');
        }
        catch(e1) {
            console.error('Could not find `include-all` module.');
            console.error('Skipping grunt tasks...');
            console.error('To fix this, please run:');
            console.error('npm install include-all --save`');
            console.error();

            grunt.registerTask('default', []);
            return;
        }
    }

    /**
     * Loads Grunt configuration modules from the specified
     * relative path. These modules should export a function
     * that, when run, should either load/configure or register
     * a Grunt task.
     */
    function loadTasks(relPath) {
        return includeAll({
            dirname: require('path').resolve(__dirname, relPath),
            filter: /(.+)\.js$/
        }) || {};
    }

    /**
     * Invokes the function from a Grunt configuration module with
     * a single argument - the `grunt` object.
     */
    function invokeConfigFn(tasks) {
        for (var taskName in tasks) {
            if (tasks.hasOwnProperty(taskName)) {
                tasks[taskName](grunt);
            }
        }
    }

    // Load task functions
    var taskConfigurations = loadTasks('./tasks/config'),
        registerDefinitions = loadTasks('./tasks/register');

    // (ensure that a default task exists)
    if (!registerDefinitions.default) {
        registerDefinitions.default = function (grunt) { grunt.registerTask('default', []); };
    }

    // Run task functions to configure Grunt.
    invokeConfigFn(taskConfigurations);
    invokeConfigFn(registerDefinitions);

};

package.json:

"dependencies": {
    "angular": "^1.7.8",
    "angular-google-maps": "^2.4.1",
    "angular-multiple-select": "^1.1.3",
    "async": "^2.6.2",
    "aws-sdk": "^2.441.0",
    "bluebird": "^3.5.4",
    "blueimp-md5": "^2.10.0",
    "bootstrap-select": "^1.13.10",
    "browserify": "^16.2.3",
    "buffer-equal-constant-time": "^1.0.1",
    "csv": "^5.1.1",
    "ejs": "^2.6.1",
    "grunt": "^1.0.4",
    "grunt-cli": "1.2.0",
    "grunt-contrib-clean": "^2.0.0",
    "grunt-contrib-concat": "~1.0.1",
    "grunt-contrib-copy": "~1.0.0",
    "grunt-contrib-cssmin": "~3.0.0",
    "grunt-contrib-less": "2.0.0",
    "grunt-contrib-uglify": "3.3.0",
    "grunt-contrib-watch": "~1.1.0",
    "grunt-sails-linker": "~1.0.4",
    "grunt-sync": "~0.8.0",
    "include-all": "^4.0.3",
    "is-my-json-valid": "^2.19.0",
    "jsforce": "^1.9.1",
    "jsonwebtoken": "^8.5.1",
    "level": "^5.0.1",
    "lodash": "^4.17.11",
    "moment": "^2.24.0",
    "moment-timezone": "^0.5.25",
    "mysql": "^2.17.1",
    "nested-pop": "^0.1.4",
    "ngmap": "^1.18.5",
    "node-where": "^1.1.0",
    "nodemailer": "^6.1.1",
    "passport": "^0.4.0",
    "passport-http-bearer": "^1.0.1",
    "passport-jwt": "^4.0.0",
    "passport-local": "^1.0.0",
    "q": "^1.5.1",
    "qr-image": "^3.2.0",
    "randomstring": "^1.1.5",
    "rc": "^1.2.8",
    "robots.txt": "^1.1.0",
    "s3-streaming-upload": "^0.2.3",
    "sails": "^1.1.0",
    "sails-mysql": "^1.0.1",
    "skipper-s3": "^0.6.0",
    "sms-global-js": "^1.0.0",
    "stream-mmmagic": "^2.1.0",
    "stripe": "^6.30.0",
    "uuid": "^3.3.2",
    "winston": "^3.2.1",
    "winston-logentries": "^3.0.0"
  },
...