Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/423.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 复制模板文件后重命名文件_Javascript_Visual Studio_Yeoman_Yeoman Generator - Fatal编程技术网

Javascript 复制模板文件后重命名文件

Javascript 复制模板文件后重命名文件,javascript,visual-studio,yeoman,yeoman-generator,Javascript,Visual Studio,Yeoman,Yeoman Generator,我正在基于yeoman的开发一个样本yeoman生成器。生成的默认写入函数如下: generators.Base.extend({ writing: function () { this.fs.copyTpl( this.sourceRoot(), this.destinationRoot()); } }); 我的模板文件包含Visual Studio项目和解决方案文件,因此我希望重命名它们以匹配appName:

我正在基于yeoman的开发一个样本yeoman生成器。生成的默认
写入
函数如下:

generators.Base.extend({
    writing: function () {
        this.fs.copyTpl(
            this.sourceRoot(),
            this.destinationRoot());
    }
});
我的模板文件包含Visual Studio项目和解决方案文件,因此我希望重命名它们以匹配
appName

generators.Base.extend({
    writing: function () {
        this.fs.copyTpl(
            this.sourceRoot(),
            this.destinationRoot(),
            { appname: this.props.appName });

        // Rename directory to match 'appName'
        this.fs.move(
            this.destinationPath('foo'), // A directory
            this.detinationPath(this.props.appName)); // From prompt when user types yo webapp

        // Rename Visual Studio .sln file to match 'appName'
        this.fs.move(
            this.destinationPath('foo/bar.sln'),
            this.destinationPath(this.props.appName + '/' + this.props.appName + '.sln');

       // ...similar renames to Visual Studio .csproj files
    }
});
但是,我在执行第一个
移动的行中得到一个断言错误:

AssertionError: Trying to copy from a source that does not exist
我认为文件/目录复制是同步的,但在第一次调用
this.fs.move
之前运行
this.fs.exists(this.destinationRoot())
时,它返回
false
。我怀疑这与
this.fs
是一个实例有关,在
writing
函数完成之前,目录/文件只存在于内存中


如果需要重命名文件/目录,该怎么办?

如果在复制功能中使用glob模式,该方法是否有效

this.fs.copyTpl(
        this.templatePath('**'),
        this.destinationPath(),
        { appname: this.props.appName });

mem fs操作是同步的,如果文件真的被复制了,exist检查将通过。

不会
这一点。sourceRoot('**')
修改
sourceRoot
?是的,我复制粘贴了您的代码。但是问题是混合了根函数和路径创建者。您需要使用
this.templatePath()
this.destinationPath()
听起来像您需要的吗?