@lvce-editor/extension-management-worker 1.7.0 → 1.8.0

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.
@@ -1468,6 +1468,30 @@ const enableExtension = async (id, isTest) => {
1468
1468
  return undefined;
1469
1469
  };
1470
1470
 
1471
+ const readJson = url => {
1472
+ return invoke$1('FileSystem.readJson', url);
1473
+ };
1474
+
1475
+ const join = (pathSeparator, ...parts) => {
1476
+ return parts.join(pathSeparator);
1477
+ };
1478
+
1479
+ const getColorThemeUri = (extensions, colorThemeId) => {
1480
+ for (const extension of extensions) {
1481
+ if (!extension.colorThemes) {
1482
+ continue;
1483
+ }
1484
+ for (const colorTheme of extension.colorThemes) {
1485
+ if (colorTheme.id !== colorThemeId) {
1486
+ continue;
1487
+ }
1488
+ const absolutePath = join('/', extension.uri, colorTheme.path);
1489
+ return absolutePath;
1490
+ }
1491
+ }
1492
+ return '';
1493
+ };
1494
+
1471
1495
  const getAllExtensions = async () => {
1472
1496
  const state = get();
1473
1497
  if (state.platform === Web) {
@@ -1476,6 +1500,54 @@ const getAllExtensions = async () => {
1476
1500
  return invoke('ExtensionManagement.getAllExtensions');
1477
1501
  };
1478
1502
 
1503
+ const getColorThemeJson$2 = async colorThemeId => {
1504
+ const extensions = await getAllExtensions();
1505
+ const colorThemeUri = getColorThemeUri(extensions, colorThemeId);
1506
+ if (!colorThemeUri) {
1507
+ return {};
1508
+ }
1509
+ const json = await readJson(colorThemeUri);
1510
+ return json;
1511
+ };
1512
+
1513
+ const assetDir = '';
1514
+
1515
+ const getColorThemeUrlWeb = colorThemeId => {
1516
+ return `${assetDir}/extensions/builtin.theme-${colorThemeId}/color-theme.json`;
1517
+ };
1518
+ const getColorThemeJson$1 = colorThemeId => {
1519
+ const url = getColorThemeUrlWeb(colorThemeId);
1520
+ // TODO handle error ?
1521
+ return getJson(url);
1522
+ };
1523
+
1524
+ const getColorThemeJson = (colorThemeId, platform) => {
1525
+ if (platform === Web) {
1526
+ return getColorThemeJson$1(colorThemeId);
1527
+ }
1528
+ return getColorThemeJson$2(colorThemeId);
1529
+ };
1530
+
1531
+ const getExtensionColorThemeNames = extension => {
1532
+ return extension.colorThemes || [];
1533
+ };
1534
+ const getColorThemeId = colorTheme => {
1535
+ return colorTheme.id;
1536
+ };
1537
+
1538
+ // TODO should send names to renderer worker or names with ids?
1539
+ const getColorThemeNamesFromExtensions = async extensions => {
1540
+ const colorThemes = extensions.flatMap(getExtensionColorThemeNames);
1541
+ const colorThemeNames = colorThemes.map(getColorThemeId);
1542
+ return colorThemeNames;
1543
+ };
1544
+
1545
+ const getColorThemeNames = async () => {
1546
+ const extensions = await getAllExtensions();
1547
+ const colorThemeNames = getColorThemeNamesFromExtensions(extensions);
1548
+ return colorThemeNames;
1549
+ };
1550
+
1479
1551
  const getExtension = async id => {
1480
1552
  const allExtensions = await getAllExtensions();
1481
1553
  for (const extension of allExtensions) {
@@ -1606,6 +1678,50 @@ const installExtension = async () => {
1606
1678
  // TODO
1607
1679
  };
1608
1680
 
1681
+ const getLanguagesFromExtension = extension => {
1682
+ // TODO what if extension is null? should not crash process, handle error gracefully
1683
+ // TODO what if extension languages is not of type array?
1684
+ // TODO what if language is null?
1685
+ if (!extension) {
1686
+ return [];
1687
+ }
1688
+ if (!extension.languages) {
1689
+ return [];
1690
+ }
1691
+ const extensionPath = extension.path;
1692
+ const getLanguageFromExtension = language => {
1693
+ if (language.tokenize) {
1694
+ if (typeof language.tokenize !== 'string') {
1695
+ console.warn(`[info] ${language.id}: language.tokenize must be of type string but was of type ${typeof language.tokenize}`);
1696
+ return {
1697
+ ...language,
1698
+ extensionPath,
1699
+ tokenize: ''
1700
+ };
1701
+ }
1702
+ const relativePath = `${extensionPath}/${language.tokenize}`;
1703
+ const absolutePath = relativePath ;
1704
+ return {
1705
+ ...language,
1706
+ extensionPath,
1707
+ tokenize: absolutePath
1708
+ };
1709
+ }
1710
+ return language;
1711
+ };
1712
+ return extension.languages.map(getLanguageFromExtension);
1713
+ };
1714
+
1715
+ const getLanguages = async () => {
1716
+ try {
1717
+ const extensions = await getAllExtensions();
1718
+ const languages = extensions.flatMap(getLanguagesFromExtension);
1719
+ return languages;
1720
+ } catch (error) {
1721
+ throw new VError(error, 'Failed to load languages');
1722
+ }
1723
+ };
1724
+
1609
1725
  const uninstallExtension = async () => {
1610
1726
  // TODO
1611
1727
  };
@@ -1616,12 +1732,16 @@ const commandMap = {
1616
1732
  'Extensions.disable': disableExtension,
1617
1733
  'Extensions.enable': enableExtension,
1618
1734
  'Extensions.getAllExtensions': getAllExtensions,
1735
+ 'Extensions.getColorThemeJson': getColorThemeJson,
1736
+ 'Extensions.getColorThemeNames': getColorThemeNames,
1619
1737
  'Extensions.getExtension': getExtension,
1738
+ 'Extensions.getLanguages': getLanguages,
1620
1739
  'Extensions.getRuntimeStatus': getRuntimeStatus,
1621
1740
  'Extensions.handleMessagePort': handleMessagePort,
1622
1741
  'Extensions.importExtension': importExtension,
1623
1742
  'Extensions.initialize': initialize,
1624
1743
  'Extensions.install': installExtension,
1744
+ 'Extensions.invalidateExtensionsCache': invalidateExtensionsCache,
1625
1745
  'Extensions.uninstall': uninstallExtension
1626
1746
  };
1627
1747
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/extension-management-worker",
3
- "version": "1.7.0",
3
+ "version": "1.8.0",
4
4
  "description": "Webworker for the Extension Management functionality in Lvce Editor.",
5
5
  "keywords": [
6
6
  "web-worker"