mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-20 12:23:02 +00:00
parent
3950496b7e
commit
02f5ff7be2
1 changed files with 13 additions and 3 deletions
|
@ -5,16 +5,25 @@ const slug = require("remark-slug");
|
||||||
const visit = require("unist-util-visit");
|
const visit = require("unist-util-visit");
|
||||||
const { format } = require("prettier");
|
const { format } = require("prettier");
|
||||||
const pkg = require("../package.json");
|
const pkg = require("../package.json");
|
||||||
|
const component_api = require("./src/COMPONENT_API.json");
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
const Prism = require("prismjs");
|
const Prism = require("prismjs");
|
||||||
require("prism-svelte");
|
require("prism-svelte");
|
||||||
|
|
||||||
|
const component_api_by_name = component_api.components.reduce((a, c) => {
|
||||||
|
return {
|
||||||
|
...a,
|
||||||
|
[c.moduleName]: true,
|
||||||
|
};
|
||||||
|
}, {});
|
||||||
|
|
||||||
function createImports(source) {
|
function createImports(source) {
|
||||||
const inlineComponents = new Set();
|
const inlineComponents = new Set();
|
||||||
const icons = new Set();
|
const icons = new Set();
|
||||||
|
|
||||||
// TODO: [refactor] better determine if component is a Carbon icon
|
// heuristic to guess if the inline component or expression name is a Carbon icon
|
||||||
const isIcon = (text) => text.match(/(16|20|24|32)/);
|
const isIcon = (text) =>
|
||||||
|
/[A-Z][a-z]*/.test(text) && !(text in component_api_by_name);
|
||||||
|
|
||||||
walk(parse(source), {
|
walk(parse(source), {
|
||||||
enter(node) {
|
enter(node) {
|
||||||
|
@ -48,7 +57,8 @@ function createImports(source) {
|
||||||
icons.size > 0
|
icons.size > 0
|
||||||
? icon_imports
|
? icon_imports
|
||||||
.map(
|
.map(
|
||||||
(icon) => `import ${icon} from "carbon-icons-svelte/lib/${icon}";`
|
(icon) =>
|
||||||
|
`import ${icon} from "carbon-icons-svelte/lib/${icon}.svelte";`
|
||||||
)
|
)
|
||||||
.join("\n")
|
.join("\n")
|
||||||
: ""
|
: ""
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue