@omnia/tooling-vue 8.0.100-vnext → 8.0.101-dev
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.
- package/internal-do-not-import-from-here/config/omnia.fx.core_a2892051-fd9f-4056-ae8d-30d16d48417d.manifest.json +1 -0
- package/internal-do-not-import-from-here/config/omnia.fx.ux.libs_0fe5c5f2-8d89-485b-afd4-36fe3ff5943a.manifest.json +1 -0
- package/internal-do-not-import-from-here/config/omnia.fx.ux_dee030cc-4ab3-4158-bb06-8049f5c67542.manifest.json +1 -0
- package/internal-do-not-import-from-here/config/omnia.fx_a5a89056-b5f5-475d-8518-a1f55090379d.manifest.json +1 -0
- package/internal-do-not-import-from-here/config/omnia.vendor.manifest.json +1 -1
- package/internal-do-not-import-from-here/config/tooling.output.json +1 -1
- package/internal-do-not-import-from-here/config/wctypings.d.ts +4456 -1521
- package/internal-do-not-import-from-here/shared.d.ts +11 -6
- package/internal-do-not-import-from-here/shared.js +32 -12
- package/internal-do-not-import-from-here/tasks/ComponentDocRegistrations.js +1 -1
- package/internal-do-not-import-from-here/tasks/bundle.js +120 -399
- package/internal-do-not-import-from-here/tasks/doc.d.ts +3 -1
- package/internal-do-not-import-from-here/tasks/doc.js +407 -391
- package/internal-do-not-import-from-here/tasks/vendor.js +22 -16
- package/internal-do-not-import-from-here/vite/hmr/graph.js +3 -1
- package/internal-do-not-import-from-here/vite/hmr/vueJsx.js +3 -2
- package/internal-do-not-import-from-here/vite/index.js +1 -1
- package/internal-do-not-import-from-here/vite/plugins/OmniaPlugin.js +1 -1
- package/internal-do-not-import-from-here/webpack-loaders/doc-loader.d.ts +1 -0
- package/internal-do-not-import-from-here/webpack-loaders/doc-loader.js +11 -0
- package/internal-do-not-import-from-here/webpack-loaders/esbuild-custom-loader.d.ts +1 -0
- package/internal-do-not-import-from-here/webpack-loaders/esbuild-custom-loader.js +10 -0
- package/internal-do-not-import-from-here/webpack-loaders/ts-loader.d.ts +5 -2
- package/internal-do-not-import-from-here/webpack-loaders/ts-loader.js +8 -0
- package/internal-do-not-import-from-here/webpack-loaders/tsx-loader.d.ts +3 -3
- package/internal-do-not-import-from-here/webpack-loaders/tsx-loader.js +3 -0
- package/internal-do-not-import-from-here/webpack-loaders/wc-loader.d.ts +1 -1
- package/internal-do-not-import-from-here/webpack-loaders/wc-loader.js +5 -1
- package/internal-do-not-import-from-here/webpack-plugins/stylexjs/index.d.ts +53 -0
- package/internal-do-not-import-from-here/webpack-plugins/stylexjs/index.js +194 -0
- package/internal-do-not-import-from-here/webpack-plugins/stylexjs/loader.d.ts +9 -0
- package/internal-do-not-import-from-here/webpack-plugins/stylexjs/loader.js +23 -0
- package/package.json +10 -10
|
@@ -1,424 +1,440 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.importSnippetCode = exports.generateComponentTypingsAndDoc = void 0;
|
|
3
4
|
const tslib_1 = require("tslib");
|
|
4
|
-
const
|
|
5
|
+
const fs_1 = tslib_1.__importDefault(require("fs"));
|
|
6
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
5
7
|
const shared_1 = require("../shared");
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
8
|
+
const tooling_composers_1 = require("@omnia/tooling-composers");
|
|
9
|
+
const tooling_1 = require("@omnia/tooling");
|
|
10
|
+
const core_1 = require("@swc/core");
|
|
11
|
+
const fsExtra = tslib_1.__importStar(require("fs-extra"));
|
|
12
|
+
const fx_models_1 = require("@omnia/fx-models");
|
|
13
|
+
async function generateComponentTypingsAndDoc(componentRegistrations) {
|
|
14
|
+
tooling_1.utils.log("Generate components typings and documentation running...");
|
|
15
|
+
var startTime = new Date().getTime();
|
|
16
|
+
let DefineVueType;
|
|
17
|
+
(function (DefineVueType) {
|
|
18
|
+
DefineVueType[DefineVueType["Prop"] = 0] = "Prop";
|
|
19
|
+
DefineVueType[DefineVueType["Model"] = 1] = "Model";
|
|
20
|
+
DefineVueType[DefineVueType["Slot"] = 2] = "Slot";
|
|
21
|
+
DefineVueType[DefineVueType["Emit"] = 4] = "Emit";
|
|
22
|
+
})(DefineVueType || (DefineVueType = {}));
|
|
23
|
+
const docResult = {};
|
|
24
|
+
function getPropertyFunctionTypeAsString(type) {
|
|
25
|
+
let params = "";
|
|
26
|
+
if (type.params?.length > 0) {
|
|
27
|
+
type.params.forEach(p => {
|
|
28
|
+
params += `${p.value}:${extractTypeValue(p.typeAnnotation)}, `;
|
|
29
|
+
});
|
|
30
|
+
params = params.replace(/,\s*$/, "");
|
|
31
|
+
}
|
|
32
|
+
return `(${params}) => ${extractTypeValue(type.typeAnnotation)}`;
|
|
30
33
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
//}
|
|
41
|
-
//if (enableDocs !== true) {
|
|
42
|
-
// resolve();
|
|
43
|
-
//}
|
|
44
|
-
//else {
|
|
45
|
-
// $.tooling.log('Generating documentation manifest', $.tooling.LogTypes.HeadLine);
|
|
46
|
-
// let startTime = new Date().getTime();
|
|
47
|
-
// //ensure folder
|
|
48
|
-
// if (!fs.existsSync(outDir)) {
|
|
49
|
-
// fs.mkdirSync(outDir);
|
|
50
|
-
// }
|
|
51
|
-
// else {
|
|
52
|
-
// // cleanup exist docs
|
|
53
|
-
// $.del.sync([outDir + '/**', '!' + outDir]);
|
|
54
|
-
// }
|
|
55
|
-
// let componentRegistrations = $.composers.ComponentRegistry.getComponentRegistrations();
|
|
56
|
-
// let docs = extractDocPathForComponents(componentRegistrations);
|
|
57
|
-
// $.tooling.logTime(`Found [${docs.componentsDocCount}] component(s) have documentation`, startTime);
|
|
58
|
-
// if (docs.paths.length > 0) {
|
|
59
|
-
// generate(docs.paths).then(() => {
|
|
60
|
-
// $.tooling.logTime('Done - Generating documentation manifest', startTime);
|
|
61
|
-
// resolve();
|
|
62
|
-
// }, reject);
|
|
63
|
-
// }
|
|
64
|
-
// else {
|
|
65
|
-
// $.tooling.logTime('Done - Generating documentation manifest', startTime);
|
|
66
|
-
// resolve();
|
|
67
|
-
// }
|
|
68
|
-
//}
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
function generate(paths) {
|
|
72
|
-
return new Promise(function (resolve, reject) {
|
|
73
|
-
const { Documentalist, TypescriptPlugin } = require("documentalist");
|
|
74
|
-
new Documentalist()
|
|
75
|
-
.use(/\.ts?$/, new TypescriptPlugin())
|
|
76
|
-
.documentGlobs(...paths) // ← async operation, returns a Promise
|
|
77
|
-
.then(docs => {
|
|
78
|
-
//console.log("ahihi", docs.typescript);
|
|
79
|
-
var rootModel = docs.typescript;
|
|
80
|
-
var filterFilesPath = filterInterfaceFilePaths(rootModel, paths);
|
|
81
|
-
var elementInterfaces = getWebComponentAndMainInterface(Object.keys(filterFilesPath));
|
|
82
|
-
var fxDocs = builtFxDocs(rootModel, elementInterfaces);
|
|
83
|
-
writeFile(extensionEnvironment.outPutPaths.rawFile, JSON.stringify(fxDocs, null, 2)); //For debugging purpose
|
|
84
|
-
writeDocsManifest(extensionEnvironment.outPutPaths.manifest, extensionEnvironment.paths.composorImportPath, fxDocs);
|
|
85
|
-
writeNavRegistrion(extensionEnvironment.outPutPaths.navRegistration, extensionEnvironment.paths.topicImportPath, extensionEnvironment.paths.messageBusTopicMediatorImportPath, fxDocs);
|
|
86
|
-
writeDocsRegistration(extensionEnvironment.outPutPaths.folder, extensionEnvironment.paths.topicImportPath, extensionEnvironment.paths.messageBusTopicMediatorImportPath, fxDocs);
|
|
87
|
-
let docManifestRelativePath = relativeOutDir + "/docs.manifest.ts";
|
|
88
|
-
let docManifestAbsolutePath = $.tooling.utils.root(docManifestRelativePath);
|
|
89
|
-
// register docs manifest
|
|
90
|
-
if ($.fs.existsSync(docManifestAbsolutePath)) {
|
|
91
|
-
try {
|
|
92
|
-
$.composers.ManifestRegistry.setCurrentManifestPath(docManifestRelativePath);
|
|
93
|
-
require(docManifestAbsolutePath);
|
|
94
|
-
$.composers.ManifestRegistry.setCurrentManifestPath();
|
|
95
|
-
delete require.cache[docManifestAbsolutePath];
|
|
34
|
+
function extractTypeValue(tsType, rawValue = false) {
|
|
35
|
+
let result = "";
|
|
36
|
+
if (tsType.type === "TsTypeAnnotation") {
|
|
37
|
+
return extractTypeValue(tsType.typeAnnotation);
|
|
38
|
+
}
|
|
39
|
+
switch (tsType.type) {
|
|
40
|
+
case "TsLiteralType":
|
|
41
|
+
if (rawValue && tsType.literal.type === "StringLiteral") {
|
|
42
|
+
result = tsType.literal.raw;
|
|
96
43
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
reject();
|
|
44
|
+
else {
|
|
45
|
+
result = tsType.literal.value;
|
|
100
46
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
var elemNameMatches = content.match(elementNameReg);
|
|
117
|
-
var entryPointMatches = content.match(entryPointReg);
|
|
118
|
-
if (elemNameMatches && entryPointMatches) {
|
|
119
|
-
for (var i = 0; i < entryPointMatches.length; i++) {
|
|
120
|
-
var elemNameMatch = elemNameMatches[i];
|
|
121
|
-
var entryPointMatch = entryPointMatches[i];
|
|
122
|
-
var sampleElemDefinition = elemNameMatch.split(':').pop();
|
|
123
|
-
sampleElemDefinition = sampleElemDefinition.trim();
|
|
124
|
-
var sampleElem = sampleElemDefinition.substr(1, sampleElemDefinition.length - 2);
|
|
125
|
-
var entryPointDefinition = entryPointMatch.split(':').pop();
|
|
126
|
-
entryPointDefinition = entryPointDefinition.trim();
|
|
127
|
-
var entryPoint = entryPointDefinition.substr(1, entryPointDefinition.length - 2);
|
|
128
|
-
entryPoint = entryPoint.replace('./', '').replace('.jsx', '.tsx').split('/').join('\\');
|
|
129
|
-
var sampleTsxFilePath = sampleManifest.dirPath + '\\' + entryPoint;
|
|
130
|
-
var sampleTsxFileContent = readFile(sampleTsxFilePath);
|
|
131
|
-
sampleTsxFileContent = sampleTsxFileContent.replace(new RegExp('\\r\\n', 'g'), '\\\\r\\\\n');
|
|
132
|
-
//console.log(sampleTsxFileContent);
|
|
133
|
-
samples.push({ elem: sampleElem, content: sampleTsxFileContent });
|
|
134
|
-
}
|
|
47
|
+
break;
|
|
48
|
+
case "TsKeywordType":
|
|
49
|
+
result = tsType.kind;
|
|
50
|
+
break;
|
|
51
|
+
case "TsTypeReference":
|
|
52
|
+
result = tsType.typeName.value;
|
|
53
|
+
break;
|
|
54
|
+
case "TsTypeQuery":
|
|
55
|
+
result = tsType.exprName.value;
|
|
56
|
+
break;
|
|
57
|
+
case "TsFunctionType":
|
|
58
|
+
result = getPropertyFunctionTypeAsString(tsType);
|
|
59
|
+
break;
|
|
60
|
+
default:
|
|
61
|
+
break;
|
|
135
62
|
}
|
|
63
|
+
return result;
|
|
136
64
|
}
|
|
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
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
content += ` .registerResources({resourcePaths:['./${elem}.ts']})\r\n`;
|
|
169
|
-
content += ` .withLoadRules().loadIfManifestLoaded({omniaServiceId:'da059968-e431-48b5-a865-d33d0fa29c9d', resourceId:'052f0298-1dc7-4d0c-b4b9-3c8497ca08f5'})\r\n`;
|
|
170
|
-
content += ` .and().loadByDomMatching({ cssSelector: "omfx-docs-resource[source='${elem}']" });\r\n`;
|
|
171
|
-
content += '\r\n';
|
|
172
|
-
}
|
|
173
|
-
writeFile(path, content);
|
|
174
|
-
}
|
|
175
|
-
function writeNavRegistrion(path, topicImportPath, messageBusTopicMediatorImportPath, fxDocs) {
|
|
176
|
-
var content = '';
|
|
177
|
-
var navRegistrationMsg = getNavRegistrationMsg(fxDocs);
|
|
178
|
-
content += `import { Topic } from "${topicImportPath}";\r\n`;
|
|
179
|
-
content += `import { MessageBusTopicMediator } from '${messageBusTopicMediatorImportPath}';\r\n`;
|
|
180
|
-
content += `const topic: Topic<string> = {namespace: "omfx.docs",name: "nav"};\r\n`;
|
|
181
|
-
content += `const registerNav = new MessageBusTopicMediator<any>(topic, { caching: { size: Number.MAX_SAFE_INTEGER} });\r\n`;
|
|
182
|
-
content += 'registerNav.publish(JSON.parse(`' + JSON.stringify(navRegistrationMsg) + '`))';
|
|
183
|
-
writeFile(path, content);
|
|
184
|
-
}
|
|
185
|
-
function generateDocsRegistrationMsg(fxDocs, elem) {
|
|
186
|
-
var props = [];
|
|
187
|
-
var elemDocumentation = elem;
|
|
188
|
-
if (fxDocs[elem] && fxDocs[elem].documentation && fxDocs[elem].documentation.contentsRaw) {
|
|
189
|
-
elemDocumentation = fxDocs[elem].documentation.contentsRaw;
|
|
190
|
-
}
|
|
191
|
-
var elemName = elemDocumentation.split('-')[0];
|
|
192
|
-
var elemDescription = elemDocumentation.split('-')[1] || '';
|
|
193
|
-
if (fxDocs[elem].props) {
|
|
194
|
-
for (var prop of Object.keys(fxDocs[elem].props)) {
|
|
195
|
-
var propObj = fxDocs[elem].props[prop];
|
|
196
|
-
var description = '';
|
|
197
|
-
if (propObj.documentation && propObj.documentation.contentsRaw) {
|
|
198
|
-
description = propObj.documentation.contentsRaw;
|
|
199
|
-
if (description && description.indexOf('\"') >= 0) {
|
|
200
|
-
description = description.replace(new RegExp('\\"', 'g'), '\\\"');
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
var defaultValue = propObj.defaultValue;
|
|
204
|
-
if (defaultValue && defaultValue.indexOf('\"') >= 0) {
|
|
205
|
-
defaultValue = defaultValue.replace(new RegExp('\\"', 'g'), '\\\"');
|
|
65
|
+
function getPropertyInfo(ce, result) {
|
|
66
|
+
const identifier = ce.callee?.property?.value;
|
|
67
|
+
if (identifier) {
|
|
68
|
+
switch (identifier) {
|
|
69
|
+
case "name":
|
|
70
|
+
result.name = ce.arguments[0].expression.value;
|
|
71
|
+
getPropertyInfo(ce.callee.object, result);
|
|
72
|
+
break;
|
|
73
|
+
case "vModel":
|
|
74
|
+
result.type = DefineVueType.Model;
|
|
75
|
+
result.propertyTypeAsString = extractTypeValue(ce.typeArguments.params[0]);
|
|
76
|
+
result.name = result.name ? `v-model:${result.name}` : result.name;
|
|
77
|
+
break;
|
|
78
|
+
case "slots":
|
|
79
|
+
result.type = DefineVueType.Slot;
|
|
80
|
+
result.propertyTypeAsObject = {};
|
|
81
|
+
ce.typeArguments.params[0].members
|
|
82
|
+
.forEach(m => {
|
|
83
|
+
result.propertyTypeAsObject[m.key.value] = extractTypeValue(m.typeAnnotation);
|
|
84
|
+
});
|
|
85
|
+
break;
|
|
86
|
+
case "prop":
|
|
87
|
+
result.type = DefineVueType.Prop;
|
|
88
|
+
result.propertyTypeAsString = extractTypeValue(ce.typeArguments.params[0]);
|
|
89
|
+
break;
|
|
90
|
+
case "emit":
|
|
91
|
+
result.type = DefineVueType.Emit;
|
|
92
|
+
result.propertyTypeAsString = extractTypeValue(ce.typeArguments.params[0]);
|
|
93
|
+
break;
|
|
94
|
+
default:
|
|
95
|
+
getPropertyInfo(ce.callee.object, result);
|
|
206
96
|
}
|
|
207
|
-
props.push({ name: prop, type: propObj.type, description: description, defaultValue: defaultValue });
|
|
208
97
|
}
|
|
209
98
|
}
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
99
|
+
async function buildDoc(wc) {
|
|
100
|
+
try {
|
|
101
|
+
const wcPath = (0, shared_1.convertManifestPathToEntryPath)(wc.manifestPath, [wc.componentOptions.entryPoint])[0];
|
|
102
|
+
const elementName = wc.componentOptions.elementName;
|
|
103
|
+
const wcParseResult = await (0, core_1.parseFile)(wcPath, {
|
|
104
|
+
syntax: 'typescript',
|
|
105
|
+
target: 'es2020',
|
|
106
|
+
tsx: true,
|
|
107
|
+
decorators: true,
|
|
108
|
+
dynamicImport: true
|
|
109
|
+
});
|
|
110
|
+
wcParseResult.body.forEach(b => {
|
|
111
|
+
if (b.type === 'ExportDefaultExpression'
|
|
112
|
+
&& b.expression.callee?.value === "defineVueComponent") {
|
|
113
|
+
if (!docResult[elementName]) {
|
|
114
|
+
docResult[elementName] = {
|
|
115
|
+
emits: {},
|
|
116
|
+
models: {},
|
|
117
|
+
props: {},
|
|
118
|
+
slots: {}
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
if (b.expression.arguments[0].expression.type === "ArrowFunctionExpression") {
|
|
122
|
+
const params = b.expression.arguments[0].expression.params;
|
|
123
|
+
const typeParams = params[0].typeAnnotation.typeAnnotation.typeParams.params;
|
|
124
|
+
const props = typeParams[0];
|
|
125
|
+
props.types.forEach((t) => {
|
|
126
|
+
const typeName = t.typeName.value;
|
|
127
|
+
if (typeName === "DefineProp"
|
|
128
|
+
|| typeName === "DefineVModel") {
|
|
129
|
+
// const isDefineVModel = (t.typeName as Identifier).value === "DefineVModel$";
|
|
130
|
+
const params = t.typeParams.params;
|
|
131
|
+
const name = extractTypeValue(params[0]) || "modelValue";
|
|
132
|
+
const type = extractTypeValue(params[1]);
|
|
133
|
+
const required = params.length > 2 ? extractTypeValue(params[2]) : false;
|
|
134
|
+
const defaultValue = params.length > 3 ? extractTypeValue(params[3], true) : undefined;
|
|
135
|
+
const description = params.length > 4 ? extractTypeValue(params[4]) : "";
|
|
136
|
+
const info = {
|
|
137
|
+
type: type,
|
|
138
|
+
description: description,
|
|
139
|
+
required: required.toString().toLowerCase() === "true" ? true : false
|
|
140
|
+
};
|
|
141
|
+
if (defaultValue !== undefined) {
|
|
142
|
+
info.defaultValue = defaultValue;
|
|
143
|
+
}
|
|
144
|
+
if (typeName === "DefineVModel") {
|
|
145
|
+
docResult[wc.componentOptions.elementName].models[name] = info;
|
|
146
|
+
}
|
|
147
|
+
else { // props
|
|
148
|
+
docResult[wc.componentOptions.elementName].props[name] = info;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
if (typeParams.length > 1) {
|
|
153
|
+
const emits = typeParams[1];
|
|
154
|
+
emits.types.forEach((t) => {
|
|
155
|
+
const typeName = t.typeName.value;
|
|
156
|
+
if (typeName === "DefineEmit") {
|
|
157
|
+
const params = t.typeParams.params;
|
|
158
|
+
const name = extractTypeValue(params[0]);
|
|
159
|
+
const type = extractTypeValue(params[1]);
|
|
160
|
+
const description = params.length > 2 ? extractTypeValue(params[2]) : "";
|
|
161
|
+
docResult[elementName].emits[name] = {
|
|
162
|
+
type: type,
|
|
163
|
+
description: description,
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
if (typeParams.length > 2) {
|
|
169
|
+
const slots = typeParams[2];
|
|
170
|
+
slots.types.forEach((t) => {
|
|
171
|
+
const typeName = t.typeName.value;
|
|
172
|
+
if (typeName === "DefineSlot") {
|
|
173
|
+
const params = t.typeParams.params;
|
|
174
|
+
const name = extractTypeValue(params[0]);
|
|
175
|
+
const type = extractTypeValue(params[1]);
|
|
176
|
+
const description = params.length > 2 ? extractTypeValue(params[2]) : "";
|
|
177
|
+
docResult[elementName].slots[name] = {
|
|
178
|
+
type: type,
|
|
179
|
+
description: description,
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
else {
|
|
186
|
+
b.expression.arguments[0].expression
|
|
187
|
+
.properties?.filter(p => p.key.value === "props"
|
|
188
|
+
|| p.key.value === "emits")
|
|
189
|
+
?.forEach(propsIdentifier => {
|
|
190
|
+
if (propsIdentifier) {
|
|
191
|
+
propsIdentifier.value
|
|
192
|
+
.properties?.forEach(p => {
|
|
193
|
+
const em = p.arguments;
|
|
194
|
+
if (em?.callee?.property?.value === "doc$") {
|
|
195
|
+
const PropertyResult = {
|
|
196
|
+
type: null,
|
|
197
|
+
propertyTypeAsString: "",
|
|
198
|
+
name: ""
|
|
199
|
+
};
|
|
200
|
+
getPropertyInfo(em, PropertyResult);
|
|
201
|
+
switch (PropertyResult.type) {
|
|
202
|
+
case DefineVueType.Prop:
|
|
203
|
+
docResult[elementName].props[PropertyResult.name] = {
|
|
204
|
+
type: PropertyResult.propertyTypeAsString,
|
|
205
|
+
description: em.arguments[0].expression.value
|
|
206
|
+
};
|
|
207
|
+
break;
|
|
208
|
+
case DefineVueType.Model:
|
|
209
|
+
docResult[elementName].models[PropertyResult.name] = {
|
|
210
|
+
type: PropertyResult.propertyTypeAsString,
|
|
211
|
+
description: em.arguments[0].expression.value
|
|
212
|
+
};
|
|
213
|
+
break;
|
|
214
|
+
case DefineVueType.Emit:
|
|
215
|
+
docResult[elementName].emits[PropertyResult.name] = {
|
|
216
|
+
type: PropertyResult.propertyTypeAsString,
|
|
217
|
+
description: em.arguments[0].expression.value
|
|
218
|
+
};
|
|
219
|
+
break;
|
|
220
|
+
case DefineVueType.Slot:
|
|
221
|
+
em.arguments[0].expression
|
|
222
|
+
.properties
|
|
223
|
+
.forEach(p => {
|
|
224
|
+
const slotName = p.key.value;
|
|
225
|
+
docResult[elementName].slots[slotName] = {
|
|
226
|
+
type: PropertyResult.propertyTypeAsObject[slotName],
|
|
227
|
+
description: p.value.value
|
|
228
|
+
};
|
|
229
|
+
});
|
|
230
|
+
break;
|
|
231
|
+
default:
|
|
232
|
+
break;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
catch (ex) {
|
|
243
|
+
tooling_1.utils.log(`Have a exception when extract doc$ for web component manifest -> ${wc.manifestPath}`, tooling_1.utils.LogTypes.Error);
|
|
244
|
+
console.error(ex);
|
|
245
|
+
throw new Error("Exit, have an exception.");
|
|
218
246
|
}
|
|
219
|
-
componentNodes.push({ name: name, elem: elem });
|
|
220
247
|
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
248
|
+
let docPath = path_1.default.resolve(__dirname, "ComponentDocRegistrations.ts");
|
|
249
|
+
;
|
|
250
|
+
let wcTypings = `
|
|
251
|
+
//{{importWC}}
|
|
252
|
+
|
|
253
|
+
type ExtractJsxProps<T> = {
|
|
254
|
+
[K in keyof (T extends { propsDefinition: any } ? T["propsDefinition"] : T)]: T extends {
|
|
255
|
+
propsDefinition: any;
|
|
256
|
+
}
|
|
257
|
+
? T["propsDefinition"][K]
|
|
258
|
+
: never;
|
|
259
|
+
} & { $children?: any; };
|
|
260
|
+
|
|
261
|
+
declare global {
|
|
262
|
+
namespace JSX {
|
|
263
|
+
interface Element { }
|
|
264
|
+
interface ElementClass { }
|
|
265
|
+
|
|
266
|
+
interface IntrinsicElements {
|
|
267
|
+
//{{elementName}}
|
|
238
268
|
}
|
|
239
|
-
elementDoc.props = props;
|
|
240
|
-
var samples = getSamples(elementInfo.interfaceFilePath);
|
|
241
|
-
elementDoc.samples = samples;
|
|
242
|
-
fxDocs[element] = elementDoc;
|
|
243
269
|
}
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
270
|
+
}`;
|
|
271
|
+
if (shared_1.isExtensionEnv) {
|
|
272
|
+
wcTypings = `import { VueComponentBaseProps } from "@omnia/fx/ux";
|
|
273
|
+
${wcTypings}`;
|
|
274
|
+
}
|
|
275
|
+
else {
|
|
276
|
+
wcTypings = `import { VueComponentBaseProps } from "../../../../client/fx/ux/index";
|
|
277
|
+
${wcTypings}`;
|
|
278
|
+
}
|
|
279
|
+
const elementNamespaces = {};
|
|
280
|
+
const wcNamespace = (0, shared_1.getBuildOption)()?.componentNamespace;
|
|
281
|
+
const info = shared_1.ConfigurationManager.outputInfo.get();
|
|
282
|
+
info.wc = {
|
|
283
|
+
namespaces: wcNamespace ? [wcNamespace] : null,
|
|
284
|
+
mappings: {}
|
|
285
|
+
};
|
|
286
|
+
await tooling_1.utils.asyncForEach(componentRegistrations, async (wc) => {
|
|
287
|
+
wcTypings = generateWebComponentTypings(wc, wcTypings, info, elementNamespaces);
|
|
288
|
+
if ((0, shared_1.getBuildOption)().docResourceManifestId) {
|
|
289
|
+
await buildDoc(wc);
|
|
261
290
|
}
|
|
291
|
+
});
|
|
292
|
+
if (Object.keys(elementNamespaces).length > 0) {
|
|
293
|
+
let result = `declare global {
|
|
294
|
+
//{{namespace}}
|
|
295
|
+
}`;
|
|
296
|
+
Object.keys(elementNamespaces).forEach(key => {
|
|
297
|
+
result = result.replace("//{{namespace}}", `
|
|
298
|
+
let ${key}: ${JSON.stringify(elementNamespaces[key], null, 2)
|
|
299
|
+
.replace(/\"typeof /g, "typeof ").replace(/ <<end>>\"/g, "")}
|
|
300
|
+
//{{namespace}}
|
|
301
|
+
`);
|
|
302
|
+
});
|
|
303
|
+
wcTypings = wcTypings + `
|
|
304
|
+
${result}
|
|
305
|
+
`;
|
|
306
|
+
}
|
|
307
|
+
if (Object.keys(docResult).length > 0) {
|
|
308
|
+
fsExtra.outputFileSync(docPath, `
|
|
309
|
+
import { extendApi } from "@omnia/fx";
|
|
310
|
+
import { ComponentDoc } from "@omnia/fx-models";
|
|
311
|
+
|
|
312
|
+
extendApi(api => api.fx.docs.registrations, api => {
|
|
313
|
+
|
|
314
|
+
const registrations: { [elementName: string]: ComponentDoc } = ${JSON.stringify(docResult)}
|
|
315
|
+
|
|
316
|
+
Object.keys(registrations).forEach(elementName => {
|
|
317
|
+
api.register(elementName, registrations[elementName]);
|
|
318
|
+
});
|
|
319
|
+
});
|
|
320
|
+
`);
|
|
321
|
+
// create dynamic doc manifest
|
|
322
|
+
tooling_composers_1.ManifestRegistry.setCurrentManifestPath(`${path_1.default.relative(tooling_1.utils.root(""), path_1.default.resolve(__dirname))}/`);
|
|
323
|
+
tooling_composers_1.Composer
|
|
324
|
+
.registerManifest((0, shared_1.getBuildOption)().docResourceManifestId || new fx_models_1.Guid(`${tooling_1.utils.generateGuid()}`), "omnia.fx.docs.components.registraions")
|
|
325
|
+
.registerResources({
|
|
326
|
+
resourcePaths: ["./ComponentDocRegistrations.ts"]
|
|
327
|
+
})
|
|
328
|
+
.withTarget(fx_models_1.ClientManifestTargetTypes.docs)
|
|
329
|
+
.extendApi(api => api.fx.docs.registrations);
|
|
330
|
+
tooling_composers_1.ManifestRegistry.setCurrentManifestPath();
|
|
262
331
|
}
|
|
332
|
+
shared_1.ConfigurationManager.webComponentTypings.update(wcTypings);
|
|
333
|
+
shared_1.ConfigurationManager.outputInfo.update(info);
|
|
334
|
+
tooling_1.utils.logTime('Done - Generate components typings and documentation', startTime);
|
|
263
335
|
}
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
if (
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
336
|
+
exports.generateComponentTypingsAndDoc = generateComponentTypingsAndDoc;
|
|
337
|
+
function generateWebComponentTypings(wc, template, info, elementNamespace) {
|
|
338
|
+
// export default defineVueWebComponent
|
|
339
|
+
const wcPath = wc.componentOptions.entryPointPath;
|
|
340
|
+
let content = fsExtra.readFileSync(wcPath, 'utf8');
|
|
341
|
+
if (content.indexOf("defineVueComponent") > -1) {
|
|
342
|
+
if (!new RegExp('export\\s+default\\s+').test(content)) {
|
|
343
|
+
throw new Error(`Missing statement 'export default a vue web component' in ${wcPath}`);
|
|
344
|
+
}
|
|
345
|
+
let friendlyManifestId = `wc${wc.manifest.resourceId.toString().replace(/-/g, '').toLowerCase()}`;
|
|
346
|
+
let importPath = wcPath.substring(0, wcPath.lastIndexOf('.tsx'));
|
|
347
|
+
if (importPath.indexOf("./") === 0) {
|
|
348
|
+
importPath = importPath.replace("./", "");
|
|
349
|
+
}
|
|
350
|
+
if (shared_1.isExtensionEnv) {
|
|
351
|
+
importPath = `../../../../${importPath}`;
|
|
352
|
+
}
|
|
353
|
+
else {
|
|
354
|
+
importPath = `../../../../${importPath}`;
|
|
355
|
+
}
|
|
356
|
+
if (info.wc.namespaces) {
|
|
357
|
+
let elementName = wc.componentOptions.elementName.replace(/-/g, ".");
|
|
358
|
+
const namespace = (wc.componentOptions.namespace === true ? "" : wc.componentOptions.namespace) || (0, shared_1.getBuildOption)()?.componentNamespace;
|
|
359
|
+
if (namespace && elementName.indexOf(`${namespace}.`) !== 0) {
|
|
360
|
+
elementName = `${namespace}.${elementName}`;
|
|
282
361
|
}
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
if (character === "{" && (!enteredScopeKind || enteredScopeKind === "{")) {
|
|
286
|
-
enteredScopeKind = "{";
|
|
287
|
-
scope++;
|
|
288
|
-
}
|
|
289
|
-
else if (character === "}" && enteredScopeKind === "{") {
|
|
290
|
-
scope--;
|
|
291
|
-
if (scope === 0)
|
|
292
|
-
break;
|
|
293
|
-
}
|
|
294
|
-
else if (character === "[" && (!enteredScopeKind || enteredScopeKind === "[")) {
|
|
295
|
-
enteredScopeKind = "[";
|
|
296
|
-
scope++;
|
|
297
|
-
}
|
|
298
|
-
else if (character === "]" && enteredScopeKind === "]") {
|
|
299
|
-
scope--;
|
|
300
|
-
if (scope === 0)
|
|
301
|
-
break;
|
|
302
|
-
}
|
|
303
|
-
else if (character === "'" && !enteredScopeKind) {
|
|
304
|
-
enteredScopeKind = "'";
|
|
305
|
-
}
|
|
306
|
-
else if (character === "'" && enteredScopeKind === "'" && beforeCharacter !== '\\') {
|
|
307
|
-
break;
|
|
308
|
-
}
|
|
309
|
-
else if (character === '"' && !enteredScopeKind) {
|
|
310
|
-
enteredScopeKind = '"';
|
|
311
|
-
}
|
|
312
|
-
else if (character === '"' && enteredScopeKind === '"' && beforeCharacter !== '\\') {
|
|
313
|
-
break;
|
|
314
|
-
}
|
|
362
|
+
if (info.wc.namespaces && info.wc.namespaces.indexOf(elementName.split(".")[0]) === -1) {
|
|
363
|
+
info.wc.namespaces.push(elementName.split(".")[0]);
|
|
315
364
|
}
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
function getPropertyNameFromPropDecorator(propDecorator) {
|
|
325
|
-
propDecorator = propDecorator.substring(propDecorator.lastIndexOf(')') + 1);
|
|
326
|
-
propDecorator = propDecorator.substring(0, propDecorator.lastIndexOf(':'));
|
|
327
|
-
var name = propDecorator.trim();
|
|
328
|
-
name = name.replace("?", ""); //remove optional in name
|
|
329
|
-
return name;
|
|
330
|
-
}
|
|
331
|
-
function getComponentProperties(rootModel, key, props) {
|
|
332
|
-
var model = rootModel[key];
|
|
333
|
-
var properties = model.properties;
|
|
334
|
-
for (var property of properties) {
|
|
335
|
-
props[property.name] = {
|
|
336
|
-
documentation: property.documentation,
|
|
337
|
-
type: property.type || 'any'
|
|
338
|
-
};
|
|
339
|
-
}
|
|
340
|
-
if (model.extends) {
|
|
341
|
-
for (var extend of model.extends) {
|
|
342
|
-
if (extend !== 'any') {
|
|
343
|
-
getComponentProperties(rootModel, extend, props);
|
|
365
|
+
info.wc.mappings[elementName] = wc.componentOptions.elementName;
|
|
366
|
+
try {
|
|
367
|
+
populateElementNamespace(elementNamespace, elementName, friendlyManifestId);
|
|
368
|
+
}
|
|
369
|
+
catch (ex) {
|
|
370
|
+
tooling_1.utils.log(`Have a exception in building element namespace with element name: ${wc.componentOptions.elementName}`, tooling_1.utils.LogTypes.Error);
|
|
371
|
+
console.error(ex);
|
|
372
|
+
throw new Error("Exit, have an exception.");
|
|
344
373
|
}
|
|
345
374
|
}
|
|
375
|
+
return template
|
|
376
|
+
.replace(/\/\/{{importWC}}/, `import ${friendlyManifestId} from '${importPath}';
|
|
377
|
+
//{{importWC}}`)
|
|
378
|
+
.replace(/\/\/{{elementName}}/, `"${wc.componentOptions.elementName}": typeof ${friendlyManifestId} extends { propsDefinition: infer TProp } ? (TProp & Omit<VueComponentBaseProps, keyof TProp>) : typeof ${friendlyManifestId} extends (...args: any[]) => any ? ExtractJsxProps<Pick<ReturnType<typeof ${friendlyManifestId}>, "propsDefinition">> : never
|
|
379
|
+
//{{elementName}}`);
|
|
380
|
+
// .replace(/\/\/{{nselementName}}/, `"${elementName}": { new(...args: any[]): { $props: typeof ${friendlyManifestId}.propsDefinition & Omit<VueComponentBaseProps, keyof typeof ${friendlyManifestId}.propsDefinition> } }
|
|
381
|
+
// //{{nselementName}}`)
|
|
346
382
|
}
|
|
383
|
+
return template;
|
|
347
384
|
}
|
|
348
|
-
function
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
385
|
+
function importSnippetCode(content, filePath) {
|
|
386
|
+
let result = content;
|
|
387
|
+
const ext = path_1.default.extname(filePath);
|
|
388
|
+
if (filePath.indexOf(".md.ts") > -1) {
|
|
389
|
+
result = content.replace(/\@import\/.*;/g, function (match) {
|
|
390
|
+
let fromLine = 0;
|
|
391
|
+
let toLine = 0;
|
|
392
|
+
const indexStartLine = match.indexOf("{");
|
|
393
|
+
if (indexStartLine > -1) {
|
|
394
|
+
const numbers = match.substring(indexStartLine + 1, match.indexOf("}")).split("-");
|
|
395
|
+
fromLine = Number(numbers[0]);
|
|
396
|
+
toLine = Number(numbers[1]);
|
|
397
|
+
}
|
|
398
|
+
const fileName = match.substring(0, indexStartLine || match.length - 1)
|
|
399
|
+
.replace("@import/", "")
|
|
400
|
+
.replace(";", "");
|
|
401
|
+
let fileContent = fs_1.default.readFileSync(fileName, 'utf-8');
|
|
402
|
+
if (fromLine > 0) {
|
|
403
|
+
fileContent = fileContent.split(/\r?\n/).slice(fromLine - 1, toLine).join("\n");
|
|
404
|
+
}
|
|
405
|
+
return fileContent;
|
|
406
|
+
});
|
|
366
407
|
}
|
|
367
408
|
return result;
|
|
368
409
|
}
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
410
|
+
exports.importSnippetCode = importSnippetCode;
|
|
411
|
+
function populateElementNamespace(namespace, elementName, importElement) {
|
|
412
|
+
const parts = elementName.split(".");
|
|
413
|
+
for (let i = 0; i < parts.length; i++) {
|
|
414
|
+
const name = parts[i];
|
|
415
|
+
if (typeof namespace === "string") {
|
|
416
|
+
throw new Error("Build element namespace -> that element name contain another element name");
|
|
417
|
+
}
|
|
418
|
+
if (!namespace[name]) {
|
|
419
|
+
if (i === parts.length - 1) {
|
|
420
|
+
namespace[name] = `typeof ${importElement} extends { propsDefinition: infer TProp } ? { new(...args: any[]): { $props: TProp & Omit<VueComponentBaseProps, keyof TProp> } } : typeof ${importElement} <<end>>`;
|
|
421
|
+
}
|
|
422
|
+
else {
|
|
423
|
+
namespace = namespace[name] = {};
|
|
377
424
|
}
|
|
378
425
|
}
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
}
|
|
382
|
-
//
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
return fs.readFileSync(filePath, 'utf-8');
|
|
392
|
-
}
|
|
393
|
-
function getAllFilesInFolderRecursively(dirPath) {
|
|
394
|
-
var files = [];
|
|
395
|
-
if (fs.existsSync(dirPath)) {
|
|
396
|
-
var paths = fs.readdirSync(dirPath).map(function (file) { return { dirPath: dirPath, filePath: dirPath + '\\' + file }; });
|
|
397
|
-
files = paths.filter(function (path) {
|
|
398
|
-
return fs.statSync(path.filePath).isFile() && path.filePath.indexOf('.manifest.ts') >= 0;
|
|
399
|
-
});
|
|
400
|
-
var folders = paths.filter(function (path) {
|
|
401
|
-
return fs.statSync(path.filePath).isFile() === false;
|
|
402
|
-
});
|
|
403
|
-
for (var path of folders) {
|
|
404
|
-
files = files.concat(getAllFilesInFolderRecursively(path.filePath));
|
|
426
|
+
else {
|
|
427
|
+
if (i === parts.length - 1) {
|
|
428
|
+
namespace[`${name}$`] = `typeof ${importElement} extends { propsDefinition: infer TProp } ? { new(...args: any[]): { $props: TProp & Omit<VueComponentBaseProps, keyof TProp> } } : typeof ${importElement} <<end>>`;
|
|
429
|
+
// throw new Error("Build element namespace -> Exist an element name contain a above that element name");
|
|
430
|
+
}
|
|
431
|
+
else {
|
|
432
|
+
if (typeof namespace[name] === "string") {
|
|
433
|
+
namespace[`${name}$`] = namespace[name];
|
|
434
|
+
namespace[name] = {};
|
|
435
|
+
}
|
|
436
|
+
namespace = namespace[name];
|
|
437
|
+
}
|
|
405
438
|
}
|
|
406
439
|
}
|
|
407
|
-
return files;
|
|
408
|
-
}
|
|
409
|
-
;
|
|
410
|
-
function extractDocPathForComponents(componentRegistrations) {
|
|
411
|
-
let componentsDocCount = 0;
|
|
412
|
-
let paths = [];
|
|
413
|
-
componentRegistrations.forEach((comp) => {
|
|
414
|
-
let defPaths = comp.componentOptions.documentations;
|
|
415
|
-
if (defPaths) {
|
|
416
|
-
componentsDocCount++;
|
|
417
|
-
defPaths.forEach((defPath) => {
|
|
418
|
-
paths.push((0, shared_1.convertManifestPathToEntryPath)(comp.manifestPath, [defPath])[0]);
|
|
419
|
-
//paths.push($.tooling.utils.root(convertManifestPathToEntryPath(comp.manifestPath, [defPath])[0]));
|
|
420
|
-
});
|
|
421
|
-
}
|
|
422
|
-
});
|
|
423
|
-
return { componentsDocCount, paths };
|
|
424
440
|
}
|