-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsyncAntd5.js
161 lines (145 loc) · 4.84 KB
/
syncAntd5.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/** 获取相对路径 */
const getRelativePath = (path1, path2) => {
const relativePath = path.relative(path.dirname(path1), path.dirname(path2));
if (relativePath === ".") {
return path.basename(path2)
}
return path.join(relativePath, path.basename(path2));
}
/** 创建文件同时创建文件夹 */
function createFileWithDirs(filePath, fileContent = '') {
// console.log("写文件: ", filePath);
// 提取目录路径
const dirPath = path.dirname(filePath);
// 递归创建目录
fs.mkdirSync(dirPath, { recursive: true });
fs.writeFileSync(filePath, fileContent, "utf-8");
}
// 目标基准路径
const baseDir = 'antd5';
const fs = require("fs");
const path = require("path");
const antd5Path = path.resolve(__dirname, "./antd5");
console.log("antd5Path: ", antd5Path)
if (!fs.existsSync(antd5Path)) {
fs.mkdirSync(antd5Path);
}
const json = require("./pub.mybricks.json");
const { comAry } = json;
const antd5ComAry = [];
const TraversalComAry = (comAry, antd5ComAry) => {
comAry.forEach((com) => {
if (typeof com === "string") {
// 直接读
antd5ComAry.push(path.join(baseDir, com))
const jsonPath = path.resolve(__dirname, com);
const antd5JsonPath = path.resolve(antd5Path, com);
const json = require(jsonPath);
const {
namespace,
target, // 废弃
...other
} = json;
const split = namespace.split(".");
split.splice(split.length - 1, 0, "antd5");
const antd5Json = {
namespace: split.join(".")
// namespace
}
const isUi = !json.rtType; // 没有rtType是ui组件;
Object.entries(other).forEach(([key, value]) => {
if (typeof value === "string") {
try {
const filePath = path.resolve(path.dirname(jsonPath), value)
if (fs.existsSync(filePath)) {
if (key === "runtime") {
if (isUi) {
antd5Json[key] = "./runtime.tsx";
// createFileWithDirs(path.resolve(antd5JsonPath, "../runtime.tsx"), `
// import React, { useRef } from "react";
// import { StyleProvider } from "@ant-design/cssinjs";
// import Runtime from "${getRelativePath(antd5JsonPath, filePath)}";
// export default function (props) {
// const container = useRef((props.env.edit || props.env.runtime.debug) ? document.querySelector("#_mybricks-geo-webview_")!.shadowRoot : null);
// return (
// <StyleProvider container={container.current!} hashPriority="high">
// <Runtime {...props} />
// </StyleProvider>
// )
// }
// `);
createFileWithDirs(path.resolve(antd5JsonPath, "../runtime.tsx"), `
import Runtime from "${getRelativePath(antd5JsonPath, filePath)}";
export default Runtime
`);
} else {
antd5Json[key] = getRelativePath(antd5JsonPath, filePath);
}
} else {
antd5Json[key] = getRelativePath(antd5JsonPath, filePath);
}
} else {
antd5Json[key] = value;
}
} catch (e) {
antd5Json[key] = value;
}
} else {
antd5Json[key] = value
}
})
createFileWithDirs(antd5JsonPath, JSON.stringify(antd5Json, null, 2));
} else {
const { title, comAry } = com;
const next = [];
TraversalComAry(comAry, next);
antd5ComAry.push({
title,
comAry: next
});
}
})
}
TraversalComAry(comAry, antd5ComAry);
// createFileWithDirs(path.resolve(__dirname, "pub.antd5.mybricks.json"), JSON.stringify({
// "name": "基础组件库(antd5)",
// "namespace": "mybricks.basic-comlib.antd5",
// "commitInfo": "update",
// comAry: antd5ComAry,
// "externals": [
// {
// "name": "@ant-design/cssinjs",
// "library": "antdCssinjs",
// "urls": [
// "public/antd/cssinjs.min.js"
// ]
// },
// {
// "name": "dayjs",
// "library": "dayjs",
// "version": "1.11.13",
// "urls": [
// "public/dayjs/dayjs@1.11.13.min.js",
// "public/dayjs/locale/zh-cn.min.js"
// ]
// },
// {
// "name": "@ant-design/icons",
// "library": "icons",
// "urls": [
// "public/ant-design-icons@4.7.0.min.js"
// ]
// },
// {
// "name": "antd",
// "library": "antd_5_21_4",
// "version": "5.21.4",
// "urls": [
// "public/antd/antd@5.21.4.min.js",
// "public/antd/locale/zh_CN.js"
// ]
// }
// ],
// "tags": "react",
// "webpackConfig": "./webpack.config.antd5.js"
// }, null, 2));