Как написать скрипт для grunt uglify? - PullRequest
0 голосов
/ 06 сентября 2018

пытается написать скрипт, чтобы сделать проект грандиозным с помощью запускающего задачи grunt и добавить скрипт в package.json, чтобы он создавался и расширялся при запуске скрипта.

package.json

  "scripts": {
    "start-prod": "npm run build-prod && npm run post-build",
    "start": "npm run lint && npm run build && npm run post-build",
    "runperfmon": "node --prof  server.js",
    "perfmon": "npm run build && npm run runperfmon",
    "build": "grunt dist --verbose",
    "post-build": "nodemon server.js",
    "setup": "rimraf package-lock.json && npm i && npm update && grunt sym_link:local && rimraf node_modules/@cvsdigital_caremark && rimraf dist",
    "watch": "grunt watch_dev",
    "lite": "grunt lite && nodemon server.js",
    "lint": "tslint -c tslint.json 'src/**/*.ts'",
    "storm": "grunt lite"
  }

Gruntfile.js

module.exports = function(grunt) {
    var package = require('./package.json');

    grunt.option('projectName', package.name);
    grunt.option('projectVersion', package.version);
    var os = require('os');
    var ifaces = os.networkInterfaces();
    var lookupIpAddress = null;
    for (var dev in ifaces) {
        if (dev != "en1" && dev != "en0") {
            continue;
        }
        ifaces[dev].forEach(function (details) {
            if (details.family == 'IPv4' && lookupIpAddress === null) {
                lookupIpAddress = details.address;
            }
        });
    }
    var ipAddress = grunt.option('host') || lookupIpAddress;

    require("load-grunt-tasks")(grunt);
    grunt.loadNpmTasks("grunt-typedoc");
    grunt.loadNpmTasks('grunt-contrib-watch');
    // grunt.loadNpmTasks('grunt-contrib-concat');
    //  grunt.loadNpmTasks('grunt-contrib-connect');
    grunt.loadNpmTasks('grunt-contrib-uglify-es');
    grunt.loadNpmTasks('grunt-tslint');
    grunt.loadNpmTasks('grunt-ts');
    grunt.loadNpmTasks('grunt-contrib-clean');
    grunt.loadNpmTasks('grunt-contrib-copy');
    grunt.loadNpmTasks('grunt-npm-command');
    grunt.loadNpmTasks('grunt-bump');
    grunt.loadNpmTasks('grunt-exec');

    // grunt.loadNpmTasks('grunt-contrib-rename');
    // grunt.loadNpmTasks('grunt-string-replace');

    var options = {
        config: {
            src: "./grunt-task-config/*.js"
        },
        projectName: grunt.option('projectName'),
        projectVersion: grunt.option('projectVersion'),
        ipAddress: ipAddress
    };
    var configs = require('load-grunt-configs')(grunt, options);
    grunt.initConfig(configs);
    grunt.cli.tasks.forEach(function (task) {
        if (task.indexOf('build:') !== -1 || task.indexOf('dev:') !== -1) {
            options.client = task.split(':')[1];
        }
    });

    grunt.registerTask('build', function () {
        grunt.task.run([
            'dist:build'
        ]);
    });

    grunt.registerTask('dist', function (env) {
        grunt.task.run([
            'clean:start',
            'tslint',
            'ts:src',
            'copy:data',
            'clean:final',
            'uglify:node'
        ]);
    });

    grunt.registerTask('sym_link', function (env) {
        if (env === 'local' && package.symlink.enable === 'true') {
            grunt.task.run([
                'shell:selfLink',
                'shell:targetLink'
            ]);
        }
    });

    grunt.registerTask('lite', function (env) {
        grunt.task.run([
            'clean:start',
            'ts:lite',
            'clean:final'
        ]);
    });



    var configs = require('load-grunt-configs')(grunt, options);
    grunt.initConfig(configs);

    grunt.registerTask('update_node_package_json', function(filePath, key, value) {
        var projectFile = filePath + "package.json";
        if(!grunt.file.exists(projectFile)) {
            grunt.log.error("file " + projectFile + " not found");
            return true; //return false to abort the execution
        }
        var project = grunt.file.readJSON(projectFile);
        project[key] = value;
        grunt.file.write(projectFile, JSON.stringify(project, null, 2));
    });



};

uglify.js

module.exports = {
    node: {
        files: [
            {
                expand: true,
                src: ['dist/node/compiled.non-min.core/**/*.js'],
                dest: 'dist/node/compiled.min.core',
                cwd: '.',
                rename: function (destBase, destPath) {
                    return destPath.replace('dist/node/compiled.non-min.core/', 'dist/node/compiled.min.core/');
                }
            }
        ]
    }
};

Ошибка

Running "uglify:node" (uglify) task
Verifying property uglify.node exists in config...OK
Options: banner="", footer="", compress={}, mangle={}, beautify=false, report="min", ie8=false
>> No files created.
...