resuxjs 0.3.10 → 0.4.0-beta.2
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/README.md +23 -1
- package/dist/bin.d.ts +1 -2
- package/dist/bin.js +4 -0
- package/dist/bin.js.map +1 -1
- package/dist/build/index.d.ts +28 -0
- package/dist/build/index.js +51 -0
- package/dist/build/index.js.map +1 -0
- package/dist/cli.d.ts +15 -5
- package/dist/cli.js +2648 -3668
- package/dist/cli.js.map +1 -1
- package/dist/compiler/adapter.d.ts +14 -11
- package/dist/compiler/adapter.js +68 -93
- package/dist/compiler/adapter.js.map +1 -1
- package/dist/compiler/dev-warnings.d.ts +8 -5
- package/dist/compiler/dev-warnings.js +248 -321
- package/dist/compiler/dev-warnings.js.map +1 -1
- package/dist/compiler/directives.d.ts +3 -0
- package/dist/compiler/directives.js +124 -150
- package/dist/compiler/directives.js.map +1 -1
- package/dist/compiler/implementation.d.ts +96 -93
- package/dist/compiler/implementation.js +2967 -3430
- package/dist/compiler/index.d.ts +14 -11
- package/dist/compiler/index.js +68 -93
- package/dist/compiler/index.js.map +1 -1
- package/dist/core/config.d.ts +12 -5
- package/dist/core/config.js +42 -25
- package/dist/core/config.js.map +1 -1
- package/dist/core/hooks.d.ts +127 -126
- package/dist/core/hooks.js +45 -55
- package/dist/core/hooks.js.map +1 -1
- package/dist/core/index.d.ts +5 -4
- package/dist/core/index.js +5 -5
- package/dist/core/module-container.d.ts +76 -74
- package/dist/core/module-container.js +181 -186
- package/dist/core/module-container.js.map +1 -1
- package/dist/core/resux.d.ts +15 -12
- package/dist/core/resux.js +17 -13
- package/dist/core/resux.js.map +1 -1
- package/dist/create-bin.d.ts +1 -2
- package/dist/create-bin.js +4 -0
- package/dist/create-bin.js.map +1 -1
- package/dist/create.d.ts +3 -0
- package/dist/create.js +499 -638
- package/dist/create.js.map +1 -1
- package/dist/deploy/cloudflare.d.ts +4 -1
- package/dist/deploy/cloudflare.js +30 -34
- package/dist/deploy/cloudflare.js.map +1 -1
- package/dist/deploy/common.d.ts +6 -4
- package/dist/deploy/common.js +118 -188
- package/dist/deploy/common.js.map +1 -1
- package/dist/deploy/framework-runtime.d.ts +3 -0
- package/dist/deploy/framework-runtime.js +43 -48
- package/dist/deploy/framework-runtime.js.map +1 -1
- package/dist/deploy/index.d.ts +4 -1
- package/dist/deploy/index.js +58 -80
- package/dist/deploy/index.js.map +1 -1
- package/dist/deploy/netlify.d.ts +4 -1
- package/dist/deploy/netlify.js +40 -41
- package/dist/deploy/netlify.js.map +1 -1
- package/dist/deploy/node.d.ts +4 -1
- package/dist/deploy/node.js +24 -19
- package/dist/deploy/node.js.map +1 -1
- package/dist/deploy/production-report.d.ts +3 -0
- package/dist/deploy/production-report.js +14 -14
- package/dist/deploy/production-report.js.map +1 -1
- package/dist/deploy/runtime-dependencies.d.ts +3 -0
- package/dist/deploy/runtime-dependencies.js +158 -220
- package/dist/deploy/runtime-dependencies.js.map +1 -1
- package/dist/deploy/static.d.ts +4 -1
- package/dist/deploy/static.js +16 -14
- package/dist/deploy/static.js.map +1 -1
- package/dist/deploy/types.d.ts +25 -22
- package/dist/deploy/types.js +0 -1
- package/dist/deploy/vercel.d.ts +4 -1
- package/dist/deploy/vercel.js +137 -188
- package/dist/deploy/vercel.js.map +1 -1
- package/dist/fonts/index.d.ts +15 -11
- package/dist/fonts/index.js +114 -134
- package/dist/fonts/index.js.map +1 -1
- package/dist/globals.d.ts +79 -78
- package/dist/globals.js +0 -1
- package/dist/halal-core/ai/classifyProject.d.ts +4 -1
- package/dist/halal-core/ai/classifyProject.js +81 -95
- package/dist/halal-core/ai/classifyProject.js.map +1 -1
- package/dist/halal-core/ai/classifyRuntimeContent.d.ts +5 -2
- package/dist/halal-core/ai/classifyRuntimeContent.js +77 -95
- package/dist/halal-core/ai/classifyRuntimeContent.js.map +1 -1
- package/dist/halal-core/ai/createProjectSummary.d.ts +38 -35
- package/dist/halal-core/ai/createProjectSummary.js +38 -39
- package/dist/halal-core/ai/createProjectSummary.js.map +1 -1
- package/dist/halal-core/ai/halalClassifierPrompt.d.ts +3 -0
- package/dist/halal-core/ai/halalClassifierPrompt.js +5 -1
- package/dist/halal-core/ai/halalClassifierPrompt.js.map +1 -1
- package/dist/halal-core/ai/redactSensitiveData.d.ts +3 -0
- package/dist/halal-core/ai/redactSensitiveData.js +82 -110
- package/dist/halal-core/ai/redactSensitiveData.js.map +1 -1
- package/dist/halal-core/ai/validateAiResponse.d.ts +4 -1
- package/dist/halal-core/ai/validateAiResponse.js +58 -85
- package/dist/halal-core/ai/validateAiResponse.js.map +1 -1
- package/dist/halal-core/cli/check.d.ts +3 -0
- package/dist/halal-core/cli/check.js +28 -30
- package/dist/halal-core/cli/check.js.map +1 -1
- package/dist/halal-core/cli/explain.d.ts +3 -0
- package/dist/halal-core/cli/explain.js +27 -31
- package/dist/halal-core/cli/explain.js.map +1 -1
- package/dist/halal-core/cli/report.d.ts +3 -0
- package/dist/halal-core/cli/report.js +14 -10
- package/dist/halal-core/cli/report.js.map +1 -1
- package/dist/halal-core/cli/submitReview.d.ts +3 -0
- package/dist/halal-core/cli/submitReview.js +13 -9
- package/dist/halal-core/cli/submitReview.js.map +1 -1
- package/dist/halal-core/cli/verifyReview.d.ts +3 -0
- package/dist/halal-core/cli/verifyReview.js +18 -15
- package/dist/halal-core/cli/verifyReview.js.map +1 -1
- package/dist/halal-core/config.d.ts +30 -27
- package/dist/halal-core/config.js +76 -118
- package/dist/halal-core/config.js.map +1 -1
- package/dist/halal-core/crypto/integrity.d.ts +6 -3
- package/dist/halal-core/crypto/integrity.js +64 -87
- package/dist/halal-core/crypto/integrity.js.map +1 -1
- package/dist/halal-core/enforce.d.ts +3 -0
- package/dist/halal-core/enforce.js +92 -105
- package/dist/halal-core/enforce.js.map +1 -1
- package/dist/halal-core/index.d.ts +20 -16
- package/dist/halal-core/index.js +18 -19
- package/dist/halal-core/lifecycle.d.ts +3 -0
- package/dist/halal-core/lifecycle.js +15 -13
- package/dist/halal-core/lifecycle.js.map +1 -1
- package/dist/halal-core/policy.d.ts +4 -1
- package/dist/halal-core/policy.js +6 -2
- package/dist/halal-core/policy.js.map +1 -1
- package/dist/halal-core/report/formatBrowserOverlay.d.ts +4 -1
- package/dist/halal-core/report/formatBrowserOverlay.js +10 -8
- package/dist/halal-core/report/formatBrowserOverlay.js.map +1 -1
- package/dist/halal-core/report/formatTerminalReport.d.ts +4 -1
- package/dist/halal-core/report/formatTerminalReport.js +27 -37
- package/dist/halal-core/report/formatTerminalReport.js.map +1 -1
- package/dist/halal-core/report/generateHalalReport.d.ts +7 -4
- package/dist/halal-core/report/generateHalalReport.js +26 -26
- package/dist/halal-core/report/generateHalalReport.js.map +1 -1
- package/dist/halal-core/report/signReport.d.ts +4 -1
- package/dist/halal-core/report/signReport.js +16 -12
- package/dist/halal-core/report/signReport.js.map +1 -1
- package/dist/halal-core/report/verifyReport.d.ts +9 -6
- package/dist/halal-core/report/verifyReport.js +51 -41
- package/dist/halal-core/report/verifyReport.js.map +1 -1
- package/dist/halal-core/review/createReviewRequest.d.ts +4 -1
- package/dist/halal-core/review/createReviewRequest.js +21 -17
- package/dist/halal-core/review/createReviewRequest.js.map +1 -1
- package/dist/halal-core/review/reviewPolicy.d.ts +3 -0
- package/dist/halal-core/review/reviewPolicy.js +19 -17
- package/dist/halal-core/review/reviewPolicy.js.map +1 -1
- package/dist/halal-core/review/signedReviewFile.d.ts +11 -8
- package/dist/halal-core/review/signedReviewFile.js +24 -22
- package/dist/halal-core/review/signedReviewFile.js.map +1 -1
- package/dist/halal-core/review/verifyReviewApproval.d.ts +9 -6
- package/dist/halal-core/review/verifyReviewApproval.js +68 -62
- package/dist/halal-core/review/verifyReviewApproval.js.map +1 -1
- package/dist/halal-core/rules/adultContentRules.d.ts +3 -0
- package/dist/halal-core/rules/adultContentRules.js +23 -23
- package/dist/halal-core/rules/adultContentRules.js.map +1 -1
- package/dist/halal-core/rules/alcoholDrugVapeRules.d.ts +3 -0
- package/dist/halal-core/rules/alcoholDrugVapeRules.js +22 -22
- package/dist/halal-core/rules/alcoholDrugVapeRules.js.map +1 -1
- package/dist/halal-core/rules/childSafetyRules.d.ts +3 -0
- package/dist/halal-core/rules/childSafetyRules.js +19 -19
- package/dist/halal-core/rules/childSafetyRules.js.map +1 -1
- package/dist/halal-core/rules/coreCategories.d.ts +7 -4
- package/dist/halal-core/rules/coreCategories.js +237 -110
- package/dist/halal-core/rules/coreCategories.js.map +1 -1
- package/dist/halal-core/rules/cyberAbuseRules.d.ts +3 -0
- package/dist/halal-core/rules/cyberAbuseRules.js +27 -27
- package/dist/halal-core/rules/cyberAbuseRules.js.map +1 -1
- package/dist/halal-core/rules/defaultBlockedRules.d.ts +21 -18
- package/dist/halal-core/rules/defaultBlockedRules.js +158 -199
- package/dist/halal-core/rules/defaultBlockedRules.js.map +1 -1
- package/dist/halal-core/rules/dependencyRules.d.ts +8 -5
- package/dist/halal-core/rules/dependencyRules.js +50 -56
- package/dist/halal-core/rules/dependencyRules.js.map +1 -1
- package/dist/halal-core/rules/endpointRules.d.ts +6 -3
- package/dist/halal-core/rules/endpointRules.js +21 -23
- package/dist/halal-core/rules/endpointRules.js.map +1 -1
- package/dist/halal-core/rules/environmentalHarmRules.d.ts +3 -0
- package/dist/halal-core/rules/environmentalHarmRules.js +17 -17
- package/dist/halal-core/rules/environmentalHarmRules.js.map +1 -1
- package/dist/halal-core/rules/financeRibaRules.d.ts +3 -0
- package/dist/halal-core/rules/financeRibaRules.js +20 -20
- package/dist/halal-core/rules/financeRibaRules.js.map +1 -1
- package/dist/halal-core/rules/gamblingRules.d.ts +3 -0
- package/dist/halal-core/rules/gamblingRules.js +22 -22
- package/dist/halal-core/rules/gamblingRules.js.map +1 -1
- package/dist/halal-core/rules/generalHarmRules.d.ts +3 -0
- package/dist/halal-core/rules/generalHarmRules.js +15 -15
- package/dist/halal-core/rules/generalHarmRules.js.map +1 -1
- package/dist/halal-core/rules/healthHarmRules.d.ts +3 -0
- package/dist/halal-core/rules/healthHarmRules.js +19 -19
- package/dist/halal-core/rules/healthHarmRules.js.map +1 -1
- package/dist/halal-core/rules/keywordRules.d.ts +11 -8
- package/dist/halal-core/rules/keywordRules.js +90 -39
- package/dist/halal-core/rules/keywordRules.js.map +1 -1
- package/dist/halal-core/rules/privacyAbuseRules.d.ts +3 -0
- package/dist/halal-core/rules/privacyAbuseRules.js +21 -21
- package/dist/halal-core/rules/privacyAbuseRules.js.map +1 -1
- package/dist/halal-core/rules/scamFraudRules.d.ts +3 -0
- package/dist/halal-core/rules/scamFraudRules.js +29 -29
- package/dist/halal-core/rules/scamFraudRules.js.map +1 -1
- package/dist/halal-core/rules/selfHarmRules.d.ts +3 -0
- package/dist/halal-core/rules/selfHarmRules.js +17 -17
- package/dist/halal-core/rules/selfHarmRules.js.map +1 -1
- package/dist/halal-core/rules/violenceExtremismRules.d.ts +3 -0
- package/dist/halal-core/rules/violenceExtremismRules.js +30 -30
- package/dist/halal-core/rules/violenceExtremismRules.js.map +1 -1
- package/dist/halal-core/runtime/guard.d.ts +17 -14
- package/dist/halal-core/runtime/guard.js +162 -183
- package/dist/halal-core/runtime/guard.js.map +1 -1
- package/dist/halal-core/runtime/index.d.ts +5 -4
- package/dist/halal-core/runtime/index.js +4 -5
- package/dist/halal-core/runtime/reviewedMemory.d.ts +4 -1
- package/dist/halal-core/runtime/reviewedMemory.js +74 -110
- package/dist/halal-core/runtime/reviewedMemory.js.map +1 -1
- package/dist/halal-core/runtime/serializeRuntimeContent.d.ts +10 -7
- package/dist/halal-core/runtime/serializeRuntimeContent.js +132 -156
- package/dist/halal-core/runtime/serializeRuntimeContent.js.map +1 -1
- package/dist/halal-core/runtime/types.d.ts +44 -41
- package/dist/halal-core/runtime/types.js +0 -1
- package/dist/halal-core/scanner/scanApiRoutes.d.ts +3 -0
- package/dist/halal-core/scanner/scanApiRoutes.js +32 -36
- package/dist/halal-core/scanner/scanApiRoutes.js.map +1 -1
- package/dist/halal-core/scanner/scanComponents.d.ts +3 -0
- package/dist/halal-core/scanner/scanComponents.js +12 -13
- package/dist/halal-core/scanner/scanComponents.js.map +1 -1
- package/dist/halal-core/scanner/scanContent.d.ts +5 -2
- package/dist/halal-core/scanner/scanContent.js +193 -263
- package/dist/halal-core/scanner/scanContent.js.map +1 -1
- package/dist/halal-core/scanner/scanDependencies.d.ts +3 -0
- package/dist/halal-core/scanner/scanDependencies.js +16 -15
- package/dist/halal-core/scanner/scanDependencies.js.map +1 -1
- package/dist/halal-core/scanner/scanDomains.d.ts +5 -2
- package/dist/halal-core/scanner/scanDomains.js +12 -12
- package/dist/halal-core/scanner/scanDomains.js.map +1 -1
- package/dist/halal-core/scanner/scanEnvNames.d.ts +3 -0
- package/dist/halal-core/scanner/scanEnvNames.js +23 -26
- package/dist/halal-core/scanner/scanEnvNames.js.map +1 -1
- package/dist/halal-core/scanner/scanMetadata.d.ts +6 -3
- package/dist/halal-core/scanner/scanMetadata.js +20 -29
- package/dist/halal-core/scanner/scanMetadata.js.map +1 -1
- package/dist/halal-core/scanner/scanPages.d.ts +3 -0
- package/dist/halal-core/scanner/scanPages.js +12 -15
- package/dist/halal-core/scanner/scanPages.js.map +1 -1
- package/dist/halal-core/scanner/scanProject.d.ts +15 -10
- package/dist/halal-core/scanner/scanProject.js +43 -49
- package/dist/halal-core/scanner/scanProject.js.map +1 -1
- package/dist/halal-core/scanner/scanRoutes.d.ts +3 -0
- package/dist/halal-core/scanner/scanRoutes.js +32 -39
- package/dist/halal-core/scanner/scanRoutes.js.map +1 -1
- package/dist/halal-core/scanner/scanTranslations.d.ts +3 -0
- package/dist/halal-core/scanner/scanTranslations.js +21 -29
- package/dist/halal-core/scanner/scanTranslations.js.map +1 -1
- package/dist/halal-core/status.d.ts +14 -11
- package/dist/halal-core/status.js +0 -1
- package/dist/halal-core/tamper/verifyCoreIntegrity.d.ts +3 -0
- package/dist/halal-core/tamper/verifyCoreIntegrity.js +26 -24
- package/dist/halal-core/tamper/verifyCoreIntegrity.js.map +1 -1
- package/dist/halal-core/tamper/verifyLifecycleHooks.d.ts +3 -0
- package/dist/halal-core/tamper/verifyLifecycleHooks.js +13 -12
- package/dist/halal-core/tamper/verifyLifecycleHooks.js.map +1 -1
- package/dist/halal-core/tamper/verifyReportSignature.d.ts +6 -3
- package/dist/halal-core/tamper/verifyReportSignature.js +20 -14
- package/dist/halal-core/tamper/verifyReportSignature.js.map +1 -1
- package/dist/halal.d.ts +20 -1
- package/dist/halal.js +18 -2
- package/dist/i18n/index.d.ts +34 -31
- package/dist/i18n/index.js +219 -288
- package/dist/i18n/index.js.map +1 -1
- package/dist/i18n/shared.d.ts +18 -15
- package/dist/i18n/shared.js +204 -266
- package/dist/i18n/shared.js.map +1 -1
- package/dist/icons/index.d.ts +143 -139
- package/dist/icons/index.js +322 -273
- package/dist/icons/index.js.map +1 -1
- package/dist/index.d.ts +8 -1
- package/dist/index.js +7 -2
- package/dist/kit/index.d.ts +9 -6
- package/dist/kit/index.js +45 -43
- package/dist/kit/index.js.map +1 -1
- package/dist/nitro-server/index.d.ts +7 -4
- package/dist/nitro-server/index.js +6 -2
- package/dist/nitro-server/index.js.map +1 -1
- package/dist/node.d.ts +6 -3
- package/dist/node.js +88 -116
- package/dist/node.js.map +1 -1
- package/dist/reactivity/computed.d.ts +6 -3
- package/dist/reactivity/computed.js +46 -53
- package/dist/reactivity/computed.js.map +1 -1
- package/dist/reactivity/effect.d.ts +8 -5
- package/dist/reactivity/effect.js +105 -146
- package/dist/reactivity/effect.js.map +1 -1
- package/dist/reactivity/index.d.ts +8 -8
- package/dist/reactivity/index.js +7 -8
- package/dist/reactivity/reactive.d.ts +3 -0
- package/dist/reactivity/reactive.js +93 -133
- package/dist/reactivity/reactive.js.map +1 -1
- package/dist/reactivity/readonly.d.ts +2 -1
- package/dist/reactivity/readonly.js +2 -2
- package/dist/reactivity/ref.d.ts +15 -15
- package/dist/reactivity/ref.js +73 -81
- package/dist/reactivity/ref.js.map +1 -1
- package/dist/reactivity/scheduler.d.ts +3 -1
- package/dist/reactivity/scheduler.js +67 -69
- package/dist/reactivity/scheduler.js.map +1 -1
- package/dist/reactivity/types.d.ts +17 -14
- package/dist/reactivity/types.js +0 -1
- package/dist/reactivity/utils.d.ts +7 -4
- package/dist/reactivity/utils.js +25 -24
- package/dist/reactivity/utils.js.map +1 -1
- package/dist/reactivity/watch.d.ts +4 -2
- package/dist/reactivity/watch.js +75 -103
- package/dist/reactivity/watch.js.map +1 -1
- package/dist/runtime/core.d.ts +31 -0
- package/dist/runtime/core.js +156 -0
- package/dist/runtime/core.js.map +1 -0
- package/dist/runtime/index.d.ts +487 -461
- package/dist/runtime/index.js +4129 -5254
- package/dist/runtime/index.js.map +1 -1
- package/dist/runtime/reactivity.d.ts +7 -0
- package/dist/runtime/reactivity.js +6 -0
- package/dist/runtime/resume.d.ts +79 -0
- package/dist/runtime/resume.js +482 -0
- package/dist/runtime/resume.js.map +1 -0
- package/dist/runtime/router.d.ts +20 -0
- package/dist/runtime/router.js +60 -0
- package/dist/runtime/router.js.map +1 -0
- package/dist/runtime/streaming.d.ts +24 -0
- package/dist/runtime/streaming.js +200 -0
- package/dist/runtime/streaming.js.map +1 -0
- package/dist/security/media-fetch.d.ts +32 -0
- package/dist/security/media-fetch.js +301 -0
- package/dist/security/media-fetch.js.map +1 -0
- package/dist/security/path-boundary.d.ts +7 -0
- package/dist/security/path-boundary.js +70 -0
- package/dist/security/path-boundary.js.map +1 -0
- package/dist/ui/index.d.ts +1580 -1576
- package/dist/ui/index.js +975 -674
- package/dist/ui/index.js.map +1 -1
- package/dist/vite-builder/index.d.ts +6 -3
- package/dist/vite-builder/index.js +6 -2
- package/dist/vite-builder/index.js.map +1 -1
- package/package.json +46 -86
- package/dist/compiler/implementation.js.map +0 -1
- package/dist/core/index.js.map +0 -1
- package/dist/deploy/types.js.map +0 -1
- package/dist/globals.js.map +0 -1
- package/dist/halal-core/index.js.map +0 -1
- package/dist/halal-core/runtime/index.js.map +0 -1
- package/dist/halal-core/runtime/types.js.map +0 -1
- package/dist/halal-core/status.js.map +0 -1
- package/dist/halal.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/reactivity/index.js.map +0 -1
- package/dist/reactivity/readonly.js.map +0 -1
- package/dist/reactivity/types.js.map +0 -1
package/dist/create.js
CHANGED
|
@@ -1,472 +1,365 @@
|
|
|
1
1
|
import { spawn } from "node:child_process";
|
|
2
2
|
import { lstat, mkdir, readFile, readdir, rm, writeFile } from "node:fs/promises";
|
|
3
|
-
import { homedir } from "node:os";
|
|
4
3
|
import path from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import { homedir } from "node:os";
|
|
5
6
|
import { stdin, stdout } from "node:process";
|
|
6
7
|
import { createInterface } from "node:readline/promises";
|
|
7
|
-
|
|
8
|
+
//#region src/create.ts
|
|
8
9
|
const defaultProjectName = "resux-app";
|
|
9
|
-
const packageManagers = new Set([
|
|
10
|
+
const packageManagers = /* @__PURE__ */ new Set([
|
|
11
|
+
"npm",
|
|
12
|
+
"pnpm",
|
|
13
|
+
"yarn",
|
|
14
|
+
"bun"
|
|
15
|
+
]);
|
|
10
16
|
const starterTemplates = [
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
"minimal",
|
|
18
|
+
"default",
|
|
19
|
+
"full",
|
|
20
|
+
"i18n",
|
|
21
|
+
"pwa",
|
|
22
|
+
"media",
|
|
23
|
+
"package-compatibility",
|
|
24
|
+
"dashboard"
|
|
19
25
|
];
|
|
20
26
|
const starterFeatures = [
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
"seo",
|
|
28
|
+
"i18n",
|
|
29
|
+
"media",
|
|
30
|
+
"pwa",
|
|
31
|
+
"tailwind",
|
|
32
|
+
"package-compatibility",
|
|
33
|
+
"server-api",
|
|
34
|
+
"tests"
|
|
29
35
|
];
|
|
30
|
-
if (isMainModule()) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
36
|
+
if (isMainModule()) runCreateResux(process.argv.slice(2)).catch((error) => {
|
|
37
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
38
|
+
process.exitCode = 1;
|
|
39
|
+
});
|
|
40
|
+
async function runCreateResux(args = process.argv.slice(2)) {
|
|
41
|
+
const options = parseArgs(args);
|
|
42
|
+
if (options.help) {
|
|
43
|
+
printHelp();
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
const prompts = createInterface({
|
|
47
|
+
input: stdin,
|
|
48
|
+
output: stdout
|
|
49
|
+
});
|
|
50
|
+
try {
|
|
51
|
+
const targetDir = await readTargetDir(options, prompts);
|
|
52
|
+
const root = path.resolve(process.cwd(), targetDir);
|
|
53
|
+
const projectName = toPackageName(path.basename(root));
|
|
54
|
+
const title = toTitle(projectName);
|
|
55
|
+
const frameworkPackage = await readFrameworkPackage();
|
|
56
|
+
const template = await readStarterTemplate(options, prompts);
|
|
57
|
+
const features = uniqueFeatures([...defaultFeaturesForTemplate(template), ...await readStarterFeatures(options, prompts, template)]);
|
|
58
|
+
const hreflang = await readHreflangSupport(options, prompts, features);
|
|
59
|
+
const install = options.install ?? await promptConfirm(prompts, "Install dependencies?", canPrompt(), options.yes);
|
|
60
|
+
const packageManager = options.packageManager ?? detectPackageManager();
|
|
61
|
+
assertSafeCreateTarget(root, process.cwd(), options.force);
|
|
62
|
+
await prepareTarget(root, options.force);
|
|
63
|
+
await copyTemplate(path.resolve(fileURLToPath(new URL("../templates/default", import.meta.url))), root, {
|
|
64
|
+
"%PROJECT_NAME%": projectName,
|
|
65
|
+
"%PROJECT_TITLE%": title
|
|
66
|
+
});
|
|
67
|
+
await writeFile(path.join(root, "package.json"), createStarterPackageJson(projectName, frameworkPackage, features, template), "utf8");
|
|
68
|
+
await applyStarterFeatureScaffold(root, title, features, { hreflang });
|
|
69
|
+
await ensureStarterProjectStructure(root, title, features, template);
|
|
70
|
+
if (install) await installDependencies(root, packageManager);
|
|
71
|
+
printNextSteps({
|
|
72
|
+
root,
|
|
73
|
+
packageManager,
|
|
74
|
+
installed: install,
|
|
75
|
+
features,
|
|
76
|
+
template
|
|
77
|
+
});
|
|
78
|
+
} finally {
|
|
79
|
+
prompts.close();
|
|
80
|
+
}
|
|
75
81
|
}
|
|
76
82
|
function parseArgs(args) {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
options.template = readTemplate(arg.slice("--template=".length));
|
|
104
|
-
}
|
|
105
|
-
else if (arg === "--features") {
|
|
106
|
-
options.features = normalizeFeatureList(args[++index]);
|
|
107
|
-
}
|
|
108
|
-
else if (arg.startsWith("--features=")) {
|
|
109
|
-
options.features = normalizeFeatureList(arg.slice("--features=".length));
|
|
110
|
-
}
|
|
111
|
-
else if (arg === "--package-manager" || arg === "--pm") {
|
|
112
|
-
options.packageManager = readPackageManager(args[++index]);
|
|
113
|
-
}
|
|
114
|
-
else if (arg.startsWith("--package-manager=")) {
|
|
115
|
-
options.packageManager = readPackageManager(arg.slice("--package-manager=".length));
|
|
116
|
-
}
|
|
117
|
-
else if (arg.startsWith("--pm=")) {
|
|
118
|
-
options.packageManager = readPackageManager(arg.slice("--pm=".length));
|
|
119
|
-
}
|
|
120
|
-
else if (arg === "--hreflang") {
|
|
121
|
-
options.hreflang = true;
|
|
122
|
-
}
|
|
123
|
-
else if (arg === "--no-hreflang") {
|
|
124
|
-
options.hreflang = false;
|
|
125
|
-
}
|
|
126
|
-
else if (arg.startsWith("-")) {
|
|
127
|
-
throw new Error(`Unknown option "${arg}". Run resux init --help for usage.`);
|
|
128
|
-
}
|
|
129
|
-
else if (!options.targetDir) {
|
|
130
|
-
options.targetDir = arg;
|
|
131
|
-
}
|
|
132
|
-
else {
|
|
133
|
-
throw new Error(`Unexpected argument "${arg}". Only one project directory can be provided.`);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
return options;
|
|
83
|
+
const options = {
|
|
84
|
+
force: false,
|
|
85
|
+
yes: false,
|
|
86
|
+
help: false
|
|
87
|
+
};
|
|
88
|
+
for (let index = 0; index < args.length; index++) {
|
|
89
|
+
const arg = args[index];
|
|
90
|
+
if (arg === "-h" || arg === "--help") options.help = true;
|
|
91
|
+
else if (arg === "-y" || arg === "--yes") options.yes = true;
|
|
92
|
+
else if (arg === "--install") options.install = true;
|
|
93
|
+
else if (arg === "--no-install") options.install = false;
|
|
94
|
+
else if (arg === "--force") options.force = true;
|
|
95
|
+
else if (arg === "--template") options.template = readTemplate(args[++index]);
|
|
96
|
+
else if (arg.startsWith("--template=")) options.template = readTemplate(arg.slice(11));
|
|
97
|
+
else if (arg === "--features") options.features = normalizeFeatureList(args[++index]);
|
|
98
|
+
else if (arg.startsWith("--features=")) options.features = normalizeFeatureList(arg.slice(11));
|
|
99
|
+
else if (arg === "--package-manager" || arg === "--pm") options.packageManager = readPackageManager(args[++index]);
|
|
100
|
+
else if (arg.startsWith("--package-manager=")) options.packageManager = readPackageManager(arg.slice(18));
|
|
101
|
+
else if (arg.startsWith("--pm=")) options.packageManager = readPackageManager(arg.slice(5));
|
|
102
|
+
else if (arg === "--hreflang") options.hreflang = true;
|
|
103
|
+
else if (arg === "--no-hreflang") options.hreflang = false;
|
|
104
|
+
else if (arg.startsWith("-")) throw new Error(`Unknown option "${arg}". Run resux init --help for usage.`);
|
|
105
|
+
else if (!options.targetDir) options.targetDir = arg;
|
|
106
|
+
else throw new Error(`Unexpected argument "${arg}". Only one project directory can be provided.`);
|
|
107
|
+
}
|
|
108
|
+
return options;
|
|
137
109
|
}
|
|
138
110
|
function readPackageManager(value) {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
}
|
|
142
|
-
return value;
|
|
111
|
+
if (!value || !packageManagers.has(value)) throw new Error("Package manager must be one of npm, pnpm, yarn, or bun.");
|
|
112
|
+
return value;
|
|
143
113
|
}
|
|
144
114
|
function readTemplate(value) {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
}
|
|
148
|
-
return value;
|
|
115
|
+
if (!value || !starterTemplates.includes(value)) throw new Error(`Template must be one of: ${starterTemplates.join(", ")}.`);
|
|
116
|
+
return value;
|
|
149
117
|
}
|
|
150
118
|
function normalizeFeatureList(raw) {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
const feature = entry;
|
|
165
|
-
if (!seen.has(feature)) {
|
|
166
|
-
seen.add(feature);
|
|
167
|
-
selected.push(feature);
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
return selected;
|
|
119
|
+
if (!raw) return [];
|
|
120
|
+
const entries = raw.split(",").map((entry) => entry.trim().toLowerCase()).filter(Boolean);
|
|
121
|
+
const selected = [];
|
|
122
|
+
const seen = /* @__PURE__ */ new Set();
|
|
123
|
+
for (const entry of entries) {
|
|
124
|
+
if (!starterFeatures.includes(entry)) throw new Error(`Unknown feature "${entry}". Supported features: ${starterFeatures.join(", ")}.`);
|
|
125
|
+
const feature = entry;
|
|
126
|
+
if (!seen.has(feature)) {
|
|
127
|
+
seen.add(feature);
|
|
128
|
+
selected.push(feature);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return selected;
|
|
171
132
|
}
|
|
172
133
|
function uniqueFeatures(features) {
|
|
173
|
-
|
|
134
|
+
return [...new Set(features)];
|
|
174
135
|
}
|
|
175
136
|
function defaultFeaturesForTemplate(template) {
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
return ["seo"];
|
|
137
|
+
if (template === "minimal") return [];
|
|
138
|
+
if (template === "full") return [
|
|
139
|
+
"seo",
|
|
140
|
+
"i18n",
|
|
141
|
+
"media",
|
|
142
|
+
"pwa",
|
|
143
|
+
"tailwind",
|
|
144
|
+
"package-compatibility",
|
|
145
|
+
"server-api",
|
|
146
|
+
"tests"
|
|
147
|
+
];
|
|
148
|
+
if (template === "i18n") return ["i18n"];
|
|
149
|
+
if (template === "pwa") return ["pwa"];
|
|
150
|
+
if (template === "media") return ["media"];
|
|
151
|
+
if (template === "package-compatibility") return ["package-compatibility"];
|
|
152
|
+
if (template === "dashboard") return [
|
|
153
|
+
"seo",
|
|
154
|
+
"tailwind",
|
|
155
|
+
"server-api"
|
|
156
|
+
];
|
|
157
|
+
return ["seo"];
|
|
198
158
|
}
|
|
199
159
|
async function readStarterTemplate(options, prompts) {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
}
|
|
206
|
-
const answer = (await prompts.question(`Template (${starterTemplates.join(", ")}) [default]: `)).trim();
|
|
207
|
-
if (!answer) {
|
|
208
|
-
return "default";
|
|
209
|
-
}
|
|
210
|
-
return readTemplate(answer);
|
|
160
|
+
if (options.template) return options.template;
|
|
161
|
+
if (options.yes || !canPrompt()) return "default";
|
|
162
|
+
const answer = (await prompts.question(`Template (${starterTemplates.join(", ")}) [default]: `)).trim();
|
|
163
|
+
if (!answer) return "default";
|
|
164
|
+
return readTemplate(answer);
|
|
211
165
|
}
|
|
212
166
|
async function readStarterFeatures(options, prompts, template) {
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
];
|
|
240
|
-
const templateDefaults = new Set(defaultFeaturesForTemplate(template));
|
|
241
|
-
for (const feature of promptOrder) {
|
|
242
|
-
const enabled = await promptConfirm(prompts, `Enable ${labels[feature]}?`, templateDefaults.has(feature), false);
|
|
243
|
-
if (enabled) {
|
|
244
|
-
selected.push(feature);
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
return selected;
|
|
167
|
+
if (Array.isArray(options.features)) return options.features;
|
|
168
|
+
if (options.yes || !canPrompt()) return [];
|
|
169
|
+
const selected = [];
|
|
170
|
+
const labels = {
|
|
171
|
+
seo: "SEO utilities",
|
|
172
|
+
i18n: "i18n (localized routes + translations)",
|
|
173
|
+
media: "media page + helpers",
|
|
174
|
+
pwa: "PWA manifest scaffold",
|
|
175
|
+
tailwind: "Tailwind CSS setup",
|
|
176
|
+
"package-compatibility": "third-party package compatibility examples",
|
|
177
|
+
"server-api": "server API and route examples",
|
|
178
|
+
tests: "basic tests scaffold"
|
|
179
|
+
};
|
|
180
|
+
const promptOrder = [
|
|
181
|
+
"tailwind",
|
|
182
|
+
"i18n",
|
|
183
|
+
"pwa",
|
|
184
|
+
"media",
|
|
185
|
+
"package-compatibility",
|
|
186
|
+
"server-api",
|
|
187
|
+
"tests",
|
|
188
|
+
"seo"
|
|
189
|
+
];
|
|
190
|
+
const templateDefaults = new Set(defaultFeaturesForTemplate(template));
|
|
191
|
+
for (const feature of promptOrder) if (await promptConfirm(prompts, `Enable ${labels[feature]}?`, templateDefaults.has(feature), false)) selected.push(feature);
|
|
192
|
+
return selected;
|
|
248
193
|
}
|
|
249
194
|
async function readHreflangSupport(options, prompts, features) {
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
return options.hreflang;
|
|
255
|
-
}
|
|
256
|
-
if (options.yes || !canPrompt()) {
|
|
257
|
-
return false;
|
|
258
|
-
}
|
|
259
|
-
return promptConfirm(prompts, "Add hreflang alternate links?", false, false);
|
|
195
|
+
if (!features.includes("i18n") && !features.includes("seo")) return false;
|
|
196
|
+
if (typeof options.hreflang === "boolean") return options.hreflang;
|
|
197
|
+
if (options.yes || !canPrompt()) return false;
|
|
198
|
+
return promptConfirm(prompts, "Add hreflang alternate links?", false, false);
|
|
260
199
|
}
|
|
261
200
|
async function readTargetDir(options, prompts) {
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
if (options.yes || !canPrompt()) {
|
|
266
|
-
return defaultProjectName;
|
|
267
|
-
}
|
|
268
|
-
const answer = await prompts.question(`Project name (${defaultProjectName}): `);
|
|
269
|
-
return answer.trim() || defaultProjectName;
|
|
201
|
+
if (options.targetDir) return options.targetDir;
|
|
202
|
+
if (options.yes || !canPrompt()) return defaultProjectName;
|
|
203
|
+
return (await prompts.question(`Project name (${defaultProjectName}): `)).trim() || defaultProjectName;
|
|
270
204
|
}
|
|
271
205
|
async function promptConfirm(prompts, label, defaultValue, yes) {
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
if (!answer) {
|
|
278
|
-
return defaultValue;
|
|
279
|
-
}
|
|
280
|
-
return answer === "y" || answer === "yes";
|
|
206
|
+
if (yes || !canPrompt()) return defaultValue;
|
|
207
|
+
const suffix = defaultValue ? "Y/n" : "y/N";
|
|
208
|
+
const answer = (await prompts.question(`${label} (${suffix}) `)).trim().toLowerCase();
|
|
209
|
+
if (!answer) return defaultValue;
|
|
210
|
+
return answer === "y" || answer === "yes";
|
|
281
211
|
}
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
const containsWorkingDirectory = relativeWorkingDirectory === ""
|
|
292
|
-
|| (!relativeWorkingDirectory.startsWith("..") && !path.isAbsolute(relativeWorkingDirectory));
|
|
293
|
-
if (target === filesystemRoot || target === homeDirectory || containsWorkingDirectory) {
|
|
294
|
-
throw new Error(`Refusing to use --force on protected directory "${target}". Choose a new child directory instead.`);
|
|
295
|
-
}
|
|
212
|
+
function assertSafeCreateTarget(root, cwd, force) {
|
|
213
|
+
if (!force) return;
|
|
214
|
+
const target = path.resolve(root);
|
|
215
|
+
const workingDirectory = path.resolve(cwd);
|
|
216
|
+
const filesystemRoot = path.parse(target).root;
|
|
217
|
+
const homeDirectory = path.resolve(homedir());
|
|
218
|
+
const relativeWorkingDirectory = path.relative(target, workingDirectory);
|
|
219
|
+
const containsWorkingDirectory = relativeWorkingDirectory === "" || !relativeWorkingDirectory.startsWith("..") && !path.isAbsolute(relativeWorkingDirectory);
|
|
220
|
+
if (target === filesystemRoot || target === homeDirectory || containsWorkingDirectory) throw new Error(`Refusing to use --force on protected directory "${target}". Choose a new child directory instead.`);
|
|
296
221
|
}
|
|
297
222
|
async function assertCreatePathHasNoSymlinkComponents(target) {
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
if (!info) {
|
|
312
|
-
break;
|
|
313
|
-
}
|
|
314
|
-
if (info.isSymbolicLink()) {
|
|
315
|
-
throw new Error(`Refusing to create a Resux project through symbolic link component "${current}". Choose a real directory instead.`);
|
|
316
|
-
}
|
|
317
|
-
}
|
|
223
|
+
const absoluteTarget = path.resolve(target);
|
|
224
|
+
const filesystemRoot = path.parse(absoluteTarget).root;
|
|
225
|
+
const segments = path.relative(filesystemRoot, absoluteTarget).split(path.sep).filter(Boolean);
|
|
226
|
+
let current = filesystemRoot;
|
|
227
|
+
for (const segment of segments) {
|
|
228
|
+
current = path.join(current, segment);
|
|
229
|
+
const info = await lstat(current).catch((error) => {
|
|
230
|
+
if (error.code === "ENOENT") return null;
|
|
231
|
+
throw error;
|
|
232
|
+
});
|
|
233
|
+
if (!info) break;
|
|
234
|
+
if (info.isSymbolicLink()) throw new Error(`Refusing to create a Resux project through symbolic link component "${current}". Choose a real directory instead.`);
|
|
235
|
+
}
|
|
318
236
|
}
|
|
319
237
|
async function prepareTarget(root, force) {
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
if (currentIdentity.dev !== rootIdentity.dev || currentIdentity.ino !== rootIdentity.ino) {
|
|
338
|
-
throw new Error(`Refusing to continue because target directory "${root}" changed during --force cleanup.`);
|
|
339
|
-
}
|
|
340
|
-
await rm(path.join(root, entry), { recursive: true, force: true });
|
|
341
|
-
}
|
|
238
|
+
await assertCreatePathHasNoSymlinkComponents(root);
|
|
239
|
+
await mkdir(root, { recursive: true });
|
|
240
|
+
await assertCreatePathHasNoSymlinkComponents(root);
|
|
241
|
+
const rootIdentity = await lstat(root);
|
|
242
|
+
if (!rootIdentity.isDirectory()) throw new Error(`Target "${root}" is not a directory.`);
|
|
243
|
+
const entries = await readdir(root);
|
|
244
|
+
if (entries.length === 0) return;
|
|
245
|
+
if (!force) throw new Error(`Target directory "${root}" is not empty. Choose another name or pass --force.`);
|
|
246
|
+
for (const entry of entries) {
|
|
247
|
+
await assertCreatePathHasNoSymlinkComponents(root);
|
|
248
|
+
const currentIdentity = await lstat(root);
|
|
249
|
+
if (currentIdentity.dev !== rootIdentity.dev || currentIdentity.ino !== rootIdentity.ino) throw new Error(`Refusing to continue because target directory "${root}" changed during --force cleanup.`);
|
|
250
|
+
await rm(path.join(root, entry), {
|
|
251
|
+
recursive: true,
|
|
252
|
+
force: true
|
|
253
|
+
});
|
|
254
|
+
}
|
|
342
255
|
}
|
|
343
256
|
async function copyTemplate(sourceRoot, targetRoot, replacements) {
|
|
344
|
-
|
|
257
|
+
await copyDirectory(sourceRoot, targetRoot, "", replacements);
|
|
345
258
|
}
|
|
346
259
|
async function copyDirectory(sourceDir, targetDir, relativeDir, replacements) {
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
await copyEntry(entry, sourceDir, targetDir, relativeDir, replacements);
|
|
351
|
-
}
|
|
260
|
+
await mkdir(targetDir, { recursive: true });
|
|
261
|
+
const entries = await readdir(sourceDir, { withFileTypes: true });
|
|
262
|
+
for (const entry of entries) await copyEntry(entry, sourceDir, targetDir, relativeDir, replacements);
|
|
352
263
|
}
|
|
353
264
|
async function copyEntry(entry, sourceDir, targetDir, relativeDir, replacements) {
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
for (const [needle, value] of Object.entries(replacements)) {
|
|
367
|
-
contents = contents.replaceAll(needle, value);
|
|
368
|
-
}
|
|
369
|
-
await writeFile(target, contents, "utf8");
|
|
265
|
+
const source = path.join(sourceDir, entry.name);
|
|
266
|
+
const targetName = entry.name === "_gitignore" ? ".gitignore" : entry.name;
|
|
267
|
+
const target = path.join(targetDir, targetName);
|
|
268
|
+
const relativePath = path.join(relativeDir, entry.name);
|
|
269
|
+
if (entry.isDirectory()) {
|
|
270
|
+
await copyDirectory(source, target, relativePath, replacements);
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
if (!entry.isFile()) return;
|
|
274
|
+
let contents = await readFile(source, "utf8");
|
|
275
|
+
for (const [needle, value] of Object.entries(replacements)) contents = contents.replaceAll(needle, value);
|
|
276
|
+
await writeFile(target, contents, "utf8");
|
|
370
277
|
}
|
|
371
278
|
async function readFrameworkPackage() {
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
279
|
+
const packageJsonPath = fileURLToPath(new URL("../package.json", import.meta.url));
|
|
280
|
+
const contents = await readFile(packageJsonPath, "utf8");
|
|
281
|
+
const packageJson = JSON.parse(contents);
|
|
282
|
+
return {
|
|
283
|
+
name: typeof packageJson.name === "string" ? packageJson.name : "resuxjs",
|
|
284
|
+
version: typeof packageJson.version === "string" ? packageJson.version : "0.0.0"
|
|
285
|
+
};
|
|
379
286
|
}
|
|
380
287
|
function createStarterPackageJson(projectName, frameworkPackage, features, template) {
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
devDependencies,
|
|
414
|
-
engines: {
|
|
415
|
-
node: ">=20.19.0",
|
|
416
|
-
},
|
|
417
|
-
}, null, 2)}\n`;
|
|
288
|
+
const selected = new Set(features);
|
|
289
|
+
const includeTests = selected.has("tests") || template === "default" || template === "full";
|
|
290
|
+
const devDependencies = {
|
|
291
|
+
"@types/node": "^24.10.1",
|
|
292
|
+
"typescript": "^5.9.3",
|
|
293
|
+
"vue-tsc": "^3.3.8"
|
|
294
|
+
};
|
|
295
|
+
if (includeTests) devDependencies.vitest = "^4.0.8";
|
|
296
|
+
if (selected.has("tailwind")) {
|
|
297
|
+
devDependencies.tailwindcss = "^3.4.17";
|
|
298
|
+
devDependencies.postcss = "^8.5.6";
|
|
299
|
+
devDependencies.autoprefixer = "^10.4.22";
|
|
300
|
+
}
|
|
301
|
+
return `${JSON.stringify({
|
|
302
|
+
name: projectName,
|
|
303
|
+
private: true,
|
|
304
|
+
type: "module",
|
|
305
|
+
scripts: {
|
|
306
|
+
prepare: "resux prepare",
|
|
307
|
+
dev: "resux dev",
|
|
308
|
+
build: "resux build",
|
|
309
|
+
preview: "resux preview",
|
|
310
|
+
start: "resux start",
|
|
311
|
+
inspect: "resux inspect",
|
|
312
|
+
typecheck: "vue-tsc --noEmit",
|
|
313
|
+
...includeTests ? { test: "vitest run" } : {}
|
|
314
|
+
},
|
|
315
|
+
dependencies: { [frameworkPackage.name]: `^${frameworkPackage.version}` },
|
|
316
|
+
devDependencies,
|
|
317
|
+
engines: { node: ">=20.19.0" },
|
|
318
|
+
overrides: { nitropack: { "rollup-plugin-visualizer": "6.0.11" } }
|
|
319
|
+
}, null, 2)}\n`;
|
|
418
320
|
}
|
|
419
321
|
async function applyStarterFeatureScaffold(root, title, features, options) {
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
}
|
|
432
|
-
if (selected.has("pwa")) {
|
|
433
|
-
await scaffoldPwaFiles(root, title);
|
|
434
|
-
}
|
|
435
|
-
await extendDefaultLayoutNavigation(root, selected);
|
|
436
|
-
await annotateStarterReadme(root, selected);
|
|
322
|
+
const selected = new Set(features);
|
|
323
|
+
await writeFile(path.join(root, "resux.config.ts"), createStarterResuxConfig(title, selected, options), "utf8");
|
|
324
|
+
if (!selected.has("seo")) {
|
|
325
|
+
await removeSeoFromPage(path.join(root, "pages", "index.vue"));
|
|
326
|
+
await removeSeoFromPage(path.join(root, "pages", "about.vue"));
|
|
327
|
+
}
|
|
328
|
+
if (selected.has("i18n")) await scaffoldI18nFiles(root);
|
|
329
|
+
if (selected.has("media")) await scaffoldMediaPage(root);
|
|
330
|
+
if (selected.has("pwa")) await scaffoldPwaFiles(root, title);
|
|
331
|
+
await extendDefaultLayoutNavigation(root, selected);
|
|
332
|
+
await annotateStarterReadme(root, selected);
|
|
437
333
|
}
|
|
438
334
|
async function ensureStarterProjectStructure(root, title, features, template) {
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
await ensureFile(path.join(root, "types", "app.d.ts"), 'import "resuxjs/globals";\n\nexport {};\n');
|
|
468
|
-
await ensureFile(path.join(root, "types", "assets.d.ts"), 'declare module "*.css";\n');
|
|
469
|
-
await ensureFile(path.join(root, "assets", "css", "main.css"), `:root {
|
|
335
|
+
const selected = new Set(features);
|
|
336
|
+
const shouldIncludeTests = selected.has("tests") || template === "default" || template === "full";
|
|
337
|
+
const shouldIncludeServerApi = selected.has("server-api") || template === "default" || template === "full";
|
|
338
|
+
const shouldIncludePackageExamples = selected.has("package-compatibility") || template === "package-compatibility" || template === "full";
|
|
339
|
+
for (const relativeDir of [
|
|
340
|
+
"pages",
|
|
341
|
+
"layouts",
|
|
342
|
+
"components",
|
|
343
|
+
"composables",
|
|
344
|
+
"utils",
|
|
345
|
+
"shared",
|
|
346
|
+
"middleware",
|
|
347
|
+
"plugins",
|
|
348
|
+
"server/api",
|
|
349
|
+
"server/routes",
|
|
350
|
+
"server/middleware",
|
|
351
|
+
"server/plugins",
|
|
352
|
+
"server/utils",
|
|
353
|
+
"public/images",
|
|
354
|
+
"assets/css",
|
|
355
|
+
"types",
|
|
356
|
+
"tests"
|
|
357
|
+
]) await mkdir(path.join(root, relativeDir), { recursive: true });
|
|
358
|
+
await ensureFile(path.join(root, ".npmrc"), "engine-strict=true\n");
|
|
359
|
+
await ensureFile(path.join(root, ".env.example"), "# Runtime environment defaults\nAPP_ORIGIN=http://localhost:3000\n");
|
|
360
|
+
await ensureFile(path.join(root, "types", "app.d.ts"), "import \"resuxjs/globals\";\n\nexport {};\n");
|
|
361
|
+
await ensureFile(path.join(root, "types", "assets.d.ts"), "declare module \"*.css\";\n");
|
|
362
|
+
await ensureFile(path.join(root, "assets", "css", "main.css"), `:root {
|
|
470
363
|
--rx-bg: #020617;
|
|
471
364
|
--rx-surface: #0f172a;
|
|
472
365
|
--rx-text: #e2e8f0;
|
|
@@ -488,7 +381,7 @@ a {
|
|
|
488
381
|
color: var(--rx-accent);
|
|
489
382
|
}
|
|
490
383
|
`);
|
|
491
|
-
|
|
384
|
+
await ensureFile(path.join(root, "components", "AppHeader.vue"), `<template>
|
|
492
385
|
<header class="starter-header">
|
|
493
386
|
<ResuxLink to="/">${title}</ResuxLink>
|
|
494
387
|
<nav>
|
|
@@ -512,7 +405,7 @@ nav {
|
|
|
512
405
|
}
|
|
513
406
|
</style>
|
|
514
407
|
`);
|
|
515
|
-
|
|
408
|
+
await ensureFile(path.join(root, "components", "AppFooter.vue"), `<template>
|
|
516
409
|
<footer class="starter-footer">
|
|
517
410
|
<small>Powered by Resux</small>
|
|
518
411
|
</footer>
|
|
@@ -525,7 +418,7 @@ nav {
|
|
|
525
418
|
}
|
|
526
419
|
</style>
|
|
527
420
|
`);
|
|
528
|
-
|
|
421
|
+
await ensureFile(path.join(root, "composables", "useCounter.ts"), `export function useCounter(key = "starter-counter") {
|
|
529
422
|
const count = useState<number>(key, () => 0);
|
|
530
423
|
const increment = () => {
|
|
531
424
|
count.value += 1;
|
|
@@ -536,39 +429,39 @@ nav {
|
|
|
536
429
|
return { count, increment, decrement };
|
|
537
430
|
}
|
|
538
431
|
`);
|
|
539
|
-
|
|
432
|
+
await ensureFile(path.join(root, "utils", "formatDate.ts"), `export function formatDate(input: string | number | Date): string {
|
|
540
433
|
const date = input instanceof Date ? input : new Date(input);
|
|
541
434
|
return new Intl.DateTimeFormat("en-US", { dateStyle: "medium" }).format(date);
|
|
542
435
|
}
|
|
543
436
|
`);
|
|
544
|
-
|
|
437
|
+
await ensureFile(path.join(root, "shared", "constants.ts"), `export const APP_NAME = ${JSON.stringify(title)};
|
|
545
438
|
`);
|
|
546
|
-
|
|
439
|
+
await ensureFile(path.join(root, "middleware", "analytics.global.ts"), `export default defineResuxRouteMiddleware((to, from) => {
|
|
547
440
|
if (to.path === from.path) {
|
|
548
441
|
return;
|
|
549
442
|
}
|
|
550
443
|
console.debug("[resux] analytics", { from: from.path, to: to.path });
|
|
551
444
|
});
|
|
552
445
|
`);
|
|
553
|
-
|
|
446
|
+
await ensureFile(path.join(root, "plugins", "example.ts"), `export default defineResuxPlugin((app) => {
|
|
554
447
|
app.provide("examplePlugin", "plugins/example.ts loaded");
|
|
555
448
|
});
|
|
556
449
|
`);
|
|
557
|
-
|
|
450
|
+
await ensureFile(path.join(root, "plugins", "client-only.client.ts"), `export default defineResuxPlugin(() => {
|
|
558
451
|
if (typeof window !== "undefined") {
|
|
559
452
|
console.debug("[resux] client-only plugin ready");
|
|
560
453
|
}
|
|
561
454
|
});
|
|
562
455
|
`);
|
|
563
|
-
|
|
456
|
+
await ensureFile(path.join(root, "plugins", "server-only.server.ts"), `export default defineResuxPlugin(() => {
|
|
564
457
|
console.debug("[resux] server-only plugin ready");
|
|
565
458
|
});
|
|
566
459
|
`);
|
|
567
|
-
|
|
460
|
+
await ensureFile(path.join(root, "server", "utils", "serverHelper.ts"), `export function serverHelper(name: string): string {
|
|
568
461
|
return "hello " + name;
|
|
569
462
|
}
|
|
570
463
|
`);
|
|
571
|
-
|
|
464
|
+
await ensureFile(path.join(root, "server", "middleware", "logger.ts"), `import { defineEventHandler } from "h3";
|
|
572
465
|
|
|
573
466
|
export default defineEventHandler((event) => {
|
|
574
467
|
const method = event.node.req.method ?? "GET";
|
|
@@ -576,36 +469,35 @@ export default defineEventHandler((event) => {
|
|
|
576
469
|
console.debug("[resux] request", method, path);
|
|
577
470
|
});
|
|
578
471
|
`);
|
|
579
|
-
|
|
472
|
+
await ensureFile(path.join(root, "public", "favicon.svg"), `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 128 128" role="img" aria-label="Resux">
|
|
580
473
|
<rect width="128" height="128" rx="24" fill="#0f172a" />
|
|
581
474
|
<path d="M32 30h30c20 0 34 12 34 29 0 16-14 29-34 29H46v30H32z" fill="#22d3ee"/>
|
|
582
475
|
<circle cx="88" cy="93" r="11" fill="#a5f3fc"/>
|
|
583
476
|
</svg>
|
|
584
477
|
`);
|
|
585
|
-
|
|
478
|
+
await ensureFile(path.join(root, "public", "images", "logo.svg"), `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 160" role="img" aria-label="Resux">
|
|
586
479
|
<rect width="640" height="160" rx="24" fill="#020617"/>
|
|
587
480
|
<text x="56" y="104" font-size="72" font-family="Segoe UI, sans-serif" fill="#22d3ee">Resux</text>
|
|
588
481
|
</svg>
|
|
589
482
|
`);
|
|
590
|
-
|
|
591
|
-
|
|
483
|
+
if (shouldIncludeServerApi) {
|
|
484
|
+
await ensureFile(path.join(root, "server", "api", "hello.get.ts"), `import { defineEventHandler } from "h3";
|
|
592
485
|
export default defineEventHandler(() => {
|
|
593
486
|
return { message: "hello resux" };
|
|
594
487
|
});
|
|
595
488
|
`);
|
|
596
|
-
|
|
489
|
+
await ensureFile(path.join(root, "server", "routes", "health.get.ts"), `import { defineEventHandler } from "h3";
|
|
597
490
|
|
|
598
491
|
export default defineEventHandler(() => ({ ok: true }));
|
|
599
492
|
`);
|
|
600
|
-
|
|
493
|
+
await ensureFile(path.join(root, "server", "plugins", "example.ts"), `import { defineNitroPlugin } from "nitropack/runtime/plugin";
|
|
601
494
|
|
|
602
495
|
export default defineNitroPlugin(() => {
|
|
603
496
|
console.debug("[resux] nitro plugin booted");
|
|
604
497
|
});
|
|
605
498
|
`);
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
await ensureFile(path.join(root, "tests", "basic.test.ts"), `import { describe, expect, it } from "vitest";
|
|
499
|
+
}
|
|
500
|
+
if (shouldIncludeTests) await ensureFile(path.join(root, "tests", "basic.test.ts"), `import { describe, expect, it } from "vitest";
|
|
609
501
|
|
|
610
502
|
describe("starter", () => {
|
|
611
503
|
it("runs", () => {
|
|
@@ -613,9 +505,8 @@ describe("starter", () => {
|
|
|
613
505
|
});
|
|
614
506
|
});
|
|
615
507
|
`);
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
await ensureFile(path.join(root, "tailwind.config.ts"), `import type { Config } from "tailwindcss";
|
|
508
|
+
if (selected.has("tailwind")) {
|
|
509
|
+
await ensureFile(path.join(root, "tailwind.config.ts"), `import type { Config } from "tailwindcss";
|
|
619
510
|
|
|
620
511
|
export default {
|
|
621
512
|
content: [
|
|
@@ -631,26 +522,24 @@ export default {
|
|
|
631
522
|
plugins: [],
|
|
632
523
|
} satisfies Config;
|
|
633
524
|
`);
|
|
634
|
-
|
|
525
|
+
await ensureFile(path.join(root, "postcss.config.cjs"), `module.exports = {
|
|
635
526
|
plugins: {
|
|
636
527
|
tailwindcss: {},
|
|
637
528
|
autoprefixer: {},
|
|
638
529
|
},
|
|
639
530
|
};
|
|
640
531
|
`);
|
|
641
|
-
|
|
532
|
+
await ensureFile(path.join(root, "assets", "css", "tailwind.css"), `@tailwind base;
|
|
642
533
|
@tailwind components;
|
|
643
534
|
@tailwind utilities;
|
|
644
535
|
`);
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
await ensurePackageCompatibilityPages(root);
|
|
648
|
-
}
|
|
536
|
+
}
|
|
537
|
+
if (shouldIncludePackageExamples) await ensurePackageCompatibilityPages(root);
|
|
649
538
|
}
|
|
650
539
|
async function ensurePackageCompatibilityPages(root) {
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
540
|
+
const pagesRoot = path.join(root, "pages", "package-tests");
|
|
541
|
+
await mkdir(pagesRoot, { recursive: true });
|
|
542
|
+
await ensureFile(path.join(root, "plugins", "package-enhancements.client.ts"), `type PackageStatus = "idle" | "loading" | "ready" | "error" | "disposed";
|
|
654
543
|
type SwiperLike = new (
|
|
655
544
|
element: HTMLElement,
|
|
656
545
|
options: Record<string, unknown>,
|
|
@@ -753,12 +642,12 @@ defineClientEnhancement("missing-package-demo", async (target) => {
|
|
|
753
642
|
}
|
|
754
643
|
});
|
|
755
644
|
`);
|
|
756
|
-
|
|
645
|
+
await ensureFile(path.join(pagesRoot, "index.vue"), `<script setup lang="ts">
|
|
757
646
|
useSeoMeta({
|
|
758
647
|
title: "Resux Package Compatibility Demos",
|
|
759
648
|
description: "SSR-first npm package demos with client enhancements and resumability-safe patterns.",
|
|
760
649
|
})
|
|
761
|
-
|
|
650
|
+
<\/script>
|
|
762
651
|
|
|
763
652
|
<template>
|
|
764
653
|
<main class="page">
|
|
@@ -777,24 +666,53 @@ useSeoMeta({
|
|
|
777
666
|
</main>
|
|
778
667
|
</template>
|
|
779
668
|
`);
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
669
|
+
for (const example of [
|
|
670
|
+
{
|
|
671
|
+
file: "swiper.vue",
|
|
672
|
+
title: "Swiper",
|
|
673
|
+
enhancement: "swiper-carousel"
|
|
674
|
+
},
|
|
675
|
+
{
|
|
676
|
+
file: "chart.vue",
|
|
677
|
+
title: "Chart",
|
|
678
|
+
enhancement: "chart-demo"
|
|
679
|
+
},
|
|
680
|
+
{
|
|
681
|
+
file: "animation.vue",
|
|
682
|
+
title: "Animation",
|
|
683
|
+
enhancement: "animation-demo"
|
|
684
|
+
},
|
|
685
|
+
{
|
|
686
|
+
file: "video-player.vue",
|
|
687
|
+
title: "Video player",
|
|
688
|
+
enhancement: "video-player-demo"
|
|
689
|
+
},
|
|
690
|
+
{
|
|
691
|
+
file: "markdown.vue",
|
|
692
|
+
title: "Markdown",
|
|
693
|
+
enhancement: "markdown-demo"
|
|
694
|
+
},
|
|
695
|
+
{
|
|
696
|
+
file: "utility.vue",
|
|
697
|
+
title: "Utility"
|
|
698
|
+
},
|
|
699
|
+
{
|
|
700
|
+
file: "css-package.vue",
|
|
701
|
+
title: "CSS package",
|
|
702
|
+
enhancement: "css-package-demo"
|
|
703
|
+
},
|
|
704
|
+
{
|
|
705
|
+
file: "missing-package.vue",
|
|
706
|
+
title: "Missing package",
|
|
707
|
+
enhancement: "missing-package-demo"
|
|
708
|
+
}
|
|
709
|
+
]) await ensureFile(path.join(pagesRoot, example.file), `<script setup lang="ts">
|
|
792
710
|
useSeoMeta({
|
|
793
711
|
title: "Resux ${example.title} Package Demo",
|
|
794
712
|
description: "SSR-first ${example.title.toLowerCase()} compatibility demo with progressive enhancement.",
|
|
795
713
|
ogTitle: "Resux ${example.title} Demo",
|
|
796
714
|
})
|
|
797
|
-
|
|
715
|
+
<\/script>
|
|
798
716
|
|
|
799
717
|
<template>
|
|
800
718
|
<main class="page">
|
|
@@ -816,49 +734,42 @@ useSeoMeta({
|
|
|
816
734
|
<article class="swiper-slide"><h2>Item 4</h2><p>SSR card content.</p><a href="/package-tests">Read more</a></article>
|
|
817
735
|
</div>
|
|
818
736
|
</div>
|
|
819
|
-
${example.enhancement === "swiper-carousel" ?
|
|
737
|
+
${example.enhancement === "swiper-carousel" ? "<div data-rx-prev aria-label=\"Previous slide\"></div><div data-rx-next aria-label=\"Next slide\"></div><div data-rx-pagination></div>" : ""}
|
|
820
738
|
</section>
|
|
821
739
|
</main>
|
|
822
740
|
</template>
|
|
823
741
|
`);
|
|
824
|
-
}
|
|
825
742
|
}
|
|
826
743
|
async function ensureFile(filePath, contents) {
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
await mkdir(path.dirname(filePath), { recursive: true });
|
|
831
|
-
await writeFile(filePath, contents, "utf8");
|
|
744
|
+
if (await pathExists(filePath)) return;
|
|
745
|
+
await mkdir(path.dirname(filePath), { recursive: true });
|
|
746
|
+
await writeFile(filePath, contents, "utf8");
|
|
832
747
|
}
|
|
833
748
|
async function pathExists(filePath) {
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
}
|
|
749
|
+
try {
|
|
750
|
+
await readFile(filePath, "utf8");
|
|
751
|
+
return true;
|
|
752
|
+
} catch {
|
|
753
|
+
return false;
|
|
754
|
+
}
|
|
841
755
|
}
|
|
842
756
|
function createStarterResuxConfig(title, features, options) {
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
? `,
|
|
757
|
+
const modules = [
|
|
758
|
+
`"resux:security"`,
|
|
759
|
+
`"resux:performance"`,
|
|
760
|
+
...features.has("i18n") ? [`"resuxjs/i18n"`] : []
|
|
761
|
+
];
|
|
762
|
+
const headLinks = [
|
|
763
|
+
...features.has("tailwind") ? [`{ rel: "stylesheet", href: "/tailwind.css" }`] : [],
|
|
764
|
+
`{ rel: "stylesheet", href: "/styles.css" }`,
|
|
765
|
+
...features.has("pwa") ? [`{ rel: "manifest", href: "/manifest.webmanifest" }`] : []
|
|
766
|
+
];
|
|
767
|
+
const headMeta = features.has("pwa") ? `,
|
|
855
768
|
meta: [
|
|
856
769
|
{ name: "theme-color", content: "#0f172a" },
|
|
857
770
|
{ name: "application-name", content: ${JSON.stringify(title)} }
|
|
858
|
-
]`
|
|
859
|
-
|
|
860
|
-
const i18nBlock = features.has("i18n")
|
|
861
|
-
? `,
|
|
771
|
+
]` : "";
|
|
772
|
+
const i18nBlock = features.has("i18n") ? `,
|
|
862
773
|
i18n: {
|
|
863
774
|
defaultLocale: "en",
|
|
864
775
|
fallbackLocale: "en",
|
|
@@ -874,10 +785,8 @@ function createStarterResuxConfig(title, features, options) {
|
|
|
874
785
|
seo: {
|
|
875
786
|
hreflang: ${options.hreflang ? "true" : "false"}
|
|
876
787
|
}
|
|
877
|
-
}`
|
|
878
|
-
|
|
879
|
-
const packageBlock = features.has("package-compatibility")
|
|
880
|
-
? `,
|
|
788
|
+
}` : "";
|
|
789
|
+
const packageBlock = features.has("package-compatibility") ? `,
|
|
881
790
|
packages: {
|
|
882
791
|
mode: {
|
|
883
792
|
"swiper": "progressive",
|
|
@@ -888,9 +797,8 @@ function createStarterResuxConfig(title, features, options) {
|
|
|
888
797
|
"date-fns": "ssr",
|
|
889
798
|
"highlight.js": "progressive"
|
|
890
799
|
}
|
|
891
|
-
}`
|
|
892
|
-
|
|
893
|
-
return `export default defineResuxConfig({
|
|
800
|
+
}` : "";
|
|
801
|
+
return `export default defineResuxConfig({
|
|
894
802
|
deploy: {
|
|
895
803
|
target: "auto"
|
|
896
804
|
},
|
|
@@ -913,34 +821,29 @@ function createStarterResuxConfig(title, features, options) {
|
|
|
913
821
|
`;
|
|
914
822
|
}
|
|
915
823
|
async function removeSeoFromPage(filePath) {
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
await writeFile(filePath, withoutSeo, "utf8");
|
|
824
|
+
const withoutSeo = (await readFile(filePath, "utf8")).replace(/\nuseSeoMeta\(\{[\s\S]*?\}\)\n/g, "\n");
|
|
825
|
+
await writeFile(filePath, withoutSeo, "utf8");
|
|
919
826
|
}
|
|
920
827
|
async function scaffoldI18nFiles(root) {
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
welcome: "مرحبًا {name}!"
|
|
941
|
-
}
|
|
942
|
-
}, null, 2)}\n`, "utf8");
|
|
943
|
-
await writeFile(path.join(root, "pages", "i18n.vue"), `<script setup lang="ts">
|
|
828
|
+
const localesDir = path.join(root, "locales");
|
|
829
|
+
await mkdir(localesDir, { recursive: true });
|
|
830
|
+
await writeFile(path.join(localesDir, "en.json"), `${JSON.stringify({ demo: {
|
|
831
|
+
badge: "I18n demo",
|
|
832
|
+
title: "Localized starter",
|
|
833
|
+
subtitle: "Switch locale prefixes and translate strings without hydration.",
|
|
834
|
+
currentLocale: "Current locale: {locale}",
|
|
835
|
+
currentDir: "Direction: {dir}",
|
|
836
|
+
welcome: "Welcome, {name}!"
|
|
837
|
+
} }, null, 2)}\n`, "utf8");
|
|
838
|
+
await writeFile(path.join(localesDir, "ar.json"), `${JSON.stringify({ demo: {
|
|
839
|
+
badge: "عرض الترجمة",
|
|
840
|
+
title: "مشروع مترجم",
|
|
841
|
+
subtitle: "بدل اللغات والمسارات بدون ترطيب.",
|
|
842
|
+
currentLocale: "اللغة الحالية: {locale}",
|
|
843
|
+
currentDir: "الاتجاه: {dir}",
|
|
844
|
+
welcome: "مرحبًا {name}!"
|
|
845
|
+
} }, null, 2)}\n`, "utf8");
|
|
846
|
+
await writeFile(path.join(root, "pages", "i18n.vue"), `<script setup lang="ts">
|
|
944
847
|
import { useI18n } from "resuxjs/i18n"
|
|
945
848
|
|
|
946
849
|
definePageMeta({
|
|
@@ -951,7 +854,7 @@ definePageMeta({
|
|
|
951
854
|
})
|
|
952
855
|
|
|
953
856
|
const i18n = useI18n()
|
|
954
|
-
|
|
857
|
+
<\/script>
|
|
955
858
|
|
|
956
859
|
<template>
|
|
957
860
|
<main class="page narrow">
|
|
@@ -970,11 +873,11 @@ const i18n = useI18n()
|
|
|
970
873
|
`, "utf8");
|
|
971
874
|
}
|
|
972
875
|
async function scaffoldMediaPage(root) {
|
|
973
|
-
|
|
876
|
+
await writeFile(path.join(root, "pages", "media.vue"), `<script setup lang="ts">
|
|
974
877
|
definePageMeta({
|
|
975
878
|
title: "Media"
|
|
976
879
|
})
|
|
977
|
-
|
|
880
|
+
<\/script>
|
|
978
881
|
|
|
979
882
|
<template>
|
|
980
883
|
<main class="page">
|
|
@@ -1013,141 +916,96 @@ definePageMeta({
|
|
|
1013
916
|
`, "utf8");
|
|
1014
917
|
}
|
|
1015
918
|
async function scaffoldPwaFiles(root, title) {
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
}, null, 2)}\n`, "utf8");
|
|
1032
|
-
await writeFile(path.join(root, "public", "sw.js"), `self.addEventListener("install", () => self.skipWaiting())
|
|
919
|
+
await writeFile(path.join(root, "public", "manifest.webmanifest"), `${JSON.stringify({
|
|
920
|
+
name: title,
|
|
921
|
+
short_name: title.replace(/\s+/g, " ").slice(0, 12),
|
|
922
|
+
start_url: "/",
|
|
923
|
+
display: "standalone",
|
|
924
|
+
background_color: "#020617",
|
|
925
|
+
theme_color: "#0f172a",
|
|
926
|
+
icons: [{
|
|
927
|
+
src: "/resux-placeholder.svg",
|
|
928
|
+
sizes: "96x96",
|
|
929
|
+
type: "image/svg+xml",
|
|
930
|
+
purpose: "any"
|
|
931
|
+
}]
|
|
932
|
+
}, null, 2)}\n`, "utf8");
|
|
933
|
+
await writeFile(path.join(root, "public", "sw.js"), `self.addEventListener("install", () => self.skipWaiting())
|
|
1033
934
|
self.addEventListener("activate", (event) => {
|
|
1034
935
|
event.waitUntil(self.clients.claim())
|
|
1035
936
|
})
|
|
1036
937
|
`, "utf8");
|
|
1037
938
|
}
|
|
1038
939
|
async function extendDefaultLayoutNavigation(root, features) {
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
return;
|
|
1047
|
-
}
|
|
1048
|
-
const marker = " </nav>";
|
|
1049
|
-
const next = source.includes(marker)
|
|
1050
|
-
? source.replace(marker, `${additions.join("\n")}\n${marker}`)
|
|
1051
|
-
: source;
|
|
1052
|
-
await writeFile(layoutPath, next, "utf8");
|
|
940
|
+
const layoutPath = path.join(root, "layouts", "default.vue");
|
|
941
|
+
const source = await readFile(layoutPath, "utf8");
|
|
942
|
+
const additions = [...features.has("i18n") ? [" <ResuxLink to=\"/i18n\">I18n</ResuxLink>"] : [], ...features.has("media") ? [" <ResuxLink to=\"/media\">Media</ResuxLink>"] : []];
|
|
943
|
+
if (!additions.length) return;
|
|
944
|
+
const marker = " </nav>";
|
|
945
|
+
const next = source.includes(marker) ? source.replace(marker, `${additions.join("\n")}\n${marker}`) : source;
|
|
946
|
+
await writeFile(layoutPath, next, "utf8");
|
|
1053
947
|
}
|
|
1054
948
|
async function annotateStarterReadme(root, features) {
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
const next = `${source.trimEnd()}\n\n## Optional Features\n\n${featureList}\n`;
|
|
1062
|
-
await writeFile(readmePath, next, "utf8");
|
|
949
|
+
if (!features.size) return;
|
|
950
|
+
const readmePath = path.join(root, "README.md");
|
|
951
|
+
const source = await readFile(readmePath, "utf8");
|
|
952
|
+
const featureList = [...features].map((feature) => `- ${feature}`).join("\n");
|
|
953
|
+
const next = `${source.trimEnd()}\n\n## Optional Features\n\n${featureList}\n`;
|
|
954
|
+
await writeFile(readmePath, next, "utf8");
|
|
1063
955
|
}
|
|
1064
956
|
async function installDependencies(root, packageManager) {
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
reject(new Error(`${packageManager} install exited with code ${code ?? "unknown"}.`));
|
|
1078
|
-
}
|
|
1079
|
-
});
|
|
1080
|
-
});
|
|
957
|
+
await new Promise((resolve, reject) => {
|
|
958
|
+
const child = spawn(packageManager, ["install"], {
|
|
959
|
+
cwd: root,
|
|
960
|
+
stdio: "inherit",
|
|
961
|
+
shell: process.platform === "win32"
|
|
962
|
+
});
|
|
963
|
+
child.on("error", reject);
|
|
964
|
+
child.on("exit", (code) => {
|
|
965
|
+
if (code === 0) resolve();
|
|
966
|
+
else reject(/* @__PURE__ */ new Error(`${packageManager} install exited with code ${code ?? "unknown"}.`));
|
|
967
|
+
});
|
|
968
|
+
});
|
|
1081
969
|
}
|
|
1082
970
|
function printNextSteps(options) {
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
if (!options.installed) {
|
|
1092
|
-
console.log(` ${options.packageManager} install`);
|
|
1093
|
-
}
|
|
1094
|
-
console.log(` ${runCommand(options.packageManager, "dev")}`);
|
|
1095
|
-
if (options.features.length > 0) {
|
|
1096
|
-
console.log(`\nSelected optional features: ${options.features.join(", ")}`);
|
|
1097
|
-
}
|
|
971
|
+
const cdTarget = formatShellPath(path.relative(process.cwd(), options.root) || ".");
|
|
972
|
+
console.log(`\nCreated Resux app in ${options.root}`);
|
|
973
|
+
console.log(`Template: ${options.template}`);
|
|
974
|
+
console.log("\nNext steps:");
|
|
975
|
+
if (cdTarget !== ".") console.log(` cd ${cdTarget}`);
|
|
976
|
+
if (!options.installed) console.log(` ${options.packageManager} install`);
|
|
977
|
+
console.log(` ${runCommand(options.packageManager, "dev")}`);
|
|
978
|
+
if (options.features.length > 0) console.log(`\nSelected optional features: ${options.features.join(", ")}`);
|
|
1098
979
|
}
|
|
1099
980
|
function runCommand(packageManager, script) {
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
if (packageManager === "bun") {
|
|
1104
|
-
return `bun run ${script}`;
|
|
1105
|
-
}
|
|
1106
|
-
return `${packageManager} ${script}`;
|
|
981
|
+
if (packageManager === "npm") return `npm run ${script}`;
|
|
982
|
+
if (packageManager === "bun") return `bun run ${script}`;
|
|
983
|
+
return `${packageManager} ${script}`;
|
|
1107
984
|
}
|
|
1108
985
|
function detectPackageManager() {
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
return "yarn";
|
|
1115
|
-
}
|
|
1116
|
-
if (agent.startsWith("bun")) {
|
|
1117
|
-
return "bun";
|
|
1118
|
-
}
|
|
1119
|
-
return "npm";
|
|
986
|
+
const agent = process.env.npm_config_user_agent ?? "";
|
|
987
|
+
if (agent.startsWith("pnpm")) return "pnpm";
|
|
988
|
+
if (agent.startsWith("yarn")) return "yarn";
|
|
989
|
+
if (agent.startsWith("bun")) return "bun";
|
|
990
|
+
return "npm";
|
|
1120
991
|
}
|
|
1121
992
|
function toPackageName(value) {
|
|
1122
|
-
|
|
1123
|
-
.trim()
|
|
1124
|
-
.toLowerCase()
|
|
1125
|
-
.replace(/\\/g, "/")
|
|
1126
|
-
.split("/")
|
|
1127
|
-
.filter(Boolean)
|
|
1128
|
-
.pop()
|
|
1129
|
-
?.replace(/[^a-z0-9._-]+/g, "-")
|
|
1130
|
-
.replace(/^[._-]+|[._-]+$/g, "");
|
|
1131
|
-
return normalized || defaultProjectName;
|
|
993
|
+
return value.trim().toLowerCase().replace(/\\/g, "/").split("/").filter(Boolean).pop()?.replace(/[^a-z0-9._-]+/g, "-").replace(/^[._-]+|[._-]+$/g, "") || defaultProjectName;
|
|
1132
994
|
}
|
|
1133
995
|
function toTitle(value) {
|
|
1134
|
-
|
|
1135
|
-
.split(/[-_]/g)
|
|
1136
|
-
.filter(Boolean)
|
|
1137
|
-
.map((part) => part.charAt(0).toUpperCase() + part.slice(1))
|
|
1138
|
-
.join(" ") || "Resux App";
|
|
996
|
+
return value.split(/[-_]/g).filter(Boolean).map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join(" ") || "Resux App";
|
|
1139
997
|
}
|
|
1140
998
|
function formatShellPath(value) {
|
|
1141
|
-
|
|
999
|
+
return /\s/.test(value) ? JSON.stringify(value) : value;
|
|
1142
1000
|
}
|
|
1143
1001
|
function canPrompt() {
|
|
1144
|
-
|
|
1002
|
+
return Boolean(stdin.isTTY && stdout.isTTY);
|
|
1145
1003
|
}
|
|
1146
1004
|
function isMainModule() {
|
|
1147
|
-
|
|
1005
|
+
return process.argv[1] ? path.resolve(process.argv[1]) === fileURLToPath(import.meta.url) : false;
|
|
1148
1006
|
}
|
|
1149
1007
|
function printHelp() {
|
|
1150
|
-
|
|
1008
|
+
console.log(`resux init
|
|
1151
1009
|
|
|
1152
1010
|
Usage:
|
|
1153
1011
|
npx resuxjs@latest init [project-dir] [options]
|
|
@@ -1166,4 +1024,7 @@ Options:
|
|
|
1166
1024
|
-h, --help Show this help message
|
|
1167
1025
|
`);
|
|
1168
1026
|
}
|
|
1027
|
+
//#endregion
|
|
1028
|
+
export { assertSafeCreateTarget, runCreateResux };
|
|
1029
|
+
|
|
1169
1030
|
//# sourceMappingURL=create.js.map
|