@fluixi-css/core 0.1.0-next.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/LICENSE +21 -0
- package/README.md +52 -0
- package/base.css +4 -0
- package/components.css +1 -0
- package/dist/base.css +4 -0
- package/dist/components.css +1 -0
- package/dist/index.css +2 -0
- package/dist/package.json +139 -0
- package/dist/reset.css +168 -0
- package/dist/src/ast.d.ts +298 -0
- package/dist/src/ast.js +2240 -0
- package/dist/src/ast.js.map +1 -0
- package/dist/src/commons/constants.d.ts +1193 -0
- package/dist/src/commons/constants.js +1323 -0
- package/dist/src/commons/constants.js.map +1 -0
- package/dist/src/commons/helper.d.ts +1298 -0
- package/dist/src/commons/helper.js +1310 -0
- package/dist/src/commons/helper.js.map +1 -0
- package/dist/src/commons/index.d.ts +3 -0
- package/dist/src/commons/index.js +4 -0
- package/dist/src/commons/index.js.map +1 -0
- package/dist/src/commons/properties.d.ts +1431 -0
- package/dist/src/commons/properties.js +2855 -0
- package/dist/src/commons/properties.js.map +1 -0
- package/dist/src/commons/types.d.ts +359 -0
- package/dist/src/commons/types.js +4 -0
- package/dist/src/commons/types.js.map +1 -0
- package/dist/src/components/avatar/index.d.ts +19 -0
- package/dist/src/components/avatar/index.js +22 -0
- package/dist/src/components/avatar/index.js.map +1 -0
- package/dist/src/components/button/index.d.ts +48 -0
- package/dist/src/components/button/index.js +51 -0
- package/dist/src/components/button/index.js.map +1 -0
- package/dist/src/components/card/index.d.ts +44 -0
- package/dist/src/components/card/index.js +47 -0
- package/dist/src/components/card/index.js.map +1 -0
- package/dist/src/components/checkbox/index.d.ts +69 -0
- package/dist/src/components/checkbox/index.js +80 -0
- package/dist/src/components/checkbox/index.js.map +1 -0
- package/dist/src/components/daterangepicker/index.d.ts +147 -0
- package/dist/src/components/daterangepicker/index.js +150 -0
- package/dist/src/components/daterangepicker/index.js.map +1 -0
- package/dist/src/components/dialog/index.d.ts +71 -0
- package/dist/src/components/dialog/index.js +74 -0
- package/dist/src/components/dialog/index.js.map +1 -0
- package/dist/src/components/drawer/index.d.ts +26 -0
- package/dist/src/components/drawer/index.js +29 -0
- package/dist/src/components/drawer/index.js.map +1 -0
- package/dist/src/components/dropdown/index.d.ts +101 -0
- package/dist/src/components/dropdown/index.js +104 -0
- package/dist/src/components/dropdown/index.js.map +1 -0
- package/dist/src/components/forms/index.d.ts +58 -0
- package/dist/src/components/forms/index.js +62 -0
- package/dist/src/components/forms/index.js.map +1 -0
- package/dist/src/components/index.d.ts +1228 -0
- package/dist/src/components/index.js +64 -0
- package/dist/src/components/index.js.map +1 -0
- package/dist/src/components/layout/index.d.ts +28 -0
- package/dist/src/components/layout/index.js +33 -0
- package/dist/src/components/layout/index.js.map +1 -0
- package/dist/src/components/list/index.d.ts +65 -0
- package/dist/src/components/list/index.js +68 -0
- package/dist/src/components/list/index.js.map +1 -0
- package/dist/src/components/popover/index.d.ts +79 -0
- package/dist/src/components/popover/index.js +82 -0
- package/dist/src/components/popover/index.js.map +1 -0
- package/dist/src/components/radio/index.d.ts +77 -0
- package/dist/src/components/radio/index.js +80 -0
- package/dist/src/components/radio/index.js.map +1 -0
- package/dist/src/components/select/index.d.ts +102 -0
- package/dist/src/components/select/index.js +105 -0
- package/dist/src/components/select/index.js.map +1 -0
- package/dist/src/components/sidenav/index.d.ts +98 -0
- package/dist/src/components/sidenav/index.js +101 -0
- package/dist/src/components/sidenav/index.js.map +1 -0
- package/dist/src/components/table/index.d.ts +95 -0
- package/dist/src/components/table/index.js +98 -0
- package/dist/src/components/table/index.js.map +1 -0
- package/dist/src/constants.d.ts +3 -0
- package/dist/src/constants.js +29 -0
- package/dist/src/constants.js.map +1 -0
- package/dist/src/css-ast.d.ts +48 -0
- package/dist/src/css-ast.js +2 -0
- package/dist/src/css-ast.js.map +1 -0
- package/dist/src/css-generator.d.ts +29 -0
- package/dist/src/css-generator.js +104 -0
- package/dist/src/css-generator.js.map +1 -0
- package/dist/src/css-helpers.d.ts +76 -0
- package/dist/src/css-helpers.js +272 -0
- package/dist/src/css-helpers.js.map +1 -0
- package/dist/src/css-lexer.d.ts +48 -0
- package/dist/src/css-lexer.js +255 -0
- package/dist/src/css-lexer.js.map +1 -0
- package/dist/src/css-parser.cjs +2047 -0
- package/dist/src/css-parser.cjs.map +1 -0
- package/dist/src/css-parser.d.ts +100 -0
- package/dist/src/css-parser.js +1098 -0
- package/dist/src/css-parser.js.map +1 -0
- package/dist/src/css-parser.mjs +2028 -0
- package/dist/src/css-parser.mjs.map +1 -0
- package/dist/src/design-system.d.ts +210 -0
- package/dist/src/design-system.js +1034 -0
- package/dist/src/design-system.js.map +1 -0
- package/dist/src/engine/ast.d.ts +44 -0
- package/dist/src/engine/ast.js +92 -0
- package/dist/src/engine/ast.js.map +1 -0
- package/dist/src/engine/atom.d.ts +74 -0
- package/dist/src/engine/atom.js +227 -0
- package/dist/src/engine/atom.js.map +1 -0
- package/dist/src/engine/compile.d.ts +5 -0
- package/dist/src/engine/compile.js +79 -0
- package/dist/src/engine/compile.js.map +1 -0
- package/dist/src/engine/defaults.d.ts +2 -0
- package/dist/src/engine/defaults.js +14 -0
- package/dist/src/engine/defaults.js.map +1 -0
- package/dist/src/engine/directives.d.ts +2 -0
- package/dist/src/engine/directives.js +191 -0
- package/dist/src/engine/directives.js.map +1 -0
- package/dist/src/engine/index.d.ts +41 -0
- package/dist/src/engine/index.js +88 -0
- package/dist/src/engine/index.js.map +1 -0
- package/dist/src/engine/registry.d.ts +46 -0
- package/dist/src/engine/registry.js +49 -0
- package/dist/src/engine/registry.js.map +1 -0
- package/dist/src/engine/scanner.d.ts +1 -0
- package/dist/src/engine/scanner.js +45 -0
- package/dist/src/engine/scanner.js.map +1 -0
- package/dist/src/engine/source.d.ts +12 -0
- package/dist/src/engine/source.js +81 -0
- package/dist/src/engine/source.js.map +1 -0
- package/dist/src/engine/theme-defaults.d.ts +2 -0
- package/dist/src/engine/theme-defaults.js +54 -0
- package/dist/src/engine/theme-defaults.js.map +1 -0
- package/dist/src/engine/theme-source.d.ts +5 -0
- package/dist/src/engine/theme-source.js +71 -0
- package/dist/src/engine/theme-source.js.map +1 -0
- package/dist/src/engine/theme.d.ts +10 -0
- package/dist/src/engine/theme.js +42 -0
- package/dist/src/engine/theme.js.map +1 -0
- package/dist/src/engine/transform.d.ts +25 -0
- package/dist/src/engine/transform.js +91 -0
- package/dist/src/engine/transform.js.map +1 -0
- package/dist/src/engine/ui-preset.d.ts +4 -0
- package/dist/src/engine/ui-preset.js +56 -0
- package/dist/src/engine/ui-preset.js.map +1 -0
- package/dist/src/engine/utilities/backgrounds.d.ts +2 -0
- package/dist/src/engine/utilities/backgrounds.js +32 -0
- package/dist/src/engine/utilities/backgrounds.js.map +1 -0
- package/dist/src/engine/utilities/borders.d.ts +2 -0
- package/dist/src/engine/utilities/borders.js +95 -0
- package/dist/src/engine/utilities/borders.js.map +1 -0
- package/dist/src/engine/utilities/effects.d.ts +2 -0
- package/dist/src/engine/utilities/effects.js +61 -0
- package/dist/src/engine/utilities/effects.js.map +1 -0
- package/dist/src/engine/utilities/flexgrid.d.ts +2 -0
- package/dist/src/engine/utilities/flexgrid.js +125 -0
- package/dist/src/engine/utilities/flexgrid.js.map +1 -0
- package/dist/src/engine/utilities/index.d.ts +3 -0
- package/dist/src/engine/utilities/index.js +20 -0
- package/dist/src/engine/utilities/index.js.map +1 -0
- package/dist/src/engine/utilities/layout.d.ts +2 -0
- package/dist/src/engine/utilities/layout.js +84 -0
- package/dist/src/engine/utilities/layout.js.map +1 -0
- package/dist/src/engine/utilities/sizing.d.ts +2 -0
- package/dist/src/engine/utilities/sizing.js +21 -0
- package/dist/src/engine/utilities/sizing.js.map +1 -0
- package/dist/src/engine/utilities/spacing.d.ts +2 -0
- package/dist/src/engine/utilities/spacing.js +39 -0
- package/dist/src/engine/utilities/spacing.js.map +1 -0
- package/dist/src/engine/utilities/typography.d.ts +2 -0
- package/dist/src/engine/utilities/typography.js +120 -0
- package/dist/src/engine/utilities/typography.js.map +1 -0
- package/dist/src/engine/utilities/values.d.ts +16 -0
- package/dist/src/engine/utilities/values.js +91 -0
- package/dist/src/engine/utilities/values.js.map +1 -0
- package/dist/src/engine/variants.d.ts +2 -0
- package/dist/src/engine/variants.js +99 -0
- package/dist/src/engine/variants.js.map +1 -0
- package/dist/src/extractor.d.ts +146 -0
- package/dist/src/extractor.js +3862 -0
- package/dist/src/extractor.js.map +1 -0
- package/dist/src/index.cjs +4518 -0
- package/dist/src/index.cjs.map +1 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +9 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/index.mjs +4480 -0
- package/dist/src/index.mjs.map +1 -0
- package/dist/src/keyframes.cjs +367 -0
- package/dist/src/keyframes.cjs.map +1 -0
- package/dist/src/keyframes.d.ts +27 -0
- package/dist/src/keyframes.js +188 -0
- package/dist/src/keyframes.js.map +1 -0
- package/dist/src/keyframes.mjs +362 -0
- package/dist/src/keyframes.mjs.map +1 -0
- package/dist/src/logger.d.ts +2 -0
- package/dist/src/logger.js +31 -0
- package/dist/src/logger.js.map +1 -0
- package/dist/src/plugin.cjs +43 -0
- package/dist/src/plugin.cjs.map +1 -0
- package/dist/src/plugin.d.ts +12 -0
- package/dist/src/plugin.js +39 -0
- package/dist/src/plugin.js.map +1 -0
- package/dist/src/plugin.mjs +41 -0
- package/dist/src/plugin.mjs.map +1 -0
- package/dist/src/presets-plugins.cjs +99 -0
- package/dist/src/presets-plugins.cjs.map +1 -0
- package/dist/src/presets-plugins.d.ts +1 -0
- package/dist/src/presets-plugins.js +56 -0
- package/dist/src/presets-plugins.js.map +1 -0
- package/dist/src/presets-plugins.mjs +97 -0
- package/dist/src/presets-plugins.mjs.map +1 -0
- package/dist/src/state.d.ts +76 -0
- package/dist/src/state.js +314 -0
- package/dist/src/state.js.map +1 -0
- package/dist/src/theme/constants.d.ts +22 -0
- package/dist/src/theme/constants.js +17 -0
- package/dist/src/theme/constants.js.map +1 -0
- package/dist/src/theme/index.d.ts +2 -0
- package/dist/src/theme/index.js +48 -0
- package/dist/src/theme/index.js.map +1 -0
- package/dist/src/theme/types.d.ts +13 -0
- package/dist/src/theme/types.js +2 -0
- package/dist/src/theme/types.js.map +1 -0
- package/dist/src/types/ast.d.ts +23 -0
- package/dist/src/types/ast.js +2 -0
- package/dist/src/types/ast.js.map +1 -0
- package/dist/src/types/base-types.d.ts +53 -0
- package/dist/src/types/base-types.js +2 -0
- package/dist/src/types/base-types.js.map +1 -0
- package/dist/src/types/components-types.d.ts +28 -0
- package/dist/src/types/components-types.js +2 -0
- package/dist/src/types/components-types.js.map +1 -0
- package/dist/src/types/config.d.ts +90 -0
- package/dist/src/types/config.js +3 -0
- package/dist/src/types/config.js.map +1 -0
- package/dist/src/types/css-parser.d.ts +361 -0
- package/dist/src/types/css-parser.js +2 -0
- package/dist/src/types/css-parser.js.map +1 -0
- package/dist/src/types/keyframes-type.d.ts +47 -0
- package/dist/src/types/keyframes-type.js +2 -0
- package/dist/src/types/keyframes-type.js.map +1 -0
- package/dist/src/types/plugin.d.ts +10 -0
- package/dist/src/types/plugin.js +2 -0
- package/dist/src/types/plugin.js.map +1 -0
- package/dist/src/types/screens-types.d.ts +47 -0
- package/dist/src/types/screens-types.js +2 -0
- package/dist/src/types/screens-types.js.map +1 -0
- package/dist/src/types/utilities-types.d.ts +147 -0
- package/dist/src/types/utilities-types.js +2 -0
- package/dist/src/types/utilities-types.js.map +1 -0
- package/dist/src/types.d.ts +77 -0
- package/dist/src/types.js +12 -0
- package/dist/src/types.js.map +1 -0
- package/dist/src/units/constants.d.ts +35 -0
- package/dist/src/units/constants.js +9 -0
- package/dist/src/units/constants.js.map +1 -0
- package/dist/src/units/index.d.ts +15 -0
- package/dist/src/units/index.js +7 -0
- package/dist/src/units/index.js.map +1 -0
- package/dist/src/units/types.d.ts +9 -0
- package/dist/src/units/types.js +2 -0
- package/dist/src/units/types.js.map +1 -0
- package/dist/src/utilities/backgrounds/constants.d.ts +2810 -0
- package/dist/src/utilities/backgrounds/constants.js +119 -0
- package/dist/src/utilities/backgrounds/constants.js.map +1 -0
- package/dist/src/utilities/backgrounds/index.d.ts +1 -0
- package/dist/src/utilities/backgrounds/index.js +2 -0
- package/dist/src/utilities/backgrounds/index.js.map +1 -0
- package/dist/src/utilities/borders/constants.d.ts +10586 -0
- package/dist/src/utilities/borders/constants.js +309 -0
- package/dist/src/utilities/borders/constants.js.map +1 -0
- package/dist/src/utilities/borders/index.d.ts +1 -0
- package/dist/src/utilities/borders/index.js +2 -0
- package/dist/src/utilities/borders/index.js.map +1 -0
- package/dist/src/utilities/breakpoints/constants.d.ts +330 -0
- package/dist/src/utilities/breakpoints/constants.js +269 -0
- package/dist/src/utilities/breakpoints/constants.js.map +1 -0
- package/dist/src/utilities/breakpoints/index.d.ts +2 -0
- package/dist/src/utilities/breakpoints/index.js +3 -0
- package/dist/src/utilities/breakpoints/index.js.map +1 -0
- package/dist/src/utilities/breakpoints/types.d.ts +8 -0
- package/dist/src/utilities/breakpoints/types.js +2 -0
- package/dist/src/utilities/breakpoints/types.js.map +1 -0
- package/dist/src/utilities/colors/base.d.ts +778 -0
- package/dist/src/utilities/colors/base.js +872 -0
- package/dist/src/utilities/colors/base.js.map +1 -0
- package/dist/src/utilities/colors/color.d.ts +1122 -0
- package/dist/src/utilities/colors/color.js +957 -0
- package/dist/src/utilities/colors/color.js.map +1 -0
- package/dist/src/utilities/colors/constants.d.ts +1 -0
- package/dist/src/utilities/colors/constants.js +2 -0
- package/dist/src/utilities/colors/constants.js.map +1 -0
- package/dist/src/utilities/colors/index.d.ts +4 -0
- package/dist/src/utilities/colors/index.js +29 -0
- package/dist/src/utilities/colors/index.js.map +1 -0
- package/dist/src/utilities/colors/types.d.ts +3 -0
- package/dist/src/utilities/colors/types.js +2 -0
- package/dist/src/utilities/colors/types.js.map +1 -0
- package/dist/src/utilities/effects/constants.d.ts +641 -0
- package/dist/src/utilities/effects/constants.js +83 -0
- package/dist/src/utilities/effects/constants.js.map +1 -0
- package/dist/src/utilities/effects/index.d.ts +1 -0
- package/dist/src/utilities/effects/index.js +2 -0
- package/dist/src/utilities/effects/index.js.map +1 -0
- package/dist/src/utilities/filters/constants.d.ts +406 -0
- package/dist/src/utilities/filters/constants.js +206 -0
- package/dist/src/utilities/filters/constants.js.map +1 -0
- package/dist/src/utilities/filters/index.d.ts +1 -0
- package/dist/src/utilities/filters/index.js +2 -0
- package/dist/src/utilities/filters/index.js.map +1 -0
- package/dist/src/utilities/flex/constants.d.ts +934 -0
- package/dist/src/utilities/flex/constants.js +221 -0
- package/dist/src/utilities/flex/constants.js.map +1 -0
- package/dist/src/utilities/flex/index.d.ts +1 -0
- package/dist/src/utilities/flex/index.js +2 -0
- package/dist/src/utilities/flex/index.js.map +1 -0
- package/dist/src/utilities/flex/types.d.ts +0 -0
- package/dist/src/utilities/flex/types.js +4 -0
- package/dist/src/utilities/flex/types.js.map +1 -0
- package/dist/src/utilities/index.d.ts +31338 -0
- package/dist/src/utilities/index.js +333 -0
- package/dist/src/utilities/index.js.map +1 -0
- package/dist/src/utilities/interactivity/constants.d.ts +1244 -0
- package/dist/src/utilities/interactivity/constants.js +165 -0
- package/dist/src/utilities/interactivity/constants.js.map +1 -0
- package/dist/src/utilities/interactivity/index.d.ts +1 -0
- package/dist/src/utilities/interactivity/index.js +2 -0
- package/dist/src/utilities/interactivity/index.js.map +1 -0
- package/dist/src/utilities/layout/constants.d.ts +837 -0
- package/dist/src/utilities/layout/constants.js +159 -0
- package/dist/src/utilities/layout/constants.js.map +1 -0
- package/dist/src/utilities/layout/index.d.ts +1 -0
- package/dist/src/utilities/layout/index.js +2 -0
- package/dist/src/utilities/layout/index.js.map +1 -0
- package/dist/src/utilities/layout/types.d.ts +0 -0
- package/dist/src/utilities/layout/types.js +2 -0
- package/dist/src/utilities/layout/types.js.map +1 -0
- package/dist/src/utilities/sizing/constants.d.ts +989 -0
- package/dist/src/utilities/sizing/constants.js +53 -0
- package/dist/src/utilities/sizing/constants.js.map +1 -0
- package/dist/src/utilities/sizing/index.d.ts +2 -0
- package/dist/src/utilities/sizing/index.js +3 -0
- package/dist/src/utilities/sizing/index.js.map +1 -0
- package/dist/src/utilities/sizing/types.d.ts +10 -0
- package/dist/src/utilities/sizing/types.js +2 -0
- package/dist/src/utilities/sizing/types.js.map +1 -0
- package/dist/src/utilities/spacing/constants.d.ts +1779 -0
- package/dist/src/utilities/spacing/constants.js +142 -0
- package/dist/src/utilities/spacing/constants.js.map +1 -0
- package/dist/src/utilities/spacing/index.d.ts +2 -0
- package/dist/src/utilities/spacing/index.js +3 -0
- package/dist/src/utilities/spacing/index.js.map +1 -0
- package/dist/src/utilities/spacing/types.d.ts +15 -0
- package/dist/src/utilities/spacing/types.js +8 -0
- package/dist/src/utilities/spacing/types.js.map +1 -0
- package/dist/src/utilities/svg/constants.d.ts +1062 -0
- package/dist/src/utilities/svg/constants.js +34 -0
- package/dist/src/utilities/svg/constants.js.map +1 -0
- package/dist/src/utilities/transforms/constants.d.ts +247 -0
- package/dist/src/utilities/transforms/constants.js +74 -0
- package/dist/src/utilities/transforms/constants.js.map +1 -0
- package/dist/src/utilities/transforms/index.d.ts +1 -0
- package/dist/src/utilities/transforms/index.js +2 -0
- package/dist/src/utilities/transforms/index.js.map +1 -0
- package/dist/src/utilities/transitions/constants.d.ts +116 -0
- package/dist/src/utilities/transitions/constants.js +91 -0
- package/dist/src/utilities/transitions/constants.js.map +1 -0
- package/dist/src/utilities/transitions/index.d.ts +1 -0
- package/dist/src/utilities/transitions/index.js +2 -0
- package/dist/src/utilities/transitions/index.js.map +1 -0
- package/dist/src/utilities/typography/constants.d.ts +2401 -0
- package/dist/src/utilities/typography/constants.js +401 -0
- package/dist/src/utilities/typography/constants.js.map +1 -0
- package/dist/src/utilities/typography/index.d.ts +1 -0
- package/dist/src/utilities/typography/index.js +2 -0
- package/dist/src/utilities/typography/index.js.map +1 -0
- package/dist/src/utils.d.ts +18 -0
- package/dist/src/utils.js +282 -0
- package/dist/src/utils.js.map +1 -0
- package/dist/src/watcher.d.ts +15 -0
- package/dist/src/watcher.js +62 -0
- package/dist/src/watcher.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/utilities.css +1 -0
- package/index.css +2 -0
- package/package.json +139 -0
- package/reset.css +168 -0
- package/utilities.css +1 -0
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
import { __awaiter } from "tslib";
|
|
2
|
+
import { createRequire } from "module";
|
|
3
|
+
import { pathToFileURL } from "url";
|
|
4
|
+
import { dirname, isAbsolute, join, normalize, relative, resolve, sep } from "path";
|
|
5
|
+
import { readFileSync } from "fs";
|
|
6
|
+
import { splitString } from "./commons/helper";
|
|
7
|
+
const require = createRequire(import.meta.url);
|
|
8
|
+
export function detectImportType(content, path) {
|
|
9
|
+
try {
|
|
10
|
+
// const pkg = readPkg(path);
|
|
11
|
+
// if(pkg){
|
|
12
|
+
// return pkg
|
|
13
|
+
// }
|
|
14
|
+
// Quick check for obvious CommonJS patterns
|
|
15
|
+
const commonJsPatterns = [
|
|
16
|
+
'module.exports',
|
|
17
|
+
'exports.',
|
|
18
|
+
'require(',
|
|
19
|
+
'global.',
|
|
20
|
+
'__dirname',
|
|
21
|
+
'__filename'
|
|
22
|
+
];
|
|
23
|
+
if (commonJsPatterns.some(pattern => content.includes(pattern))) {
|
|
24
|
+
return 'require';
|
|
25
|
+
}
|
|
26
|
+
// Check for ES Module syntax
|
|
27
|
+
const esModulePatterns = [
|
|
28
|
+
/\bimport\s+[^'"]*['"][^'"]+['"]/, // import statements
|
|
29
|
+
/\bexport\s+(?:default|const|let|var|function|class|interface|type)\b/, // export declarations
|
|
30
|
+
/\bexport\s*{[^}]*}/, // export lists
|
|
31
|
+
/\bexport\s*\*\s*from/ // re-exports
|
|
32
|
+
];
|
|
33
|
+
if (esModulePatterns.some(pattern => pattern.test(content))) {
|
|
34
|
+
return 'import';
|
|
35
|
+
}
|
|
36
|
+
const ext = path.toLowerCase();
|
|
37
|
+
if (ext.endsWith('.mjs'))
|
|
38
|
+
return 'import';
|
|
39
|
+
if (ext.endsWith('.cjs'))
|
|
40
|
+
return 'require';
|
|
41
|
+
// Default to require for unknown cases
|
|
42
|
+
return 'require';
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
return 'require';
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
export function detectModuleType(path) {
|
|
49
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
50
|
+
try {
|
|
51
|
+
const packagePath = path.split("/").slice(0, -1).join("/") + "/package.json";
|
|
52
|
+
const packageJson = JSON.parse(readFileSync(packagePath, "utf8"));
|
|
53
|
+
return packageJson.type === "module" ? "module" : "commonjs";
|
|
54
|
+
}
|
|
55
|
+
catch (_a) {
|
|
56
|
+
return "commonjs";
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
export function loadTypeScriptFile(content, filename) {
|
|
61
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
62
|
+
// Simple TypeScript transpilation
|
|
63
|
+
try {
|
|
64
|
+
const type = detectImportType(content, filename);
|
|
65
|
+
let ts;
|
|
66
|
+
if (type === 'import') {
|
|
67
|
+
ts = yield import('typescript');
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
ts = require('typescript');
|
|
71
|
+
}
|
|
72
|
+
const result = ts.transpileModule(content, {
|
|
73
|
+
compilerOptions: {
|
|
74
|
+
module: ts.ModuleKind.CommonJS,
|
|
75
|
+
target: ts.ScriptTarget.ES2018,
|
|
76
|
+
},
|
|
77
|
+
fileName: filename
|
|
78
|
+
});
|
|
79
|
+
// Evaluate the code directly
|
|
80
|
+
const moduleExports = {};
|
|
81
|
+
const moduleFn = new Function('exports', 'require', 'module', '__filename', '__dirname', result.outputText);
|
|
82
|
+
const moduleObj = { exports: moduleExports };
|
|
83
|
+
moduleFn(moduleExports, require, moduleObj, filename, dirname(filename));
|
|
84
|
+
// console.log('moduleObj', moduleObj.exports)
|
|
85
|
+
return moduleObj.exports.default || moduleObj.exports;
|
|
86
|
+
}
|
|
87
|
+
catch (e) {
|
|
88
|
+
console.error('error while importing ts file config', e);
|
|
89
|
+
// throw e
|
|
90
|
+
}
|
|
91
|
+
return null;
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
export function filePathToUrl(path) {
|
|
95
|
+
try {
|
|
96
|
+
// Ensure the path is absolute and normalized
|
|
97
|
+
const absolutePath = require.resolve(path);
|
|
98
|
+
// Convert to URL format, handling Windows paths correctly
|
|
99
|
+
const url = pathToFileURL(absolutePath).href;
|
|
100
|
+
return url;
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
// Fallback to direct path conversion if resolve fails
|
|
104
|
+
return pathToFileURL(normalize(path)).href;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
export function findPackageJson(path) {
|
|
108
|
+
try {
|
|
109
|
+
// Normalize path separators for the current OS
|
|
110
|
+
const normalizedPath = normalize(path);
|
|
111
|
+
const parts = normalizedPath.split(sep);
|
|
112
|
+
// Search up the directory tree for package.json
|
|
113
|
+
while (parts.length > 0) {
|
|
114
|
+
const packagePath = [...parts, 'package.json'].join(sep);
|
|
115
|
+
try {
|
|
116
|
+
const content = JSON.parse(readFileSync(packagePath, 'utf8'));
|
|
117
|
+
return { path: packagePath, content };
|
|
118
|
+
}
|
|
119
|
+
catch (_a) {
|
|
120
|
+
parts.pop();
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
125
|
+
catch (_b) {
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
export function importWithFallbacks(path, logger) {
|
|
130
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
131
|
+
const normalizedPath = path;
|
|
132
|
+
const _importType = path.endsWith('.cjs') ? 'require' : path.endsWith('.mjs') ? 'import' : detectImportType(readFileSync(normalizedPath, 'utf8'), normalizedPath);
|
|
133
|
+
const type = yield detectModuleType(normalizedPath);
|
|
134
|
+
// const type = _importType === 'import' ? "module" : "commonjs";
|
|
135
|
+
// if(type === "commonjs"){
|
|
136
|
+
// try{
|
|
137
|
+
// const resolvedPath = require.resolve(normalizedPath);
|
|
138
|
+
const strategies = [
|
|
139
|
+
// Strategy 1: Direct require
|
|
140
|
+
() => __awaiter(this, void 0, void 0, function* () {
|
|
141
|
+
const importType = path.endsWith('.cjs') ? 'require' : _importType;
|
|
142
|
+
if (importType === 'require' && type !== "module") {
|
|
143
|
+
const resolvedPath = require.resolve(normalizedPath);
|
|
144
|
+
const mod = require(resolvedPath);
|
|
145
|
+
// console.log('Successfully loaded config with require')
|
|
146
|
+
return { value: mod.default || mod, path: resolvedPath };
|
|
147
|
+
}
|
|
148
|
+
else if (importType === "import") {
|
|
149
|
+
const fileUrl = filePathToUrl(normalizedPath);
|
|
150
|
+
const mod = yield import(fileUrl);
|
|
151
|
+
// console.log('Successfully loaded config with import')
|
|
152
|
+
return { value: mod.default || mod, path: normalizedPath };
|
|
153
|
+
}
|
|
154
|
+
return null;
|
|
155
|
+
}),
|
|
156
|
+
() => __awaiter(this, void 0, void 0, function* () {
|
|
157
|
+
if (type === 'module' && _importType === "import") {
|
|
158
|
+
const fileUrl = filePathToUrl(normalizedPath);
|
|
159
|
+
logger === null || logger === void 0 ? void 0 : logger.debug("Dynamic import with file URL:", fileUrl);
|
|
160
|
+
const mod = yield import(fileUrl);
|
|
161
|
+
// console.log('Successfully loaded config with import file url')
|
|
162
|
+
return { value: mod.default || mod, path: normalizedPath };
|
|
163
|
+
}
|
|
164
|
+
else if (type === 'module' && _importType === "require") {
|
|
165
|
+
const content = readFileSync(normalizedPath, 'utf8');
|
|
166
|
+
const moduleExports = {};
|
|
167
|
+
const moduleFn = new Function('exports', 'require', 'module', '__filename', '__dirname', content);
|
|
168
|
+
const moduleObj = { exports: moduleExports };
|
|
169
|
+
moduleFn(moduleExports, require, moduleObj, path, dirname(path));
|
|
170
|
+
return { value: moduleObj.exports.default || moduleObj.exports, path: normalizedPath };
|
|
171
|
+
}
|
|
172
|
+
return null;
|
|
173
|
+
}),
|
|
174
|
+
];
|
|
175
|
+
let lastError;
|
|
176
|
+
for (const strategy of strategies) {
|
|
177
|
+
try {
|
|
178
|
+
const result = yield strategy();
|
|
179
|
+
if (result) {
|
|
180
|
+
return result;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
catch (error) {
|
|
184
|
+
lastError = error;
|
|
185
|
+
if (!logger) {
|
|
186
|
+
console.log('Import strategy failed:', error.message);
|
|
187
|
+
}
|
|
188
|
+
logger === null || logger === void 0 ? void 0 : logger.debug("Import strategy failed:", error.message);
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
if (lastError) {
|
|
193
|
+
throw lastError;
|
|
194
|
+
}
|
|
195
|
+
return null;
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
export function normalizeFilePath(path) {
|
|
199
|
+
// Normalize path separators and handle Windows paths
|
|
200
|
+
const normalized = normalize(path).replace(/\\/g, '/');
|
|
201
|
+
return normalized;
|
|
202
|
+
}
|
|
203
|
+
export const getAbsPath = (relativeFilePath, directory = __dirname) => {
|
|
204
|
+
try {
|
|
205
|
+
if (isAbsolute(relativeFilePath)) {
|
|
206
|
+
return relativeFilePath;
|
|
207
|
+
}
|
|
208
|
+
return join(directory, relativeFilePath);
|
|
209
|
+
}
|
|
210
|
+
catch (e) {
|
|
211
|
+
return null;
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
export const getRelativePath = (dir1, dir2 = __dirname) => {
|
|
215
|
+
try {
|
|
216
|
+
return relative(dir1, dir2);
|
|
217
|
+
}
|
|
218
|
+
catch (e) {
|
|
219
|
+
return null;
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
export const getFilePath = (filename) => {
|
|
223
|
+
if (typeof filename === "string" && filename.length > 0) {
|
|
224
|
+
try {
|
|
225
|
+
return resolve(filename);
|
|
226
|
+
}
|
|
227
|
+
catch (_a) {
|
|
228
|
+
return "";
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
return '';
|
|
232
|
+
};
|
|
233
|
+
export const matchLiteralString = (content) => {
|
|
234
|
+
const first = matchLiteralStringA(content);
|
|
235
|
+
// Match both regular string literals and template literals with expressions
|
|
236
|
+
// const templateLiteralRegex = /(?<=`|'|"|\$\{)(?:(?!\$\{|`|'|").)*?(?=`|'|"|\$\{)/g;
|
|
237
|
+
const templateLiteralRegex = /(['"`])((?:\\.|(?!\1)(?!\$\{)[\s\S]|\$\{[^}]*\})*)\1/g;
|
|
238
|
+
// const templateLiteralRegex = /`?([^$`]+)(?=\$\{)|'([^']*)'|"([^"]*)"/g;
|
|
239
|
+
const matches = content.match(templateLiteralRegex);
|
|
240
|
+
if (matches) {
|
|
241
|
+
// Process each match to extract the actual class names
|
|
242
|
+
return matches.map(match => {
|
|
243
|
+
// For template literals with expressions, we need to:
|
|
244
|
+
// 1. Replace ${...} expressions with a space to preserve class separation
|
|
245
|
+
// 2. Remove the backticks/quotes
|
|
246
|
+
// if(match.includes('w-full${')){
|
|
247
|
+
// console.log('match inclueds', match)
|
|
248
|
+
// }
|
|
249
|
+
if (match.includes('bg-emerald')) {
|
|
250
|
+
console.log('match', match);
|
|
251
|
+
}
|
|
252
|
+
return match
|
|
253
|
+
.replace(/\${[^}]*}/g, ' ')
|
|
254
|
+
.replace(/^[`'"]/g, '')
|
|
255
|
+
.replace(/[`'"]$/g, '')
|
|
256
|
+
.trim();
|
|
257
|
+
}).flatMap(s => splitString(s));
|
|
258
|
+
}
|
|
259
|
+
return [];
|
|
260
|
+
};
|
|
261
|
+
export const matchLiteralStringA = (content) => {
|
|
262
|
+
// Match both full strings and nested strings
|
|
263
|
+
const regex = /(['"`])((?:(?!\1|\\).|\\.)*)\1|\[(.*?)(['"`])((?:(?!\4|\\).|\\.)*)\4(.*?)\]/g;
|
|
264
|
+
const matches = [];
|
|
265
|
+
let match;
|
|
266
|
+
while ((match = regex.exec(content)) !== null) {
|
|
267
|
+
if (match[2]) {
|
|
268
|
+
// Full string match
|
|
269
|
+
matches.push(match[2]);
|
|
270
|
+
}
|
|
271
|
+
else if (match[3] && match[5]) {
|
|
272
|
+
// Nested string match (e.g., within square brackets)
|
|
273
|
+
matches.push(match[0].slice(1, -1)); // Full attribute selector
|
|
274
|
+
matches.push(match[5]); // Inner quoted string
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
if (matches.some(m => m.includes('bg-emerald'))) {
|
|
278
|
+
console.log('matches', matches);
|
|
279
|
+
}
|
|
280
|
+
return matches.flatMap(s => splitString(s));
|
|
281
|
+
};
|
|
282
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AACpC,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAC,MAAM,MAAM,CAAC;AACnF,OAAO,EAAE,YAAY,EAAE,MAAM,IAAI,CAAC;AAClC,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAG/C,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAE/C,MAAM,UAAU,gBAAgB,CAAC,OAAe,EAAE,IAAY;IAC1D,IAAI,CAAC;QACH,6BAA6B;QAC7B,WAAW;QACX,eAAe;QACf,IAAI;QACJ,4CAA4C;QAC5C,MAAM,gBAAgB,GAAG;YACvB,gBAAgB;YAChB,UAAU;YACV,UAAU;YACV,SAAS;YACT,WAAW;YACX,YAAY;SACb,CAAC;QAEF,IAAI,gBAAgB,CAAC,IAAI,CAAC,OAAO,CAAC,EA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Ae,EAAE,EAAE;IACtD,6CAA6C;IAC7C,MAAM,KAAK,GAAG,8EAA8E,CAAC;IAC7F,MAAM,OAAO,GAAa,EAAE,CAAC;IAC7B,IAAI,KAA6B,CAAC;IAElC,OAAO,CAAC,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC;QAC5C,IAAI,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;YACX,oBAAoB;YACpB,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;QAC3B,CAAC;aAAM,IAAI,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;YAC9B,qDAAqD;YACrD,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,0BAA0B;YAC/D,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,sBAAsB;QAClD,CAAC;IACL,CAAC;IACD,IAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAA,EAAE,CAAA,CAAC,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC,EAAC,CAAC;QAC5C,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,OAAO,CAAC,CAAA;IACjC,CAAC;IAED,OAAO,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;AAChD,CAAC,CAAA","sourcesContent":["\nimport { createRequire } from \"module\";\nimport { pathToFileURL } from \"url\";\nimport { dirname, isAbsolute, join, normalize, relative, resolve, sep} from \"path\";\nimport { readFileSync } from \"fs\";\nimport { splitString } from \"./commons/helper\";\n\n\nconst require = createRequire(import.meta.url);\n\nexport function detectImportType(content: string, path: string): 'require' | 'import' {\n try {\n // const pkg = readPkg(path);\n // if(pkg){\n // return pkg\n // }\n // Quick check for obvious CommonJS patterns\n const commonJsPatterns = [\n 'module.exports',\n 'exports.',\n 'require(',\n 'global.',\n '__dirname',\n '__filename'\n ];\n \n if (commonJsPatterns.some(pattern => content.includes(pattern))) {\n return 'require';\n }\n \n // Check for ES Module syntax\n const esModulePatterns = [\n /\\bimport\\s+[^'\"]*['\"][^'\"]+['\"]/, // import statements\n /\\bexport\\s+(?:default|const|let|var|function|class|interface|type)\\b/, // export declarations\n /\\bexport\\s*{[^}]*}/, // export lists\n /\\bexport\\s*\\*\\s*from/ // re-exports\n ];\n \n if (esModulePatterns.some(pattern => pattern.test(content))) {\n return 'import';\n }\n\n const ext = path.toLowerCase();\n if (ext.endsWith('.mjs')) return 'import';\n if (ext.endsWith('.cjs')) return 'require';\n \n // Default to require for unknown cases\n return 'require';\n } catch (error) {\n return 'require';\n }\n}\n \nexport async function detectModuleType(path: string): Promise<\"module\" | \"commonjs\"> {\ntry {\n const packagePath =\n path.split(\"/\").slice(0, -1).join(\"/\") + \"/package.json\";\n const packageJson = JSON.parse(readFileSync(packagePath, \"utf8\"));\n return packageJson.type === \"module\" ? \"module\" : \"commonjs\";\n} catch {\n return \"commonjs\";\n}\n}\nexport async function loadTypeScriptFile(content: string, filename: string) {\n // Simple TypeScript transpilation\n try{\n const type = detectImportType(content, filename)\n let ts: any | undefined;\n if(type==='import'){\n ts = await import('typescript');\n }else{\n ts = require('typescript');\n }\n const result = ts.transpileModule(content, {\n compilerOptions: {\n module: ts.ModuleKind.CommonJS,\n target: ts.ScriptTarget.ES2018,\n },\n fileName: filename\n });\n\n // Evaluate the code directly\n const moduleExports = {};\n const moduleFn = new Function('exports', 'require', 'module', '__filename', '__dirname', result.outputText);\n const moduleObj = { exports: moduleExports };\n moduleFn(moduleExports, require, moduleObj, filename, dirname(filename));\n // console.log('moduleObj', moduleObj.exports)\n return (moduleObj.exports as any).default || moduleObj.exports;\n }catch(e){\n console.error('error while importing ts file config', e)\n // throw e\n }\n return null\n}\n\nexport function filePathToUrl(path: string): string {\n try {\n // Ensure the path is absolute and normalized\n const absolutePath = require.resolve(path);\n // Convert to URL format, handling Windows paths correctly\n const url = pathToFileURL(absolutePath).href;\n return url;\n } catch (error) {\n // Fallback to direct path conversion if resolve fails\n return pathToFileURL(normalize(path)).href;\n }\n}\n\nexport function findPackageJson(path: string): {path: string, content: any} | null {\n try {\n // Normalize path separators for the current OS\n const normalizedPath = normalize(path);\n const parts = normalizedPath.split(sep);\n \n // Search up the directory tree for package.json\n while (parts.length > 0) {\n const packagePath = [...parts, 'package.json'].join(sep);\n try {\n const content = JSON.parse(readFileSync(packagePath, 'utf8'));\n return {path: packagePath, content};\n } catch {\n parts.pop();\n }\n }\n return null;\n } catch {\n return null;\n }\n}\n\nexport async function importWithFallbacks(path: string, logger?: any) {\n const normalizedPath = path;\n const _importType = path.endsWith('.cjs') ? 'require' : path.endsWith('.mjs') ? 'import' : detectImportType(readFileSync(normalizedPath, 'utf8'), normalizedPath);\n const type = await detectModuleType(normalizedPath);\n // const type = _importType === 'import' ? \"module\" : \"commonjs\";\n \n // if(type === \"commonjs\"){\n // try{\n // const resolvedPath = require.resolve(normalizedPath);\n const strategies = [\n // Strategy 1: Direct require\n async () => {\n const importType = path.endsWith('.cjs') ? 'require' : _importType;\n if (importType === 'require' && type!==\"module\") {\n const resolvedPath = require.resolve(normalizedPath);\n const mod = require(resolvedPath);\n // console.log('Successfully loaded config with require')\n return {value: mod.default || mod, path: resolvedPath};\n } else if(importType === \"import\") {\n const fileUrl = filePathToUrl(normalizedPath);\n const mod = await import(fileUrl);\n // console.log('Successfully loaded config with import')\n return {value: mod.default || mod, path: normalizedPath};\n }\n return null\n },\n async () => {\n if(type==='module' && _importType === \"import\") {\n const fileUrl = filePathToUrl(normalizedPath);\n logger?.debug(\"Dynamic import with file URL:\", fileUrl);\n const mod = await import(fileUrl);\n // console.log('Successfully loaded config with import file url')\n return {value: mod.default || mod, path: normalizedPath};\n }else if(type==='module' && _importType === \"require\") {\n const content = readFileSync(normalizedPath, 'utf8');\n const moduleExports = {};\n const moduleFn = new Function('exports', 'require', 'module', '__filename', '__dirname', content);\n const moduleObj = { exports: moduleExports };\n moduleFn(moduleExports, require, moduleObj, path, dirname(path));\n return {value: (moduleObj.exports as any).default || moduleObj.exports, path: normalizedPath};\n }\n return null;\n },\n ];\n \n let lastError;\n for (const strategy of strategies) {\n try {\n const result = await strategy();\n if(result){\n return result;\n }\n } catch (error: any) {\n lastError = error;\n if(!logger){\n console.log('Import strategy failed:', error.message);\n }\n logger?.debug(\"Import strategy failed:\", error.message);\n continue;\n }\n }\n \n if (lastError) {\n throw lastError;\n }\n return null\n}\n\nexport function normalizeFilePath(path: string): string {\n // Normalize path separators and handle Windows paths\n const normalized = normalize(path).replace(/\\\\/g, '/');\n return normalized;\n}\n\nexport const getAbsPath = (relativeFilePath: string, directory: string = __dirname)=>{\n try{\n if(isAbsolute(relativeFilePath)){\n return relativeFilePath\n }\n return join(directory, relativeFilePath) as string\n }catch(e){\n return null;\n }\n}\nexport const getRelativePath = (dir1: string, dir2: string = __dirname)=>{\n try{\n return relative(dir1, dir2)\n }catch(e){\n return null;\n }\n}\n\nexport const getFilePath = (filename: string)=>{\n if(typeof filename === \"string\" && filename.length > 0){\n try{\n return resolve(filename);\n }catch{\n return \"\"\n }\n }\n return '';\n }\n\n export const matchLiteralString = (content: string) => {\n const first = matchLiteralStringA(content)\n // Match both regular string literals and template literals with expressions\n // const templateLiteralRegex = /(?<=`|'|\"|\\$\\{)(?:(?!\\$\\{|`|'|\").)*?(?=`|'|\"|\\$\\{)/g;\n const templateLiteralRegex =/(['\"`])((?:\\\\.|(?!\\1)(?!\\$\\{)[\\s\\S]|\\$\\{[^}]*\\})*)\\1/g;\n // const templateLiteralRegex = /`?([^$`]+)(?=\\$\\{)|'([^']*)'|\"([^\"]*)\"/g;\n const matches = content.match(templateLiteralRegex);\n \n if (matches) {\n // Process each match to extract the actual class names\n return matches.map(match => {\n // For template literals with expressions, we need to:\n // 1. Replace ${...} expressions with a space to preserve class separation\n // 2. Remove the backticks/quotes\n // if(match.includes('w-full${')){\n // console.log('match inclueds', match)\n // }\n if(match.includes('bg-emerald')){\n console.log('match', match)\n }\n return match\n .replace(/\\${[^}]*}/g, ' ')\n .replace(/^[`'\"]/g, '')\n .replace(/[`'\"]$/g, '')\n .trim();\n }).flatMap(s=>splitString(s));\n }\n return [];\n};\n\n export const matchLiteralStringA = (content: string) => {\n // Match both full strings and nested strings\n const regex = /(['\"`])((?:(?!\\1|\\\\).|\\\\.)*)\\1|\\[(.*?)(['\"`])((?:(?!\\4|\\\\).|\\\\.)*)\\4(.*?)\\]/g;\n const matches: string[] = [];\n let match: RegExpExecArray | null;\n \n while ((match = regex.exec(content)) !== null) {\n if (match[2]) {\n // Full string match\n matches.push(match[2]);\n } else if (match[3] && match[5]) {\n // Nested string match (e.g., within square brackets)\n matches.push(match[0].slice(1, -1)); // Full attribute selector\n matches.push(match[5]); // Inner quoted string\n }\n }\n if(matches.some(m=>m.includes('bg-emerald'))){\n console.log('matches', matches)\n }\n \n return matches.flatMap(s => splitString(s));\n}\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { FSWatcher } from 'node:fs';
|
|
2
|
+
export default class Watcher {
|
|
3
|
+
private watchers;
|
|
4
|
+
private files;
|
|
5
|
+
private changed;
|
|
6
|
+
constructor(files?: string[]);
|
|
7
|
+
addFiles(files: string[]): void;
|
|
8
|
+
get watcherFiles(): string[];
|
|
9
|
+
watch(directory?: string): {
|
|
10
|
+
watcher: FSWatcher;
|
|
11
|
+
file: string;
|
|
12
|
+
}[];
|
|
13
|
+
stop(file?: string): void;
|
|
14
|
+
getChangedFiles(): string[];
|
|
15
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { watch } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
export default class Watcher {
|
|
4
|
+
constructor(files) {
|
|
5
|
+
this.watchers = [];
|
|
6
|
+
this.files = new Set(files || []);
|
|
7
|
+
this.changed = new Set();
|
|
8
|
+
}
|
|
9
|
+
addFiles(files) {
|
|
10
|
+
for (const file of files.slice()) {
|
|
11
|
+
if (!this.files.has(file)) {
|
|
12
|
+
this.files.add(file);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
get watcherFiles() {
|
|
17
|
+
return Array.from(this.files);
|
|
18
|
+
}
|
|
19
|
+
watch(directory) {
|
|
20
|
+
if (directory) {
|
|
21
|
+
const watched = watch(directory, (eventType, filename) => {
|
|
22
|
+
if (filename) {
|
|
23
|
+
console.log(`File changed: ${filename} - Event type: ${eventType}`);
|
|
24
|
+
this.changed.add(join(directory, filename));
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
this.watchers.push({ watcher: watched, file: directory });
|
|
28
|
+
console.log(`Watching for changes in directory: ${directory}`);
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
for (const file of this.files) {
|
|
32
|
+
const watcher = this.watchers.find(w => w.file === file);
|
|
33
|
+
if (!watcher) {
|
|
34
|
+
this.watchers.push({ watcher: watch(file, (eventType) => {
|
|
35
|
+
if (eventType) {
|
|
36
|
+
console.log(`File changed: ${file} - Event type: ${eventType}`);
|
|
37
|
+
this.changed.add(file);
|
|
38
|
+
}
|
|
39
|
+
}), file });
|
|
40
|
+
console.log(file, ' watched');
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return this.watchers.slice();
|
|
45
|
+
}
|
|
46
|
+
stop(file) {
|
|
47
|
+
if (this.watchers.length === 0)
|
|
48
|
+
return;
|
|
49
|
+
this.watchers.forEach(watcher => watcher.watcher.close());
|
|
50
|
+
this.watchers = [];
|
|
51
|
+
console.log('Stopped watching.');
|
|
52
|
+
}
|
|
53
|
+
// public clear(): void {
|
|
54
|
+
// this.watchers = [];
|
|
55
|
+
// this.files.clear();
|
|
56
|
+
// this.changed.clear();
|
|
57
|
+
// }
|
|
58
|
+
getChangedFiles() {
|
|
59
|
+
return Array.from(this.changed);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=watcher.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"watcher.js","sourceRoot":"","sources":["../../src/watcher.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAa,MAAM,SAAS,CAAC;AAC3C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,MAAM,CAAC,OAAO,OAAO,OAAO;IAKxB,YAAY,KAAgB;QAJpB,aAAQ,GAAyC,EAAE,CAAC;QAKxD,IAAI,CAAC,KAAK,GAAG,IAAI,GAAG,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC;QAClC,IAAI,CAAC,OAAO,GAAG,IAAI,GAAG,EAAE,CAAC;IAC7B,CAAC;IAED,QAAQ,CAAC,KAAe;QACpB,KAAI,MAAM,IAAI,IAAI,KAAK,CAAC,KAAK,EAAE,EAAC,CAAC;YAC7B,IAAG,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAC,CAAC;gBACtB,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;YACzB,CAAC;QACL,CAAC;IACL,CAAC;IAED,IAAI,YAAY;QACZ,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAClC,CAAC;IAEM,KAAK,CAAC,SAAkB;QAC3B,IAAG,SAAS,EAAC,CAAC;YACV,MAAM,OAAO,GAAG,KAAK,CAAC,SAAS,EAAE,CAAC,SAAS,EAAE,QAAQ,EAAE,EAAE;gBACrD,IAAI,QAAQ,EAAE,CAAC;oBACX,OAAO,CAAC,GAAG,CAAC,iBAAiB,QAAQ,kBAAkB,SAAS,EAAE,CAAC,CAAC;oBACpE,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,EAAE,QAAQ,C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nB,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;IACrC,CAAC;IACD,yBAAyB;IACzB,0BAA0B;IAC1B,0BAA0B;IAC1B,4BAA4B;IAC5B,IAAI;IAEG,eAAe;QAClB,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACpC,CAAC;CACJ","sourcesContent":["import { watch, FSWatcher } from 'node:fs';\nimport { join } from 'node:path';\n\nexport default class Watcher {\n private watchers: {watcher: FSWatcher, file: string}[] = [];\n private files: Set<string>;\n private changed: Set<string>;\n\n constructor(files?: string[]) {\n this.files = new Set(files || []);\n this.changed = new Set();\n }\n\n addFiles(files: string[]){\n for(const file of files.slice()){\n if(!this.files.has(file)){\n this.files.add(file);\n }\n }\n }\n\n get watcherFiles(){\n return Array.from(this.files);\n }\n\n public watch(directory?: string) {\n if(directory){\n const watched = watch(directory, (eventType, filename) => {\n if (filename) {\n console.log(`File changed: ${filename} - Event type: ${eventType}`);\n this.changed.add(join(directory, filename));\n }\n });\n this.watchers.push({watcher: watched, file: directory});\n console.log(`Watching for changes in directory: ${directory}`);\n }else{\n for(const file of this.files){\n const watcher = this.watchers.find(w=>w.file === file);\n if(!watcher){\n this.watchers.push({watcher: watch(file, (eventType) => {\n if (eventType) {\n console.log(`File changed: ${file} - Event type: ${eventType}`);\n this.changed.add(file);\n }\n }), file});\n console.log(file, ' watched')\n }\n }\n }\n return this.watchers.slice()\n }\n\n public stop(file?: string): void {\n if(this.watchers.length === 0) return;\n this.watchers.forEach(watcher => watcher.watcher.close());\n this.watchers = [];\n console.log('Stopped watching.');\n }\n // public clear(): void {\n // this.watchers = [];\n // this.files.clear();\n // this.changed.clear();\n // }\n\n public getChangedFiles(): string[] {\n return Array.from(this.changed);\n }\n}"]}
|