program story

grunt-contrib-copy에서“확장”옵션은 무엇을합니까?

inputbox 2020. 8. 22. 08:47
반응형

grunt-contrib-copy에서“확장”옵션은 무엇을합니까? 예제는 모두 그것을 사용하지만 문서는 그것이하는 일에 대해 아무것도 말하지 않습니다.


  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) {
  '엄격한 사용';

  var path = require ( 'path');

  grunt.registerMultiTask ( 'copy', 'Copy files.', function () {
    var kindOf = grunt.util.kindOf;

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

    var copyOptions = {
      프로세스 : options.processContent,
      noProcess : options.processContentExclude
    };

    grunt.verbose.writeflags (options, 'Options');

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

    this.files.forEach (function (filePair) {
      isExpandedPair = filePair.orig.expand || 그릇된;

      filePair.src.forEach (function (src) {
        if (detectDestType (filePair.dest) === '디렉터리') {
          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 ++;
        }
      });
    });

확장을 사용하면 대상 경로를 전체 (예 :)로 만들 것인지 아니면 /path/missing1/missing2부모가있을 때 마지막 디렉토리 만 만들 것인지 () 지정할 수 있습니다 /path/existing/missing.


때문에 expand불평 소리의 일부가 꿀꿀-있는 contrib 복사에 대한 구체적인 아니라,에 대한 정보는에서 찾을 수 있습니다 그런트의 파일 구성 API :

설정 expand하기 위해 true다음과 같은 옵션을 사용하려면 :

  • cwd모든 src일치 항목은이 경로를 기준으로합니다 (포함하지 않음).
  • src를 기준으로 일치시킬 패턴 cwd입니다.
  • dest 대상 경로 접두사.
  • ext생성 된 dest경로 에서 기존 확장을이 값으로 바꿉니다 .
  • extDot Used to indicate where the period indicating the extension is located. Can take either 'first' (extension begins after the first period in the file name) or 'last' (extension begins after the last period), and is set by default to 'first'.
  • flatten Remove all path parts from generated dest paths.
  • rename This function is called for each matched src file, (after extension renaming and flattening). The dest and matched src path are passed in, and this function must return a new dest value. If the same dest is returned more than once, each src which used it will be added to an array of sources for it.

Additionally it seems like dest will always be considered to be a destination directory if setting expand to true.

참고URL : https://stackoverflow.com/questions/16977884/what-does-the-expand-option-do-in-grunt-contrib-copy-the-examples-all-use-it

반응형