【问题标题】:Yeoman generator - deep copy empty folder structureYeoman 生成器 - 深拷贝空文件夹结构
【发布时间】:2015-10-22 19:02:45
【问题描述】:

给定以下生成器文件夹结构;我正在尝试深度复制“for_copy”文件夹下的所有文件夹。

  • 生成器根
    • 应用程序
    • 模板
      • for_copy
        • 数据
        • 外部
        • 媒体

所有文件夹都是空的。我希望在调用生成器时为我创建这个结构。

我尝试过使用 fs.copy、bulkCopy 和 bulkDirectory。他们都没有做这项工作。

任何关于我如何实现这一目标的线索将不胜感激。

见下面代码sn-p:

writing: function() {
        this.log('Writing templates...');

        //doesn't work
        this.fs.copy(
            this.templatePath('for_copy'),
            this.destinationRoot()
            );

        //doesn't work
        this.bulkCopy(
            this.templatePath('for_copy'),
            this.destinationRoot()
            );

        //doesn't work
        this.bulkDirectory(
            this.templatePath('for_copy'),
            this.destinationRoot()
            );

        //doesn't work
        this.bulkDirectory(
            this.templatePath('for_copy') +'**/*',
            this.destinationRoot()
            );
  }

【问题讨论】:

    标签: copy directory generator yeoman yeoman-generator


    【解决方案1】:

    Yeoman 只关心文件。当您使用bulkDirectory 时,您实际上是在复制文件,而不是目录。

    您可以使用mkdirp 模块来创建目录。

    mkdirp.sync(path.join(this.destinationPath(), 'data'));
    mkdirp.sync(path.join(this.destinationPath(), 'external'));
    // etc ...
    

    【讨论】:

      猜你喜欢
      • 2011-08-31
      • 2022-01-15
      • 1970-01-01
      • 1970-01-01
      • 2011-01-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-09
      相关资源
      最近更新 更多