-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: verify consistent node usages across frameeworks
- Loading branch information
1 parent
f5f867c
commit 5008a2b
Showing
22 changed files
with
112 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { parse } from 'node:path' | ||
import { readFileSync } from 'fs-extra' | ||
import { globby } from 'globby' | ||
|
||
const main = async () => { | ||
const components = await globby(['../frameworks/*/src/components/*/*.{tsx,vue}']) | ||
|
||
const items = components | ||
.filter((file) => !file.endsWith('.stories.tsx')) | ||
.filter((file) => !file.endsWith('.stories.vue')) | ||
.filter((file) => !file.endsWith('.test.tsx')) | ||
.map((file) => { | ||
const content = readFileSync(file, 'utf-8') | ||
// search for the first occurent of ark.div, ark.span etc | ||
// and log the result | ||
const match = content.match(/<ark.([A-Za-z]*)/) | ||
return { | ||
name: parse(file).name, | ||
node: match?.[1], | ||
} | ||
}) | ||
|
||
groupItems(items) | ||
} | ||
|
||
interface Item { | ||
name: string | ||
node?: string | ||
} | ||
|
||
function groupItems(items: Item[]): void { | ||
const groupedItems = new Map<string, string[]>() | ||
|
||
for (const item of items) { | ||
if (!groupedItems.has(item.name)) { | ||
groupedItems.set(item.name, []) | ||
} | ||
if (item.node !== undefined) { | ||
// only add node if it's not undefined | ||
groupedItems.get(item.name)?.push(item.node) | ||
} | ||
} | ||
|
||
const result = Array.from(groupedItems).filter(([_, nodes]) => { | ||
return nodes.length > 1 && new Set(nodes).size > 1 | ||
}) | ||
|
||
if (result.length > 0) { | ||
console.log('The following components have mixed nodes:') | ||
result.map(([name, nodes]) => { | ||
console.log(name, nodes) | ||
}) | ||
process.exit(1) | ||
} | ||
} | ||
|
||
main().catch((err) => { | ||
console.error(err.message) | ||
process.exit(1) | ||
}) |