@rien7/seji 0.0.0-stage → 0.6.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.
- package/bin/design-surface.mjs +6 -0
- package/bin/postinstall.mjs +19 -0
- package/bin/seji.mjs +573 -0
- package/dist/agent/host.d.mts +34 -0
- package/dist/agent/host.mjs +387 -0
- package/dist/agent/messages.d.mts +9 -0
- package/dist/agent/messages.mjs +70 -0
- package/dist/agent/runtimes.mjs +157 -0
- package/dist/cli/app.mjs +321 -0
- package/dist/cli/appScan.mjs +284 -0
- package/dist/cli/catalog.mjs +78 -0
- package/dist/cli/component.mjs +165 -0
- package/dist/cli/consolidate.mjs +159 -0
- package/dist/cli/cssImport.mjs +68 -0
- package/dist/cli/dev.mjs +335 -0
- package/dist/cli/doctor.mjs +306 -0
- package/dist/cli/init.mjs +338 -0
- package/dist/cli/legacyNames.mjs +266 -0
- package/dist/cli/migrate.mjs +163 -0
- package/dist/cli/prompt.mjs +34 -0
- package/dist/cli/propose.mjs +208 -0
- package/dist/cli/providers.mjs +344 -0
- package/dist/cli/reviewOps.mjs +110 -0
- package/dist/cli/semver.mjs +45 -0
- package/dist/cli/setup.mjs +357 -0
- package/dist/cli/sketches.mjs +47 -0
- package/dist/cli/skills.mjs +150 -0
- package/dist/cli/snapshot.mjs +107 -0
- package/dist/cli/tokenOps.mjs +120 -0
- package/dist/cli/types.mjs +191 -0
- package/dist/cli/updater.mjs +274 -0
- package/dist/components/astIndex.mjs +992 -0
- package/dist/components/ops.mjs +1069 -0
- package/dist/editor/AgentProposalCard.d.ts +10 -0
- package/dist/editor/AgentProposalCard.d.ts.map +1 -0
- package/dist/editor/AgentProposalCard.js +31 -0
- package/dist/editor/AgentProposalCard.js.map +1 -0
- package/dist/editor/App.d.ts +2 -0
- package/dist/editor/App.d.ts.map +1 -0
- package/dist/editor/App.js +2832 -0
- package/dist/editor/App.js.map +1 -0
- package/dist/editor/CanvasHud.d.ts +12 -0
- package/dist/editor/CanvasHud.d.ts.map +1 -0
- package/dist/editor/CanvasHud.js +13 -0
- package/dist/editor/CanvasHud.js.map +1 -0
- package/dist/editor/CanvasSurface.d.ts +31 -0
- package/dist/editor/CanvasSurface.d.ts.map +1 -0
- package/dist/editor/CanvasSurface.js +270 -0
- package/dist/editor/CanvasSurface.js.map +1 -0
- package/dist/editor/CommentPopover.d.ts +17 -0
- package/dist/editor/CommentPopover.d.ts.map +1 -0
- package/dist/editor/CommentPopover.js +62 -0
- package/dist/editor/CommentPopover.js.map +1 -0
- package/dist/editor/Comments.d.ts +13 -0
- package/dist/editor/Comments.d.ts.map +1 -0
- package/dist/editor/Comments.js +41 -0
- package/dist/editor/Comments.js.map +1 -0
- package/dist/editor/ComponentPage.d.ts +28 -0
- package/dist/editor/ComponentPage.d.ts.map +1 -0
- package/dist/editor/ComponentPage.js +55 -0
- package/dist/editor/ComponentPage.js.map +1 -0
- package/dist/editor/ComponentPanel.d.ts +38 -0
- package/dist/editor/ComponentPanel.d.ts.map +1 -0
- package/dist/editor/ComponentPanel.js +275 -0
- package/dist/editor/ComponentPanel.js.map +1 -0
- package/dist/editor/Glyph.d.ts +51 -0
- package/dist/editor/Glyph.d.ts.map +1 -0
- package/dist/editor/Glyph.js +50 -0
- package/dist/editor/Glyph.js.map +1 -0
- package/dist/editor/History.d.ts +7 -0
- package/dist/editor/History.d.ts.map +1 -0
- package/dist/editor/History.js +51 -0
- package/dist/editor/History.js.map +1 -0
- package/dist/editor/Inspector.d.ts +56 -0
- package/dist/editor/Inspector.d.ts.map +1 -0
- package/dist/editor/Inspector.js +510 -0
- package/dist/editor/Inspector.js.map +1 -0
- package/dist/editor/LazyMount.d.ts +10 -0
- package/dist/editor/LazyMount.d.ts.map +1 -0
- package/dist/editor/LazyMount.js +29 -0
- package/dist/editor/LazyMount.js.map +1 -0
- package/dist/editor/LocaleSwitch.d.ts +3 -0
- package/dist/editor/LocaleSwitch.d.ts.map +1 -0
- package/dist/editor/LocaleSwitch.js +9 -0
- package/dist/editor/LocaleSwitch.js.map +1 -0
- package/dist/editor/PreviewFrame.d.ts +10 -0
- package/dist/editor/PreviewFrame.d.ts.map +1 -0
- package/dist/editor/PreviewFrame.js +22 -0
- package/dist/editor/PreviewFrame.js.map +1 -0
- package/dist/editor/ProjectIndex.d.ts +12 -0
- package/dist/editor/ProjectIndex.d.ts.map +1 -0
- package/dist/editor/ProjectIndex.js +43 -0
- package/dist/editor/ProjectIndex.js.map +1 -0
- package/dist/editor/PromoteComponent.d.ts +28 -0
- package/dist/editor/PromoteComponent.d.ts.map +1 -0
- package/dist/editor/PromoteComponent.js +33 -0
- package/dist/editor/PromoteComponent.js.map +1 -0
- package/dist/editor/PromoteForm.d.ts +18 -0
- package/dist/editor/PromoteForm.d.ts.map +1 -0
- package/dist/editor/PromoteForm.js +35 -0
- package/dist/editor/PromoteForm.js.map +1 -0
- package/dist/editor/PromoteToken.d.ts +31 -0
- package/dist/editor/PromoteToken.d.ts.map +1 -0
- package/dist/editor/PromoteToken.js +94 -0
- package/dist/editor/PromoteToken.js.map +1 -0
- package/dist/editor/StatePreviews.d.ts +28 -0
- package/dist/editor/StatePreviews.d.ts.map +1 -0
- package/dist/editor/StatePreviews.js +113 -0
- package/dist/editor/StatePreviews.js.map +1 -0
- package/dist/editor/ValueCombo.d.ts +51 -0
- package/dist/editor/ValueCombo.d.ts.map +1 -0
- package/dist/editor/ValueCombo.js +260 -0
- package/dist/editor/ValueCombo.js.map +1 -0
- package/dist/editor/agent/AgentPanel.d.ts +19 -0
- package/dist/editor/agent/AgentPanel.d.ts.map +1 -0
- package/dist/editor/agent/AgentPanel.js +271 -0
- package/dist/editor/agent/AgentPanel.js.map +1 -0
- package/dist/editor/agent/Markdown.d.ts +5 -0
- package/dist/editor/agent/Markdown.d.ts.map +1 -0
- package/dist/editor/agent/Markdown.js +28 -0
- package/dist/editor/agent/Markdown.js.map +1 -0
- package/dist/editor/agent/agentApi.d.ts +106 -0
- package/dist/editor/agent/agentApi.d.ts.map +1 -0
- package/dist/editor/agent/agentApi.js +66 -0
- package/dist/editor/agent/agentApi.js.map +1 -0
- package/dist/editor/agent/toolLines.d.ts +38 -0
- package/dist/editor/agent/toolLines.d.ts.map +1 -0
- package/dist/editor/agent/toolLines.js +159 -0
- package/dist/editor/agent/toolLines.js.map +1 -0
- package/dist/editor/agent/useAgent.d.ts +15 -0
- package/dist/editor/agent/useAgent.d.ts.map +1 -0
- package/dist/editor/agent/useAgent.js +65 -0
- package/dist/editor/agent/useAgent.js.map +1 -0
- package/dist/editor/api.d.ts +378 -0
- package/dist/editor/api.d.ts.map +1 -0
- package/dist/editor/api.js +247 -0
- package/dist/editor/api.js.map +1 -0
- package/dist/editor/camera.d.ts +18 -0
- package/dist/editor/camera.d.ts.map +1 -0
- package/dist/editor/camera.js +40 -0
- package/dist/editor/camera.js.map +1 -0
- package/dist/editor/canvas.d.ts +25 -0
- package/dist/editor/canvas.d.ts.map +1 -0
- package/dist/editor/canvas.js +35 -0
- package/dist/editor/canvas.js.map +1 -0
- package/dist/editor/changes/ChangesPage.d.ts +25 -0
- package/dist/editor/changes/ChangesPage.d.ts.map +1 -0
- package/dist/editor/changes/ChangesPage.js +132 -0
- package/dist/editor/changes/ChangesPage.js.map +1 -0
- package/dist/editor/changes/changeModel.d.ts +25 -0
- package/dist/editor/changes/changeModel.d.ts.map +1 -0
- package/dist/editor/changes/changeModel.js +81 -0
- package/dist/editor/changes/changeModel.js.map +1 -0
- package/dist/editor/changes/changeState.d.mts +29 -0
- package/dist/editor/changes/changeState.mjs +187 -0
- package/dist/editor/chrome/EditorChrome.d.ts +49 -0
- package/dist/editor/chrome/EditorChrome.d.ts.map +1 -0
- package/dist/editor/chrome/EditorChrome.js +21 -0
- package/dist/editor/chrome/EditorChrome.js.map +1 -0
- package/dist/editor/drafts.d.ts +46 -0
- package/dist/editor/drafts.d.ts.map +1 -0
- package/dist/editor/drafts.js +38 -0
- package/dist/editor/drafts.js.map +1 -0
- package/dist/editor/i18n.d.ts +29 -0
- package/dist/editor/i18n.d.ts.map +1 -0
- package/dist/editor/i18n.js +2320 -0
- package/dist/editor/i18n.js.map +1 -0
- package/dist/editor/iconStroke.d.ts +6 -0
- package/dist/editor/iconStroke.d.ts.map +1 -0
- package/dist/editor/iconStroke.js +6 -0
- package/dist/editor/iconStroke.js.map +1 -0
- package/dist/editor/main.d.ts +2 -0
- package/dist/editor/main.d.ts.map +1 -0
- package/dist/editor/main.js +14 -0
- package/dist/editor/main.js.map +1 -0
- package/dist/editor/model.d.ts +16 -0
- package/dist/editor/model.d.ts.map +1 -0
- package/dist/editor/model.js +11 -0
- package/dist/editor/model.js.map +1 -0
- package/dist/editor/reasons.d.ts +44 -0
- package/dist/editor/reasons.d.ts.map +1 -0
- package/dist/editor/reasons.js +131 -0
- package/dist/editor/reasons.js.map +1 -0
- package/dist/editor/reviewLifecycle.d.ts +8 -0
- package/dist/editor/reviewLifecycle.d.ts.map +1 -0
- package/dist/editor/reviewLifecycle.js +21 -0
- package/dist/editor/reviewLifecycle.js.map +1 -0
- package/dist/editor/styles.css +8737 -0
- package/dist/editor/tokenMatch.d.ts +59 -0
- package/dist/editor/tokenMatch.d.ts.map +1 -0
- package/dist/editor/tokenMatch.js +198 -0
- package/dist/editor/tokenMatch.js.map +1 -0
- package/dist/editor/tokens/ConsolidatePage.d.ts +16 -0
- package/dist/editor/tokens/ConsolidatePage.d.ts.map +1 -0
- package/dist/editor/tokens/ConsolidatePage.js +244 -0
- package/dist/editor/tokens/ConsolidatePage.js.map +1 -0
- package/dist/editor/tokens/TokenActivity.d.ts +18 -0
- package/dist/editor/tokens/TokenActivity.d.ts.map +1 -0
- package/dist/editor/tokens/TokenActivity.js +18 -0
- package/dist/editor/tokens/TokenActivity.js.map +1 -0
- package/dist/editor/tokens/TokenDialogs.d.ts +26 -0
- package/dist/editor/tokens/TokenDialogs.d.ts.map +1 -0
- package/dist/editor/tokens/TokenDialogs.js +119 -0
- package/dist/editor/tokens/TokenDialogs.js.map +1 -0
- package/dist/editor/tokens/TokenList.d.ts +21 -0
- package/dist/editor/tokens/TokenList.d.ts.map +1 -0
- package/dist/editor/tokens/TokenList.js +98 -0
- package/dist/editor/tokens/TokenList.js.map +1 -0
- package/dist/editor/tokens/TokenPage.d.ts +25 -0
- package/dist/editor/tokens/TokenPage.d.ts.map +1 -0
- package/dist/editor/tokens/TokenPage.js +108 -0
- package/dist/editor/tokens/TokenPage.js.map +1 -0
- package/dist/editor/tokens/tokenModel.d.ts +35 -0
- package/dist/editor/tokens/tokenModel.d.ts.map +1 -0
- package/dist/editor/tokens/tokenModel.js +72 -0
- package/dist/editor/tokens/tokenModel.js.map +1 -0
- package/dist/editor/ui/Button.d.ts +3 -0
- package/dist/editor/ui/Button.d.ts.map +1 -0
- package/dist/editor/ui/Button.js +6 -0
- package/dist/editor/ui/Button.js.map +1 -0
- package/dist/editor/ui/CommentBox.d.ts +23 -0
- package/dist/editor/ui/CommentBox.d.ts.map +1 -0
- package/dist/editor/ui/CommentBox.js +41 -0
- package/dist/editor/ui/CommentBox.js.map +1 -0
- package/dist/editor/ui/Icon.d.ts +8 -0
- package/dist/editor/ui/Icon.d.ts.map +1 -0
- package/dist/editor/ui/Icon.js +6 -0
- package/dist/editor/ui/Icon.js.map +1 -0
- package/dist/editor/ui/IconButton.d.ts +11 -0
- package/dist/editor/ui/IconButton.d.ts.map +1 -0
- package/dist/editor/ui/IconButton.js +6 -0
- package/dist/editor/ui/IconButton.js.map +1 -0
- package/dist/editor/ui/NumberInput.d.ts +14 -0
- package/dist/editor/ui/NumberInput.d.ts.map +1 -0
- package/dist/editor/ui/NumberInput.js +6 -0
- package/dist/editor/ui/NumberInput.js.map +1 -0
- package/dist/editor/ui/PageLine.d.ts +14 -0
- package/dist/editor/ui/PageLine.d.ts.map +1 -0
- package/dist/editor/ui/PageLine.js +7 -0
- package/dist/editor/ui/PageLine.js.map +1 -0
- package/dist/editor/ui/SearchPicker.d.ts +41 -0
- package/dist/editor/ui/SearchPicker.d.ts.map +1 -0
- package/dist/editor/ui/SearchPicker.js +82 -0
- package/dist/editor/ui/SearchPicker.js.map +1 -0
- package/dist/editor/ui/Select.d.ts +19 -0
- package/dist/editor/ui/Select.d.ts.map +1 -0
- package/dist/editor/ui/Select.js +12 -0
- package/dist/editor/ui/Select.js.map +1 -0
- package/dist/editor/ui/TokenField.d.ts +14 -0
- package/dist/editor/ui/TokenField.d.ts.map +1 -0
- package/dist/editor/ui/TokenField.js +41 -0
- package/dist/editor/ui/TokenField.js.map +1 -0
- package/dist/editor/ui/TokenPicker.d.ts +31 -0
- package/dist/editor/ui/TokenPicker.d.ts.map +1 -0
- package/dist/editor/ui/TokenPicker.js +26 -0
- package/dist/editor/ui/TokenPicker.js.map +1 -0
- package/dist/editor/useBuildError.d.ts +7 -0
- package/dist/editor/useBuildError.d.ts.map +1 -0
- package/dist/editor/useBuildError.js +30 -0
- package/dist/editor/useBuildError.js.map +1 -0
- package/dist/editor/useLatestRequest.d.ts +22 -0
- package/dist/editor/useLatestRequest.d.ts.map +1 -0
- package/dist/editor/useLatestRequest.js +49 -0
- package/dist/editor/useLatestRequest.js.map +1 -0
- package/dist/editor-bundle/editor.css +2 -0
- package/dist/editor-bundle/editor.js +83 -0
- package/dist/editor-ui.d.ts +15 -0
- package/dist/editor-ui.d.ts.map +1 -0
- package/dist/editor-ui.js +14 -0
- package/dist/editor-ui.js.map +1 -0
- package/dist/inspector/runtime.d.ts +18 -0
- package/dist/inspector/runtime.d.ts.map +1 -0
- package/dist/inspector/runtime.js +1280 -0
- package/dist/inspector/runtime.js.map +1 -0
- package/dist/preview/main.d.ts +3 -0
- package/dist/preview/main.d.ts.map +1 -0
- package/dist/preview/main.js +320 -0
- package/dist/preview/main.js.map +1 -0
- package/dist/preview/preview.css +40 -0
- package/dist/runtime/index.d.ts +3 -0
- package/dist/runtime/index.d.ts.map +1 -0
- package/dist/runtime/index.js +2 -0
- package/dist/runtime/index.js.map +1 -0
- package/dist/shared/buildError.d.mts +27 -0
- package/dist/shared/buildError.mjs +141 -0
- package/dist/shared/cameraFit.d.mts +16 -0
- package/dist/shared/cameraFit.mjs +47 -0
- package/dist/shared/canvasLayout.d.mts +13 -0
- package/dist/shared/canvasLayout.mjs +171 -0
- package/dist/shared/commentShots.d.mts +12 -0
- package/dist/shared/commentShots.mjs +53 -0
- package/dist/shared/componentExtract.d.mts +43 -0
- package/dist/shared/componentExtract.mjs +136 -0
- package/dist/shared/componentMeta.d.mts +26 -0
- package/dist/shared/componentMeta.mjs +87 -0
- package/dist/shared/componentOps.d.mts +70 -0
- package/dist/shared/componentOps.mjs +407 -0
- package/dist/shared/componentTarget.d.mts +15 -0
- package/dist/shared/componentTarget.mjs +58 -0
- package/dist/shared/components.d.mts +30 -0
- package/dist/shared/components.mjs +106 -0
- package/dist/shared/consolidateCategories.d.mts +2 -0
- package/dist/shared/consolidateCategories.mjs +6 -0
- package/dist/shared/env.d.mts +4 -0
- package/dist/shared/env.mjs +18 -0
- package/dist/shared/gitChanges.d.mts +2 -0
- package/dist/shared/gitChanges.mjs +30 -0
- package/dist/shared/oklab.d.mts +6 -0
- package/dist/shared/oklab.mjs +56 -0
- package/dist/shared/optimizeEntries.d.mts +5 -0
- package/dist/shared/optimizeEntries.mjs +24 -0
- package/dist/shared/packages.d.mts +11 -0
- package/dist/shared/packages.mjs +96 -0
- package/dist/shared/projectFiles.d.mts +23 -0
- package/dist/shared/projectFiles.mjs +72 -0
- package/dist/shared/prompt.d.mts +20 -0
- package/dist/shared/prompt.mjs +201 -0
- package/dist/shared/proposals.d.mts +11 -0
- package/dist/shared/proposals.mjs +42 -0
- package/dist/shared/protocol.d.ts +122 -0
- package/dist/shared/protocol.d.ts.map +1 -0
- package/dist/shared/protocol.js +7 -0
- package/dist/shared/protocol.js.map +1 -0
- package/dist/shared/reviewArchive.d.mts +4 -0
- package/dist/shared/reviewArchive.mjs +19 -0
- package/dist/shared/reviewStore.d.mts +30 -0
- package/dist/shared/reviewStore.mjs +218 -0
- package/dist/shared/reviewVerify.d.mts +21 -0
- package/dist/shared/reviewVerify.mjs +158 -0
- package/dist/shared/sizeModes.d.mts +15 -0
- package/dist/shared/sizeModes.mjs +53 -0
- package/dist/shared/sketches.d.mts +10 -0
- package/dist/shared/sketches.mjs +64 -0
- package/dist/shared/snapshotCheck.d.mts +13 -0
- package/dist/shared/snapshotCheck.mjs +81 -0
- package/dist/shared/timeout.d.mts +1 -0
- package/dist/shared/timeout.mjs +15 -0
- package/dist/shared/tokens.d.ts +2 -0
- package/dist/shared/tokens.d.ts.map +1 -0
- package/dist/shared/tokens.js +2 -0
- package/dist/shared/tokens.js.map +1 -0
- package/dist/shared/types.d.ts +689 -0
- package/dist/shared/types.d.ts.map +1 -0
- package/dist/shared/types.js +13 -0
- package/dist/shared/types.js.map +1 -0
- package/dist/shared/wheelRouting.d.mts +9 -0
- package/dist/shared/wheelRouting.mjs +31 -0
- package/dist/shared/writeScope.mjs +96 -0
- package/dist/snapshots/diff.d.mts +28 -0
- package/dist/snapshots/diff.mjs +263 -0
- package/dist/snapshots/index.d.mts +110 -0
- package/dist/snapshots/index.mjs +638 -0
- package/dist/snapshots/render.d.mts +24 -0
- package/dist/snapshots/render.mjs +250 -0
- package/dist/snapshots/toolOps.d.mts +25 -0
- package/dist/snapshots/toolOps.mjs +69 -0
- package/dist/tokens/adapters/css.mjs +51 -0
- package/dist/tokens/adapters/cssInCode.mjs +314 -0
- package/dist/tokens/adapters/oxcShared.mjs +80 -0
- package/dist/tokens/adapters/preprocessor.mjs +63 -0
- package/dist/tokens/adapters/registry.mjs +53 -0
- package/dist/tokens/adapters/tailwindcss.mjs +424 -0
- package/dist/tokens/adapters/types.mjs +117 -0
- package/dist/tokens/consolidate/index.d.mts +42 -0
- package/dist/tokens/consolidate/index.mjs +111 -0
- package/dist/tokens/consolidate/normalize.mjs +479 -0
- package/dist/tokens/consolidate/plan.mjs +726 -0
- package/dist/tokens/consolidate/scan.mjs +928 -0
- package/dist/tokens/extract.mjs +441 -0
- package/dist/tokens/moduleData.d.mts +14 -0
- package/dist/tokens/moduleData.mjs +32 -0
- package/dist/tokens/opLock.d.mts +4 -0
- package/dist/tokens/opLock.mjs +108 -0
- package/dist/tokens/ops.d.mts +71 -0
- package/dist/tokens/ops.mjs +1511 -0
- package/dist/tokens/pipeline.mjs +813 -0
- package/dist/tokens/report.d.mts +47 -0
- package/dist/tokens/report.mjs +257 -0
- package/dist/tokens/rewrite/code.mjs +172 -0
- package/dist/tokens/rewrite/css.mjs +154 -0
- package/dist/tokens/rewrite/index.mjs +244 -0
- package/dist/tokens/rewrite/tailwind.mjs +288 -0
- package/dist/tokens/rewrite/text.mjs +116 -0
- package/dist/tokens/rewrite/value.mjs +115 -0
- package/dist/tokens/usage.d.mts +97 -0
- package/dist/tokens/usage.mjs +680 -0
- package/dist/vite/agent.d.ts +21 -0
- package/dist/vite/agent.d.ts.map +1 -0
- package/dist/vite/agent.js +165 -0
- package/dist/vite/agent.js.map +1 -0
- package/dist/vite/events.d.ts +27 -0
- package/dist/vite/events.d.ts.map +1 -0
- package/dist/vite/events.js +156 -0
- package/dist/vite/events.js.map +1 -0
- package/dist/vite/layout.d.ts +2 -0
- package/dist/vite/layout.d.ts.map +1 -0
- package/dist/vite/layout.js +4 -0
- package/dist/vite/layout.js.map +1 -0
- package/dist/vite/plugin.d.ts +40 -0
- package/dist/vite/plugin.d.ts.map +1 -0
- package/dist/vite/plugin.js +1255 -0
- package/dist/vite/plugin.js.map +1 -0
- package/dist/vite/requestGuard.d.mts +3 -0
- package/dist/vite/requestGuard.mjs +43 -0
- package/dist/vite/review.d.ts +11 -0
- package/dist/vite/review.d.ts.map +1 -0
- package/dist/vite/review.js +283 -0
- package/dist/vite/review.js.map +1 -0
- package/package.json +104 -4
- package/skills/seji/SKILL.md +395 -0
- package/skills/seji-authoring/SKILL.md +397 -0
- package/skills/seji-tokens/SKILL.md +432 -0
- package/README.md +0 -3
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
// `seji component …`, `seji propose component …` and
|
|
2
|
+
// `seji proposal …`: argument parsing over the shared component operations (the
|
|
3
|
+
// HTTP API uses the same functions with the same catalog, see catalog.mjs).
|
|
4
|
+
import path from 'node:path'
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
describeComponent,
|
|
8
|
+
parseFrames,
|
|
9
|
+
listComponents,
|
|
10
|
+
planComponentAction,
|
|
11
|
+
recordComponentAction,
|
|
12
|
+
revertComponentAction,
|
|
13
|
+
showComponent,
|
|
14
|
+
} from '../shared/componentOps.mjs'
|
|
15
|
+
import { decideProposal } from '../shared/proposals.mjs'
|
|
16
|
+
import { loadComponentCatalog } from './catalog.mjs'
|
|
17
|
+
|
|
18
|
+
const VALUE_FLAGS = new Set([
|
|
19
|
+
'--to',
|
|
20
|
+
'--into',
|
|
21
|
+
'--replacement',
|
|
22
|
+
'--reason',
|
|
23
|
+
'--design',
|
|
24
|
+
'--frames',
|
|
25
|
+
'--frame',
|
|
26
|
+
'--rationale',
|
|
27
|
+
'--note',
|
|
28
|
+
'--value',
|
|
29
|
+
'--config',
|
|
30
|
+
])
|
|
31
|
+
const BOOLEAN_FLAGS = new Set(['--no-replacement', '--replace-all', '--dry-run', '--force'])
|
|
32
|
+
// Repeatable: every occurrence is kept (`--frame a --frame b`, `--frames a,b`, or both).
|
|
33
|
+
const LIST_FLAGS = new Set(['--frames', '--frame'])
|
|
34
|
+
|
|
35
|
+
function parse(argv) {
|
|
36
|
+
const positional = []
|
|
37
|
+
const flags = {}
|
|
38
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
39
|
+
const token = argv[i]
|
|
40
|
+
if (!token.startsWith('--')) {
|
|
41
|
+
positional.push(token)
|
|
42
|
+
continue
|
|
43
|
+
}
|
|
44
|
+
const [key, inline] = token.includes('=') ? [token.slice(0, token.indexOf('=')), token.slice(token.indexOf('=') + 1)] : [token, undefined]
|
|
45
|
+
if (BOOLEAN_FLAGS.has(key)) {
|
|
46
|
+
flags[key] = true
|
|
47
|
+
} else if (VALUE_FLAGS.has(key)) {
|
|
48
|
+
const value = inline ?? argv[i + 1]
|
|
49
|
+
if (value === undefined || (inline === undefined && value.startsWith('--'))) throw new Error(`${key} needs a value`)
|
|
50
|
+
if (LIST_FLAGS.has(key)) flags['--frames'] = [...(flags['--frames'] ?? []), value]
|
|
51
|
+
else flags[key] = value
|
|
52
|
+
if (inline === undefined) i += 1
|
|
53
|
+
} else {
|
|
54
|
+
throw new Error(`unknown option: ${key}`)
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return { positional, flags }
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const relative = (root, file) => path.relative(root, file).split(path.sep).join('/')
|
|
61
|
+
const SUBCOMMANDS = ['list', 'show', 'describe', 'rename', 'merge', 'deprecate', 'undeprecate', 'delete', 'tidy', 'revert']
|
|
62
|
+
|
|
63
|
+
function describeResult(root, name, result) {
|
|
64
|
+
if (result.op) {
|
|
65
|
+
const op = result.op
|
|
66
|
+
const left = op.leftovers.length
|
|
67
|
+
? `\nLeft for the agent:\n${op.leftovers.map((place) => ` ${place.file}:${place.line}:${place.column} ${place.reason}${place.text ? ` ${place.text}` : ''}`).join('\n')}`
|
|
68
|
+
: ''
|
|
69
|
+
return `${op.summary}: tool changed ${op.counts.changed} place(s) in ${op.counts.files} file(s), left ${op.leftovers.length} for the agent. Recorded ${op.itemId} (batch ${op.batchId}) in ${relative(root, result.reviewPath)}${left}`
|
|
70
|
+
}
|
|
71
|
+
if (result.action === 'deprecate') {
|
|
72
|
+
return `Marked ${name} deprecated in design/components.json${result.entry?.replacement ? ` (replacement: ${result.entry.replacement})` : ' (no replacement)'}`
|
|
73
|
+
}
|
|
74
|
+
if (result.action === 'undeprecate') return `${name} is no longer deprecated in design/components.json`
|
|
75
|
+
const { item, reviewPath } = result
|
|
76
|
+
return `Recorded ${item.componentAction} of ${name} as ${item.id} in ${relative(root, reviewPath)}`
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** Returns the text to print. Throws on bad input. */
|
|
80
|
+
export async function runComponentCommand({ root, argv }) {
|
|
81
|
+
const [sub, ...rest] = argv
|
|
82
|
+
const { positional, flags } = parse(rest)
|
|
83
|
+
if (!SUBCOMMANDS.includes(sub)) {
|
|
84
|
+
throw new Error(`unknown component subcommand: ${sub ?? '(missing)'} (expected ${SUBCOMMANDS.join(', ')})`)
|
|
85
|
+
}
|
|
86
|
+
if (sub === 'revert') {
|
|
87
|
+
const batch = positional[0]
|
|
88
|
+
if (!batch) throw new Error('component revert needs a <batch> id')
|
|
89
|
+
const result = await revertComponentAction({ root, batch, design: flags['--design'], force: Boolean(flags['--force']), dryRun: Boolean(flags['--dry-run']) })
|
|
90
|
+
return JSON.stringify(result, null, 2)
|
|
91
|
+
}
|
|
92
|
+
const catalog = await loadComponentCatalog(root, { configFile: flags['--config'] })
|
|
93
|
+
if (sub === 'list') {
|
|
94
|
+
return JSON.stringify(await listComponents({ root, catalog }), null, 2)
|
|
95
|
+
}
|
|
96
|
+
const name = positional[0]
|
|
97
|
+
if (!name) throw new Error(`component ${sub} needs a component name`)
|
|
98
|
+
if (sub === 'show') {
|
|
99
|
+
const report = await showComponent({ root, name, catalog })
|
|
100
|
+
if (!report) throw new Error(`unknown component: ${name}`)
|
|
101
|
+
return JSON.stringify(report, null, 2)
|
|
102
|
+
}
|
|
103
|
+
if (sub === 'describe') {
|
|
104
|
+
const text = positional.slice(1).join(' ')
|
|
105
|
+
const entry = await describeComponent({ root, name, description: text, catalog })
|
|
106
|
+
return entry?.$description ? `Described ${name} in design/components.json` : `Cleared the usage note of ${name}`
|
|
107
|
+
}
|
|
108
|
+
const common = { root, name, catalog, design: flags['--design'], reason: flags['--reason'] }
|
|
109
|
+
let args
|
|
110
|
+
if (sub === 'rename') {
|
|
111
|
+
args = { ...common, action: 'rename', to: flags['--to'] ?? positional[1] }
|
|
112
|
+
} else if (sub === 'merge') {
|
|
113
|
+
args = { ...common, action: 'merge', to: flags['--into'] ?? positional[1] }
|
|
114
|
+
} else if (sub === 'deprecate') {
|
|
115
|
+
if (!flags['--replacement'] && !flags['--no-replacement']) {
|
|
116
|
+
throw new Error('deprecate needs --replacement <Component> or an explicit --no-replacement')
|
|
117
|
+
}
|
|
118
|
+
args = {
|
|
119
|
+
...common,
|
|
120
|
+
action: 'deprecate',
|
|
121
|
+
to: flags['--no-replacement'] ? null : flags['--replacement'],
|
|
122
|
+
mode: flags['--replace-all'] ? 'replace' : 'mark',
|
|
123
|
+
}
|
|
124
|
+
} else if (sub === 'undeprecate') {
|
|
125
|
+
args = { ...common, action: 'undeprecate' }
|
|
126
|
+
} else if (sub === 'delete') {
|
|
127
|
+
args = { ...common, action: 'delete' }
|
|
128
|
+
} else {
|
|
129
|
+
args = { ...common, action: 'tidy', frames: parseFrames(flags['--frames']) }
|
|
130
|
+
}
|
|
131
|
+
if (flags['--dry-run']) {
|
|
132
|
+
return JSON.stringify(await planComponentAction(args), null, 2)
|
|
133
|
+
}
|
|
134
|
+
return describeResult(root, name, await recordComponentAction(args))
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** `propose component <Name> --frames a,b --rationale "…" [--reason "<summary>"] [--design <id>]` (tidy only). */
|
|
138
|
+
export async function proposeComponent({ root, argv }) {
|
|
139
|
+
const { positional, flags } = parse(argv)
|
|
140
|
+
const name = positional[0]
|
|
141
|
+
if (!name) throw new Error('propose component needs a component name')
|
|
142
|
+
if (!flags['--rationale']) throw new Error('propose component needs --rationale')
|
|
143
|
+
const catalog = await loadComponentCatalog(root, { configFile: flags['--config'] })
|
|
144
|
+
const { item, reviewPath } = await recordComponentAction({
|
|
145
|
+
root,
|
|
146
|
+
name,
|
|
147
|
+
catalog,
|
|
148
|
+
action: 'tidy',
|
|
149
|
+
design: flags['--design'],
|
|
150
|
+
reason: flags['--reason'],
|
|
151
|
+
frames: parseFrames(flags['--frames']),
|
|
152
|
+
author: 'agent',
|
|
153
|
+
rationale: flags['--rationale'],
|
|
154
|
+
})
|
|
155
|
+
return `Proposed tidy of ${name} (${(item.frames ?? []).join(', ')}) as ${item.id} in ${relative(root, reviewPath)}`
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/** `proposal <design> <id> approve|reject|reset [--note <text>] [--value <value>]`. */
|
|
159
|
+
export function runProposalCommand({ root, argv }) {
|
|
160
|
+
const { positional, flags } = parse(argv)
|
|
161
|
+
const [design, id, decision] = positional
|
|
162
|
+
if (!design || !id || !decision) throw new Error('proposal needs <design> <id> approve|reject|reset')
|
|
163
|
+
const { item, reviewPath } = decideProposal({ root, design, id, decision, note: flags['--note'], value: flags['--value'] })
|
|
164
|
+
return `${item.id}: ${item.proposalDecision ?? 'undecided'} in ${relative(root, reviewPath)}`
|
|
165
|
+
}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
// CLI front for `seji consolidate …` (src/tokens/consolidate).
|
|
2
|
+
import { ConsolidateError, runConsolidate } from '../tokens/consolidate/index.mjs'
|
|
3
|
+
import { TokenOpError } from '../tokens/ops.mjs'
|
|
4
|
+
import { baselineHooks, compareToolItem, toolSnapshotsRequest } from '../snapshots/toolOps.mjs'
|
|
5
|
+
|
|
6
|
+
const VALUE_FLAGS = new Map([
|
|
7
|
+
['scope', ['scope', 'list']],
|
|
8
|
+
['category', ['category', 'list']],
|
|
9
|
+
['tolerance', ['tolerance', 'value']],
|
|
10
|
+
['root-px', ['rootPx', 'value']],
|
|
11
|
+
['design', ['design', 'value']],
|
|
12
|
+
['action', ['action', 'value']],
|
|
13
|
+
['token', ['token', 'value']],
|
|
14
|
+
['name', ['name', 'value']],
|
|
15
|
+
['tier', ['tier', 'value']],
|
|
16
|
+
['description', ['description', 'value']],
|
|
17
|
+
['value', ['value', 'value']],
|
|
18
|
+
['merge', ['merge', 'list']],
|
|
19
|
+
])
|
|
20
|
+
const BOOLEAN_FLAGS = new Map([
|
|
21
|
+
['dry-run', ['dryRun', true]],
|
|
22
|
+
['force', ['force', true]],
|
|
23
|
+
['accept-visible-change', ['acceptVisibleChange', true]],
|
|
24
|
+
['reject-visible-change', ['acceptVisibleChange', false]],
|
|
25
|
+
['json', ['json', true]],
|
|
26
|
+
['snapshots', ['snapshots', true]],
|
|
27
|
+
])
|
|
28
|
+
const POSITIONALS = { show: ['plan'], set: ['plan', 'row'], apply: ['plan'], revert: ['plan'], discard: ['plan'] }
|
|
29
|
+
|
|
30
|
+
export function parseConsolidateArgs(command, argv) {
|
|
31
|
+
const args = {}
|
|
32
|
+
const positionals = []
|
|
33
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
34
|
+
const raw = argv[i]
|
|
35
|
+
if (!raw.startsWith('--') || raw === '--') {
|
|
36
|
+
positionals.push(raw)
|
|
37
|
+
continue
|
|
38
|
+
}
|
|
39
|
+
const eq = raw.indexOf('=')
|
|
40
|
+
const name = eq > 2 ? raw.slice(2, eq) : raw.slice(2)
|
|
41
|
+
if (BOOLEAN_FLAGS.has(name)) {
|
|
42
|
+
if (eq > 2) throw new Error(`--${name} takes no value`)
|
|
43
|
+
const [key, value] = BOOLEAN_FLAGS.get(name)
|
|
44
|
+
args[key] = value
|
|
45
|
+
continue
|
|
46
|
+
}
|
|
47
|
+
const flag = VALUE_FLAGS.get(name)
|
|
48
|
+
if (!flag) throw new Error(`unknown option for consolidate ${command}: --${name}`)
|
|
49
|
+
let value
|
|
50
|
+
if (eq > 2) value = raw.slice(eq + 1)
|
|
51
|
+
else {
|
|
52
|
+
value = argv[i + 1]
|
|
53
|
+
if (value === undefined) throw new Error(`--${name} requires a value`)
|
|
54
|
+
const nextName = value.startsWith('--') ? value.slice(2).split('=')[0] : null
|
|
55
|
+
// `--token --color-ink` is a value; `--token --dry-run` is a missing value.
|
|
56
|
+
if (nextName && (VALUE_FLAGS.has(nextName) || BOOLEAN_FLAGS.has(nextName))) throw new Error(`--${name} requires a value`)
|
|
57
|
+
i += 1
|
|
58
|
+
}
|
|
59
|
+
const [key, kind] = flag
|
|
60
|
+
if (kind === 'list') args[key] = [...(args[key] ?? []), value]
|
|
61
|
+
else args[key] = value
|
|
62
|
+
}
|
|
63
|
+
const names = POSITIONALS[command] ?? []
|
|
64
|
+
if (positionals.length > names.length) throw new Error(`unexpected argument: ${positionals[names.length]}`)
|
|
65
|
+
names.forEach((name, index) => {
|
|
66
|
+
if (positionals[index] !== undefined) args[name] = positionals[index]
|
|
67
|
+
})
|
|
68
|
+
return args
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const short = (value, width) => {
|
|
72
|
+
const text = String(value ?? '')
|
|
73
|
+
return text.length > width ? `${text.slice(0, width - 1)}…` : text.padEnd(width)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function describeAction(row) {
|
|
77
|
+
if (row.action === 'skip') return row.suggestion?.action === 'merge' ? `skip (suggest merge ${row.suggestion.merge.join(', ')} → ${row.suggestion.token})` : row.suggestion?.action === 'keep' ? 'keep' : 'skip'
|
|
78
|
+
if (row.action === 'undecided') {
|
|
79
|
+
const proposed = row.proposed ? describeAction(row.proposed) : row.suggestion?.action
|
|
80
|
+
return `undecided — pick with --action (tool proposes: ${proposed})`
|
|
81
|
+
}
|
|
82
|
+
if (row.action === 'reuse') return `reuse ${row.token}`
|
|
83
|
+
if (row.action === 'merge') return `merge ${row.merge?.join(', ')} → ${row.token}`
|
|
84
|
+
if (row.action === 'create') return `create ${row.name || '<name?>'} [${row.tier || 'tier?'}] = ${row.value}`
|
|
85
|
+
return row.action
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** Human-readable table of scan / plan rows. */
|
|
89
|
+
export function formatRows(result) {
|
|
90
|
+
const lines = []
|
|
91
|
+
const header = result.id ? `Plan ${result.id} (${result.status})` : 'Consolidation scan'
|
|
92
|
+
const scope = result.options?.scope?.length ? result.options.scope.join(', ') : '(project)'
|
|
93
|
+
lines.push(`${header} · scope ${scope} · ${result.options?.categories?.join(', ')}`)
|
|
94
|
+
const c = result.counts ?? {}
|
|
95
|
+
lines.push(`${c.rows ?? result.rows.length} row(s) · ${c.occurrences ?? 0} hard-coded value(s), ${c.replaceable ?? 0} replaceable by the tool, ${c.leftovers ?? 0} for the agent · ${c.tokensInUse ?? 0} token(s) in use · ${c.visibleChanges ?? 0} row(s) change rendering`)
|
|
96
|
+
lines.push('')
|
|
97
|
+
lines.push(`${short('row', 5)} ${short('category', 12)} ${short('value', 22)} ${short('found', 12)} ${short('tokens', 28)} action`)
|
|
98
|
+
for (const row of result.rows) {
|
|
99
|
+
const values = row.values.length ? row.values.map((value) => value.canonical).join(' ') : row.anchor
|
|
100
|
+
const found = row.counts.occurrences ? `${row.counts.occurrences}× (${row.counts.replaceable} tool)` : '—'
|
|
101
|
+
const tokens = row.tokens.map((entry) => entry.path).join(', ') || '—'
|
|
102
|
+
const visible = row.visibleChange?.length
|
|
103
|
+
? ` ⚠ changes rendering: ${row.visibleChange
|
|
104
|
+
.slice(0, 2)
|
|
105
|
+
.map((change) => `${change.token ? `${change.token} ` : ''}${change.from}→${change.to} ${Object.entries(change.delta).map(([key, value]) => `${key} ${value}`).join(' ')}`)
|
|
106
|
+
.join('; ')}${row.acceptVisibleChange ? ' (accepted)' : ''}`
|
|
107
|
+
: ''
|
|
108
|
+
lines.push(`${short(row.id, 5)} ${short(row.category, 12)} ${short(values, 22)} ${short(found, 12)} ${short(tokens, 28)} ${describeAction(row)}${visible}`)
|
|
109
|
+
}
|
|
110
|
+
if (result.readiness) {
|
|
111
|
+
lines.push('')
|
|
112
|
+
if (result.readiness.ready) lines.push('Ready to apply.')
|
|
113
|
+
for (const entry of result.readiness.blocked) lines.push(`Blocked ${entry.row}: ${entry.problems.join('; ')}`)
|
|
114
|
+
}
|
|
115
|
+
if (result.unclustered?.length) {
|
|
116
|
+
lines.push('')
|
|
117
|
+
lines.push(`Not clustered (computed / formula values, left for the agent): ${result.unclustered.length}`)
|
|
118
|
+
}
|
|
119
|
+
return lines.join('\n')
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** Run `seji consolidate <command> …`; prints JSON (or a table) and returns the exit code. */
|
|
123
|
+
export async function runConsolidateCli({ root, command, argv }) {
|
|
124
|
+
let args
|
|
125
|
+
try {
|
|
126
|
+
args = parseConsolidateArgs(command, argv)
|
|
127
|
+
} catch (error) {
|
|
128
|
+
console.error(`seji: ${error instanceof Error ? error.message : String(error)}`)
|
|
129
|
+
return 1
|
|
130
|
+
}
|
|
131
|
+
const { json, snapshots, ...rest } = args
|
|
132
|
+
const request = toolSnapshotsRequest({ kind: 'consolidate', op: command, snapshots, dryRun: rest.dryRun })
|
|
133
|
+
if (request.error) {
|
|
134
|
+
console.error(`seji: --${request.error.replace(/^snapshots: true\|false/, 'snapshots')}`)
|
|
135
|
+
return 1
|
|
136
|
+
}
|
|
137
|
+
try {
|
|
138
|
+
// `apply --snapshots`: render the affected screens before the write, compare after it.
|
|
139
|
+
const baseline = request.take ? baselineHooks({ root }) : null
|
|
140
|
+
const result = await runConsolidate({ root, command, args: rest, ...(baseline ? { hooks: baseline.hooks } : {}) })
|
|
141
|
+
if (baseline) result.snapshots = await compareToolItem({ root, state: baseline.state, result })
|
|
142
|
+
const table = !json && (command === 'scan' || command === 'plan' || command === 'show')
|
|
143
|
+
if (table) {
|
|
144
|
+
console.log(formatRows(result))
|
|
145
|
+
if (command === 'plan') console.log(`\nSaved ${result.file}. Edit rows with \`seji consolidate set ${result.id} <row> …\`, then \`consolidate apply ${result.id} --dry-run\`.`)
|
|
146
|
+
} else {
|
|
147
|
+
console.log(JSON.stringify(result, null, 2))
|
|
148
|
+
}
|
|
149
|
+
return result.refused ? 2 : 0
|
|
150
|
+
} catch (error) {
|
|
151
|
+
if (error instanceof ConsolidateError || error instanceof TokenOpError) {
|
|
152
|
+
console.log(JSON.stringify({ error: error.message, ...(error.details ?? {}) }, null, 2))
|
|
153
|
+
console.error(`seji: ${error.message}`)
|
|
154
|
+
return 1
|
|
155
|
+
}
|
|
156
|
+
console.error(`seji: ${error instanceof Error ? error.message : String(error)}`)
|
|
157
|
+
return 1
|
|
158
|
+
}
|
|
159
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// The one write outside design/: `@import "./tokens.generated.css";` in the app's CSS entry,
|
|
2
|
+
// after `@import "tailwindcss"` (after the other leading @imports), with the path relative to the
|
|
3
|
+
// entry. Located and inserted through the postcss syntax tree; untouched nodes keep their text.
|
|
4
|
+
import { existsSync, readFileSync, writeFileSync } from 'node:fs'
|
|
5
|
+
import { dirname, relative, resolve, sep } from 'node:path'
|
|
6
|
+
|
|
7
|
+
import postcss from 'postcss'
|
|
8
|
+
|
|
9
|
+
import { cssImports } from './appScan.mjs'
|
|
10
|
+
|
|
11
|
+
const toPosix = (file) => file.split(sep).join('/')
|
|
12
|
+
|
|
13
|
+
export const importSpecifier = (cssEntry, generatedCss) => {
|
|
14
|
+
const rel = toPosix(relative(dirname(cssEntry), generatedCss))
|
|
15
|
+
return rel.startsWith('.') ? rel : `./${rel}`
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** Does `cssEntry` import `generatedCss`? */
|
|
19
|
+
export function hasTokenImport(cssEntry, generatedCss) {
|
|
20
|
+
if (!cssEntry || !existsSync(cssEntry)) return false
|
|
21
|
+
try {
|
|
22
|
+
const root = postcss.parse(readFileSync(cssEntry, 'utf8'), { from: cssEntry })
|
|
23
|
+
return cssImports(root).some(({ target }) => /^[./]/.test(target) && resolve(dirname(cssEntry), target) === resolve(generatedCss))
|
|
24
|
+
} catch {
|
|
25
|
+
return false
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Insert the import. `{ status: 'added' | 'present' | 'skipped', file, line?, reason? }`. */
|
|
30
|
+
export function ensureTokenImport(cssEntry, generatedCss, { dryRun = false, displayRoot = dirname(cssEntry) } = {}) {
|
|
31
|
+
const file = toPosix(relative(displayRoot, cssEntry))
|
|
32
|
+
if (!/\.css$/i.test(cssEntry)) return { status: 'skipped', file, reason: `${file} is not plain CSS; add @import "${importSpecifier(cssEntry, generatedCss)}"; to it by hand` }
|
|
33
|
+
const text = readFileSync(cssEntry, 'utf8')
|
|
34
|
+
let root
|
|
35
|
+
try {
|
|
36
|
+
root = postcss.parse(text, { from: cssEntry })
|
|
37
|
+
} catch (error) {
|
|
38
|
+
return { status: 'skipped', file, reason: `${file} does not parse: ${error instanceof Error ? error.message : String(error)}` }
|
|
39
|
+
}
|
|
40
|
+
const imports = cssImports(root)
|
|
41
|
+
if (imports.some(({ target }) => /^[./]/.test(target) && resolve(dirname(cssEntry), target) === resolve(generatedCss))) return { status: 'present', file }
|
|
42
|
+
const spec = importSpecifier(cssEntry, generatedCss)
|
|
43
|
+
const node = postcss.atRule({ name: 'import', params: `"${spec}"` })
|
|
44
|
+
// Leading @charset / @import / @layer statements stay first; ours goes right after them.
|
|
45
|
+
let anchor = null
|
|
46
|
+
for (const child of root.nodes) {
|
|
47
|
+
if (child.type === 'comment') continue
|
|
48
|
+
if (child.type === 'atrule' && (child.name === 'import' || child.name === 'charset' || (child.name === 'layer' && !child.nodes))) {
|
|
49
|
+
anchor = child
|
|
50
|
+
continue
|
|
51
|
+
}
|
|
52
|
+
break
|
|
53
|
+
}
|
|
54
|
+
if (anchor) {
|
|
55
|
+
node.raws.before = '\n'
|
|
56
|
+
anchor.after(node)
|
|
57
|
+
} else {
|
|
58
|
+
const first = root.first
|
|
59
|
+
root.prepend(node)
|
|
60
|
+
node.raws.before = ''
|
|
61
|
+
if (first) first.raws.before = '\n\n'
|
|
62
|
+
}
|
|
63
|
+
if (node === root.last) root.raws.semicolon = true
|
|
64
|
+
const output = root.toString()
|
|
65
|
+
if (!dryRun) writeFileSync(cssEntry, output)
|
|
66
|
+
const line = output.slice(0, output.indexOf(`@import "${spec}"`)).split('\n').length
|
|
67
|
+
return { status: 'added', file, line, spec }
|
|
68
|
+
}
|