@omnia/tooling-vue 8.0.103-dev → 8.0.104-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.
@@ -7,237 +7,23 @@ const path_1 = tslib_1.__importDefault(require("path"));
7
7
  const shared_1 = require("../shared");
8
8
  const tooling_composers_1 = require("@omnia/tooling-composers");
9
9
  const tooling_1 = require("@omnia/tooling");
10
- const core_1 = require("@swc/core");
11
10
  const fsExtra = tslib_1.__importStar(require("fs-extra"));
12
11
  const fx_models_1 = require("@omnia/fx-models");
13
12
  async function generateComponentTypingsAndDoc(componentRegistrations) {
14
13
  tooling_1.utils.log("Generate components typings and documentation running...");
15
14
  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
15
  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)}`;
33
- }
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;
43
- }
44
- else {
45
- result = tsType.literal.value;
46
- }
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;
62
- }
63
- return result;
64
- }
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);
96
- }
97
- }
98
- }
99
16
  async function buildDoc(wc) {
100
17
  try {
101
18
  const wcPath = (0, shared_1.convertManifestPathToEntryPath)(wc.manifestPath, [wc.componentOptions.entryPoint])[0];
102
19
  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
- });
20
+ const result = (0, shared_1.extractVueComponentInfo)(wcPath);
21
+ docResult[elementName] = {
22
+ emits: result.emits,
23
+ models: result.models,
24
+ props: result.props,
25
+ slots: result.slots
26
+ };
241
27
  }
242
28
  catch (ex) {
243
29
  tooling_1.utils.log(`Have a exception when extract doc$ for web component manifest -> ${wc.manifestPath}`, tooling_1.utils.LogTypes.Error);
@@ -246,7 +32,6 @@ async function generateComponentTypingsAndDoc(componentRegistrations) {
246
32
  }
247
33
  }
248
34
  let docPath = path_1.default.resolve(__dirname, "ComponentDocRegistrations.ts");
249
- ;
250
35
  let wcTypings = `
251
36
  //{{importWC}}
252
37
 
@@ -153,7 +153,7 @@ async function buildFileGraph(unknownId, code) {
153
153
  return { fileGraph, code };
154
154
  }
155
155
  fileGraph.js.scanned = true;
156
- code = (0, shared_1.transformVueComponent)(code, fileGraph.id);
156
+ code = (0, shared_1.transformDefineVueComponent)(code, fileGraph.id);
157
157
  const esbuildTransformResult = await (0, vite_1.transformWithEsbuild)(code, id, esbuildTransformOptions);
158
158
  code = esbuildTransformResult.code;
159
159
  // d.ts or interface only
@@ -50,6 +50,9 @@ function default_1() {
50
50
  {
51
51
  loader: path.resolve(__dirname, $.isExtensionEnv ? './esbuild-custom-loader.js' : './esbuild-custom-loader.ts'),
52
52
  },
53
+ {
54
+ loader: path.resolve(__dirname, $.isExtensionEnv ? './vue-component-loader.js' : './vue-component-loader.ts'),
55
+ },
53
56
  {
54
57
  loader: 'esbuild-loader',
55
58
  options: {
@@ -65,9 +68,9 @@ function default_1() {
65
68
  }
66
69
  },
67
70
  },
68
- {
69
- loader: path.resolve(__dirname, $.isExtensionEnv ? './wc-loader.js' : './wc-loader.ts'),
70
- }
71
+ // {
72
+ // loader: path.resolve(__dirname, $.isExtensionEnv ? './vue-component-loader.js' : './vue-component-loader.ts'),
73
+ // }
71
74
  ];
72
75
  return [
73
76
  {
@@ -5,7 +5,7 @@ const path_1 = tslib_1.__importDefault(require("path"));
5
5
  const shared_1 = require("../shared");
6
6
  function default_1(content, context) {
7
7
  const filePath = "./" + path_1.default.relative(process.cwd(), this.resourcePath).replace(/\\/g, "/");
8
- content = (0, shared_1.transformVueComponent)(content, filePath);
8
+ content = (0, shared_1.transformDefineVueComponent)(content, filePath);
9
9
  return content;
10
10
  }
11
11
  exports.default = default_1;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@omnia/tooling-vue",
3
3
  "license": "MIT",
4
- "version": "8.0.103-dev",
4
+ "version": "8.0.104-dev",
5
5
  "description": "Used to bundle and serve manifests web component that build on Vue framework.",
6
6
  "scripts": {
7
7
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -19,8 +19,8 @@
19
19
  ],
20
20
  "author": "Precio Fishbone",
21
21
  "dependencies": {
22
- "@omnia/fx-models": "8.0.103-dev",
23
- "@omnia/tooling-composers": "8.0.103-dev",
22
+ "@omnia/fx-models": "8.0.104-dev",
23
+ "@omnia/tooling-composers": "8.0.104-dev",
24
24
  "@types/mousetrap": "1.5.34",
25
25
  "@types/quill": "1.3.6",
26
26
  "@types/zepto": "1.0.29",