-
-
Notifications
You must be signed in to change notification settings - Fork 58
Export CSS parser function, add CLI with --stats flag, and add stats utility #76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Copilot
wants to merge
16
commits into
main
Choose a base branch
from
copilot/create-cli-css-parser
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 12 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
3321b1f
Initial plan
Copilot fc53e2f
Initial plan for CLI and parser function implementation
Copilot 9a02c01
Add CSS parser function and CLI implementation
Copilot dbd6060
Address code review feedback: remove unused import and make parse fun…
Copilot 3c6da86
Rename cli.ts to bin.ts and use consistent import style
Copilot 44be182
Update CLI to accept file path argument instead of stdin
Copilot 3ce456e
Refactor to use parse function in plugin and add comprehensive tests
Copilot b4481b0
Add stats.ts with ts-morph to count tag usage in codebase
Copilot bf2f871
Update stats to count by rootAttributes from Parsed
Copilot a44df83
Add --stats flag to CLI to output tag usage statistics
Copilot 6e1cec8
Fix type safety in stats.ts and use os.tmpdir() in tests
Copilot 3f40f7b
Fix parse() to handle multi-selector rules correctly
Copilot 173ccac
Move postcss from devDependencies to dependencies
Copilot 6e926a6
update
typicode f3aaa48
Sort stats results by count in descending order
Copilot 9bcb29a
update
typicode File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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,70 @@ | ||
| #!/usr/bin/env node | ||
| import fs = require('node:fs') | ||
|
typicode marked this conversation as resolved.
Outdated
|
||
| import path = require('node:path') | ||
| import { parseArgs } from 'node:util' | ||
| import type { Parsed } from './index' | ||
| const { parse } = require('./index') | ||
| const { stats } = require('./stats') | ||
|
|
||
| const { values, positionals } = parseArgs({ | ||
| args: process.argv.slice(2), | ||
| options: { | ||
| stats: { | ||
| type: 'boolean', | ||
| default: false, | ||
| }, | ||
| }, | ||
| strict: true, | ||
| allowPositionals: true, | ||
| }) | ||
|
|
||
| if (positionals.length === 0) { | ||
| console.error('Error: Please provide a CSS file path') | ||
| console.error('Usage: mistcss <path-to-css-file> [--stats]') | ||
| process.exit(1) | ||
| } | ||
|
|
||
| const cssPath = positionals[0] | ||
| const css = fs.readFileSync(cssPath, 'utf-8') | ||
|
|
||
| const parsed = parse(css) | ||
|
|
||
| if (values.stats) { | ||
| // Find tsconfig.json in current directory or parent directories | ||
| let currentDir = process.cwd() | ||
| let tsconfigPath = null | ||
|
|
||
| while (currentDir !== path.dirname(currentDir)) { | ||
| const candidate = path.join(currentDir, 'tsconfig.json') | ||
| if (fs.existsSync(candidate)) { | ||
| tsconfigPath = candidate | ||
| break | ||
| } | ||
| currentDir = path.dirname(currentDir) | ||
| } | ||
|
|
||
| if (!tsconfigPath) { | ||
| console.error('Error: tsconfig.json not found in current directory or parent directories') | ||
| process.exit(1) | ||
| } | ||
|
|
||
| const statsResult = stats(parsed, tsconfigPath) | ||
| console.log(JSON.stringify(statsResult, null, 2)) | ||
| } else { | ||
| // Convert Sets to Arrays for JSON serialization | ||
| const serializable = Object.fromEntries( | ||
| (Object.entries(parsed) as [string, Parsed[string]][]).map(([key, value]) => [ | ||
| key, | ||
| { | ||
| ...value, | ||
| attributes: Object.fromEntries( | ||
| Object.entries(value.attributes).map(([k, v]) => [k, Array.from(v)]) | ||
| ), | ||
| booleanAttributes: Array.from(value.booleanAttributes), | ||
| properties: Array.from(value.properties), | ||
| }, | ||
| ]) | ||
| ) | ||
|
|
||
| console.log(JSON.stringify(serializable, null, 2)) | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
exportsfield is a string, which restricts consumers to importing only the package root. That makes the documentedmistcss/lib/stats(and any other subpath likelib/stats) unavailable in Node whenexportsis present. Ifstatsis intended to be a public utility, switchexportsto an object and explicitly export./stats(and any other public subpaths), while keeping.pointing at./lib/index.js.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot don't export stats