@moneko/core 3.0.0-beta.84 → 3.0.0-beta.85

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,331 +1 @@
1
- import { readFileSync } from 'fs';
2
- import { dirname } from 'path';
3
- import ts from 'typescript';
4
- import { CONFIG } from './common.js';
5
- import { alias } from './webpack.common.js';
6
- const { ScriptKind , ScriptTarget , SyntaxKind , createSourceFile , forEachChild , getLeadingCommentRanges , isInterfaceDeclaration , isQuestionToken , isPropertySignature , isFunctionTypeNode , isUnionTypeNode , isMethodSignature } = ts;
7
- const allType = {};
8
- function getPropertyComment(propertyNode) {
9
- const comments = getLeadingCommentRanges(propertyNode.getSourceFile().text, propertyNode.pos);
10
- if (comments) {
11
- const commentText = propertyNode.getSourceFile().text.substring(comments[0].pos, comments[0].end);
12
- const match = commentText.match(/\/\*\*([\s\S]*?)\*\//);
13
- if (match) {
14
- const trimmedCommentText = match[1].replace(/^\s*\* ?/gm, '').replace(/\s+$/, '').trim();
15
- return trimmedCommentText;
16
- }
17
- }
18
- return null;
19
- }
20
- function getDefaultValueFromComment(commentText) {
21
- if (!commentText) return null;
22
- const defaultValueRegex = /@default\s+([^\n]+)/;
23
- const defaultValueMatch = commentText.match(defaultValueRegex);
24
- return defaultValueMatch ? defaultValueMatch[1].trim() : null;
25
- }
26
- function getVersionFromComment(commentText) {
27
- if (!commentText) return null;
28
- const versionRegex = /@since\s+([^\n]+)/;
29
- const versionMatch = commentText.match(versionRegex);
30
- return versionMatch ? versionMatch[1].trim() : null;
31
- }
32
- function getAuthor(commentText) {
33
- if (!commentText) return null;
34
- const regex = /@author (\w+)\s*(?:<([^>]+)>)?/;
35
- const match = commentText.match(regex);
36
- if (match?.length) {
37
- const author = match[1].trim();
38
- let url = match[2]?.trim();
39
- const isEmail = /^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/.test(url);
40
- if (!url) {
41
- url = `https://github.com/${author}`;
42
- } else if (isEmail) {
43
- url = `mailto:${url}`;
44
- }
45
- return `[${author}${isEmail ? ' 📧' : ' ⎋'}](${url})`;
46
- }
47
- return null;
48
- }
49
- function getIgnore(commentText) {
50
- if (!commentText) return null;
51
- const versionRegex = /@ignore\s+([^\n]+)/;
52
- const versionMatch = commentText.match(versionRegex);
53
- return versionMatch ? versionMatch[1].trim() : null;
54
- }
55
- const regex = /(?<!['"])(unknown|any|void|bigint|object|undefined|null|boolean|number|string|symbol)(?!['"])/g;
56
- function getTypeText(typeText, hasColor) {
57
- if (!typeText) return null;
58
- let modifiedTypeText = typeText.replace(/\b([A-Z][a-zA-Z0-9]*)\b/g, (item)=>{
59
- if (allType[item]) {
60
- const url = `/${[
61
- CONFIG.routeBaseName,
62
- allType[item]
63
- ].join('/').split('/').filter(Boolean).join('/')}`;
64
- return hasColor ? `[\\color{#009688}{${item}}](${url})` : `[${item}](${url})`;
65
- }
66
- return hasColor ? `\\color{#009688}{${item}}` : item;
67
- });
68
- if (hasColor) {
69
- modifiedTypeText = modifiedTypeText.replace(regex, (match)=>{
70
- return `\\color{#009688}{${match}}`;
71
- });
72
- }
73
- return modifiedTypeText;
74
- }
75
- function getMemberValue(memberNode) {
76
- const initializer = memberNode.initializer;
77
- if (initializer && ts.isStringLiteral(initializer)) {
78
- return ` '${initializer.text}'`;
79
- }
80
- return null;
81
- }
82
- function replacePairedSymbols(inputString) {
83
- if (!inputString) return null;
84
- const coloredContent = [];
85
- let matches;
86
- while(matches = /\\color{([^|}]*)\|?([^|}]*)\|?([^|}]*)\|?([^}]*)}{([^}]*)}/g.exec(inputString)){
87
- coloredContent.push(matches[0]);
88
- }
89
- return inputString.replace(/(\{|\}|\[|\]|\(|\)|=>|keyof|typeof|true|false)/g, (match)=>{
90
- if (coloredContent.some((content)=>content.includes(match))) {
91
- return match;
92
- }
93
- return `\\color{#569cd6}{${match}}`;
94
- });
95
- }
96
- function isFunctionTypeProperty(member) {
97
- if (member.type) {
98
- if (isUnionTypeNode(member.type)) {
99
- for (const typeNode of member.type.types){
100
- if (isFunctionTypeNode(typeNode)) {
101
- return true;
102
- }
103
- }
104
- } else {
105
- return isFunctionTypeNode(member.type);
106
- }
107
- }
108
- return false;
109
- }
110
- function replaceText(str) {
111
- return replacePairedSymbols(str)?.replace(/^\s*\|\s*|\s*\|\s*$/gm, '').replace(/\n/g, '<br/>').replace(/\*/g, '\\*').replace(/\|/g, '\\|').replace(/(['"])((?:(?!\1).)*)\1/g, '\\color{#ce9178}{$1$2$1}');
112
- }
113
- function getBaseInterfaces(interfaceNode) {
114
- const baseInterfaces = [];
115
- if (interfaceNode.heritageClauses) {
116
- for (const clause of interfaceNode.heritageClauses){
117
- if (clause.token === ts.SyntaxKind.ExtendsKeyword) {
118
- for (const typeNode of clause.types){
119
- baseInterfaces.push(typeNode.getText());
120
- }
121
- }
122
- }
123
- }
124
- return baseInterfaces;
125
- }
126
- function getComment(comment) {
127
- if (!comment) return null;
128
- return comment.replace(/^@[a-z].+/gm, '').replace(/(\n\s+)+/g, '<br />').replace(/\n/g, '<br />').replace(/(<br \/>)$/g, '');
129
- }
130
- function getMethodText(member) {
131
- if (isMethodSignature(member)) {
132
- return `(${member.parameters.map((param)=>`${param.name.getText()}: ${param.type?.getText() || 'any'}`).join(', ')}): ${member.type?.getText() || 'any'}`;
133
- }
134
- return member.type?.getText() || 'any';
135
- }
136
- function generateInterfaceDocumentation(node) {
137
- const typeName = node.name.text;
138
- Object.assign(allType, {
139
- [node.name.text]: dirname(node.getSourceFile().fileName).replace(alias['@pkg'], '')
140
- });
141
- const baseComment = getPropertyComment(node);
142
- const vers = getVersionFromComment(baseComment);
143
- const title = getComment(baseComment);
144
- const ignore = getIgnore(baseComment)?.split('|') || [];
145
- const ignoreComment = ignore.includes('comment');
146
- const ignoreInitial = ignore.includes('initial');
147
- const ignoreOptional = ignore.includes('optional');
148
- const ignoreVersion = ignore.includes('version');
149
- const ignoreAuthor = ignore.includes('author');
150
- const subTitle = title ? `\\color{|4||0.45}{${typeName}}` : typeName;
151
- const baseInterfaces = getBaseInterfaces(node)?.map((s)=>{
152
- return `<n-tag color="#4c81db" css=".tag{gap:0px;}">${getTypeText(replaceText(s))}</n-tag>`;
153
- });
154
- const heading = [
155
- title,
156
- subTitle,
157
- vers && `\\color{#52c11b|1||0.9}{${vers}}`,
158
- baseInterfaces.length > 0 && `<sub>\`extends\`</sub> ${baseInterfaces.join(' ')}`
159
- ].filter(Boolean).join(' ');
160
- let markdownContent = `## ${heading}`;
161
- const members = node.members.filter((m)=>isPropertySignature(m) && m.type?.kind !== SyntaxKind.NeverKeyword || isMethodSignature(m));
162
- const rowsData = [];
163
- if (members.length) {
164
- members.forEach((member)=>{
165
- const type = getTypeText(replaceText(getMethodText(member)), true);
166
- const propertyComment = getPropertyComment(member);
167
- let name = replaceText(member.name.getText());
168
- if (name && !name.startsWith('\\color')) {
169
- if (isMethodSignature(member) || isFunctionTypeProperty(member) || type?.includes('=>')) {
170
- name = `\\color{#f9a913}{${name}}`;
171
- } else if (!/^("|')(.+)("|')$/.test(name)) {
172
- name = `\\color{#4c81db}{${name}}`;
173
- }
174
- }
175
- const isOptional = member.questionToken && isQuestionToken(member.questionToken);
176
- rowsData.push([
177
- name,
178
- !ignoreOptional && `\\color{${isOptional ? '#f9a913' : '#52c11b'}\\|\\|\\|0.9}{${isOptional ? '✘' : '✔'}}`,
179
- !ignoreComment && replaceText(getComment(propertyComment)),
180
- type,
181
- !ignoreInitial && replaceText(getDefaultValueFromComment(propertyComment)),
182
- !ignoreVersion && replaceText(getVersionFromComment(propertyComment)),
183
- !ignoreAuthor && (getAuthor(propertyComment) || getAuthor(baseComment))
184
- ]);
185
- });
186
- let hasAuthor = false, hasVersion = false, hasInitial = false, hasComment = false;
187
- rowsData.forEach((row)=>{
188
- if (!ignoreComment && row[2]) {
189
- hasComment = true;
190
- }
191
- if (!ignoreInitial && row[4]) {
192
- hasInitial = true;
193
- }
194
- if (!ignoreVersion && row[5]) {
195
- hasVersion = true;
196
- }
197
- if (!ignoreAuthor && row[6]) {
198
- hasAuthor = true;
199
- }
200
- });
201
- markdownContent += '\n';
202
- const cols = [
203
- '属性',
204
- !ignoreOptional && '必要',
205
- hasComment && '说明',
206
- '类型',
207
- hasInitial && '默认值',
208
- hasVersion && '版本',
209
- hasAuthor && '作者'
210
- ].filter(Boolean).join('|');
211
- markdownContent += `|${cols}|`;
212
- const algins = [
213
- ':-',
214
- !ignoreOptional && ':-',
215
- hasComment && ':-',
216
- ':-',
217
- hasInitial && ':-',
218
- hasVersion && ':-',
219
- hasAuthor && ':-'
220
- ].filter(Boolean);
221
- markdownContent += '\n';
222
- const alignStr = algins.join('|');
223
- markdownContent += `|${alignStr}|`;
224
- rowsData.forEach((row)=>{
225
- markdownContent += '\n';
226
- const rowStr = [
227
- row[0] || '-',
228
- !ignoreOptional && (row[1] || '-'),
229
- hasComment && (row[2] || '-'),
230
- row[3] || '-',
231
- hasInitial && (row[4] || '-'),
232
- hasVersion && (row[5] || '-'),
233
- hasAuthor && (row[6] || '-')
234
- ].filter(Boolean).join('|');
235
- markdownContent += `|${rowStr}|`;
236
- });
237
- markdownContent += '\n';
238
- }
239
- markdownContent += '\n';
240
- return markdownContent;
241
- }
242
- function generateEnumDocumentation(node) {
243
- const enumName = node.name.text;
244
- Object.assign(allType, {
245
- [node.name.text]: dirname(node.getSourceFile().fileName).replace(alias['@pkg'], '')
246
- });
247
- const baseComment = getPropertyComment(node);
248
- const ignore = getIgnore(baseComment)?.split('|') || [];
249
- const ignoreComment = ignore.includes('comment');
250
- const ignoreVersion = ignore.includes('version');
251
- const ignoreAuthor = ignore.includes('author');
252
- let markdownContent = `## ${enumName}`;
253
- if (node.members.length) {
254
- const rowsData = [];
255
- node.members.forEach((member)=>{
256
- let name = replaceText(member.name.getText());
257
- const memberComment = getPropertyComment(member);
258
- const value = replaceText(getMemberValue(member));
259
- const version = replaceText(getVersionFromComment(memberComment));
260
- const comment = replaceText(getComment(memberComment));
261
- if (name && !name.startsWith('\\color') && !/^("|')(.+)("|')$/.test(name)) {
262
- name = `\\color{#4c81db}{${name}}`;
263
- }
264
- rowsData.push([
265
- name,
266
- !ignoreComment && comment,
267
- value,
268
- !ignoreVersion && version,
269
- !ignoreAuthor && (getAuthor(memberComment) || getAuthor(baseComment))
270
- ]);
271
- });
272
- let hasAuthor = false, hasVersion = false, hasComment = false;
273
- rowsData.forEach((row)=>{
274
- if (!ignoreComment && row[1]) {
275
- hasComment = true;
276
- }
277
- if (!ignoreVersion && row[3]) {
278
- hasVersion = true;
279
- }
280
- if (!ignoreAuthor && row[4]) {
281
- hasAuthor = true;
282
- }
283
- });
284
- markdownContent += '\n';
285
- const cols = [
286
- '属性',
287
- hasComment && '说明',
288
- '值',
289
- hasVersion && '版本',
290
- hasAuthor && '作者'
291
- ].filter(Boolean).join('|');
292
- markdownContent += `|${cols}|`;
293
- const algins = [
294
- ':-',
295
- hasComment && ':-',
296
- ':-',
297
- hasVersion && ':-',
298
- hasAuthor && ':-'
299
- ].filter(Boolean);
300
- markdownContent += '\n';
301
- const alignStr = algins.join('|');
302
- markdownContent += `|${alignStr}|`;
303
- rowsData.forEach((row)=>{
304
- markdownContent += '\n';
305
- const rowStr = [
306
- row[0] || '-',
307
- hasComment && (row[1] || '-'),
308
- row[2] || '-',
309
- hasVersion && (row[3] || '-'),
310
- hasAuthor && (row[4] || '-')
311
- ].filter(Boolean).join('|');
312
- markdownContent += `|${rowStr}|`;
313
- });
314
- }
315
- markdownContent += '\n';
316
- markdownContent += '\n';
317
- return markdownContent;
318
- }
319
- export default function generateApi(path) {
320
- const content = readFileSync(path, 'utf-8');
321
- const sourceFile = createSourceFile(path, content, ScriptTarget.Latest, true, ScriptKind.TS);
322
- let markdownDocumentation = '';
323
- forEachChild(sourceFile, (node)=>{
324
- if (isInterfaceDeclaration(node)) {
325
- markdownDocumentation += generateInterfaceDocumentation(node);
326
- } else if (ts.isEnumDeclaration(node)) {
327
- markdownDocumentation += generateEnumDocumentation(node);
328
- }
329
- });
330
- return markdownDocumentation;
331
- }
1
+ import{readFileSync as e}from"fs";import{dirname as t}from"path";import n from"typescript";import{CONFIG as r}from"./common.js";import{alias as l}from"./webpack.common.js";let{ScriptKind:o,ScriptTarget:i,SyntaxKind:u,createSourceFile:c,forEachChild:a,getLeadingCommentRanges:s,isInterfaceDeclaration:f,isQuestionToken:m,isPropertySignature:p,isFunctionTypeNode:g,isUnionTypeNode:$,isMethodSignature:h}=n,b={};function d(e){let t=s(e.getSourceFile().text,e.pos);if(t){let n=e.getSourceFile().text.substring(t[0].pos,t[0].end),r=n.match(/\/\*\*([\s\S]*?)\*\//);if(r){let e=r[1].replace(/^\s*\* ?/gm,"").replace(/\s+$/,"").trim();return e}}return null}function y(e){if(!e)return null;let t=e.match(/@since\s+([^\n]+)/);return t?t[1].trim():null}function x(e){if(!e)return null;let t=e.match(/@author (\w+)\s*(?:<([^>]+)>)?/);if(t?.length){let e=t[1].trim(),n=t[2]?.trim(),r=/^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/.test(n);return n?r&&(n=`mailto:${n}`):n=`https://github.com/${e}`,`[${e}${r?" 📧":" ⎋"}](${n})`}return null}function j(e){if(!e)return null;let t=e.match(/@ignore\s+([^\n]+)/);return t?t[1].trim():null}let T=/(?<!['"])(unknown|any|void|bigint|object|undefined|null|boolean|number|string|symbol)(?!['"])/g;function k(e,t){if(!e)return null;let n=e.replace(/\b([A-Z][a-zA-Z0-9]*)\b/g,e=>{if(b[e]){let n=`/${[r.routeBaseName,b[e]].join("/").split("/").filter(Boolean).join("/")}`;return t?`[\\color{#009688}{${e}}](${n})`:`[${e}](${n})`}return t?`\\color{#009688}{${e}}`:e});return t&&(n=n.replace(T,e=>`\\color{#009688}{${e}}`)),n}function w(e){return(function(e){let t;if(!e)return null;let n=[];for(;t=/\\color{([^|}]*)\|?([^|}]*)\|?([^|}]*)\|?([^}]*)}{([^}]*)}/g.exec(e);)n.push(t[0]);return e.replace(/(\{|\}|\[|\]|\(|\)|=>|keyof|typeof|true|false)/g,e=>n.some(t=>t.includes(e))?e:`\\color{#569cd6}{${e}}`)})(e)?.replace(/^\s*\|\s*|\s*\|\s*$/gm,"").replace(/\n/g,"<br/>").replace(/\*/g,"\\*").replace(/\|/g,"\\|").replace(/(['"])((?:(?!\1).)*)\1/g,"\\color{#ce9178}{$1$2$1}")}function B(e){return e?e.replace(/^@[a-z].+/gm,"").replace(/(\n\s+)+/g,"<br />").replace(/\n/g,"<br />").replace(/(<br \/>)$/g,""):null}export default function E(r){let s=e(r,"utf-8"),T=c(r,s,i.Latest,!0,o.TS),E="";return a(T,e=>{f(e)?E+=function(e){let r=e.name.text;Object.assign(b,{[e.name.text]:t(e.getSourceFile().fileName).replace(l["@pkg"],"")});let o=d(e),i=y(o),c=B(o),a=j(o)?.split("|")||[],s=a.includes("comment"),f=a.includes("initial"),T=a.includes("optional"),E=a.includes("version"),S=a.includes("author"),v=c?`\\color{|4||0.45}{${r}}`:r,F=(function(e){let t=[];if(e.heritageClauses){for(let r of e.heritageClauses)if(r.token===n.SyntaxKind.ExtendsKeyword)for(let e of r.types)t.push(e.getText())}return t})(e)?.map(e=>`<n-tag color="#4c81db" css=".tag{gap:0px;}">${k(w(e))}</n-tag>`),N=[c,v,i&&`\\color{#52c11b|1||0.9}{${i}}`,F.length>0&&`<sub>\`extends\`</sub> ${F.join(" ")}`].filter(Boolean).join(" "),z=`## ${N}`,K=e.members.filter(e=>p(e)&&e.type?.kind!==u.NeverKeyword||h(e)),q=[];if(K.length){K.forEach(e=>{let t=k(w(h(e)?`(${e.parameters.map(e=>`${e.name.getText()}: ${e.type?.getText()||"any"}`).join(", ")}): ${e.type?.getText()||"any"}`:e.type?.getText()||"any"),!0),n=d(e),r=w(e.name.getText());!r||r.startsWith("\\color")||(h(e)||function(e){if(e.type){if(!$(e.type))return g(e.type);for(let t of e.type.types)if(g(t))return!0}return!1}(e)||t?.includes("=>")?r=`\\color{#f9a913}{${r}}`:/^("|')(.+)("|')$/.test(r)||(r=`\\color{#4c81db}{${r}}`));let l=e.questionToken&&m(e.questionToken);q.push([r,!T&&`\\color{${l?"#f9a913":"#52c11b"}\\|\\|\\|0.9}{${l?"✘":"✔"}}`,!s&&w(B(n)),t,!f&&w(function(e){if(!e)return null;let t=e.match(/@default\s+([^\n]+)/);return t?t[1].trim():null}(n)),!E&&w(y(n)),!S&&(x(n)||x(o))])});let e=!1,t=!1,n=!1,r=!1;q.forEach(l=>{!s&&l[2]&&(r=!0),!f&&l[4]&&(n=!0),!E&&l[5]&&(t=!0),!S&&l[6]&&(e=!0)}),z+="\n";let l=["属性",!T&&"必要",r&&"说明","类型",n&&"默认值",t&&"版本",e&&"作者"].filter(Boolean).join("|");z+=`|${l}|`;let i=[":-",!T&&":-",r&&":-",":-",n&&":-",t&&":-",e&&":-"].filter(Boolean);z+="\n";let u=i.join("|");z+=`|${u}|`,q.forEach(l=>{z+="\n";let o=[l[0]||"-",!T&&(l[1]||"-"),r&&(l[2]||"-"),l[3]||"-",n&&(l[4]||"-"),t&&(l[5]||"-"),e&&(l[6]||"-")].filter(Boolean).join("|");z+=`|${o}|`}),z+="\n"}return z+="\n"}(e):n.isEnumDeclaration(e)&&(E+=function(e){let r=e.name.text;Object.assign(b,{[e.name.text]:t(e.getSourceFile().fileName).replace(l["@pkg"],"")});let o=d(e),i=j(o)?.split("|")||[],u=i.includes("comment"),c=i.includes("version"),a=i.includes("author"),s=`## ${r}`;if(e.members.length){let t=[];e.members.forEach(e=>{let r=w(e.name.getText()),l=d(e),i=w(function(e){let t=e.initializer;return t&&n.isStringLiteral(t)?` '${t.text}'`:null}(e)),s=w(y(l)),f=w(B(l));!r||r.startsWith("\\color")||/^("|')(.+)("|')$/.test(r)||(r=`\\color{#4c81db}{${r}}`),t.push([r,!u&&f,i,!c&&s,!a&&(x(l)||x(o))])});let r=!1,l=!1,i=!1;t.forEach(e=>{!u&&e[1]&&(i=!0),!c&&e[3]&&(l=!0),!a&&e[4]&&(r=!0)}),s+="\n";let f=["属性",i&&"说明","值",l&&"版本",r&&"作者"].filter(Boolean).join("|");s+=`|${f}|`;let m=[":-",i&&":-",":-",l&&":-",r&&":-"].filter(Boolean);s+="\n";let p=m.join("|");s+=`|${p}|`,t.forEach(e=>{s+="\n";let t=[e[0]||"-",i&&(e[1]||"-"),e[2]||"-",l&&(e[3]||"-"),r&&(e[4]||"-")].filter(Boolean).join("|");s+=`|${t}|`})}return s+="\n\n"}(e))}),E}
package/lib/has-pkg.js CHANGED
@@ -1,14 +1 @@
1
- import { accessSync, constants } from 'fs';
2
- import path from 'path';
3
- import { PROGRAMPATH } from './process-env.js';
4
- export function hasPkg(name) {
5
- let flag = false;
6
- try {
7
- const antdPath = path.join(PROGRAMPATH, `./node_modules/${name}/package.json`);
8
- accessSync(antdPath, constants.R_OK);
9
- flag = true;
10
- } catch (error) {
11
- flag = false;
12
- }
13
- return flag;
14
- }
1
+ import{accessSync as o,constants as r}from"fs";import t from"path";import{PROGRAMPATH as e}from"./process-env.js";export function hasPkg(m){let n=!1;try{let p=t.join(e,`./node_modules/${m}/package.json`);o(p,r.R_OK),n=!0}catch(o){n=!1}return n}
@@ -1,24 +1 @@
1
- import HtmlWebpackPlugin from 'html-webpack-plugin';
2
- class AddEntryAttributeWebpackPlugin {
3
- entryMatchCallback;
4
- constructor(matchCallback){
5
- this.entryMatchCallback = matchCallback;
6
- }
7
- apply(compiler) {
8
- compiler.hooks.compilation.tap('AddEntryAttributeWebpackPlugin', (compilation)=>{
9
- const HtmlWebpackPluginInstance = compiler.options.plugins.find((p)=>p instanceof HtmlWebpackPlugin);
10
- if (HtmlWebpackPluginInstance) {
11
- const hooks = HtmlWebpackPluginInstance.getHooks(compilation);
12
- hooks.alterAssetTagGroups.tap('AddEntryAttributeWebpackPlugin', (data)=>{
13
- data.headTags.forEach((tag)=>{
14
- if (tag.tagName === 'script' && typeof tag.attributes?.src === 'string' && this.entryMatchCallback(tag.attributes.src)) {
15
- tag.attributes.entry = true;
16
- }
17
- });
18
- return data;
19
- });
20
- }
21
- });
22
- }
23
- }
24
- export default AddEntryAttributeWebpackPlugin;
1
+ import t from"html-webpack-plugin";export default class{constructor(t){this.entryMatchCallback=t}apply(a){a.hooks.compilation.tap("AddEntryAttributeWebpackPlugin",e=>{let r=a.options.plugins.find(a=>a instanceof t);if(r){let t=r.getHooks(e);t.alterAssetTagGroups.tap("AddEntryAttributeWebpackPlugin",t=>(t.headTags.forEach(t=>{"script"===t.tagName&&"string"==typeof t.attributes?.src&&this.entryMatchCallback(t.attributes.src)&&(t.attributes.entry=!0)}),t))}})}};
@@ -1,44 +1 @@
1
- import path from 'path';
2
- import { merge } from 'webpack-merge';
3
- import { CONFIG } from './common.js';
4
- import { PACKAGENAME, PROGRAMPATH, pkgName, programInfo } from './process-env.js';
5
- const { template , favicon , ...option } = CONFIG.htmlPluginOption || {
6
- template: `./node_modules/${pkgName}/template/index.html`,
7
- favicon: `./node_modules/${pkgName}/template/favicon.ico`
8
- };
9
- const htmlPluginOption = merge({
10
- title: CONFIG.env?.PROJECTNAME || PACKAGENAME.toLocaleUpperCase() || 'Title',
11
- filename: 'index.html',
12
- hash: false,
13
- minify: {
14
- collapseWhitespace: true,
15
- removeComments: true,
16
- removeRedundantAttributes: false,
17
- removeScriptTypeAttributes: false,
18
- removeStyleLinkTypeAttributes: false,
19
- removeAttributeQuotes: true,
20
- useShortDoctype: true
21
- },
22
- meta: {
23
- charset: 'UTF-8',
24
- 'X-UA-Compatible': {
25
- 'http-equiv': 'X-UA-Compatible',
26
- content: 'IE=edge,Chrome=1'
27
- },
28
- HandheldFriendly: 'true',
29
- MobileOptimized: '320',
30
- 'screen-orientation': 'portrait',
31
- 'x5-orientation': 'portrait',
32
- browsermode: 'application',
33
- 'x5-page-mode': 'app',
34
- 'msapplication-tap-highlight': 'no',
35
- viewport: 'width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no',
36
- 'apple-mobile-web-app-capable': 'yes',
37
- renderer: 'webkit',
38
- description: programInfo.description || ''
39
- },
40
- tags: [],
41
- template: path.join(PROGRAMPATH, template),
42
- favicon: path.join(PROGRAMPATH, favicon)
43
- }, option);
44
- export default htmlPluginOption;
1
+ import e from"path";import{merge as t}from"webpack-merge";import{CONFIG as i}from"./common.js";import{PACKAGENAME as o,PROGRAMPATH as a,pkgName as m,programInfo as p}from"./process-env.js";let{template:r,favicon:n,...l}=i.htmlPluginOption||{template:`./node_modules/${m}/template/index.html`,favicon:`./node_modules/${m}/template/favicon.ico`},s=t({title:i.env?.PROJECTNAME||o.toLocaleUpperCase()||"Title",filename:"index.html",hash:!1,minify:{collapseWhitespace:!0,removeComments:!0,removeRedundantAttributes:!1,removeScriptTypeAttributes:!1,removeStyleLinkTypeAttributes:!1,removeAttributeQuotes:!0,useShortDoctype:!0},meta:{charset:"UTF-8","X-UA-Compatible":{"http-equiv":"X-UA-Compatible",content:"IE=edge,Chrome=1"},HandheldFriendly:"true",MobileOptimized:"320","screen-orientation":"portrait","x5-orientation":"portrait",browsermode:"application","x5-page-mode":"app","msapplication-tap-highlight":"no",viewport:"width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no","apple-mobile-web-app-capable":"yes",renderer:"webkit",description:p.description||""},tags:[],template:e.join(a,r),favicon:e.join(a,n)},l);export default s;
package/lib/index.js CHANGED
@@ -1,3 +1 @@
1
- export * from './process-env.js';
2
- export * from './utils.js';
3
- export * from '../typings/global.js';
1
+ export*from"./process-env.js";export*from"./utils.js";export*from"../typings/global.js";
package/lib/minify.js CHANGED
@@ -1,46 +1 @@
1
- import TerserPlugin from 'terser-webpack-plugin';
2
- import { merge } from 'webpack-merge';
3
- import { swcMinifyOption } from './swcrc.js';
4
- export const minify = {
5
- terser: {
6
- minify: TerserPlugin.terserMinify,
7
- terserOptions: {
8
- ecma: 2015,
9
- parse: {},
10
- compress: {
11
- global_defs: {
12
- '@alert': 'console.log'
13
- },
14
- drop_console: true,
15
- drop_debugger: true,
16
- pure_funcs: [
17
- 'console.log',
18
- 'console.warn',
19
- 'console.error',
20
- 'console.info'
21
- ]
22
- },
23
- toplevel: false,
24
- mangle: true,
25
- module: false,
26
- format: {
27
- comments: false
28
- },
29
- ie8: false,
30
- keep_classnames: undefined,
31
- keep_fnames: false,
32
- safari10: false
33
- },
34
- extractComments: false
35
- },
36
- swc: {
37
- minify: TerserPlugin.swcMinify,
38
- terserOptions: swcMinifyOption
39
- }
40
- };
41
- export const getMinifyOption = (type, options = {})=>{
42
- const min = minify[type];
43
- return Object.assign(min, {
44
- terserOptions: merge(min.terserOptions, options)
45
- });
46
- };
1
+ import e from"terser-webpack-plugin";import{merge as o}from"webpack-merge";import{swcMinifyOption as r}from"./swcrc.js";export const minify={terser:{minify:e.terserMinify,terserOptions:{ecma:2015,parse:{},compress:{global_defs:{"@alert":"console.log"},drop_console:!0,drop_debugger:!0,pure_funcs:["console.log","console.warn","console.error","console.info"]},toplevel:!1,mangle:!0,module:!1,format:{comments:!1},ie8:!1,keep_classnames:void 0,keep_fnames:!1,safari10:!1},extractComments:!1},swc:{minify:e.swcMinify,terserOptions:r}};export const getMinifyOption=(e,r={})=>{let s=minify[e];return Object.assign(s,{terserOptions:o(s.terserOptions,r)})};
package/lib/modifyVars.js CHANGED
@@ -1,11 +1 @@
1
- import { CONFIG } from './common.js';
2
- import htmlPluginOption from './html-plugin-option.js';
3
- const prefixCls = CONFIG.prefixCls || 'n';
4
- const modifyVars = {};
5
- Object.assign(modifyVars, {
6
- '@prefix-cls': prefixCls,
7
- '@ant-prefix': prefixCls,
8
- '@iconfont-css-prefix': `${prefixCls}-icon`,
9
- '@favicon': JSON.stringify(htmlPluginOption.favicon)
10
- }, CONFIG.modifyVars || {});
11
- export default modifyVars;
1
+ import{CONFIG as i}from"./common.js";import o from"./html-plugin-option.js";let f=i.prefixCls||"n",n={};Object.assign(n,{"@prefix-cls":f,"@ant-prefix":f,"@iconfont-css-prefix":`${f}-icon`,"@favicon":JSON.stringify(o.favicon)},i.modifyVars||{});export default n;
@@ -1,46 +1 @@
1
- import ExternalTemplateRemotesPlugin from 'external-remotes-plugin';
2
- import webpack from 'webpack';
3
- import ModuleFederationPlugin from 'webpack/lib/container/ModuleFederationPlugin.js';
4
- import { CONFIG } from './common.js';
5
- import { resolve } from './utils.js';
6
- const NormalModuleReplacementPlugin = webpack.NormalModuleReplacementPlugin;
7
- const aliasLibrary = {};
8
- const exposesMap = {};
9
- const remoteMap = {};
10
- export const moduleFederation = CONFIG.moduleFederation?.map((opt)=>{
11
- if (Array.isArray(opt.remotes)) {
12
- for(let r = 0, rlen = opt.remotes.length; r < rlen; r++){
13
- const m = opt.remotes[r];
14
- const aliasName = m.alias || m.name;
15
- const filename = m.filename || 'remote_entry.js';
16
- remoteMap[aliasName] = `${m.name}@${m.host}/${filename}`;
17
- if (Array.isArray(m.library)) {
18
- for(let i = 0, len = m.library.length; i < len; i++){
19
- aliasLibrary[m.library[i]] = `${aliasName}/${m.library[i]}`;
20
- }
21
- }
22
- }
23
- }
24
- if (Array.isArray(opt.exposes)) {
25
- for(let i = 0, len = opt.exposes.length; i < len; i++){
26
- const m = opt.exposes[i];
27
- if (typeof m === 'string') {
28
- exposesMap[`./${m}`] = resolve(m);
29
- } else if (Object.prototype.toString.call(m) === '[object Object]') {
30
- exposesMap[`./${m.name}`] = resolve(m.path);
31
- }
32
- }
33
- }
34
- return new ModuleFederationPlugin({
35
- filename: 'remote_entry.js',
36
- ...opt,
37
- remotes: remoteMap,
38
- exposes: exposesMap
39
- });
40
- });
41
- if (moduleFederation.length) {
42
- moduleFederation.push(new ExternalTemplateRemotesPlugin());
43
- moduleFederation.push(new NormalModuleReplacementPlugin(/(.*)/, (resource)=>{
44
- if (aliasLibrary[resource.request]) resource.request = aliasLibrary[resource.request];
45
- }));
46
- }
1
+ import e from"external-remotes-plugin";import r from"webpack";import t from"webpack/lib/container/ModuleFederationPlugin.js";import{CONFIG as o}from"./common.js";import{resolve as l}from"./utils.js";let a=r.NormalModuleReplacementPlugin,i={},m={},n={};export const moduleFederation=o.moduleFederation?.map(e=>{if(Array.isArray(e.remotes))for(let r=0,t=e.remotes.length;r<t;r++){let t=e.remotes[r],o=t.alias||t.name,l=t.filename||"remote_entry.js";if(n[o]=`${t.name}@${t.host}/${l}`,Array.isArray(t.library))for(let e=0,r=t.library.length;e<r;e++)i[t.library[e]]=`${o}/${t.library[e]}`}if(Array.isArray(e.exposes))for(let r=0,t=e.exposes.length;r<t;r++){let t=e.exposes[r];"string"==typeof t?m[`./${t}`]=l(t):"[object Object]"===Object.prototype.toString.call(t)&&(m[`./${t.name}`]=l(t.path))}return new t({filename:"remote_entry.js",...e,remotes:n,exposes:m})});moduleFederation.length&&(moduleFederation.push(new e),moduleFederation.push(new a(/(.*)/,e=>{i[e.request]&&(e.request=i[e.request])})));