@omnia/tooling-vue 8.0.102-vnext → 8.0.104-vnext

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.
@@ -14,7 +14,7 @@ const fx_models_1 = require("@omnia/fx-models");
14
14
  const $ = tslib_1.__importStar(require("../variables"));
15
15
  const shared_1 = require("../shared");
16
16
  const tooling_1 = require("@omnia/tooling");
17
- const core_1 = require("@swc/core");
17
+ const doc_1 = require("./doc");
18
18
  const MiniCssExtractPlugin = require('mini-css-extract-plugin');
19
19
  const ConcatSource = require('webpack-core/lib/ConcatSource');
20
20
  const CircularDependencyPlugin = require('circular-dependency-plugin');
@@ -202,11 +202,12 @@ function buildEntries(serve = false) {
202
202
  var componentRegistry = $.composers.ComponentRegistry;
203
203
  let componentRegistrations = componentRegistry.getRegistrations();
204
204
  const serviceInfo = $.composers.ServiceManifestRegistry.getServiceInfo();
205
- if (serviceInfo.serviceType === tooling_composers_1.ServiceTypes.WebApp) {
206
- await generateComponentTypingsAndDoc(componentRegistrations);
207
- }
208
205
  startTime = new Date().getTime();
209
206
  $.tooling.logTime("Found [" + componentRegistrations.length + "] component registrations", startTime);
207
+ let componentEntries = createVueEntryFormComponentRegistrations(componentRegistrations);
208
+ if (serviceInfo.serviceType === tooling_composers_1.ServiceTypes.WebApp) {
209
+ await (0, doc_1.generateComponentTypingsAndDoc)(componentRegistrations);
210
+ }
210
211
  var resourceRegistry = $.composers.ResourceRegistry;
211
212
  let resourceBundlesWithBuildOptions = resourceRegistry.getRegisteredResourceBundles(shared_1.convertManifestPathToEntryPath);
212
213
  $.tooling.logTime("Found [" + resourceBundlesWithBuildOptions?.size + "] resource bundles", startTime);
@@ -222,7 +223,6 @@ function buildEntries(serve = false) {
222
223
  console.log("debug " + res[0] + " has build options for paths " + resource.paths + " buildoptions: " + JSON.stringify(resource.buildOptions));
223
224
  }
224
225
  }
225
- let componentEntries = createVueEntryFormRegistrations(componentRegistrations);
226
226
  var entries = $.merge(componentEntries, resourceEntries);
227
227
  if (checkDuplicateWebpackEntryPoints(entries)) {
228
228
  $.tooling.log('Build manifests metadata have error that found duplicated resource path', $.tooling.LogTypes.Error);
@@ -257,247 +257,6 @@ function buildEntries(serve = false) {
257
257
  }
258
258
  });
259
259
  }
260
- async function generateComponentTypingsAndDoc(componentRegistrations) {
261
- tooling_1.utils.log("Generate components typings and documentation running...");
262
- var startTime = new Date().getTime();
263
- let DefineVueType;
264
- (function (DefineVueType) {
265
- DefineVueType[DefineVueType["Prop"] = 0] = "Prop";
266
- DefineVueType[DefineVueType["Model"] = 1] = "Model";
267
- DefineVueType[DefineVueType["Slot"] = 2] = "Slot";
268
- DefineVueType[DefineVueType["Emit"] = 4] = "Emit";
269
- })(DefineVueType || (DefineVueType = {}));
270
- const docResult = {};
271
- function getPropertyFunctionTypeAsString(type) {
272
- let params = "";
273
- if (type.params?.length > 0) {
274
- type.params.forEach(p => {
275
- params += `${p.value}:${getPropertyType(p.typeAnnotation)}, `;
276
- });
277
- params = params.replace(/,\s*$/, "");
278
- }
279
- return `(${params}) => ${getPropertyType(type.typeAnnotation)}`;
280
- }
281
- function getPropertyType(tsType) {
282
- let result = "";
283
- if (tsType.type === "TsTypeAnnotation") {
284
- return getPropertyType(tsType.typeAnnotation);
285
- }
286
- switch (tsType.type) {
287
- case "TsLiteralType":
288
- result = tsType.literal.value;
289
- break;
290
- case "TsKeywordType":
291
- result = tsType.kind;
292
- break;
293
- case "TsTypeReference":
294
- result = tsType.typeName.value;
295
- break;
296
- case "TsFunctionType":
297
- result = getPropertyFunctionTypeAsString(tsType);
298
- break;
299
- default:
300
- break;
301
- }
302
- return result;
303
- }
304
- function getNameProperty(ce, result) {
305
- const identifier = ce.callee?.property?.value;
306
- if (identifier) {
307
- switch (identifier) {
308
- case "name":
309
- result.name = ce.arguments[0].expression.value;
310
- getNameProperty(ce.callee.object, result);
311
- break;
312
- case "vModel":
313
- result.type = DefineVueType.Model;
314
- result.propertyTypeAsString = getPropertyType(ce.typeArguments.params[0]);
315
- result.name = result.name ? `v-model:${result.name}` : result.name;
316
- break;
317
- case "slots":
318
- result.type = DefineVueType.Slot;
319
- result.propertyTypeAsObject = {};
320
- ce.typeArguments.params[0].members
321
- .forEach(m => {
322
- result.propertyTypeAsObject[m.key.value] = getPropertyType(m.typeAnnotation);
323
- });
324
- break;
325
- case "prop":
326
- result.type = DefineVueType.Prop;
327
- result.propertyTypeAsString = getPropertyType(ce.typeArguments.params[0]);
328
- break;
329
- case "emit":
330
- result.type = DefineVueType.Emit;
331
- result.propertyTypeAsString = getPropertyType(ce.typeArguments.params[0]);
332
- break;
333
- default:
334
- getNameProperty(ce.callee.object, result);
335
- }
336
- }
337
- }
338
- async function buildDoc(wc) {
339
- try {
340
- const wcPath = (0, shared_1.convertManifestPathToEntryPath)(wc.manifestPath, [wc.componentOptions.entryPoint])[0];
341
- const wcParseResult = await (0, core_1.parseFile)(wcPath, {
342
- syntax: 'typescript',
343
- target: 'es2020',
344
- tsx: true,
345
- decorators: true,
346
- dynamicImport: true
347
- });
348
- wcParseResult.body.forEach(b => {
349
- if (b.type === 'ExportDefaultExpression'
350
- && b.expression.callee?.value === "defineVueWebComponent") {
351
- b.expression.arguments[0].expression
352
- .properties?.filter(p => p.key.value === "props"
353
- || p.key.value === "emits")
354
- ?.forEach(propsIdentifier => {
355
- if (propsIdentifier) {
356
- propsIdentifier.value
357
- .properties?.forEach(p => {
358
- const em = p.arguments;
359
- if (em?.callee?.property?.value === "doc$") {
360
- const PropertyResult = {
361
- type: null,
362
- propertyTypeAsString: "",
363
- name: ""
364
- };
365
- getNameProperty(em, PropertyResult);
366
- if (!docResult[wc.componentOptions.elementName]) {
367
- docResult[wc.componentOptions.elementName] = {
368
- emits: {},
369
- models: {},
370
- props: {},
371
- slots: {}
372
- };
373
- }
374
- switch (PropertyResult.type) {
375
- case DefineVueType.Prop:
376
- docResult[wc.componentOptions.elementName].props[PropertyResult.name] = {
377
- type: PropertyResult.propertyTypeAsString,
378
- description: em.arguments[0].expression.value
379
- };
380
- break;
381
- case DefineVueType.Model:
382
- docResult[wc.componentOptions.elementName].models[PropertyResult.name] = {
383
- type: PropertyResult.propertyTypeAsString,
384
- description: em.arguments[0].expression.value
385
- };
386
- break;
387
- case DefineVueType.Emit:
388
- docResult[wc.componentOptions.elementName].emits[PropertyResult.name] = {
389
- type: PropertyResult.propertyTypeAsString,
390
- description: em.arguments[0].expression.value
391
- };
392
- break;
393
- case DefineVueType.Slot:
394
- em.arguments[0].expression
395
- .properties
396
- .forEach(p => {
397
- const slotName = p.key.value;
398
- docResult[wc.componentOptions.elementName].slots[slotName] = {
399
- type: PropertyResult.propertyTypeAsObject[slotName],
400
- description: p.value.value
401
- };
402
- });
403
- break;
404
- default:
405
- break;
406
- }
407
- }
408
- });
409
- }
410
- });
411
- }
412
- });
413
- }
414
- catch (ex) {
415
- tooling_1.utils.log(`Have a exception when extract doc$ for web component manifest -> ${wc.manifestPath}`, tooling_1.utils.LogTypes.Error);
416
- console.error(ex);
417
- throw new Error("Exit, have an exception.");
418
- }
419
- }
420
- let docPath = $.path.resolve(__dirname, "ComponentDocRegistrations.ts");
421
- ;
422
- const wcNamespace = getBuildOption()?.webComponentNamespace;
423
- const info = shared_1.ConfigurationManager.outputInfo.get();
424
- info.wc = {
425
- namespace: wcNamespace,
426
- mappings: {}
427
- };
428
- let wcTypings = wcNamespace ? `
429
- //{{importWC}}
430
- declare global {
431
- namespace JSX {
432
- interface Element { }
433
- interface ElementClass { }
434
-
435
- interface IntrinsicElements {
436
- //{{elementName}}
437
- }
438
- }
439
- }
440
-
441
- declare global {
442
- let ${wcNamespace}: {
443
- //{{nselementName}}
444
- };
445
- }
446
- `
447
- : `
448
- //{{importWC}}
449
- declare global {
450
- namespace JSX {
451
- interface Element { }
452
- interface ElementClass { }
453
-
454
- interface IntrinsicElements {
455
- //{{elementName}}
456
- }
457
- }
458
- }`;
459
- if ($.isExtensionEnv) {
460
- wcTypings = `import { VueComponentBaseProps } from "@omnia/fx/ux";
461
- ${wcTypings}`;
462
- }
463
- else {
464
- wcTypings = `import { VueComponentBaseProps } from "../../../../client/fx/ux/index";
465
- ${wcTypings}`;
466
- }
467
- await tooling_1.utils.asyncForEach(componentRegistrations, async (wc) => {
468
- wcTypings = generateWebComponentTypings(wc, wcTypings, info);
469
- await buildDoc(wc);
470
- });
471
- if (Object.keys(docResult).length > 0) {
472
- fsExtra.outputFileSync(docPath, `
473
- import { extendApi } from "@omnia/fx";
474
- import { ComponentDoc } from "@omnia/fx-models";
475
-
476
- extendApi(api => api.fx.docs.registrations, api => {
477
-
478
- const registrations: { [elementName: string]: ComponentDoc } = ${JSON.stringify(docResult)}
479
-
480
- Object.keys(registrations).forEach(elementName => {
481
- api.register(elementName, registrations[elementName]);
482
- });
483
- });
484
- `);
485
- // create dynamic doc manifest
486
- $.composers.ManifestRegistry.setCurrentManifestPath(`${path_1.default.relative(tooling_1.utils.root(""), path_1.default.resolve(__dirname))}/`);
487
- $.composers
488
- .Composer
489
- .registerManifest(getBuildOption().docResourceManifestId || new fx_models_1.Guid(`${tooling_1.utils.generateGuid()}`), "omnia.fx.docs.components.registraions")
490
- .registerResources({
491
- resourcePaths: ["./ComponentDocRegistrations.ts"]
492
- })
493
- .withTarget(fx_models_1.ClientManifestTargetTypes.Docs)
494
- .extendApi(api => api.fx.docs.registrations);
495
- $.composers.ManifestRegistry.setCurrentManifestPath();
496
- }
497
- shared_1.ConfigurationManager.webComponentTypings.update(wcTypings);
498
- shared_1.ConfigurationManager.outputInfo.update(info);
499
- tooling_1.utils.logTime('Done - Generate components typings and documentation', startTime);
500
- }
501
260
  function buildManifestMetadatas(entries) {
502
261
  return new Promise(function (resolve, reject) {
503
262
  try {
@@ -1561,89 +1320,18 @@ function getServiceId() {
1561
1320
  return serviceId;
1562
1321
  }
1563
1322
  exports.getServiceId = getServiceId;
1564
- function extractTypingsForComponents(componentRegistrations) {
1565
- let foundTypes = {};
1566
- componentRegistrations.forEach((comp) => {
1567
- let defPaths = comp.componentOptions.typings;
1568
- if (defPaths) {
1569
- let isChildSpec = false;
1570
- defPaths.forEach((defPath) => {
1571
- let entryPointPath = (0, shared_1.convertManifestPathToEntryPath)(comp.manifestPath, [defPath])[0];
1572
- let contents = $.fs.readFileSync(entryPointPath, 'utf8');
1573
- let wcEl = getWcElement(contents, isChildSpec);
1574
- if (wcEl) {
1575
- //Now lets find the interface mapped to element
1576
- //example /*@WebComponentInterface("omfx-dialog")*/
1577
- let interfaceToken = `/*@WebComponentInterface("${wcEl}")*/`;
1578
- let interfaceIndex = contents.indexOf(interfaceToken);
1579
- if (interfaceIndex > -1) {
1580
- let wcProps = [];
1581
- let intf = contents.substring(interfaceIndex);
1582
- let nextIsDomProp = false;
1583
- intf = intf
1584
- .substring(intf.indexOf("{") + 1, intf.indexOf("}"))
1585
- .replace(/\?/g, '')
1586
- .trim()
1587
- .split(/\r\n|\r|\n/g).forEach((group) => {
1588
- /*@DomProperty*/
1589
- let sub = group.trim();
1590
- if (sub.indexOf("/*@DomProperty*/") > -1) {
1591
- nextIsDomProp = true;
1592
- return;
1593
- }
1594
- if (nextIsDomProp) {
1595
- if (sub.indexOf(':')) {
1596
- sub = sub.split(':')[0];
1597
- }
1598
- if (sub) {
1599
- if (!foundTypes[wcEl]) {
1600
- foundTypes[wcEl] = [];
1601
- }
1602
- foundTypes[wcEl].push(sub);
1603
- }
1604
- nextIsDomProp = false;
1605
- }
1606
- });
1607
- }
1608
- }
1609
- isChildSpec = true;
1610
- });
1611
- }
1612
- });
1613
- return foundTypes;
1614
- }
1615
- var lastWcElement = "";
1616
- function getWcElement(contents, isChildSpec) {
1617
- if (isChildSpec) {
1618
- if (lastWcElement === "") {
1619
- new Error("Cant find the /*@DomProperty*/ on the parent interface for the WebComponent definition");
1620
- }
1621
- return lastWcElement;
1622
- }
1623
- else {
1624
- lastWcElement = "";
1625
- }
1626
- let wcElToken = "/*@WebComponent*/";
1627
- let wcElIndex = contents.indexOf(wcElToken);
1628
- let wcEl = "";
1629
- if (wcElIndex > -1) {
1630
- wcEl = contents.substring(wcElIndex);
1631
- wcEl = wcEl.substring(wcEl.indexOf('"') + 1);
1632
- wcEl = wcEl.substring(0, wcEl.indexOf('"'));
1633
- lastWcElement = wcEl;
1634
- }
1635
- return lastWcElement;
1636
- }
1637
- function createVueEntryFormRegistrations(registrations) {
1323
+ function createVueEntryFormComponentRegistrations(registrations) {
1638
1324
  let entryPaths = {};
1639
1325
  for (let r of registrations) {
1640
- if (r.componentOptions.entryPoint.endsWith('.jsx') || r.componentOptions.entryPoint.endsWith('.vue') || r.componentOptions.entryPoint.endsWith('.tsx') || r.componentOptions.entryPoint.endsWith('.ts')) {
1326
+ if (r.componentOptions.entryPoint.endsWith('.tsx')
1327
+ || r.componentOptions.entryPoint.endsWith('.vue')) {
1641
1328
  let entryPointPath = (0, shared_1.convertManifestPathToEntryPath)(r.manifestPath, [r.componentOptions.entryPoint]);
1642
1329
  let entryId = r.manifest.resourceId;
1643
1330
  if (r.manifest.resourceName) {
1644
1331
  entryId = `${r.manifest.resourceName}_${entryId}`;
1645
1332
  }
1646
- entryPaths[entryId] = entryPointPath;
1333
+ r.componentOptions.entryPointPath = entryPointPath[0];
1334
+ entryPaths[entryId.toString()] = entryPointPath;
1647
1335
  }
1648
1336
  else {
1649
1337
  $.tooling.log('The OmniaFx build system only supports .jsx, .vue and .tsx based components at the moment ', $.tooling.LogTypes.Error);
@@ -1963,35 +1651,3 @@ function sortString(a, b) {
1963
1651
  }
1964
1652
  return -1;
1965
1653
  }
1966
- function generateWebComponentTypings(wc, template, info) {
1967
- // export default defineVueWebComponent
1968
- let wcPath = (0, shared_1.convertManifestPathToEntryPath)(wc.manifestPath, [wc.componentOptions.entryPoint])[0];
1969
- let content = fsExtra.readFileSync(wcPath, 'utf8');
1970
- if (content.indexOf("defineVueWebComponent") > -1) {
1971
- if (!new RegExp('export\\s+default\\s+').test(content)) {
1972
- throw new Error(`Missing statement 'export default a vue web component' in ${wcPath}`);
1973
- }
1974
- let friendlyManifestId = `wc${wc.manifest.resourceId.toString().replace(/-/g, '').toLowerCase()}`;
1975
- let importPath = wcPath.substring(0, wcPath.lastIndexOf('.tsx'));
1976
- if (importPath.indexOf("./") === 0) {
1977
- importPath = importPath.replace("./", "");
1978
- }
1979
- if ($.isExtensionEnv) {
1980
- importPath = `../../../../${importPath}`;
1981
- }
1982
- else {
1983
- importPath = `../../../../${importPath}`;
1984
- }
1985
- let elementNamePascalCase = wc.componentOptions.elementName.replace("omfx-", "").replace(/-([a-z])/g, function (g) { return g[1].toUpperCase(); });
1986
- elementNamePascalCase = elementNamePascalCase[0].toUpperCase() + elementNamePascalCase.substring(1, elementNamePascalCase.length);
1987
- info.wc.mappings[elementNamePascalCase] = wc.componentOptions.elementName;
1988
- return template
1989
- .replace(/\/\/{{importWC}}/, `import ${friendlyManifestId} from '${importPath}';
1990
- //{{importWC}}`)
1991
- .replace(/\/\/{{elementName}}/, `"${wc.componentOptions.elementName}": typeof ${friendlyManifestId}.propsDefinition & Omit<VueComponentBaseProps, keyof typeof ${friendlyManifestId}.propsDefinition>
1992
- //{{elementName}}`)
1993
- .replace(/\/\/{{nselementName}}/, `"${elementNamePascalCase}": { new(...args: any[]): { $props: typeof ${friendlyManifestId}.propsDefinition & Omit<VueComponentBaseProps, keyof typeof ${friendlyManifestId}.propsDefinition> } }
1994
- //{{nselementName}}`);
1995
- }
1996
- return template;
1997
- }
@@ -1 +1,2 @@
1
- export {};
1
+ import { ComponentRegistration } from "@omnia/tooling-composers";
2
+ export declare function generateComponentTypingsAndDoc(componentRegistrations: ComponentRegistration[]): Promise<void>;