Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/446.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 Can';t使用Promise、catch和gulp将文件写入dist文件夹_Javascript_Node.js_Gulp - Fatal编程技术网

Javascript Can';t使用Promise、catch和gulp将文件写入dist文件夹

Javascript Can';t使用Promise、catch和gulp将文件写入dist文件夹,javascript,node.js,gulp,Javascript,Node.js,Gulp,我正在将index.html文件映射到刮取标记内容并另存为名为font.css的文件 这是我的风格: <style>@font-face{font-family:Averti;src:url(https://services.serving-sys.com/HostingServices/custdev/site-140253/Averti/Averti-Bold.woff) format('truetype');font-weight:700;font-style:normal}@

我正在将index.html文件映射到刮取标记内容并另存为名为font.css的文件

这是我的风格:

<style>@font-face{font-family:Averti;src:url(https://services.serving-sys.com/HostingServices/custdev/site-140253/Averti/Averti-Bold.woff) format('truetype');font-weight:700;font-style:normal}@font-face{font-family:Averti-Light;src:url(https://services.serving-sys.com/HostingServices/custdev/site-140253/Averti_Webfonts/Averti-Light.woff) format('truetype');font-weight:400;font-style:normal}</style>

我在./dist文件夹中创建了css和js文件夹,代码工作起来很有魅力。除此之外,错误消息会出现在控制台中。

如果您的代码被正确地拆分为单独的行,并且缩进匹配,则会更容易提供帮助。
/dist/css
是否存在?/dist/css不存在,因为它是一个gulp任务,并且假设在运行gulp时创建它。缩进不正确,因为在编辑器中放置代码时,它来自代码区域。index.html存在于dist文件夹中
async function createStyle(){

var jsonObject = [] 

setTimeout(function(){  

fs.readFile('./dist/index.html', 'utf8',  function(err, html){
    if (!err){
        const $ = cheerio.load(html)
        var cssScript = $('head > style').map(( i, x ) => x.children[0])
                                         .filter(( i, x ) => x && x.data.match(/@font-face/)).get(0);
        jsonObject.push(cssScript)
        exportStyle(jsonObject)
    }
})}, 2000); 

async function exportStyle(_json) {

const stylePromise = new Promise(function(resolve, reject) {

    fs.writeFile('./dist/css/fonts.css', _json, err => {
        if (err) {
            reject();
        } else {                                
            resolve();
            console.log('Created: fonts.css');                                                     
        }            
        console.log(err);                             
        });
});
       (async function() {
           try {
                await stylePromise;
         } catch(err) {
                console.log(err);
         }
})();}}