resuxjs 0.2.43 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +991 -666
- package/dist/cli.js +1990 -355
- package/dist/cli.js.map +1 -1
- package/dist/compiler/adapter.d.ts +17 -0
- package/dist/compiler/adapter.js +106 -0
- package/dist/compiler/adapter.js.map +1 -0
- package/dist/compiler/dev-warnings.d.ts +11 -0
- package/dist/compiler/dev-warnings.js +360 -0
- package/dist/compiler/dev-warnings.js.map +1 -0
- package/dist/compiler/directives.d.ts +13 -0
- package/dist/compiler/directives.js +167 -0
- package/dist/compiler/directives.js.map +1 -0
- package/dist/compiler/implementation.d.ts +129 -0
- package/dist/compiler/implementation.js +3745 -0
- package/dist/compiler/implementation.js.map +1 -0
- package/dist/compiler/index.d.ts +9 -103
- package/dist/compiler/index.js +74 -1971
- package/dist/compiler/index.js.map +1 -1
- package/dist/core/config.d.ts +8 -0
- package/dist/core/config.js +21 -0
- package/dist/core/config.js.map +1 -0
- package/dist/core/hooks.d.ts +133 -0
- package/dist/core/hooks.js +54 -0
- package/dist/core/hooks.js.map +1 -0
- package/dist/core/index.d.ts +4 -0
- package/dist/core/index.js +5 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/module-container.d.ts +100 -0
- package/dist/core/module-container.js +171 -0
- package/dist/core/module-container.js.map +1 -0
- package/dist/core/resux.d.ts +18 -0
- package/dist/core/resux.js +18 -0
- package/dist/core/resux.js.map +1 -0
- package/dist/create.d.ts +1 -0
- package/dist/create.js +878 -22
- package/dist/create.js.map +1 -1
- package/dist/deploy/cloudflare.js +17 -3
- package/dist/deploy/cloudflare.js.map +1 -1
- package/dist/deploy/common.js +4 -3
- package/dist/deploy/common.js.map +1 -1
- package/dist/fonts/index.d.ts +16 -0
- package/dist/fonts/index.js +154 -0
- package/dist/fonts/index.js.map +1 -0
- package/dist/globals.d.ts +27 -2
- package/dist/halal-core/ai/classifyProject.d.ts +4 -0
- package/dist/halal-core/ai/classifyProject.js +104 -0
- package/dist/halal-core/ai/classifyProject.js.map +1 -0
- package/dist/halal-core/ai/createProjectSummary.d.ts +39 -0
- package/dist/halal-core/ai/createProjectSummary.js +42 -0
- package/dist/halal-core/ai/createProjectSummary.js.map +1 -0
- package/dist/halal-core/ai/halalClassifierPrompt.d.ts +1 -0
- package/dist/halal-core/ai/halalClassifierPrompt.js +20 -0
- package/dist/halal-core/ai/halalClassifierPrompt.js.map +1 -0
- package/dist/halal-core/ai/redactSensitiveData.d.ts +1 -0
- package/dist/halal-core/ai/redactSensitiveData.js +139 -0
- package/dist/halal-core/ai/redactSensitiveData.js.map +1 -0
- package/dist/halal-core/ai/validateAiResponse.d.ts +2 -0
- package/dist/halal-core/ai/validateAiResponse.js +97 -0
- package/dist/halal-core/ai/validateAiResponse.js.map +1 -0
- package/dist/halal-core/cli/check.d.ts +1 -0
- package/dist/halal-core/cli/check.js +36 -0
- package/dist/halal-core/cli/check.js.map +1 -0
- package/dist/halal-core/cli/explain.d.ts +1 -0
- package/dist/halal-core/cli/explain.js +35 -0
- package/dist/halal-core/cli/explain.js.map +1 -0
- package/dist/halal-core/cli/report.d.ts +1 -0
- package/dist/halal-core/cli/report.js +15 -0
- package/dist/halal-core/cli/report.js.map +1 -0
- package/dist/halal-core/cli/submitReview.d.ts +1 -0
- package/dist/halal-core/cli/submitReview.js +12 -0
- package/dist/halal-core/cli/submitReview.js.map +1 -0
- package/dist/halal-core/cli/verifyReview.d.ts +1 -0
- package/dist/halal-core/cli/verifyReview.js +19 -0
- package/dist/halal-core/cli/verifyReview.js.map +1 -0
- package/dist/halal-core/config.d.ts +40 -0
- package/dist/halal-core/config.js +128 -0
- package/dist/halal-core/config.js.map +1 -0
- package/dist/halal-core/crypto/integrity.d.ts +9 -0
- package/dist/halal-core/crypto/integrity.js +101 -0
- package/dist/halal-core/crypto/integrity.js.map +1 -0
- package/dist/halal-core/enforce.d.ts +5 -0
- package/dist/halal-core/enforce.js +119 -0
- package/dist/halal-core/enforce.js.map +1 -0
- package/dist/halal-core/index.d.ts +14 -0
- package/dist/halal-core/index.js +17 -0
- package/dist/halal-core/index.js.map +1 -0
- package/dist/halal-core/lifecycle.d.ts +1 -0
- package/dist/halal-core/lifecycle.js +15 -0
- package/dist/halal-core/lifecycle.js.map +1 -0
- package/dist/halal-core/policy.d.ts +2 -0
- package/dist/halal-core/policy.js +5 -0
- package/dist/halal-core/policy.js.map +1 -0
- package/dist/halal-core/report/formatBrowserOverlay.d.ts +2 -0
- package/dist/halal-core/report/formatBrowserOverlay.js +41 -0
- package/dist/halal-core/report/formatBrowserOverlay.js.map +1 -0
- package/dist/halal-core/report/formatTerminalReport.d.ts +2 -0
- package/dist/halal-core/report/formatTerminalReport.js +39 -0
- package/dist/halal-core/report/formatTerminalReport.js.map +1 -0
- package/dist/halal-core/report/generateHalalReport.d.ts +7 -0
- package/dist/halal-core/report/generateHalalReport.js +46 -0
- package/dist/halal-core/report/generateHalalReport.js.map +1 -0
- package/dist/halal-core/report/signReport.d.ts +3 -0
- package/dist/halal-core/report/signReport.js +17 -0
- package/dist/halal-core/report/signReport.js.map +1 -0
- package/dist/halal-core/report/verifyReport.d.ts +11 -0
- package/dist/halal-core/report/verifyReport.js +45 -0
- package/dist/halal-core/report/verifyReport.js.map +1 -0
- package/dist/halal-core/review/createReviewRequest.d.ts +2 -0
- package/dist/halal-core/review/createReviewRequest.js +21 -0
- package/dist/halal-core/review/createReviewRequest.js.map +1 -0
- package/dist/halal-core/review/reviewPolicy.d.ts +3 -0
- package/dist/halal-core/review/reviewPolicy.js +21 -0
- package/dist/halal-core/review/reviewPolicy.js.map +1 -0
- package/dist/halal-core/review/signedReviewFile.d.ts +13 -0
- package/dist/halal-core/review/signedReviewFile.js +28 -0
- package/dist/halal-core/review/signedReviewFile.js.map +1 -0
- package/dist/halal-core/review/verifyReviewApproval.d.ts +10 -0
- package/dist/halal-core/review/verifyReviewApproval.js +68 -0
- package/dist/halal-core/review/verifyReviewApproval.js.map +1 -0
- package/dist/halal-core/rules/adultContentRules.d.ts +2 -0
- package/dist/halal-core/rules/adultContentRules.js +26 -0
- package/dist/halal-core/rules/adultContentRules.js.map +1 -0
- package/dist/halal-core/rules/alcoholDrugVapeRules.d.ts +2 -0
- package/dist/halal-core/rules/alcoholDrugVapeRules.js +25 -0
- package/dist/halal-core/rules/alcoholDrugVapeRules.js.map +1 -0
- package/dist/halal-core/rules/childSafetyRules.d.ts +2 -0
- package/dist/halal-core/rules/childSafetyRules.js +22 -0
- package/dist/halal-core/rules/childSafetyRules.js.map +1 -0
- package/dist/halal-core/rules/coreCategories.d.ts +7 -0
- package/dist/halal-core/rules/coreCategories.js +112 -0
- package/dist/halal-core/rules/coreCategories.js.map +1 -0
- package/dist/halal-core/rules/cyberAbuseRules.d.ts +2 -0
- package/dist/halal-core/rules/cyberAbuseRules.js +30 -0
- package/dist/halal-core/rules/cyberAbuseRules.js.map +1 -0
- package/dist/halal-core/rules/defaultBlockedRules.d.ts +20 -0
- package/dist/halal-core/rules/defaultBlockedRules.js +216 -0
- package/dist/halal-core/rules/defaultBlockedRules.js.map +1 -0
- package/dist/halal-core/rules/dependencyRules.d.ts +9 -0
- package/dist/halal-core/rules/dependencyRules.js +59 -0
- package/dist/halal-core/rules/dependencyRules.js.map +1 -0
- package/dist/halal-core/rules/endpointRules.d.ts +6 -0
- package/dist/halal-core/rules/endpointRules.js +26 -0
- package/dist/halal-core/rules/endpointRules.js.map +1 -0
- package/dist/halal-core/rules/environmentalHarmRules.d.ts +2 -0
- package/dist/halal-core/rules/environmentalHarmRules.js +20 -0
- package/dist/halal-core/rules/environmentalHarmRules.js.map +1 -0
- package/dist/halal-core/rules/financeRibaRules.d.ts +2 -0
- package/dist/halal-core/rules/financeRibaRules.js +23 -0
- package/dist/halal-core/rules/financeRibaRules.js.map +1 -0
- package/dist/halal-core/rules/gamblingRules.d.ts +2 -0
- package/dist/halal-core/rules/gamblingRules.js +25 -0
- package/dist/halal-core/rules/gamblingRules.js.map +1 -0
- package/dist/halal-core/rules/generalHarmRules.d.ts +2 -0
- package/dist/halal-core/rules/generalHarmRules.js +18 -0
- package/dist/halal-core/rules/generalHarmRules.js.map +1 -0
- package/dist/halal-core/rules/healthHarmRules.d.ts +2 -0
- package/dist/halal-core/rules/healthHarmRules.js +22 -0
- package/dist/halal-core/rules/healthHarmRules.js.map +1 -0
- package/dist/halal-core/rules/keywordRules.d.ts +10 -0
- package/dist/halal-core/rules/keywordRules.js +41 -0
- package/dist/halal-core/rules/keywordRules.js.map +1 -0
- package/dist/halal-core/rules/privacyAbuseRules.d.ts +2 -0
- package/dist/halal-core/rules/privacyAbuseRules.js +24 -0
- package/dist/halal-core/rules/privacyAbuseRules.js.map +1 -0
- package/dist/halal-core/rules/scamFraudRules.d.ts +2 -0
- package/dist/halal-core/rules/scamFraudRules.js +32 -0
- package/dist/halal-core/rules/scamFraudRules.js.map +1 -0
- package/dist/halal-core/rules/selfHarmRules.d.ts +2 -0
- package/dist/halal-core/rules/selfHarmRules.js +20 -0
- package/dist/halal-core/rules/selfHarmRules.js.map +1 -0
- package/dist/halal-core/rules/violenceExtremismRules.d.ts +2 -0
- package/dist/halal-core/rules/violenceExtremismRules.js +33 -0
- package/dist/halal-core/rules/violenceExtremismRules.js.map +1 -0
- package/dist/halal-core/scanner/scanApiRoutes.d.ts +1 -0
- package/dist/halal-core/scanner/scanApiRoutes.js +40 -0
- package/dist/halal-core/scanner/scanApiRoutes.js.map +1 -0
- package/dist/halal-core/scanner/scanComponents.d.ts +1 -0
- package/dist/halal-core/scanner/scanComponents.js +17 -0
- package/dist/halal-core/scanner/scanComponents.js.map +1 -0
- package/dist/halal-core/scanner/scanContent.d.ts +5 -0
- package/dist/halal-core/scanner/scanContent.js +302 -0
- package/dist/halal-core/scanner/scanContent.js.map +1 -0
- package/dist/halal-core/scanner/scanDependencies.d.ts +1 -0
- package/dist/halal-core/scanner/scanDependencies.js +19 -0
- package/dist/halal-core/scanner/scanDependencies.js.map +1 -0
- package/dist/halal-core/scanner/scanDomains.d.ts +4 -0
- package/dist/halal-core/scanner/scanDomains.js +14 -0
- package/dist/halal-core/scanner/scanDomains.js.map +1 -0
- package/dist/halal-core/scanner/scanEnvNames.d.ts +1 -0
- package/dist/halal-core/scanner/scanEnvNames.js +30 -0
- package/dist/halal-core/scanner/scanEnvNames.js.map +1 -0
- package/dist/halal-core/scanner/scanMetadata.d.ts +6 -0
- package/dist/halal-core/scanner/scanMetadata.js +33 -0
- package/dist/halal-core/scanner/scanMetadata.js.map +1 -0
- package/dist/halal-core/scanner/scanPages.d.ts +1 -0
- package/dist/halal-core/scanner/scanPages.js +19 -0
- package/dist/halal-core/scanner/scanPages.js.map +1 -0
- package/dist/halal-core/scanner/scanProject.d.ts +13 -0
- package/dist/halal-core/scanner/scanProject.js +62 -0
- package/dist/halal-core/scanner/scanProject.js.map +1 -0
- package/dist/halal-core/scanner/scanRoutes.d.ts +1 -0
- package/dist/halal-core/scanner/scanRoutes.js +43 -0
- package/dist/halal-core/scanner/scanRoutes.js.map +1 -0
- package/dist/halal-core/scanner/scanTranslations.d.ts +1 -0
- package/dist/halal-core/scanner/scanTranslations.js +32 -0
- package/dist/halal-core/scanner/scanTranslations.js.map +1 -0
- package/dist/halal-core/status.d.ts +14 -0
- package/dist/halal-core/status.js +2 -0
- package/dist/halal-core/status.js.map +1 -0
- package/dist/halal-core/tamper/verifyCoreIntegrity.d.ts +1 -0
- package/dist/halal-core/tamper/verifyCoreIntegrity.js +28 -0
- package/dist/halal-core/tamper/verifyCoreIntegrity.js.map +1 -0
- package/dist/halal-core/tamper/verifyLifecycleHooks.d.ts +1 -0
- package/dist/halal-core/tamper/verifyLifecycleHooks.js +14 -0
- package/dist/halal-core/tamper/verifyLifecycleHooks.js.map +1 -0
- package/dist/halal-core/tamper/verifyReportSignature.d.ts +5 -0
- package/dist/halal-core/tamper/verifyReportSignature.js +18 -0
- package/dist/halal-core/tamper/verifyReportSignature.js.map +1 -0
- package/dist/i18n/index.d.ts +45 -0
- package/dist/i18n/index.js +284 -0
- package/dist/i18n/index.js.map +1 -0
- package/dist/i18n/shared.d.ts +35 -0
- package/dist/i18n/shared.js +270 -0
- package/dist/i18n/shared.js.map +1 -0
- package/dist/icons/index.d.ts +159 -0
- package/dist/icons/index.js +286 -0
- package/dist/icons/index.js.map +1 -0
- package/dist/kit/index.d.ts +29 -0
- package/dist/kit/index.js +72 -0
- package/dist/kit/index.js.map +1 -0
- package/dist/nitro-server/index.d.ts +7 -0
- package/dist/nitro-server/index.js +4 -0
- package/dist/nitro-server/index.js.map +1 -0
- package/dist/reactivity/computed.js +9 -4
- package/dist/reactivity/computed.js.map +1 -1
- package/dist/reactivity/effect.d.ts +3 -1
- package/dist/reactivity/effect.js +56 -6
- package/dist/reactivity/effect.js.map +1 -1
- package/dist/reactivity/reactive.js +64 -15
- package/dist/reactivity/reactive.js.map +1 -1
- package/dist/reactivity/ref.d.ts +1 -0
- package/dist/reactivity/ref.js +13 -6
- package/dist/reactivity/ref.js.map +1 -1
- package/dist/reactivity/scheduler.js +36 -4
- package/dist/reactivity/scheduler.js.map +1 -1
- package/dist/reactivity/watch.js +27 -5
- package/dist/reactivity/watch.js.map +1 -1
- package/dist/runtime/index.d.ts +226 -3
- package/dist/runtime/index.js +13344 -6395
- package/dist/runtime/index.js.map +1 -1
- package/dist/ui/index.d.ts +1828 -0
- package/dist/ui/index.js +938 -0
- package/dist/ui/index.js.map +1 -0
- package/dist/vite-builder/index.d.ts +6 -0
- package/dist/vite-builder/index.js +4 -0
- package/dist/vite-builder/index.js.map +1 -0
- package/package.json +145 -105
- package/templates/default/.env.example +1 -0
- package/templates/default/README.md +18 -14
- package/templates/default/_gitignore +8 -5
- package/templates/default/assets/css/main.css +4 -0
- package/templates/default/nitro.config.ts +9 -5
- package/templates/default/pages/index.vue +102 -87
- package/templates/default/public/favicon.svg +4 -0
- package/templates/default/types/app.d.ts +3 -0
- package/templates/default/.resux-nitro/handler.ts +0 -21
package/dist/create.js
CHANGED
|
@@ -1,11 +1,32 @@
|
|
|
1
1
|
import { spawn } from "node:child_process";
|
|
2
2
|
import { mkdir, readFile, readdir, rm, writeFile } from "node:fs/promises";
|
|
3
|
+
import { homedir } from "node:os";
|
|
3
4
|
import path from "node:path";
|
|
4
5
|
import { stdin, stdout } from "node:process";
|
|
5
6
|
import { createInterface } from "node:readline/promises";
|
|
6
7
|
import { fileURLToPath } from "node:url";
|
|
7
8
|
const defaultProjectName = "resux-app";
|
|
8
9
|
const packageManagers = new Set(["npm", "pnpm", "yarn", "bun"]);
|
|
10
|
+
const starterTemplates = [
|
|
11
|
+
"minimal",
|
|
12
|
+
"default",
|
|
13
|
+
"full",
|
|
14
|
+
"i18n",
|
|
15
|
+
"pwa",
|
|
16
|
+
"media",
|
|
17
|
+
"package-compatibility",
|
|
18
|
+
"dashboard",
|
|
19
|
+
];
|
|
20
|
+
const starterFeatures = [
|
|
21
|
+
"seo",
|
|
22
|
+
"i18n",
|
|
23
|
+
"media",
|
|
24
|
+
"pwa",
|
|
25
|
+
"tailwind",
|
|
26
|
+
"package-compatibility",
|
|
27
|
+
"server-api",
|
|
28
|
+
"tests",
|
|
29
|
+
];
|
|
9
30
|
if (isMainModule()) {
|
|
10
31
|
runCreateResux(process.argv.slice(2)).catch((error) => {
|
|
11
32
|
console.error(error instanceof Error ? error.message : String(error));
|
|
@@ -25,18 +46,28 @@ export async function runCreateResux(args = process.argv.slice(2)) {
|
|
|
25
46
|
const projectName = toPackageName(path.basename(root));
|
|
26
47
|
const title = toTitle(projectName);
|
|
27
48
|
const frameworkPackage = await readFrameworkPackage();
|
|
49
|
+
const template = await readStarterTemplate(options, prompts);
|
|
50
|
+
const templateDefaults = defaultFeaturesForTemplate(template);
|
|
51
|
+
const features = uniqueFeatures([
|
|
52
|
+
...templateDefaults,
|
|
53
|
+
...await readStarterFeatures(options, prompts, template),
|
|
54
|
+
]);
|
|
55
|
+
const hreflang = await readHreflangSupport(options, prompts, features);
|
|
28
56
|
const install = options.install ?? await promptConfirm(prompts, "Install dependencies?", canPrompt(), options.yes);
|
|
29
57
|
const packageManager = options.packageManager ?? detectPackageManager();
|
|
58
|
+
assertSafeCreateTarget(root, process.cwd(), options.force);
|
|
30
59
|
await prepareTarget(root, options.force);
|
|
31
60
|
await copyTemplate(path.resolve(fileURLToPath(new URL("../templates/default", import.meta.url))), root, {
|
|
32
61
|
"%PROJECT_NAME%": projectName,
|
|
33
62
|
"%PROJECT_TITLE%": title
|
|
34
63
|
});
|
|
35
|
-
await writeFile(path.join(root, "package.json"), createStarterPackageJson(projectName, frameworkPackage), "utf8");
|
|
64
|
+
await writeFile(path.join(root, "package.json"), createStarterPackageJson(projectName, frameworkPackage, features, template), "utf8");
|
|
65
|
+
await applyStarterFeatureScaffold(root, title, features, { hreflang });
|
|
66
|
+
await ensureStarterProjectStructure(root, title, features, template);
|
|
36
67
|
if (install) {
|
|
37
68
|
await installDependencies(root, packageManager);
|
|
38
69
|
}
|
|
39
|
-
printNextSteps({ root, packageManager, installed: install });
|
|
70
|
+
printNextSteps({ root, packageManager, installed: install, features, template });
|
|
40
71
|
}
|
|
41
72
|
finally {
|
|
42
73
|
prompts.close();
|
|
@@ -65,6 +96,18 @@ function parseArgs(args) {
|
|
|
65
96
|
else if (arg === "--force") {
|
|
66
97
|
options.force = true;
|
|
67
98
|
}
|
|
99
|
+
else if (arg === "--template") {
|
|
100
|
+
options.template = readTemplate(args[++index]);
|
|
101
|
+
}
|
|
102
|
+
else if (arg.startsWith("--template=")) {
|
|
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
|
+
}
|
|
68
111
|
else if (arg === "--package-manager" || arg === "--pm") {
|
|
69
112
|
options.packageManager = readPackageManager(args[++index]);
|
|
70
113
|
}
|
|
@@ -74,6 +117,12 @@ function parseArgs(args) {
|
|
|
74
117
|
else if (arg.startsWith("--pm=")) {
|
|
75
118
|
options.packageManager = readPackageManager(arg.slice("--pm=".length));
|
|
76
119
|
}
|
|
120
|
+
else if (arg === "--hreflang") {
|
|
121
|
+
options.hreflang = true;
|
|
122
|
+
}
|
|
123
|
+
else if (arg === "--no-hreflang") {
|
|
124
|
+
options.hreflang = false;
|
|
125
|
+
}
|
|
77
126
|
else if (arg.startsWith("-")) {
|
|
78
127
|
throw new Error(`Unknown option "${arg}". Run resux init --help for usage.`);
|
|
79
128
|
}
|
|
@@ -92,6 +141,123 @@ function readPackageManager(value) {
|
|
|
92
141
|
}
|
|
93
142
|
return value;
|
|
94
143
|
}
|
|
144
|
+
function readTemplate(value) {
|
|
145
|
+
if (!value || !starterTemplates.includes(value)) {
|
|
146
|
+
throw new Error(`Template must be one of: ${starterTemplates.join(", ")}.`);
|
|
147
|
+
}
|
|
148
|
+
return value;
|
|
149
|
+
}
|
|
150
|
+
function normalizeFeatureList(raw) {
|
|
151
|
+
if (!raw) {
|
|
152
|
+
return [];
|
|
153
|
+
}
|
|
154
|
+
const entries = raw
|
|
155
|
+
.split(",")
|
|
156
|
+
.map((entry) => entry.trim().toLowerCase())
|
|
157
|
+
.filter(Boolean);
|
|
158
|
+
const selected = [];
|
|
159
|
+
const seen = new Set();
|
|
160
|
+
for (const entry of entries) {
|
|
161
|
+
if (!starterFeatures.includes(entry)) {
|
|
162
|
+
throw new Error(`Unknown feature "${entry}". Supported features: ${starterFeatures.join(", ")}.`);
|
|
163
|
+
}
|
|
164
|
+
const feature = entry;
|
|
165
|
+
if (!seen.has(feature)) {
|
|
166
|
+
seen.add(feature);
|
|
167
|
+
selected.push(feature);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return selected;
|
|
171
|
+
}
|
|
172
|
+
function uniqueFeatures(features) {
|
|
173
|
+
return [...new Set(features)];
|
|
174
|
+
}
|
|
175
|
+
function defaultFeaturesForTemplate(template) {
|
|
176
|
+
if (template === "minimal") {
|
|
177
|
+
return [];
|
|
178
|
+
}
|
|
179
|
+
if (template === "full") {
|
|
180
|
+
return ["seo", "i18n", "media", "pwa", "tailwind", "package-compatibility", "server-api", "tests"];
|
|
181
|
+
}
|
|
182
|
+
if (template === "i18n") {
|
|
183
|
+
return ["i18n"];
|
|
184
|
+
}
|
|
185
|
+
if (template === "pwa") {
|
|
186
|
+
return ["pwa"];
|
|
187
|
+
}
|
|
188
|
+
if (template === "media") {
|
|
189
|
+
return ["media"];
|
|
190
|
+
}
|
|
191
|
+
if (template === "package-compatibility") {
|
|
192
|
+
return ["package-compatibility"];
|
|
193
|
+
}
|
|
194
|
+
if (template === "dashboard") {
|
|
195
|
+
return ["seo", "tailwind", "server-api"];
|
|
196
|
+
}
|
|
197
|
+
return ["seo"];
|
|
198
|
+
}
|
|
199
|
+
async function readStarterTemplate(options, prompts) {
|
|
200
|
+
if (options.template) {
|
|
201
|
+
return options.template;
|
|
202
|
+
}
|
|
203
|
+
if (options.yes || !canPrompt()) {
|
|
204
|
+
return "default";
|
|
205
|
+
}
|
|
206
|
+
const answer = (await prompts.question(`Template (${starterTemplates.join(", ")}) [default]: `)).trim();
|
|
207
|
+
if (!answer) {
|
|
208
|
+
return "default";
|
|
209
|
+
}
|
|
210
|
+
return readTemplate(answer);
|
|
211
|
+
}
|
|
212
|
+
async function readStarterFeatures(options, prompts, template) {
|
|
213
|
+
if (Array.isArray(options.features)) {
|
|
214
|
+
return options.features;
|
|
215
|
+
}
|
|
216
|
+
if (options.yes || !canPrompt()) {
|
|
217
|
+
return [];
|
|
218
|
+
}
|
|
219
|
+
const selected = [];
|
|
220
|
+
const labels = {
|
|
221
|
+
seo: "SEO utilities",
|
|
222
|
+
i18n: "i18n (localized routes + translations)",
|
|
223
|
+
media: "media page + helpers",
|
|
224
|
+
pwa: "PWA manifest scaffold",
|
|
225
|
+
tailwind: "Tailwind CSS setup",
|
|
226
|
+
"package-compatibility": "third-party package compatibility examples",
|
|
227
|
+
"server-api": "server API and route examples",
|
|
228
|
+
tests: "basic tests scaffold",
|
|
229
|
+
};
|
|
230
|
+
const promptOrder = [
|
|
231
|
+
"tailwind",
|
|
232
|
+
"i18n",
|
|
233
|
+
"pwa",
|
|
234
|
+
"media",
|
|
235
|
+
"package-compatibility",
|
|
236
|
+
"server-api",
|
|
237
|
+
"tests",
|
|
238
|
+
"seo",
|
|
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;
|
|
248
|
+
}
|
|
249
|
+
async function readHreflangSupport(options, prompts, features) {
|
|
250
|
+
if (!features.includes("i18n") && !features.includes("seo")) {
|
|
251
|
+
return false;
|
|
252
|
+
}
|
|
253
|
+
if (typeof options.hreflang === "boolean") {
|
|
254
|
+
return options.hreflang;
|
|
255
|
+
}
|
|
256
|
+
if (options.yes || !canPrompt()) {
|
|
257
|
+
return false;
|
|
258
|
+
}
|
|
259
|
+
return promptConfirm(prompts, "Add hreflang alternate links?", false, false);
|
|
260
|
+
}
|
|
95
261
|
async function readTargetDir(options, prompts) {
|
|
96
262
|
if (options.targetDir) {
|
|
97
263
|
return options.targetDir;
|
|
@@ -113,6 +279,21 @@ async function promptConfirm(prompts, label, defaultValue, yes) {
|
|
|
113
279
|
}
|
|
114
280
|
return answer === "y" || answer === "yes";
|
|
115
281
|
}
|
|
282
|
+
export function assertSafeCreateTarget(root, cwd, force) {
|
|
283
|
+
if (!force) {
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
const target = path.resolve(root);
|
|
287
|
+
const workingDirectory = path.resolve(cwd);
|
|
288
|
+
const filesystemRoot = path.parse(target).root;
|
|
289
|
+
const homeDirectory = path.resolve(homedir());
|
|
290
|
+
const relativeWorkingDirectory = path.relative(target, workingDirectory);
|
|
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
|
+
}
|
|
296
|
+
}
|
|
116
297
|
async function prepareTarget(root, force) {
|
|
117
298
|
await mkdir(root, { recursive: true });
|
|
118
299
|
const entries = await readdir(root);
|
|
@@ -163,23 +344,690 @@ async function readFrameworkPackage() {
|
|
|
163
344
|
version: typeof packageJson.version === "string" ? packageJson.version : "0.0.0"
|
|
164
345
|
};
|
|
165
346
|
}
|
|
166
|
-
function createStarterPackageJson(projectName, frameworkPackage) {
|
|
347
|
+
function createStarterPackageJson(projectName, frameworkPackage, features, template) {
|
|
348
|
+
const selected = new Set(features);
|
|
349
|
+
const includeTests = selected.has("tests") || template === "default" || template === "full";
|
|
350
|
+
const devDependencies = {
|
|
351
|
+
"@types/node": "^24.10.1",
|
|
352
|
+
"typescript": "^5.9.3",
|
|
353
|
+
"vue-tsc": "^3.3.8",
|
|
354
|
+
};
|
|
355
|
+
if (includeTests) {
|
|
356
|
+
devDependencies.vitest = "^4.0.8";
|
|
357
|
+
}
|
|
358
|
+
if (selected.has("tailwind")) {
|
|
359
|
+
devDependencies.tailwindcss = "^3.4.17";
|
|
360
|
+
devDependencies.postcss = "^8.5.6";
|
|
361
|
+
devDependencies.autoprefixer = "^10.4.22";
|
|
362
|
+
}
|
|
167
363
|
return `${JSON.stringify({
|
|
168
364
|
name: projectName,
|
|
169
365
|
private: true,
|
|
170
366
|
type: "module",
|
|
171
367
|
scripts: {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
368
|
+
prepare: "resux prepare",
|
|
369
|
+
dev: "resux dev",
|
|
370
|
+
build: "resux build",
|
|
371
|
+
preview: "resux preview",
|
|
372
|
+
start: "resux start",
|
|
373
|
+
inspect: "resux inspect",
|
|
374
|
+
typecheck: "vue-tsc --noEmit",
|
|
375
|
+
...(includeTests ? { test: "vitest run" } : {}),
|
|
177
376
|
},
|
|
178
377
|
dependencies: {
|
|
179
378
|
[frameworkPackage.name]: `^${frameworkPackage.version}`
|
|
180
|
-
}
|
|
379
|
+
},
|
|
380
|
+
devDependencies,
|
|
381
|
+
engines: {
|
|
382
|
+
node: ">=20.19.0",
|
|
383
|
+
},
|
|
181
384
|
}, null, 2)}\n`;
|
|
182
385
|
}
|
|
386
|
+
async function applyStarterFeatureScaffold(root, title, features, options) {
|
|
387
|
+
const selected = new Set(features);
|
|
388
|
+
await writeFile(path.join(root, "resux.config.ts"), createStarterResuxConfig(title, selected, options), "utf8");
|
|
389
|
+
if (!selected.has("seo")) {
|
|
390
|
+
await removeSeoFromPage(path.join(root, "pages", "index.vue"));
|
|
391
|
+
await removeSeoFromPage(path.join(root, "pages", "about.vue"));
|
|
392
|
+
}
|
|
393
|
+
if (selected.has("i18n")) {
|
|
394
|
+
await scaffoldI18nFiles(root);
|
|
395
|
+
}
|
|
396
|
+
if (selected.has("media")) {
|
|
397
|
+
await scaffoldMediaPage(root);
|
|
398
|
+
}
|
|
399
|
+
if (selected.has("pwa")) {
|
|
400
|
+
await scaffoldPwaFiles(root, title);
|
|
401
|
+
}
|
|
402
|
+
await extendDefaultLayoutNavigation(root, selected);
|
|
403
|
+
await annotateStarterReadme(root, selected);
|
|
404
|
+
}
|
|
405
|
+
async function ensureStarterProjectStructure(root, title, features, template) {
|
|
406
|
+
const selected = new Set(features);
|
|
407
|
+
const shouldIncludeTests = selected.has("tests") || template === "default" || template === "full";
|
|
408
|
+
const shouldIncludeServerApi = selected.has("server-api") || template === "default" || template === "full";
|
|
409
|
+
const shouldIncludePackageExamples = selected.has("package-compatibility") || template === "package-compatibility" || template === "full";
|
|
410
|
+
const requiredDirs = [
|
|
411
|
+
"pages",
|
|
412
|
+
"layouts",
|
|
413
|
+
"components",
|
|
414
|
+
"composables",
|
|
415
|
+
"utils",
|
|
416
|
+
"shared",
|
|
417
|
+
"middleware",
|
|
418
|
+
"plugins",
|
|
419
|
+
"server/api",
|
|
420
|
+
"server/routes",
|
|
421
|
+
"server/middleware",
|
|
422
|
+
"server/plugins",
|
|
423
|
+
"server/utils",
|
|
424
|
+
"public/images",
|
|
425
|
+
"assets/css",
|
|
426
|
+
"types",
|
|
427
|
+
"tests",
|
|
428
|
+
];
|
|
429
|
+
for (const relativeDir of requiredDirs) {
|
|
430
|
+
await mkdir(path.join(root, relativeDir), { recursive: true });
|
|
431
|
+
}
|
|
432
|
+
await ensureFile(path.join(root, ".npmrc"), "engine-strict=true\n");
|
|
433
|
+
await ensureFile(path.join(root, ".env.example"), "# Runtime environment defaults\nAPP_ORIGIN=http://localhost:3000\n");
|
|
434
|
+
await ensureFile(path.join(root, "types", "app.d.ts"), 'import "resuxjs/globals";\n\nexport {};\n');
|
|
435
|
+
await ensureFile(path.join(root, "types", "assets.d.ts"), 'declare module "*.css";\n');
|
|
436
|
+
await ensureFile(path.join(root, "assets", "css", "main.css"), `:root {
|
|
437
|
+
--rx-bg: #020617;
|
|
438
|
+
--rx-surface: #0f172a;
|
|
439
|
+
--rx-text: #e2e8f0;
|
|
440
|
+
--rx-muted: #94a3b8;
|
|
441
|
+
--rx-accent: #22d3ee;
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
* {
|
|
445
|
+
box-sizing: border-box;
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
body {
|
|
449
|
+
margin: 0;
|
|
450
|
+
font-family: "Segoe UI", system-ui, sans-serif;
|
|
451
|
+
background: radial-gradient(circle at top, #111827 0%, var(--rx-bg) 60%);
|
|
452
|
+
color: var(--rx-text);
|
|
453
|
+
}
|
|
454
|
+
a {
|
|
455
|
+
color: var(--rx-accent);
|
|
456
|
+
}
|
|
457
|
+
`);
|
|
458
|
+
await ensureFile(path.join(root, "components", "AppHeader.vue"), `<template>
|
|
459
|
+
<header class="starter-header">
|
|
460
|
+
<ResuxLink to="/">${title}</ResuxLink>
|
|
461
|
+
<nav>
|
|
462
|
+
<ResuxLink to="/">Home</ResuxLink>
|
|
463
|
+
<ResuxLink to="/about">About</ResuxLink>
|
|
464
|
+
</nav>
|
|
465
|
+
</header>
|
|
466
|
+
</template>
|
|
467
|
+
|
|
468
|
+
<style scoped>
|
|
469
|
+
.starter-header {
|
|
470
|
+
display: flex;
|
|
471
|
+
align-items: center;
|
|
472
|
+
justify-content: space-between;
|
|
473
|
+
gap: 1rem;
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
nav {
|
|
477
|
+
display: inline-flex;
|
|
478
|
+
gap: 0.75rem;
|
|
479
|
+
}
|
|
480
|
+
</style>
|
|
481
|
+
`);
|
|
482
|
+
await ensureFile(path.join(root, "components", "AppFooter.vue"), `<template>
|
|
483
|
+
<footer class="starter-footer">
|
|
484
|
+
<small>Powered by Resux</small>
|
|
485
|
+
</footer>
|
|
486
|
+
</template>
|
|
487
|
+
|
|
488
|
+
<style scoped>
|
|
489
|
+
.starter-footer {
|
|
490
|
+
opacity: 0.75;
|
|
491
|
+
margin-top: 2rem;
|
|
492
|
+
}
|
|
493
|
+
</style>
|
|
494
|
+
`);
|
|
495
|
+
await ensureFile(path.join(root, "composables", "useCounter.ts"), `export function useCounter(key = "starter-counter") {
|
|
496
|
+
const count = useState<number>(key, () => 0);
|
|
497
|
+
const increment = () => {
|
|
498
|
+
count.value += 1;
|
|
499
|
+
};
|
|
500
|
+
const decrement = () => {
|
|
501
|
+
count.value -= 1;
|
|
502
|
+
};
|
|
503
|
+
return { count, increment, decrement };
|
|
504
|
+
}
|
|
505
|
+
`);
|
|
506
|
+
await ensureFile(path.join(root, "utils", "formatDate.ts"), `export function formatDate(input: string | number | Date): string {
|
|
507
|
+
const date = input instanceof Date ? input : new Date(input);
|
|
508
|
+
return new Intl.DateTimeFormat("en-US", { dateStyle: "medium" }).format(date);
|
|
509
|
+
}
|
|
510
|
+
`);
|
|
511
|
+
await ensureFile(path.join(root, "shared", "constants.ts"), `export const APP_NAME = ${JSON.stringify(title)};
|
|
512
|
+
`);
|
|
513
|
+
await ensureFile(path.join(root, "middleware", "analytics.global.ts"), `export default defineResuxRouteMiddleware((to, from) => {
|
|
514
|
+
if (to.path === from.path) {
|
|
515
|
+
return;
|
|
516
|
+
}
|
|
517
|
+
console.debug("[resux] analytics", { from: from.path, to: to.path });
|
|
518
|
+
});
|
|
519
|
+
`);
|
|
520
|
+
await ensureFile(path.join(root, "plugins", "example.ts"), `export default defineResuxPlugin((app) => {
|
|
521
|
+
app.provide("examplePlugin", "plugins/example.ts loaded");
|
|
522
|
+
});
|
|
523
|
+
`);
|
|
524
|
+
await ensureFile(path.join(root, "plugins", "client-only.client.ts"), `export default defineResuxPlugin(() => {
|
|
525
|
+
if (typeof window !== "undefined") {
|
|
526
|
+
console.debug("[resux] client-only plugin ready");
|
|
527
|
+
}
|
|
528
|
+
});
|
|
529
|
+
`);
|
|
530
|
+
await ensureFile(path.join(root, "plugins", "server-only.server.ts"), `export default defineResuxPlugin(() => {
|
|
531
|
+
console.debug("[resux] server-only plugin ready");
|
|
532
|
+
});
|
|
533
|
+
`);
|
|
534
|
+
await ensureFile(path.join(root, "server", "utils", "serverHelper.ts"), `export function serverHelper(name: string): string {
|
|
535
|
+
return "hello " + name;
|
|
536
|
+
}
|
|
537
|
+
`);
|
|
538
|
+
await ensureFile(path.join(root, "server", "middleware", "logger.ts"), `import { defineEventHandler } from "h3";
|
|
539
|
+
|
|
540
|
+
export default defineEventHandler((event) => {
|
|
541
|
+
const method = event.node.req.method ?? "GET";
|
|
542
|
+
const path = event.node.req.url ?? "/";
|
|
543
|
+
console.debug("[resux] request", method, path);
|
|
544
|
+
});
|
|
545
|
+
`);
|
|
546
|
+
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">
|
|
547
|
+
<rect width="128" height="128" rx="24" fill="#0f172a" />
|
|
548
|
+
<path d="M32 30h30c20 0 34 12 34 29 0 16-14 29-34 29H46v30H32z" fill="#22d3ee"/>
|
|
549
|
+
<circle cx="88" cy="93" r="11" fill="#a5f3fc"/>
|
|
550
|
+
</svg>
|
|
551
|
+
`);
|
|
552
|
+
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">
|
|
553
|
+
<rect width="640" height="160" rx="24" fill="#020617"/>
|
|
554
|
+
<text x="56" y="104" font-size="72" font-family="Segoe UI, sans-serif" fill="#22d3ee">Resux</text>
|
|
555
|
+
</svg>
|
|
556
|
+
`);
|
|
557
|
+
if (shouldIncludeServerApi) {
|
|
558
|
+
await ensureFile(path.join(root, "server", "api", "hello.get.ts"), `import { defineEventHandler } from "h3";
|
|
559
|
+
export default defineEventHandler(() => {
|
|
560
|
+
return { message: "hello resux" };
|
|
561
|
+
});
|
|
562
|
+
`);
|
|
563
|
+
await ensureFile(path.join(root, "server", "routes", "health.get.ts"), `import { defineEventHandler } from "h3";
|
|
564
|
+
|
|
565
|
+
export default defineEventHandler(() => ({ ok: true }));
|
|
566
|
+
`);
|
|
567
|
+
await ensureFile(path.join(root, "server", "plugins", "example.ts"), `import { defineNitroPlugin } from "nitropack/runtime/plugin";
|
|
568
|
+
|
|
569
|
+
export default defineNitroPlugin(() => {
|
|
570
|
+
console.debug("[resux] nitro plugin booted");
|
|
571
|
+
});
|
|
572
|
+
`);
|
|
573
|
+
}
|
|
574
|
+
if (shouldIncludeTests) {
|
|
575
|
+
await ensureFile(path.join(root, "tests", "basic.test.ts"), `import { describe, expect, it } from "vitest";
|
|
576
|
+
|
|
577
|
+
describe("starter", () => {
|
|
578
|
+
it("runs", () => {
|
|
579
|
+
expect(true).toBe(true);
|
|
580
|
+
});
|
|
581
|
+
});
|
|
582
|
+
`);
|
|
583
|
+
}
|
|
584
|
+
if (selected.has("tailwind")) {
|
|
585
|
+
await ensureFile(path.join(root, "tailwind.config.ts"), `import type { Config } from "tailwindcss";
|
|
586
|
+
|
|
587
|
+
export default {
|
|
588
|
+
content: [
|
|
589
|
+
"./app.vue",
|
|
590
|
+
"./pages/**/*.{vue,ts}",
|
|
591
|
+
"./layouts/**/*.vue",
|
|
592
|
+
"./components/**/*.vue",
|
|
593
|
+
"./plugins/**/*.{ts,js}",
|
|
594
|
+
],
|
|
595
|
+
theme: {
|
|
596
|
+
extend: {},
|
|
597
|
+
},
|
|
598
|
+
plugins: [],
|
|
599
|
+
} satisfies Config;
|
|
600
|
+
`);
|
|
601
|
+
await ensureFile(path.join(root, "postcss.config.cjs"), `module.exports = {
|
|
602
|
+
plugins: {
|
|
603
|
+
tailwindcss: {},
|
|
604
|
+
autoprefixer: {},
|
|
605
|
+
},
|
|
606
|
+
};
|
|
607
|
+
`);
|
|
608
|
+
await ensureFile(path.join(root, "assets", "css", "tailwind.css"), `@tailwind base;
|
|
609
|
+
@tailwind components;
|
|
610
|
+
@tailwind utilities;
|
|
611
|
+
`);
|
|
612
|
+
}
|
|
613
|
+
if (shouldIncludePackageExamples) {
|
|
614
|
+
await ensurePackageCompatibilityPages(root);
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
async function ensurePackageCompatibilityPages(root) {
|
|
618
|
+
const pagesRoot = path.join(root, "pages", "package-tests");
|
|
619
|
+
await mkdir(pagesRoot, { recursive: true });
|
|
620
|
+
await ensureFile(path.join(root, "plugins", "package-enhancements.client.ts"), `type PackageStatus = "idle" | "loading" | "ready" | "error" | "disposed";
|
|
621
|
+
type SwiperLike = new (
|
|
622
|
+
element: HTMLElement,
|
|
623
|
+
options: Record<string, unknown>,
|
|
624
|
+
) => { destroy?: (deleteInstance?: boolean, cleanStyles?: boolean) => void };
|
|
625
|
+
|
|
626
|
+
const SWIPER_PACKAGE = "swiper";
|
|
627
|
+
const SWIPER_MODULES_PACKAGE = "swiper/modules";
|
|
628
|
+
const MISSING_PACKAGE = "resux-missing-package-demo";
|
|
629
|
+
|
|
630
|
+
function setEnhancementStatus(target: Element, status: PackageStatus, detail = "") {
|
|
631
|
+
const root = target.closest("[data-rx-package-demo]") || target;
|
|
632
|
+
if (!root || typeof (root as Element).querySelector !== "function") {
|
|
633
|
+
return;
|
|
634
|
+
}
|
|
635
|
+
const statusNode = (root as Element).querySelector("[data-rx-package-status]");
|
|
636
|
+
if (statusNode) {
|
|
637
|
+
statusNode.textContent = detail ? status + ": " + detail : status;
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
function toMessage(error: unknown): string {
|
|
642
|
+
return error instanceof Error ? error.message : String(error);
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
function readSwiperOptions(target: Element): Record<string, unknown> {
|
|
646
|
+
const raw = target.getAttribute("data-swiper-options");
|
|
647
|
+
if (!raw) {
|
|
648
|
+
return {};
|
|
649
|
+
}
|
|
650
|
+
try {
|
|
651
|
+
const parsed = JSON.parse(raw) as unknown;
|
|
652
|
+
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
653
|
+
return parsed as Record<string, unknown>;
|
|
654
|
+
}
|
|
655
|
+
} catch {
|
|
656
|
+
// Ignore invalid JSON and use defaults.
|
|
657
|
+
}
|
|
658
|
+
return {};
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
defineClientEnhancement("swiper-carousel", async (target) => {
|
|
662
|
+
setEnhancementStatus(target, "loading");
|
|
663
|
+
try {
|
|
664
|
+
const [Swiper, modules] = await Promise.all([
|
|
665
|
+
useClientPackage<SwiperLike>(SWIPER_PACKAGE, {
|
|
666
|
+
css: ["swiper/css", "swiper/css/navigation", "swiper/css/pagination"],
|
|
667
|
+
}),
|
|
668
|
+
useClientPackage<Record<string, unknown>>(SWIPER_MODULES_PACKAGE, {
|
|
669
|
+
preferDefault: false,
|
|
670
|
+
}),
|
|
671
|
+
]);
|
|
672
|
+
const carousel = target.querySelector(".swiper");
|
|
673
|
+
if (!carousel) {
|
|
674
|
+
setEnhancementStatus(target, "error", "Missing .swiper element");
|
|
675
|
+
return;
|
|
676
|
+
}
|
|
677
|
+
const instance = new Swiper(carousel as HTMLElement, {
|
|
678
|
+
modules: [modules.Navigation, modules.Pagination].filter(Boolean),
|
|
679
|
+
slidesPerView: 1,
|
|
680
|
+
spaceBetween: 16,
|
|
681
|
+
breakpoints: {
|
|
682
|
+
640: { slidesPerView: 1.2, spaceBetween: 16 },
|
|
683
|
+
768: { slidesPerView: 2, spaceBetween: 20 },
|
|
684
|
+
1024: { slidesPerView: 3, spaceBetween: 24 },
|
|
685
|
+
1280: { slidesPerView: 4, spaceBetween: 24 },
|
|
686
|
+
},
|
|
687
|
+
navigation: {
|
|
688
|
+
nextEl: target.querySelector("[data-rx-next]") as HTMLElement | null,
|
|
689
|
+
prevEl: target.querySelector("[data-rx-prev]") as HTMLElement | null,
|
|
690
|
+
},
|
|
691
|
+
pagination: {
|
|
692
|
+
el: target.querySelector("[data-rx-pagination]") as HTMLElement | null,
|
|
693
|
+
clickable: true,
|
|
694
|
+
},
|
|
695
|
+
...readSwiperOptions(target),
|
|
696
|
+
});
|
|
697
|
+
setEnhancementStatus(target, "ready");
|
|
698
|
+
return () => {
|
|
699
|
+
instance.destroy?.(true, true);
|
|
700
|
+
setEnhancementStatus(target, "disposed");
|
|
701
|
+
};
|
|
702
|
+
} catch (error) {
|
|
703
|
+
setEnhancementStatus(target, "error", toMessage(error));
|
|
704
|
+
}
|
|
705
|
+
});
|
|
706
|
+
|
|
707
|
+
for (const name of ["chart-demo", "animation-demo", "video-player-demo", "markdown-demo", "css-package-demo"]) {
|
|
708
|
+
defineClientEnhancement(name, async (target) => {
|
|
709
|
+
setEnhancementStatus(target, "ready", "Client enhancement active");
|
|
710
|
+
});
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
defineClientEnhancement("missing-package-demo", async (target) => {
|
|
714
|
+
setEnhancementStatus(target, "loading");
|
|
715
|
+
try {
|
|
716
|
+
await useClientPackage(MISSING_PACKAGE);
|
|
717
|
+
setEnhancementStatus(target, "ready");
|
|
718
|
+
} catch (error) {
|
|
719
|
+
setEnhancementStatus(target, "error", toMessage(error));
|
|
720
|
+
}
|
|
721
|
+
});
|
|
722
|
+
`);
|
|
723
|
+
await ensureFile(path.join(pagesRoot, "index.vue"), `<script setup lang="ts">
|
|
724
|
+
useSeoMeta({
|
|
725
|
+
title: "Resux Package Compatibility Demos",
|
|
726
|
+
description: "SSR-first npm package demos with client enhancements and resumability-safe patterns.",
|
|
727
|
+
})
|
|
728
|
+
</script>
|
|
729
|
+
|
|
730
|
+
<template>
|
|
731
|
+
<main class="page">
|
|
732
|
+
<h1>Package compatibility demos</h1>
|
|
733
|
+
<p>Each page renders semantic SSR HTML first, then applies browser-only enhancement without hydration.</p>
|
|
734
|
+
<ul>
|
|
735
|
+
<li><ResuxLink to="/package-tests/swiper">Swiper</ResuxLink></li>
|
|
736
|
+
<li><ResuxLink to="/package-tests/chart">Chart</ResuxLink></li>
|
|
737
|
+
<li><ResuxLink to="/package-tests/animation">Animation</ResuxLink></li>
|
|
738
|
+
<li><ResuxLink to="/package-tests/video-player">Video player</ResuxLink></li>
|
|
739
|
+
<li><ResuxLink to="/package-tests/markdown">Markdown</ResuxLink></li>
|
|
740
|
+
<li><ResuxLink to="/package-tests/utility">Utility</ResuxLink></li>
|
|
741
|
+
<li><ResuxLink to="/package-tests/css-package">CSS package</ResuxLink></li>
|
|
742
|
+
<li><ResuxLink to="/package-tests/missing-package">Missing package</ResuxLink></li>
|
|
743
|
+
</ul>
|
|
744
|
+
</main>
|
|
745
|
+
</template>
|
|
746
|
+
`);
|
|
747
|
+
const examples = [
|
|
748
|
+
{ file: "swiper.vue", title: "Swiper", enhancement: "swiper-carousel" },
|
|
749
|
+
{ file: "chart.vue", title: "Chart", enhancement: "chart-demo" },
|
|
750
|
+
{ file: "animation.vue", title: "Animation", enhancement: "animation-demo" },
|
|
751
|
+
{ file: "video-player.vue", title: "Video player", enhancement: "video-player-demo" },
|
|
752
|
+
{ file: "markdown.vue", title: "Markdown", enhancement: "markdown-demo" },
|
|
753
|
+
{ file: "utility.vue", title: "Utility" },
|
|
754
|
+
{ file: "css-package.vue", title: "CSS package", enhancement: "css-package-demo" },
|
|
755
|
+
{ file: "missing-package.vue", title: "Missing package", enhancement: "missing-package-demo" },
|
|
756
|
+
];
|
|
757
|
+
for (const example of examples) {
|
|
758
|
+
await ensureFile(path.join(pagesRoot, example.file), `<script setup lang="ts">
|
|
759
|
+
useSeoMeta({
|
|
760
|
+
title: "Resux ${example.title} Package Demo",
|
|
761
|
+
description: "SSR-first ${example.title.toLowerCase()} compatibility demo with progressive enhancement.",
|
|
762
|
+
ogTitle: "Resux ${example.title} Demo",
|
|
763
|
+
})
|
|
764
|
+
</script>
|
|
765
|
+
|
|
766
|
+
<template>
|
|
767
|
+
<main class="page">
|
|
768
|
+
<h1>${example.title} package demo</h1>
|
|
769
|
+
<p>Semantic HTML is rendered on the server before any package code runs.</p>
|
|
770
|
+
<section class="panel" data-rx-package-demo="true"${example.enhancement ? `
|
|
771
|
+
use-client-enhancement="${example.enhancement}"
|
|
772
|
+
data-trigger="visible"` : ""}>
|
|
773
|
+
<p data-rx-package-status>idle</p>
|
|
774
|
+
<ul>
|
|
775
|
+
<li>SSR content remains visible without JavaScript.</li>
|
|
776
|
+
<li>Enhancement is isolated to client runtime only.</li>
|
|
777
|
+
</ul>
|
|
778
|
+
<div class="swiper"${example.enhancement === "swiper-carousel" ? "" : " style=\"display:none\""}>
|
|
779
|
+
<div class="swiper-wrapper">
|
|
780
|
+
<article class="swiper-slide"><h2>Item 1</h2><p>SSR card content.</p><a href="/package-tests">Read more</a></article>
|
|
781
|
+
<article class="swiper-slide"><h2>Item 2</h2><p>SSR card content.</p><a href="/package-tests">Read more</a></article>
|
|
782
|
+
<article class="swiper-slide"><h2>Item 3</h2><p>SSR card content.</p><a href="/package-tests">Read more</a></article>
|
|
783
|
+
<article class="swiper-slide"><h2>Item 4</h2><p>SSR card content.</p><a href="/package-tests">Read more</a></article>
|
|
784
|
+
</div>
|
|
785
|
+
</div>
|
|
786
|
+
${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>' : ''}
|
|
787
|
+
</section>
|
|
788
|
+
</main>
|
|
789
|
+
</template>
|
|
790
|
+
`);
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
async function ensureFile(filePath, contents) {
|
|
794
|
+
if (await pathExists(filePath)) {
|
|
795
|
+
return;
|
|
796
|
+
}
|
|
797
|
+
await mkdir(path.dirname(filePath), { recursive: true });
|
|
798
|
+
await writeFile(filePath, contents, "utf8");
|
|
799
|
+
}
|
|
800
|
+
async function pathExists(filePath) {
|
|
801
|
+
try {
|
|
802
|
+
await readFile(filePath, "utf8");
|
|
803
|
+
return true;
|
|
804
|
+
}
|
|
805
|
+
catch {
|
|
806
|
+
return false;
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
function createStarterResuxConfig(title, features, options) {
|
|
810
|
+
const modules = [
|
|
811
|
+
`"resux:security"`,
|
|
812
|
+
`"resux:performance"`,
|
|
813
|
+
...(features.has("i18n") ? [`"resuxjs/i18n"`] : [])
|
|
814
|
+
];
|
|
815
|
+
const headLinks = [
|
|
816
|
+
...(features.has("tailwind") ? [`{ rel: "stylesheet", href: "/tailwind.css" }`] : []),
|
|
817
|
+
`{ rel: "stylesheet", href: "/styles.css" }`,
|
|
818
|
+
...(features.has("pwa") ? [`{ rel: "manifest", href: "/manifest.webmanifest" }`] : [])
|
|
819
|
+
];
|
|
820
|
+
const headMeta = features.has("pwa")
|
|
821
|
+
? `,
|
|
822
|
+
meta: [
|
|
823
|
+
{ name: "theme-color", content: "#0f172a" },
|
|
824
|
+
{ name: "application-name", content: ${JSON.stringify(title)} }
|
|
825
|
+
]`
|
|
826
|
+
: "";
|
|
827
|
+
const i18nBlock = features.has("i18n")
|
|
828
|
+
? `,
|
|
829
|
+
i18n: {
|
|
830
|
+
defaultLocale: "en",
|
|
831
|
+
fallbackLocale: "en",
|
|
832
|
+
strategy: "prefix_except_default",
|
|
833
|
+
locales: [
|
|
834
|
+
{ code: "en", name: "English", dir: "ltr" },
|
|
835
|
+
{ code: "ar", name: "العربية", dir: "rtl" }
|
|
836
|
+
],
|
|
837
|
+
messages: {
|
|
838
|
+
en: () => import("./locales/en.json"),
|
|
839
|
+
ar: () => import("./locales/ar.json")
|
|
840
|
+
},
|
|
841
|
+
seo: {
|
|
842
|
+
hreflang: ${options.hreflang ? "true" : "false"}
|
|
843
|
+
}
|
|
844
|
+
}`
|
|
845
|
+
: "";
|
|
846
|
+
const packageBlock = features.has("package-compatibility")
|
|
847
|
+
? `,
|
|
848
|
+
packages: {
|
|
849
|
+
mode: {
|
|
850
|
+
"swiper": "progressive",
|
|
851
|
+
"chart.js": "progressive",
|
|
852
|
+
"gsap": "clientOnly",
|
|
853
|
+
"plyr": "progressive",
|
|
854
|
+
"marked": "ssr",
|
|
855
|
+
"date-fns": "ssr",
|
|
856
|
+
"highlight.js": "progressive"
|
|
857
|
+
}
|
|
858
|
+
}`
|
|
859
|
+
: "";
|
|
860
|
+
return `export default defineResuxConfig({
|
|
861
|
+
deploy: {
|
|
862
|
+
target: "auto"
|
|
863
|
+
},
|
|
864
|
+
modules: [
|
|
865
|
+
${modules.join(",\n ")}
|
|
866
|
+
],
|
|
867
|
+
app: {
|
|
868
|
+
head: {
|
|
869
|
+
link: [
|
|
870
|
+
${headLinks.join(",\n ")}
|
|
871
|
+
]${headMeta}
|
|
872
|
+
}
|
|
873
|
+
},
|
|
874
|
+
runtimeConfig: {
|
|
875
|
+
public: {
|
|
876
|
+
appName: ${JSON.stringify(title)}
|
|
877
|
+
}
|
|
878
|
+
}${packageBlock}${i18nBlock}
|
|
879
|
+
})
|
|
880
|
+
`;
|
|
881
|
+
}
|
|
882
|
+
async function removeSeoFromPage(filePath) {
|
|
883
|
+
const source = await readFile(filePath, "utf8");
|
|
884
|
+
const withoutSeo = source.replace(/\nuseSeoMeta\(\{[\s\S]*?\}\)\n/g, "\n");
|
|
885
|
+
await writeFile(filePath, withoutSeo, "utf8");
|
|
886
|
+
}
|
|
887
|
+
async function scaffoldI18nFiles(root) {
|
|
888
|
+
const localesDir = path.join(root, "locales");
|
|
889
|
+
await mkdir(localesDir, { recursive: true });
|
|
890
|
+
await writeFile(path.join(localesDir, "en.json"), `${JSON.stringify({
|
|
891
|
+
demo: {
|
|
892
|
+
badge: "I18n demo",
|
|
893
|
+
title: "Localized starter",
|
|
894
|
+
subtitle: "Switch locale prefixes and translate strings without hydration.",
|
|
895
|
+
currentLocale: "Current locale: {locale}",
|
|
896
|
+
currentDir: "Direction: {dir}",
|
|
897
|
+
welcome: "Welcome, {name}!"
|
|
898
|
+
}
|
|
899
|
+
}, null, 2)}\n`, "utf8");
|
|
900
|
+
await writeFile(path.join(localesDir, "ar.json"), `${JSON.stringify({
|
|
901
|
+
demo: {
|
|
902
|
+
badge: "عرض الترجمة",
|
|
903
|
+
title: "مشروع مترجم",
|
|
904
|
+
subtitle: "بدل اللغات والمسارات بدون ترطيب.",
|
|
905
|
+
currentLocale: "اللغة الحالية: {locale}",
|
|
906
|
+
currentDir: "الاتجاه: {dir}",
|
|
907
|
+
welcome: "مرحبًا {name}!"
|
|
908
|
+
}
|
|
909
|
+
}, null, 2)}\n`, "utf8");
|
|
910
|
+
await writeFile(path.join(root, "pages", "i18n.vue"), `<script setup lang="ts">
|
|
911
|
+
import { useI18n } from "resuxjs/i18n"
|
|
912
|
+
|
|
913
|
+
definePageMeta({
|
|
914
|
+
title: {
|
|
915
|
+
en: "I18n",
|
|
916
|
+
ar: "الترجمة"
|
|
917
|
+
}
|
|
918
|
+
})
|
|
919
|
+
|
|
920
|
+
const i18n = useI18n()
|
|
921
|
+
</script>
|
|
922
|
+
|
|
923
|
+
<template>
|
|
924
|
+
<main class="page narrow">
|
|
925
|
+
<p class="eyebrow">{{ i18n.t("demo.badge") }}</p>
|
|
926
|
+
<h1>{{ i18n.t("demo.title") }}</h1>
|
|
927
|
+
<p class="lede">{{ i18n.t("demo.subtitle") }}</p>
|
|
928
|
+
<p>{{ i18n.t("demo.currentLocale", { locale: i18n.locale.value }) }}</p>
|
|
929
|
+
<p>{{ i18n.t("demo.currentDir", { dir: i18n.dir.value }) }}</p>
|
|
930
|
+
<p>{{ i18n.t("demo.welcome", { name: "Resux" }) }}</p>
|
|
931
|
+
<div class="actions">
|
|
932
|
+
<ResuxLink :to="i18n.switchLocalePath('en')">English</ResuxLink>
|
|
933
|
+
<ResuxLink :to="i18n.switchLocalePath('ar')">العربية</ResuxLink>
|
|
934
|
+
</div>
|
|
935
|
+
</main>
|
|
936
|
+
</template>
|
|
937
|
+
`, "utf8");
|
|
938
|
+
}
|
|
939
|
+
async function scaffoldMediaPage(root) {
|
|
940
|
+
await writeFile(path.join(root, "pages", "media.vue"), `<script setup lang="ts">
|
|
941
|
+
definePageMeta({
|
|
942
|
+
title: "Media"
|
|
943
|
+
})
|
|
944
|
+
</script>
|
|
945
|
+
|
|
946
|
+
<template>
|
|
947
|
+
<main class="page">
|
|
948
|
+
<p class="eyebrow">Media</p>
|
|
949
|
+
<h1>Responsive media components</h1>
|
|
950
|
+
<p class="lede">This route validates Resux media rendering with SSR + resumable handlers.</p>
|
|
951
|
+
|
|
952
|
+
<section class="stats-grid">
|
|
953
|
+
<article class="stat">
|
|
954
|
+
<span>ResuxImg</span>
|
|
955
|
+
<ResuxImg
|
|
956
|
+
src="/resux-placeholder.svg"
|
|
957
|
+
alt="Resux placeholder"
|
|
958
|
+
width="256"
|
|
959
|
+
height="256"
|
|
960
|
+
format="webp"
|
|
961
|
+
quality="82"
|
|
962
|
+
sizes="(min-width: 768px) 30vw, 80vw"
|
|
963
|
+
preload
|
|
964
|
+
priority
|
|
965
|
+
/>
|
|
966
|
+
</article>
|
|
967
|
+
<article class="stat">
|
|
968
|
+
<span>ResuxPicture</span>
|
|
969
|
+
<ResuxPicture
|
|
970
|
+
src="/resux-placeholder.svg"
|
|
971
|
+
alt="Resux placeholder picture"
|
|
972
|
+
widths="240,360,480"
|
|
973
|
+
formats="avif,webp,png"
|
|
974
|
+
sizes="(min-width: 768px) 30vw, 80vw"
|
|
975
|
+
/>
|
|
976
|
+
</article>
|
|
977
|
+
</section>
|
|
978
|
+
</main>
|
|
979
|
+
</template>
|
|
980
|
+
`, "utf8");
|
|
981
|
+
}
|
|
982
|
+
async function scaffoldPwaFiles(root, title) {
|
|
983
|
+
await writeFile(path.join(root, "public", "manifest.webmanifest"), `${JSON.stringify({
|
|
984
|
+
name: title,
|
|
985
|
+
short_name: title.replace(/\s+/g, " ").slice(0, 12),
|
|
986
|
+
start_url: "/",
|
|
987
|
+
display: "standalone",
|
|
988
|
+
background_color: "#020617",
|
|
989
|
+
theme_color: "#0f172a",
|
|
990
|
+
icons: [
|
|
991
|
+
{
|
|
992
|
+
src: "/resux-placeholder.svg",
|
|
993
|
+
sizes: "96x96",
|
|
994
|
+
type: "image/svg+xml",
|
|
995
|
+
purpose: "any"
|
|
996
|
+
}
|
|
997
|
+
]
|
|
998
|
+
}, null, 2)}\n`, "utf8");
|
|
999
|
+
await writeFile(path.join(root, "public", "sw.js"), `self.addEventListener("install", () => self.skipWaiting())
|
|
1000
|
+
self.addEventListener("activate", (event) => {
|
|
1001
|
+
event.waitUntil(self.clients.claim())
|
|
1002
|
+
})
|
|
1003
|
+
`, "utf8");
|
|
1004
|
+
}
|
|
1005
|
+
async function extendDefaultLayoutNavigation(root, features) {
|
|
1006
|
+
const layoutPath = path.join(root, "layouts", "default.vue");
|
|
1007
|
+
const source = await readFile(layoutPath, "utf8");
|
|
1008
|
+
const additions = [
|
|
1009
|
+
...(features.has("i18n") ? [' <ResuxLink to="/i18n">I18n</ResuxLink>'] : []),
|
|
1010
|
+
...(features.has("media") ? [' <ResuxLink to="/media">Media</ResuxLink>'] : [])
|
|
1011
|
+
];
|
|
1012
|
+
if (!additions.length) {
|
|
1013
|
+
return;
|
|
1014
|
+
}
|
|
1015
|
+
const marker = " </nav>";
|
|
1016
|
+
const next = source.includes(marker)
|
|
1017
|
+
? source.replace(marker, `${additions.join("\n")}\n${marker}`)
|
|
1018
|
+
: source;
|
|
1019
|
+
await writeFile(layoutPath, next, "utf8");
|
|
1020
|
+
}
|
|
1021
|
+
async function annotateStarterReadme(root, features) {
|
|
1022
|
+
if (!features.size) {
|
|
1023
|
+
return;
|
|
1024
|
+
}
|
|
1025
|
+
const readmePath = path.join(root, "README.md");
|
|
1026
|
+
const source = await readFile(readmePath, "utf8");
|
|
1027
|
+
const featureList = [...features].map((feature) => `- ${feature}`).join("\n");
|
|
1028
|
+
const next = `${source.trimEnd()}\n\n## Optional Features\n\n${featureList}\n`;
|
|
1029
|
+
await writeFile(readmePath, next, "utf8");
|
|
1030
|
+
}
|
|
183
1031
|
async function installDependencies(root, packageManager) {
|
|
184
1032
|
await new Promise((resolve, reject) => {
|
|
185
1033
|
const child = spawn(packageManager, ["install"], {
|
|
@@ -202,6 +1050,7 @@ function printNextSteps(options) {
|
|
|
202
1050
|
const relative = path.relative(process.cwd(), options.root) || ".";
|
|
203
1051
|
const cdTarget = formatShellPath(relative);
|
|
204
1052
|
console.log(`\nCreated Resux app in ${options.root}`);
|
|
1053
|
+
console.log(`Template: ${options.template}`);
|
|
205
1054
|
console.log("\nNext steps:");
|
|
206
1055
|
if (cdTarget !== ".") {
|
|
207
1056
|
console.log(` cd ${cdTarget}`);
|
|
@@ -210,6 +1059,9 @@ function printNextSteps(options) {
|
|
|
210
1059
|
console.log(` ${options.packageManager} install`);
|
|
211
1060
|
}
|
|
212
1061
|
console.log(` ${runCommand(options.packageManager, "dev")}`);
|
|
1062
|
+
if (options.features.length > 0) {
|
|
1063
|
+
console.log(`\nSelected optional features: ${options.features.join(", ")}`);
|
|
1064
|
+
}
|
|
213
1065
|
}
|
|
214
1066
|
function runCommand(packageManager, script) {
|
|
215
1067
|
if (packageManager === "npm") {
|
|
@@ -262,19 +1114,23 @@ function isMainModule() {
|
|
|
262
1114
|
return process.argv[1] ? path.resolve(process.argv[1]) === fileURLToPath(import.meta.url) : false;
|
|
263
1115
|
}
|
|
264
1116
|
function printHelp() {
|
|
265
|
-
console.log(`resux init
|
|
266
|
-
|
|
267
|
-
Usage:
|
|
268
|
-
npx resuxjs@latest init [project-dir] [options]
|
|
269
|
-
resux init [project-dir] [options]
|
|
270
|
-
|
|
271
|
-
Options:
|
|
272
|
-
--install Install dependencies after scaffolding
|
|
273
|
-
--no-install Skip dependency installation
|
|
274
|
-
--
|
|
275
|
-
--
|
|
276
|
-
|
|
277
|
-
-
|
|
1117
|
+
console.log(`resux init
|
|
1118
|
+
|
|
1119
|
+
Usage:
|
|
1120
|
+
npx resuxjs@latest init [project-dir] [options]
|
|
1121
|
+
resux init [project-dir] [options]
|
|
1122
|
+
|
|
1123
|
+
Options:
|
|
1124
|
+
--install Install dependencies after scaffolding
|
|
1125
|
+
--no-install Skip dependency installation
|
|
1126
|
+
--template <name> Starter template (minimal,default,full,i18n,pwa,media,package-compatibility,dashboard)
|
|
1127
|
+
--features <list> Comma-separated optional starter features (seo,i18n,media,pwa,tailwind,package-compatibility,server-api,tests)
|
|
1128
|
+
--hreflang Enable i18n hreflang alternate links in generated config
|
|
1129
|
+
--no-hreflang Disable i18n hreflang alternate links in generated config
|
|
1130
|
+
--package-manager <pm> Use npm, pnpm, yarn, or bun for next steps
|
|
1131
|
+
--force Empty the target directory before scaffolding
|
|
1132
|
+
-y, --yes Use default answers
|
|
1133
|
+
-h, --help Show this help message
|
|
278
1134
|
`);
|
|
279
1135
|
}
|
|
280
1136
|
//# sourceMappingURL=create.js.map
|