1. ホーム
  2. javascript

[解決済み] grunt-contrib-copyの "expand "オプションは、何をするのですか?サンプルはすべてそれを使っていますが、ドキュメントにはそれが何をするものなのか何も書かれていません。

2023-01-02 12:13:53

質問

  1. READMEとサンプルはこちらです。 https://github.com/gruntjs/grunt-contrib-copy/blob/master/README.md .
  2. 以下は、(どうやら私には理解できない)コードの関連部分です。 https://github.com/gruntjs/grunt-contrib-copy/blob/master/tasks/copy.js :
module.exports = function(grunt) {。
  'use strict' を使用します。

  var path = require('path');

  grunt.registerMultiTask('copy', 'ファイルをコピーする。', function() {)
    var kindOf = grunt.util.kindOf;

    var options = this.options({
      processContent: false,
      processContentExclude: []
    });

    var copyOptions = {
      process: オプション.processContent,
      noProcess: オプション.processContentExclude
    };

    grunt.verbose.writeflags(options, 'オプション');

    var dest;
    var isExpandedPair;
    var tally = {
      dirs: 0,
      files: 0
    };

    this.files.forEach(function(filePair) {)
      isExpandedPair = filePair.orig.expand || false;

      filePair.src.forEach(function(src))の場合{。
        if (detectDestType(filePair.dest) === 'directory') {。
          dest = (isExpandedPair) ? filePair.dest : unixifyPath(path.join(filePair.dest, src));
        } else {
          dest = filePair.dest;
        }

        if (grunt.file.isDir(src)) {。
          grunt.verbose.writeln('Creating ' + dest.cyan);
          grunt.file.mkdir(dest)を実行します。
          tally.dirs++;
        } else {
          grunt.verbose.writeln('Copying ' + src.cyan + ' -> ' + dest.cyan).を実行します。
          grunt.file.copy(src, dest, copyOptions);
          tally.files++;
        }
      });
    });

どのように解決するのですか?

Expand では、宛先のパスを完全に作成するかどうかを指定できます (たとえば /path/missing1/missing2 など)、あるいは親が存在するときに最後のディレクトリだけを作成するか ( /path/existing/missing ).