سؤال

I am using the Grunt copy task in a Gruntfile. The project was created by Yeoman.

I am looking for suggestions on how to simplify the task definition. You'll notice the expand and dest fields are the same for each set of files. Is there a way I can simplify this? Can I use options?

Here is my task

copy: {
  componentsToTmp: {
    files: [
      {
        expand: true,
        cwd: '<%= yeoman.components %>/angular',
        dest: '<%= yeoman.tmp %>/js',
        src: ['angular.min.js']
      },
      {
        expand: true,
        cwd: '<%= yeoman.components %>/angular-bootstrap',
        dest: '<%= yeoman.tmp %>/js',
        src: ['ui-bootstrap-tpls.min.js']
      },
      {
        expand: true,
        cwd: '<%= yeoman.components %>/angular-cookies',
        dest: '<%= yeoman.tmp %>/js',
        src: ['angular-cookies.min.js']
      },
      {
        expand: true,
        cwd: '<%= yeoman.components %>/angular-l10n/build',
        dest: '<%= yeoman.tmp %>/js',
        src: ['l10n.min.js']
      },
      {
        expand: true,
        cwd: '<%= yeoman.components %>/angular-local-storage',
        dest: '<%= yeoman.tmp %>/js',
        src: ['angular-local-storage.min.js']
      },
      {
        expand: true,
        cwd: '<%= yeoman.components %>/angular-resource',
        dest: '<%= yeoman.tmp %>/js',
        src: ['angular-resource.min.js']
      },
      {
        expand: true,
        cwd: '<%= yeoman.components %>/angular-sanitize',
        dest: '<%= yeoman.tmp %>/js',
        src: ['angular-sanitize.min.js']
      },
      {
        expand: true,
        cwd: '<%= yeoman.components %>/angular-ui/build',
        dest: '<%= yeoman.tmp %>/js',
        src: ['angular-ui.min.js']
      },
      {
        expand: true,
        cwd: '<%= yeoman.components %>/angularjs-gravatardirective/src',
        dest: '<%= yeoman.tmp %>/js',
        src: ['md5-service.min.js', 'gravatar-directive.min.js']
      },
      {
        expand: true,
        cwd: '<%= yeoman.components %>/bootstrap/bootstrap/js',
        dest: '<%= yeoman.tmp %>/js',
        src: ['bootstrap.min.js']
      },
      {
        expand: true,
        cwd: '<%= yeoman.components %>/jquery',
        dest: '<%= yeoman.tmp %>/js',
        src: ['jquery.min.js']
      },
      {
        expand: true,
        cwd: '<%= yeoman.components %>/jquery-ui/ui/minified',
        dest: '<%= yeoman.tmp %>/js',
        src: ['jquery-ui.min.js']
      },
      {
        expand: true,
        cwd: '<%= yeoman.components %>/momentjs/min',
        dest: '<%= yeoman.tmp %>/js',
        src: ['moment.min.js']
      },
      {
        expand: true,
        cwd: '<%= yeoman.components %>/qrcode',
        dest: '<%= yeoman.tmp %>/js',
        src: ['qrcode.min.js']
      },
      {
        expand: true,
        cwd: '<%= yeoman.components %>/underscore',
        dest: '<%= yeoman.tmp %>/js',
        src: ['underscore-min.js']
      },
      {
        expand: true,
        cwd: '<%= yeoman.app %>/angular-local-storage-obscure',
        dest: '<%= yeoman.tmp %>/js',
        src: ['angular-local-storage-obscure.js']
      }
    ]
  }
}
هل كانت مفيدة؟

المحلول

Something like this?

copy: {
  components: {
    files: [{
      src: [
        '<%= yeoman.app %>/angular-local-storage-obscure/angular-local-storage-obscure.js',
        '<%= yeoman.components %>/underscore/underscore-min.js',
        '<%= yeoman.components %>/qrcode/qrcode.min.js',
        '<%= yeoman.components %>/momentjs/min/moment.min.js',
        '<%= yeoman.components %>/jquery-ui/ui/minified/jquery-ui.min.js',
        '<%= yeoman.components %>/jquery/jquery.min.js',
        '<%= yeoman.components %>/bootstrap/bootstrap/js/bootstrap.min.js', // etc
      ],
      dest: '<%= yeoman.tmp %>/js',
      expand: true,
      flatten: true,
      filter: 'isFile'
    }]
  }
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top