@fangzhongya/vue-components 0.1.2-5 → 0.1.2-8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,468 +0,0 @@
1
- import {
2
- firstUpper,
3
- getComponentNames,
4
- humpToLine,
5
- styleLog
6
- } from "./chunk-FDVNT7FU.js";
7
-
8
- // packages/component.ts
9
- import fastGlob from "fast-glob";
10
- import { resolve } from "path";
11
- function getMatchDir(name) {
12
- return [name + ".js"];
13
- }
14
- function isUrlsMatchi(key, arr) {
15
- if (arr) {
16
- for (let index = 0; index < arr.length; index++) {
17
- const element = arr[index];
18
- if (typeof element == "string") {
19
- if (key.endsWith(element)) {
20
- return true;
21
- }
22
- } else {
23
- if (element.test(key)) {
24
- return true;
25
- }
26
- }
27
- }
28
- }
29
- return false;
30
- }
31
- function getForUrl(arr, name) {
32
- for (let index = 0; index < arr.length; index++) {
33
- const element = arr[index];
34
- if (typeof name == "string") {
35
- if (element.endsWith(name)) {
36
- return element;
37
- }
38
- } else {
39
- if (name.test(element)) {
40
- return element;
41
- }
42
- }
43
- }
44
- }
45
- function getForUrlStart(arr, name) {
46
- if (arr) {
47
- for (let index = 0; index < arr.length; index++) {
48
- const element = arr[index];
49
- if (name.startsWith(element)) {
50
- return name;
51
- }
52
- }
53
- }
54
- }
55
- var FangComponent = class {
56
- config;
57
- #comUrls;
58
- #dirUrls;
59
- #cacheObj;
60
- #curDir;
61
- #aliassArr;
62
- #aliassValueArr;
63
- constructor(config) {
64
- this.config = config || {};
65
- this.#setConfigValue();
66
- }
67
- #setConfigValue() {
68
- this.#setGetMatch();
69
- this.#comUrls = [];
70
- this.#dirUrls = [];
71
- this.#cacheObj = {};
72
- this.#curDir = "";
73
- if (this.config.dir) {
74
- this.config.dir = this.config.dir + "/";
75
- this.config.dir = this.config.dir.replace(
76
- /\/\/$/,
77
- "/"
78
- );
79
- this.#curDir = resolve(
80
- process.cwd(),
81
- this.config.dir
82
- ).replace(/\\/g, "/") + "/";
83
- }
84
- this.#aliassArr = [];
85
- const aliass = this.config.aliass;
86
- if (aliass) {
87
- this.#aliassArr = Object.keys(aliass);
88
- this.#aliassValueArr = this.#aliassArr.map(
89
- (key) => {
90
- return this.#curDir + aliass[key] + "/";
91
- }
92
- );
93
- }
94
- this.#getUrls();
95
- }
96
- #setGetMatch() {
97
- if (!this.config.getMatch) {
98
- this.config.getMatch = function(v, extensions, matchs, matchexts) {
99
- const urls = [];
100
- if (matchs) {
101
- matchs.forEach((key) => {
102
- const s = "/" + v + key;
103
- if (extensions) {
104
- extensions?.forEach((z) => {
105
- urls.push(s + "." + z);
106
- });
107
- } else {
108
- const reg = new RegExp(
109
- s + ".([a-z|A-Z]+?)$"
110
- );
111
- urls.push(reg);
112
- }
113
- });
114
- }
115
- if (matchexts) {
116
- matchexts.forEach((key) => {
117
- urls.push("/" + v + key);
118
- });
119
- }
120
- return [...new Set(urls)];
121
- };
122
- }
123
- }
124
- #getUrls() {
125
- const url = this.#getFgUrl();
126
- if (url) {
127
- this.#comUrls = fastGlob.sync(url, {
128
- onlyFiles: false,
129
- absolute: true
130
- });
131
- }
132
- if (this.config.directives) {
133
- const durl = this.config.dir + "**/" + this.config.directives + "/*.js";
134
- this.#dirUrls = fastGlob.sync(durl, {
135
- onlyFiles: false,
136
- absolute: true
137
- }) || [];
138
- }
139
- if (this.config.urlprefix) {
140
- if (this.config.dir) {
141
- const dir = this.config.dir;
142
- const reg = new RegExp("^" + this.#curDir);
143
- const urls = [];
144
- const dirUrls = [];
145
- this.#comUrls?.forEach((key) => {
146
- urls.push(key.replace(reg, dir));
147
- });
148
- this.#dirUrls?.forEach((key) => {
149
- dirUrls.push(key.replace(reg, dir));
150
- });
151
- this.config.urls = urls;
152
- this.config.dirUrls = dirUrls;
153
- }
154
- }
155
- }
156
- #getFgUrl() {
157
- if (this.config.extensions) {
158
- if (this.config.extensions.length > 1) {
159
- return this.config.dir + "**/*.{" + this.config.extensions.join(",") + "}";
160
- } else if (this.config.extensions.length == 1) {
161
- return this.config.dir + "**/*." + this.config.extensions[0];
162
- }
163
- } else {
164
- return this.config.dir + "**/*.*";
165
- }
166
- }
167
- #getCache(name, type) {
168
- if (this.#cacheObj) {
169
- const obj = this.#cacheObj[type] || {};
170
- return obj[name];
171
- }
172
- }
173
- #setCache(name, type, obj) {
174
- const cach = this.#cacheObj || {};
175
- const co = cach[type] || {};
176
- co[name] = obj;
177
- cach[type] = co;
178
- }
179
- #namefilter(name) {
180
- name = humpToLine(name);
181
- if (this.config.startss) {
182
- for (let index = 0; index < this.config.startss.length; index++) {
183
- const element = this.config.startss[index] + "-";
184
- if (name.startsWith(element)) {
185
- return false;
186
- }
187
- }
188
- }
189
- if (this.config.filtes) {
190
- for (let index = 0; index < this.config.filtes.length; index++) {
191
- const element = this.config.filtes[index];
192
- if (name === element) {
193
- return false;
194
- }
195
- }
196
- }
197
- return true;
198
- }
199
- #getNameFromUrl(from, name, type) {
200
- let dname = "";
201
- if (this.config.getFromName) {
202
- dname = this.config.getFromName(
203
- from,
204
- name,
205
- type
206
- );
207
- }
208
- return {
209
- name: dname || "default",
210
- from
211
- };
212
- }
213
- #getCorrespondUrl2(type, urls, ml, yname, top) {
214
- const v = this.#curDir + ml + "/";
215
- const as = [];
216
- for (let index = 0; index < urls.length; index++) {
217
- const element = urls[index];
218
- if (element.startsWith(v)) {
219
- as.push(element);
220
- }
221
- }
222
- if (as.length == 1) {
223
- return as[0];
224
- } else if (as.length > 1) {
225
- let m;
226
- if (/[A-Z]/.test(yname.slice(0, 1))) {
227
- m = yname.replace(firstUpper(top), "");
228
- } else {
229
- m = yname.replace(top, "");
230
- }
231
- return this.#getCorrespondUrl(as, m, type, ml);
232
- }
233
- }
234
- #getConfigUrl(type, name, ml, yname, top) {
235
- const ms = this.#setMatchUrls(name, type);
236
- const urls = this.#getUrlsMatchi(ms, type);
237
- if (urls.length == 1) {
238
- return urls[0];
239
- } else if (urls.length > 1) {
240
- return this.#getCorrespondUrl2(
241
- type,
242
- urls,
243
- ml,
244
- yname,
245
- top
246
- );
247
- }
248
- }
249
- #setNameFrom(name, type) {
250
- let mb = humpToLine(name);
251
- const alias = this.config.alias;
252
- if (alias) {
253
- if (mb.startsWith(alias + "-")) {
254
- const reg = new RegExp("^" + alias + "-");
255
- mb = mb.replace(reg, "");
256
- const reg1 = new RegExp("^" + alias);
257
- const reg2 = new RegExp(
258
- "^" + firstUpper(alias)
259
- );
260
- if (reg1.test(name)) {
261
- name = name.replace(reg1, "");
262
- } else if (reg2.test(name)) {
263
- name = name.replace(reg2, "");
264
- } else if (reg.test(name)) {
265
- name = name.replace(reg, "");
266
- }
267
- } else {
268
- if (this.config.onlyAlias) {
269
- return;
270
- }
271
- }
272
- }
273
- if (this.#aliassArr) {
274
- for (let index = 0; index < this.#aliassArr.length; index++) {
275
- const element = this.#aliassArr[index];
276
- const aliass = this.config.aliass || {};
277
- if (mb.startsWith(element + "-")) {
278
- const sl = mb.substring(
279
- element.length + 1
280
- );
281
- const from2 = this.#getConfigUrl(
282
- type,
283
- sl,
284
- aliass[element],
285
- name,
286
- element
287
- );
288
- if (from2) {
289
- return this.#getNameFromUrl(
290
- from2,
291
- name,
292
- type
293
- );
294
- }
295
- }
296
- }
297
- }
298
- const from = this.#getMatchUrl(name, type);
299
- if (from) {
300
- return this.#getNameFromUrl(from, name, type);
301
- }
302
- }
303
- #setMatchUrls(name, type) {
304
- const arr = getComponentNames(name);
305
- const urls = [];
306
- if (type == "directive") {
307
- arr.forEach((v) => {
308
- const vs = getMatchDir(v);
309
- urls.push(...vs);
310
- });
311
- } else {
312
- const getMatch = this.config.getMatch;
313
- if (getMatch) {
314
- arr.forEach((v) => {
315
- const vs = getMatch(
316
- v,
317
- this.config.extensions,
318
- this.config.matchs,
319
- this.config.matchexts
320
- );
321
- if (vs) {
322
- urls.push(...vs);
323
- }
324
- });
325
- }
326
- }
327
- return urls;
328
- }
329
- #setMatchUrl(name, type) {
330
- let urls = [];
331
- if (type == "directive") {
332
- urls = getMatchDir(name);
333
- } else {
334
- const getMatch = this.config.getMatch;
335
- if (getMatch) {
336
- urls = getMatch(
337
- name,
338
- this.config.extensions,
339
- this.config.matchs,
340
- this.config.matchexts
341
- );
342
- }
343
- }
344
- return urls;
345
- }
346
- #getUrlsMatchi(arr, type) {
347
- const as = [];
348
- if (type == "directive") {
349
- this.#dirUrls?.forEach((key) => {
350
- if (isUrlsMatchi(key, arr)) {
351
- as.push(key);
352
- }
353
- });
354
- } else {
355
- this.#comUrls?.forEach((key) => {
356
- if (isUrlsMatchi(key, arr)) {
357
- as.push(key);
358
- }
359
- });
360
- }
361
- return as;
362
- }
363
- #excludeBm(urls) {
364
- let val = [];
365
- urls.forEach((v) => {
366
- if (!getForUrlStart(this.#aliassValueArr, v)) {
367
- val.push(v);
368
- }
369
- });
370
- if (val.length == 0) {
371
- val = urls;
372
- }
373
- return val;
374
- }
375
- #getCorrespondUrl(urls, name, type, bm) {
376
- if (!bm) {
377
- urls = this.#excludeBm(urls);
378
- }
379
- if (urls.length == 1) {
380
- return urls[0];
381
- }
382
- const arr = this.#setMatchUrl(name, type);
383
- for (let index = 0; index < arr.length; index++) {
384
- const element = arr[index];
385
- let url = getForUrl(urls, element);
386
- if (url) {
387
- return url;
388
- }
389
- }
390
- }
391
- #getMatchUrl(name, type) {
392
- const ml = this.#setMatchUrls(name, type);
393
- const urls = this.#getUrlsMatchi(ml, type);
394
- if (urls.length == 1) {
395
- return urls[0];
396
- } else if (urls.length > 1) {
397
- return this.#getCorrespondUrl(urls, name, type);
398
- }
399
- }
400
- #setLog(name, type, obj, is) {
401
- if (this.config.log) {
402
- const texts = {
403
- component: 2,
404
- directive: 5
405
- };
406
- const arr = [];
407
- arr.push(
408
- styleLog("[@fangzhongya/vue-components]", {
409
- text: 3
410
- })
411
- );
412
- if (obj) {
413
- let sfrom = styleLog(obj?.from, {
414
- text: 4,
415
- revert: true
416
- });
417
- arr.push(
418
- styleLog(type, {
419
- text: texts[type]
420
- })
421
- );
422
- arr.push(
423
- styleLog(name, {
424
- bold: true
425
- })
426
- );
427
- if (!is) {
428
- sfrom = styleLog("+", {
429
- text: 2
430
- }) + sfrom;
431
- }
432
- arr.push(sfrom);
433
- } else {
434
- arr.push(
435
- styleLog(type, {
436
- text: texts[type],
437
- lineThrough: true
438
- })
439
- );
440
- arr.push(
441
- styleLog(name, {
442
- bold: true
443
- })
444
- );
445
- }
446
- console.log(arr.join(" "));
447
- }
448
- }
449
- resolve(name, type) {
450
- const cache = this.#getCache(name, type);
451
- if (this.config.isCache && cache) {
452
- this.#setLog(name, type, cache, true);
453
- return cache;
454
- } else if (this.#namefilter(name)) {
455
- let obj = this.#setNameFrom(name, type);
456
- if (obj) {
457
- this.#setLog(name, type, obj);
458
- this.#setCache(name, type, obj);
459
- return obj;
460
- }
461
- }
462
- }
463
- };
464
- var component_default = FangComponent;
465
-
466
- export {
467
- component_default
468
- };
@@ -1,22 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});// packages/config.ts
2
- var config = {
3
- dir: "./src/components/",
4
- extensions: ["vue"],
5
- alias: "",
6
- onlyAlias: false,
7
- aliass: {},
8
- matchs: [],
9
- matchexts: [".vue", "/index.vue"],
10
- directives: "directive",
11
- isCache: true,
12
- startss: [],
13
- filtes: ["router-link", "router-view"],
14
- log: true,
15
- getFromName() {
16
- return "default";
17
- }
18
- };
19
-
20
-
21
-
22
- exports.config = config;
@@ -1,22 +0,0 @@
1
- // packages/config.ts
2
- var config = {
3
- dir: "./src/components/",
4
- extensions: ["vue"],
5
- alias: "",
6
- onlyAlias: false,
7
- aliass: {},
8
- matchs: [],
9
- matchexts: [".vue", "/index.vue"],
10
- directives: "directive",
11
- isCache: true,
12
- startss: [],
13
- filtes: ["router-link", "router-view"],
14
- log: true,
15
- getFromName() {
16
- return "default";
17
- }
18
- };
19
-
20
- export {
21
- config
22
- };