梦尋Junjie
梦尋Junjie
  • 发布:2022-07-04 19:24
  • 更新:2022-07-04 19:50
  • 阅读:433

easycom custom 过于死板

分类:uni-app

easycom custom 表达条件不灵活,文档说明也是模模糊糊

说是能用正则 ,但是用给定以外的案例正则 却没有办法正常使用

2022-07-04 19:24 负责人:无 分享
已邀请:
梦尋Junjie

梦尋Junjie (作者) - 原来她有男朋友

如果使用
{"vf-(?=[flex,fauto,finitial])":"@/components/vf/flex/$1"}
这种正则 那么

<vf-flex> 触发的查询却是 @/components/vf/flex/$1flex

梦尋Junjie

梦尋Junjie (作者) - 原来她有男朋友

还好会点java

package com.nuohui.app;  

import java.io.File;  
import java.io.FileWriter;  
import java.io.IOException;  
import java.util.function.Consumer;  
import java.util.function.Function;  

import org.json.JSONObject;  
import org.junjie.json.JSON;  

import com.fasterxml.jackson.databind.node.ObjectNode;  

public class PagesEasycom {  

    public static void main(String[] args) throws IOException {  

        File file = new File("D:\\workingSpace\\nuohui\\Charging\\pages.json");  

        ObjectNode parse = (ObjectNode) JSON.parse(file);  

        if (!parse.has("easycom")) {  
            ObjectNode objectNode = parse.objectNode();  
            parse.set("easycom", objectNode);  
        }  
        ObjectNode easycom = (ObjectNode) parse.get("easycom");  
        if (easycom.has("custom")) {  
            ObjectNode objectNode = parse.objectNode();  
            easycom.set("custom", objectNode);  
        }  
        ObjectNode custom = (ObjectNode) easycom.get("custom");  

        // -> 读取  
        File vf = new File("D:\\workingSpace\\nuohui\\Charging\\components\\vf");  

        des(vf, vue -> vue.getName().endsWith(".vue"), (f) -> {  
            String name   = f.getName();  
            String vfName = name.substring(0, name.lastIndexOf('.'));  
            String path   = f.getPath().replaceAll("\\\\", "/");  
            String value  = path.substring(path.indexOf("components"));  
            custom.put(vfName, "@/" + value);  
        });  

        System.err.println(custom);  

        FileWriter fw = new FileWriter(file);  

        fw.write(new JSONObject(parse.toString()).toString(4));  
        fw.flush();  
        fw.close();  

    }  

    public static void des(File file, Function<File, Boolean> filter, Consumer<File> run) {  

        if (file.isFile()) {  
            if (filter.apply(file)) {  
                run.accept(file);  
            }  
        } else if (file.isDirectory()) {  
            File[] listFiles = file.listFiles();  
            for (File file2 : listFiles) {  
                des(file2, filter, run);  
            }  
        }  

    }  

}  

该问题目前已经被锁定, 无法添加新回复