Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Renaming a newly created directory throws "Trying to copy from a source that does not exist" error #455

Closed
nfriend opened this issue Jun 15, 2016 · 3 comments

Comments

@nfriend
Copy link

nfriend commented Jun 15, 2016

I'm trying to rename a folder in the destination directory. The directory structure inside my templates folder looks like this:

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

I'm trying to rename the widget directory (in destinationPath) to a name that the user enters during the prompting stage. Here's how I'm attempting this:

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)
        );
    }
})

The call to copyTpl is correctly scaffolding and templating the app from the templatePath to the destinationPath. However, when the fs.move operation is called, I get the following error message:

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)

From what I understand from the Yeoman file system documenation, all actions on the virtual file system are synchronous, so the app/widget directory should exist before the mem-fs-editor instance attempts to move it.

Is there a different way I should be renaming the directory?

Here's some debug info:

1.8.4
C:\ProgramData\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\Sy
stem32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\W
iFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files\Sa
feNet\Authentication\SAC\x64;C:\Program Files\SafeNet\Authentication\SAC\x32;C:\
Program Files\Microsoft SQL Server\120\Tools\Binn\;C:\Users\username\AppData\Roa
ming\nvm;C:\Program Files\nodejs;C:\Program Files (x86)\sbt\\bin;C:\Program File
s\Git\cmd;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files
 (x86)\Bitvise SSH Client;C:\Python27;C:\Program Files (x86)\Windows Kits\8.1\Wi
ndows Performance Toolkit\;C:\Program Files (x86)\PDFtk Server\bin\;C:\Program F
iles (x86)\Microsoft VS Code\bin;C:\Users\username\AppData\Roaming\npm;C:\Users\
username\AppData\Roaming\nvm;C:\Program Files\nodejs;C:\Users\username\AppData\L
ocal\atom\bin %NODE_PATH%
win32 { http_parser: '2.6.1',
  node: '5.6.0',
  v8: '4.6.85.31',
  uv: '1.8.0',
  zlib: '1.2.8',
  ares: '1.10.1-DEV',
  icu: '56.1',
  modules: '47',
  openssl: '1.0.2f' }
The system cannot find the file specified.

I'm on Windows 8.1.

@nfriend
Copy link
Author

nfriend commented Jun 15, 2016

Update: I was able to accomplish what I wanted by registering the gulp-rename plugin as a transform stream:

copyAppTemplate: function () {
    var _this = this;
    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);
},

@SBoudrias
Copy link
Member

I think the issue is the virtual file system doesn't store references to folders. It might work using a glob pattern, but I'm not sure glob matching if going to work over the virtual files.

This is a bug.

Would you mind reopening on the relevant repo https://github.com/SBoudrias/mem-fs-editor

Yo is only the UI layer, the ticket is going to get lost if it stays here.

@nfriend
Copy link
Author

nfriend commented Jun 15, 2016

Thanks for the response. I've created a similar issue on the mem-fs-editor repo: SBoudrias/mem-fs-editor#61

@nfriend nfriend closed this as completed Jun 15, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants