还好会点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);
}
}
}
}
2 个回复
梦尋Junjie (作者) - 原来她有男朋友
如果使用
{"vf-(?=[flex,fauto,finitial])":"@/components/vf/flex/$1"}
这种正则 那么
<vf-flex> 触发的查询却是 @/components/vf/flex/$1flex
梦尋Junjie (作者) - 原来她有男朋友
还好会点java