Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.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
Vue.js 如何在Nuxt中使用fs extra复制文件和文件夹_Vue.js_Nuxt.js_Fs_Chokidar_Fs Extra - Fatal编程技术网

Vue.js 如何在Nuxt中使用fs extra复制文件和文件夹

Vue.js 如何在Nuxt中使用fs extra复制文件和文件夹,vue.js,nuxt.js,fs,chokidar,fs-extra,Vue.js,Nuxt.js,Fs,Chokidar,Fs Extra,我使用的是Nuxtjs 2.15.4,我正在尝试为我的应用程序创建多个主题 流程非常简单:我有一个themes文件夹,其中包含我的themes文件夹。在nuxt build/dev中,将调用一个模块: const path=require('path')) const chokidar=require('chokidar'); 常数fse=需要('fs-extra'); 导出默认异步函数(moduleOptions){ //moduleOptions.themeName='newtheme'&m

我使用的是Nuxtjs 2.15.4,我正在尝试为我的应用程序创建多个主题

流程非常简单:我有一个
themes
文件夹,其中包含我的themes文件夹。在nuxt build/dev中,将调用一个模块:

const path=require('path'))
const chokidar=require('chokidar');
常数fse=需要('fs-extra');
导出默认异步函数(moduleOptions){
//moduleOptions.themeName='newtheme'&moduleOptions.CustomizeName='false'
const themeName=moduleOptions.themeName
const defaultThemeDir=path.join(this.options.rootDir'。/themes/main')
const newThemeDir=path.join(this.options.rootDir'./themes/'+moduleOptions.themeName)
const sourceDir=path.join(this.options.rootDir,'./'))
const emptySourceDir=async()=>{
emptyDir(path.join(this.options.rootDir,'assets'))
emptyDir(path.join(this.options.rootDir,'components'))
emptyDir(path.join(this.options.rootDir,'layouts'))
emptyDir(path.join(this.options.rootDir,'middleware'))
emptyDir(path.join(this.options.rootDir,'pages'))
emptyDir(path.join(this.options.rootDir,'plugins'))
emptyDir(path.join(this.options.rootDir,'static'))
}
const copyThemesDirectory=async()=>{
等待fse.copy(path.join(defaultThemeDir,'base')、sourceDir)
if(themeName!=“main”){
等待fse.copy(path.join(newThemeDir,'base'),sourceDir)
}
if(moduleOptions.CustomizeTime==='true'){
等待fse.copy(path.join(newThemeDir,'custom')、sourceDir)
}
}
const toTargetPath=(旧路径)=>{
让newPath=oldPath.replace(this.options.rootDir“”)
.replace(“\\themes\\main\\base\\”,“\\”)
.replace(“\\themes\\main\\custom\\”,“\\”)
.replace(“\\themes\\”+themeName+“\\base\\”,“\\”)
.replace(“\\themes\\”+themeName+“\\custom\\”,“\\”)
返回path.join(this.options.rootDir,newPath)
}
等待清空资源
等待copyThemesDirectory()
if(process.env.NODE_env===‘development’){
在('all',异步(事件,文件路径)=>{
如果(事件=='add'| |事件=='change'){
fse.copy(文件路径,toTargetPath(文件路径))
}
如果(事件=='unlink'){
删除(toTargetPath(文件路径))
}
})
}
}
它将清空nuxt根目录中的一些文件夹,然后将
themes/main/base
复制到其中。之后,它将检查主题名是否不是“main”,并将
themes/{themeName}/base
复制到根目录中。然后它将检查定制选项,如果为true,它将把
theme/{themeName}/custom
文件夹复制到根目录

这部分做得没有问题!第二部分是
开发
模式,它告诉我这样的错误:这些文件(添加到新主题或自定义中的新文件)不存在

在chokidar的帮助下,查看我的主题文件夹,如果有任何更改,它将删除或复制根目录中的内容。如果主主题库文件夹中存在相同的文件,则会显示错误

我甚至尝试了
fse.copy(filePath,toTargetPath(filePath),{overwrite:true})
fse.copySync(filePath,toTargetPath(filePath),{overwrite:true})

下面是一个错误示例:

错误enoint:没有这样的文件或目录,请取消链接“{my local directory}\components\global\footer\sub\links.vue”

有人知道它有什么问题吗??它还可以运行watch
change
add
部分,即使是在第一次尝试时,也可以简单地从主题复制到根目录

#更新

看起来即使在构建中也有错误。我建造,它给我

Error: ENOENT: no such file or directory, mkdir '/var/www/static/images/folder'
然后,当我构建它时,再次运行,没有错误。这是我的主题文件夹结构:

-themes
|__ main
|   |__base
|   |   |__assets
|   |   |__components
|   |   |__middleware
|   |   |__layouts
|   |   |__pages
|   |   |__plugins
|   |   |__static
|   |
|   |__custom
|
|__ newtheme
    |__base
    |__custom

真的不确定这里发生了什么(不用于这种结构重写),但是这里没有任何异步问题吗?比如说,如果一个文件夹没有创建完成,你就依赖它了?我发现问题在于重写。当存在重复文件时,它会抛出一个错误,即在目标文件夹中找不到该文件,并创建目录,然后在第二次尝试时,它将复制该文件。可能有一个标志,如bash中的
mkdir-p