-
Notifications
You must be signed in to change notification settings - Fork 324
Expand file tree
/
Copy pathinit.js
More file actions
125 lines (97 loc) · 2.89 KB
/
init.js
File metadata and controls
125 lines (97 loc) · 2.89 KB
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
const path = require('path');
const fs = require('fs');
const glob = require('glob');
const { deleteFolder } = require('t-comm');
const { config } = require('./config');
const { copyComponents, checkVue2CliExist, checkVue2HxExist, checkVue3HxExist } = require('./helper');
const { generateDts } = require('../release/typescript');
async function copyOneProject({
globMode,
sourceDir,
isChat,
}) {
const list = glob.sync(globMode, {
ignore: '**/node_modules/**/*',
nodir: true,
}).filter(item => !item.includes('node_modules'));
for (const item of list) {
const relativePath = path.relative(sourceDir, item);
await copyComponents({
relativePath,
filePath: item,
isChat,
});
}
console.log(`[Wrote] done! Length is ${list.length}!`);
}
function clearTargetDir() {
deleteFolder(config.componentTargetDirInVue3Cli);
deleteFolder(config.componentTargetDirInApp);
deleteFolder(config.pagesMoreDirInVue3Cli);
deleteFolder(config.pagesMoreDirInApp);
if (checkVue2CliExist()) {
deleteFolder(config.componentTargetDirInVue2Cli);
deleteFolder(config.pagesMoreDirInVue2Cli);
}
if (checkVue2HxExist()) {
deleteFolder(config.componentTargetDirInVue2Hx);
deleteFolder(config.componentChatTargetDirInVue2Hx);
deleteFolder(config.pagesMoreDirInVue2Hx);
}
if (checkVue3HxExist()) {
deleteFolder(config.componentTargetDirInVue3Hx);
deleteFolder(config.componentChatTargetDirInVue3Hx);
deleteFolder(config.pagesMoreDirInVue3Hx);
}
}
async function main() {
await clearTargetDir();
await copyInfra({
infraDir: config.infraDirInApp,
});
if (checkVue2CliExist()) {
await copyInfra({
infraDir: config.infraDirInVue2Cli,
});
}
if (checkVue2HxExist()) {
await copyInfra({
infraDir: config.infraDirInVue2Hx,
});
}
if (checkVue3HxExist()) {
await copyInfra({
infraDir: config.infraDirInVue3Hx,
});
}
await copyOneProject({
globMode: config.sourceGlob,
sourceDir: config.sourceDir,
isChat: false,
});
// 为主包生成 .d.ts 声明文件
generateDts(config.sourceDir, config.componentTargetDirInVue3Cli);
await copyOneProject({
globMode: config.chatSourceGlob,
sourceDir: config.chatSourceDir,
isChat: true,
});
// 为 chat 包生成 .d.ts 声明文件
generateDts(config.chatSourceDir, config.componentTargetDirInVue3Cli);
}
async function copyInfra({
infraDir,
}) {
const list = glob.sync([config.demoPagesGlob], {
ignore: '**/node_modules/**/*',
nodir: true,
});
for (const item of list) {
const relativePath = path.relative(path.resolve(config.vue3CliRoot, 'src'), item);
const targetPath = path.resolve(infraDir, relativePath);
fs.mkdirSync(path.dirname(targetPath), { recursive: true });
fs.copyFileSync(item, targetPath);
}
console.log(`[Wrote] done! Length of App Files is ${list.length}!`);
}
main();