@coze-arch/cli 0.0.1-alpha.3002ee → 0.0.1-alpha.3260db
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/lib/__templates__/expo/.coze +7 -2
- package/lib/__templates__/expo/.cozeproj/scripts/dev_build.sh +46 -0
- package/lib/__templates__/expo/.cozeproj/scripts/dev_run.sh +229 -0
- package/lib/__templates__/expo/.cozeproj/scripts/prod_build.sh +47 -0
- package/lib/__templates__/expo/.cozeproj/scripts/prod_run.sh +34 -0
- package/lib/__templates__/expo/.cozeproj/scripts/server_dev_run.sh +46 -0
- package/lib/__templates__/expo/README.md +64 -7
- package/lib/__templates__/expo/_gitignore +1 -1
- package/lib/__templates__/expo/_npmrc +3 -5
- package/lib/__templates__/expo/client/app/+not-found.tsx +8 -72
- package/lib/__templates__/expo/client/app/_layout.tsx +17 -12
- package/lib/__templates__/expo/client/app/index.tsx +1 -0
- package/lib/__templates__/expo/client/app.config.ts +76 -0
- package/lib/__templates__/expo/client/components/Screen.tsx +5 -18
- package/lib/__templates__/expo/client/components/ThemedText.tsx +33 -0
- package/lib/__templates__/expo/client/components/ThemedView.tsx +37 -0
- package/lib/__templates__/expo/client/contexts/AuthContext.tsx +14 -107
- package/lib/__templates__/expo/client/declarations.d.ts +5 -0
- package/lib/__templates__/expo/{eslint.config.mjs → client/eslint.config.mjs} +33 -10
- package/lib/__templates__/expo/client/global.css +6 -0
- package/lib/__templates__/expo/client/heroui/components/accordion/accordion.animation.ts +178 -0
- package/lib/__templates__/expo/client/heroui/components/accordion/accordion.constants.ts +62 -0
- package/lib/__templates__/expo/client/heroui/components/accordion/accordion.md +437 -0
- package/lib/__templates__/expo/client/heroui/components/accordion/accordion.styles.ts +95 -0
- package/lib/__templates__/expo/client/heroui/components/accordion/accordion.tsx +340 -0
- package/lib/__templates__/expo/client/heroui/components/accordion/accordion.types.ts +267 -0
- package/lib/__templates__/expo/client/heroui/components/accordion/index.ts +17 -0
- package/lib/__templates__/expo/client/heroui/components/alert/alert.constants.ts +13 -0
- package/lib/__templates__/expo/client/heroui/components/alert/alert.hooks.ts +28 -0
- package/lib/__templates__/expo/client/heroui/components/alert/alert.md +263 -0
- package/lib/__templates__/expo/client/heroui/components/alert/alert.styles.ts +65 -0
- package/lib/__templates__/expo/client/heroui/components/alert/alert.tsx +181 -0
- package/lib/__templates__/expo/client/heroui/components/alert/alert.types.ts +99 -0
- package/lib/__templates__/expo/client/heroui/components/alert/alert.utils.tsx +25 -0
- package/lib/__templates__/expo/client/heroui/components/alert/default-icon.tsx +28 -0
- package/lib/__templates__/expo/client/heroui/components/alert/index.ts +15 -0
- package/lib/__templates__/expo/client/heroui/components/alert/success-icon.tsx +28 -0
- package/lib/__templates__/expo/client/heroui/components/alert/warning-icon.tsx +28 -0
- package/lib/__templates__/expo/client/heroui/components/avatar/avatar.animation.ts +123 -0
- package/lib/__templates__/expo/client/heroui/components/avatar/avatar.constants.ts +19 -0
- package/lib/__templates__/expo/client/heroui/components/avatar/avatar.context.ts +11 -0
- package/lib/__templates__/expo/client/heroui/components/avatar/avatar.md +386 -0
- package/lib/__templates__/expo/client/heroui/components/avatar/avatar.styles.ts +145 -0
- package/lib/__templates__/expo/client/heroui/components/avatar/avatar.tsx +307 -0
- package/lib/__templates__/expo/client/heroui/components/avatar/avatar.types.ts +239 -0
- package/lib/__templates__/expo/client/heroui/components/avatar/index.ts +13 -0
- package/lib/__templates__/expo/client/heroui/components/avatar/person-icon.tsx +23 -0
- package/lib/__templates__/expo/client/heroui/components/bottom-sheet/bottom-sheet.animation.ts +42 -0
- package/lib/__templates__/expo/client/heroui/components/bottom-sheet/bottom-sheet.constants.ts +13 -0
- package/lib/__templates__/expo/client/heroui/components/bottom-sheet/bottom-sheet.md +349 -0
- package/lib/__templates__/expo/client/heroui/components/bottom-sheet/bottom-sheet.styles.ts +66 -0
- package/lib/__templates__/expo/client/heroui/components/bottom-sheet/bottom-sheet.tsx +351 -0
- package/lib/__templates__/expo/client/heroui/components/bottom-sheet/bottom-sheet.types.ts +150 -0
- package/lib/__templates__/expo/client/heroui/components/bottom-sheet/index.ts +16 -0
- package/lib/__templates__/expo/client/heroui/components/button/button.constants.ts +7 -0
- package/lib/__templates__/expo/client/heroui/components/button/button.md +381 -0
- package/lib/__templates__/expo/client/heroui/components/button/button.styles.ts +89 -0
- package/lib/__templates__/expo/client/heroui/components/button/button.tsx +284 -0
- package/lib/__templates__/expo/client/heroui/components/button/button.types.ts +175 -0
- package/lib/__templates__/expo/client/heroui/components/button/button.utils.ts +34 -0
- package/lib/__templates__/expo/client/heroui/components/button/index.ts +9 -0
- package/lib/__templates__/expo/client/heroui/components/card/card.constants.ts +11 -0
- package/lib/__templates__/expo/client/heroui/components/card/card.md +186 -0
- package/lib/__templates__/expo/client/heroui/components/card/card.styles.ts +35 -0
- package/lib/__templates__/expo/client/heroui/components/card/card.tsx +153 -0
- package/lib/__templates__/expo/client/heroui/components/card/card.types.ts +77 -0
- package/lib/__templates__/expo/client/heroui/components/card/index.ts +10 -0
- package/lib/__templates__/expo/client/heroui/components/checkbox/checkbox.animation.ts +202 -0
- package/lib/__templates__/expo/client/heroui/components/checkbox/checkbox.constants.ts +6 -0
- package/lib/__templates__/expo/client/heroui/components/checkbox/checkbox.md +311 -0
- package/lib/__templates__/expo/client/heroui/components/checkbox/checkbox.styles.ts +105 -0
- package/lib/__templates__/expo/client/heroui/components/checkbox/checkbox.tsx +251 -0
- package/lib/__templates__/expo/client/heroui/components/checkbox/checkbox.types.ts +216 -0
- package/lib/__templates__/expo/client/heroui/components/checkbox/index.ts +3 -0
- package/lib/__templates__/expo/client/heroui/components/chip/chip.animation.ts +18 -0
- package/lib/__templates__/expo/client/heroui/components/chip/chip.constants.ts +7 -0
- package/lib/__templates__/expo/client/heroui/components/chip/chip.md +190 -0
- package/lib/__templates__/expo/client/heroui/components/chip/chip.styles.ts +234 -0
- package/lib/__templates__/expo/client/heroui/components/chip/chip.tsx +125 -0
- package/lib/__templates__/expo/client/heroui/components/chip/chip.types.ts +69 -0
- package/lib/__templates__/expo/client/heroui/components/chip/index.ts +3 -0
- package/lib/__templates__/expo/client/heroui/components/close-button/close-button.constants.ts +6 -0
- package/lib/__templates__/expo/client/heroui/components/close-button/close-button.md +109 -0
- package/lib/__templates__/expo/client/heroui/components/close-button/close-button.styles.ts +13 -0
- package/lib/__templates__/expo/client/heroui/components/close-button/close-button.tsx +57 -0
- package/lib/__templates__/expo/client/heroui/components/close-button/close-button.types.ts +30 -0
- package/lib/__templates__/expo/client/heroui/components/close-button/index.ts +6 -0
- package/lib/__templates__/expo/client/heroui/components/control-field/control-field.animation.ts +18 -0
- package/lib/__templates__/expo/client/heroui/components/control-field/control-field.constants.ts +7 -0
- package/lib/__templates__/expo/client/heroui/components/control-field/control-field.context.ts +14 -0
- package/lib/__templates__/expo/client/heroui/components/control-field/control-field.md +241 -0
- package/lib/__templates__/expo/client/heroui/components/control-field/control-field.styles.ts +15 -0
- package/lib/__templates__/expo/client/heroui/components/control-field/control-field.tsx +245 -0
- package/lib/__templates__/expo/client/heroui/components/control-field/control-field.types.ts +67 -0
- package/lib/__templates__/expo/client/heroui/components/control-field/index.ts +6 -0
- package/lib/__templates__/expo/client/heroui/components/description/description.animation.ts +53 -0
- package/lib/__templates__/expo/client/heroui/components/description/description.constants.ts +30 -0
- package/lib/__templates__/expo/client/heroui/components/description/description.md +129 -0
- package/lib/__templates__/expo/client/heroui/components/description/description.styles.ts +25 -0
- package/lib/__templates__/expo/client/heroui/components/description/description.tsx +81 -0
- package/lib/__templates__/expo/client/heroui/components/description/description.types.ts +77 -0
- package/lib/__templates__/expo/client/heroui/components/description/index.ts +3 -0
- package/lib/__templates__/expo/client/heroui/components/dialog/dialog.animation.ts +9 -0
- package/lib/__templates__/expo/client/heroui/components/dialog/dialog.constants.ts +13 -0
- package/lib/__templates__/expo/client/heroui/components/dialog/dialog.md +288 -0
- package/lib/__templates__/expo/client/heroui/components/dialog/dialog.styles.ts +77 -0
- package/lib/__templates__/expo/client/heroui/components/dialog/dialog.tsx +379 -0
- package/lib/__templates__/expo/client/heroui/components/dialog/dialog.types.ts +199 -0
- package/lib/__templates__/expo/client/heroui/components/dialog/index.ts +12 -0
- package/lib/__templates__/expo/client/heroui/components/field-error/field-error.animation.ts +50 -0
- package/lib/__templates__/expo/client/heroui/components/field-error/field-error.constants.ts +31 -0
- package/lib/__templates__/expo/client/heroui/components/field-error/field-error.md +204 -0
- package/lib/__templates__/expo/client/heroui/components/field-error/field-error.styles.ts +23 -0
- package/lib/__templates__/expo/client/heroui/components/field-error/field-error.tsx +91 -0
- package/lib/__templates__/expo/client/heroui/components/field-error/field-error.types.ts +79 -0
- package/lib/__templates__/expo/client/heroui/components/field-error/index.ts +3 -0
- package/lib/__templates__/expo/client/heroui/components/input/index.ts +3 -0
- package/lib/__templates__/expo/client/heroui/components/input/input.constants.ts +6 -0
- package/lib/__templates__/expo/client/heroui/components/input/input.md +193 -0
- package/lib/__templates__/expo/client/heroui/components/input/input.styles.ts +51 -0
- package/lib/__templates__/expo/client/heroui/components/input/input.tsx +96 -0
- package/lib/__templates__/expo/client/heroui/components/input/input.types.ts +44 -0
- package/lib/__templates__/expo/client/heroui/components/input-group/index.ts +9 -0
- package/lib/__templates__/expo/client/heroui/components/input-group/input-group.animation.ts +14 -0
- package/lib/__templates__/expo/client/heroui/components/input-group/input-group.constants.ts +6 -0
- package/lib/__templates__/expo/client/heroui/components/input-group/input-group.md +197 -0
- package/lib/__templates__/expo/client/heroui/components/input-group/input-group.styles.ts +31 -0
- package/lib/__templates__/expo/client/heroui/components/input-group/input-group.tsx +239 -0
- package/lib/__templates__/expo/client/heroui/components/input-group/input-group.types.ts +98 -0
- package/lib/__templates__/expo/client/heroui/components/input-otp/index.ts +9 -0
- package/lib/__templates__/expo/client/heroui/components/input-otp/input-otp.animation.ts +199 -0
- package/lib/__templates__/expo/client/heroui/components/input-otp/input-otp.constants.ts +12 -0
- package/lib/__templates__/expo/client/heroui/components/input-otp/input-otp.md +376 -0
- package/lib/__templates__/expo/client/heroui/components/input-otp/input-otp.styles.ts +68 -0
- package/lib/__templates__/expo/client/heroui/components/input-otp/input-otp.tsx +414 -0
- package/lib/__templates__/expo/client/heroui/components/input-otp/input-otp.types.ts +275 -0
- package/lib/__templates__/expo/client/heroui/components/label/index.ts +3 -0
- package/lib/__templates__/expo/client/heroui/components/label/label.animation.ts +18 -0
- package/lib/__templates__/expo/client/heroui/components/label/label.constants.ts +7 -0
- package/lib/__templates__/expo/client/heroui/components/label/label.md +187 -0
- package/lib/__templates__/expo/client/heroui/components/label/label.styles.ts +44 -0
- package/lib/__templates__/expo/client/heroui/components/label/label.tsx +172 -0
- package/lib/__templates__/expo/client/heroui/components/label/label.types.ts +86 -0
- package/lib/__templates__/expo/client/heroui/components/list-group/index.ts +17 -0
- package/lib/__templates__/expo/client/heroui/components/list-group/list-group.constants.ts +17 -0
- package/lib/__templates__/expo/client/heroui/components/list-group/list-group.md +387 -0
- package/lib/__templates__/expo/client/heroui/components/list-group/list-group.styles.ts +40 -0
- package/lib/__templates__/expo/client/heroui/components/list-group/list-group.tsx +206 -0
- package/lib/__templates__/expo/client/heroui/components/list-group/list-group.types.ts +132 -0
- package/lib/__templates__/expo/client/heroui/components/menu/index.ts +38 -0
- package/lib/__templates__/expo/client/heroui/components/menu/menu.animation.ts +121 -0
- package/lib/__templates__/expo/client/heroui/components/menu/menu.constants.ts +37 -0
- package/lib/__templates__/expo/client/heroui/components/menu/menu.md +620 -0
- package/lib/__templates__/expo/client/heroui/components/menu/menu.styles.ts +107 -0
- package/lib/__templates__/expo/client/heroui/components/menu/menu.tsx +664 -0
- package/lib/__templates__/expo/client/heroui/components/menu/menu.types.ts +394 -0
- package/lib/__templates__/expo/client/heroui/components/popover/arrow-svg.tsx +180 -0
- package/lib/__templates__/expo/client/heroui/components/popover/index.ts +18 -0
- package/lib/__templates__/expo/client/heroui/components/popover/popover.animation.ts +9 -0
- package/lib/__templates__/expo/client/heroui/components/popover/popover.constants.ts +34 -0
- package/lib/__templates__/expo/client/heroui/components/popover/popover.md +508 -0
- package/lib/__templates__/expo/client/heroui/components/popover/popover.styles.ts +98 -0
- package/lib/__templates__/expo/client/heroui/components/popover/popover.tsx +624 -0
- package/lib/__templates__/expo/client/heroui/components/popover/popover.types.ts +290 -0
- package/lib/__templates__/expo/client/heroui/components/pressable-feedback/index.ts +4 -0
- package/lib/__templates__/expo/client/heroui/components/pressable-feedback/pressable-feedback.animation.ts +449 -0
- package/lib/__templates__/expo/client/heroui/components/pressable-feedback/pressable-feedback.constants.ts +12 -0
- package/lib/__templates__/expo/client/heroui/components/pressable-feedback/pressable-feedback.md +328 -0
- package/lib/__templates__/expo/client/heroui/components/pressable-feedback/pressable-feedback.styles.ts +85 -0
- package/lib/__templates__/expo/client/heroui/components/pressable-feedback/pressable-feedback.tsx +330 -0
- package/lib/__templates__/expo/client/heroui/components/pressable-feedback/pressable-feedback.types.ts +386 -0
- package/lib/__templates__/expo/client/heroui/components/radio/index.ts +9 -0
- package/lib/__templates__/expo/client/heroui/components/radio/radio.animation.ts +92 -0
- package/lib/__templates__/expo/client/heroui/components/radio/radio.constants.ts +11 -0
- package/lib/__templates__/expo/client/heroui/components/radio/radio.md +339 -0
- package/lib/__templates__/expo/client/heroui/components/radio/radio.styles.ts +80 -0
- package/lib/__templates__/expo/client/heroui/components/radio/radio.tsx +217 -0
- package/lib/__templates__/expo/client/heroui/components/radio/radio.types.ts +106 -0
- package/lib/__templates__/expo/client/heroui/components/radio-group/index.ts +9 -0
- package/lib/__templates__/expo/client/heroui/components/radio-group/radio-group.animation.ts +20 -0
- package/lib/__templates__/expo/client/heroui/components/radio-group/radio-group.constants.ts +7 -0
- package/lib/__templates__/expo/client/heroui/components/radio-group/radio-group.context.ts +14 -0
- package/lib/__templates__/expo/client/heroui/components/radio-group/radio-group.md +273 -0
- package/lib/__templates__/expo/client/heroui/components/radio-group/radio-group.styles.ts +15 -0
- package/lib/__templates__/expo/client/heroui/components/radio-group/radio-group.tsx +220 -0
- package/lib/__templates__/expo/client/heroui/components/radio-group/radio-group.types.ts +64 -0
- package/lib/__templates__/expo/client/heroui/components/scroll-shadow/index.ts +7 -0
- package/lib/__templates__/expo/client/heroui/components/scroll-shadow/scroll-shadow.animation.ts +132 -0
- package/lib/__templates__/expo/client/heroui/components/scroll-shadow/scroll-shadow.constants.ts +21 -0
- package/lib/__templates__/expo/client/heroui/components/scroll-shadow/scroll-shadow.md +206 -0
- package/lib/__templates__/expo/client/heroui/components/scroll-shadow/scroll-shadow.styles.ts +52 -0
- package/lib/__templates__/expo/client/heroui/components/scroll-shadow/scroll-shadow.tsx +262 -0
- package/lib/__templates__/expo/client/heroui/components/scroll-shadow/scroll-shadow.types.ts +121 -0
- package/lib/__templates__/expo/client/heroui/components/search-field/index.ts +17 -0
- package/lib/__templates__/expo/client/heroui/components/search-field/search-field.animation.ts +18 -0
- package/lib/__templates__/expo/client/heroui/components/search-field/search-field.constants.ts +10 -0
- package/lib/__templates__/expo/client/heroui/components/search-field/search-field.md +231 -0
- package/lib/__templates__/expo/client/heroui/components/search-field/search-field.styles.ts +35 -0
- package/lib/__templates__/expo/client/heroui/components/search-field/search-field.tsx +253 -0
- package/lib/__templates__/expo/client/heroui/components/search-field/search-field.types.ts +160 -0
- package/lib/__templates__/expo/client/heroui/components/search-field/search-icon.tsx +37 -0
- package/lib/__templates__/expo/client/heroui/components/select/index.ts +28 -0
- package/lib/__templates__/expo/client/heroui/components/select/select.animation.ts +92 -0
- package/lib/__templates__/expo/client/heroui/components/select/select.constants.ts +53 -0
- package/lib/__templates__/expo/client/heroui/components/select/select.md +796 -0
- package/lib/__templates__/expo/client/heroui/components/select/select.styles.ts +149 -0
- package/lib/__templates__/expo/client/heroui/components/select/select.tsx +828 -0
- package/lib/__templates__/expo/client/heroui/components/select/select.types.ts +438 -0
- package/lib/__templates__/expo/client/heroui/components/separator/index.ts +7 -0
- package/lib/__templates__/expo/client/heroui/components/separator/separator.constants.ts +6 -0
- package/lib/__templates__/expo/client/heroui/components/separator/separator.md +106 -0
- package/lib/__templates__/expo/client/heroui/components/separator/separator.styles.ts +50 -0
- package/lib/__templates__/expo/client/heroui/components/separator/separator.tsx +62 -0
- package/lib/__templates__/expo/client/heroui/components/separator/separator.types.ts +40 -0
- package/lib/__templates__/expo/client/heroui/components/skeleton/index.ts +7 -0
- package/lib/__templates__/expo/client/heroui/components/skeleton/linear-gradient.tsx +45 -0
- package/lib/__templates__/expo/client/heroui/components/skeleton/skeleton.animation.ts +350 -0
- package/lib/__templates__/expo/client/heroui/components/skeleton/skeleton.constants.ts +39 -0
- package/lib/__templates__/expo/client/heroui/components/skeleton/skeleton.md +208 -0
- package/lib/__templates__/expo/client/heroui/components/skeleton/skeleton.styles.ts +49 -0
- package/lib/__templates__/expo/client/heroui/components/skeleton/skeleton.tsx +183 -0
- package/lib/__templates__/expo/client/heroui/components/skeleton/skeleton.types.ts +191 -0
- package/lib/__templates__/expo/client/heroui/components/skeleton-group/index.ts +7 -0
- package/lib/__templates__/expo/client/heroui/components/skeleton-group/skeleton-group.constants.ts +7 -0
- package/lib/__templates__/expo/client/heroui/components/skeleton-group/skeleton-group.md +247 -0
- package/lib/__templates__/expo/client/heroui/components/skeleton-group/skeleton-group.styles.ts +10 -0
- package/lib/__templates__/expo/client/heroui/components/skeleton-group/skeleton-group.tsx +94 -0
- package/lib/__templates__/expo/client/heroui/components/skeleton-group/skeleton-group.types.ts +28 -0
- package/lib/__templates__/expo/client/heroui/components/slider/index.ts +23 -0
- package/lib/__templates__/expo/client/heroui/components/slider/slider.animation.ts +87 -0
- package/lib/__templates__/expo/client/heroui/components/slider/slider.constants.ts +24 -0
- package/lib/__templates__/expo/client/heroui/components/slider/slider.md +348 -0
- package/lib/__templates__/expo/client/heroui/components/slider/slider.styles.ts +85 -0
- package/lib/__templates__/expo/client/heroui/components/slider/slider.tsx +413 -0
- package/lib/__templates__/expo/client/heroui/components/slider/slider.types.ts +120 -0
- package/lib/__templates__/expo/client/heroui/components/spinner/index.ts +10 -0
- package/lib/__templates__/expo/client/heroui/components/spinner/spinner-icon.tsx +49 -0
- package/lib/__templates__/expo/client/heroui/components/spinner/spinner.animation.ts +150 -0
- package/lib/__templates__/expo/client/heroui/components/spinner/spinner.constants.ts +36 -0
- package/lib/__templates__/expo/client/heroui/components/spinner/spinner.md +199 -0
- package/lib/__templates__/expo/client/heroui/components/spinner/spinner.styles.ts +44 -0
- package/lib/__templates__/expo/client/heroui/components/spinner/spinner.tsx +198 -0
- package/lib/__templates__/expo/client/heroui/components/spinner/spinner.types.ts +158 -0
- package/lib/__templates__/expo/client/heroui/components/surface/index.ts +3 -0
- package/lib/__templates__/expo/client/heroui/components/surface/surface.animation.ts +18 -0
- package/lib/__templates__/expo/client/heroui/components/surface/surface.constants.ts +6 -0
- package/lib/__templates__/expo/client/heroui/components/surface/surface.md +136 -0
- package/lib/__templates__/expo/client/heroui/components/surface/surface.styles.ts +28 -0
- package/lib/__templates__/expo/client/heroui/components/surface/surface.tsx +66 -0
- package/lib/__templates__/expo/client/heroui/components/surface/surface.types.ts +46 -0
- package/lib/__templates__/expo/client/heroui/components/switch/index.ts +3 -0
- package/lib/__templates__/expo/client/heroui/components/switch/switch.animation.ts +243 -0
- package/lib/__templates__/expo/client/heroui/components/switch/switch.constants.ts +26 -0
- package/lib/__templates__/expo/client/heroui/components/switch/switch.md +334 -0
- package/lib/__templates__/expo/client/heroui/components/switch/switch.styles.ts +83 -0
- package/lib/__templates__/expo/client/heroui/components/switch/switch.tsx +280 -0
- package/lib/__templates__/expo/client/heroui/components/switch/switch.types.ts +208 -0
- package/lib/__templates__/expo/client/heroui/components/tabs/index.ts +8 -0
- package/lib/__templates__/expo/client/heroui/components/tabs/tabs.animation.ts +246 -0
- package/lib/__templates__/expo/client/heroui/components/tabs/tabs.constants.ts +17 -0
- package/lib/__templates__/expo/client/heroui/components/tabs/tabs.context.ts +28 -0
- package/lib/__templates__/expo/client/heroui/components/tabs/tabs.md +565 -0
- package/lib/__templates__/expo/client/heroui/components/tabs/tabs.styles.ts +168 -0
- package/lib/__templates__/expo/client/heroui/components/tabs/tabs.tsx +445 -0
- package/lib/__templates__/expo/client/heroui/components/tabs/tabs.types.ts +341 -0
- package/lib/__templates__/expo/client/heroui/components/tag-group/index.ts +15 -0
- package/lib/__templates__/expo/client/heroui/components/tag-group/tag-group.animation.ts +17 -0
- package/lib/__templates__/expo/client/heroui/components/tag-group/tag-group.constants.ts +10 -0
- package/lib/__templates__/expo/client/heroui/components/tag-group/tag-group.md +404 -0
- package/lib/__templates__/expo/client/heroui/components/tag-group/tag-group.styles.ts +74 -0
- package/lib/__templates__/expo/client/heroui/components/tag-group/tag-group.tsx +325 -0
- package/lib/__templates__/expo/client/heroui/components/tag-group/tag-group.types.ts +125 -0
- package/lib/__templates__/expo/client/heroui/components/text-area/index.ts +3 -0
- package/lib/__templates__/expo/client/heroui/components/text-area/text-area.constants.ts +6 -0
- package/lib/__templates__/expo/client/heroui/components/text-area/text-area.md +133 -0
- package/lib/__templates__/expo/client/heroui/components/text-area/text-area.styles.ts +10 -0
- package/lib/__templates__/expo/client/heroui/components/text-area/text-area.tsx +44 -0
- package/lib/__templates__/expo/client/heroui/components/text-area/text-area.types.ts +6 -0
- package/lib/__templates__/expo/client/heroui/components/text-field/index.ts +3 -0
- package/lib/__templates__/expo/client/heroui/components/text-field/text-field.animation.ts +20 -0
- package/lib/__templates__/expo/client/heroui/components/text-field/text-field.constants.ts +6 -0
- package/lib/__templates__/expo/client/heroui/components/text-field/text-field.md +256 -0
- package/lib/__templates__/expo/client/heroui/components/text-field/text-field.styles.ts +10 -0
- package/lib/__templates__/expo/client/heroui/components/text-field/text-field.tsx +82 -0
- package/lib/__templates__/expo/client/heroui/components/text-field/text-field.types.ts +56 -0
- package/lib/__templates__/expo/client/heroui/components/toast/index.ts +4 -0
- package/lib/__templates__/expo/client/heroui/components/toast/toast.animation.ts +381 -0
- package/lib/__templates__/expo/client/heroui/components/toast/toast.constants.ts +10 -0
- package/lib/__templates__/expo/client/heroui/components/toast/toast.hooks.ts +73 -0
- package/lib/__templates__/expo/client/heroui/components/toast/toast.md +420 -0
- package/lib/__templates__/expo/client/heroui/components/toast/toast.styles.ts +89 -0
- package/lib/__templates__/expo/client/heroui/components/toast/toast.tsx +472 -0
- package/lib/__templates__/expo/client/heroui/components/toast/toast.types.ts +320 -0
- package/lib/__templates__/expo/client/heroui/docs.md +54 -0
- package/lib/__templates__/expo/client/heroui/helpers/external/hooks/index.ts +3 -0
- package/lib/__templates__/expo/client/heroui/helpers/external/hooks/use-is-on-surface.ts +8 -0
- package/lib/__templates__/expo/client/heroui/helpers/external/hooks/use-theme-color.ts +137 -0
- package/lib/__templates__/expo/client/heroui/helpers/external/utils/cn.ts +12 -0
- package/lib/__templates__/expo/client/heroui/helpers/external/utils/color-kit/index.ts +2392 -0
- package/lib/__templates__/expo/client/heroui/helpers/external/utils/color-kit/types.ts +212 -0
- package/lib/__templates__/expo/client/heroui/helpers/external/utils/index.ts +2 -0
- package/lib/__templates__/expo/client/heroui/helpers/internal/components/animated-check-icon.tsx +78 -0
- package/lib/__templates__/expo/client/heroui/helpers/internal/components/bottom-sheet-content-container.tsx +97 -0
- package/lib/__templates__/expo/client/heroui/helpers/internal/components/bottom-sheet-content.tsx +158 -0
- package/lib/__templates__/expo/client/heroui/helpers/internal/components/check-icon.tsx +28 -0
- package/lib/__templates__/expo/client/heroui/helpers/internal/components/chevron-down-icon.tsx +28 -0
- package/lib/__templates__/expo/client/heroui/helpers/internal/components/chevron-right-icon.tsx +29 -0
- package/lib/__templates__/expo/client/heroui/helpers/internal/components/close-icon.tsx +29 -0
- package/lib/__templates__/expo/client/heroui/helpers/internal/components/full-window-overlay.tsx +48 -0
- package/lib/__templates__/expo/client/heroui/helpers/internal/components/hero-text.tsx +71 -0
- package/lib/__templates__/expo/client/heroui/helpers/internal/components/index.ts +9 -0
- package/lib/__templates__/expo/client/heroui/helpers/internal/contexts/animation-settings-context.ts +19 -0
- package/lib/__templates__/expo/client/heroui/helpers/internal/contexts/bottom-sheet-is-dragging-context.ts +11 -0
- package/lib/__templates__/expo/client/heroui/helpers/internal/contexts/form-field-context.ts +36 -0
- package/lib/__templates__/expo/client/heroui/helpers/internal/contexts/index.ts +3 -0
- package/lib/__templates__/expo/client/heroui/helpers/internal/hooks/index.ts +14 -0
- package/lib/__templates__/expo/client/heroui/helpers/internal/hooks/use-augmented-ref.ts +32 -0
- package/lib/__templates__/expo/client/heroui/helpers/internal/hooks/use-bottom-sheet-aware-handlers.ts +94 -0
- package/lib/__templates__/expo/client/heroui/helpers/internal/hooks/use-bottom-sheet-gesture-handlers.ts +52 -0
- package/lib/__templates__/expo/client/heroui/helpers/internal/hooks/use-combined-animation-disabled-state.ts +49 -0
- package/lib/__templates__/expo/client/heroui/helpers/internal/hooks/use-controllable-state.ts +124 -0
- package/lib/__templates__/expo/client/heroui/helpers/internal/hooks/use-dev-info.ts +38 -0
- package/lib/__templates__/expo/client/heroui/helpers/internal/hooks/use-keyboard-status.ts +22 -0
- package/lib/__templates__/expo/client/heroui/helpers/internal/hooks/use-popup-bottom-sheet-content-animation.ts +67 -0
- package/lib/__templates__/expo/client/heroui/helpers/internal/hooks/use-popup-dialog-content-animation.ts +296 -0
- package/lib/__templates__/expo/client/heroui/helpers/internal/hooks/use-popup-overlay-animation.ts +91 -0
- package/lib/__templates__/expo/client/heroui/helpers/internal/hooks/use-popup-popover-content-animation.ts +199 -0
- package/lib/__templates__/expo/client/heroui/helpers/internal/hooks/use-popup-root-animation.ts +26 -0
- package/lib/__templates__/expo/client/heroui/helpers/internal/hooks/use-relative-position.ts +353 -0
- package/lib/__templates__/expo/client/heroui/helpers/internal/hooks/use-resolved-style-property.ts +118 -0
- package/lib/__templates__/expo/client/heroui/helpers/internal/types/animation.ts +131 -0
- package/lib/__templates__/expo/client/heroui/helpers/internal/types/bottom-sheet.ts +99 -0
- package/lib/__templates__/expo/client/heroui/helpers/internal/types/index.ts +5 -0
- package/lib/__templates__/expo/client/heroui/helpers/internal/types/misc.ts +10 -0
- package/lib/__templates__/expo/client/heroui/helpers/internal/types/primitives.ts +146 -0
- package/lib/__templates__/expo/client/heroui/helpers/internal/types/theme.ts +18 -0
- package/lib/__templates__/expo/client/heroui/helpers/internal/utils/animation.ts +266 -0
- package/lib/__templates__/expo/client/heroui/helpers/internal/utils/children-to-string.ts +117 -0
- package/lib/__templates__/expo/client/heroui/helpers/internal/utils/combine-styles.ts +17 -0
- package/lib/__templates__/expo/client/heroui/helpers/internal/utils/create-context.ts +60 -0
- package/lib/__templates__/expo/client/heroui/helpers/internal/utils/ease-gradient/create-interpolation.ts +35 -0
- package/lib/__templates__/expo/client/heroui/helpers/internal/utils/ease-gradient/index.ts +97 -0
- package/lib/__templates__/expo/client/heroui/helpers/internal/utils/get-element-by-display-name.ts +15 -0
- package/lib/__templates__/expo/client/heroui/helpers/internal/utils/get-element-with-default.ts +17 -0
- package/lib/__templates__/expo/client/heroui/helpers/internal/utils/has-prop.ts +18 -0
- package/lib/__templates__/expo/client/heroui/helpers/internal/utils/index.ts +8 -0
- package/lib/__templates__/expo/client/heroui/index.tsx +51 -0
- package/lib/__templates__/expo/client/heroui/primitives/README.md +27 -0
- package/lib/__templates__/expo/client/heroui/primitives/accordion/accordion.tsx +270 -0
- package/lib/__templates__/expo/client/heroui/primitives/accordion/accordion.types.ts +117 -0
- package/lib/__templates__/expo/client/heroui/primitives/accordion/accordion.utils.ts +12 -0
- package/lib/__templates__/expo/client/heroui/primitives/accordion/index.ts +2 -0
- package/lib/__templates__/expo/client/heroui/primitives/activity-indicator/activity-indicator.tsx +50 -0
- package/lib/__templates__/expo/client/heroui/primitives/activity-indicator/activity-indicator.types.ts +24 -0
- package/lib/__templates__/expo/client/heroui/primitives/activity-indicator/index.ts +2 -0
- package/lib/__templates__/expo/client/heroui/primitives/alert/alert.tsx +124 -0
- package/lib/__templates__/expo/client/heroui/primitives/alert/alert.types.ts +87 -0
- package/lib/__templates__/expo/client/heroui/primitives/alert/index.ts +2 -0
- package/lib/__templates__/expo/client/heroui/primitives/avatar/avatar.tsx +171 -0
- package/lib/__templates__/expo/client/heroui/primitives/avatar/avatar.types.ts +62 -0
- package/lib/__templates__/expo/client/heroui/primitives/avatar/avatar.utils.ts +102 -0
- package/lib/__templates__/expo/client/heroui/primitives/avatar/index.ts +2 -0
- package/lib/__templates__/expo/client/heroui/primitives/bottom-sheet/bottom-sheet.tsx +235 -0
- package/lib/__templates__/expo/client/heroui/primitives/bottom-sheet/bottom-sheet.types.ts +127 -0
- package/lib/__templates__/expo/client/heroui/primitives/bottom-sheet/index.ts +2 -0
- package/lib/__templates__/expo/client/heroui/primitives/checkbox/checkbox.tsx +119 -0
- package/lib/__templates__/expo/client/heroui/primitives/checkbox/checkbox.types.ts +37 -0
- package/lib/__templates__/expo/client/heroui/primitives/checkbox/index.ts +2 -0
- package/lib/__templates__/expo/client/heroui/primitives/dialog/dialog.tsx +274 -0
- package/lib/__templates__/expo/client/heroui/primitives/dialog/dialog.types.ts +129 -0
- package/lib/__templates__/expo/client/heroui/primitives/dialog/index.ts +2 -0
- package/lib/__templates__/expo/client/heroui/primitives/input-otp/index.ts +3 -0
- package/lib/__templates__/expo/client/heroui/primitives/input-otp/input-otp.tsx +431 -0
- package/lib/__templates__/expo/client/heroui/primitives/input-otp/input-otp.types.ts +169 -0
- package/lib/__templates__/expo/client/heroui/primitives/input-otp/input-otp.utils.ts +31 -0
- package/lib/__templates__/expo/client/heroui/primitives/label/index.ts +2 -0
- package/lib/__templates__/expo/client/heroui/primitives/label/label.tsx +24 -0
- package/lib/__templates__/expo/client/heroui/primitives/label/label.types.ts +39 -0
- package/lib/__templates__/expo/client/heroui/primitives/menu/index.ts +2 -0
- package/lib/__templates__/expo/client/heroui/primitives/menu/menu.tsx +765 -0
- package/lib/__templates__/expo/client/heroui/primitives/menu/menu.types.ts +401 -0
- package/lib/__templates__/expo/client/heroui/primitives/popover/index.ts +2 -0
- package/lib/__templates__/expo/client/heroui/primitives/popover/popover.tsx +382 -0
- package/lib/__templates__/expo/client/heroui/primitives/popover/popover.types.ts +201 -0
- package/lib/__templates__/expo/client/heroui/primitives/portal/index.ts +1 -0
- package/lib/__templates__/expo/client/heroui/primitives/portal/portal.tsx +126 -0
- package/lib/__templates__/expo/client/heroui/primitives/radio/index.ts +2 -0
- package/lib/__templates__/expo/client/heroui/primitives/radio/radio.tsx +133 -0
- package/lib/__templates__/expo/client/heroui/primitives/radio/radio.types.ts +47 -0
- package/lib/__templates__/expo/client/heroui/primitives/radio-group/index.ts +2 -0
- package/lib/__templates__/expo/client/heroui/primitives/radio-group/radio-group.tsx +114 -0
- package/lib/__templates__/expo/client/heroui/primitives/radio-group/radio-group.types.ts +65 -0
- package/lib/__templates__/expo/client/heroui/primitives/select/index.ts +2 -0
- package/lib/__templates__/expo/client/heroui/primitives/select/select.tsx +705 -0
- package/lib/__templates__/expo/client/heroui/primitives/select/select.types.ts +409 -0
- package/lib/__templates__/expo/client/heroui/primitives/select/select.utils.ts +35 -0
- package/lib/__templates__/expo/client/heroui/primitives/slider/index.ts +3 -0
- package/lib/__templates__/expo/client/heroui/primitives/slider/slider.tsx +463 -0
- package/lib/__templates__/expo/client/heroui/primitives/slider/slider.types.ts +208 -0
- package/lib/__templates__/expo/client/heroui/primitives/slider/slider.utils.ts +93 -0
- package/lib/__templates__/expo/client/heroui/primitives/slot/index.ts +1 -0
- package/lib/__templates__/expo/client/heroui/primitives/slot/slot.tsx +121 -0
- package/lib/__templates__/expo/client/heroui/primitives/slot/types.ts +19 -0
- package/lib/__templates__/expo/client/heroui/primitives/slot/utils.ts +96 -0
- package/lib/__templates__/expo/client/heroui/primitives/switch/index.ts +2 -0
- package/lib/__templates__/expo/client/heroui/primitives/switch/switch.tsx +61 -0
- package/lib/__templates__/expo/client/heroui/primitives/switch/switch.types.ts +55 -0
- package/lib/__templates__/expo/client/heroui/primitives/tabs/index.ts +2 -0
- package/lib/__templates__/expo/client/heroui/primitives/tabs/tabs.tsx +202 -0
- package/lib/__templates__/expo/client/heroui/primitives/tabs/tabs.types.ts +77 -0
- package/lib/__templates__/expo/client/heroui/primitives/tag-group/index.ts +2 -0
- package/lib/__templates__/expo/client/heroui/primitives/tag-group/tag-group.tsx +324 -0
- package/lib/__templates__/expo/client/heroui/primitives/tag-group/tag-group.types.ts +119 -0
- package/lib/__templates__/expo/client/heroui/primitives/toast/index.ts +2 -0
- package/lib/__templates__/expo/client/heroui/primitives/toast/toast.tsx +138 -0
- package/lib/__templates__/expo/client/heroui/primitives/toast/toast.types.ts +86 -0
- package/lib/__templates__/expo/client/heroui/providers/animation-settings/index.ts +8 -0
- package/lib/__templates__/expo/client/heroui/providers/animation-settings/provider.tsx +47 -0
- package/lib/__templates__/expo/client/heroui/providers/animation-settings/types.ts +27 -0
- package/lib/__templates__/expo/client/heroui/providers/hero-ui-native/index.ts +2 -0
- package/lib/__templates__/expo/client/heroui/providers/hero-ui-native/provider.tsx +67 -0
- package/lib/__templates__/expo/client/heroui/providers/hero-ui-native/types.ts +114 -0
- package/lib/__templates__/expo/client/heroui/providers/hero-ui-native-raw/index.ts +2 -0
- package/lib/__templates__/expo/client/heroui/providers/hero-ui-native-raw/provider.tsx +50 -0
- package/lib/__templates__/expo/client/heroui/providers/hero-ui-native-raw/types.ts +39 -0
- package/lib/__templates__/expo/client/heroui/providers/text-component/index.ts +2 -0
- package/lib/__templates__/expo/client/heroui/providers/text-component/provider.tsx +9 -0
- package/lib/__templates__/expo/client/heroui/providers/text-component/types.ts +52 -0
- package/lib/__templates__/expo/client/heroui/providers/toast/index.ts +3 -0
- package/lib/__templates__/expo/client/heroui/providers/toast/insets-container.tsx +87 -0
- package/lib/__templates__/expo/client/heroui/providers/toast/provider.tsx +431 -0
- package/lib/__templates__/expo/client/heroui/providers/toast/reducer.ts +34 -0
- package/lib/__templates__/expo/client/heroui/providers/toast/toast-config.context.ts +27 -0
- package/lib/__templates__/expo/client/heroui/providers/toast/toast-item-renderer.tsx +45 -0
- package/lib/__templates__/expo/client/heroui/providers/toast/types.ts +373 -0
- package/lib/__templates__/expo/client/heroui/styles/index.css +3 -0
- package/lib/__templates__/expo/client/heroui/styles/theme.css +112 -0
- package/lib/__templates__/expo/client/heroui/styles/utilities.css +8 -0
- package/lib/__templates__/expo/client/heroui/styles/variables.css +146 -0
- package/lib/__templates__/expo/client/hooks/useSafeRouter.ts +152 -0
- package/lib/__templates__/expo/client/metro.config.js +128 -0
- package/lib/__templates__/expo/client/package.json +100 -0
- package/lib/__templates__/expo/client/screens/demo/index.tsx +19 -0
- package/lib/__templates__/expo/client/scripts/install-missing-deps.js +1 -0
- package/lib/__templates__/expo/client/theme.css +263 -0
- package/lib/__templates__/expo/client/tsconfig.json +24 -0
- package/lib/__templates__/expo/client/uniwind-types.d.ts +10 -0
- package/lib/__templates__/expo/client/utils/index.ts +23 -2
- package/lib/__templates__/expo/eslint-plugins/fontawesome6/index.js +9 -0
- package/lib/__templates__/expo/eslint-plugins/fontawesome6/names.js +1889 -0
- package/lib/__templates__/expo/eslint-plugins/fontawesome6/rule.js +174 -0
- package/lib/__templates__/expo/eslint-plugins/fontawesome6/v5-only-names.js +388 -0
- package/lib/__templates__/expo/eslint-plugins/react-native/index.js +9 -0
- package/lib/__templates__/expo/eslint-plugins/react-native/rule.js +64 -0
- package/lib/__templates__/expo/eslint-plugins/reanimated/index.js +9 -0
- package/lib/__templates__/expo/eslint-plugins/reanimated/rule.js +88 -0
- package/lib/__templates__/expo/package.json +16 -103
- package/lib/__templates__/expo/patches/expo@54.0.33.patch +45 -0
- package/lib/__templates__/expo/pnpm-lock.yaml +1622 -3274
- package/lib/__templates__/expo/pnpm-workspace.yaml +3 -0
- package/lib/__templates__/expo/server/build.js +21 -0
- package/lib/__templates__/expo/server/package.json +34 -0
- package/lib/__templates__/expo/server/src/index.ts +20 -0
- package/lib/__templates__/expo/server/tsconfig.json +24 -0
- package/lib/__templates__/expo/template.config.js +58 -1
- package/lib/__templates__/expo/tsconfig.json +1 -24
- package/lib/__templates__/nextjs/.coze +4 -3
- package/lib/__templates__/nextjs/_npmrc +2 -1
- package/lib/__templates__/nextjs/next.config.ts +12 -0
- package/lib/__templates__/nextjs/package.json +17 -1
- package/lib/__templates__/nextjs/pnpm-lock.yaml +3352 -1083
- package/lib/__templates__/nextjs/scripts/dev.sh +8 -27
- package/lib/__templates__/nextjs/scripts/prepare.sh +9 -0
- package/lib/__templates__/nextjs/src/app/globals.css +109 -89
- package/lib/__templates__/nextjs/src/app/layout.tsx +19 -32
- package/lib/__templates__/nextjs/src/app/page.tsx +18 -48
- package/lib/__templates__/nextjs/src/components/ui/resizable.tsx +29 -22
- package/lib/__templates__/nextjs/src/components/ui/sidebar.tsx +228 -230
- package/lib/__templates__/nextjs/template.config.js +68 -3
- package/lib/__templates__/taro/.coze +14 -0
- package/lib/__templates__/taro/.cozeproj/scripts/deploy_build.sh +19 -0
- package/lib/__templates__/taro/.cozeproj/scripts/deploy_run.sh +14 -0
- package/lib/__templates__/taro/.cozeproj/scripts/dev_build.sh +2 -0
- package/lib/__templates__/taro/.cozeproj/scripts/dev_run.sh +80 -0
- package/lib/__templates__/taro/.cozeproj/scripts/init_env.sh +5 -0
- package/lib/__templates__/taro/.cozeproj/scripts/pack.sh +1 -0
- package/lib/__templates__/taro/README.md +747 -0
- package/lib/__templates__/taro/_gitignore +40 -0
- package/lib/__templates__/taro/_npmrc +18 -0
- package/lib/__templates__/taro/babel.config.js +12 -0
- package/lib/__templates__/taro/config/dev.ts +9 -0
- package/lib/__templates__/taro/config/index.ts +173 -0
- package/lib/__templates__/taro/config/prod.ts +35 -0
- package/lib/__templates__/taro/eslint.config.mjs +57 -0
- package/lib/__templates__/taro/key/private.appid.key +0 -0
- package/lib/__templates__/taro/package.json +97 -0
- package/lib/__templates__/taro/pnpm-lock.yaml +22708 -0
- package/lib/__templates__/taro/pnpm-workspace.yaml +2 -0
- package/lib/__templates__/taro/project.config.json +15 -0
- package/lib/__templates__/taro/server/nest-cli.json +10 -0
- package/lib/__templates__/taro/server/package.json +41 -0
- package/lib/__templates__/taro/server/src/app.controller.ts +23 -0
- package/lib/__templates__/taro/server/src/app.module.ts +10 -0
- package/lib/__templates__/taro/server/src/app.service.ts +8 -0
- package/lib/__templates__/taro/server/src/interceptors/http-status.interceptor.ts +23 -0
- package/lib/__templates__/taro/server/src/main.ts +49 -0
- package/lib/__templates__/taro/server/tsconfig.json +24 -0
- package/lib/__templates__/taro/src/app.config.ts +11 -0
- package/lib/__templates__/taro/src/app.css +52 -0
- package/lib/__templates__/taro/src/app.ts +14 -0
- package/lib/__templates__/taro/src/index.html +39 -0
- package/lib/__templates__/taro/src/network.ts +39 -0
- package/lib/__templates__/taro/src/pages/index/index.config.ts +3 -0
- package/lib/__templates__/taro/src/pages/index/index.css +1 -0
- package/lib/__templates__/taro/src/pages/index/index.tsx +33 -0
- package/lib/__templates__/taro/src/utils/h5-styles.ts +33 -0
- package/lib/__templates__/taro/src/utils/wx-debug.ts +23 -0
- package/lib/__templates__/taro/stylelint.config.mjs +4 -0
- package/lib/__templates__/taro/template.config.js +68 -0
- package/lib/__templates__/taro/tsconfig.json +29 -0
- package/lib/__templates__/taro/types/global.d.ts +32 -0
- package/lib/__templates__/templates.json +93 -36
- package/lib/__templates__/vite/.coze +4 -3
- package/lib/__templates__/vite/README.md +204 -26
- package/lib/__templates__/vite/_npmrc +2 -1
- package/lib/__templates__/vite/eslint.config.mjs +9 -0
- package/lib/__templates__/vite/package.json +15 -2
- package/lib/__templates__/vite/pnpm-lock.yaml +1697 -221
- package/lib/__templates__/vite/scripts/dev.sh +7 -26
- package/lib/__templates__/vite/scripts/prepare.sh +9 -0
- package/lib/__templates__/vite/src/main.ts +17 -48
- package/lib/__templates__/vite/template.config.js +77 -7
- package/lib/__templates__/vite/vite.config.ts +3 -3
- package/lib/cli.js +1510 -512
- package/package.json +10 -4
- package/lib/__templates__/expo/.cozeproj/scripts/deploy_build.sh +0 -115
- package/lib/__templates__/expo/.cozeproj/scripts/deploy_run.sh +0 -271
- package/lib/__templates__/expo/app.json +0 -63
- package/lib/__templates__/expo/babel.config.js +0 -9
- package/lib/__templates__/expo/client/app/(tabs)/_layout.tsx +0 -43
- package/lib/__templates__/expo/client/app/(tabs)/home.tsx +0 -1
- package/lib/__templates__/expo/client/app/(tabs)/index.tsx +0 -7
- package/lib/__templates__/expo/client/constants/theme.ts +0 -118
- package/lib/__templates__/expo/client/hooks/useColorScheme.ts +0 -1
- package/lib/__templates__/expo/client/hooks/useTheme.ts +0 -13
- package/lib/__templates__/expo/client/index.js +0 -12
- package/lib/__templates__/expo/client/screens/home/index.tsx +0 -54
- package/lib/__templates__/expo/client/screens/home/styles.ts +0 -332
- package/lib/__templates__/expo/metro.config.js +0 -53
- package/lib/__templates__/expo/src/index.ts +0 -12
- package/lib/__templates__/nextjs/.vscode/settings.json +0 -121
- package/lib/__templates__/nextjs/server.mjs +0 -50
- package/lib/__templates__/vite/.vscode/settings.json +0 -7
- /package/lib/__templates__/expo/{eslint-formatter-simple.mjs → client/eslint-formatter-simple.mjs} +0 -0
package/lib/cli.js
CHANGED
|
@@ -5,12 +5,15 @@ var commander = require('commander');
|
|
|
5
5
|
var path = require('path');
|
|
6
6
|
var fs = require('fs');
|
|
7
7
|
var shelljs = require('shelljs');
|
|
8
|
+
var perf_hooks = require('perf_hooks');
|
|
8
9
|
var fs$1 = require('fs/promises');
|
|
9
|
-
var
|
|
10
|
+
var os = require('os');
|
|
10
11
|
var jsYaml = require('js-yaml');
|
|
11
|
-
var
|
|
12
|
+
var toml = require('@iarna/toml');
|
|
13
|
+
var child_process = require('child_process');
|
|
12
14
|
var addFormats = require('ajv-formats');
|
|
13
15
|
var Ajv = require('ajv');
|
|
16
|
+
var minimist = require('minimist');
|
|
14
17
|
var changeCase = require('change-case');
|
|
15
18
|
var ejs = require('ejs');
|
|
16
19
|
|
|
@@ -124,7 +127,7 @@ const generateTemplatesHelpText = () => {
|
|
|
124
127
|
return lines.join('\n');
|
|
125
128
|
};
|
|
126
129
|
|
|
127
|
-
function _nullishCoalesce$2(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain$
|
|
130
|
+
function _nullishCoalesce$2(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain$3(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var LogLevel; (function (LogLevel) {
|
|
128
131
|
const ERROR = 0; LogLevel[LogLevel["ERROR"] = ERROR] = "ERROR";
|
|
129
132
|
const WARN = 1; LogLevel[LogLevel["WARN"] = WARN] = "WARN";
|
|
130
133
|
const SUCCESS = 2; LogLevel[LogLevel["SUCCESS"] = SUCCESS] = "SUCCESS";
|
|
@@ -171,7 +174,7 @@ class Logger {
|
|
|
171
174
|
return level;
|
|
172
175
|
}
|
|
173
176
|
|
|
174
|
-
const envLevel = _optionalChain$
|
|
177
|
+
const envLevel = _optionalChain$3([process, 'access', _ => _.env, 'access', _2 => _2.LOG_LEVEL, 'optionalAccess', _3 => _3.toLowerCase, 'call', _4 => _4()]);
|
|
175
178
|
if (envLevel && envLevel in LOG_LEVEL_MAP) {
|
|
176
179
|
return LOG_LEVEL_MAP[envLevel];
|
|
177
180
|
}
|
|
@@ -183,7 +186,7 @@ class Logger {
|
|
|
183
186
|
// 简单检测:Node.js 环境且支持 TTY
|
|
184
187
|
return (
|
|
185
188
|
typeof process !== 'undefined' &&
|
|
186
|
-
_optionalChain$
|
|
189
|
+
_optionalChain$3([process, 'access', _5 => _5.stdout, 'optionalAccess', _6 => _6.isTTY]) === true &&
|
|
187
190
|
process.env.NO_COLOR === undefined
|
|
188
191
|
);
|
|
189
192
|
}
|
|
@@ -269,123 +272,446 @@ const createLogger = (options = {}) =>
|
|
|
269
272
|
// 导出默认实例
|
|
270
273
|
const logger = createLogger();
|
|
271
274
|
|
|
272
|
-
function _optionalChain$3(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
273
|
-
// Safe JSON parsing utilities with type safety and error handling
|
|
274
|
-
// Provides fallback values, validation, and error monitoring capabilities
|
|
275
|
-
|
|
276
275
|
/**
|
|
277
|
-
*
|
|
276
|
+
* 时间统计工具
|
|
278
277
|
*/
|
|
278
|
+
class TimeTracker {
|
|
279
|
+
|
|
280
|
+
|
|
279
281
|
|
|
282
|
+
constructor() {
|
|
283
|
+
this.startTime = perf_hooks.performance.now();
|
|
284
|
+
this.lastTime = this.startTime;
|
|
285
|
+
}
|
|
280
286
|
|
|
287
|
+
/**
|
|
288
|
+
* 记录阶段耗时
|
|
289
|
+
* @param phaseName 阶段名称
|
|
290
|
+
*/
|
|
291
|
+
logPhase(phaseName) {
|
|
292
|
+
const now = perf_hooks.performance.now();
|
|
293
|
+
const phaseTime = now - this.lastTime;
|
|
294
|
+
this.lastTime = now;
|
|
281
295
|
|
|
296
|
+
logger.verbose(`⏱ ${phaseName}: ${phaseTime.toFixed(2)}ms`);
|
|
297
|
+
}
|
|
282
298
|
|
|
299
|
+
/**
|
|
300
|
+
* 记录总耗时
|
|
301
|
+
*/
|
|
302
|
+
logTotal() {
|
|
303
|
+
const totalTime = perf_hooks.performance.now() - this.startTime;
|
|
304
|
+
logger.verbose(`⏱ Total time: ${totalTime.toFixed(2)}ms`);
|
|
305
|
+
}
|
|
283
306
|
|
|
307
|
+
/**
|
|
308
|
+
* 获取当前耗时(不输出日志)
|
|
309
|
+
* @returns 从开始到现在的总耗时(毫秒)
|
|
310
|
+
*/
|
|
311
|
+
getElapsedTime() {
|
|
312
|
+
return perf_hooks.performance.now() - this.startTime;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
284
315
|
|
|
316
|
+
/**
|
|
317
|
+
* 获取模板配置文件路径
|
|
318
|
+
* @returns templates.json 的绝对路径
|
|
319
|
+
*/
|
|
320
|
+
const getTemplatesConfigPath = () => {
|
|
321
|
+
const configPath = path.resolve(getTemplatesDir(), 'templates.json');
|
|
322
|
+
logger.verbose(`Templates config path: ${configPath}`);
|
|
323
|
+
logger.verbose(`Config file exists: ${fs.existsSync(configPath)}`);
|
|
324
|
+
return configPath;
|
|
325
|
+
};
|
|
285
326
|
|
|
327
|
+
/**
|
|
328
|
+
* 获取模板目录路径
|
|
329
|
+
* @returns __templates__ 目录的绝对路径
|
|
330
|
+
*/
|
|
331
|
+
const getTemplatesDir = () => {
|
|
332
|
+
const templatesDir = path.resolve(__dirname, './__templates__');
|
|
333
|
+
logger.verbose(`Templates directory: ${templatesDir}`);
|
|
334
|
+
logger.verbose(`Templates directory exists: ${fs.existsSync(templatesDir)}`);
|
|
335
|
+
return templatesDir;
|
|
336
|
+
};
|
|
286
337
|
|
|
338
|
+
/**
|
|
339
|
+
* 加载模板配置文件
|
|
340
|
+
* 支持 .ts 和 .js 文件(通过 sucrase 注册)
|
|
341
|
+
*
|
|
342
|
+
* @param templatePath - 模板目录路径
|
|
343
|
+
* @returns 模板配置对象
|
|
344
|
+
*/
|
|
287
345
|
|
|
346
|
+
const loadTemplateConfig = async (
|
|
347
|
+
templatePath,
|
|
348
|
+
) => {
|
|
349
|
+
logger.verbose(`Loading template config from: ${templatePath}`);
|
|
288
350
|
|
|
351
|
+
const tsConfigPath = path.join(templatePath, 'template.config.ts');
|
|
352
|
+
const jsConfigPath = path.join(templatePath, 'template.config.js');
|
|
289
353
|
|
|
354
|
+
logger.verbose('Checking for config files:');
|
|
355
|
+
logger.verbose(` - TypeScript: ${tsConfigPath}`);
|
|
356
|
+
logger.verbose(` - JavaScript: ${jsConfigPath}`);
|
|
290
357
|
|
|
358
|
+
let configPath;
|
|
291
359
|
|
|
360
|
+
const [tsExists, jsExists] = await Promise.all([
|
|
361
|
+
fs$1.access(tsConfigPath).then(
|
|
362
|
+
() => true,
|
|
363
|
+
() => false,
|
|
364
|
+
),
|
|
365
|
+
fs$1.access(jsConfigPath).then(
|
|
366
|
+
() => true,
|
|
367
|
+
() => false,
|
|
368
|
+
),
|
|
369
|
+
]);
|
|
292
370
|
|
|
371
|
+
logger.verbose('Config file existence check:');
|
|
372
|
+
logger.verbose(` - template.config.ts: ${tsExists}`);
|
|
373
|
+
logger.verbose(` - template.config.js: ${jsExists}`);
|
|
293
374
|
|
|
375
|
+
if (tsExists) {
|
|
376
|
+
configPath = tsConfigPath;
|
|
377
|
+
} else if (jsExists) {
|
|
378
|
+
configPath = jsConfigPath;
|
|
379
|
+
} else {
|
|
380
|
+
throw new Error(
|
|
381
|
+
`Template config not found in ${templatePath}.\n` +
|
|
382
|
+
'Expected: template.config.ts or template.config.js',
|
|
383
|
+
);
|
|
384
|
+
}
|
|
294
385
|
|
|
386
|
+
logger.verbose(`Using config file: ${configPath}`);
|
|
295
387
|
|
|
388
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports, security/detect-non-literal-require -- Sucrase handles .ts files at runtime, path is validated above
|
|
389
|
+
const config = require(configPath);
|
|
296
390
|
|
|
391
|
+
logger.verbose('Template config loaded successfully');
|
|
297
392
|
|
|
393
|
+
return config.default || config;
|
|
394
|
+
};
|
|
298
395
|
|
|
396
|
+
/**
|
|
397
|
+
* 加载模板列表配置
|
|
398
|
+
*
|
|
399
|
+
* @param configPath - templates.json 配置文件路径
|
|
400
|
+
* @returns 模板列表配置
|
|
401
|
+
*/
|
|
402
|
+
const loadTemplatesConfig = async (
|
|
403
|
+
configPath,
|
|
404
|
+
) => {
|
|
405
|
+
logger.verbose(`Loading templates config from: ${configPath}`);
|
|
299
406
|
|
|
407
|
+
const content = await fs$1.readFile(configPath, 'utf-8');
|
|
408
|
+
// eslint-disable-next-line no-restricted-syntax -- Static config file loaded at build time, safeJsonParse not needed
|
|
409
|
+
const config = JSON.parse(content) ;
|
|
300
410
|
|
|
411
|
+
logger.verbose(
|
|
412
|
+
`Found ${config.templates.length} templates: ${config.templates.map(t => t.name).join(', ')}`,
|
|
413
|
+
);
|
|
301
414
|
|
|
415
|
+
return config;
|
|
416
|
+
};
|
|
302
417
|
|
|
418
|
+
/**
|
|
419
|
+
* 根据模板名称查找模板元信息
|
|
420
|
+
*
|
|
421
|
+
* @param templatesConfig - 模板列表配置
|
|
422
|
+
* @param templateName - 模板名称
|
|
423
|
+
* @returns 模板元信息
|
|
424
|
+
*/
|
|
425
|
+
const findTemplate = (
|
|
426
|
+
templatesConfig,
|
|
427
|
+
templateName,
|
|
428
|
+
) => {
|
|
429
|
+
const template = templatesConfig.templates.find(t => t.name === templateName);
|
|
303
430
|
|
|
431
|
+
if (!template) {
|
|
432
|
+
const availableTemplates = templatesConfig.templates
|
|
433
|
+
.map(t => t.name)
|
|
434
|
+
.join(', ');
|
|
435
|
+
throw new Error(
|
|
436
|
+
`Template "${templateName}" not found.\n` +
|
|
437
|
+
`Available templates: ${availableTemplates}\n` +
|
|
438
|
+
'Use --template <name> to specify a template.',
|
|
439
|
+
);
|
|
440
|
+
}
|
|
304
441
|
|
|
442
|
+
return template;
|
|
443
|
+
};
|
|
305
444
|
|
|
445
|
+
/**
|
|
446
|
+
* 获取模板的完整路径
|
|
447
|
+
*
|
|
448
|
+
* @param basePath - 模板目录(templates.json 所在目录)
|
|
449
|
+
* @param templateMetadata - 模板元信息
|
|
450
|
+
* @returns 模板完整路径
|
|
451
|
+
*/
|
|
452
|
+
const getTemplatePath = async (
|
|
453
|
+
basePath,
|
|
454
|
+
templateMetadata,
|
|
455
|
+
) => {
|
|
456
|
+
logger.verbose('Resolving template path:');
|
|
457
|
+
logger.verbose(` - Base path: ${basePath}`);
|
|
458
|
+
logger.verbose(` - Template location: ${templateMetadata.location}`);
|
|
306
459
|
|
|
460
|
+
// location 是相对于 templates.json 文件的路径
|
|
461
|
+
const templatePath = path.join(basePath, templateMetadata.location);
|
|
307
462
|
|
|
463
|
+
logger.verbose(` - Resolved path: ${templatePath}`);
|
|
308
464
|
|
|
465
|
+
try {
|
|
466
|
+
await fs$1.access(templatePath);
|
|
467
|
+
logger.verbose(' - Template directory exists: ✓');
|
|
468
|
+
// eslint-disable-next-line @coze-arch/use-error-in-catch -- Error handling done in throw statement
|
|
469
|
+
} catch (e) {
|
|
470
|
+
logger.error(' - Template directory does not exist: ✗');
|
|
471
|
+
throw new Error(`Template directory not found: ${templatePath}`);
|
|
472
|
+
}
|
|
309
473
|
|
|
474
|
+
return templatePath;
|
|
475
|
+
};
|
|
310
476
|
|
|
311
477
|
/**
|
|
312
|
-
*
|
|
313
|
-
*
|
|
314
|
-
* @example
|
|
315
|
-
* ```ts
|
|
316
|
-
* // Basic usage - returns unknown | undefined
|
|
317
|
-
* const data = safeJsonParse('{"a":1}'); // { a: 1 }
|
|
318
|
-
*
|
|
319
|
-
* // With default value - always returns T
|
|
320
|
-
* const config = safeJsonParse(str, {});
|
|
321
|
-
* const user = safeJsonParse(str, null);
|
|
322
|
-
*
|
|
323
|
-
* // With error reporting
|
|
324
|
-
* const data = safeJsonParse(input, null, {
|
|
325
|
-
* onError: (error, input) => logger.error('Parse failed', { error, input })
|
|
326
|
-
* });
|
|
327
|
-
*
|
|
328
|
-
* // With validation
|
|
329
|
-
* const isUser = (data: unknown): data is User => ...;
|
|
330
|
-
* const user = safeJsonParse<User>(input, null, { validate: isUser });
|
|
331
|
-
* ```
|
|
478
|
+
* 对单个模板执行 pnpm install
|
|
332
479
|
*/
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
optionsArg,
|
|
337
|
-
) {
|
|
338
|
-
// Parse arguments
|
|
339
|
-
let defaultValue;
|
|
340
|
-
let options;
|
|
480
|
+
const warmupTemplate = (templatePath, templateName) => {
|
|
481
|
+
logger.info(`\nWarming up template: ${templateName}`);
|
|
482
|
+
logger.info(` Path: ${templatePath}`);
|
|
341
483
|
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
defaultValue = defaultValueOrOptions ;
|
|
351
|
-
options = optionsArg;
|
|
484
|
+
const result = shelljs.exec('pnpm install', {
|
|
485
|
+
cwd: templatePath,
|
|
486
|
+
silent: true,
|
|
487
|
+
});
|
|
488
|
+
|
|
489
|
+
// 输出 stdout
|
|
490
|
+
if (result.stdout) {
|
|
491
|
+
process.stdout.write(result.stdout);
|
|
352
492
|
}
|
|
353
493
|
|
|
354
|
-
//
|
|
355
|
-
if (
|
|
356
|
-
|
|
494
|
+
// 输出 stderr
|
|
495
|
+
if (result.stderr) {
|
|
496
|
+
process.stderr.write(result.stderr);
|
|
357
497
|
}
|
|
358
498
|
|
|
359
|
-
|
|
360
|
-
|
|
499
|
+
if (result.code === 0) {
|
|
500
|
+
logger.success(` ✓ ${templateName} warmed up successfully`);
|
|
501
|
+
} else {
|
|
502
|
+
const errorMessage = [
|
|
503
|
+
`pnpm install failed for ${templateName} with exit code ${result.code}`,
|
|
504
|
+
result.stderr ? `\nStderr:\n${result.stderr}` : '',
|
|
505
|
+
result.stdout ? `\nStdout:\n${result.stdout}` : '',
|
|
506
|
+
]
|
|
507
|
+
.filter(Boolean)
|
|
508
|
+
.join('');
|
|
361
509
|
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
return parsed;
|
|
366
|
-
} else {
|
|
367
|
-
const validationError = new Error('JSON validation failed');
|
|
368
|
-
_optionalChain$3([options, 'access', _2 => _2.onError, 'optionalCall', _3 => _3(validationError, input)]);
|
|
510
|
+
throw new Error(errorMessage);
|
|
511
|
+
}
|
|
512
|
+
};
|
|
369
513
|
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
}
|
|
514
|
+
/**
|
|
515
|
+
* 执行 warmup 命令的内部实现
|
|
516
|
+
*/
|
|
517
|
+
const executeWarmup = async (
|
|
518
|
+
options
|
|
376
519
|
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
520
|
+
,
|
|
521
|
+
|
|
522
|
+
command,
|
|
523
|
+
) => {
|
|
524
|
+
const timer = new TimeTracker();
|
|
525
|
+
|
|
526
|
+
try {
|
|
527
|
+
const { template: templateFilter } = options;
|
|
528
|
+
|
|
529
|
+
logger.info('Starting template warmup...');
|
|
530
|
+
timer.logPhase('Initialization');
|
|
531
|
+
|
|
532
|
+
// 加载模板配置
|
|
533
|
+
const configPath = getTemplatesConfigPath();
|
|
534
|
+
const templatesConfig = await loadTemplatesConfig(configPath);
|
|
535
|
+
|
|
536
|
+
logger.verbose(
|
|
537
|
+
`Found ${templatesConfig.templates.length} templates in config`,
|
|
538
|
+
);
|
|
539
|
+
|
|
540
|
+
// 过滤模板
|
|
541
|
+
const templatesToWarmup = templateFilter
|
|
542
|
+
? templatesConfig.templates.filter(t => t.name === templateFilter)
|
|
543
|
+
: templatesConfig.templates;
|
|
544
|
+
|
|
545
|
+
if (templatesToWarmup.length === 0) {
|
|
546
|
+
if (templateFilter) {
|
|
547
|
+
logger.warn(`Template "${templateFilter}" not found`);
|
|
548
|
+
logger.info(
|
|
549
|
+
`Available templates: ${templatesConfig.templates.map(t => t.name).join(', ')}`,
|
|
550
|
+
);
|
|
551
|
+
} else {
|
|
552
|
+
logger.warn('No templates found');
|
|
553
|
+
}
|
|
554
|
+
return;
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
logger.info(
|
|
558
|
+
`\nWill warm up ${templatesToWarmup.length} template(s): ${templatesToWarmup.map(t => t.name).join(', ')}`,
|
|
559
|
+
);
|
|
560
|
+
|
|
561
|
+
// 获取模板基础路径
|
|
562
|
+
const basePath = configPath.replace(/\/templates\.json$/, '');
|
|
563
|
+
|
|
564
|
+
// 对每个模板执行 pnpm install
|
|
565
|
+
for (const templateMetadata of templatesToWarmup) {
|
|
566
|
+
const templatePath = await getTemplatePath(basePath, templateMetadata);
|
|
567
|
+
warmupTemplate(templatePath, templateMetadata.name);
|
|
568
|
+
timer.logPhase(`Warmup ${templateMetadata.name}`);
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
logger.success('\n✅ All templates warmed up successfully!');
|
|
572
|
+
logger.info(
|
|
573
|
+
'\nNext time you run `coze init`, it will be much faster as node_modules are pre-installed.',
|
|
574
|
+
);
|
|
575
|
+
|
|
576
|
+
timer.logTotal();
|
|
577
|
+
} catch (error) {
|
|
578
|
+
timer.logTotal();
|
|
579
|
+
logger.error('Failed to warmup templates:');
|
|
580
|
+
logger.error(error instanceof Error ? error.message : String(error));
|
|
581
|
+
process.exit(1);
|
|
582
|
+
}
|
|
583
|
+
};
|
|
584
|
+
|
|
585
|
+
/**
|
|
586
|
+
* 注册 warmup 命令到 program
|
|
587
|
+
*/
|
|
588
|
+
const registerCommand$4 = program => {
|
|
589
|
+
program
|
|
590
|
+
.command('warmup')
|
|
591
|
+
.description('Pre-install dependencies for templates to speed up init')
|
|
592
|
+
.option('-t, --template <name>', 'Warmup a specific template only')
|
|
593
|
+
.action(async (options, command) => {
|
|
594
|
+
await executeWarmup(options);
|
|
595
|
+
});
|
|
596
|
+
};
|
|
597
|
+
|
|
598
|
+
function _optionalChain$2(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
599
|
+
// Safe JSON parsing utilities with type safety and error handling
|
|
600
|
+
// Provides fallback values, validation, and error monitoring capabilities
|
|
601
|
+
|
|
602
|
+
/**
|
|
603
|
+
* Options for safe JSON parsing
|
|
604
|
+
*/
|
|
605
|
+
|
|
606
|
+
|
|
607
|
+
|
|
608
|
+
|
|
609
|
+
|
|
610
|
+
|
|
611
|
+
|
|
612
|
+
|
|
613
|
+
|
|
614
|
+
|
|
615
|
+
|
|
616
|
+
|
|
617
|
+
|
|
618
|
+
|
|
619
|
+
|
|
620
|
+
|
|
621
|
+
|
|
622
|
+
|
|
623
|
+
|
|
624
|
+
|
|
625
|
+
|
|
626
|
+
|
|
627
|
+
|
|
628
|
+
|
|
629
|
+
|
|
630
|
+
|
|
631
|
+
|
|
632
|
+
|
|
633
|
+
|
|
634
|
+
|
|
635
|
+
|
|
636
|
+
|
|
637
|
+
/**
|
|
638
|
+
* Safely parse JSON with error handling and type safety
|
|
639
|
+
*
|
|
640
|
+
* @example
|
|
641
|
+
* ```ts
|
|
642
|
+
* // Basic usage - returns unknown | undefined
|
|
643
|
+
* const data = safeJsonParse('{"a":1}'); // { a: 1 }
|
|
644
|
+
*
|
|
645
|
+
* // With default value - always returns T
|
|
646
|
+
* const config = safeJsonParse(str, {});
|
|
647
|
+
* const user = safeJsonParse(str, null);
|
|
648
|
+
*
|
|
649
|
+
* // With error reporting
|
|
650
|
+
* const data = safeJsonParse(input, null, {
|
|
651
|
+
* onError: (error, input) => logger.error('Parse failed', { error, input })
|
|
652
|
+
* });
|
|
653
|
+
*
|
|
654
|
+
* // With validation
|
|
655
|
+
* const isUser = (data: unknown): data is User => ...;
|
|
656
|
+
* const user = safeJsonParse<User>(input, null, { validate: isUser });
|
|
657
|
+
* ```
|
|
658
|
+
*/
|
|
659
|
+
function safeJsonParse(
|
|
660
|
+
input,
|
|
661
|
+
defaultValueOrOptions,
|
|
662
|
+
optionsArg,
|
|
663
|
+
) {
|
|
664
|
+
// Parse arguments
|
|
665
|
+
let defaultValue;
|
|
666
|
+
let options;
|
|
667
|
+
|
|
668
|
+
if (arguments.length === 2) {
|
|
669
|
+
// safeJsonParse(input, options) or safeJsonParse(input, defaultValue)
|
|
670
|
+
{
|
|
671
|
+
defaultValue = defaultValueOrOptions ;
|
|
672
|
+
options = undefined;
|
|
673
|
+
}
|
|
674
|
+
} else if (arguments.length === 3) {
|
|
675
|
+
// safeJsonParse(input, defaultValue, options)
|
|
676
|
+
defaultValue = defaultValueOrOptions ;
|
|
677
|
+
options = optionsArg;
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
// If input is already an object (and not null), return it directly
|
|
681
|
+
if (typeof input === 'object' && input !== null) {
|
|
682
|
+
return input ;
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
try {
|
|
686
|
+
const parsed = JSON.parse(String(input));
|
|
687
|
+
|
|
688
|
+
// Optional validation
|
|
689
|
+
if (_optionalChain$2([options, 'optionalAccess', _ => _.validate])) {
|
|
690
|
+
if (options.validate(parsed)) {
|
|
691
|
+
return parsed;
|
|
692
|
+
} else {
|
|
693
|
+
const validationError = new Error('JSON validation failed');
|
|
694
|
+
_optionalChain$2([options, 'access', _2 => _2.onError, 'optionalCall', _3 => _3(validationError, input)]);
|
|
695
|
+
|
|
696
|
+
if (options.throwOnValidationError) {
|
|
697
|
+
throw validationError;
|
|
698
|
+
}
|
|
699
|
+
return defaultValue;
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
return parsed;
|
|
704
|
+
} catch (error) {
|
|
705
|
+
// Re-throw validation errors when throwOnValidationError is true
|
|
706
|
+
if (error instanceof Error && error.message === 'JSON validation failed' && _optionalChain$2([options, 'optionalAccess', _4 => _4.throwOnValidationError])) {
|
|
381
707
|
throw error;
|
|
382
708
|
}
|
|
383
|
-
_optionalChain$
|
|
709
|
+
_optionalChain$2([options, 'optionalAccess', _5 => _5.onError, 'optionalCall', _6 => _6(error , input)]);
|
|
384
710
|
return defaultValue;
|
|
385
711
|
}
|
|
386
712
|
}
|
|
387
713
|
|
|
388
|
-
function _optionalChain$
|
|
714
|
+
function _optionalChain$1(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
389
715
|
|
|
390
716
|
|
|
391
717
|
/**
|
|
@@ -401,7 +727,7 @@ const parseConfigContent = (content) => {
|
|
|
401
727
|
return config ;
|
|
402
728
|
} catch (error) {
|
|
403
729
|
// TOML 解析失败,继续尝试其他格式
|
|
404
|
-
|
|
730
|
+
|
|
405
731
|
console.debug('TOML parse failed:', error);
|
|
406
732
|
}
|
|
407
733
|
|
|
@@ -413,7 +739,7 @@ const parseConfigContent = (content) => {
|
|
|
413
739
|
}
|
|
414
740
|
} catch (error) {
|
|
415
741
|
// YAML 解析失败,继续尝试其他格式
|
|
416
|
-
|
|
742
|
+
|
|
417
743
|
console.debug('YAML parse failed:', error);
|
|
418
744
|
}
|
|
419
745
|
|
|
@@ -475,13 +801,13 @@ const getCommandConfig = (
|
|
|
475
801
|
// 根据命令名称映射到配置路径
|
|
476
802
|
switch (commandName) {
|
|
477
803
|
case 'dev':
|
|
478
|
-
commandConfig = _optionalChain$
|
|
804
|
+
commandConfig = _optionalChain$1([config, 'access', _ => _.dev, 'optionalAccess', _2 => _2.run]);
|
|
479
805
|
break;
|
|
480
806
|
case 'build':
|
|
481
|
-
commandConfig = _optionalChain$
|
|
807
|
+
commandConfig = _optionalChain$1([config, 'access', _3 => _3.deploy, 'optionalAccess', _4 => _4.build]);
|
|
482
808
|
break;
|
|
483
809
|
case 'start':
|
|
484
|
-
commandConfig = _optionalChain$
|
|
810
|
+
commandConfig = _optionalChain$1([config, 'access', _5 => _5.deploy, 'optionalAccess', _6 => _6.run]);
|
|
485
811
|
break;
|
|
486
812
|
default:
|
|
487
813
|
throw new Error(`Unknown command: ${commandName}`);
|
|
@@ -497,27 +823,276 @@ const getCommandConfig = (
|
|
|
497
823
|
return commandConfig;
|
|
498
824
|
};
|
|
499
825
|
|
|
500
|
-
|
|
826
|
+
// ABOUTME: Fix rule to comment out problematic outputFileTracingRoot config in Next.js projects
|
|
827
|
+
// ABOUTME: This config can cause issues in monorepo environments and should be removed
|
|
828
|
+
|
|
829
|
+
|
|
830
|
+
|
|
501
831
|
|
|
502
832
|
/**
|
|
503
|
-
*
|
|
833
|
+
* 检查是否为 Next.js 项目
|
|
504
834
|
*/
|
|
505
|
-
const
|
|
506
|
-
const
|
|
507
|
-
|
|
508
|
-
|
|
835
|
+
const isNextProject = (projectFolder) => {
|
|
836
|
+
const packageJsonPath = path.join(projectFolder, 'package.json');
|
|
837
|
+
|
|
838
|
+
if (!fs.existsSync(packageJsonPath)) {
|
|
839
|
+
return false;
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
try {
|
|
843
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
844
|
+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
|
|
845
|
+
const deps = {
|
|
846
|
+
...packageJson.dependencies,
|
|
847
|
+
...packageJson.devDependencies,
|
|
848
|
+
};
|
|
849
|
+
|
|
850
|
+
return 'next' in deps;
|
|
851
|
+
} catch (e) {
|
|
852
|
+
return false;
|
|
853
|
+
}
|
|
854
|
+
};
|
|
855
|
+
|
|
856
|
+
/**
|
|
857
|
+
* 查找 Next.js 配置文件
|
|
858
|
+
*/
|
|
859
|
+
const findNextConfigFile = (projectFolder) => {
|
|
860
|
+
const possibleConfigs = [
|
|
861
|
+
'next.config.ts',
|
|
862
|
+
'next.config.js',
|
|
863
|
+
'next.config.mjs',
|
|
864
|
+
];
|
|
865
|
+
|
|
866
|
+
for (const configFile of possibleConfigs) {
|
|
867
|
+
const configPath = path.join(projectFolder, configFile);
|
|
868
|
+
if (fs.existsSync(configPath)) {
|
|
869
|
+
return configPath;
|
|
509
870
|
}
|
|
510
|
-
}
|
|
871
|
+
}
|
|
872
|
+
|
|
873
|
+
return null;
|
|
874
|
+
};
|
|
875
|
+
|
|
876
|
+
/**
|
|
877
|
+
* 注释掉 outputFileTracingRoot 配置
|
|
878
|
+
*/
|
|
879
|
+
const commentOutOutputTracingRoot = (
|
|
880
|
+
configPath,
|
|
881
|
+
) => {
|
|
882
|
+
let content = fs.readFileSync(configPath, 'utf-8');
|
|
883
|
+
let modified = false;
|
|
884
|
+
let originalLine = null;
|
|
885
|
+
|
|
886
|
+
// 匹配包含 outputFileTracingRoot 的行(尚未被注释的)
|
|
887
|
+
// 支持 path.resolve(...) 后面有空格,然后可选逗号
|
|
888
|
+
// 只匹配单行配置,不匹配跨多行的配置
|
|
889
|
+
const pattern =
|
|
890
|
+
/^(\s*)(outputFileTracingRoot:\s*path\.resolve\([^\n\r)]+\)\s*,?)\s*$/gm;
|
|
891
|
+
|
|
892
|
+
const matches = content.match(pattern);
|
|
893
|
+
|
|
894
|
+
if (matches && matches.length > 0) {
|
|
895
|
+
originalLine = matches[0].trim();
|
|
511
896
|
|
|
512
|
-
|
|
897
|
+
// 在匹配的行前添加 // 注释
|
|
898
|
+
content = content.replace(pattern, '$1// $2');
|
|
899
|
+
modified = true;
|
|
900
|
+
|
|
901
|
+
fs.writeFileSync(configPath, content, 'utf-8');
|
|
902
|
+
}
|
|
903
|
+
|
|
904
|
+
return { modified, originalLine };
|
|
905
|
+
};
|
|
906
|
+
|
|
907
|
+
// start_aigc
|
|
908
|
+
/**
|
|
909
|
+
* Fix 规则:注释掉 Next.js 项目中的 outputFileTracingRoot 配置
|
|
910
|
+
* 这个配置在 monorepo 环境中可能会导致问题
|
|
911
|
+
*/
|
|
912
|
+
const fixNextOutputTracingRoot = context => {
|
|
913
|
+
const ruleName = 'next-output-tracing-root';
|
|
914
|
+
|
|
915
|
+
// 1. 检查是否为 Next.js 项目
|
|
916
|
+
if (!isNextProject(context.projectFolder)) {
|
|
917
|
+
return {
|
|
918
|
+
ruleName,
|
|
919
|
+
applied: false,
|
|
920
|
+
message: 'Not a Next.js project, skipping',
|
|
921
|
+
};
|
|
922
|
+
}
|
|
923
|
+
|
|
924
|
+
// 2. 查找 Next.js 配置文件
|
|
925
|
+
const configPath = findNextConfigFile(context.projectFolder);
|
|
926
|
+
|
|
927
|
+
if (!configPath) {
|
|
928
|
+
return {
|
|
929
|
+
ruleName,
|
|
930
|
+
applied: false,
|
|
931
|
+
message: 'Next.js config file not found, skipping',
|
|
932
|
+
};
|
|
933
|
+
}
|
|
934
|
+
|
|
935
|
+
// 3. 注释掉 outputFileTracingRoot 配置
|
|
936
|
+
const { modified, originalLine } = commentOutOutputTracingRoot(configPath);
|
|
937
|
+
|
|
938
|
+
if (modified && originalLine) {
|
|
939
|
+
logger.success(
|
|
940
|
+
`Commented out outputFileTracingRoot in ${configPath.split('/').pop()}`,
|
|
941
|
+
);
|
|
942
|
+
logger.info(` Original: ${originalLine}`);
|
|
943
|
+
|
|
944
|
+
return {
|
|
945
|
+
ruleName,
|
|
946
|
+
applied: true,
|
|
947
|
+
message: `Successfully commented out: ${originalLine}`,
|
|
948
|
+
};
|
|
949
|
+
}
|
|
513
950
|
|
|
514
951
|
return {
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
},
|
|
952
|
+
ruleName,
|
|
953
|
+
applied: false,
|
|
954
|
+
message: 'No outputFileTracingRoot config found, skipping',
|
|
519
955
|
};
|
|
520
956
|
};
|
|
957
|
+
// end_aigc
|
|
958
|
+
|
|
959
|
+
/**
|
|
960
|
+
* 所有修复规则的数组
|
|
961
|
+
* 按顺序执行,新增规则直接添加到数组中
|
|
962
|
+
*/
|
|
963
|
+
const rules = [
|
|
964
|
+
// Next.js related fixes
|
|
965
|
+
fixNextOutputTracingRoot,
|
|
966
|
+
|
|
967
|
+
// Add more rules here
|
|
968
|
+
] ;
|
|
969
|
+
|
|
970
|
+
// ABOUTME: Fix command for resolving legacy issues from previous project versions
|
|
971
|
+
// ABOUTME: Applies a series of fix rules defined in the fix-rules directory
|
|
972
|
+
|
|
973
|
+
|
|
974
|
+
// start_aigc
|
|
975
|
+
/**
|
|
976
|
+
* 执行 fix 命令的内部实现
|
|
977
|
+
*/
|
|
978
|
+
const executeFix = async (options = {}) => {
|
|
979
|
+
try {
|
|
980
|
+
const cwd = process.cwd();
|
|
981
|
+
const projectFolder = options.directory
|
|
982
|
+
? path.resolve(cwd, options.directory)
|
|
983
|
+
: cwd;
|
|
984
|
+
|
|
985
|
+
logger.info(`Running fix command on: ${projectFolder}`);
|
|
986
|
+
logger.info(`Found ${rules.length} fix rule(s) to apply\n`);
|
|
987
|
+
|
|
988
|
+
const context = {
|
|
989
|
+
cwd,
|
|
990
|
+
projectFolder,
|
|
991
|
+
};
|
|
992
|
+
|
|
993
|
+
let appliedCount = 0;
|
|
994
|
+
let skippedCount = 0;
|
|
995
|
+
|
|
996
|
+
// 依次执行所有修复规则
|
|
997
|
+
for (const rule of rules) {
|
|
998
|
+
try {
|
|
999
|
+
const result = await Promise.resolve(rule(context));
|
|
1000
|
+
|
|
1001
|
+
if (result.applied) {
|
|
1002
|
+
appliedCount++;
|
|
1003
|
+
logger.success(`✓ ${result.ruleName}: ${result.message}`);
|
|
1004
|
+
} else {
|
|
1005
|
+
skippedCount++;
|
|
1006
|
+
logger.info(`○ ${result.ruleName}: ${result.message}`);
|
|
1007
|
+
}
|
|
1008
|
+
} catch (error) {
|
|
1009
|
+
logger.error(
|
|
1010
|
+
`✗ Rule execution failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
1011
|
+
);
|
|
1012
|
+
}
|
|
1013
|
+
}
|
|
1014
|
+
|
|
1015
|
+
// 输出汇总信息
|
|
1016
|
+
logger.info(
|
|
1017
|
+
`\nSummary: ${appliedCount} fixed, ${skippedCount} skipped, ${rules.length} total`,
|
|
1018
|
+
);
|
|
1019
|
+
|
|
1020
|
+
if (appliedCount > 0) {
|
|
1021
|
+
logger.success('\nFixes applied successfully!');
|
|
1022
|
+
} else {
|
|
1023
|
+
logger.info('\nNo fixes needed');
|
|
1024
|
+
}
|
|
1025
|
+
} catch (error) {
|
|
1026
|
+
logger.error('Failed to run fix command:');
|
|
1027
|
+
logger.error(error instanceof Error ? error.message : String(error));
|
|
1028
|
+
process.exit(1);
|
|
1029
|
+
}
|
|
1030
|
+
};
|
|
1031
|
+
// end_aigc
|
|
1032
|
+
|
|
1033
|
+
/**
|
|
1034
|
+
* 注册 fix 命令到 program
|
|
1035
|
+
*/
|
|
1036
|
+
const registerCommand$3 = program => {
|
|
1037
|
+
program
|
|
1038
|
+
.command('fix')
|
|
1039
|
+
.description(
|
|
1040
|
+
'Fix legacy issues from previous versions (e.g., problematic configs)',
|
|
1041
|
+
)
|
|
1042
|
+
.argument(
|
|
1043
|
+
'[directory]',
|
|
1044
|
+
'Target directory to fix (defaults to current directory)',
|
|
1045
|
+
)
|
|
1046
|
+
.action(async (directory) => {
|
|
1047
|
+
await executeFix({ directory });
|
|
1048
|
+
});
|
|
1049
|
+
};
|
|
1050
|
+
|
|
1051
|
+
function _nullishCoalesce$1(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
1052
|
+
/**
|
|
1053
|
+
* 日志文件名常量
|
|
1054
|
+
*/
|
|
1055
|
+
const LOG_FILE_NAME$1 = 'dev.log';
|
|
1056
|
+
|
|
1057
|
+
/**
|
|
1058
|
+
* 获取日志目录
|
|
1059
|
+
* 优先使用环境变量 COZE_LOG_DIR,否则使用 ~/.coze-logs
|
|
1060
|
+
*/
|
|
1061
|
+
const getLogDir$1 = () =>
|
|
1062
|
+
process.env.COZE_LOG_DIR || path.join(os.homedir(), '.coze-logs');
|
|
1063
|
+
|
|
1064
|
+
/**
|
|
1065
|
+
* 解析日志文件路径
|
|
1066
|
+
* - 如果是绝对路径,直接使用
|
|
1067
|
+
* - 如果是相对路径,基于 getLogDir() + 相对路径
|
|
1068
|
+
* - 如果为空,使用 getLogDir() + LOG_FILE_NAME
|
|
1069
|
+
*/
|
|
1070
|
+
const resolveLogFilePath$1 = (logFile) => {
|
|
1071
|
+
if (!logFile) {
|
|
1072
|
+
return path.join(getLogDir$1(), LOG_FILE_NAME$1);
|
|
1073
|
+
}
|
|
1074
|
+
|
|
1075
|
+
if (path.isAbsolute(logFile)) {
|
|
1076
|
+
return logFile;
|
|
1077
|
+
}
|
|
1078
|
+
|
|
1079
|
+
return path.join(getLogDir$1(), logFile);
|
|
1080
|
+
};
|
|
1081
|
+
|
|
1082
|
+
/**
|
|
1083
|
+
* 创建日志写入流
|
|
1084
|
+
*/
|
|
1085
|
+
const createLogStream$1 = (logFilePath) => {
|
|
1086
|
+
const logDir = path.dirname(logFilePath);
|
|
1087
|
+
|
|
1088
|
+
// 确保日志目录存在
|
|
1089
|
+
if (!fs.existsSync(logDir)) {
|
|
1090
|
+
fs.mkdirSync(logDir, { recursive: true });
|
|
1091
|
+
}
|
|
1092
|
+
|
|
1093
|
+
// 使用 'w' 标志覆盖之前的日志
|
|
1094
|
+
return fs.createWriteStream(logFilePath, { flags: 'w' });
|
|
1095
|
+
};
|
|
521
1096
|
|
|
522
1097
|
/**
|
|
523
1098
|
* 执行命令的内部实现
|
|
@@ -529,21 +1104,32 @@ const executeRun = async (
|
|
|
529
1104
|
try {
|
|
530
1105
|
logger.info(`Running ${commandName} command...`);
|
|
531
1106
|
|
|
532
|
-
// 1.
|
|
1107
|
+
// 1. 对于 build 命令,先执行 fix 以确保项目配置正确
|
|
1108
|
+
if (['dev', 'build'].includes(commandName)) {
|
|
1109
|
+
logger.info('\n🔧 Running fix command before build...\n');
|
|
1110
|
+
try {
|
|
1111
|
+
await executeFix();
|
|
1112
|
+
// eslint-disable-next-line @coze-arch/no-empty-catch
|
|
1113
|
+
} catch (e) {
|
|
1114
|
+
// just ignore
|
|
1115
|
+
}
|
|
1116
|
+
logger.info('');
|
|
1117
|
+
}
|
|
1118
|
+
|
|
1119
|
+
// 2. 加载 .coze 配置
|
|
533
1120
|
const config = await loadCozeConfig();
|
|
534
1121
|
const commandArgs = getCommandConfig(config, commandName);
|
|
535
1122
|
|
|
536
|
-
//
|
|
537
|
-
const
|
|
538
|
-
const
|
|
539
|
-
const logStream = logManager.createWriteStream(logFile);
|
|
1123
|
+
// 3. 准备日志
|
|
1124
|
+
const logFilePath = resolveLogFilePath$1(options.logFile);
|
|
1125
|
+
const logStream = createLogStream$1(logFilePath);
|
|
540
1126
|
|
|
541
|
-
//
|
|
1127
|
+
// 4. 执行命令
|
|
542
1128
|
const commandString = commandArgs.join(' ');
|
|
543
1129
|
|
|
544
1130
|
logger.info(`Executing: ${commandString}`);
|
|
545
1131
|
logger.info(`Working directory: ${process.cwd()}`);
|
|
546
|
-
logger.info(`Log file: ${
|
|
1132
|
+
logger.info(`Log file: ${logFilePath}`);
|
|
547
1133
|
|
|
548
1134
|
const childProcess = shelljs.exec(commandString, {
|
|
549
1135
|
async: true,
|
|
@@ -555,12 +1141,12 @@ const executeRun = async (
|
|
|
555
1141
|
}
|
|
556
1142
|
|
|
557
1143
|
// 将输出同时写入控制台和日志文件
|
|
558
|
-
_optionalChain
|
|
1144
|
+
_optionalChain([childProcess, 'access', _ => _.stdout, 'optionalAccess', _2 => _2.on, 'call', _3 => _3('data', (data) => {
|
|
559
1145
|
process.stdout.write(data);
|
|
560
1146
|
logStream.write(data);
|
|
561
1147
|
})]);
|
|
562
1148
|
|
|
563
|
-
_optionalChain
|
|
1149
|
+
_optionalChain([childProcess, 'access', _4 => _4.stderr, 'optionalAccess', _5 => _5.on, 'call', _6 => _6('data', (data) => {
|
|
564
1150
|
process.stderr.write(data);
|
|
565
1151
|
logStream.write(data);
|
|
566
1152
|
})]);
|
|
@@ -572,11 +1158,11 @@ const executeRun = async (
|
|
|
572
1158
|
logger.error(
|
|
573
1159
|
`Command exited with code ${_nullishCoalesce$1(code, () => ( 'unknown'))}${signal ? ` and signal ${signal}` : ''}`,
|
|
574
1160
|
);
|
|
575
|
-
logger.error(`Check log file for details: ${
|
|
1161
|
+
logger.error(`Check log file for details: ${logFilePath}`);
|
|
576
1162
|
process.exit(code || 1);
|
|
577
1163
|
} else {
|
|
578
1164
|
logger.success('Command completed successfully');
|
|
579
|
-
logger.info(`Log file: ${
|
|
1165
|
+
logger.info(`Log file: ${logFilePath}`);
|
|
580
1166
|
}
|
|
581
1167
|
});
|
|
582
1168
|
|
|
@@ -599,7 +1185,7 @@ const executeRun = async (
|
|
|
599
1185
|
/**
|
|
600
1186
|
* 注册 dev/build/start 命令到 program
|
|
601
1187
|
*/
|
|
602
|
-
const registerCommand$
|
|
1188
|
+
const registerCommand$2 = program => {
|
|
603
1189
|
// dev 命令
|
|
604
1190
|
program
|
|
605
1191
|
.command('dev')
|
|
@@ -609,279 +1195,118 @@ const registerCommand$1 = program => {
|
|
|
609
1195
|
await executeRun('dev', options);
|
|
610
1196
|
});
|
|
611
1197
|
|
|
612
|
-
// build 命令
|
|
613
|
-
program
|
|
614
|
-
.command('build')
|
|
615
|
-
.description('Build for production')
|
|
616
|
-
.option('--log-file <path>', 'Log file path')
|
|
617
|
-
.action(async options => {
|
|
618
|
-
await executeRun('build', options);
|
|
619
|
-
});
|
|
620
|
-
|
|
621
|
-
// start 命令
|
|
622
|
-
program
|
|
623
|
-
.command('start')
|
|
624
|
-
.description('Start production server')
|
|
625
|
-
.option('--log-file <path>', 'Log file path')
|
|
626
|
-
.action(async options => {
|
|
627
|
-
await executeRun('start', options);
|
|
628
|
-
});
|
|
629
|
-
};
|
|
630
|
-
|
|
631
|
-
/**
|
|
632
|
-
* 时间统计工具
|
|
633
|
-
*/
|
|
634
|
-
class TimeTracker {
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
constructor() {
|
|
639
|
-
this.startTime = perf_hooks.performance.now();
|
|
640
|
-
this.lastTime = this.startTime;
|
|
641
|
-
}
|
|
642
|
-
|
|
643
|
-
/**
|
|
644
|
-
* 记录阶段耗时
|
|
645
|
-
* @param phaseName 阶段名称
|
|
646
|
-
*/
|
|
647
|
-
logPhase(phaseName) {
|
|
648
|
-
const now = perf_hooks.performance.now();
|
|
649
|
-
const phaseTime = now - this.lastTime;
|
|
650
|
-
this.lastTime = now;
|
|
651
|
-
|
|
652
|
-
logger.verbose(`⏱ ${phaseName}: ${phaseTime.toFixed(2)}ms`);
|
|
653
|
-
}
|
|
654
|
-
|
|
655
|
-
/**
|
|
656
|
-
* 记录总耗时
|
|
657
|
-
*/
|
|
658
|
-
logTotal() {
|
|
659
|
-
const totalTime = perf_hooks.performance.now() - this.startTime;
|
|
660
|
-
logger.verbose(`⏱ Total time: ${totalTime.toFixed(2)}ms`);
|
|
661
|
-
}
|
|
662
|
-
|
|
663
|
-
/**
|
|
664
|
-
* 获取当前耗时(不输出日志)
|
|
665
|
-
* @returns 从开始到现在的总耗时(毫秒)
|
|
666
|
-
*/
|
|
667
|
-
getElapsedTime() {
|
|
668
|
-
return perf_hooks.performance.now() - this.startTime;
|
|
669
|
-
}
|
|
670
|
-
}
|
|
671
|
-
|
|
672
|
-
/**
|
|
673
|
-
* 获取模板配置文件路径
|
|
674
|
-
* @returns templates.json 的绝对路径
|
|
675
|
-
*/
|
|
676
|
-
const getTemplatesConfigPath = () => {
|
|
677
|
-
const configPath = path.resolve(getTemplatesDir(), 'templates.json');
|
|
678
|
-
logger.verbose(`Templates config path: ${configPath}`);
|
|
679
|
-
logger.verbose(`Config file exists: ${fs.existsSync(configPath)}`);
|
|
680
|
-
return configPath;
|
|
681
|
-
};
|
|
682
|
-
|
|
683
|
-
/**
|
|
684
|
-
* 获取模板目录路径
|
|
685
|
-
* @returns __templates__ 目录的绝对路径
|
|
686
|
-
*/
|
|
687
|
-
const getTemplatesDir = () => {
|
|
688
|
-
const templatesDir = path.resolve(__dirname, './__templates__');
|
|
689
|
-
logger.verbose(`Templates directory: ${templatesDir}`);
|
|
690
|
-
logger.verbose(`Templates directory exists: ${fs.existsSync(templatesDir)}`);
|
|
691
|
-
return templatesDir;
|
|
692
|
-
};
|
|
693
|
-
|
|
694
|
-
/**
|
|
695
|
-
* 创建 AJV 验证器实例
|
|
696
|
-
*/
|
|
697
|
-
const createAjvInstance = () => {
|
|
698
|
-
const ajv = new Ajv({
|
|
699
|
-
useDefaults: true, // 自动应用默认值
|
|
700
|
-
coerceTypes: true, // 类型强制转换
|
|
701
|
-
removeAdditional: false, // 保留额外属性以便后续报错
|
|
702
|
-
allErrors: true, // 收集所有错误
|
|
703
|
-
});
|
|
704
|
-
|
|
705
|
-
addFormats(ajv);
|
|
706
|
-
return ajv;
|
|
707
|
-
};
|
|
708
|
-
|
|
709
|
-
/**
|
|
710
|
-
* 验证参数
|
|
711
|
-
*
|
|
712
|
-
* @param schema - JSON Schema 定义
|
|
713
|
-
* @param params - 待验证的参数
|
|
714
|
-
* @returns 验证后的参数(应用了默认值)
|
|
715
|
-
* @throws 验证失败时抛出错误
|
|
716
|
-
*/
|
|
717
|
-
const validateParams = (
|
|
718
|
-
schema,
|
|
719
|
-
params,
|
|
720
|
-
) => {
|
|
721
|
-
const ajv = createAjvInstance();
|
|
722
|
-
const validate = ajv.compile(schema);
|
|
723
|
-
|
|
724
|
-
const isValid = validate(params);
|
|
725
|
-
|
|
726
|
-
if (!isValid) {
|
|
727
|
-
const errors = validate.errors || [];
|
|
728
|
-
const errorMessages = errors.map(err => {
|
|
729
|
-
const path = err.instancePath || '/';
|
|
730
|
-
const message = err.message || 'validation failed';
|
|
731
|
-
return ` - ${path}: ${message}`;
|
|
732
|
-
});
|
|
733
|
-
|
|
734
|
-
throw new Error(
|
|
735
|
-
`Parameter validation failed:\n${errorMessages.join('\n')}\n\nPlease check your parameters and try again.`,
|
|
736
|
-
);
|
|
737
|
-
}
|
|
738
|
-
|
|
739
|
-
return params ;
|
|
740
|
-
};
|
|
741
|
-
|
|
742
|
-
/**
|
|
743
|
-
* 加载模板配置文件
|
|
744
|
-
* 支持 .ts 和 .js 文件(通过 sucrase 注册)
|
|
745
|
-
*
|
|
746
|
-
* @param templatePath - 模板目录路径
|
|
747
|
-
* @returns 模板配置对象
|
|
748
|
-
*/
|
|
749
|
-
|
|
750
|
-
const loadTemplateConfig = async (
|
|
751
|
-
templatePath,
|
|
752
|
-
) => {
|
|
753
|
-
logger.verbose(`Loading template config from: ${templatePath}`);
|
|
754
|
-
|
|
755
|
-
const tsConfigPath = path.join(templatePath, 'template.config.ts');
|
|
756
|
-
const jsConfigPath = path.join(templatePath, 'template.config.js');
|
|
757
|
-
|
|
758
|
-
logger.verbose('Checking for config files:');
|
|
759
|
-
logger.verbose(` - TypeScript: ${tsConfigPath}`);
|
|
760
|
-
logger.verbose(` - JavaScript: ${jsConfigPath}`);
|
|
761
|
-
|
|
762
|
-
let configPath;
|
|
763
|
-
|
|
764
|
-
const [tsExists, jsExists] = await Promise.all([
|
|
765
|
-
fs$1.access(tsConfigPath).then(
|
|
766
|
-
() => true,
|
|
767
|
-
() => false,
|
|
768
|
-
),
|
|
769
|
-
fs$1.access(jsConfigPath).then(
|
|
770
|
-
() => true,
|
|
771
|
-
() => false,
|
|
772
|
-
),
|
|
773
|
-
]);
|
|
774
|
-
|
|
775
|
-
logger.verbose('Config file existence check:');
|
|
776
|
-
logger.verbose(` - template.config.ts: ${tsExists}`);
|
|
777
|
-
logger.verbose(` - template.config.js: ${jsExists}`);
|
|
778
|
-
|
|
779
|
-
if (tsExists) {
|
|
780
|
-
configPath = tsConfigPath;
|
|
781
|
-
} else if (jsExists) {
|
|
782
|
-
configPath = jsConfigPath;
|
|
783
|
-
} else {
|
|
784
|
-
throw new Error(
|
|
785
|
-
`Template config not found in ${templatePath}.\n` +
|
|
786
|
-
'Expected: template.config.ts or template.config.js',
|
|
787
|
-
);
|
|
788
|
-
}
|
|
789
|
-
|
|
790
|
-
logger.verbose(`Using config file: ${configPath}`);
|
|
791
|
-
|
|
792
|
-
// eslint-disable-next-line @typescript-eslint/no-require-imports, security/detect-non-literal-require -- Sucrase handles .ts files at runtime, path is validated above
|
|
793
|
-
const config = require(configPath);
|
|
794
|
-
|
|
795
|
-
logger.verbose('Template config loaded successfully');
|
|
1198
|
+
// build 命令
|
|
1199
|
+
program
|
|
1200
|
+
.command('build')
|
|
1201
|
+
.description('Build for production')
|
|
1202
|
+
.option('--log-file <path>', 'Log file path')
|
|
1203
|
+
.action(async options => {
|
|
1204
|
+
await executeRun('build', options);
|
|
1205
|
+
});
|
|
796
1206
|
|
|
797
|
-
|
|
1207
|
+
// start 命令
|
|
1208
|
+
program
|
|
1209
|
+
.command('start')
|
|
1210
|
+
.description('Start production server')
|
|
1211
|
+
.option('--log-file <path>', 'Log file path')
|
|
1212
|
+
.action(async options => {
|
|
1213
|
+
await executeRun('start', options);
|
|
1214
|
+
});
|
|
798
1215
|
};
|
|
799
1216
|
|
|
800
1217
|
/**
|
|
801
|
-
*
|
|
1218
|
+
* 在后台启动一个独立的子进程
|
|
1219
|
+
* 类似于 `setsid command args >/dev/null 2>&1 &`
|
|
802
1220
|
*
|
|
803
|
-
* @param
|
|
804
|
-
* @
|
|
1221
|
+
* @param command - 要执行的命令 (例如: 'npm', 'node', 'bash')
|
|
1222
|
+
* @param args - 命令参数数组 (例如: ['run', 'dev'])
|
|
1223
|
+
* @param options - 配置选项
|
|
1224
|
+
* @returns 子进程的 PID
|
|
805
1225
|
*/
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
1226
|
+
function spawnDetached(
|
|
1227
|
+
command,
|
|
1228
|
+
args,
|
|
1229
|
+
options,
|
|
1230
|
+
) {
|
|
1231
|
+
const { cwd, verbose = true } = options;
|
|
1232
|
+
const isWindows = os.platform() === 'win32';
|
|
810
1233
|
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
1234
|
+
if (verbose) {
|
|
1235
|
+
console.log(`Spawning detached process: ${command} ${args.join(' ')}`);
|
|
1236
|
+
console.log(`Working directory: ${cwd}`);
|
|
1237
|
+
}
|
|
814
1238
|
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
1239
|
+
// 使用 spawn 创建后台子进程
|
|
1240
|
+
const child = child_process.spawn(command, args, {
|
|
1241
|
+
cwd,
|
|
1242
|
+
detached: !isWindows, // Windows 不完全支持 detached,但仍可以使用
|
|
1243
|
+
stdio: 'ignore', // 忽略所有输入输出,让进程完全独立运行
|
|
1244
|
+
});
|
|
818
1245
|
|
|
819
|
-
|
|
820
|
-
|
|
1246
|
+
// 分离父子进程引用,允许父进程退出而不等待子进程
|
|
1247
|
+
child.unref();
|
|
1248
|
+
|
|
1249
|
+
if (verbose && child.pid) {
|
|
1250
|
+
console.log(`Process started with PID: ${child.pid}`);
|
|
1251
|
+
}
|
|
1252
|
+
|
|
1253
|
+
return child.pid;
|
|
1254
|
+
}
|
|
821
1255
|
|
|
822
1256
|
/**
|
|
823
|
-
*
|
|
824
|
-
*
|
|
825
|
-
* @param templatesConfig - 模板列表配置
|
|
826
|
-
* @param templateName - 模板名称
|
|
827
|
-
* @returns 模板元信息
|
|
1257
|
+
* 创建 AJV 验证器实例
|
|
828
1258
|
*/
|
|
829
|
-
const
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
const availableTemplates = templatesConfig.templates
|
|
837
|
-
.map(t => t.name)
|
|
838
|
-
.join(', ');
|
|
839
|
-
throw new Error(
|
|
840
|
-
`Template "${templateName}" not found.\n` +
|
|
841
|
-
`Available templates: ${availableTemplates}\n` +
|
|
842
|
-
'Use --template <name> to specify a template.',
|
|
843
|
-
);
|
|
844
|
-
}
|
|
1259
|
+
const createAjvInstance = () => {
|
|
1260
|
+
const ajv = new Ajv({
|
|
1261
|
+
useDefaults: true, // 自动应用默认值
|
|
1262
|
+
coerceTypes: true, // 类型强制转换
|
|
1263
|
+
removeAdditional: false, // 保留额外属性以便后续报错
|
|
1264
|
+
allErrors: true, // 收集所有错误
|
|
1265
|
+
});
|
|
845
1266
|
|
|
846
|
-
|
|
1267
|
+
addFormats(ajv);
|
|
1268
|
+
return ajv;
|
|
847
1269
|
};
|
|
848
1270
|
|
|
849
1271
|
/**
|
|
850
|
-
*
|
|
1272
|
+
* 验证参数
|
|
851
1273
|
*
|
|
852
|
-
* @param
|
|
853
|
-
* @param
|
|
854
|
-
* @returns
|
|
1274
|
+
* @param schema - JSON Schema 定义
|
|
1275
|
+
* @param params - 待验证的参数
|
|
1276
|
+
* @returns 验证后的参数(应用了默认值)
|
|
1277
|
+
* @throws 验证失败时抛出错误
|
|
855
1278
|
*/
|
|
856
|
-
const
|
|
857
|
-
|
|
858
|
-
|
|
1279
|
+
const validateParams = (
|
|
1280
|
+
schema,
|
|
1281
|
+
params,
|
|
859
1282
|
) => {
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
logger.verbose(` - Template location: ${templateMetadata.location}`);
|
|
1283
|
+
const ajv = createAjvInstance();
|
|
1284
|
+
const validate = ajv.compile(schema);
|
|
863
1285
|
|
|
864
|
-
|
|
865
|
-
const templatePath = path.join(basePath, templateMetadata.location);
|
|
1286
|
+
const isValid = validate(params);
|
|
866
1287
|
|
|
867
|
-
|
|
1288
|
+
if (!isValid) {
|
|
1289
|
+
const errors = validate.errors || [];
|
|
1290
|
+
const errorMessages = errors.map(err => {
|
|
1291
|
+
const path = err.instancePath || '/';
|
|
1292
|
+
const message = err.message || 'validation failed';
|
|
1293
|
+
return ` - ${path}: ${message}`;
|
|
1294
|
+
});
|
|
868
1295
|
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
// eslint-disable-next-line @coze-arch/use-error-in-catch -- Error handling done in throw statement
|
|
873
|
-
} catch (e) {
|
|
874
|
-
logger.error(' - Template directory does not exist: ✗');
|
|
875
|
-
throw new Error(`Template directory not found: ${templatePath}`);
|
|
1296
|
+
throw new Error(
|
|
1297
|
+
`Parameter validation failed:\n${errorMessages.join('\n')}\n\nPlease check your parameters and try again.`,
|
|
1298
|
+
);
|
|
876
1299
|
}
|
|
877
1300
|
|
|
878
|
-
return
|
|
1301
|
+
return params ;
|
|
879
1302
|
};
|
|
880
1303
|
|
|
881
1304
|
/**
|
|
882
1305
|
* 从 Commander 解析透传参数
|
|
883
1306
|
* 将 kebab-case 的 CLI 参数转换为 camelCase
|
|
884
1307
|
*
|
|
1308
|
+
* 使用 minimist 解析 process.argv,自动处理类型转换
|
|
1309
|
+
*
|
|
885
1310
|
* @param command - Commander 命令实例
|
|
886
1311
|
* @param knownOptions - 已知的选项集合(不需要透传的选项)
|
|
887
1312
|
* @returns 参数对象
|
|
@@ -890,20 +1315,34 @@ const parsePassThroughParams = (
|
|
|
890
1315
|
command,
|
|
891
1316
|
knownOptions = new Set(),
|
|
892
1317
|
) => {
|
|
893
|
-
|
|
1318
|
+
// 使用 minimist 解析所有参数
|
|
1319
|
+
// eslint-disable-next-line @typescript-eslint/no-magic-numbers -- slice(2) to skip node and script path
|
|
1320
|
+
const parsed = minimist(process.argv.slice(2));
|
|
894
1321
|
|
|
895
|
-
|
|
896
|
-
|
|
1322
|
+
// 过滤掉已知选项和位置参数(_)
|
|
1323
|
+
const filtered = Object.entries(parsed).reduce(
|
|
897
1324
|
(params, [key, value]) => {
|
|
898
|
-
|
|
1325
|
+
// 跳过 minimist 的位置参数数组
|
|
1326
|
+
if (key === '_') {
|
|
1327
|
+
return params;
|
|
1328
|
+
}
|
|
1329
|
+
|
|
1330
|
+
// 跳过已知选项(支持原始格式和 camelCase 格式)
|
|
1331
|
+
if (knownOptions.has(key) || knownOptions.has(changeCase.camelCase(key))) {
|
|
899
1332
|
return params;
|
|
900
1333
|
}
|
|
901
1334
|
|
|
1335
|
+
// 将 kebab-case 转换为 camelCase
|
|
902
1336
|
const camelKey = changeCase.camelCase(key);
|
|
903
|
-
|
|
1337
|
+
// eslint-disable-next-line security/detect-object-injection -- camelKey is sanitized by camelCase
|
|
1338
|
+
params[camelKey] = value;
|
|
1339
|
+
|
|
1340
|
+
return params;
|
|
904
1341
|
},
|
|
905
|
-
|
|
1342
|
+
{},
|
|
906
1343
|
);
|
|
1344
|
+
|
|
1345
|
+
return filtered;
|
|
907
1346
|
};
|
|
908
1347
|
|
|
909
1348
|
/**
|
|
@@ -998,6 +1437,11 @@ const shouldIgnoreFile = (filePath) => {
|
|
|
998
1437
|
return directoryPatterns.some(dir => pathParts.includes(dir));
|
|
999
1438
|
};
|
|
1000
1439
|
|
|
1440
|
+
// ABOUTME: File system utilities for template file processing
|
|
1441
|
+
// ABOUTME: Provides directory scanning, file path conversion, and node_modules copying
|
|
1442
|
+
|
|
1443
|
+
|
|
1444
|
+
// start_aigc
|
|
1001
1445
|
/**
|
|
1002
1446
|
* 递归获取目录中的所有文件
|
|
1003
1447
|
*
|
|
@@ -1058,33 +1502,327 @@ const convertDotfileName = (filePath) => {
|
|
|
1058
1502
|
// 白名单:需要从 _ 开头转换为 . 开头的文件
|
|
1059
1503
|
const dotfileWhitelist = ['_gitignore', '_npmrc'];
|
|
1060
1504
|
|
|
1061
|
-
const fileName = path.basename(filePath);
|
|
1505
|
+
const fileName = path.basename(filePath);
|
|
1506
|
+
|
|
1507
|
+
// 只对白名单中的文件进行转换(如 _gitignore -> .gitignore)
|
|
1508
|
+
if (dotfileWhitelist.includes(fileName)) {
|
|
1509
|
+
return filePath.replace(/(^|\/|\\)_([^/\\]+)$/g, '$1.$2');
|
|
1510
|
+
}
|
|
1511
|
+
|
|
1512
|
+
return filePath;
|
|
1513
|
+
};
|
|
1514
|
+
// end_aigc
|
|
1515
|
+
|
|
1516
|
+
// ABOUTME: File rendering utilities for template processing
|
|
1517
|
+
// ABOUTME: Handles file content rendering, hook execution, and file writing
|
|
1518
|
+
|
|
1519
|
+
|
|
1520
|
+
|
|
1521
|
+
|
|
1522
|
+
|
|
1523
|
+
|
|
1524
|
+
|
|
1525
|
+
|
|
1526
|
+
// start_aigc
|
|
1527
|
+
/**
|
|
1528
|
+
* 执行文件渲染钩子
|
|
1529
|
+
*
|
|
1530
|
+
* @param templateConfig - 模板配置
|
|
1531
|
+
* @param fileInfo - 文件渲染信息
|
|
1532
|
+
* @param context - 模板上下文
|
|
1533
|
+
* @returns 处理后的文件信息,或 null 表示跳过该文件
|
|
1534
|
+
*/
|
|
1535
|
+
const executeFileRenderHook = async (
|
|
1536
|
+
templateConfig,
|
|
1537
|
+
fileInfo,
|
|
1538
|
+
context,
|
|
1539
|
+
) => {
|
|
1540
|
+
if (!templateConfig.onFileRender) {
|
|
1541
|
+
return fileInfo;
|
|
1542
|
+
}
|
|
1543
|
+
|
|
1544
|
+
const result = await templateConfig.onFileRender(
|
|
1545
|
+
fileInfo,
|
|
1546
|
+
context,
|
|
1547
|
+
);
|
|
1548
|
+
|
|
1549
|
+
// false: 跳过文件
|
|
1550
|
+
if (result === false) {
|
|
1551
|
+
return null;
|
|
1552
|
+
}
|
|
1553
|
+
|
|
1554
|
+
// undefined/void: 使用默认内容
|
|
1555
|
+
if (result === undefined || result === null) {
|
|
1556
|
+
return fileInfo;
|
|
1557
|
+
}
|
|
1558
|
+
|
|
1559
|
+
// string: 作为 content,其他不变
|
|
1560
|
+
if (typeof result === 'string') {
|
|
1561
|
+
return {
|
|
1562
|
+
...fileInfo,
|
|
1563
|
+
content: result,
|
|
1564
|
+
};
|
|
1565
|
+
}
|
|
1566
|
+
|
|
1567
|
+
// FileRenderInfo: 使用新对象的信息
|
|
1568
|
+
return result;
|
|
1569
|
+
};
|
|
1570
|
+
|
|
1571
|
+
/**
|
|
1572
|
+
* 准备单个文件的渲染信息(不实际写入)
|
|
1573
|
+
* 用于 dry-run 阶段,收集所有将要写入的文件信息
|
|
1574
|
+
*
|
|
1575
|
+
* @param options - 准备选项
|
|
1576
|
+
* @returns 文件渲染信息,或 null 表示该文件被跳过
|
|
1577
|
+
*/
|
|
1578
|
+
const prepareFileInfo = async (options
|
|
1579
|
+
|
|
1580
|
+
|
|
1581
|
+
|
|
1582
|
+
|
|
1583
|
+
) => {
|
|
1584
|
+
const { file, templatePath, context, templateConfig } = options;
|
|
1585
|
+
|
|
1586
|
+
const srcPath = path.join(templatePath, file);
|
|
1587
|
+
const destFile = convertDotfileName(file);
|
|
1588
|
+
|
|
1589
|
+
logger.verbose(
|
|
1590
|
+
` - Preparing: ${file}${destFile !== file ? ` -> ${destFile}` : ''}`,
|
|
1591
|
+
);
|
|
1592
|
+
|
|
1593
|
+
// 判断是否为二进制文件
|
|
1594
|
+
const isBinary = !shouldRenderFile(srcPath);
|
|
1595
|
+
let content;
|
|
1596
|
+
let wasRendered = false;
|
|
1597
|
+
|
|
1598
|
+
if (isBinary) {
|
|
1599
|
+
// 二进制文件,读取为 buffer 然后转为 base64
|
|
1600
|
+
const buffer = await fs$1.readFile(srcPath);
|
|
1601
|
+
content = buffer.toString('base64');
|
|
1602
|
+
} else {
|
|
1603
|
+
// 文本文件,渲染后的内容
|
|
1604
|
+
content = await renderTemplate(srcPath, context);
|
|
1605
|
+
wasRendered = true;
|
|
1606
|
+
}
|
|
1607
|
+
|
|
1608
|
+
// 构造文件信息对象
|
|
1609
|
+
const fileInfo = {
|
|
1610
|
+
path: file,
|
|
1611
|
+
destPath: destFile,
|
|
1612
|
+
content,
|
|
1613
|
+
isBinary,
|
|
1614
|
+
wasRendered,
|
|
1615
|
+
};
|
|
1616
|
+
|
|
1617
|
+
// 执行文件渲染钩子
|
|
1618
|
+
const processedFileInfo = await executeFileRenderHook(
|
|
1619
|
+
templateConfig,
|
|
1620
|
+
fileInfo,
|
|
1621
|
+
context,
|
|
1622
|
+
);
|
|
1623
|
+
|
|
1624
|
+
// 如果返回 null,表示该文件被 hook 跳过
|
|
1625
|
+
if (processedFileInfo === null) {
|
|
1626
|
+
logger.verbose(' ⊘ Skipped by onFileRender hook');
|
|
1627
|
+
return null;
|
|
1628
|
+
}
|
|
1629
|
+
|
|
1630
|
+
return processedFileInfo;
|
|
1631
|
+
};
|
|
1632
|
+
|
|
1633
|
+
/**
|
|
1634
|
+
* 写入渲染后的文件到目标路径
|
|
1635
|
+
*
|
|
1636
|
+
* @param options - 写入选项
|
|
1637
|
+
*/
|
|
1638
|
+
const writeRenderedFile = async (options
|
|
1639
|
+
|
|
1640
|
+
|
|
1641
|
+
|
|
1642
|
+
) => {
|
|
1643
|
+
const { fileInfo, srcPath, destPath } = options;
|
|
1644
|
+
|
|
1645
|
+
logger.verbose(` - Writing: ${fileInfo.destPath}`);
|
|
1646
|
+
|
|
1647
|
+
// 确保目标目录存在
|
|
1648
|
+
await ensureDir(path.dirname(destPath));
|
|
1649
|
+
|
|
1650
|
+
// 写入文件
|
|
1651
|
+
if (fileInfo.isBinary) {
|
|
1652
|
+
// 二进制文件:如果内容是原始 base64(未被 hook 修改),直接复制;否则从 base64 解码写入
|
|
1653
|
+
const buffer = await fs$1.readFile(srcPath);
|
|
1654
|
+
const originalContent = buffer.toString('base64');
|
|
1655
|
+
|
|
1656
|
+
if (fileInfo.content === originalContent) {
|
|
1657
|
+
await fs$1.copyFile(srcPath, destPath);
|
|
1658
|
+
logger.verbose(' ✓ Copied (binary)');
|
|
1659
|
+
} else {
|
|
1660
|
+
const modifiedBuffer = Buffer.from(fileInfo.content, 'base64');
|
|
1661
|
+
await fs$1.writeFile(destPath, modifiedBuffer);
|
|
1662
|
+
logger.verbose(' ✓ Written (binary, modified by hook)');
|
|
1663
|
+
}
|
|
1664
|
+
} else {
|
|
1665
|
+
// 文本文件
|
|
1666
|
+
await fs$1.writeFile(destPath, fileInfo.content, 'utf-8');
|
|
1667
|
+
logger.verbose(' ✓ Rendered and written');
|
|
1668
|
+
}
|
|
1669
|
+
};
|
|
1670
|
+
// end_aigc
|
|
1671
|
+
|
|
1672
|
+
// ABOUTME: File conflict detection utilities for template processing
|
|
1673
|
+
// ABOUTME: Provides dry-run file collection and conflict checking
|
|
1674
|
+
|
|
1675
|
+
|
|
1676
|
+
|
|
1677
|
+
|
|
1678
|
+
|
|
1679
|
+
|
|
1680
|
+
|
|
1681
|
+
// start_aigc
|
|
1682
|
+
/**
|
|
1683
|
+
* 收集所有将要写入的文件路径(dry-run 阶段)
|
|
1684
|
+
*
|
|
1685
|
+
* @param options - 收集选项
|
|
1686
|
+
* @returns 将要写入的文件路径列表
|
|
1687
|
+
*/
|
|
1688
|
+
const collectFilesToRender = async (options
|
|
1689
|
+
|
|
1690
|
+
|
|
1691
|
+
|
|
1692
|
+
|
|
1693
|
+
) => {
|
|
1694
|
+
const { files, templatePath, context, templateConfig } = options;
|
|
1695
|
+
|
|
1696
|
+
logger.verbose('\nDry-run: Collecting files to render...');
|
|
1697
|
+
|
|
1698
|
+
const fileInfos = await Promise.all(
|
|
1699
|
+
files.map(file =>
|
|
1700
|
+
prepareFileInfo({
|
|
1701
|
+
file,
|
|
1702
|
+
templatePath,
|
|
1703
|
+
context,
|
|
1704
|
+
templateConfig,
|
|
1705
|
+
}),
|
|
1706
|
+
),
|
|
1707
|
+
);
|
|
1708
|
+
|
|
1709
|
+
// 过滤掉被 hook 跳过的文件,收集 destPath
|
|
1710
|
+
const filesToWrite = fileInfos
|
|
1711
|
+
.filter((info) => info !== null)
|
|
1712
|
+
.map(info => info.destPath);
|
|
1713
|
+
|
|
1714
|
+
logger.verbose(` - ${filesToWrite.length} files will be written`);
|
|
1715
|
+
logger.verbose(
|
|
1716
|
+
` - ${fileInfos.length - filesToWrite.length} files skipped by hooks`,
|
|
1717
|
+
);
|
|
1718
|
+
|
|
1719
|
+
return filesToWrite;
|
|
1720
|
+
};
|
|
1721
|
+
|
|
1722
|
+
/**
|
|
1723
|
+
* 检测文件冲突
|
|
1724
|
+
*
|
|
1725
|
+
* @param outputPath - 输出目录路径
|
|
1726
|
+
* @param filesToWrite - 将要写入的文件路径列表
|
|
1727
|
+
* @returns 冲突的文件路径列表
|
|
1728
|
+
*/
|
|
1729
|
+
const detectFileConflicts = (
|
|
1730
|
+
outputPath,
|
|
1731
|
+
filesToWrite,
|
|
1732
|
+
) => {
|
|
1733
|
+
logger.verbose('\nChecking for file conflicts...');
|
|
1734
|
+
|
|
1735
|
+
const conflicts = [];
|
|
1736
|
+
|
|
1737
|
+
for (const file of filesToWrite) {
|
|
1738
|
+
const fullPath = path.join(outputPath, file);
|
|
1739
|
+
if (fs.existsSync(fullPath)) {
|
|
1740
|
+
conflicts.push(file);
|
|
1741
|
+
logger.verbose(` ⚠ Conflict detected: ${file}`);
|
|
1742
|
+
}
|
|
1743
|
+
}
|
|
1744
|
+
|
|
1745
|
+
if (conflicts.length === 0) {
|
|
1746
|
+
logger.verbose(' ✓ No conflicts detected');
|
|
1747
|
+
} else {
|
|
1748
|
+
logger.verbose(` ⚠ ${conflicts.length} conflicts detected`);
|
|
1749
|
+
}
|
|
1750
|
+
|
|
1751
|
+
return conflicts;
|
|
1752
|
+
};
|
|
1753
|
+
// end_aigc
|
|
1754
|
+
|
|
1755
|
+
// ABOUTME: Main file processing orchestration for template rendering
|
|
1756
|
+
// ABOUTME: Coordinates file system, rendering, and conflict detection layers
|
|
1757
|
+
|
|
1758
|
+
|
|
1759
|
+
|
|
1760
|
+
// start_aigc
|
|
1761
|
+
/**
|
|
1762
|
+
* 处理单个文件(准备 + 写入)
|
|
1763
|
+
*
|
|
1764
|
+
* @param options - 处理选项
|
|
1765
|
+
*/
|
|
1766
|
+
const processSingleFile = async (options
|
|
1767
|
+
|
|
1768
|
+
|
|
1769
|
+
|
|
1770
|
+
|
|
1771
|
+
|
|
1772
|
+
) => {
|
|
1773
|
+
const { file, templatePath, outputPath, context, templateConfig } = options;
|
|
1774
|
+
|
|
1775
|
+
const srcPath = path.join(templatePath, file);
|
|
1062
1776
|
|
|
1063
|
-
//
|
|
1064
|
-
|
|
1065
|
-
|
|
1777
|
+
// 准备文件信息
|
|
1778
|
+
const processedFileInfo = await prepareFileInfo({
|
|
1779
|
+
file,
|
|
1780
|
+
templatePath,
|
|
1781
|
+
context,
|
|
1782
|
+
templateConfig,
|
|
1783
|
+
});
|
|
1784
|
+
|
|
1785
|
+
// 如果返回 null,跳过该文件
|
|
1786
|
+
if (processedFileInfo === null) {
|
|
1787
|
+
return;
|
|
1066
1788
|
}
|
|
1067
1789
|
|
|
1068
|
-
|
|
1790
|
+
// 使用处理后的目标路径
|
|
1791
|
+
const finalDestPath = path.join(outputPath, processedFileInfo.destPath);
|
|
1792
|
+
|
|
1793
|
+
// 写入文件
|
|
1794
|
+
await writeRenderedFile({
|
|
1795
|
+
fileInfo: processedFileInfo,
|
|
1796
|
+
srcPath,
|
|
1797
|
+
destPath: finalDestPath,
|
|
1798
|
+
});
|
|
1069
1799
|
};
|
|
1070
1800
|
|
|
1071
1801
|
/**
|
|
1072
1802
|
* 复制并处理模板文件到目标目录
|
|
1073
1803
|
*
|
|
1074
|
-
*
|
|
1075
|
-
*
|
|
1076
|
-
*
|
|
1804
|
+
* 流程:
|
|
1805
|
+
* 1. 验证模板目录
|
|
1806
|
+
* 2. 扫描所有模板文件
|
|
1807
|
+
* 3. Dry-run:收集将要写入的文件列表(考虑 hooks 影响)
|
|
1808
|
+
* 4. 冲突检测:检查是否有文件会被覆盖
|
|
1809
|
+
* 5. 实际写入:渲染并写入所有文件
|
|
1810
|
+
* 6. 复制 node_modules(如果存在)
|
|
1811
|
+
*
|
|
1812
|
+
* @param options - 处理选项
|
|
1077
1813
|
*/
|
|
1078
|
-
const processTemplateFiles = async (
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1814
|
+
const processTemplateFiles = async (options
|
|
1815
|
+
|
|
1816
|
+
|
|
1817
|
+
|
|
1818
|
+
|
|
1082
1819
|
) => {
|
|
1820
|
+
const { templatePath, outputPath, context, templateConfig } = options;
|
|
1083
1821
|
logger.verbose('Processing template files:');
|
|
1084
1822
|
logger.verbose(` - Template path: ${templatePath}`);
|
|
1085
1823
|
logger.verbose(` - Output path: ${outputPath}`);
|
|
1086
1824
|
|
|
1087
|
-
// 验证模板目录是否存在
|
|
1825
|
+
// 阶段 0: 验证模板目录是否存在
|
|
1088
1826
|
try {
|
|
1089
1827
|
const stat = await fs$1.stat(templatePath);
|
|
1090
1828
|
logger.verbose(
|
|
@@ -1100,6 +1838,7 @@ const processTemplateFiles = async (
|
|
|
1100
1838
|
throw error;
|
|
1101
1839
|
}
|
|
1102
1840
|
|
|
1841
|
+
// 阶段 1: 扫描所有模板文件
|
|
1103
1842
|
const files = await getAllFiles(templatePath);
|
|
1104
1843
|
|
|
1105
1844
|
logger.verbose(` - Found ${files.length} files to process`);
|
|
@@ -1109,102 +1848,46 @@ const processTemplateFiles = async (
|
|
|
1109
1848
|
return;
|
|
1110
1849
|
}
|
|
1111
1850
|
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1851
|
+
// 阶段 2: Dry-run - 收集所有将要写入的文件
|
|
1852
|
+
const filesToWrite = await collectFilesToRender({
|
|
1853
|
+
files,
|
|
1854
|
+
templatePath,
|
|
1855
|
+
context,
|
|
1856
|
+
templateConfig,
|
|
1857
|
+
});
|
|
1117
1858
|
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
);
|
|
1859
|
+
// 阶段 3: 冲突检测
|
|
1860
|
+
const conflicts = detectFileConflicts(outputPath, filesToWrite);
|
|
1121
1861
|
|
|
1122
|
-
|
|
1123
|
-
|
|
1862
|
+
if (conflicts.length > 0) {
|
|
1863
|
+
// 有冲突,抛出详细的错误信息
|
|
1864
|
+
const conflictList = conflicts.map(f => ` - ${f}`).join('\n');
|
|
1865
|
+
throw new Error(
|
|
1866
|
+
`File conflicts detected in output directory: ${outputPath}\n\n` +
|
|
1867
|
+
`The following files already exist and would be overwritten:\n${conflictList}\n\n` +
|
|
1868
|
+
'Please remove these files or use a different output directory.',
|
|
1869
|
+
);
|
|
1870
|
+
}
|
|
1124
1871
|
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1872
|
+
// 阶段 4: 实际写入文件
|
|
1873
|
+
logger.verbose('\nWriting files...');
|
|
1874
|
+
await Promise.all(
|
|
1875
|
+
files.map(file =>
|
|
1876
|
+
processSingleFile({
|
|
1877
|
+
file,
|
|
1878
|
+
templatePath,
|
|
1879
|
+
outputPath,
|
|
1880
|
+
context,
|
|
1881
|
+
templateConfig,
|
|
1882
|
+
}),
|
|
1883
|
+
),
|
|
1136
1884
|
);
|
|
1137
1885
|
|
|
1138
1886
|
logger.verbose('✓ All files processed successfully');
|
|
1139
1887
|
|
|
1140
|
-
//
|
|
1141
|
-
const sourceNodeModules = path.join(templatePath, 'node_modules');
|
|
1142
|
-
const targetNodeModules = path.join(outputPath, 'node_modules');
|
|
1143
|
-
|
|
1144
|
-
if (fs.existsSync(sourceNodeModules)) {
|
|
1145
|
-
logger.info('\nCopying node_modules from pre-warmed template...');
|
|
1146
|
-
logger.verbose(` From: ${sourceNodeModules}`);
|
|
1147
|
-
logger.verbose(` To: ${targetNodeModules}`);
|
|
1148
|
-
|
|
1149
|
-
const result = shelljs.exec(`cp -R "${sourceNodeModules}" "${targetNodeModules}"`, {
|
|
1150
|
-
silent: true,
|
|
1151
|
-
});
|
|
1152
|
-
|
|
1153
|
-
if (result.stdout) {
|
|
1154
|
-
process.stdout.write(result.stdout);
|
|
1155
|
-
}
|
|
1156
|
-
|
|
1157
|
-
if (result.stderr) {
|
|
1158
|
-
process.stderr.write(result.stderr);
|
|
1159
|
-
}
|
|
1160
|
-
|
|
1161
|
-
if (result.code === 0) {
|
|
1162
|
-
logger.success('✓ node_modules copied successfully');
|
|
1163
|
-
} else {
|
|
1164
|
-
logger.warn(
|
|
1165
|
-
`Failed to copy node_modules: ${result.stderr || 'unknown error'}`,
|
|
1166
|
-
);
|
|
1167
|
-
logger.info('Will need to run pnpm install manually');
|
|
1168
|
-
}
|
|
1169
|
-
}
|
|
1170
|
-
};
|
|
1171
|
-
|
|
1172
|
-
/**
|
|
1173
|
-
* 检查输出目录是否为空
|
|
1174
|
-
* 注意:.git 目录会被忽略,允许在已初始化 git 的目录中创建项目
|
|
1175
|
-
*
|
|
1176
|
-
* @param outputPath - 输出目录路径
|
|
1177
|
-
* @returns 是否为空
|
|
1178
|
-
*/
|
|
1179
|
-
const isOutputDirEmpty = async (
|
|
1180
|
-
outputPath,
|
|
1181
|
-
) => {
|
|
1182
|
-
try {
|
|
1183
|
-
const entries = await fs$1.readdir(outputPath);
|
|
1184
|
-
// 过滤掉 .git 目录,允许在已初始化 git 的目录中创建项目
|
|
1185
|
-
const filteredEntries = entries.filter(entry => entry !== '.git');
|
|
1186
|
-
return filteredEntries.length === 0;
|
|
1187
|
-
} catch (e) {
|
|
1188
|
-
// 目录不存在,视为空
|
|
1189
|
-
return true;
|
|
1190
|
-
}
|
|
1191
|
-
};
|
|
1192
|
-
|
|
1193
|
-
/**
|
|
1194
|
-
* 验证输出目录
|
|
1195
|
-
*
|
|
1196
|
-
* @param outputPath - 输出目录路径
|
|
1197
|
-
* @throws 如果目录不为空则抛出错误
|
|
1198
|
-
*/
|
|
1199
|
-
const validateOutputDir = async (outputPath) => {
|
|
1200
|
-
const isEmpty = await isOutputDirEmpty(outputPath);
|
|
1201
|
-
if (!isEmpty) {
|
|
1202
|
-
throw new Error(
|
|
1203
|
-
`Output directory is not empty: ${outputPath}\n` +
|
|
1204
|
-
'Please use an empty directory or remove existing files.',
|
|
1205
|
-
);
|
|
1206
|
-
}
|
|
1888
|
+
// node_modules 将由 pnpm install 处理(利用缓存和硬链接机制)
|
|
1207
1889
|
};
|
|
1890
|
+
// end_aigc
|
|
1208
1891
|
|
|
1209
1892
|
/**
|
|
1210
1893
|
* 模板引擎执行选项
|
|
@@ -1284,15 +1967,40 @@ const executeAfterRenderHook = async (
|
|
|
1284
1967
|
}
|
|
1285
1968
|
};
|
|
1286
1969
|
|
|
1970
|
+
/**
|
|
1971
|
+
* 执行完成钩子
|
|
1972
|
+
*/
|
|
1973
|
+
const executeCompleteHook = async (
|
|
1974
|
+
templateConfig,
|
|
1975
|
+
context,
|
|
1976
|
+
outputPath,
|
|
1977
|
+
) => {
|
|
1978
|
+
if (templateConfig.onComplete) {
|
|
1979
|
+
await templateConfig.onComplete(context, outputPath);
|
|
1980
|
+
}
|
|
1981
|
+
};
|
|
1982
|
+
|
|
1287
1983
|
/**
|
|
1288
1984
|
* 准备输出目录
|
|
1289
1985
|
*/
|
|
1290
|
-
const prepareOutputDirectory =
|
|
1986
|
+
const prepareOutputDirectory = (outputPath) => {
|
|
1291
1987
|
const absolutePath = path.resolve(process.cwd(), outputPath);
|
|
1292
|
-
|
|
1988
|
+
// 不再在这里验证目录是否为空,冲突检测已移至 processTemplateFiles 中
|
|
1293
1989
|
return absolutePath;
|
|
1294
1990
|
};
|
|
1295
1991
|
|
|
1992
|
+
/**
|
|
1993
|
+
* 模板引擎执行结果
|
|
1994
|
+
*/
|
|
1995
|
+
|
|
1996
|
+
|
|
1997
|
+
|
|
1998
|
+
|
|
1999
|
+
|
|
2000
|
+
|
|
2001
|
+
|
|
2002
|
+
|
|
2003
|
+
|
|
1296
2004
|
/**
|
|
1297
2005
|
* 执行完整的模板渲染流程
|
|
1298
2006
|
*/
|
|
@@ -1316,18 +2024,27 @@ const execute = async (
|
|
|
1316
2024
|
});
|
|
1317
2025
|
|
|
1318
2026
|
// 5. 准备输出目录
|
|
1319
|
-
const absoluteOutputPath =
|
|
2027
|
+
const absoluteOutputPath = prepareOutputDirectory(outputPath);
|
|
1320
2028
|
|
|
1321
2029
|
// 6. 处理模板文件
|
|
1322
|
-
await processTemplateFiles(
|
|
2030
|
+
await processTemplateFiles({
|
|
2031
|
+
templatePath,
|
|
2032
|
+
outputPath: absoluteOutputPath,
|
|
2033
|
+
context,
|
|
2034
|
+
templateConfig,
|
|
2035
|
+
});
|
|
1323
2036
|
|
|
1324
2037
|
// 7. 执行 onAfterRender 钩子
|
|
1325
2038
|
await executeAfterRenderHook(templateConfig, context, absoluteOutputPath);
|
|
1326
2039
|
|
|
1327
|
-
return
|
|
2040
|
+
return {
|
|
2041
|
+
outputPath: absoluteOutputPath,
|
|
2042
|
+
templateConfig,
|
|
2043
|
+
context,
|
|
2044
|
+
};
|
|
1328
2045
|
};
|
|
1329
2046
|
|
|
1330
|
-
function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
|
|
2047
|
+
function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
|
|
1331
2048
|
/**
|
|
1332
2049
|
* 运行 pnpm install
|
|
1333
2050
|
*/
|
|
@@ -1430,45 +2147,33 @@ const runGitInit = (projectPath) => {
|
|
|
1430
2147
|
};
|
|
1431
2148
|
|
|
1432
2149
|
/**
|
|
1433
|
-
* 运行开发服务器
|
|
2150
|
+
* 运行开发服务器(后台模式)
|
|
2151
|
+
* 启动后台子进程运行开发服务器,父进程可以直接退出
|
|
2152
|
+
* 使用 CLI 自己的 dev 命令(定义在 run.ts)而不是直接运行 npm run dev
|
|
1434
2153
|
*/
|
|
1435
|
-
const
|
|
1436
|
-
logger.info('\nStarting development server...');
|
|
1437
|
-
logger.info(`Executing: npm run dev in ${projectPath}`);
|
|
1438
|
-
logger.info('Press Ctrl+C to stop the server\n');
|
|
1439
|
-
|
|
1440
|
-
// 使用 async: true 异步执行,不阻塞进程
|
|
1441
|
-
const child = shelljs.exec('npm run dev', {
|
|
1442
|
-
cwd: projectPath,
|
|
1443
|
-
async: true,
|
|
1444
|
-
silent: true, // 手动处理输出以便显示详细信息
|
|
1445
|
-
});
|
|
2154
|
+
const runDev = (projectPath) => {
|
|
2155
|
+
logger.info('\nStarting development server in background...');
|
|
1446
2156
|
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
process.stdout.write(data);
|
|
1451
|
-
})]);
|
|
2157
|
+
// 获取当前 CLI 的可执行文件路径
|
|
2158
|
+
// process.argv[0] 是 node,process.argv[1] 是 CLI 入口文件
|
|
2159
|
+
const cliPath = process.argv[1];
|
|
1452
2160
|
|
|
1453
|
-
|
|
1454
|
-
_optionalChain([child, 'access', _4 => _4.stderr, 'optionalAccess', _5 => _5.on, 'call', _6 => _6('data', (data) => {
|
|
1455
|
-
process.stderr.write(data);
|
|
1456
|
-
})]);
|
|
2161
|
+
logger.info(`Executing: ${cliPath} dev in ${projectPath}`);
|
|
1457
2162
|
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
2163
|
+
// 使用通用的后台执行函数启动开发服务器
|
|
2164
|
+
// 调用 CLI 自己的 dev 命令
|
|
2165
|
+
const pid = spawnDetached(process.argv[0], [cliPath, 'dev'], {
|
|
2166
|
+
cwd: projectPath,
|
|
2167
|
+
verbose: false, // 不输出额外的进程信息,由 logger 统一处理
|
|
2168
|
+
});
|
|
1463
2169
|
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
});
|
|
2170
|
+
logger.success('Development server started in background!');
|
|
2171
|
+
if (pid) {
|
|
2172
|
+
logger.info(`Process ID: ${pid}`);
|
|
2173
|
+
logger.info(
|
|
2174
|
+
'\nThe dev server is running independently. You can close this terminal.',
|
|
2175
|
+
);
|
|
2176
|
+
logger.info(`To stop the server later, use: kill ${pid}`);
|
|
1472
2177
|
}
|
|
1473
2178
|
};
|
|
1474
2179
|
|
|
@@ -1499,32 +2204,27 @@ const executeInit = async (
|
|
|
1499
2204
|
logger.info(`Initializing project with template: ${templateName}`);
|
|
1500
2205
|
timer.logPhase('Initialization');
|
|
1501
2206
|
|
|
1502
|
-
//
|
|
1503
|
-
const
|
|
2207
|
+
// 执行模板引擎,返回结果对象
|
|
2208
|
+
const result = await execute({
|
|
1504
2209
|
templateName,
|
|
1505
2210
|
outputPath,
|
|
1506
2211
|
command,
|
|
1507
2212
|
});
|
|
2213
|
+
const { outputPath: absoluteOutputPath, templateConfig, context } = result;
|
|
1508
2214
|
|
|
1509
2215
|
timer.logPhase('Template engine execution');
|
|
1510
2216
|
logger.success('Project created successfully!');
|
|
1511
2217
|
|
|
1512
|
-
//
|
|
2218
|
+
// 安装依赖(始终使用 pnpm install,利用缓存机制)
|
|
1513
2219
|
if (!skipInstall) {
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
if (hasNodeModules) {
|
|
1518
|
-
logger.info(
|
|
1519
|
-
'\n💡 Using pre-warmed node_modules, skipping pnpm install',
|
|
1520
|
-
);
|
|
1521
|
-
timer.logPhase('Node modules (pre-warmed)');
|
|
1522
|
-
} else {
|
|
1523
|
-
runPnpmInstall(absoluteOutputPath);
|
|
1524
|
-
timer.logPhase('Dependencies installation');
|
|
1525
|
-
}
|
|
2220
|
+
runPnpmInstall(absoluteOutputPath);
|
|
2221
|
+
timer.logPhase('Dependencies installation');
|
|
1526
2222
|
}
|
|
1527
2223
|
|
|
2224
|
+
// 执行 onComplete 钩子(在 pnpm install 之后)
|
|
2225
|
+
await executeCompleteHook(templateConfig, context, absoluteOutputPath);
|
|
2226
|
+
timer.logPhase('Complete hook execution');
|
|
2227
|
+
|
|
1528
2228
|
// 如果没有跳过 git,则初始化 git 仓库
|
|
1529
2229
|
if (!skipGit) {
|
|
1530
2230
|
runGitInit(absoluteOutputPath);
|
|
@@ -1533,7 +2233,7 @@ const executeInit = async (
|
|
|
1533
2233
|
|
|
1534
2234
|
// 如果没有跳过 dev,则启动开发服务器
|
|
1535
2235
|
if (!skipDev) {
|
|
1536
|
-
|
|
2236
|
+
runDev(absoluteOutputPath);
|
|
1537
2237
|
timer.logPhase('Dev server startup');
|
|
1538
2238
|
} else {
|
|
1539
2239
|
// 只有跳过 dev 时才显示 Next steps
|
|
@@ -1547,7 +2247,7 @@ const executeInit = async (
|
|
|
1547
2247
|
' git init && git add . && git commit -m "initial commit"',
|
|
1548
2248
|
);
|
|
1549
2249
|
}
|
|
1550
|
-
logger.info('
|
|
2250
|
+
logger.info(' coze dev');
|
|
1551
2251
|
}
|
|
1552
2252
|
|
|
1553
2253
|
// 输出总耗时
|
|
@@ -1563,7 +2263,7 @@ const executeInit = async (
|
|
|
1563
2263
|
/**
|
|
1564
2264
|
* 注册 init 命令到 program
|
|
1565
2265
|
*/
|
|
1566
|
-
const registerCommand = program => {
|
|
2266
|
+
const registerCommand$1 = program => {
|
|
1567
2267
|
program
|
|
1568
2268
|
.command('init')
|
|
1569
2269
|
.description('Initialize a new project from a template')
|
|
@@ -1581,14 +2281,312 @@ const registerCommand = program => {
|
|
|
1581
2281
|
});
|
|
1582
2282
|
};
|
|
1583
2283
|
|
|
1584
|
-
|
|
2284
|
+
// ABOUTME: This file implements the update command for coze CLI
|
|
2285
|
+
// ABOUTME: It wraps pnpm update/install to update package dependencies with logging support
|
|
2286
|
+
|
|
2287
|
+
|
|
2288
|
+
|
|
2289
|
+
|
|
2290
|
+
/**
|
|
2291
|
+
* 日志文件名常量
|
|
2292
|
+
*/
|
|
2293
|
+
const LOG_FILE_NAME = 'update.log';
|
|
2294
|
+
|
|
2295
|
+
/**
|
|
2296
|
+
* 获取日志目录
|
|
2297
|
+
* 优先使用环境变量 COZE_LOG_DIR,否则使用 ~/.coze-logs
|
|
2298
|
+
*/
|
|
2299
|
+
const getLogDir = () =>
|
|
2300
|
+
process.env.COZE_LOG_DIR || path.join(os.homedir(), '.coze-logs');
|
|
2301
|
+
|
|
2302
|
+
/**
|
|
2303
|
+
* 解析日志文件路径
|
|
2304
|
+
* - 如果是绝对路径,直接使用
|
|
2305
|
+
* - 如果是相对路径,基于 getLogDir() + 相对路径
|
|
2306
|
+
* - 如果为空,使用 getLogDir() + LOG_FILE_NAME
|
|
2307
|
+
*/
|
|
2308
|
+
const resolveLogFilePath = (logFile) => {
|
|
2309
|
+
if (!logFile) {
|
|
2310
|
+
return path.join(getLogDir(), LOG_FILE_NAME);
|
|
2311
|
+
}
|
|
2312
|
+
|
|
2313
|
+
if (path.isAbsolute(logFile)) {
|
|
2314
|
+
return logFile;
|
|
2315
|
+
}
|
|
2316
|
+
|
|
2317
|
+
return path.join(getLogDir(), logFile);
|
|
2318
|
+
};
|
|
2319
|
+
|
|
2320
|
+
/**
|
|
2321
|
+
* 创建日志写入流
|
|
2322
|
+
*/
|
|
2323
|
+
const createLogStream = (logFilePath) => {
|
|
2324
|
+
const logDir = path.dirname(logFilePath);
|
|
2325
|
+
|
|
2326
|
+
// 确保日志目录存在
|
|
2327
|
+
if (!fs.existsSync(logDir)) {
|
|
2328
|
+
fs.mkdirSync(logDir, { recursive: true });
|
|
2329
|
+
}
|
|
2330
|
+
|
|
2331
|
+
// 使用 'w' 标志覆盖之前的日志
|
|
2332
|
+
return fs.createWriteStream(logFilePath, { flags: 'w' });
|
|
2333
|
+
};
|
|
2334
|
+
|
|
2335
|
+
/**
|
|
2336
|
+
* 格式化时间戳
|
|
2337
|
+
*/
|
|
2338
|
+
const formatTimestamp = () => {
|
|
2339
|
+
const now = new Date();
|
|
2340
|
+
return now.toISOString();
|
|
2341
|
+
};
|
|
2342
|
+
|
|
2343
|
+
/**
|
|
2344
|
+
* 写入带时间戳的日志
|
|
2345
|
+
*/
|
|
2346
|
+
const writeLogWithTimestamp = (stream, message) => {
|
|
2347
|
+
const timestamp = formatTimestamp();
|
|
2348
|
+
const lines = message.split('\n');
|
|
2349
|
+
lines.forEach(line => {
|
|
2350
|
+
if (line) {
|
|
2351
|
+
stream.write(`[${timestamp}] ${line}\n`);
|
|
2352
|
+
} else {
|
|
2353
|
+
stream.write('\n');
|
|
2354
|
+
}
|
|
2355
|
+
});
|
|
2356
|
+
// 确保数据写入磁盘
|
|
2357
|
+
stream.uncork();
|
|
2358
|
+
};
|
|
2359
|
+
|
|
2360
|
+
/**
|
|
2361
|
+
* 同时输出到控制台和日志文件
|
|
2362
|
+
*/
|
|
2363
|
+
const logWithFile = (
|
|
2364
|
+
stream,
|
|
2365
|
+
level,
|
|
2366
|
+
message,
|
|
2367
|
+
) => {
|
|
2368
|
+
// 输出到控制台
|
|
2369
|
+
switch (level) {
|
|
2370
|
+
case 'info':
|
|
2371
|
+
logger.info(message);
|
|
2372
|
+
break;
|
|
2373
|
+
case 'success':
|
|
2374
|
+
logger.success(message);
|
|
2375
|
+
break;
|
|
2376
|
+
case 'error':
|
|
2377
|
+
logger.error(message);
|
|
2378
|
+
break;
|
|
2379
|
+
default:
|
|
2380
|
+
logger.info(message);
|
|
2381
|
+
break;
|
|
2382
|
+
}
|
|
2383
|
+
|
|
2384
|
+
// 写入日志文件(带时间戳)
|
|
2385
|
+
writeLogWithTimestamp(stream, `[${level.toUpperCase()}] ${message}`);
|
|
2386
|
+
};
|
|
2387
|
+
|
|
2388
|
+
// start_aigc
|
|
2389
|
+
/**
|
|
2390
|
+
* 构建 pnpm add 命令
|
|
2391
|
+
*/
|
|
2392
|
+
const buildPnpmCommand = (
|
|
2393
|
+
packageName,
|
|
2394
|
+
options
|
|
2395
|
+
|
|
2396
|
+
|
|
2397
|
+
|
|
2398
|
+
|
|
2399
|
+
,
|
|
2400
|
+
) => {
|
|
2401
|
+
const { global, version, registry, extraArgs } = options;
|
|
2402
|
+
|
|
2403
|
+
const parts = ['pnpm', 'add'];
|
|
2404
|
+
|
|
2405
|
+
// 添加全局标记
|
|
2406
|
+
if (global) {
|
|
2407
|
+
parts.push('-g');
|
|
2408
|
+
}
|
|
2409
|
+
|
|
2410
|
+
// 添加包名和版本
|
|
2411
|
+
if (version && version !== 'latest') {
|
|
2412
|
+
parts.push(`${packageName}@${version}`);
|
|
2413
|
+
} else {
|
|
2414
|
+
parts.push(`${packageName}@latest`);
|
|
2415
|
+
}
|
|
2416
|
+
|
|
2417
|
+
// 添加 registry
|
|
2418
|
+
if (registry) {
|
|
2419
|
+
parts.push(`--registry=${registry}`);
|
|
2420
|
+
}
|
|
2421
|
+
|
|
2422
|
+
// 添加额外参数
|
|
2423
|
+
if (extraArgs.length > 0) {
|
|
2424
|
+
parts.push(...extraArgs);
|
|
2425
|
+
}
|
|
2426
|
+
|
|
2427
|
+
return parts.join(' ');
|
|
2428
|
+
};
|
|
2429
|
+
// end_aigc
|
|
2430
|
+
|
|
2431
|
+
// start_aigc
|
|
2432
|
+
/**
|
|
2433
|
+
* 执行 update 命令的内部实现
|
|
2434
|
+
*/
|
|
2435
|
+
const executeUpdate = (
|
|
2436
|
+
packageName,
|
|
2437
|
+
options
|
|
2438
|
+
|
|
2439
|
+
|
|
2440
|
+
|
|
2441
|
+
|
|
2442
|
+
|
|
2443
|
+
|
|
2444
|
+
,
|
|
2445
|
+
) => {
|
|
2446
|
+
let logStream = null;
|
|
2447
|
+
|
|
2448
|
+
try {
|
|
2449
|
+
const { global, cwd, version, registry, logFile, extraArgs } = options;
|
|
2450
|
+
|
|
2451
|
+
// 准备日志
|
|
2452
|
+
const logFilePath = resolveLogFilePath(logFile);
|
|
2453
|
+
|
|
2454
|
+
// 调试:确认日志路径
|
|
2455
|
+
logger.info(`Log file path resolved to: ${logFilePath}`);
|
|
2456
|
+
|
|
2457
|
+
logStream = createLogStream(logFilePath);
|
|
2458
|
+
|
|
2459
|
+
// 调试:确认流已创建
|
|
2460
|
+
logger.info('Log stream created successfully');
|
|
2461
|
+
|
|
2462
|
+
logWithFile(logStream, 'info', `Updating package: ${packageName}`);
|
|
2463
|
+
|
|
2464
|
+
// 构建命令
|
|
2465
|
+
const command = buildPnpmCommand(packageName, {
|
|
2466
|
+
global,
|
|
2467
|
+
version,
|
|
2468
|
+
registry,
|
|
2469
|
+
extraArgs,
|
|
2470
|
+
});
|
|
2471
|
+
|
|
2472
|
+
// 确定工作目录
|
|
2473
|
+
const workingDir = cwd
|
|
2474
|
+
? path.isAbsolute(cwd)
|
|
2475
|
+
? cwd
|
|
2476
|
+
: path.join(process.cwd(), cwd)
|
|
2477
|
+
: process.cwd();
|
|
2478
|
+
|
|
2479
|
+
logWithFile(logStream, 'info', `Executing: ${command}`);
|
|
2480
|
+
logWithFile(logStream, 'info', `Working directory: ${workingDir}`);
|
|
2481
|
+
logWithFile(logStream, 'info', `Log file: ${logFilePath}`);
|
|
2482
|
+
|
|
2483
|
+
// 记录命令开始时间
|
|
2484
|
+
writeLogWithTimestamp(logStream, '--- Command execution started ---');
|
|
2485
|
+
|
|
2486
|
+
// 同步执行命令
|
|
2487
|
+
const result = shelljs.exec(command, {
|
|
2488
|
+
cwd: workingDir,
|
|
2489
|
+
silent: true, // 使用 silent 来捕获输出
|
|
2490
|
+
});
|
|
2491
|
+
|
|
2492
|
+
// 将输出写入控制台和日志文件(带时间戳)
|
|
2493
|
+
if (result.stdout) {
|
|
2494
|
+
process.stdout.write(result.stdout);
|
|
2495
|
+
writeLogWithTimestamp(logStream, result.stdout.trim());
|
|
2496
|
+
}
|
|
2497
|
+
|
|
2498
|
+
if (result.stderr) {
|
|
2499
|
+
process.stderr.write(result.stderr);
|
|
2500
|
+
writeLogWithTimestamp(logStream, result.stderr.trim());
|
|
2501
|
+
}
|
|
2502
|
+
|
|
2503
|
+
// 记录命令结束时间
|
|
2504
|
+
writeLogWithTimestamp(logStream, '--- Command execution ended ---');
|
|
2505
|
+
|
|
2506
|
+
// 检查执行结果并记录到日志
|
|
2507
|
+
if (result.code === 0) {
|
|
2508
|
+
logWithFile(logStream, 'success', 'Package updated successfully');
|
|
2509
|
+
logWithFile(logStream, 'info', `Log file: ${logFilePath}`);
|
|
2510
|
+
} else {
|
|
2511
|
+
logWithFile(
|
|
2512
|
+
logStream,
|
|
2513
|
+
'error',
|
|
2514
|
+
`Command exited with code ${result.code}`,
|
|
2515
|
+
);
|
|
2516
|
+
logWithFile(
|
|
2517
|
+
logStream,
|
|
2518
|
+
'error',
|
|
2519
|
+
`Check log file for details: ${logFilePath}`,
|
|
2520
|
+
);
|
|
2521
|
+
}
|
|
2522
|
+
|
|
2523
|
+
// 关闭日志流并等待写入完成
|
|
2524
|
+
logStream.end(() => {
|
|
2525
|
+
// 流关闭后再退出进程
|
|
2526
|
+
if (result.code !== 0) {
|
|
2527
|
+
process.exit(result.code || 1);
|
|
2528
|
+
}
|
|
2529
|
+
});
|
|
2530
|
+
} catch (error) {
|
|
2531
|
+
logger.error('Failed to update package:');
|
|
2532
|
+
logger.error(error instanceof Error ? error.message : String(error));
|
|
2533
|
+
|
|
2534
|
+
// 写入错误到日志文件
|
|
2535
|
+
if (logStream) {
|
|
2536
|
+
writeLogWithTimestamp(
|
|
2537
|
+
logStream,
|
|
2538
|
+
`[ERROR] ${error instanceof Error ? error.message : String(error)}`,
|
|
2539
|
+
);
|
|
2540
|
+
// 等待流关闭后再退出
|
|
2541
|
+
logStream.end(() => {
|
|
2542
|
+
process.exit(1);
|
|
2543
|
+
});
|
|
2544
|
+
} else {
|
|
2545
|
+
process.exit(1);
|
|
2546
|
+
}
|
|
2547
|
+
}
|
|
2548
|
+
};
|
|
2549
|
+
// end_aigc
|
|
2550
|
+
|
|
2551
|
+
/**
|
|
2552
|
+
* 注册 update 命令到 program
|
|
2553
|
+
*/
|
|
2554
|
+
const registerCommand = program => {
|
|
2555
|
+
program
|
|
2556
|
+
.command('update <package>')
|
|
2557
|
+
.description('Update a package dependency')
|
|
2558
|
+
.option('-g, --global', 'Update package globally', false)
|
|
2559
|
+
.option('-c, --cwd <path>', 'Working directory for the update')
|
|
2560
|
+
.option(
|
|
2561
|
+
'--to <version>',
|
|
2562
|
+
'Version to update to (default: latest)',
|
|
2563
|
+
'latest',
|
|
2564
|
+
)
|
|
2565
|
+
.option('--registry <url>', 'Registry URL to use for the update')
|
|
2566
|
+
.option('--log-file <path>', 'Log file path')
|
|
2567
|
+
.allowUnknownOption() // 允许透传参数给 pnpm
|
|
2568
|
+
.action((packageName, options, command) => {
|
|
2569
|
+
// 收集所有未知选项作为额外参数
|
|
2570
|
+
const extraArgs = command.args.slice(1);
|
|
2571
|
+
|
|
2572
|
+
executeUpdate(packageName, {
|
|
2573
|
+
...options,
|
|
2574
|
+
version: options.to, // 将 --to 映射到 version
|
|
2575
|
+
extraArgs,
|
|
2576
|
+
});
|
|
2577
|
+
});
|
|
2578
|
+
};
|
|
2579
|
+
|
|
2580
|
+
var version = "0.0.1-alpha.3260db";
|
|
1585
2581
|
var packageJson = {
|
|
1586
2582
|
version: version};
|
|
1587
2583
|
|
|
1588
2584
|
const commands = [
|
|
1589
|
-
registerCommand,
|
|
1590
2585
|
registerCommand$1,
|
|
1591
|
-
|
|
2586
|
+
registerCommand$2,
|
|
2587
|
+
registerCommand$4,
|
|
2588
|
+
registerCommand$3,
|
|
2589
|
+
registerCommand,
|
|
1592
2590
|
];
|
|
1593
2591
|
|
|
1594
2592
|
const main = () => {
|