@omnia/tooling-vue 8.0.109-vnext → 8.0.110-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.
Files changed (34) hide show
  1. package/internal-do-not-import-from-here/config/omnia.fx.core_a2892051-fd9f-4056-ae8d-30d16d48417d.manifest.json +1 -0
  2. package/internal-do-not-import-from-here/config/omnia.fx.ux.libs_0fe5c5f2-8d89-485b-afd4-36fe3ff5943a.manifest.json +1 -0
  3. package/internal-do-not-import-from-here/config/omnia.fx.ux_dee030cc-4ab3-4158-bb06-8049f5c67542.manifest.json +1 -0
  4. package/internal-do-not-import-from-here/config/omnia.fx_a5a89056-b5f5-475d-8518-a1f55090379d.manifest.json +1 -0
  5. package/internal-do-not-import-from-here/config/omnia.vendor.manifest.json +1 -1
  6. package/internal-do-not-import-from-here/config/tooling.output.json +1 -1
  7. package/internal-do-not-import-from-here/config/wctypings.d.ts +4460 -1570
  8. package/internal-do-not-import-from-here/shared.d.ts +32 -10
  9. package/internal-do-not-import-from-here/shared.js +313 -27
  10. package/internal-do-not-import-from-here/tasks/ComponentDocRegistrations.js +1 -1
  11. package/internal-do-not-import-from-here/tasks/bundle.js +92 -32
  12. package/internal-do-not-import-from-here/tasks/doc.d.ts +1 -0
  13. package/internal-do-not-import-from-here/tasks/doc.js +125 -183
  14. package/internal-do-not-import-from-here/tasks/vendor.js +22 -16
  15. package/internal-do-not-import-from-here/vite/hmr/graph.js +3 -1
  16. package/internal-do-not-import-from-here/vite/hmr/vueJsx.js +3 -2
  17. package/internal-do-not-import-from-here/vite/index.js +1 -1
  18. package/internal-do-not-import-from-here/vite/plugins/OmniaPlugin.js +1 -1
  19. package/internal-do-not-import-from-here/webpack-loaders/doc-loader.d.ts +1 -0
  20. package/internal-do-not-import-from-here/webpack-loaders/doc-loader.js +11 -0
  21. package/internal-do-not-import-from-here/webpack-loaders/esbuild-custom-loader.d.ts +1 -0
  22. package/internal-do-not-import-from-here/webpack-loaders/esbuild-custom-loader.js +10 -0
  23. package/internal-do-not-import-from-here/webpack-loaders/ts-loader.d.ts +5 -2
  24. package/internal-do-not-import-from-here/webpack-loaders/ts-loader.js +8 -0
  25. package/internal-do-not-import-from-here/webpack-loaders/tsx-loader.d.ts +3 -3
  26. package/internal-do-not-import-from-here/webpack-loaders/tsx-loader.js +9 -3
  27. package/internal-do-not-import-from-here/webpack-loaders/vue-component-loader.d.ts +1 -0
  28. package/internal-do-not-import-from-here/webpack-loaders/{wc-loader.js → vue-component-loader.js} +3 -1
  29. package/internal-do-not-import-from-here/webpack-plugins/stylexjs/index.d.ts +53 -0
  30. package/internal-do-not-import-from-here/webpack-plugins/stylexjs/index.js +194 -0
  31. package/internal-do-not-import-from-here/webpack-plugins/stylexjs/loader.d.ts +9 -0
  32. package/internal-do-not-import-from-here/webpack-plugins/stylexjs/loader.js +23 -0
  33. package/package.json +10 -10
  34. package/internal-do-not-import-from-here/webpack-loaders/wc-loader.d.ts +0 -1
@@ -15,6 +15,7 @@ const $ = tslib_1.__importStar(require("../variables"));
15
15
  const shared_1 = require("../shared");
16
16
  const tooling_1 = require("@omnia/tooling");
17
17
  const doc_1 = require("./doc");
18
+ const stylexjs_1 = require("../webpack-plugins/stylexjs");
18
19
  const MiniCssExtractPlugin = require('mini-css-extract-plugin');
19
20
  const ConcatSource = require('webpack-core/lib/ConcatSource');
20
21
  const CircularDependencyPlugin = require('circular-dependency-plugin');
@@ -257,7 +258,7 @@ function buildEntries(serve = false) {
257
258
  }
258
259
  });
259
260
  }
260
- function buildManifestMetadatas(entries) {
261
+ function buildManifestMetadata(entries) {
261
262
  return new Promise(function (resolve, reject) {
262
263
  try {
263
264
  var startTime = new Date().getTime();
@@ -344,7 +345,7 @@ function beforeBundleManifest(entries) {
344
345
  // isRunBuildMetadata = !isEqual(entries, cachedEntries);
345
346
  // }
346
347
  // }
347
- if ($.fs.existsSync(cachedEntriesPath)) {
348
+ if (!isBuildWebpackManifestOnly() && $.fs.existsSync(cachedEntriesPath)) {
348
349
  let cachedEntries = require(cachedEntriesPath);
349
350
  isRunBuildMetadata = !isEqual(entries, cachedEntries);
350
351
  }
@@ -376,9 +377,15 @@ function beforeBundleManifest(entries) {
376
377
  fsExtra.writeJsonSync(manifestPath, content);
377
378
  }
378
379
  });
379
- buildManifestMetadatas(entriesToBuild).then(() => {
380
+ buildManifestMetadata(entriesToBuild).then(() => {
380
381
  fsExtra.ensureFileSync(cachedEntriesPath);
381
382
  fsExtra.writeJsonSync(cachedEntriesPath, entries);
383
+ if (isBuildWebpackManifestOnly()) {
384
+ fsExtra.copyFileSync(`${outDirManifestMetadata}/omnia.fx.core_a2892051-fd9f-4056-ae8d-30d16d48417d.manifest.json`, "client/tooling/vue/config/omnia.fx.core_a2892051-fd9f-4056-ae8d-30d16d48417d.manifest.json");
385
+ fsExtra.copyFileSync(`${outDirManifestMetadata}/omnia.fx_a5a89056-b5f5-475d-8518-a1f55090379d.manifest.json`, "client/tooling/vue/config/omnia.fx_a5a89056-b5f5-475d-8518-a1f55090379d.manifest.json");
386
+ fsExtra.copyFileSync(`${outDirManifestMetadata}/omnia.fx.ux_dee030cc-4ab3-4158-bb06-8049f5c67542.manifest.json`, "client/tooling/vue/config/omnia.fx.ux_dee030cc-4ab3-4158-bb06-8049f5c67542.manifest.json");
387
+ fsExtra.copyFileSync(`${outDirManifestMetadata}/omnia.fx.ux.libs_0fe5c5f2-8d89-485b-afd4-36fe3ff5943a.manifest.json`, "client/tooling/vue/config/omnia.fx.ux.libs_0fe5c5f2-8d89-485b-afd4-36fe3ff5943a.manifest.json");
388
+ }
382
389
  resolve(entries);
383
390
  });
384
391
  }
@@ -518,12 +525,15 @@ function afterGenerateManifestsMetadata() {
518
525
  .then(resolve, reject);
519
526
  });
520
527
  }
528
+ function isBuildWebpackManifestOnly() {
529
+ return process.argv?.find(argv => argv === "--webpackManifest") !== undefined;
530
+ }
521
531
  function minifyBundles() {
522
532
  return new Promise(function (resolve, reject) {
523
533
  if (process.argv.length > 0 && process.argv.find(argv => argv === "--minify") !== undefined) {
524
534
  let startTime = new Date().getTime();
525
535
  $.tooling.log('Minify bundles running...');
526
- const jsPaths = (0, globby_1.globbySync)([`${$.tooling.utils.root($.tooling.composer.OmniaOutput.OutputBundlePath)}/*.js`]);
536
+ const jsPaths = (0, globby_1.globbySync)([`${$.tooling.utils.root($.tooling.composer.OmniaOutput.OutputBundlePath).replace(/\\/g, "/")}/*.js`]);
527
537
  let promises = [];
528
538
  jsPaths.forEach(filePath => {
529
539
  promises.push(new Promise(async (resolve, reject) => {
@@ -580,6 +590,25 @@ function createVueWebpackConfig(currentEntry, entries, bundleOutputDir, viteHmrO
580
590
  ...referenceManifests,
581
591
  extractCss,
582
592
  new $.omniaWebpackPlugins.NamedModulesPlugin(buildModuleName()),
593
+ new stylexjs_1.StylexPlugin({
594
+ // filename: 'styles.[contenthash].css',
595
+ filename: `${Object.keys(entry)[0]}.css`,
596
+ // get webpack mode and set value for dev
597
+ dev: false,
598
+ // Use statically generated CSS files and not runtime injected CSS.
599
+ // Even in development.
600
+ runtimeInjection: false,
601
+ // optional. default: 'x'
602
+ classNamePrefix: 'o',
603
+ // Required for CSS variable support
604
+ unstable_moduleResolution: {
605
+ // type: 'commonJS' | 'haste'
606
+ // default: 'commonJS'
607
+ type: 'commonJS',
608
+ // The absolute path to the root directory of your project
609
+ rootDir: __dirname,
610
+ },
611
+ }),
583
612
  ];
584
613
  if (!buildOption.detectCircularDependencyOptions || buildOption.detectCircularDependencyOptions.disable !== true) {
585
614
  plugins.unshift(new CircularDependencyPlugin({
@@ -652,10 +681,10 @@ function createVueWebpackConfig(currentEntry, entries, bundleOutputDir, viteHmrO
652
681
  plugins.push(new $.omniaWebpackPlugins.ChunkAssets(function (compilation, fileName) {
653
682
  chunkAsset(entries, compilation, fileName, viteHmrOption);
654
683
  }));
655
- let webpackEntries = {};
656
- Object.keys(entry).forEach(name => {
657
- webpackEntries[name] = { import: entry[name] };
658
- });
684
+ // let webpackEntries = {};
685
+ // Object.keys(entry).forEach(name => {
686
+ // webpackEntries[name] = { import: entry[name] }
687
+ // })
659
688
  return {
660
689
  mode: 'production',
661
690
  devtool: false,
@@ -683,7 +712,7 @@ function createVueWebpackConfig(currentEntry, entries, bundleOutputDir, viteHmrO
683
712
  '@microsoft/signalr$': '@microsoft/signalr/dist/webworker/signalr.js',
684
713
  }),
685
714
  },
686
- target: ['web', 'es2022'],
715
+ target: ['web', 'es2022'], // Will change ES6 when stop support IE11
687
716
  output: {
688
717
  //library: {
689
718
  // type: "umd"
@@ -718,8 +747,8 @@ function createVueWebpackConfig(currentEntry, entries, bundleOutputDir, viteHmrO
718
747
  }
719
748
  return false;
720
749
  },
721
- // use: 'null-loader',
722
750
  use: [
751
+ // 'null-loader',
723
752
  {
724
753
  loader: path_1.default.resolve(__dirname, $.isExtensionEnv ? '../webpack-loaders/ingore-vuetify-locale.js' : '../webpack-loaders/ingore-vuetify-locale.ts'),
725
754
  }
@@ -833,7 +862,7 @@ function createWebpackConfigForManifestMetadata(entry, metadataOutputDir) {
833
862
  var entensionId = getServiceId();
834
863
  return Object.assign({}, getBaseWebpackConfigForManifestMetadata(entry, metadataOutputDir), {
835
864
  plugins: [
836
- ...buildReferenceManifestFromConfig(),
865
+ ...buildReferenceManifestFromConfig(Object.keys(entry)[0]),
837
866
  new $.omniaWebpackPlugins.NamedModulesPlugin(buildModuleName()),
838
867
  new $.webpack.DllPlugin({
839
868
  entryOnly: false,
@@ -1061,9 +1090,10 @@ function createCombinedManfest(omniaServiceId, manifestIds, targetManifestId, ta
1061
1090
  if (manifestIds &&
1062
1091
  targetManifestId &&
1063
1092
  manifestIds.length > 0) {
1064
- let manifestIdToFileNameMap = {};
1065
- let targetFileName = `${targetManifestName ? targetManifestName + "_" : ""}${targetManifestId}.js`;
1066
- manifestIdToFileNameMap[targetManifestId] = targetFileName;
1093
+ const manifestIdToFileNameMap = {};
1094
+ const targetJsFileName = `${targetManifestName ? targetManifestName + "_" : ""}${targetManifestId}.js`;
1095
+ const targetCssFileName = `${targetManifestName ? targetManifestName + "_" : ""}${targetManifestId}.css`;
1096
+ manifestIdToFileNameMap[targetManifestId] = targetJsFileName;
1067
1097
  $.tooling.log("Creating manifest group bundle [" + targetManifestId + "]", $.tooling.LogTypes.HeadLine);
1068
1098
  let omniaServiceId = getServiceId();
1069
1099
  manifestIds.sort((manifestId1, manifestId2) => {
@@ -1080,18 +1110,32 @@ function createCombinedManfest(omniaServiceId, manifestIds, targetManifestId, ta
1080
1110
  }
1081
1111
  return result;
1082
1112
  });
1083
- let bundleNames = [];
1113
+ const jsBundleNames = [];
1114
+ const cssBundleNames = [];
1084
1115
  for (let i = 0; i < manifestIds.length; i++) {
1085
1116
  let manifest = $.composers.LoadableManifestRegistry.getRegisteredManifest(manifestIds[i]);
1086
- bundleNames[i] = outputDir + `/${manifest.resourceName ? manifest.resourceName + "_" : ""}${manifest.resourceId}.js`;
1087
- if (!$.fs.existsSync(bundleNames[i])) {
1088
- throw new Error("Error, can't create combined bundle: " + targetFileName + " can't find bundle to include: " + bundleNames[i]);
1117
+ jsBundleNames[i] = outputDir + `/${manifest.resourceName ? manifest.resourceName + "_" : ""}${manifest.resourceId}.js`;
1118
+ const cssFilePath = outputDir + `/${manifest.resourceName ? manifest.resourceName + "_" : ""}${manifest.resourceId}.css`;
1119
+ if (!fsExtra.existsSync(jsBundleNames[i])) {
1120
+ throw new Error("Error, can't create combined bundle: " + targetJsFileName + " can't find bundle to include: " + jsBundleNames[i]);
1121
+ }
1122
+ if (fsExtra.existsSync(cssFilePath)) {
1123
+ cssBundleNames.push(cssFilePath);
1089
1124
  }
1090
- manifestIdToFileNameMap[manifestIds[i]] = bundleNames[i];
1125
+ manifestIdToFileNameMap[manifestIds[i]] = jsBundleNames[i];
1091
1126
  $.tooling.log("Adding manifest bundle [" + manifestIds[i] + "] to group", $.tooling.LogTypes.Info);
1092
1127
  }
1093
- let mergedContent = "";
1094
- bundleNames.forEach(filePath => {
1128
+ let mergedCssContent = "";
1129
+ cssBundleNames.forEach(filePath => {
1130
+ mergedCssContent = `${mergedCssContent}
1131
+ ${fsExtra.readFileSync(filePath, 'utf8')}
1132
+ `;
1133
+ });
1134
+ if (mergedCssContent) {
1135
+ fsExtra.writeFileSync(`${outputDir}/${targetCssFileName}`, mergedCssContent);
1136
+ }
1137
+ let mergedJsContent = "";
1138
+ jsBundleNames.forEach(filePath => {
1095
1139
  let manifestId = "";
1096
1140
  let currentFilename = $.path.basename(filePath);
1097
1141
  for (let id in manifestIdToFileNameMap) {
@@ -1104,13 +1148,13 @@ function createCombinedManfest(omniaServiceId, manifestIds, targetManifestId, ta
1104
1148
  throw Error("Couldn't extract manifest id from filename: " + currentFilename);
1105
1149
  }
1106
1150
  let content = fsExtra.readFileSync(filePath, 'utf8');
1107
- mergedContent = `
1108
- ${mergedContent}
1151
+ mergedJsContent = `
1152
+ ${mergedJsContent}
1109
1153
  /* Start of resource:${manifestId} */omniaWebpackJsonp["bb000000-0000-bbbb-0000-0000000000bb"]["${fx_models_1.OmniaResourceManifests.FxCore.toString()}"]("06e712d2-9897-4891-9353-148547efe61c").ManifestResourceLoader.registerWebComponentFromGroupBundle("${omniaServiceId}", "${manifestId}", "${targetManifestId}", function(){
1110
1154
  ${content}
1111
1155
  })//End of resource:${manifestId} `;
1112
1156
  });
1113
- fsExtra.writeFileSync(`${outputDir}/${targetFileName}`, `/******/ if (typeof omniaLoader === 'undefined') {
1157
+ fsExtra.writeFileSync(`${outputDir}/${targetJsFileName}`, `/******/ if (typeof omniaLoader === 'undefined') {
1114
1158
  /******/ globalThis['omniaLoader'] = {};
1115
1159
  /******/ }
1116
1160
  /******/ omniaLoader['${omniaServiceId}'] = omniaLoader['${omniaServiceId}'] || {};
@@ -1119,7 +1163,7 @@ ${content}
1119
1163
  /******/
1120
1164
  }
1121
1165
  /******/ omniaLoader['${omniaServiceId}']['${targetManifestId}'] = function () {
1122
- ${mergedContent}
1166
+ ${mergedJsContent}
1123
1167
  }
1124
1168
  ${$.composers.LoadableManifestRegistry.isDefineWithNoDependency(targetManifestId) ? `omniaLoader['${omniaServiceId}']['${targetManifestId}']()` : ''}`, 'utf8');
1125
1169
  $.tooling.log("Done - Creating manifest group bundle for manifest id: " + targetManifestId, $.tooling.LogTypes.HeadLine);
@@ -1203,12 +1247,17 @@ function buildReferenceManifest(currentEntry, entries) {
1203
1247
  var manifests = [];
1204
1248
  var dynamicReferenceManifests = [];
1205
1249
  let buildOptions = getBuildOption();
1206
- if (buildOptions && buildOptions.bundleOptions && buildOptions.bundleOptions.commonsChunk)
1207
- return dynamicReferenceManifests.concat(buildReferenceManifestFromConfig());
1208
1250
  var currentEntryName = Object.keys(currentEntry)[0];
1209
- // exclude omnia vendor
1210
- if (currentEntryName.indexOf(fx_models_1.OmniaResourceManifests.Vendor.toString()) === -1
1211
- && currentEntryName.indexOf(vendorProdId) === -1) {
1251
+ if (buildOptions && buildOptions.bundleOptions && buildOptions.bundleOptions.commonsChunk)
1252
+ return dynamicReferenceManifests.concat(buildReferenceManifestFromConfig(currentEntryName));
1253
+ // exclude pre-built webpack manifest
1254
+ if ($.isExtensionEnv
1255
+ || (currentEntryName.indexOf(fx_models_1.OmniaResourceManifests.Vendor.toString()) === -1
1256
+ && currentEntryName.indexOf(vendorProdId) === -1
1257
+ // && currentEntryName.indexOf(OmniaResourceManifests.FxCore.toString()) === -1
1258
+ // && currentEntryName.indexOf(OmniaResourceManifests.Fx.toString()) === -1
1259
+ // && currentEntryName.indexOf(OmniaResourceManifests.FxUx.toString()) === -1
1260
+ )) {
1212
1261
  Object.keys(entries).forEach((entryName) => {
1213
1262
  if (entryName !== currentEntryName) {
1214
1263
  if ($.fs.existsSync($.tooling.utils.root(outDirManifestMetadata + "/" + entryName + ".manifest.json"))) {
@@ -1222,14 +1271,14 @@ function buildReferenceManifest(currentEntry, entries) {
1222
1271
  }
1223
1272
  });
1224
1273
  }
1225
- manifests = buildReferenceManifestFromConfig().concat(dynamicReferenceManifests).concat(manifests);
1274
+ manifests = buildReferenceManifestFromConfig(currentEntryName).concat(dynamicReferenceManifests).concat(manifests);
1226
1275
  return manifests;
1227
1276
  }
1228
1277
  function cleanUpComposer() {
1229
1278
  $.composers.ManifestRegistry.clearState();
1230
1279
  }
1231
1280
  exports.cleanUpComposer = cleanUpComposer;
1232
- function buildReferenceManifestFromConfig() {
1281
+ function buildReferenceManifestFromConfig(entryName) {
1233
1282
  var manifests = [];
1234
1283
  let buildOptions = getBuildOption();
1235
1284
  if (buildOptions.reference) {
@@ -1241,6 +1290,17 @@ function buildReferenceManifestFromConfig() {
1241
1290
  }));
1242
1291
  }
1243
1292
  }
1293
+ if (!isBuildWebpackManifestOnly() && buildOptions.webpackManifests) {
1294
+ for (let manifestPath of buildOptions.webpackManifests) {
1295
+ if (manifestPath.indexOf(entryName) === -1) {
1296
+ manifests.push(new $.omniaWebpackPlugins.DllReferencePlugin({
1297
+ context: $.tooling.utils.root(""),
1298
+ manifest: $.tooling.utils.root(manifestPath),
1299
+ // name: `md${++trackingModuleRefId}` //require('md5')(manifestPath)
1300
+ }));
1301
+ }
1302
+ }
1303
+ }
1244
1304
  if ($.isExtensionEnv) {
1245
1305
  _registeredReferenceManifests.forEach(manifest => {
1246
1306
  manifests.push(new $.omniaWebpackPlugins.DllReferencePlugin({
@@ -1,2 +1,3 @@
1
1
  import { ComponentRegistration } from "@omnia/tooling-composers";
2
2
  export declare function generateComponentTypingsAndDoc(componentRegistrations: ComponentRegistration[]): Promise<void>;
3
+ export declare function importSnippetCode(content: string, filePath: string): string;
@@ -1,167 +1,29 @@
1
1
  'use strict';
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generateComponentTypingsAndDoc = void 0;
3
+ exports.importSnippetCode = exports.generateComponentTypingsAndDoc = void 0;
4
4
  const tslib_1 = require("tslib");
5
+ const fs_1 = tslib_1.__importDefault(require("fs"));
5
6
  const path_1 = tslib_1.__importDefault(require("path"));
6
7
  const shared_1 = require("../shared");
7
8
  const tooling_composers_1 = require("@omnia/tooling-composers");
8
9
  const tooling_1 = require("@omnia/tooling");
9
- const core_1 = require("@swc/core");
10
10
  const fsExtra = tslib_1.__importStar(require("fs-extra"));
11
11
  const fx_models_1 = require("@omnia/fx-models");
12
12
  async function generateComponentTypingsAndDoc(componentRegistrations) {
13
13
  tooling_1.utils.log("Generate components typings and documentation running...");
14
14
  var startTime = new Date().getTime();
15
- let DefineVueType;
16
- (function (DefineVueType) {
17
- DefineVueType[DefineVueType["Prop"] = 0] = "Prop";
18
- DefineVueType[DefineVueType["Model"] = 1] = "Model";
19
- DefineVueType[DefineVueType["Slot"] = 2] = "Slot";
20
- DefineVueType[DefineVueType["Emit"] = 4] = "Emit";
21
- })(DefineVueType || (DefineVueType = {}));
22
15
  const docResult = {};
23
- function getPropertyFunctionTypeAsString(type) {
24
- let params = "";
25
- if (type.params?.length > 0) {
26
- type.params.forEach(p => {
27
- params += `${p.value}:${getPropertyType(p.typeAnnotation)}, `;
28
- });
29
- params = params.replace(/,\s*$/, "");
30
- }
31
- return `(${params}) => ${getPropertyType(type.typeAnnotation)}`;
32
- }
33
- function getPropertyType(tsType) {
34
- let result = "";
35
- if (tsType.type === "TsTypeAnnotation") {
36
- return getPropertyType(tsType.typeAnnotation);
37
- }
38
- switch (tsType.type) {
39
- case "TsLiteralType":
40
- result = tsType.literal.value;
41
- break;
42
- case "TsKeywordType":
43
- result = tsType.kind;
44
- break;
45
- case "TsTypeReference":
46
- result = tsType.typeName.value;
47
- break;
48
- case "TsFunctionType":
49
- result = getPropertyFunctionTypeAsString(tsType);
50
- break;
51
- default:
52
- break;
53
- }
54
- return result;
55
- }
56
- function getNameProperty(ce, result) {
57
- const identifier = ce.callee?.property?.value;
58
- if (identifier) {
59
- switch (identifier) {
60
- case "name":
61
- result.name = ce.arguments[0].expression.value;
62
- getNameProperty(ce.callee.object, result);
63
- break;
64
- case "vModel":
65
- result.type = DefineVueType.Model;
66
- result.propertyTypeAsString = getPropertyType(ce.typeArguments.params[0]);
67
- result.name = result.name ? `v-model:${result.name}` : result.name;
68
- break;
69
- case "slots":
70
- result.type = DefineVueType.Slot;
71
- result.propertyTypeAsObject = {};
72
- ce.typeArguments.params[0].members
73
- .forEach(m => {
74
- result.propertyTypeAsObject[m.key.value] = getPropertyType(m.typeAnnotation);
75
- });
76
- break;
77
- case "prop":
78
- result.type = DefineVueType.Prop;
79
- result.propertyTypeAsString = getPropertyType(ce.typeArguments.params[0]);
80
- break;
81
- case "emit":
82
- result.type = DefineVueType.Emit;
83
- result.propertyTypeAsString = getPropertyType(ce.typeArguments.params[0]);
84
- break;
85
- default:
86
- getNameProperty(ce.callee.object, result);
87
- }
88
- }
89
- }
90
16
  async function buildDoc(wc) {
91
17
  try {
92
18
  const wcPath = (0, shared_1.convertManifestPathToEntryPath)(wc.manifestPath, [wc.componentOptions.entryPoint])[0];
93
- const wcParseResult = await (0, core_1.parseFile)(wcPath, {
94
- syntax: 'typescript',
95
- target: 'es2020',
96
- tsx: true,
97
- decorators: true,
98
- dynamicImport: true
99
- });
100
- wcParseResult.body.forEach(b => {
101
- if (b.type === 'ExportDefaultExpression'
102
- && b.expression.callee?.value === "defineVueComponent") {
103
- b.expression.arguments[0].expression
104
- .properties?.filter(p => p.key.value === "props"
105
- || p.key.value === "emits")
106
- ?.forEach(propsIdentifier => {
107
- if (propsIdentifier) {
108
- propsIdentifier.value
109
- .properties?.forEach(p => {
110
- const em = p.arguments;
111
- if (em?.callee?.property?.value === "doc$") {
112
- const PropertyResult = {
113
- type: null,
114
- propertyTypeAsString: "",
115
- name: ""
116
- };
117
- getNameProperty(em, PropertyResult);
118
- if (!docResult[wc.componentOptions.elementName]) {
119
- docResult[wc.componentOptions.elementName] = {
120
- emits: {},
121
- models: {},
122
- props: {},
123
- slots: {}
124
- };
125
- }
126
- switch (PropertyResult.type) {
127
- case DefineVueType.Prop:
128
- docResult[wc.componentOptions.elementName].props[PropertyResult.name] = {
129
- type: PropertyResult.propertyTypeAsString,
130
- description: em.arguments[0].expression.value
131
- };
132
- break;
133
- case DefineVueType.Model:
134
- docResult[wc.componentOptions.elementName].models[PropertyResult.name] = {
135
- type: PropertyResult.propertyTypeAsString,
136
- description: em.arguments[0].expression.value
137
- };
138
- break;
139
- case DefineVueType.Emit:
140
- docResult[wc.componentOptions.elementName].emits[PropertyResult.name] = {
141
- type: PropertyResult.propertyTypeAsString,
142
- description: em.arguments[0].expression.value
143
- };
144
- break;
145
- case DefineVueType.Slot:
146
- em.arguments[0].expression
147
- .properties
148
- .forEach(p => {
149
- const slotName = p.key.value;
150
- docResult[wc.componentOptions.elementName].slots[slotName] = {
151
- type: PropertyResult.propertyTypeAsObject[slotName],
152
- description: p.value.value
153
- };
154
- });
155
- break;
156
- default:
157
- break;
158
- }
159
- }
160
- });
161
- }
162
- });
163
- }
164
- });
19
+ const elementName = wc.componentOptions.elementName;
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
+ };
165
27
  }
166
28
  catch (ex) {
167
29
  tooling_1.utils.log(`Have a exception when extract doc$ for web component manifest -> ${wc.manifestPath}`, tooling_1.utils.LogTypes.Error);
@@ -170,35 +32,18 @@ async function generateComponentTypingsAndDoc(componentRegistrations) {
170
32
  }
171
33
  }
172
34
  let docPath = path_1.default.resolve(__dirname, "ComponentDocRegistrations.ts");
173
- ;
174
- const wcNamespace = (0, shared_1.getBuildOption)()?.webComponentNamespace;
175
- const info = shared_1.ConfigurationManager.outputInfo.get();
176
- info.wc = {
177
- namespace: wcNamespace,
178
- mappings: {}
179
- };
180
- let wcTypings = wcNamespace ? `
35
+ let wcTypings = `
181
36
  //{{importWC}}
182
- declare global {
183
- namespace JSX {
184
- interface Element { }
185
- interface ElementClass { }
186
37
 
187
- interface IntrinsicElements {
188
- //{{elementName}}
189
- }
38
+ type ExtractJsxProps<T> = {
39
+ [K in keyof (T extends { propsDefinition: any } ? T["propsDefinition"] : T)]: T extends {
40
+ propsDefinition: any;
190
41
  }
191
- }
42
+ ? T["propsDefinition"][K]
43
+ : never;
44
+ } & { $children?: any; };
192
45
 
193
46
  declare global {
194
- let ${wcNamespace}: {
195
- //{{nselementName}}
196
- };
197
- }
198
- `
199
- : `
200
- //{{importWC}}
201
- declare global {
202
47
  namespace JSX {
203
48
  interface Element { }
204
49
  interface ElementClass { }
@@ -216,10 +61,34 @@ declare global {
216
61
  wcTypings = `import { VueComponentBaseProps } from "../../../../client/fx/ux/index";
217
62
  ${wcTypings}`;
218
63
  }
64
+ const elementNamespaces = {};
65
+ const wcNamespace = (0, shared_1.getBuildOption)()?.componentNamespace;
66
+ const info = shared_1.ConfigurationManager.outputInfo.get();
67
+ info.wc = {
68
+ namespaces: wcNamespace ? [wcNamespace] : null,
69
+ mappings: {}
70
+ };
219
71
  await tooling_1.utils.asyncForEach(componentRegistrations, async (wc) => {
220
- wcTypings = generateWebComponentTypings(wc, wcTypings, info);
221
- await buildDoc(wc);
72
+ wcTypings = generateWebComponentTypings(wc, wcTypings, info, elementNamespaces);
73
+ if ((0, shared_1.getBuildOption)().docResourceManifestId) {
74
+ await buildDoc(wc);
75
+ }
222
76
  });
77
+ if (Object.keys(elementNamespaces).length > 0) {
78
+ let result = `declare global {
79
+ //{{namespace}}
80
+ }`;
81
+ Object.keys(elementNamespaces).forEach(key => {
82
+ result = result.replace("//{{namespace}}", `
83
+ let ${key}: ${JSON.stringify(elementNamespaces[key], null, 2)
84
+ .replace(/\"typeof /g, "typeof ").replace(/ <<end>>\"/g, "")}
85
+ //{{namespace}}
86
+ `);
87
+ });
88
+ wcTypings = wcTypings + `
89
+ ${result}
90
+ `;
91
+ }
223
92
  if (Object.keys(docResult).length > 0) {
224
93
  fsExtra.outputFileSync(docPath, `
225
94
  import { extendApi } from "@omnia/fx";
@@ -241,7 +110,7 @@ extendApi(api => api.fx.docs.registrations, api => {
241
110
  .registerResources({
242
111
  resourcePaths: ["./ComponentDocRegistrations.ts"]
243
112
  })
244
- .withTarget(fx_models_1.ClientManifestTargetTypes.Docs)
113
+ .withTarget(fx_models_1.ClientManifestTargetTypes.docs)
245
114
  .extendApi(api => api.fx.docs.registrations);
246
115
  tooling_composers_1.ManifestRegistry.setCurrentManifestPath();
247
116
  }
@@ -250,7 +119,7 @@ extendApi(api => api.fx.docs.registrations, api => {
250
119
  tooling_1.utils.logTime('Done - Generate components typings and documentation', startTime);
251
120
  }
252
121
  exports.generateComponentTypingsAndDoc = generateComponentTypingsAndDoc;
253
- function generateWebComponentTypings(wc, template, info) {
122
+ function generateWebComponentTypings(wc, template, info, elementNamespace) {
254
123
  // export default defineVueWebComponent
255
124
  const wcPath = wc.componentOptions.entryPointPath;
256
125
  let content = fsExtra.readFileSync(wcPath, 'utf8');
@@ -269,16 +138,89 @@ function generateWebComponentTypings(wc, template, info) {
269
138
  else {
270
139
  importPath = `../../../../${importPath}`;
271
140
  }
272
- let elementNamePascalCase = wc.componentOptions.elementName.replace("omfx-", "").replace(/-([a-z])/g, function (g) { return g[1].toUpperCase(); });
273
- elementNamePascalCase = elementNamePascalCase[0].toUpperCase() + elementNamePascalCase.substring(1, elementNamePascalCase.length);
274
- info.wc.mappings[elementNamePascalCase] = wc.componentOptions.elementName;
141
+ if (info.wc.namespaces) {
142
+ let elementName = wc.componentOptions.elementName.replace(/-/g, ".");
143
+ const namespace = (wc.componentOptions.namespace === true ? "" : wc.componentOptions.namespace) || (0, shared_1.getBuildOption)()?.componentNamespace;
144
+ if (namespace && elementName.indexOf(`${namespace}.`) !== 0) {
145
+ elementName = `${namespace}.${elementName}`;
146
+ }
147
+ if (info.wc.namespaces && info.wc.namespaces.indexOf(elementName.split(".")[0]) === -1) {
148
+ info.wc.namespaces.push(elementName.split(".")[0]);
149
+ }
150
+ info.wc.mappings[elementName] = wc.componentOptions.elementName;
151
+ try {
152
+ populateElementNamespace(elementNamespace, elementName, friendlyManifestId);
153
+ }
154
+ catch (ex) {
155
+ tooling_1.utils.log(`Have a exception in building element namespace with element name: ${wc.componentOptions.elementName}`, tooling_1.utils.LogTypes.Error);
156
+ console.error(ex);
157
+ throw new Error("Exit, have an exception.");
158
+ }
159
+ }
275
160
  return template
276
161
  .replace(/\/\/{{importWC}}/, `import ${friendlyManifestId} from '${importPath}';
277
162
  //{{importWC}}`)
278
- .replace(/\/\/{{elementName}}/, `"${wc.componentOptions.elementName}": typeof ${friendlyManifestId}.propsDefinition & Omit<VueComponentBaseProps, keyof typeof ${friendlyManifestId}.propsDefinition>
279
- //{{elementName}}`)
280
- .replace(/\/\/{{nselementName}}/, `"${elementNamePascalCase}": { new(...args: any[]): { $props: typeof ${friendlyManifestId}.propsDefinition & Omit<VueComponentBaseProps, keyof typeof ${friendlyManifestId}.propsDefinition> } }
281
- //{{nselementName}}`);
163
+ .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
164
+ //{{elementName}}`);
165
+ // .replace(/\/\/{{nselementName}}/, `"${elementName}": { new(...args: any[]): { $props: typeof ${friendlyManifestId}.propsDefinition & Omit<VueComponentBaseProps, keyof typeof ${friendlyManifestId}.propsDefinition> } }
166
+ // //{{nselementName}}`)
282
167
  }
283
168
  return template;
284
169
  }
170
+ function importSnippetCode(content, filePath) {
171
+ let result = content;
172
+ const ext = path_1.default.extname(filePath);
173
+ if (filePath.indexOf(".md.ts") > -1) {
174
+ result = content.replace(/\@import\/.*;/g, function (match) {
175
+ let fromLine = 0;
176
+ let toLine = 0;
177
+ const indexStartLine = match.indexOf("{");
178
+ if (indexStartLine > -1) {
179
+ const numbers = match.substring(indexStartLine + 1, match.indexOf("}")).split("-");
180
+ fromLine = Number(numbers[0]);
181
+ toLine = Number(numbers[1]);
182
+ }
183
+ const fileName = match.substring(0, indexStartLine || match.length - 1)
184
+ .replace("@import/", "")
185
+ .replace(";", "");
186
+ let fileContent = fs_1.default.readFileSync(fileName, 'utf-8');
187
+ if (fromLine > 0) {
188
+ fileContent = fileContent.split(/\r?\n/).slice(fromLine - 1, toLine).join("\n");
189
+ }
190
+ return fileContent;
191
+ });
192
+ }
193
+ return result;
194
+ }
195
+ exports.importSnippetCode = importSnippetCode;
196
+ function populateElementNamespace(namespace, elementName, importElement) {
197
+ const parts = elementName.split(".");
198
+ for (let i = 0; i < parts.length; i++) {
199
+ const name = parts[i];
200
+ if (typeof namespace === "string") {
201
+ throw new Error("Build element namespace -> that element name contain another element name");
202
+ }
203
+ if (!namespace[name]) {
204
+ if (i === parts.length - 1) {
205
+ namespace[name] = `typeof ${importElement} extends { propsDefinition: infer TProp } ? { new(...args: any[]): { $props: TProp & Omit<VueComponentBaseProps, keyof TProp> } } : typeof ${importElement} <<end>>`;
206
+ }
207
+ else {
208
+ namespace = namespace[name] = {};
209
+ }
210
+ }
211
+ else {
212
+ if (i === parts.length - 1) {
213
+ namespace[`${name}$`] = `typeof ${importElement} extends { propsDefinition: infer TProp } ? { new(...args: any[]): { $props: TProp & Omit<VueComponentBaseProps, keyof TProp> } } : typeof ${importElement} <<end>>`;
214
+ // throw new Error("Build element namespace -> Exist an element name contain a above that element name");
215
+ }
216
+ else {
217
+ if (typeof namespace[name] === "string") {
218
+ tooling_1.utils.log(`Generate namespace for component with suffix $ -> ${parts.slice(0, i + 1).join(".")}$`);
219
+ namespace[`${name}$`] = namespace[name];
220
+ namespace[name] = {};
221
+ }
222
+ namespace = namespace[name];
223
+ }
224
+ }
225
+ }
226
+ }