2016-06-15 4 views
0

Я пытаюсь переименовать папку в каталоге назначения. Структура каталогов внутри моей templates папки выглядит следующим образом:Переименовать вновь созданный каталог с помощью Yeoman (mem-fs-editor)

root/ 
├── generators 
│ └── app 
│  ├── templates 
│  │ └── app 
│  │  └── widget 
│  │   ├── widget.controller.ts 
│  │   ├── widget.service.ts 
│  │   └── widget.module.ts 
│  └── index.js 
└── .yo-rc.json 

Я пытаюсь переименовать каталог widgetdestinationPath) на имя, которое пользователь вводит во время prompting стадии. Вот как я пытаюсь это:

module.exports = generators.Base.extend({ 
    copyAppTemplate: function() { 
     this.fs.copyTpl(this.templatePath('**/*'), this.destinationPath('.'), this.props); 

     this.fs.move(
      this.destinationPath('app/widget'), 
      this.destinationPath('app/' + this.props.widgetName) 
     ); 
    } 
}) 

Вызов copyTpl правильно подмостей и шаблонирования приложение из templatePath в destinationPath. Однако, когда операция fs.move называется, я получаю следующее сообщение об ошибке:

PS C:\Users\username\code\generator-dashboard-widget-test> yo dashboard-widget 
? Your widget's name: (generator-dashboard-widget-test) 
? Your widget's name: generator-dashboard-widget-test 

events.js:154 
    throw er; // Unhandled 'error' event 
    ^
AssertionError: Trying to copy from a source that does not exist: C:\Users\username\code\generator-dashboard-widget-test\app\widget 
    at EditionInterface.exports._copySingle (C:\Users\username\code\generator-dashboard-widget\node_modules\mem-fs-editor\lib\actions\copy.js:45:3) 
    at EditionInterface.exports.copy (C:\Users\username\code\generator-dashboard-widget\node_modules\mem-fs-editor\lib\actions\copy.js:23:17) 
    at EditionInterface.module.exports [as move] (C:\Users\username\code\generator-dashboard-widget\node_modules\mem-fs-editor\lib\actions\move.js:4:8) 
    at module.exports.generators.Base.extend.copyAppTemplate (C:\Users\username\code\generator-dashboard-widget\generators\app\index.js:54:17) 
    at Object.<anonymous> (C:\Users\username\code\generator-dashboard-widget\node_modules\yeoman-generator\lib\base.js:431:23) 
    at C:\Users\username\code\generator-dashboard-widget\node_modules\run-async\index.js:26:25 
    at C:\Users\username\code\generator-dashboard-widget\node_modules\run-async\index.js:25:19 
    at C:\Users\username\code\generator-dashboard-widget\node_modules\yeoman-generator\lib\base.js:432:9 
    at processImmediate [as _immediateCallback] (timers.js:383:17) 

Из того, что я понял из Yeoman file system documenation, все действия на виртуальной файловой системе являются синхронными, поэтому каталог app/widget должен существовать до mem-fs-editor экземпляр пытается переместить его.

Есть ли другой способ переименовать каталог?

Я использую Yeoman 1.8.4 на Windows 8.1 с узлом 5.6.0.

ответ

0

Я не выяснял этот конкретный вопрос, но я был в состоянии сделать то, что я был после того, как с помощью gulp-rename плагина, как преобразование потока:

copyAppTemplate: function() { 
    var _this = this; 

    // move a file like "app/widget/widget.controller.ts" to 
    // "app/my-widget-name/my-widget-name.controller.ts" 
    this.registerTransformStream(rename(function (path) { 
     path.dirname = path.dirname.replace('widget', _this.props.widgetName); 
     path.basename = path.basename.replace('widget', _this.props.widgetName); 
     return path; 
    })); 

    this.fs.copyTpl(this.templatePath('**/*'), this.destinationPath('.'), this.props); 
}, 

Я также открыл вопрос GitHub для наблюдения за этим поведением здесь: https://github.com/yeoman/yo/issues/455

 Смежные вопросы

  • Нет связанных вопросов^_^