resuxjs 0.3.11 → 0.4.0-beta.3
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 +5 -0
- package/dist/bin.js.map +1 -1
- package/dist/build/index.d.ts +29 -0
- package/dist/build/index.js +51 -0
- package/dist/build/index.js.map +1 -0
- package/dist/cli.d.ts +19 -8
- package/dist/cli.js +2653 -3688
- package/dist/cli.js.map +1 -1
- package/dist/compiler/adapter.d.ts +19 -15
- package/dist/compiler/adapter.js +69 -93
- package/dist/compiler/adapter.js.map +1 -1
- package/dist/compiler/dev-warnings.d.ts +14 -10
- package/dist/compiler/dev-warnings.js +247 -319
- package/dist/compiler/dev-warnings.js.map +1 -1
- package/dist/compiler/directives.d.ts +7 -3
- package/dist/compiler/directives.js +125 -150
- package/dist/compiler/directives.js.map +1 -1
- package/dist/compiler/implementation.d.ts +117 -112
- package/dist/compiler/implementation.js +2954 -3426
- package/dist/compiler/index.d.ts +19 -15
- package/dist/compiler/index.js +69 -93
- package/dist/compiler/index.js.map +1 -1
- package/dist/core/config.d.ts +19 -10
- package/dist/core/config.js +42 -25
- package/dist/core/config.js.map +1 -1
- package/dist/core/hooks.d.ts +133 -131
- 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 +6 -5
- package/dist/core/module-container.d.ts +97 -93
- package/dist/core/module-container.js +180 -185
- package/dist/core/module-container.js.map +1 -1
- package/dist/core/resux.d.ts +20 -15
- package/dist/core/resux.js +18 -13
- package/dist/core/resux.js.map +1 -1
- package/dist/create-bin.d.ts +1 -2
- package/dist/create-bin.js +5 -0
- package/dist/create-bin.js.map +1 -1
- package/dist/create.d.ts +6 -2
- package/dist/create.js +496 -638
- package/dist/create.js.map +1 -1
- package/dist/deploy/cloudflare.d.ts +7 -2
- package/dist/deploy/cloudflare.js +31 -34
- package/dist/deploy/cloudflare.js.map +1 -1
- package/dist/deploy/common.d.ts +19 -15
- package/dist/deploy/common.js +119 -188
- package/dist/deploy/common.js.map +1 -1
- package/dist/deploy/framework-runtime.d.ts +5 -1
- package/dist/deploy/framework-runtime.js +44 -48
- package/dist/deploy/framework-runtime.js.map +1 -1
- package/dist/deploy/index.d.ts +8 -3
- package/dist/deploy/index.js +56 -80
- package/dist/deploy/index.js.map +1 -1
- package/dist/deploy/netlify.d.ts +7 -2
- package/dist/deploy/netlify.js +41 -41
- package/dist/deploy/netlify.js.map +1 -1
- package/dist/deploy/node.d.ts +7 -2
- package/dist/deploy/node.js +24 -19
- package/dist/deploy/node.js.map +1 -1
- package/dist/deploy/production-report.d.ts +5 -1
- package/dist/deploy/production-report.js +15 -14
- package/dist/deploy/production-report.js.map +1 -1
- package/dist/deploy/runtime-dependencies.d.ts +8 -4
- package/dist/deploy/runtime-dependencies.js +158 -220
- package/dist/deploy/runtime-dependencies.js.map +1 -1
- package/dist/deploy/static.d.ts +7 -2
- package/dist/deploy/static.js +17 -14
- package/dist/deploy/static.js.map +1 -1
- package/dist/deploy/types.d.ts +33 -29
- package/dist/deploy/types.js +1 -2
- package/dist/deploy/vercel.d.ts +8 -3
- package/dist/deploy/vercel.js +138 -188
- package/dist/deploy/vercel.js.map +1 -1
- package/dist/fonts/index.d.ts +19 -14
- package/dist/fonts/index.js +115 -134
- package/dist/fonts/index.js.map +1 -1
- package/dist/globals.d.ts +79 -78
- package/dist/globals.js +1 -2
- package/dist/halal-core/ai/classifyProject.d.ts +9 -4
- package/dist/halal-core/ai/classifyProject.js +82 -95
- package/dist/halal-core/ai/classifyProject.js.map +1 -1
- package/dist/halal-core/ai/classifyRuntimeContent.d.ts +8 -3
- package/dist/halal-core/ai/classifyRuntimeContent.js +78 -95
- package/dist/halal-core/ai/classifyRuntimeContent.js.map +1 -1
- package/dist/halal-core/ai/createProjectSummary.d.ts +40 -36
- package/dist/halal-core/ai/createProjectSummary.js +39 -39
- package/dist/halal-core/ai/createProjectSummary.js.map +1 -1
- package/dist/halal-core/ai/halalClassifierPrompt.d.ts +5 -1
- 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 +5 -1
- 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 +7 -2
- package/dist/halal-core/ai/validateAiResponse.js +56 -83
- package/dist/halal-core/ai/validateAiResponse.js.map +1 -1
- package/dist/halal-core/cli/check.d.ts +5 -1
- 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 +5 -1
- 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 +5 -1
- 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 +5 -1
- 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 +5 -1
- package/dist/halal-core/cli/verifyReview.js +17 -15
- package/dist/halal-core/cli/verifyReview.js.map +1 -1
- package/dist/halal-core/config.d.ts +39 -35
- package/dist/halal-core/config.js +77 -118
- package/dist/halal-core/config.js.map +1 -1
- package/dist/halal-core/crypto/integrity.d.ts +12 -8
- package/dist/halal-core/crypto/integrity.js +65 -87
- package/dist/halal-core/crypto/integrity.js.map +1 -1
- package/dist/halal-core/enforce.d.ts +9 -5
- package/dist/halal-core/enforce.js +90 -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 +19 -19
- package/dist/halal-core/lifecycle.d.ts +5 -1
- package/dist/halal-core/lifecycle.js +16 -13
- package/dist/halal-core/lifecycle.js.map +1 -1
- package/dist/halal-core/policy.d.ts +7 -2
- package/dist/halal-core/policy.js +7 -2
- package/dist/halal-core/policy.js.map +1 -1
- package/dist/halal-core/report/formatBrowserOverlay.d.ts +7 -2
- 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 +7 -2
- 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 +11 -6
- package/dist/halal-core/report/generateHalalReport.js +25 -27
- package/dist/halal-core/report/generateHalalReport.js.map +1 -1
- package/dist/halal-core/report/signReport.d.ts +8 -3
- package/dist/halal-core/report/signReport.js +17 -12
- package/dist/halal-core/report/signReport.js.map +1 -1
- package/dist/halal-core/report/verifyReport.d.ts +14 -9
- package/dist/halal-core/report/verifyReport.js +52 -41
- package/dist/halal-core/report/verifyReport.js.map +1 -1
- package/dist/halal-core/review/createReviewRequest.d.ts +7 -2
- 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 +7 -3
- 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 +17 -12
- package/dist/halal-core/review/signedReviewFile.js +25 -22
- package/dist/halal-core/review/signedReviewFile.js.map +1 -1
- package/dist/halal-core/review/verifyReviewApproval.d.ts +12 -8
- package/dist/halal-core/review/verifyReviewApproval.js +69 -62
- package/dist/halal-core/review/verifyReviewApproval.js.map +1 -1
- package/dist/halal-core/rules/adultContentRules.d.ts +6 -2
- 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 +6 -2
- 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 +6 -2
- 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 +10 -6
- 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 +6 -2
- 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 +24 -19
- package/dist/halal-core/rules/defaultBlockedRules.js +156 -199
- package/dist/halal-core/rules/defaultBlockedRules.js.map +1 -1
- package/dist/halal-core/rules/dependencyRules.d.ts +11 -7
- 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 +9 -5
- 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 +6 -2
- 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 +6 -2
- 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 +6 -2
- 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 +6 -2
- 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 +6 -2
- 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 +13 -9
- 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 +6 -2
- 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 +6 -2
- 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 +6 -2
- 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 +6 -2
- 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 +22 -17
- package/dist/halal-core/runtime/guard.js +163 -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 +5 -5
- package/dist/halal-core/runtime/reviewedMemory.d.ts +10 -5
- package/dist/halal-core/runtime/reviewedMemory.js +75 -110
- package/dist/halal-core/runtime/reviewedMemory.js.map +1 -1
- package/dist/halal-core/runtime/serializeRuntimeContent.d.ts +17 -12
- package/dist/halal-core/runtime/serializeRuntimeContent.js +133 -156
- package/dist/halal-core/runtime/serializeRuntimeContent.js.map +1 -1
- package/dist/halal-core/runtime/types.d.ts +55 -50
- package/dist/halal-core/runtime/types.js +1 -2
- package/dist/halal-core/scanner/scanApiRoutes.d.ts +5 -1
- package/dist/halal-core/scanner/scanApiRoutes.js +33 -36
- package/dist/halal-core/scanner/scanApiRoutes.js.map +1 -1
- package/dist/halal-core/scanner/scanComponents.d.ts +5 -1
- package/dist/halal-core/scanner/scanComponents.js +13 -13
- package/dist/halal-core/scanner/scanComponents.js.map +1 -1
- package/dist/halal-core/scanner/scanContent.d.ts +8 -4
- package/dist/halal-core/scanner/scanContent.js +192 -261
- package/dist/halal-core/scanner/scanContent.js.map +1 -1
- package/dist/halal-core/scanner/scanDependencies.d.ts +5 -1
- package/dist/halal-core/scanner/scanDependencies.js +17 -15
- package/dist/halal-core/scanner/scanDependencies.js.map +1 -1
- package/dist/halal-core/scanner/scanDomains.d.ts +7 -3
- 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 +5 -1
- package/dist/halal-core/scanner/scanEnvNames.js +24 -26
- package/dist/halal-core/scanner/scanEnvNames.js.map +1 -1
- package/dist/halal-core/scanner/scanMetadata.d.ts +9 -5
- package/dist/halal-core/scanner/scanMetadata.js +21 -29
- package/dist/halal-core/scanner/scanMetadata.js.map +1 -1
- package/dist/halal-core/scanner/scanPages.d.ts +5 -1
- package/dist/halal-core/scanner/scanPages.js +13 -15
- package/dist/halal-core/scanner/scanPages.js.map +1 -1
- package/dist/halal-core/scanner/scanProject.d.ts +19 -12
- package/dist/halal-core/scanner/scanProject.js +44 -49
- package/dist/halal-core/scanner/scanProject.js.map +1 -1
- package/dist/halal-core/scanner/scanRoutes.d.ts +5 -1
- package/dist/halal-core/scanner/scanRoutes.js +33 -39
- package/dist/halal-core/scanner/scanRoutes.js.map +1 -1
- package/dist/halal-core/scanner/scanTranslations.d.ts +5 -1
- package/dist/halal-core/scanner/scanTranslations.js +22 -29
- package/dist/halal-core/scanner/scanTranslations.js.map +1 -1
- package/dist/halal-core/status.d.ts +17 -13
- package/dist/halal-core/status.js +1 -2
- package/dist/halal-core/tamper/verifyCoreIntegrity.d.ts +5 -1
- package/dist/halal-core/tamper/verifyCoreIntegrity.js +27 -24
- package/dist/halal-core/tamper/verifyCoreIntegrity.js.map +1 -1
- package/dist/halal-core/tamper/verifyLifecycleHooks.d.ts +5 -1
- 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 +9 -4
- 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 +19 -2
- package/dist/i18n/index.d.ts +44 -40
- package/dist/i18n/index.js +218 -288
- package/dist/i18n/index.js.map +1 -1
- package/dist/i18n/shared.d.ts +33 -29
- package/dist/i18n/shared.js +204 -266
- package/dist/i18n/shared.js.map +1 -1
- package/dist/icons/index.d.ts +160 -154
- package/dist/icons/index.js +323 -273
- package/dist/icons/index.js.map +1 -1
- package/dist/index.d.ts +8 -1
- package/dist/index.js +8 -2
- package/dist/kit/index.d.ts +32 -27
- package/dist/kit/index.js +46 -43
- package/dist/kit/index.js.map +1 -1
- package/dist/nitro-server/index.d.ts +10 -6
- package/dist/nitro-server/index.js +6 -2
- package/dist/nitro-server/index.js.map +1 -1
- package/dist/node.d.ts +9 -4
- package/dist/node.js +89 -116
- package/dist/node.js.map +1 -1
- package/dist/reactivity/computed.d.ts +11 -6
- package/dist/reactivity/computed.js +46 -53
- package/dist/reactivity/computed.js.map +1 -1
- package/dist/reactivity/effect.d.ts +23 -18
- package/dist/reactivity/effect.js +105 -147
- package/dist/reactivity/effect.js.map +1 -1
- package/dist/reactivity/index.d.ts +8 -8
- package/dist/reactivity/index.js +8 -8
- package/dist/reactivity/reactive.d.ts +9 -5
- package/dist/reactivity/reactive.js +95 -134
- package/dist/reactivity/reactive.js.map +1 -1
- package/dist/reactivity/readonly.d.ts +2 -1
- package/dist/reactivity/readonly.js +3 -2
- package/dist/reactivity/ref.d.ts +23 -21
- package/dist/reactivity/ref.js +71 -81
- package/dist/reactivity/ref.js.map +1 -1
- package/dist/reactivity/scheduler.d.ts +8 -5
- package/dist/reactivity/scheduler.js +67 -69
- package/dist/reactivity/scheduler.js.map +1 -1
- package/dist/reactivity/types.d.ts +29 -25
- package/dist/reactivity/types.js +1 -2
- package/dist/reactivity/utils.d.ts +17 -13
- package/dist/reactivity/utils.js +25 -24
- package/dist/reactivity/utils.js.map +1 -1
- package/dist/reactivity/watch.d.ts +8 -4
- package/dist/reactivity/watch.js +74 -103
- package/dist/reactivity/watch.js.map +1 -1
- package/dist/runtime/core.d.ts +32 -0
- package/dist/runtime/core.js +155 -0
- package/dist/runtime/core.js.map +1 -0
- package/dist/runtime/index.d.ts +649 -622
- package/dist/runtime/index.js +4105 -5243
- package/dist/runtime/index.js.map +1 -1
- package/dist/runtime/reactivity.d.ts +7 -0
- package/dist/runtime/reactivity.js +7 -0
- package/dist/runtime/resume.d.ts +80 -0
- package/dist/runtime/resume.js +482 -0
- package/dist/runtime/resume.js.map +1 -0
- package/dist/runtime/router.d.ts +21 -0
- package/dist/runtime/router.js +60 -0
- package/dist/runtime/router.js.map +1 -0
- package/dist/runtime/streaming.d.ts +25 -0
- package/dist/runtime/streaming.js +200 -0
- package/dist/runtime/streaming.js.map +1 -0
- package/dist/security/media-fetch.d.ts +33 -0
- package/dist/security/media-fetch.js +302 -0
- package/dist/security/media-fetch.js.map +1 -0
- package/dist/security/path-boundary.d.ts +8 -0
- package/dist/security/path-boundary.js +71 -0
- package/dist/security/path-boundary.js.map +1 -0
- package/dist/ui/index.d.ts +1774 -1768
- package/dist/ui/index.js +974 -674
- package/dist/ui/index.js.map +1 -1
- package/dist/vite-builder/index.d.ts +9 -5
- 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
|
+
|
|
9
|
+
//#region src/create.ts
|
|
8
10
|
const defaultProjectName = "resux-app";
|
|
9
|
-
const packageManagers = new Set([
|
|
11
|
+
const packageManagers = new Set([
|
|
12
|
+
"npm",
|
|
13
|
+
"pnpm",
|
|
14
|
+
"yarn",
|
|
15
|
+
"bun"
|
|
16
|
+
]);
|
|
10
17
|
const starterTemplates = [
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
"minimal",
|
|
19
|
+
"default",
|
|
20
|
+
"full",
|
|
21
|
+
"i18n",
|
|
22
|
+
"pwa",
|
|
23
|
+
"media",
|
|
24
|
+
"package-compatibility",
|
|
25
|
+
"dashboard"
|
|
19
26
|
];
|
|
20
27
|
const starterFeatures = [
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
28
|
+
"seo",
|
|
29
|
+
"i18n",
|
|
30
|
+
"media",
|
|
31
|
+
"pwa",
|
|
32
|
+
"tailwind",
|
|
33
|
+
"package-compatibility",
|
|
34
|
+
"server-api",
|
|
35
|
+
"tests"
|
|
29
36
|
];
|
|
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
|
-
|
|
37
|
+
if (isMainModule()) runCreateResux(process.argv.slice(2)).catch((error) => {
|
|
38
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
39
|
+
process.exitCode = 1;
|
|
40
|
+
});
|
|
41
|
+
async function runCreateResux(args = process.argv.slice(2)) {
|
|
42
|
+
const options = parseArgs(args);
|
|
43
|
+
if (options.help) {
|
|
44
|
+
printHelp();
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const prompts = createInterface({
|
|
48
|
+
input: stdin,
|
|
49
|
+
output: stdout
|
|
50
|
+
});
|
|
51
|
+
try {
|
|
52
|
+
const targetDir = await readTargetDir(options, prompts);
|
|
53
|
+
const root = path.resolve(process.cwd(), targetDir);
|
|
54
|
+
const projectName = toPackageName(path.basename(root));
|
|
55
|
+
const title = toTitle(projectName);
|
|
56
|
+
const frameworkPackage = await readFrameworkPackage();
|
|
57
|
+
const template = await readStarterTemplate(options, prompts);
|
|
58
|
+
const features = uniqueFeatures([...defaultFeaturesForTemplate(template), ...await readStarterFeatures(options, prompts, template)]);
|
|
59
|
+
const hreflang = await readHreflangSupport(options, prompts, features);
|
|
60
|
+
const install = options.install ?? await promptConfirm(prompts, "Install dependencies?", canPrompt(), options.yes);
|
|
61
|
+
const packageManager = options.packageManager ?? detectPackageManager();
|
|
62
|
+
assertSafeCreateTarget(root, process.cwd(), options.force);
|
|
63
|
+
await prepareTarget(root, options.force);
|
|
64
|
+
await copyTemplate(path.resolve(fileURLToPath(new URL("../templates/default", import.meta.url))), root, {
|
|
65
|
+
"%PROJECT_NAME%": projectName,
|
|
66
|
+
"%PROJECT_TITLE%": title
|
|
67
|
+
});
|
|
68
|
+
await writeFile(path.join(root, "package.json"), createStarterPackageJson(projectName, frameworkPackage, features, template), "utf8");
|
|
69
|
+
await applyStarterFeatureScaffold(root, title, features, { hreflang });
|
|
70
|
+
await ensureStarterProjectStructure(root, title, features, template);
|
|
71
|
+
if (install) await installDependencies(root, packageManager);
|
|
72
|
+
printNextSteps({
|
|
73
|
+
root,
|
|
74
|
+
packageManager,
|
|
75
|
+
installed: install,
|
|
76
|
+
features,
|
|
77
|
+
template
|
|
78
|
+
});
|
|
79
|
+
} finally {
|
|
80
|
+
prompts.close();
|
|
81
|
+
}
|
|
75
82
|
}
|
|
76
83
|
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;
|
|
84
|
+
const options = {
|
|
85
|
+
force: false,
|
|
86
|
+
yes: false,
|
|
87
|
+
help: false
|
|
88
|
+
};
|
|
89
|
+
for (let index = 0; index < args.length; index++) {
|
|
90
|
+
const arg = args[index];
|
|
91
|
+
if (arg === "-h" || arg === "--help") options.help = true;
|
|
92
|
+
else if (arg === "-y" || arg === "--yes") options.yes = true;
|
|
93
|
+
else if (arg === "--install") options.install = true;
|
|
94
|
+
else if (arg === "--no-install") options.install = false;
|
|
95
|
+
else if (arg === "--force") options.force = true;
|
|
96
|
+
else if (arg === "--template") options.template = readTemplate(args[++index]);
|
|
97
|
+
else if (arg.startsWith("--template=")) options.template = readTemplate(arg.slice(11));
|
|
98
|
+
else if (arg === "--features") options.features = normalizeFeatureList(args[++index]);
|
|
99
|
+
else if (arg.startsWith("--features=")) options.features = normalizeFeatureList(arg.slice(11));
|
|
100
|
+
else if (arg === "--package-manager" || arg === "--pm") options.packageManager = readPackageManager(args[++index]);
|
|
101
|
+
else if (arg.startsWith("--package-manager=")) options.packageManager = readPackageManager(arg.slice(18));
|
|
102
|
+
else if (arg.startsWith("--pm=")) options.packageManager = readPackageManager(arg.slice(5));
|
|
103
|
+
else if (arg === "--hreflang") options.hreflang = true;
|
|
104
|
+
else if (arg === "--no-hreflang") options.hreflang = false;
|
|
105
|
+
else if (arg.startsWith("-")) throw new Error(`Unknown option "${arg}". Run resux init --help for usage.`);
|
|
106
|
+
else if (!options.targetDir) options.targetDir = arg;
|
|
107
|
+
else throw new Error(`Unexpected argument "${arg}". Only one project directory can be provided.`);
|
|
108
|
+
}
|
|
109
|
+
return options;
|
|
137
110
|
}
|
|
138
111
|
function readPackageManager(value) {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
}
|
|
142
|
-
return value;
|
|
112
|
+
if (!value || !packageManagers.has(value)) throw new Error("Package manager must be one of npm, pnpm, yarn, or bun.");
|
|
113
|
+
return value;
|
|
143
114
|
}
|
|
144
115
|
function readTemplate(value) {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
}
|
|
148
|
-
return value;
|
|
116
|
+
if (!value || !starterTemplates.includes(value)) throw new Error(`Template must be one of: ${starterTemplates.join(", ")}.`);
|
|
117
|
+
return value;
|
|
149
118
|
}
|
|
150
119
|
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;
|
|
120
|
+
if (!raw) return [];
|
|
121
|
+
const entries = raw.split(",").map((entry) => entry.trim().toLowerCase()).filter(Boolean);
|
|
122
|
+
const selected = [];
|
|
123
|
+
const seen = /* @__PURE__ */ new Set();
|
|
124
|
+
for (const entry of entries) {
|
|
125
|
+
if (!starterFeatures.includes(entry)) throw new Error(`Unknown feature "${entry}". Supported features: ${starterFeatures.join(", ")}.`);
|
|
126
|
+
const feature = entry;
|
|
127
|
+
if (!seen.has(feature)) {
|
|
128
|
+
seen.add(feature);
|
|
129
|
+
selected.push(feature);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return selected;
|
|
171
133
|
}
|
|
172
134
|
function uniqueFeatures(features) {
|
|
173
|
-
|
|
135
|
+
return [...new Set(features)];
|
|
174
136
|
}
|
|
175
137
|
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"];
|
|
138
|
+
if (template === "minimal") return [];
|
|
139
|
+
if (template === "full") return [
|
|
140
|
+
"seo",
|
|
141
|
+
"i18n",
|
|
142
|
+
"media",
|
|
143
|
+
"pwa",
|
|
144
|
+
"tailwind",
|
|
145
|
+
"package-compatibility",
|
|
146
|
+
"server-api",
|
|
147
|
+
"tests"
|
|
148
|
+
];
|
|
149
|
+
if (template === "i18n") return ["i18n"];
|
|
150
|
+
if (template === "pwa") return ["pwa"];
|
|
151
|
+
if (template === "media") return ["media"];
|
|
152
|
+
if (template === "package-compatibility") return ["package-compatibility"];
|
|
153
|
+
if (template === "dashboard") return [
|
|
154
|
+
"seo",
|
|
155
|
+
"tailwind",
|
|
156
|
+
"server-api"
|
|
157
|
+
];
|
|
158
|
+
return ["seo"];
|
|
198
159
|
}
|
|
199
160
|
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);
|
|
161
|
+
if (options.template) return options.template;
|
|
162
|
+
if (options.yes || !canPrompt()) return "default";
|
|
163
|
+
const answer = (await prompts.question(`Template (${starterTemplates.join(", ")}) [default]: `)).trim();
|
|
164
|
+
if (!answer) return "default";
|
|
165
|
+
return readTemplate(answer);
|
|
211
166
|
}
|
|
212
167
|
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;
|
|
168
|
+
if (Array.isArray(options.features)) return options.features;
|
|
169
|
+
if (options.yes || !canPrompt()) return [];
|
|
170
|
+
const selected = [];
|
|
171
|
+
const labels = {
|
|
172
|
+
seo: "SEO utilities",
|
|
173
|
+
i18n: "i18n (localized routes + translations)",
|
|
174
|
+
media: "media page + helpers",
|
|
175
|
+
pwa: "PWA manifest scaffold",
|
|
176
|
+
tailwind: "Tailwind CSS setup",
|
|
177
|
+
"package-compatibility": "third-party package compatibility examples",
|
|
178
|
+
"server-api": "server API and route examples",
|
|
179
|
+
tests: "basic tests scaffold"
|
|
180
|
+
};
|
|
181
|
+
const promptOrder = [
|
|
182
|
+
"tailwind",
|
|
183
|
+
"i18n",
|
|
184
|
+
"pwa",
|
|
185
|
+
"media",
|
|
186
|
+
"package-compatibility",
|
|
187
|
+
"server-api",
|
|
188
|
+
"tests",
|
|
189
|
+
"seo"
|
|
190
|
+
];
|
|
191
|
+
const templateDefaults = new Set(defaultFeaturesForTemplate(template));
|
|
192
|
+
for (const feature of promptOrder) if (await promptConfirm(prompts, `Enable ${labels[feature]}?`, templateDefaults.has(feature), false)) selected.push(feature);
|
|
193
|
+
return selected;
|
|
248
194
|
}
|
|
249
195
|
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);
|
|
196
|
+
if (!features.includes("i18n") && !features.includes("seo")) return false;
|
|
197
|
+
if (typeof options.hreflang === "boolean") return options.hreflang;
|
|
198
|
+
if (options.yes || !canPrompt()) return false;
|
|
199
|
+
return promptConfirm(prompts, "Add hreflang alternate links?", false, false);
|
|
260
200
|
}
|
|
261
201
|
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;
|
|
202
|
+
if (options.targetDir) return options.targetDir;
|
|
203
|
+
if (options.yes || !canPrompt()) return defaultProjectName;
|
|
204
|
+
return (await prompts.question(`Project name (${defaultProjectName}): `)).trim() || defaultProjectName;
|
|
270
205
|
}
|
|
271
206
|
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";
|
|
207
|
+
if (yes || !canPrompt()) return defaultValue;
|
|
208
|
+
const suffix = defaultValue ? "Y/n" : "y/N";
|
|
209
|
+
const answer = (await prompts.question(`${label} (${suffix}) `)).trim().toLowerCase();
|
|
210
|
+
if (!answer) return defaultValue;
|
|
211
|
+
return answer === "y" || answer === "yes";
|
|
281
212
|
}
|
|
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
|
-
}
|
|
213
|
+
function assertSafeCreateTarget(root, cwd, force) {
|
|
214
|
+
if (!force) return;
|
|
215
|
+
const target = path.resolve(root);
|
|
216
|
+
const workingDirectory = path.resolve(cwd);
|
|
217
|
+
const filesystemRoot = path.parse(target).root;
|
|
218
|
+
const homeDirectory = path.resolve(homedir());
|
|
219
|
+
const relativeWorkingDirectory = path.relative(target, workingDirectory);
|
|
220
|
+
const containsWorkingDirectory = relativeWorkingDirectory === "" || !relativeWorkingDirectory.startsWith("..") && !path.isAbsolute(relativeWorkingDirectory);
|
|
221
|
+
if (target === filesystemRoot || target === homeDirectory || containsWorkingDirectory) throw new Error(`Refusing to use --force on protected directory "${target}". Choose a new child directory instead.`);
|
|
296
222
|
}
|
|
297
223
|
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
|
-
}
|
|
224
|
+
const absoluteTarget = path.resolve(target);
|
|
225
|
+
const filesystemRoot = path.parse(absoluteTarget).root;
|
|
226
|
+
const segments = path.relative(filesystemRoot, absoluteTarget).split(path.sep).filter(Boolean);
|
|
227
|
+
let current = filesystemRoot;
|
|
228
|
+
for (const segment of segments) {
|
|
229
|
+
current = path.join(current, segment);
|
|
230
|
+
const info = await lstat(current).catch((error) => {
|
|
231
|
+
if (error.code === "ENOENT") return null;
|
|
232
|
+
throw error;
|
|
233
|
+
});
|
|
234
|
+
if (!info) break;
|
|
235
|
+
if (info.isSymbolicLink()) throw new Error(`Refusing to create a Resux project through symbolic link component "${current}". Choose a real directory instead.`);
|
|
236
|
+
}
|
|
318
237
|
}
|
|
319
238
|
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
|
-
}
|
|
239
|
+
await assertCreatePathHasNoSymlinkComponents(root);
|
|
240
|
+
await mkdir(root, { recursive: true });
|
|
241
|
+
await assertCreatePathHasNoSymlinkComponents(root);
|
|
242
|
+
const rootIdentity = await lstat(root);
|
|
243
|
+
if (!rootIdentity.isDirectory()) throw new Error(`Target "${root}" is not a directory.`);
|
|
244
|
+
const entries = await readdir(root);
|
|
245
|
+
if (entries.length === 0) return;
|
|
246
|
+
if (!force) throw new Error(`Target directory "${root}" is not empty. Choose another name or pass --force.`);
|
|
247
|
+
for (const entry of entries) {
|
|
248
|
+
await assertCreatePathHasNoSymlinkComponents(root);
|
|
249
|
+
const currentIdentity = await lstat(root);
|
|
250
|
+
if (currentIdentity.dev !== rootIdentity.dev || currentIdentity.ino !== rootIdentity.ino) throw new Error(`Refusing to continue because target directory "${root}" changed during --force cleanup.`);
|
|
251
|
+
await rm(path.join(root, entry), {
|
|
252
|
+
recursive: true,
|
|
253
|
+
force: true
|
|
254
|
+
});
|
|
255
|
+
}
|
|
342
256
|
}
|
|
343
257
|
async function copyTemplate(sourceRoot, targetRoot, replacements) {
|
|
344
|
-
|
|
258
|
+
await copyDirectory(sourceRoot, targetRoot, "", replacements);
|
|
345
259
|
}
|
|
346
260
|
async function copyDirectory(sourceDir, targetDir, relativeDir, replacements) {
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
await copyEntry(entry, sourceDir, targetDir, relativeDir, replacements);
|
|
351
|
-
}
|
|
261
|
+
await mkdir(targetDir, { recursive: true });
|
|
262
|
+
const entries = await readdir(sourceDir, { withFileTypes: true });
|
|
263
|
+
for (const entry of entries) await copyEntry(entry, sourceDir, targetDir, relativeDir, replacements);
|
|
352
264
|
}
|
|
353
265
|
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");
|
|
266
|
+
const source = path.join(sourceDir, entry.name);
|
|
267
|
+
const targetName = entry.name === "_gitignore" ? ".gitignore" : entry.name;
|
|
268
|
+
const target = path.join(targetDir, targetName);
|
|
269
|
+
const relativePath = path.join(relativeDir, entry.name);
|
|
270
|
+
if (entry.isDirectory()) {
|
|
271
|
+
await copyDirectory(source, target, relativePath, replacements);
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
if (!entry.isFile()) return;
|
|
275
|
+
let contents = await readFile(source, "utf8");
|
|
276
|
+
for (const [needle, value] of Object.entries(replacements)) contents = contents.replaceAll(needle, value);
|
|
277
|
+
await writeFile(target, contents, "utf8");
|
|
370
278
|
}
|
|
371
279
|
async function readFrameworkPackage() {
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
};
|
|
280
|
+
const contents = await readFile(fileURLToPath(new URL("../package.json", import.meta.url)), "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,28 @@ function createStarterResuxConfig(title, features, options) {
|
|
|
913
821
|
`;
|
|
914
822
|
}
|
|
915
823
|
async function removeSeoFromPage(filePath) {
|
|
916
|
-
|
|
917
|
-
const withoutSeo = source.replace(/\nuseSeoMeta\(\{[\s\S]*?\}\)\n/g, "\n");
|
|
918
|
-
await writeFile(filePath, withoutSeo, "utf8");
|
|
824
|
+
await writeFile(filePath, (await readFile(filePath, "utf8")).replace(/\nuseSeoMeta\(\{[\s\S]*?\}\)\n/g, "\n"), "utf8");
|
|
919
825
|
}
|
|
920
826
|
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">
|
|
827
|
+
const localesDir = path.join(root, "locales");
|
|
828
|
+
await mkdir(localesDir, { recursive: true });
|
|
829
|
+
await writeFile(path.join(localesDir, "en.json"), `${JSON.stringify({ demo: {
|
|
830
|
+
badge: "I18n demo",
|
|
831
|
+
title: "Localized starter",
|
|
832
|
+
subtitle: "Switch locale prefixes and translate strings without hydration.",
|
|
833
|
+
currentLocale: "Current locale: {locale}",
|
|
834
|
+
currentDir: "Direction: {dir}",
|
|
835
|
+
welcome: "Welcome, {name}!"
|
|
836
|
+
} }, null, 2)}\n`, "utf8");
|
|
837
|
+
await writeFile(path.join(localesDir, "ar.json"), `${JSON.stringify({ demo: {
|
|
838
|
+
badge: "عرض الترجمة",
|
|
839
|
+
title: "مشروع مترجم",
|
|
840
|
+
subtitle: "بدل اللغات والمسارات بدون ترطيب.",
|
|
841
|
+
currentLocale: "اللغة الحالية: {locale}",
|
|
842
|
+
currentDir: "الاتجاه: {dir}",
|
|
843
|
+
welcome: "مرحبًا {name}!"
|
|
844
|
+
} }, null, 2)}\n`, "utf8");
|
|
845
|
+
await writeFile(path.join(root, "pages", "i18n.vue"), `<script setup lang="ts">
|
|
944
846
|
import { useI18n } from "resuxjs/i18n"
|
|
945
847
|
|
|
946
848
|
definePageMeta({
|
|
@@ -951,7 +853,7 @@ definePageMeta({
|
|
|
951
853
|
})
|
|
952
854
|
|
|
953
855
|
const i18n = useI18n()
|
|
954
|
-
|
|
856
|
+
<\/script>
|
|
955
857
|
|
|
956
858
|
<template>
|
|
957
859
|
<main class="page narrow">
|
|
@@ -970,11 +872,11 @@ const i18n = useI18n()
|
|
|
970
872
|
`, "utf8");
|
|
971
873
|
}
|
|
972
874
|
async function scaffoldMediaPage(root) {
|
|
973
|
-
|
|
875
|
+
await writeFile(path.join(root, "pages", "media.vue"), `<script setup lang="ts">
|
|
974
876
|
definePageMeta({
|
|
975
877
|
title: "Media"
|
|
976
878
|
})
|
|
977
|
-
|
|
879
|
+
<\/script>
|
|
978
880
|
|
|
979
881
|
<template>
|
|
980
882
|
<main class="page">
|
|
@@ -1013,141 +915,94 @@ definePageMeta({
|
|
|
1013
915
|
`, "utf8");
|
|
1014
916
|
}
|
|
1015
917
|
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())
|
|
918
|
+
await writeFile(path.join(root, "public", "manifest.webmanifest"), `${JSON.stringify({
|
|
919
|
+
name: title,
|
|
920
|
+
short_name: title.replace(/\s+/g, " ").slice(0, 12),
|
|
921
|
+
start_url: "/",
|
|
922
|
+
display: "standalone",
|
|
923
|
+
background_color: "#020617",
|
|
924
|
+
theme_color: "#0f172a",
|
|
925
|
+
icons: [{
|
|
926
|
+
src: "/resux-placeholder.svg",
|
|
927
|
+
sizes: "96x96",
|
|
928
|
+
type: "image/svg+xml",
|
|
929
|
+
purpose: "any"
|
|
930
|
+
}]
|
|
931
|
+
}, null, 2)}\n`, "utf8");
|
|
932
|
+
await writeFile(path.join(root, "public", "sw.js"), `self.addEventListener("install", () => self.skipWaiting())
|
|
1033
933
|
self.addEventListener("activate", (event) => {
|
|
1034
934
|
event.waitUntil(self.clients.claim())
|
|
1035
935
|
})
|
|
1036
936
|
`, "utf8");
|
|
1037
937
|
}
|
|
1038
938
|
async function extendDefaultLayoutNavigation(root, features) {
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
if (!additions.length) {
|
|
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");
|
|
939
|
+
const layoutPath = path.join(root, "layouts", "default.vue");
|
|
940
|
+
const source = await readFile(layoutPath, "utf8");
|
|
941
|
+
const additions = [...features.has("i18n") ? [" <ResuxLink to=\"/i18n\">I18n</ResuxLink>"] : [], ...features.has("media") ? [" <ResuxLink to=\"/media\">Media</ResuxLink>"] : []];
|
|
942
|
+
if (!additions.length) return;
|
|
943
|
+
const marker = " </nav>";
|
|
944
|
+
await writeFile(layoutPath, source.includes(marker) ? source.replace(marker, `${additions.join("\n")}\n${marker}`) : source, "utf8");
|
|
1053
945
|
}
|
|
1054
946
|
async function annotateStarterReadme(root, features) {
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
const featureList = [...features].map((feature) => `- ${feature}`).join("\n");
|
|
1061
|
-
const next = `${source.trimEnd()}\n\n## Optional Features\n\n${featureList}\n`;
|
|
1062
|
-
await writeFile(readmePath, next, "utf8");
|
|
947
|
+
if (!features.size) return;
|
|
948
|
+
const readmePath = path.join(root, "README.md");
|
|
949
|
+
const source = await readFile(readmePath, "utf8");
|
|
950
|
+
const featureList = [...features].map((feature) => `- ${feature}`).join("\n");
|
|
951
|
+
await writeFile(readmePath, `${source.trimEnd()}\n\n## Optional Features\n\n${featureList}\n`, "utf8");
|
|
1063
952
|
}
|
|
1064
953
|
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
|
-
});
|
|
954
|
+
await new Promise((resolve, reject) => {
|
|
955
|
+
const child = spawn(packageManager, ["install"], {
|
|
956
|
+
cwd: root,
|
|
957
|
+
stdio: "inherit",
|
|
958
|
+
shell: process.platform === "win32"
|
|
959
|
+
});
|
|
960
|
+
child.on("error", reject);
|
|
961
|
+
child.on("exit", (code) => {
|
|
962
|
+
if (code === 0) resolve();
|
|
963
|
+
else reject(/* @__PURE__ */ new Error(`${packageManager} install exited with code ${code ?? "unknown"}.`));
|
|
964
|
+
});
|
|
965
|
+
});
|
|
1081
966
|
}
|
|
1082
967
|
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
|
-
}
|
|
968
|
+
const cdTarget = formatShellPath(path.relative(process.cwd(), options.root) || ".");
|
|
969
|
+
console.log(`\nCreated Resux app in ${options.root}`);
|
|
970
|
+
console.log(`Template: ${options.template}`);
|
|
971
|
+
console.log("\nNext steps:");
|
|
972
|
+
if (cdTarget !== ".") console.log(` cd ${cdTarget}`);
|
|
973
|
+
if (!options.installed) console.log(` ${options.packageManager} install`);
|
|
974
|
+
console.log(` ${runCommand(options.packageManager, "dev")}`);
|
|
975
|
+
if (options.features.length > 0) console.log(`\nSelected optional features: ${options.features.join(", ")}`);
|
|
1098
976
|
}
|
|
1099
977
|
function runCommand(packageManager, script) {
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
if (packageManager === "bun") {
|
|
1104
|
-
return `bun run ${script}`;
|
|
1105
|
-
}
|
|
1106
|
-
return `${packageManager} ${script}`;
|
|
978
|
+
if (packageManager === "npm") return `npm run ${script}`;
|
|
979
|
+
if (packageManager === "bun") return `bun run ${script}`;
|
|
980
|
+
return `${packageManager} ${script}`;
|
|
1107
981
|
}
|
|
1108
982
|
function detectPackageManager() {
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
return "yarn";
|
|
1115
|
-
}
|
|
1116
|
-
if (agent.startsWith("bun")) {
|
|
1117
|
-
return "bun";
|
|
1118
|
-
}
|
|
1119
|
-
return "npm";
|
|
983
|
+
const agent = process.env.npm_config_user_agent ?? "";
|
|
984
|
+
if (agent.startsWith("pnpm")) return "pnpm";
|
|
985
|
+
if (agent.startsWith("yarn")) return "yarn";
|
|
986
|
+
if (agent.startsWith("bun")) return "bun";
|
|
987
|
+
return "npm";
|
|
1120
988
|
}
|
|
1121
989
|
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;
|
|
990
|
+
return value.trim().toLowerCase().replace(/\\/g, "/").split("/").filter(Boolean).pop()?.replace(/[^a-z0-9._-]+/g, "-").replace(/^[._-]+|[._-]+$/g, "") || defaultProjectName;
|
|
1132
991
|
}
|
|
1133
992
|
function toTitle(value) {
|
|
1134
|
-
|
|
1135
|
-
.split(/[-_]/g)
|
|
1136
|
-
.filter(Boolean)
|
|
1137
|
-
.map((part) => part.charAt(0).toUpperCase() + part.slice(1))
|
|
1138
|
-
.join(" ") || "Resux App";
|
|
993
|
+
return value.split(/[-_]/g).filter(Boolean).map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join(" ") || "Resux App";
|
|
1139
994
|
}
|
|
1140
995
|
function formatShellPath(value) {
|
|
1141
|
-
|
|
996
|
+
return /\s/.test(value) ? JSON.stringify(value) : value;
|
|
1142
997
|
}
|
|
1143
998
|
function canPrompt() {
|
|
1144
|
-
|
|
999
|
+
return Boolean(stdin.isTTY && stdout.isTTY);
|
|
1145
1000
|
}
|
|
1146
1001
|
function isMainModule() {
|
|
1147
|
-
|
|
1002
|
+
return process.argv[1] ? path.resolve(process.argv[1]) === fileURLToPath(import.meta.url) : false;
|
|
1148
1003
|
}
|
|
1149
1004
|
function printHelp() {
|
|
1150
|
-
|
|
1005
|
+
console.log(`resux init
|
|
1151
1006
|
|
|
1152
1007
|
Usage:
|
|
1153
1008
|
npx resuxjs@latest init [project-dir] [options]
|
|
@@ -1166,4 +1021,7 @@ Options:
|
|
|
1166
1021
|
-h, --help Show this help message
|
|
1167
1022
|
`);
|
|
1168
1023
|
}
|
|
1024
|
+
|
|
1025
|
+
//#endregion
|
|
1026
|
+
export { assertSafeCreateTarget, runCreateResux };
|
|
1169
1027
|
//# sourceMappingURL=create.js.map
|