@designos/compiler-cli 0.2.0 → 0.3.1
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/LICENSE +21 -0
- package/README.md +16 -6
- package/dist/cli.js +570 -7
- package/dist/cli.js.map +1 -1
- package/package.json +5 -4
package/dist/cli.js
CHANGED
|
@@ -1478,10 +1478,416 @@ var designos_kit_schema_default = {
|
|
|
1478
1478
|
}
|
|
1479
1479
|
};
|
|
1480
1480
|
|
|
1481
|
+
// ../../schemas/designos.kit.schema.v2.json
|
|
1482
|
+
var designos_kit_schema_v2_default = {
|
|
1483
|
+
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
1484
|
+
$id: "https://raw.githubusercontent.com/relacloud/design-os/main/schemas/designos.kit.schema.v2.json",
|
|
1485
|
+
title: "DesignOS Component Kit Manifest (Version 2)",
|
|
1486
|
+
description: "Root manifest for a version 2 DesignOS component kit.",
|
|
1487
|
+
type: "object",
|
|
1488
|
+
additionalProperties: false,
|
|
1489
|
+
required: [
|
|
1490
|
+
"schemaVersion",
|
|
1491
|
+
"id",
|
|
1492
|
+
"name",
|
|
1493
|
+
"version",
|
|
1494
|
+
"compilerProject",
|
|
1495
|
+
"designos",
|
|
1496
|
+
"components",
|
|
1497
|
+
"design"
|
|
1498
|
+
],
|
|
1499
|
+
properties: {
|
|
1500
|
+
$schema: {
|
|
1501
|
+
type: "string",
|
|
1502
|
+
format: "uri"
|
|
1503
|
+
},
|
|
1504
|
+
schemaVersion: {
|
|
1505
|
+
const: "2",
|
|
1506
|
+
description: "Version of this kit-manifest contract; independent from compiler project schemaVersion."
|
|
1507
|
+
},
|
|
1508
|
+
id: {
|
|
1509
|
+
type: "string",
|
|
1510
|
+
minLength: 1,
|
|
1511
|
+
maxLength: 214,
|
|
1512
|
+
pattern: "^(?:@[a-z0-9][a-z0-9._-]*/)?[a-z0-9][a-z0-9._-]*$",
|
|
1513
|
+
description: "Exact package identifier; semantic validation checks equality with package.json.name."
|
|
1514
|
+
},
|
|
1515
|
+
name: {
|
|
1516
|
+
type: "string",
|
|
1517
|
+
minLength: 1,
|
|
1518
|
+
maxLength: 160
|
|
1519
|
+
},
|
|
1520
|
+
version: {
|
|
1521
|
+
$ref: "#/$defs/semver",
|
|
1522
|
+
description: "Strict SemVer 2.0.0 package version; this value is not a compatibility range."
|
|
1523
|
+
},
|
|
1524
|
+
description: {
|
|
1525
|
+
type: "string",
|
|
1526
|
+
maxLength: 2e3
|
|
1527
|
+
},
|
|
1528
|
+
license: {
|
|
1529
|
+
type: "string",
|
|
1530
|
+
minLength: 1,
|
|
1531
|
+
maxLength: 128
|
|
1532
|
+
},
|
|
1533
|
+
compilerProject: {
|
|
1534
|
+
$ref: "#/$defs/packageRelativePath",
|
|
1535
|
+
description: "Package-relative path to the compiler project; existence and real-path containment are semantic checks."
|
|
1536
|
+
},
|
|
1537
|
+
design: {
|
|
1538
|
+
type: "object",
|
|
1539
|
+
additionalProperties: false,
|
|
1540
|
+
required: [
|
|
1541
|
+
"manifest"
|
|
1542
|
+
],
|
|
1543
|
+
properties: {
|
|
1544
|
+
manifest: {
|
|
1545
|
+
$ref: "#/$defs/packageRelativePath",
|
|
1546
|
+
description: "Package-relative path to the kit design manifest."
|
|
1547
|
+
}
|
|
1548
|
+
},
|
|
1549
|
+
minProperties: 1
|
|
1550
|
+
},
|
|
1551
|
+
designos: {
|
|
1552
|
+
type: "object",
|
|
1553
|
+
additionalProperties: false,
|
|
1554
|
+
required: [
|
|
1555
|
+
"kit"
|
|
1556
|
+
],
|
|
1557
|
+
properties: {
|
|
1558
|
+
kit: {
|
|
1559
|
+
type: "string",
|
|
1560
|
+
minLength: 1,
|
|
1561
|
+
description: "Non-empty SemVer range for the kit contract. Schema validation checks only the string; semantic validation parses the range."
|
|
1562
|
+
},
|
|
1563
|
+
core: {
|
|
1564
|
+
type: "string",
|
|
1565
|
+
minLength: 1,
|
|
1566
|
+
description: "Optional non-empty SemVer range for DesignOS core; semantic validation parses the range."
|
|
1567
|
+
},
|
|
1568
|
+
compiler: {
|
|
1569
|
+
type: "string",
|
|
1570
|
+
minLength: 1,
|
|
1571
|
+
description: "Optional non-empty SemVer range for the compiler; semantic validation parses the range."
|
|
1572
|
+
},
|
|
1573
|
+
editor: {
|
|
1574
|
+
type: "string",
|
|
1575
|
+
minLength: 1,
|
|
1576
|
+
description: "Optional non-empty SemVer range for the editor; semantic validation parses the range."
|
|
1577
|
+
}
|
|
1578
|
+
}
|
|
1579
|
+
},
|
|
1580
|
+
components: {
|
|
1581
|
+
type: "array",
|
|
1582
|
+
minItems: 1,
|
|
1583
|
+
items: {
|
|
1584
|
+
$ref: "#/$defs/component"
|
|
1585
|
+
}
|
|
1586
|
+
},
|
|
1587
|
+
editor: {
|
|
1588
|
+
type: "object",
|
|
1589
|
+
additionalProperties: false,
|
|
1590
|
+
properties: {
|
|
1591
|
+
catalog: {
|
|
1592
|
+
$ref: "#/$defs/packageRelativePath"
|
|
1593
|
+
},
|
|
1594
|
+
previews: {
|
|
1595
|
+
type: "object",
|
|
1596
|
+
description: "Optional editor host adapters keyed by stable component type.",
|
|
1597
|
+
propertyNames: {
|
|
1598
|
+
minLength: 1
|
|
1599
|
+
},
|
|
1600
|
+
additionalProperties: {
|
|
1601
|
+
$ref: "#/$defs/packageRelativePath"
|
|
1602
|
+
}
|
|
1603
|
+
}
|
|
1604
|
+
},
|
|
1605
|
+
minProperties: 1
|
|
1606
|
+
},
|
|
1607
|
+
metadata: {
|
|
1608
|
+
type: "object",
|
|
1609
|
+
description: "Reserved for non-normative publisher-specific metadata.",
|
|
1610
|
+
additionalProperties: true
|
|
1611
|
+
}
|
|
1612
|
+
},
|
|
1613
|
+
$defs: {
|
|
1614
|
+
component: {
|
|
1615
|
+
type: "object",
|
|
1616
|
+
additionalProperties: false,
|
|
1617
|
+
required: [
|
|
1618
|
+
"type",
|
|
1619
|
+
"source",
|
|
1620
|
+
"exportName",
|
|
1621
|
+
"manifest"
|
|
1622
|
+
],
|
|
1623
|
+
properties: {
|
|
1624
|
+
type: {
|
|
1625
|
+
type: "string",
|
|
1626
|
+
minLength: 1,
|
|
1627
|
+
maxLength: 128,
|
|
1628
|
+
description: "Stable public component type; uniqueness and manifest agreement are semantic checks."
|
|
1629
|
+
},
|
|
1630
|
+
source: {
|
|
1631
|
+
$ref: "#/$defs/packageRelativePath"
|
|
1632
|
+
},
|
|
1633
|
+
exportName: {
|
|
1634
|
+
type: "string",
|
|
1635
|
+
pattern: "^[A-Za-z_$][A-Za-z0-9_$]*$",
|
|
1636
|
+
description: "Compiler export identifier; agreement with the compiler-project entry is a semantic check."
|
|
1637
|
+
},
|
|
1638
|
+
manifest: {
|
|
1639
|
+
$ref: "#/$defs/packageRelativePath"
|
|
1640
|
+
}
|
|
1641
|
+
}
|
|
1642
|
+
},
|
|
1643
|
+
packageRelativePath: {
|
|
1644
|
+
type: "string",
|
|
1645
|
+
minLength: 1,
|
|
1646
|
+
maxLength: 1024,
|
|
1647
|
+
pattern: "^(?!/)(?![A-Za-z]:)(?!.*(?:^|/)\\.\\.?/)(?!.*(?:^|/)\\.\\.?$)[^\\\\\\u0000]+$",
|
|
1648
|
+
description: "Package-relative path with basic lexical restrictions. Semantic validation must check normalized segments, existence, and real-path containment after symlink resolution."
|
|
1649
|
+
},
|
|
1650
|
+
semver: {
|
|
1651
|
+
type: "string",
|
|
1652
|
+
pattern: "^(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)(?:-((?:0|[1-9][0-9]*|[0-9]*[A-Za-z-][0-9A-Za-z-]*)(?:\\.(?:0|[1-9][0-9]*|[0-9]*[A-Za-z-][0-9A-Za-z-]*))*))?(?:\\+([0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*))?$",
|
|
1653
|
+
description: "Strict SemVer 2.0.0 version syntax, excluding compatibility ranges."
|
|
1654
|
+
}
|
|
1655
|
+
}
|
|
1656
|
+
};
|
|
1657
|
+
|
|
1658
|
+
// ../../schemas/designos.design.schema.json
|
|
1659
|
+
var designos_design_schema_default = {
|
|
1660
|
+
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
1661
|
+
$id: "https://raw.githubusercontent.com/relacloud/design-os/main/schemas/designos.design.schema.json",
|
|
1662
|
+
title: "DesignOS Kit Design Manifest",
|
|
1663
|
+
description: "Declarative design tokens, defaults, and presets owned by a component kit.",
|
|
1664
|
+
type: "object",
|
|
1665
|
+
additionalProperties: false,
|
|
1666
|
+
required: ["schemaVersion", "name", "tokens", "presets"],
|
|
1667
|
+
properties: {
|
|
1668
|
+
$schema: {
|
|
1669
|
+
type: "string",
|
|
1670
|
+
format: "uri"
|
|
1671
|
+
},
|
|
1672
|
+
schemaVersion: {
|
|
1673
|
+
const: "1",
|
|
1674
|
+
description: "Version of the design-manifest format; independent from the kit-manifest and kit package versions."
|
|
1675
|
+
},
|
|
1676
|
+
name: {
|
|
1677
|
+
type: "string",
|
|
1678
|
+
minLength: 1,
|
|
1679
|
+
maxLength: 160
|
|
1680
|
+
},
|
|
1681
|
+
description: {
|
|
1682
|
+
type: "string",
|
|
1683
|
+
maxLength: 2e3
|
|
1684
|
+
},
|
|
1685
|
+
tokens: {
|
|
1686
|
+
type: "array",
|
|
1687
|
+
minItems: 1,
|
|
1688
|
+
items: {
|
|
1689
|
+
$ref: "#/$defs/token"
|
|
1690
|
+
}
|
|
1691
|
+
},
|
|
1692
|
+
presets: {
|
|
1693
|
+
type: "array",
|
|
1694
|
+
minItems: 1,
|
|
1695
|
+
items: {
|
|
1696
|
+
$ref: "#/$defs/preset"
|
|
1697
|
+
}
|
|
1698
|
+
}
|
|
1699
|
+
},
|
|
1700
|
+
$defs: {
|
|
1701
|
+
token: {
|
|
1702
|
+
type: "object",
|
|
1703
|
+
additionalProperties: false,
|
|
1704
|
+
required: ["id", "label", "type", "default", "cssVariable"],
|
|
1705
|
+
properties: {
|
|
1706
|
+
id: {
|
|
1707
|
+
type: "string",
|
|
1708
|
+
minLength: 1,
|
|
1709
|
+
maxLength: 128,
|
|
1710
|
+
pattern: "^[A-Za-z][A-Za-z0-9._-]*$",
|
|
1711
|
+
description: "Stable identifier used as the key in saved design values and preset values."
|
|
1712
|
+
},
|
|
1713
|
+
label: {
|
|
1714
|
+
type: "string",
|
|
1715
|
+
minLength: 1,
|
|
1716
|
+
maxLength: 160
|
|
1717
|
+
},
|
|
1718
|
+
description: {
|
|
1719
|
+
type: "string",
|
|
1720
|
+
maxLength: 1e3
|
|
1721
|
+
},
|
|
1722
|
+
group: {
|
|
1723
|
+
type: "string",
|
|
1724
|
+
minLength: 1,
|
|
1725
|
+
maxLength: 100
|
|
1726
|
+
},
|
|
1727
|
+
type: {
|
|
1728
|
+
enum: ["color", "font-family", "number", "select"]
|
|
1729
|
+
},
|
|
1730
|
+
default: {
|
|
1731
|
+
anyOf: [{ type: "string" }, { type: "number" }]
|
|
1732
|
+
},
|
|
1733
|
+
cssVariable: {
|
|
1734
|
+
type: "string",
|
|
1735
|
+
pattern: "^--[A-Za-z_][A-Za-z0-9_-]*$",
|
|
1736
|
+
description: "CSS custom property used when projecting the saved design into preview or runtime styles."
|
|
1737
|
+
},
|
|
1738
|
+
options: {
|
|
1739
|
+
type: "array",
|
|
1740
|
+
minItems: 1,
|
|
1741
|
+
items: {
|
|
1742
|
+
$ref: "#/$defs/option"
|
|
1743
|
+
}
|
|
1744
|
+
},
|
|
1745
|
+
min: {
|
|
1746
|
+
type: "number"
|
|
1747
|
+
},
|
|
1748
|
+
max: {
|
|
1749
|
+
type: "number"
|
|
1750
|
+
},
|
|
1751
|
+
step: {
|
|
1752
|
+
type: "number",
|
|
1753
|
+
exclusiveMinimum: 0
|
|
1754
|
+
},
|
|
1755
|
+
unit: {
|
|
1756
|
+
enum: ["", "px", "rem", "em", "%"]
|
|
1757
|
+
}
|
|
1758
|
+
},
|
|
1759
|
+
allOf: [
|
|
1760
|
+
{
|
|
1761
|
+
if: {
|
|
1762
|
+
properties: { type: { const: "color" } },
|
|
1763
|
+
required: ["type"]
|
|
1764
|
+
},
|
|
1765
|
+
then: {
|
|
1766
|
+
properties: {
|
|
1767
|
+
default: { $ref: "#/$defs/colorValue" }
|
|
1768
|
+
}
|
|
1769
|
+
}
|
|
1770
|
+
},
|
|
1771
|
+
{
|
|
1772
|
+
if: {
|
|
1773
|
+
properties: { type: { const: "font-family" } },
|
|
1774
|
+
required: ["type"]
|
|
1775
|
+
},
|
|
1776
|
+
then: {
|
|
1777
|
+
required: ["options"],
|
|
1778
|
+
properties: {
|
|
1779
|
+
default: { $ref: "#/$defs/fontFamilyValue" },
|
|
1780
|
+
options: {
|
|
1781
|
+
type: "array",
|
|
1782
|
+
minItems: 1,
|
|
1783
|
+
items: { $ref: "#/$defs/option" }
|
|
1784
|
+
}
|
|
1785
|
+
}
|
|
1786
|
+
}
|
|
1787
|
+
},
|
|
1788
|
+
{
|
|
1789
|
+
if: {
|
|
1790
|
+
properties: { type: { const: "number" } },
|
|
1791
|
+
required: ["type"]
|
|
1792
|
+
},
|
|
1793
|
+
then: {
|
|
1794
|
+
required: ["min", "max", "step"],
|
|
1795
|
+
properties: {
|
|
1796
|
+
default: { type: "number" },
|
|
1797
|
+
min: { type: "number" },
|
|
1798
|
+
max: { type: "number" },
|
|
1799
|
+
step: { type: "number", exclusiveMinimum: 0 }
|
|
1800
|
+
}
|
|
1801
|
+
}
|
|
1802
|
+
},
|
|
1803
|
+
{
|
|
1804
|
+
if: {
|
|
1805
|
+
properties: { type: { const: "select" } },
|
|
1806
|
+
required: ["type"]
|
|
1807
|
+
},
|
|
1808
|
+
then: {
|
|
1809
|
+
required: ["options"],
|
|
1810
|
+
properties: {
|
|
1811
|
+
default: { $ref: "#/$defs/optionValue" },
|
|
1812
|
+
options: {
|
|
1813
|
+
type: "array",
|
|
1814
|
+
minItems: 1,
|
|
1815
|
+
items: { $ref: "#/$defs/option" }
|
|
1816
|
+
}
|
|
1817
|
+
}
|
|
1818
|
+
}
|
|
1819
|
+
}
|
|
1820
|
+
]
|
|
1821
|
+
},
|
|
1822
|
+
option: {
|
|
1823
|
+
type: "object",
|
|
1824
|
+
additionalProperties: false,
|
|
1825
|
+
required: ["value", "label"],
|
|
1826
|
+
properties: {
|
|
1827
|
+
value: {
|
|
1828
|
+
$ref: "#/$defs/optionValue"
|
|
1829
|
+
},
|
|
1830
|
+
label: {
|
|
1831
|
+
type: "string",
|
|
1832
|
+
minLength: 1,
|
|
1833
|
+
maxLength: 160
|
|
1834
|
+
}
|
|
1835
|
+
}
|
|
1836
|
+
},
|
|
1837
|
+
preset: {
|
|
1838
|
+
type: "object",
|
|
1839
|
+
additionalProperties: false,
|
|
1840
|
+
required: ["id", "name", "values"],
|
|
1841
|
+
properties: {
|
|
1842
|
+
id: {
|
|
1843
|
+
type: "string",
|
|
1844
|
+
minLength: 1,
|
|
1845
|
+
maxLength: 128,
|
|
1846
|
+
pattern: "^[A-Za-z][A-Za-z0-9._-]*$"
|
|
1847
|
+
},
|
|
1848
|
+
name: {
|
|
1849
|
+
type: "string",
|
|
1850
|
+
minLength: 1,
|
|
1851
|
+
maxLength: 160
|
|
1852
|
+
},
|
|
1853
|
+
description: {
|
|
1854
|
+
type: "string",
|
|
1855
|
+
maxLength: 1e3
|
|
1856
|
+
},
|
|
1857
|
+
values: {
|
|
1858
|
+
type: "object",
|
|
1859
|
+
minProperties: 1,
|
|
1860
|
+
additionalProperties: {
|
|
1861
|
+
anyOf: [{ type: "string" }, { type: "number" }]
|
|
1862
|
+
},
|
|
1863
|
+
description: "Values keyed by token ID. Semantic validation checks completeness and token compatibility."
|
|
1864
|
+
}
|
|
1865
|
+
}
|
|
1866
|
+
},
|
|
1867
|
+
colorValue: {
|
|
1868
|
+
type: "string",
|
|
1869
|
+
pattern: "^#(?:[A-Fa-f0-9]{3}|[A-Fa-f0-9]{4}|[A-Fa-f0-9]{6}|[A-Fa-f0-9]{8})$"
|
|
1870
|
+
},
|
|
1871
|
+
fontFamilyValue: {
|
|
1872
|
+
type: "string",
|
|
1873
|
+
minLength: 1,
|
|
1874
|
+
maxLength: 160,
|
|
1875
|
+
pattern: "^[A-Za-z0-9][A-Za-z0-9 _.,'-]*$"
|
|
1876
|
+
},
|
|
1877
|
+
optionValue: {
|
|
1878
|
+
type: "string",
|
|
1879
|
+
minLength: 1,
|
|
1880
|
+
maxLength: 160,
|
|
1881
|
+
pattern: "^[A-Za-z0-9][A-Za-z0-9 _.,'-]*$"
|
|
1882
|
+
}
|
|
1883
|
+
}
|
|
1884
|
+
};
|
|
1885
|
+
|
|
1481
1886
|
// ../core/package.json
|
|
1482
1887
|
var package_default = {
|
|
1483
1888
|
name: "@designos/core",
|
|
1484
|
-
version: "0.1
|
|
1889
|
+
version: "0.2.1",
|
|
1890
|
+
license: "MIT",
|
|
1485
1891
|
private: false,
|
|
1486
1892
|
type: "module",
|
|
1487
1893
|
exports: {
|
|
@@ -1524,7 +1930,8 @@ var package_default = {
|
|
|
1524
1930
|
// package.json
|
|
1525
1931
|
var package_default2 = {
|
|
1526
1932
|
name: "@designos/compiler-cli",
|
|
1527
|
-
version: "0.
|
|
1933
|
+
version: "0.3.1",
|
|
1934
|
+
license: "MIT",
|
|
1528
1935
|
private: false,
|
|
1529
1936
|
type: "module",
|
|
1530
1937
|
bin: {
|
|
@@ -1571,14 +1978,16 @@ var package_default2 = {
|
|
|
1571
1978
|
};
|
|
1572
1979
|
|
|
1573
1980
|
// src/kit-validator.ts
|
|
1574
|
-
var
|
|
1981
|
+
var schemaValidators = (() => {
|
|
1575
1982
|
const ajv = new Ajv2020({ allErrors: true, strict: true });
|
|
1576
1983
|
addFormats(ajv);
|
|
1577
|
-
return
|
|
1984
|
+
return {
|
|
1985
|
+
"1": ajv.compile(designos_kit_schema_default),
|
|
1986
|
+
"2": ajv.compile(designos_kit_schema_v2_default),
|
|
1987
|
+
design: ajv.compile(designos_design_schema_default)
|
|
1988
|
+
};
|
|
1578
1989
|
})();
|
|
1579
|
-
var CURRENT_KIT_CONTRACT_VERSION = "1.0.0";
|
|
1580
1990
|
var CURRENT_TOOL_VERSIONS = {
|
|
1581
|
-
kit: CURRENT_KIT_CONTRACT_VERSION,
|
|
1582
1991
|
core: package_default.version,
|
|
1583
1992
|
compiler: package_default2.version
|
|
1584
1993
|
};
|
|
@@ -1772,7 +2181,7 @@ function validateCompatibility(manifest, diagnostics) {
|
|
|
1772
2181
|
);
|
|
1773
2182
|
continue;
|
|
1774
2183
|
}
|
|
1775
|
-
const currentVersion = CURRENT_TOOL_VERSIONS[name];
|
|
2184
|
+
const currentVersion = name === "kit" ? manifest.schemaVersion === "2" ? "2.0.0" : "1.0.0" : CURRENT_TOOL_VERSIONS[name];
|
|
1776
2185
|
if (!currentVersion && name === "editor") {
|
|
1777
2186
|
diagnostics.push({
|
|
1778
2187
|
severity: "info",
|
|
@@ -1973,6 +2382,148 @@ async function validateEditorAdapters(rootRealPath, manifest, components, diagno
|
|
|
1973
2382
|
}
|
|
1974
2383
|
}
|
|
1975
2384
|
}
|
|
2385
|
+
function isValidDesignValue(token, value) {
|
|
2386
|
+
switch (token.type) {
|
|
2387
|
+
case "color":
|
|
2388
|
+
return typeof value === "string" && /^#(?:[A-Fa-f0-9]{3}|[A-Fa-f0-9]{4}|[A-Fa-f0-9]{6}|[A-Fa-f0-9]{8})$/.test(
|
|
2389
|
+
value
|
|
2390
|
+
);
|
|
2391
|
+
case "font-family":
|
|
2392
|
+
case "select":
|
|
2393
|
+
return typeof value === "string" && (token.options ?? []).some((option) => option.value === value);
|
|
2394
|
+
case "number":
|
|
2395
|
+
return typeof value === "number" && Number.isFinite(value) && token.min !== void 0 && token.max !== void 0 && token.step !== void 0 && token.step > 0 && value >= token.min && value <= token.max && Math.abs(
|
|
2396
|
+
(value - token.min) / token.step - Math.round((value - token.min) / token.step)
|
|
2397
|
+
) < 1e-9;
|
|
2398
|
+
}
|
|
2399
|
+
}
|
|
2400
|
+
function validateDesignSemantics(design, diagnostics) {
|
|
2401
|
+
const tokensById = /* @__PURE__ */ new Map();
|
|
2402
|
+
const tokenIds = /* @__PURE__ */ new Set();
|
|
2403
|
+
const cssVariables = /* @__PURE__ */ new Set();
|
|
2404
|
+
for (const [index, token] of design.tokens.entries()) {
|
|
2405
|
+
const path = `design.tokens[${index}]`;
|
|
2406
|
+
if (tokenIds.has(token.id)) {
|
|
2407
|
+
addError(
|
|
2408
|
+
diagnostics,
|
|
2409
|
+
"KIT_DESIGN_TOKEN_ID_DUPLICATE",
|
|
2410
|
+
`Duplicate design token ID ${JSON.stringify(token.id)}.`,
|
|
2411
|
+
`${path}.id`
|
|
2412
|
+
);
|
|
2413
|
+
} else {
|
|
2414
|
+
tokenIds.add(token.id);
|
|
2415
|
+
tokensById.set(token.id, token);
|
|
2416
|
+
}
|
|
2417
|
+
if (cssVariables.has(token.cssVariable)) {
|
|
2418
|
+
addError(
|
|
2419
|
+
diagnostics,
|
|
2420
|
+
"KIT_DESIGN_CSS_VARIABLE_DUPLICATE",
|
|
2421
|
+
`CSS variable ${JSON.stringify(token.cssVariable)} is assigned to more than one design token.`,
|
|
2422
|
+
`${path}.cssVariable`
|
|
2423
|
+
);
|
|
2424
|
+
}
|
|
2425
|
+
cssVariables.add(token.cssVariable);
|
|
2426
|
+
if (token.type === "number" && token.min > token.max) {
|
|
2427
|
+
addError(
|
|
2428
|
+
diagnostics,
|
|
2429
|
+
"KIT_DESIGN_NUMBER_RANGE_INVALID",
|
|
2430
|
+
"Numeric token minimum must not exceed its maximum.",
|
|
2431
|
+
`${path}.min`
|
|
2432
|
+
);
|
|
2433
|
+
}
|
|
2434
|
+
const optionValues = /* @__PURE__ */ new Set();
|
|
2435
|
+
for (const [optionIndex, option] of (token.options ?? []).entries()) {
|
|
2436
|
+
if (optionValues.has(option.value)) {
|
|
2437
|
+
addError(
|
|
2438
|
+
diagnostics,
|
|
2439
|
+
"KIT_DESIGN_OPTION_VALUE_DUPLICATE",
|
|
2440
|
+
`Duplicate option value ${JSON.stringify(option.value)} for token ${JSON.stringify(token.id)}.`,
|
|
2441
|
+
`${path}.options[${optionIndex}].value`
|
|
2442
|
+
);
|
|
2443
|
+
}
|
|
2444
|
+
optionValues.add(option.value);
|
|
2445
|
+
}
|
|
2446
|
+
if (!isValidDesignValue(token, token.default)) {
|
|
2447
|
+
addError(
|
|
2448
|
+
diagnostics,
|
|
2449
|
+
"KIT_DESIGN_DEFAULT_INVALID",
|
|
2450
|
+
`Default value is not valid for ${token.type} token ${JSON.stringify(token.id)}.`,
|
|
2451
|
+
`${path}.default`
|
|
2452
|
+
);
|
|
2453
|
+
}
|
|
2454
|
+
}
|
|
2455
|
+
const presetIds = /* @__PURE__ */ new Set();
|
|
2456
|
+
for (const [index, preset] of design.presets.entries()) {
|
|
2457
|
+
const path = `design.presets[${index}]`;
|
|
2458
|
+
if (presetIds.has(preset.id)) {
|
|
2459
|
+
addError(
|
|
2460
|
+
diagnostics,
|
|
2461
|
+
"KIT_DESIGN_PRESET_ID_DUPLICATE",
|
|
2462
|
+
`Duplicate design preset ID ${JSON.stringify(preset.id)}.`,
|
|
2463
|
+
`${path}.id`
|
|
2464
|
+
);
|
|
2465
|
+
}
|
|
2466
|
+
presetIds.add(preset.id);
|
|
2467
|
+
for (const token of tokensById.values()) {
|
|
2468
|
+
if (!Object.hasOwn(preset.values, token.id)) {
|
|
2469
|
+
addError(
|
|
2470
|
+
diagnostics,
|
|
2471
|
+
"KIT_DESIGN_PRESET_VALUE_MISSING",
|
|
2472
|
+
`Preset ${JSON.stringify(preset.id)} must define a value for token ${JSON.stringify(token.id)}.`,
|
|
2473
|
+
`${path}.values.${token.id}`
|
|
2474
|
+
);
|
|
2475
|
+
} else if (!isValidDesignValue(token, preset.values[token.id])) {
|
|
2476
|
+
addError(
|
|
2477
|
+
diagnostics,
|
|
2478
|
+
"KIT_DESIGN_PRESET_VALUE_INVALID",
|
|
2479
|
+
`Preset value is not valid for ${token.type} token ${JSON.stringify(token.id)}.`,
|
|
2480
|
+
`${path}.values.${token.id}`
|
|
2481
|
+
);
|
|
2482
|
+
}
|
|
2483
|
+
}
|
|
2484
|
+
for (const tokenId of Object.keys(preset.values)) {
|
|
2485
|
+
if (!tokensById.has(tokenId)) {
|
|
2486
|
+
addError(
|
|
2487
|
+
diagnostics,
|
|
2488
|
+
"KIT_DESIGN_PRESET_VALUE_UNKNOWN",
|
|
2489
|
+
`Preset ${JSON.stringify(preset.id)} references unknown token ${JSON.stringify(tokenId)}.`,
|
|
2490
|
+
`${path}.values.${tokenId}`
|
|
2491
|
+
);
|
|
2492
|
+
}
|
|
2493
|
+
}
|
|
2494
|
+
}
|
|
2495
|
+
}
|
|
2496
|
+
async function validateDesignManifest(rootRealPath, manifest, diagnostics) {
|
|
2497
|
+
if (manifest.schemaVersion !== "2" || !manifest.design) return;
|
|
2498
|
+
const designPath = await resolveRootFile(
|
|
2499
|
+
rootRealPath,
|
|
2500
|
+
manifest.design.manifest,
|
|
2501
|
+
"design.manifest",
|
|
2502
|
+
diagnostics
|
|
2503
|
+
);
|
|
2504
|
+
if (!designPath) return;
|
|
2505
|
+
const designValue = await readJsonFile(
|
|
2506
|
+
designPath,
|
|
2507
|
+
manifest.design.manifest,
|
|
2508
|
+
diagnostics
|
|
2509
|
+
);
|
|
2510
|
+
if (designValue === void 0) return;
|
|
2511
|
+
if (!schemaValidators.design(designValue)) {
|
|
2512
|
+
for (const error of schemaValidators.design.errors ?? []) {
|
|
2513
|
+
diagnostics.push({
|
|
2514
|
+
severity: "error",
|
|
2515
|
+
code: "KIT_DESIGN_MANIFEST_SCHEMA_INVALID",
|
|
2516
|
+
path: `design.manifest${error.instancePath || ""}`,
|
|
2517
|
+
message: `${error.message ?? "Schema constraint failed"}${error.params ? ` (${JSON.stringify(error.params)})` : ""}`
|
|
2518
|
+
});
|
|
2519
|
+
}
|
|
2520
|
+
return;
|
|
2521
|
+
}
|
|
2522
|
+
validateDesignSemantics(
|
|
2523
|
+
designValue,
|
|
2524
|
+
diagnostics
|
|
2525
|
+
);
|
|
2526
|
+
}
|
|
1976
2527
|
async function validateComponentKit(kitRoot) {
|
|
1977
2528
|
const diagnostics = [];
|
|
1978
2529
|
let rootRealPath;
|
|
@@ -2003,6 +2554,17 @@ async function validateComponentKit(kitRoot) {
|
|
|
2003
2554
|
diagnostics
|
|
2004
2555
|
);
|
|
2005
2556
|
if (rawManifest === void 0) return { valid: false, diagnostics };
|
|
2557
|
+
const rawSchemaVersion = isRecord(rawManifest) ? rawManifest.schemaVersion : void 0;
|
|
2558
|
+
if (typeof rawSchemaVersion === "string" && rawSchemaVersion !== "1" && rawSchemaVersion !== "2") {
|
|
2559
|
+
addError(
|
|
2560
|
+
diagnostics,
|
|
2561
|
+
"KIT_SCHEMA_VERSION_UNSUPPORTED",
|
|
2562
|
+
`Unsupported kit schemaVersion ${JSON.stringify(rawSchemaVersion)}; supported versions are "1" and "2".`,
|
|
2563
|
+
"schemaVersion"
|
|
2564
|
+
);
|
|
2565
|
+
return { valid: false, diagnostics };
|
|
2566
|
+
}
|
|
2567
|
+
const schemaValidator = rawSchemaVersion === "2" ? schemaValidators["2"] : schemaValidators["1"];
|
|
2006
2568
|
if (!schemaValidator(rawManifest)) {
|
|
2007
2569
|
for (const error of schemaValidator.errors ?? []) {
|
|
2008
2570
|
diagnostics.push({
|
|
@@ -2016,6 +2578,7 @@ async function validateComponentKit(kitRoot) {
|
|
|
2016
2578
|
}
|
|
2017
2579
|
const manifest = rawManifest;
|
|
2018
2580
|
validateCompatibility(manifest, diagnostics);
|
|
2581
|
+
await validateDesignManifest(rootRealPath, manifest, diagnostics);
|
|
2019
2582
|
const packageCandidate = resolve(rootRealPath, "package.json");
|
|
2020
2583
|
const packagePath = await resolveExistingFile(
|
|
2021
2584
|
rootRealPath,
|