@diviswap/sdk 1.7.27 → 1.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +73 -82
- package/bin/create-diviswap-app.js +5 -5
- package/dist/cli/index.js +438 -185
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +302 -178
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +302 -178
- package/dist/index.mjs.map +1 -1
- package/dist/react/index.d.mts +2 -2
- package/dist/react/index.d.ts +2 -2
- package/dist/react/index.js +260 -183
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +260 -183
- package/dist/react/index.mjs.map +1 -1
- package/dist/{wallet-DZymADRo.d.mts → wallet-Ca1U51kT.d.mts} +1 -1
- package/dist/{wallet-DZymADRo.d.ts → wallet-Ca1U51kT.d.ts} +1 -1
- package/package.json +98 -97
- package/src/cli/templates/index.ts +86 -54
- package/src/cli/templates/shared/client.ts +65 -65
package/dist/cli/index.js
CHANGED
|
@@ -129,12 +129,42 @@ function getTemplate(templateName, data) {
|
|
|
129
129
|
const possiblePaths = [
|
|
130
130
|
// Development paths - try different extensions
|
|
131
131
|
path.join(packageRoot, "src", "cli", "templates", `${templateName}.hbs`),
|
|
132
|
-
path.join(
|
|
133
|
-
|
|
132
|
+
path.join(
|
|
133
|
+
packageRoot,
|
|
134
|
+
"src",
|
|
135
|
+
"cli",
|
|
136
|
+
"templates",
|
|
137
|
+
`${templateName}.ts.hbs`
|
|
138
|
+
),
|
|
139
|
+
path.join(
|
|
140
|
+
packageRoot,
|
|
141
|
+
"src",
|
|
142
|
+
"cli",
|
|
143
|
+
"templates",
|
|
144
|
+
`${templateName}.tsx.hbs`
|
|
145
|
+
),
|
|
134
146
|
// Production paths - try different extensions
|
|
135
|
-
path.join(
|
|
136
|
-
|
|
137
|
-
|
|
147
|
+
path.join(
|
|
148
|
+
packageRoot,
|
|
149
|
+
"dist",
|
|
150
|
+
"cli",
|
|
151
|
+
"templates",
|
|
152
|
+
`${templateName}.hbs`
|
|
153
|
+
),
|
|
154
|
+
path.join(
|
|
155
|
+
packageRoot,
|
|
156
|
+
"dist",
|
|
157
|
+
"cli",
|
|
158
|
+
"templates",
|
|
159
|
+
`${templateName}.ts.hbs`
|
|
160
|
+
),
|
|
161
|
+
path.join(
|
|
162
|
+
packageRoot,
|
|
163
|
+
"dist",
|
|
164
|
+
"cli",
|
|
165
|
+
"templates",
|
|
166
|
+
`${templateName}.tsx.hbs`
|
|
167
|
+
)
|
|
138
168
|
];
|
|
139
169
|
let templateSource = null;
|
|
140
170
|
for (const path of possiblePaths) {
|
|
@@ -160,7 +190,9 @@ function getTemplate(templateName, data) {
|
|
|
160
190
|
return template(data);
|
|
161
191
|
}
|
|
162
192
|
function getInlineTemplateSource(templateName) {
|
|
163
|
-
console.warn(
|
|
193
|
+
console.warn(
|
|
194
|
+
`Template ${templateName} not found in filesystem, returning empty template`
|
|
195
|
+
);
|
|
164
196
|
return "// Template not found";
|
|
165
197
|
}
|
|
166
198
|
|
|
@@ -233,7 +265,10 @@ async function generateNextjsAppFiles(ensureFile, features, projectRoot) {
|
|
|
233
265
|
);
|
|
234
266
|
ensureFile(
|
|
235
267
|
`${prefix}hooks/useDiviswapData.ts`,
|
|
236
|
-
getTemplate("nextjs-app/dashboard-hooks", {
|
|
268
|
+
getTemplate("nextjs-app/dashboard-hooks", {
|
|
269
|
+
features,
|
|
270
|
+
prefix: "Diviswap"
|
|
271
|
+
})
|
|
237
272
|
);
|
|
238
273
|
ensureFile(
|
|
239
274
|
`${prefix}hooks/useDiviswapKYC.ts`,
|
|
@@ -276,7 +311,7 @@ async function generateNextjsPagesFiles(ensureFile, features, projectRoot) {
|
|
|
276
311
|
getTemplate("nextjs-pages/client", { features })
|
|
277
312
|
);
|
|
278
313
|
}
|
|
279
|
-
async function generateReactFiles(ensureFile, features,
|
|
314
|
+
async function generateReactFiles(ensureFile, features, _projectRoot) {
|
|
280
315
|
ensureFile(
|
|
281
316
|
"src/diviswap/api-client.ts",
|
|
282
317
|
getTemplate("react/api-client-wrapper", { features })
|
|
@@ -384,7 +419,7 @@ function httpsRequest(url, options) {
|
|
|
384
419
|
}
|
|
385
420
|
async function validatePartnerCredentials(keyId, secretKey, authMethod = "hmac", environment = "sandbox") {
|
|
386
421
|
try {
|
|
387
|
-
const apiUrl =
|
|
422
|
+
const apiUrl = "https://api.diviswap.com";
|
|
388
423
|
const testPath = "/api/v1/fees";
|
|
389
424
|
const method = "POST";
|
|
390
425
|
const body = "{}";
|
|
@@ -393,7 +428,14 @@ async function validatePartnerCredentials(keyId, secretKey, authMethod = "hmac",
|
|
|
393
428
|
"X-Client-Id": keyId
|
|
394
429
|
};
|
|
395
430
|
if (authMethod === "hmac") {
|
|
396
|
-
const hmacHeaders = generateHMACHeaders(
|
|
431
|
+
const hmacHeaders = generateHMACHeaders(
|
|
432
|
+
method,
|
|
433
|
+
testPath,
|
|
434
|
+
"",
|
|
435
|
+
body,
|
|
436
|
+
keyId,
|
|
437
|
+
secretKey
|
|
438
|
+
);
|
|
397
439
|
headers = { ...headers, ...hmacHeaders };
|
|
398
440
|
} else {
|
|
399
441
|
const jwt = generateJWT(keyId, secretKey);
|
|
@@ -462,7 +504,7 @@ ${timestamp}
|
|
|
462
504
|
${nonce}`;
|
|
463
505
|
const signature = crypto__default.default.createHmac("sha256", secretKey).update(canonical).digest("base64");
|
|
464
506
|
return {
|
|
465
|
-
|
|
507
|
+
Authorization: `HMAC ${keyId}:${signature}:${timestamp}:${nonce}`
|
|
466
508
|
};
|
|
467
509
|
}
|
|
468
510
|
function generateJWT(keyId, secretKey, expiresIn = 300) {
|
|
@@ -470,12 +512,16 @@ function generateJWT(keyId, secretKey, expiresIn = 300) {
|
|
|
470
512
|
const now = Math.floor(Date.now() / 1e3);
|
|
471
513
|
const payload = {
|
|
472
514
|
iss: keyId,
|
|
473
|
-
aud: "api.
|
|
515
|
+
aud: "api.diviswap.com",
|
|
474
516
|
exp: now + Math.min(expiresIn, 300),
|
|
475
517
|
iat: now
|
|
476
518
|
};
|
|
477
|
-
const encodedHeader = Buffer.from(JSON.stringify(header)).toString(
|
|
478
|
-
|
|
519
|
+
const encodedHeader = Buffer.from(JSON.stringify(header)).toString(
|
|
520
|
+
"base64url"
|
|
521
|
+
);
|
|
522
|
+
const encodedPayload = Buffer.from(JSON.stringify(payload)).toString(
|
|
523
|
+
"base64url"
|
|
524
|
+
);
|
|
479
525
|
const signature = crypto__default.default.createHmac("sha256", secretKey).update(`${encodedHeader}.${encodedPayload}`).digest("base64url");
|
|
480
526
|
return `${encodedHeader}.${encodedPayload}.${signature}`;
|
|
481
527
|
}
|
|
@@ -498,7 +544,7 @@ var frameworkFiles = {
|
|
|
498
544
|
"lib/diviswap/hooks.ts",
|
|
499
545
|
"lib/diviswap/client.ts"
|
|
500
546
|
],
|
|
501
|
-
|
|
547
|
+
react: [
|
|
502
548
|
"src/diviswap/provider.tsx",
|
|
503
549
|
"src/diviswap/hooks.ts",
|
|
504
550
|
"src/diviswap/client.ts",
|
|
@@ -507,7 +553,7 @@ var frameworkFiles = {
|
|
|
507
553
|
"src/diviswap/example.tsx",
|
|
508
554
|
"src/diviswap/types.ts"
|
|
509
555
|
],
|
|
510
|
-
|
|
556
|
+
vue3: [
|
|
511
557
|
"src/plugins/diviswap.ts",
|
|
512
558
|
"src/composables/useDiviswap.ts",
|
|
513
559
|
"src/components/DiviswapProvider.vue",
|
|
@@ -516,7 +562,7 @@ var frameworkFiles = {
|
|
|
516
562
|
"src/views/DiviswapExample.vue",
|
|
517
563
|
"src/diviswap/types.ts"
|
|
518
564
|
],
|
|
519
|
-
|
|
565
|
+
vanilla: [
|
|
520
566
|
"diviswap/client.js",
|
|
521
567
|
"diviswap/example.html",
|
|
522
568
|
"diviswap/example.js",
|
|
@@ -560,7 +606,7 @@ function updateNextConfig(projectRoot) {
|
|
|
560
606
|
if (content.includes("env:")) {
|
|
561
607
|
updatedContent = content.replace(
|
|
562
608
|
/env:\s*{([^}]*)}/,
|
|
563
|
-
(
|
|
609
|
+
(_match, existingVars) => {
|
|
564
610
|
const needsComma = existingVars.trim().length > 0 && !existingVars.trim().endsWith(",");
|
|
565
611
|
return `env: {${existingVars}${needsComma ? "," : ""}${diviswapEnvVars}
|
|
566
612
|
}`;
|
|
@@ -621,7 +667,10 @@ async function init(options) {
|
|
|
621
667
|
message: "What framework are you using?",
|
|
622
668
|
choices: [
|
|
623
669
|
{ title: "Next.js (App Router)", value: "nextjs-app" },
|
|
624
|
-
{
|
|
670
|
+
{
|
|
671
|
+
title: "Next.js (Pages Router)",
|
|
672
|
+
value: "nextjs-pages"
|
|
673
|
+
},
|
|
625
674
|
{ title: "React", value: "react" },
|
|
626
675
|
{ title: "Vue 3", value: "vue3" },
|
|
627
676
|
{ title: "Vanilla JavaScript", value: "vanilla" },
|
|
@@ -631,6 +680,10 @@ async function init(options) {
|
|
|
631
680
|
framework = response2.selectedFramework;
|
|
632
681
|
}
|
|
633
682
|
}
|
|
683
|
+
if (!framework) {
|
|
684
|
+
console.log(kleur__default.default.yellow("\nNo framework selected. Aborting setup."));
|
|
685
|
+
process.exit(1);
|
|
686
|
+
}
|
|
634
687
|
let environment = options.env || "sandbox";
|
|
635
688
|
if (!options.skipEnv && !options.env) {
|
|
636
689
|
const envResponse = await prompts__default.default({
|
|
@@ -638,8 +691,16 @@ async function init(options) {
|
|
|
638
691
|
name: "environment",
|
|
639
692
|
message: "Which environment are you using?",
|
|
640
693
|
choices: [
|
|
641
|
-
{
|
|
642
|
-
|
|
694
|
+
{
|
|
695
|
+
title: "Production",
|
|
696
|
+
value: "production",
|
|
697
|
+
description: "Live environment for real transactions"
|
|
698
|
+
},
|
|
699
|
+
{
|
|
700
|
+
title: "Sandbox",
|
|
701
|
+
value: "sandbox",
|
|
702
|
+
description: "Testing environment with simulated transactions (uses sandbox credentials)"
|
|
703
|
+
}
|
|
643
704
|
],
|
|
644
705
|
initial: 1
|
|
645
706
|
// Default to sandbox for safety
|
|
@@ -650,8 +711,12 @@ async function init(options) {
|
|
|
650
711
|
let secretKey;
|
|
651
712
|
let authMethod = "hmac";
|
|
652
713
|
if (!options.skipEnv) {
|
|
653
|
-
console.log(
|
|
654
|
-
|
|
714
|
+
console.log(
|
|
715
|
+
kleur__default.default.yellow("\n\u{1F4DD} Partner Authentication Credentials\n")
|
|
716
|
+
);
|
|
717
|
+
console.log(
|
|
718
|
+
"Partner credentials are provided by Diviswap after approval."
|
|
719
|
+
);
|
|
655
720
|
console.log("Contact Diviswap support if you need partner access.");
|
|
656
721
|
const authMethodResponse = await prompts__default.default({
|
|
657
722
|
type: "select",
|
|
@@ -704,9 +769,20 @@ async function init(options) {
|
|
|
704
769
|
]);
|
|
705
770
|
keyId = partnerCredentials.keyId;
|
|
706
771
|
secretKey = partnerCredentials.secretKey;
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
772
|
+
if (!keyId || !secretKey) {
|
|
773
|
+
console.log(kleur__default.default.yellow("\nCredentials not provided. Aborting setup."));
|
|
774
|
+
process.exit(1);
|
|
775
|
+
}
|
|
776
|
+
console.log(
|
|
777
|
+
`
|
|
778
|
+
Validating partner credentials with ${environment} API...`
|
|
779
|
+
);
|
|
780
|
+
const validation = await validatePartnerCredentials(
|
|
781
|
+
keyId,
|
|
782
|
+
secretKey,
|
|
783
|
+
authMethod,
|
|
784
|
+
environment
|
|
785
|
+
);
|
|
710
786
|
if (validation.valid) {
|
|
711
787
|
console.log(kleur__default.default.green(`\u2705 ${validation.message}`));
|
|
712
788
|
} else {
|
|
@@ -718,7 +794,11 @@ Validating partner credentials with ${environment} API...`);
|
|
|
718
794
|
initial: false
|
|
719
795
|
});
|
|
720
796
|
if (!continueResponse.continue) {
|
|
721
|
-
console.log(
|
|
797
|
+
console.log(
|
|
798
|
+
kleur__default.default.yellow(
|
|
799
|
+
"\nAborted. Please check your partner credentials and try again."
|
|
800
|
+
)
|
|
801
|
+
);
|
|
722
802
|
process.exit(1);
|
|
723
803
|
}
|
|
724
804
|
}
|
|
@@ -732,25 +812,56 @@ Validating partner credentials with ${environment} API...`);
|
|
|
732
812
|
name: "features",
|
|
733
813
|
message: "Select features to include:",
|
|
734
814
|
choices: [
|
|
735
|
-
{
|
|
736
|
-
|
|
815
|
+
{
|
|
816
|
+
title: "On-ramp (Crypto purchases)",
|
|
817
|
+
value: "onramp",
|
|
818
|
+
selected: true
|
|
819
|
+
},
|
|
820
|
+
{
|
|
821
|
+
title: "Off-ramp (Crypto withdrawals)",
|
|
822
|
+
value: "offramp",
|
|
823
|
+
selected: true
|
|
824
|
+
},
|
|
737
825
|
{ title: "Integrator Fees", value: "fees", selected: true },
|
|
738
|
-
{
|
|
739
|
-
|
|
740
|
-
|
|
826
|
+
{
|
|
827
|
+
title: "Webhook Support",
|
|
828
|
+
value: "webhooks",
|
|
829
|
+
selected: false
|
|
830
|
+
},
|
|
831
|
+
{
|
|
832
|
+
title: "Real-time Updates (WebSocket)",
|
|
833
|
+
value: "realtime",
|
|
834
|
+
selected: false
|
|
835
|
+
},
|
|
836
|
+
{
|
|
837
|
+
title: "Example Page (Demo implementation)",
|
|
838
|
+
value: "example",
|
|
839
|
+
selected: false
|
|
840
|
+
}
|
|
741
841
|
],
|
|
742
842
|
hint: "- Space to select. Return to submit",
|
|
743
843
|
instructions: false
|
|
744
844
|
});
|
|
745
845
|
const features = response.features || ["onramp", "offramp", "fees"];
|
|
746
846
|
if (!response.features) {
|
|
747
|
-
console.log(
|
|
847
|
+
console.log(
|
|
848
|
+
kleur__default.default.yellow(
|
|
849
|
+
"\nNo features selected, using defaults: onramp, offramp, fees"
|
|
850
|
+
)
|
|
851
|
+
);
|
|
748
852
|
}
|
|
749
853
|
if (!options.force) {
|
|
750
|
-
const existingFiles = await checkExistingFiles(
|
|
854
|
+
const existingFiles = await checkExistingFiles(
|
|
855
|
+
framework,
|
|
856
|
+
process.cwd()
|
|
857
|
+
);
|
|
751
858
|
if (existingFiles.length > 0) {
|
|
752
|
-
console.log(
|
|
753
|
-
|
|
859
|
+
console.log(
|
|
860
|
+
kleur__default.default.yellow("\n\u26A0\uFE0F The following files already exist:\n")
|
|
861
|
+
);
|
|
862
|
+
existingFiles.forEach(
|
|
863
|
+
(file) => console.log(kleur__default.default.gray(` - ${file}`))
|
|
864
|
+
);
|
|
754
865
|
const response2 = await prompts__default.default({
|
|
755
866
|
type: "confirm",
|
|
756
867
|
name: "confirmOverwrite",
|
|
@@ -758,7 +869,9 @@ Validating partner credentials with ${environment} API...`);
|
|
|
758
869
|
initial: false
|
|
759
870
|
});
|
|
760
871
|
if (!response2.confirmOverwrite) {
|
|
761
|
-
console.log(
|
|
872
|
+
console.log(
|
|
873
|
+
kleur__default.default.yellow("\nAborted. No files were modified.")
|
|
874
|
+
);
|
|
762
875
|
process.exit(0);
|
|
763
876
|
}
|
|
764
877
|
}
|
|
@@ -787,31 +900,53 @@ Validating partner credentials with ${environment} API...`);
|
|
|
787
900
|
});
|
|
788
901
|
if (newEnvVars.length > 0) {
|
|
789
902
|
const separator = envContent && !envContent.endsWith("\n") ? "\n" : "";
|
|
790
|
-
fs.appendFileSync(
|
|
791
|
-
|
|
903
|
+
fs.appendFileSync(
|
|
904
|
+
envPath,
|
|
905
|
+
separator + "# Diviswap SDK Configuration (Partner Authentication)\n" + newEnvVars.join("\n") + "\n"
|
|
906
|
+
);
|
|
907
|
+
console.log(
|
|
908
|
+
kleur__default.default.green(
|
|
909
|
+
`\u2705 Updated ${envFile} with partner authentication credentials`
|
|
910
|
+
)
|
|
911
|
+
);
|
|
792
912
|
}
|
|
793
913
|
}
|
|
794
914
|
if (framework.includes("nextjs")) {
|
|
795
915
|
console.log("\nUpdating Next.js configuration...");
|
|
796
916
|
const configUpdated = updateNextConfig(process.cwd());
|
|
797
917
|
if (configUpdated) {
|
|
798
|
-
console.log(
|
|
918
|
+
console.log(
|
|
919
|
+
kleur__default.default.green(
|
|
920
|
+
"\u2705 Updated next.config with Diviswap environment variables"
|
|
921
|
+
)
|
|
922
|
+
);
|
|
799
923
|
}
|
|
800
924
|
}
|
|
801
925
|
if (!options.skipInstall) {
|
|
802
926
|
console.log("Installing dependencies...");
|
|
803
927
|
try {
|
|
804
|
-
const packageManager = fs.existsSync(
|
|
928
|
+
const packageManager = fs.existsSync(
|
|
929
|
+
path.join(process.cwd(), "yarn.lock")
|
|
930
|
+
) ? "yarn" : fs.existsSync(path.join(process.cwd(), "pnpm-lock.yaml")) ? "pnpm" : "npm";
|
|
805
931
|
const deps = ["@diviswap/sdk"];
|
|
806
932
|
if (features.includes("realtime")) {
|
|
807
933
|
deps.push("socket.io-client");
|
|
808
934
|
}
|
|
809
|
-
child_process.execSync(
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
935
|
+
child_process.execSync(
|
|
936
|
+
`${packageManager} ${packageManager === "npm" ? "install" : "add"} ${deps.join(" ")}`,
|
|
937
|
+
{
|
|
938
|
+
stdio: "inherit"
|
|
939
|
+
}
|
|
940
|
+
);
|
|
941
|
+
console.log(
|
|
942
|
+
kleur__default.default.green("\u2705 Dependencies installed successfully!")
|
|
943
|
+
);
|
|
813
944
|
} catch (error) {
|
|
814
|
-
console.log(
|
|
945
|
+
console.log(
|
|
946
|
+
kleur__default.default.red(
|
|
947
|
+
"\u274C Failed to install dependencies. Please run npm/yarn/pnpm install manually."
|
|
948
|
+
)
|
|
949
|
+
);
|
|
815
950
|
}
|
|
816
951
|
}
|
|
817
952
|
console.log(kleur__default.default.green().bold("\n\u2728 Diviswap SDK setup complete!\n"));
|
|
@@ -822,8 +957,14 @@ Validating partner credentials with ${environment} API...`);
|
|
|
822
957
|
console.log(kleur__default.default.cyan("\n\u{1F4D6} Next steps:\n"));
|
|
823
958
|
if (framework.includes("nextjs")) {
|
|
824
959
|
console.log("1. Add DiviswapClientProvider to your providers:");
|
|
825
|
-
console.log(
|
|
826
|
-
|
|
960
|
+
console.log(
|
|
961
|
+
kleur__default.default.gray(" // app/providers.tsx or app/layout.tsx")
|
|
962
|
+
);
|
|
963
|
+
console.log(
|
|
964
|
+
kleur__default.default.gray(
|
|
965
|
+
' import { DiviswapClientProvider } from "./components/diviswap-provider"'
|
|
966
|
+
)
|
|
967
|
+
);
|
|
827
968
|
console.log(kleur__default.default.gray(" "));
|
|
828
969
|
console.log(kleur__default.default.gray(" // In your providers chain:"));
|
|
829
970
|
console.log(kleur__default.default.gray(" <DiviswapClientProvider>"));
|
|
@@ -836,20 +977,37 @@ Validating partner credentials with ${environment} API...`);
|
|
|
836
977
|
console.log(kleur__default.default.gray(" http://localhost:3000/diviswap"));
|
|
837
978
|
} else {
|
|
838
979
|
console.log("\n3. Use the Diviswap hooks in your components:");
|
|
839
|
-
console.log(
|
|
980
|
+
console.log(
|
|
981
|
+
kleur__default.default.gray(
|
|
982
|
+
' import { useDiviswap } from "@diviswap/sdk/react"'
|
|
983
|
+
)
|
|
984
|
+
);
|
|
840
985
|
}
|
|
841
986
|
} else if (framework === "react") {
|
|
842
987
|
console.log("1. Import and use the Diviswap provider:");
|
|
843
|
-
console.log(
|
|
988
|
+
console.log(
|
|
989
|
+
kleur__default.default.gray(
|
|
990
|
+
' import { DiviswapProvider } from "@diviswap/sdk/react"'
|
|
991
|
+
)
|
|
992
|
+
);
|
|
844
993
|
console.log("\n2. Wrap your app with the provider:");
|
|
845
|
-
console.log(
|
|
994
|
+
console.log(
|
|
995
|
+
kleur__default.default.gray(" <DiviswapProvider><App /></DiviswapProvider>")
|
|
996
|
+
);
|
|
846
997
|
console.log("\n3. Use the hooks in your components:");
|
|
847
|
-
console.log(
|
|
998
|
+
console.log(
|
|
999
|
+
kleur__default.default.gray(
|
|
1000
|
+
' import { useDiviswap } from "@diviswap/sdk/react"'
|
|
1001
|
+
)
|
|
1002
|
+
);
|
|
848
1003
|
}
|
|
849
1004
|
console.log("\n\u{1F4DA} Documentation: https://docs.diviswap.io");
|
|
850
1005
|
console.log("\u{1F4AC} Support: support@diviswap.io\n");
|
|
851
1006
|
} catch (error) {
|
|
852
|
-
console.error(
|
|
1007
|
+
console.error(
|
|
1008
|
+
kleur__default.default.red("\n\u274C Setup failed:"),
|
|
1009
|
+
error instanceof Error ? error.message : error
|
|
1010
|
+
);
|
|
853
1011
|
process.exit(1);
|
|
854
1012
|
}
|
|
855
1013
|
}
|
|
@@ -862,7 +1020,9 @@ async function createApp(projectName, options) {
|
|
|
862
1020
|
message: "What is your project name?",
|
|
863
1021
|
initial: "diviswap-app",
|
|
864
1022
|
validate: (input) => {
|
|
865
|
-
if (/^(?:@[a-z0-9-*~][a-z0-9-*._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/.test(
|
|
1023
|
+
if (/^(?:@[a-z0-9-*~][a-z0-9-*._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/.test(
|
|
1024
|
+
input
|
|
1025
|
+
)) {
|
|
866
1026
|
return true;
|
|
867
1027
|
}
|
|
868
1028
|
return "Project name must be a valid npm package name";
|
|
@@ -870,6 +1030,10 @@ async function createApp(projectName, options) {
|
|
|
870
1030
|
});
|
|
871
1031
|
projectName = response.name;
|
|
872
1032
|
}
|
|
1033
|
+
if (!projectName) {
|
|
1034
|
+
console.log(kleur__default.default.yellow("\nNo project name provided. Aborting."));
|
|
1035
|
+
process.exit(1);
|
|
1036
|
+
}
|
|
873
1037
|
const projectPath = path.join(process.cwd(), projectName);
|
|
874
1038
|
if (fs.existsSync(projectPath)) {
|
|
875
1039
|
const response = await prompts__default.default({
|
|
@@ -887,8 +1051,10 @@ async function createApp(projectName, options) {
|
|
|
887
1051
|
if (options.useYarn) packageManager = "yarn";
|
|
888
1052
|
else if (options.usePnpm) packageManager = "pnpm";
|
|
889
1053
|
else if (!options.useNpm) {
|
|
890
|
-
if (fs.existsSync(path.join(process.cwd(), "yarn.lock")))
|
|
891
|
-
|
|
1054
|
+
if (fs.existsSync(path.join(process.cwd(), "yarn.lock")))
|
|
1055
|
+
packageManager = "yarn";
|
|
1056
|
+
else if (fs.existsSync(path.join(process.cwd(), "pnpm-lock.yaml")))
|
|
1057
|
+
packageManager = "pnpm";
|
|
892
1058
|
}
|
|
893
1059
|
let template = options.template || "nextjs";
|
|
894
1060
|
if (!["nextjs", "react", "vue"].includes(template)) {
|
|
@@ -897,13 +1063,20 @@ async function createApp(projectName, options) {
|
|
|
897
1063
|
name: "selectedTemplate",
|
|
898
1064
|
message: "Select a project template:",
|
|
899
1065
|
choices: [
|
|
900
|
-
{
|
|
1066
|
+
{
|
|
1067
|
+
title: "Next.js (Full-stack React framework)",
|
|
1068
|
+
value: "nextjs"
|
|
1069
|
+
},
|
|
901
1070
|
{ title: "React (Single-page application)", value: "react" },
|
|
902
1071
|
{ title: "Vue 3 (Progressive framework)", value: "vue" }
|
|
903
1072
|
]
|
|
904
1073
|
});
|
|
905
1074
|
template = response.selectedTemplate;
|
|
906
1075
|
}
|
|
1076
|
+
if (!template) {
|
|
1077
|
+
console.log(kleur__default.default.yellow("\nNo template selected. Aborting."));
|
|
1078
|
+
process.exit(1);
|
|
1079
|
+
}
|
|
907
1080
|
const useTypeScript = !options.javascript;
|
|
908
1081
|
console.log(kleur__default.default.cyan("\n\u{1F4CB} Project Configuration:"));
|
|
909
1082
|
console.log(` Name: ${kleur__default.default.white(projectName)}`);
|
|
@@ -942,19 +1115,25 @@ async function createApp(projectName, options) {
|
|
|
942
1115
|
console.log(kleur__default.default.green("\u2705 Project created successfully!"));
|
|
943
1116
|
console.log(kleur__default.default.blue("\n\u{1F527} Setting up Diviswap SDK...\n"));
|
|
944
1117
|
const frameworkMap = {
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
1118
|
+
nextjs: options.app ? "nextjs-app" : "nextjs-pages",
|
|
1119
|
+
react: "react",
|
|
1120
|
+
vue: "vue3"
|
|
948
1121
|
};
|
|
949
1122
|
await init({
|
|
950
1123
|
framework: frameworkMap[template],
|
|
951
1124
|
skipInstall: false,
|
|
952
1125
|
skipEnv: false
|
|
953
1126
|
});
|
|
954
|
-
console.log(
|
|
1127
|
+
console.log(
|
|
1128
|
+
kleur__default.default.green().bold("\n\u2728 Your Diviswap-powered app is ready!\n")
|
|
1129
|
+
);
|
|
955
1130
|
console.log("Next steps:");
|
|
956
1131
|
console.log(kleur__default.default.gray(` cd ${projectName}`));
|
|
957
|
-
console.log(
|
|
1132
|
+
console.log(
|
|
1133
|
+
kleur__default.default.gray(
|
|
1134
|
+
` ${packageManager} ${packageManager === "npm" ? "run dev" : "dev"}`
|
|
1135
|
+
)
|
|
1136
|
+
);
|
|
958
1137
|
console.log();
|
|
959
1138
|
console.log("Visit your app at:");
|
|
960
1139
|
console.log(kleur__default.default.cyan(" http://localhost:3000"));
|
|
@@ -971,7 +1150,31 @@ async function createApp(projectName, options) {
|
|
|
971
1150
|
}
|
|
972
1151
|
}
|
|
973
1152
|
async function createNextJsProject(projectPath, options) {
|
|
974
|
-
const {
|
|
1153
|
+
const {
|
|
1154
|
+
typescript,
|
|
1155
|
+
packageManager,
|
|
1156
|
+
eslint,
|
|
1157
|
+
tailwind,
|
|
1158
|
+
app,
|
|
1159
|
+
srcDir,
|
|
1160
|
+
importAlias
|
|
1161
|
+
} = options;
|
|
1162
|
+
const devDeps = {};
|
|
1163
|
+
if (typescript) {
|
|
1164
|
+
devDeps["@types/node"] = "^20.0.0";
|
|
1165
|
+
devDeps["@types/react"] = "^18.2.0";
|
|
1166
|
+
devDeps["@types/react-dom"] = "^18.2.0";
|
|
1167
|
+
devDeps["typescript"] = "^5.0.0";
|
|
1168
|
+
}
|
|
1169
|
+
if (eslint) {
|
|
1170
|
+
devDeps["eslint"] = "^8.0.0";
|
|
1171
|
+
devDeps["eslint-config-next"] = "^14.0.0";
|
|
1172
|
+
}
|
|
1173
|
+
if (tailwind) {
|
|
1174
|
+
devDeps["tailwindcss"] = "^3.3.0";
|
|
1175
|
+
devDeps["postcss"] = "^8.4.0";
|
|
1176
|
+
devDeps["autoprefixer"] = "^10.4.0";
|
|
1177
|
+
}
|
|
975
1178
|
const packageJson = {
|
|
976
1179
|
name: path.basename(projectPath),
|
|
977
1180
|
version: "0.1.0",
|
|
@@ -983,33 +1186,13 @@ async function createNextJsProject(projectPath, options) {
|
|
|
983
1186
|
lint: "next lint"
|
|
984
1187
|
},
|
|
985
1188
|
dependencies: {
|
|
986
|
-
|
|
1189
|
+
react: "^18.2.0",
|
|
987
1190
|
"react-dom": "^18.2.0",
|
|
988
|
-
|
|
1191
|
+
next: "^14.0.0",
|
|
989
1192
|
"@diviswap/sdk": "latest"
|
|
990
1193
|
},
|
|
991
|
-
devDependencies:
|
|
992
|
-
"@types/node": "^20.0.0",
|
|
993
|
-
"@types/react": "^18.2.0",
|
|
994
|
-
"@types/react-dom": "^18.2.0",
|
|
995
|
-
"typescript": "^5.0.0"
|
|
996
|
-
} : {}
|
|
1194
|
+
devDependencies: devDeps
|
|
997
1195
|
};
|
|
998
|
-
if (eslint) {
|
|
999
|
-
packageJson.devDependencies = {
|
|
1000
|
-
...packageJson.devDependencies,
|
|
1001
|
-
"eslint": "^8.0.0",
|
|
1002
|
-
"eslint-config-next": "^14.0.0"
|
|
1003
|
-
};
|
|
1004
|
-
}
|
|
1005
|
-
if (tailwind) {
|
|
1006
|
-
packageJson.devDependencies = {
|
|
1007
|
-
...packageJson.devDependencies,
|
|
1008
|
-
"tailwindcss": "^3.3.0",
|
|
1009
|
-
"postcss": "^8.4.0",
|
|
1010
|
-
"autoprefixer": "^10.4.0"
|
|
1011
|
-
};
|
|
1012
|
-
}
|
|
1013
1196
|
fs.writeFileSync("package.json", JSON.stringify(packageJson, null, 2));
|
|
1014
1197
|
if (typescript) {
|
|
1015
1198
|
const tsConfig = {
|
|
@@ -1029,7 +1212,9 @@ async function createNextJsProject(projectPath, options) {
|
|
|
1029
1212
|
jsx: "preserve",
|
|
1030
1213
|
incremental: true,
|
|
1031
1214
|
paths: importAlias ? {
|
|
1032
|
-
[importAlias.replace("/*", "/*")]: [
|
|
1215
|
+
[importAlias.replace("/*", "/*")]: [
|
|
1216
|
+
`./${srcDir ? "src/" : ""}*`
|
|
1217
|
+
]
|
|
1033
1218
|
} : {}
|
|
1034
1219
|
},
|
|
1035
1220
|
include: ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
|
|
@@ -1063,7 +1248,10 @@ export default function RootLayout({
|
|
|
1063
1248
|
</html>
|
|
1064
1249
|
)
|
|
1065
1250
|
}`;
|
|
1066
|
-
fs.writeFileSync(
|
|
1251
|
+
fs.writeFileSync(
|
|
1252
|
+
srcDir ? "src/app/layout.tsx" : "app/layout.tsx",
|
|
1253
|
+
layoutContent
|
|
1254
|
+
);
|
|
1067
1255
|
const pageContent = `export default function Home() {
|
|
1068
1256
|
return (
|
|
1069
1257
|
<main className="flex min-h-screen flex-col items-center justify-center p-24">
|
|
@@ -1078,8 +1266,11 @@ export default function RootLayout({
|
|
|
1078
1266
|
</main>
|
|
1079
1267
|
)
|
|
1080
1268
|
}`;
|
|
1081
|
-
fs.writeFileSync(
|
|
1082
|
-
|
|
1269
|
+
fs.writeFileSync(
|
|
1270
|
+
srcDir ? "src/app/page.tsx" : "app/page.tsx",
|
|
1271
|
+
pageContent
|
|
1272
|
+
);
|
|
1273
|
+
const globalsContent = tailwind ? `@tailwind base;
|
|
1083
1274
|
@tailwind components;
|
|
1084
1275
|
@tailwind utilities;` : `html, body {
|
|
1085
1276
|
padding: 0;
|
|
@@ -1091,7 +1282,10 @@ export default function RootLayout({
|
|
|
1091
1282
|
* {
|
|
1092
1283
|
box-sizing: border-box;
|
|
1093
1284
|
}`;
|
|
1094
|
-
fs.writeFileSync(
|
|
1285
|
+
fs.writeFileSync(
|
|
1286
|
+
srcDir ? "src/app/globals.css" : "app/globals.css",
|
|
1287
|
+
globalsContent
|
|
1288
|
+
);
|
|
1095
1289
|
} else {
|
|
1096
1290
|
fs.mkdirSync(srcDir ? "src/pages" : "pages", { recursive: true });
|
|
1097
1291
|
fs.mkdirSync(srcDir ? "src/styles" : "styles", { recursive: true });
|
|
@@ -1100,7 +1294,10 @@ export default function RootLayout({
|
|
|
1100
1294
|
export default function App(${typescript ? "{ Component, pageProps }: AppProps" : "{ Component, pageProps }"}) {
|
|
1101
1295
|
return <Component {...pageProps} />
|
|
1102
1296
|
}`;
|
|
1103
|
-
fs.writeFileSync(
|
|
1297
|
+
fs.writeFileSync(
|
|
1298
|
+
srcDir ? "src/pages/_app.tsx" : "pages/_app.tsx",
|
|
1299
|
+
appContent
|
|
1300
|
+
);
|
|
1104
1301
|
const indexContent = `export default function Home() {
|
|
1105
1302
|
return (
|
|
1106
1303
|
<main className="flex min-h-screen flex-col items-center justify-center p-24">
|
|
@@ -1115,8 +1312,26 @@ export default function App(${typescript ? "{ Component, pageProps }: AppProps"
|
|
|
1115
1312
|
</main>
|
|
1116
1313
|
)
|
|
1117
1314
|
}`;
|
|
1118
|
-
fs.writeFileSync(
|
|
1119
|
-
|
|
1315
|
+
fs.writeFileSync(
|
|
1316
|
+
srcDir ? "src/pages/index.tsx" : "pages/index.tsx",
|
|
1317
|
+
indexContent
|
|
1318
|
+
);
|
|
1319
|
+
const pagesGlobalsCss = tailwind ? `@tailwind base;
|
|
1320
|
+
@tailwind components;
|
|
1321
|
+
@tailwind utilities;` : `html, body {
|
|
1322
|
+
padding: 0;
|
|
1323
|
+
margin: 0;
|
|
1324
|
+
font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen,
|
|
1325
|
+
Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, sans-serif;
|
|
1326
|
+
}
|
|
1327
|
+
|
|
1328
|
+
* {
|
|
1329
|
+
box-sizing: border-box;
|
|
1330
|
+
}`;
|
|
1331
|
+
fs.writeFileSync(
|
|
1332
|
+
srcDir ? "src/styles/globals.css" : "styles/globals.css",
|
|
1333
|
+
pagesGlobalsCss
|
|
1334
|
+
);
|
|
1120
1335
|
}
|
|
1121
1336
|
if (tailwind) {
|
|
1122
1337
|
const tailwindConfig = `/** @type {import('tailwindcss').Config} */
|
|
@@ -1212,20 +1427,36 @@ The easiest way to deploy your Next.js app is to use the [Vercel Platform](https
|
|
|
1212
1427
|
}
|
|
1213
1428
|
async function createReactProject(projectPath, options) {
|
|
1214
1429
|
const { typescript, packageManager, eslint, tailwind } = options;
|
|
1430
|
+
const devDeps = {
|
|
1431
|
+
"@vitejs/plugin-react": "^4.2.0",
|
|
1432
|
+
vite: "^5.0.0"
|
|
1433
|
+
};
|
|
1434
|
+
if (typescript) {
|
|
1435
|
+
devDeps["@types/react"] = "^18.2.0";
|
|
1436
|
+
devDeps["@types/react-dom"] = "^18.2.0";
|
|
1437
|
+
devDeps["typescript"] = "^5.0.0";
|
|
1438
|
+
}
|
|
1439
|
+
if (eslint) {
|
|
1440
|
+
devDeps["eslint"] = "^8.0.0";
|
|
1441
|
+
devDeps["eslint-plugin-react"] = "^7.33.0";
|
|
1442
|
+
devDeps["eslint-plugin-react-hooks"] = "^4.6.0";
|
|
1443
|
+
}
|
|
1444
|
+
if (tailwind) {
|
|
1445
|
+
devDeps["tailwindcss"] = "^3.3.0";
|
|
1446
|
+
devDeps["postcss"] = "^8.4.0";
|
|
1447
|
+
devDeps["autoprefixer"] = "^10.4.0";
|
|
1448
|
+
}
|
|
1215
1449
|
const packageJson = {
|
|
1216
1450
|
name: path.basename(projectPath),
|
|
1217
1451
|
version: "0.1.0",
|
|
1218
1452
|
private: true,
|
|
1219
1453
|
dependencies: {
|
|
1220
|
-
|
|
1454
|
+
react: "^18.2.0",
|
|
1221
1455
|
"react-dom": "^18.2.0",
|
|
1222
1456
|
"react-router-dom": "^6.20.0",
|
|
1223
1457
|
"@diviswap/sdk": "latest"
|
|
1224
1458
|
},
|
|
1225
|
-
devDependencies:
|
|
1226
|
-
"@vitejs/plugin-react": "^4.2.0",
|
|
1227
|
-
"vite": "^5.0.0"
|
|
1228
|
-
},
|
|
1459
|
+
devDependencies: devDeps,
|
|
1229
1460
|
scripts: {
|
|
1230
1461
|
dev: "vite",
|
|
1231
1462
|
build: "vite build",
|
|
@@ -1233,30 +1464,6 @@ async function createReactProject(projectPath, options) {
|
|
|
1233
1464
|
lint: eslint ? "eslint . --ext .js,.jsx,.ts,.tsx" : 'echo "No linting configured"'
|
|
1234
1465
|
}
|
|
1235
1466
|
};
|
|
1236
|
-
if (typescript) {
|
|
1237
|
-
packageJson.devDependencies = {
|
|
1238
|
-
...packageJson.devDependencies,
|
|
1239
|
-
"@types/react": "^18.2.0",
|
|
1240
|
-
"@types/react-dom": "^18.2.0",
|
|
1241
|
-
"typescript": "^5.0.0"
|
|
1242
|
-
};
|
|
1243
|
-
}
|
|
1244
|
-
if (eslint) {
|
|
1245
|
-
packageJson.devDependencies = {
|
|
1246
|
-
...packageJson.devDependencies,
|
|
1247
|
-
"eslint": "^8.0.0",
|
|
1248
|
-
"eslint-plugin-react": "^7.33.0",
|
|
1249
|
-
"eslint-plugin-react-hooks": "^4.6.0"
|
|
1250
|
-
};
|
|
1251
|
-
}
|
|
1252
|
-
if (tailwind) {
|
|
1253
|
-
packageJson.devDependencies = {
|
|
1254
|
-
...packageJson.devDependencies,
|
|
1255
|
-
"tailwindcss": "^3.3.0",
|
|
1256
|
-
"postcss": "^8.4.0",
|
|
1257
|
-
"autoprefixer": "^10.4.0"
|
|
1258
|
-
};
|
|
1259
|
-
}
|
|
1260
1467
|
fs.writeFileSync("package.json", JSON.stringify(packageJson, null, 2));
|
|
1261
1468
|
const viteConfig = `import { defineConfig } from 'vite'
|
|
1262
1469
|
import react from '@vitejs/plugin-react'
|
|
@@ -1298,7 +1505,10 @@ export default defineConfig({
|
|
|
1298
1505
|
},
|
|
1299
1506
|
include: ["vite.config.ts"]
|
|
1300
1507
|
};
|
|
1301
|
-
fs.writeFileSync(
|
|
1508
|
+
fs.writeFileSync(
|
|
1509
|
+
"tsconfig.node.json",
|
|
1510
|
+
JSON.stringify(tsConfigNode, null, 2)
|
|
1511
|
+
);
|
|
1302
1512
|
}
|
|
1303
1513
|
fs.mkdirSync("src", { recursive: true });
|
|
1304
1514
|
fs.mkdirSync("public", { recursive: true });
|
|
@@ -1461,6 +1671,28 @@ The Diviswap SDK has been pre-configured in this project. Visit [http://localhos
|
|
|
1461
1671
|
}
|
|
1462
1672
|
async function createVueProject(projectPath, options) {
|
|
1463
1673
|
const { typescript, packageManager, eslint, tailwind } = options;
|
|
1674
|
+
const devDeps = {
|
|
1675
|
+
"@vitejs/plugin-vue": "^4.5.0",
|
|
1676
|
+
vite: "^5.0.0"
|
|
1677
|
+
};
|
|
1678
|
+
if (typescript) {
|
|
1679
|
+
devDeps["@vue/tsconfig"] = "^0.5.0";
|
|
1680
|
+
devDeps["typescript"] = "^5.0.0";
|
|
1681
|
+
devDeps["vue-tsc"] = "^1.8.0";
|
|
1682
|
+
}
|
|
1683
|
+
if (eslint) {
|
|
1684
|
+
devDeps["@rushstack/eslint-patch"] = "^1.3.0";
|
|
1685
|
+
if (typescript) {
|
|
1686
|
+
devDeps["@vue/eslint-config-typescript"] = "^12.0.0";
|
|
1687
|
+
}
|
|
1688
|
+
devDeps["eslint"] = "^8.0.0";
|
|
1689
|
+
devDeps["eslint-plugin-vue"] = "^9.0.0";
|
|
1690
|
+
}
|
|
1691
|
+
if (tailwind) {
|
|
1692
|
+
devDeps["tailwindcss"] = "^3.3.0";
|
|
1693
|
+
devDeps["postcss"] = "^8.4.0";
|
|
1694
|
+
devDeps["autoprefixer"] = "^10.4.0";
|
|
1695
|
+
}
|
|
1464
1696
|
const packageJson = {
|
|
1465
1697
|
name: path.basename(projectPath),
|
|
1466
1698
|
version: "0.1.0",
|
|
@@ -1472,45 +1704,12 @@ async function createVueProject(projectPath, options) {
|
|
|
1472
1704
|
lint: eslint ? "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore" : 'echo "No linting configured"'
|
|
1473
1705
|
},
|
|
1474
1706
|
dependencies: {
|
|
1475
|
-
|
|
1707
|
+
vue: "^3.3.0",
|
|
1476
1708
|
"vue-router": "^4.2.0",
|
|
1477
1709
|
"@diviswap/sdk": "latest"
|
|
1478
1710
|
},
|
|
1479
|
-
devDependencies:
|
|
1480
|
-
"@vitejs/plugin-vue": "^4.5.0",
|
|
1481
|
-
"vite": "^5.0.0"
|
|
1482
|
-
}
|
|
1711
|
+
devDependencies: devDeps
|
|
1483
1712
|
};
|
|
1484
|
-
if (typescript) {
|
|
1485
|
-
packageJson.devDependencies = {
|
|
1486
|
-
...packageJson.devDependencies,
|
|
1487
|
-
"@vue/tsconfig": "^0.5.0",
|
|
1488
|
-
"typescript": "^5.0.0",
|
|
1489
|
-
"vue-tsc": "^1.8.0"
|
|
1490
|
-
};
|
|
1491
|
-
}
|
|
1492
|
-
if (eslint) {
|
|
1493
|
-
packageJson.devDependencies = {
|
|
1494
|
-
...packageJson.devDependencies,
|
|
1495
|
-
"@rushstack/eslint-patch": "^1.3.0",
|
|
1496
|
-
"@vue/eslint-config-typescript": typescript ? "^12.0.0" : void 0,
|
|
1497
|
-
"eslint": "^8.0.0",
|
|
1498
|
-
"eslint-plugin-vue": "^9.0.0"
|
|
1499
|
-
};
|
|
1500
|
-
}
|
|
1501
|
-
if (tailwind) {
|
|
1502
|
-
packageJson.devDependencies = {
|
|
1503
|
-
...packageJson.devDependencies,
|
|
1504
|
-
"tailwindcss": "^3.3.0",
|
|
1505
|
-
"postcss": "^8.4.0",
|
|
1506
|
-
"autoprefixer": "^10.4.0"
|
|
1507
|
-
};
|
|
1508
|
-
}
|
|
1509
|
-
Object.keys(packageJson.devDependencies).forEach((key) => {
|
|
1510
|
-
if (packageJson.devDependencies[key] === void 0) {
|
|
1511
|
-
delete packageJson.devDependencies[key];
|
|
1512
|
-
}
|
|
1513
|
-
});
|
|
1514
1713
|
fs.writeFileSync("package.json", JSON.stringify(packageJson, null, 2));
|
|
1515
1714
|
const viteConfig = `import { fileURLToPath, URL } from 'node:url'
|
|
1516
1715
|
import { defineConfig } from 'vite'
|
|
@@ -1605,7 +1804,10 @@ const router = createRouter({
|
|
|
1605
1804
|
})
|
|
1606
1805
|
|
|
1607
1806
|
export default router`;
|
|
1608
|
-
fs.writeFileSync(
|
|
1807
|
+
fs.writeFileSync(
|
|
1808
|
+
`src/router/index.${typescript ? "ts" : "js"}`,
|
|
1809
|
+
routerContent
|
|
1810
|
+
);
|
|
1609
1811
|
const homeView = `<template>
|
|
1610
1812
|
<div class="flex min-h-screen flex-col items-center justify-center p-24">
|
|
1611
1813
|
<h1 class="text-4xl font-bold mb-8">Welcome to Diviswap</h1>
|
|
@@ -1771,11 +1973,8 @@ var SCAFFOLDED_FILES = {
|
|
|
1771
1973
|
"src/pages/api/webhooks/diviswap.ts",
|
|
1772
1974
|
"pages/api/webhooks/diviswap.ts"
|
|
1773
1975
|
],
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
"src/diviswap/example.tsx"
|
|
1777
|
-
],
|
|
1778
|
-
"vue3": [
|
|
1976
|
+
react: ["src/diviswap/api-client.ts", "src/diviswap/example.tsx"],
|
|
1977
|
+
vue3: [
|
|
1779
1978
|
"src/plugins/diviswap.ts",
|
|
1780
1979
|
"src/composables/useDiviswap.ts",
|
|
1781
1980
|
"src/components/DiviswapProvider.vue",
|
|
@@ -1784,7 +1983,7 @@ var SCAFFOLDED_FILES = {
|
|
|
1784
1983
|
"src/views/DiviswapExample.vue",
|
|
1785
1984
|
"src/diviswap/types.ts"
|
|
1786
1985
|
],
|
|
1787
|
-
|
|
1986
|
+
vanilla: [
|
|
1788
1987
|
"diviswap/client.js",
|
|
1789
1988
|
"diviswap/example.html",
|
|
1790
1989
|
"diviswap/example.js",
|
|
@@ -1823,7 +2022,9 @@ async function uninstall(options = {}) {
|
|
|
1823
2022
|
const confirmation = await prompts__default.default({
|
|
1824
2023
|
type: "confirm",
|
|
1825
2024
|
name: "confirmUninstall",
|
|
1826
|
-
message: kleur__default.default.yellow(
|
|
2025
|
+
message: kleur__default.default.yellow(
|
|
2026
|
+
"Are you sure you want to remove all Diviswap SDK files and configuration?"
|
|
2027
|
+
),
|
|
1827
2028
|
initial: false
|
|
1828
2029
|
});
|
|
1829
2030
|
if (!confirmation.confirmUninstall) {
|
|
@@ -1834,7 +2035,7 @@ async function uninstall(options = {}) {
|
|
|
1834
2035
|
console.log(kleur__default.default.blue("\u{1F50D} Scanning for Diviswap files...\\n"));
|
|
1835
2036
|
let filesRemoved = 0;
|
|
1836
2037
|
let dirsRemoved = 0;
|
|
1837
|
-
for (const [
|
|
2038
|
+
for (const [_framework, files] of Object.entries(SCAFFOLDED_FILES)) {
|
|
1838
2039
|
for (const file of files) {
|
|
1839
2040
|
const filePath = path.join(projectRoot, file);
|
|
1840
2041
|
if (fs.existsSync(filePath)) {
|
|
@@ -1843,7 +2044,11 @@ async function uninstall(options = {}) {
|
|
|
1843
2044
|
console.log(kleur__default.default.gray(`\u2713 Removed: ${file}`));
|
|
1844
2045
|
filesRemoved++;
|
|
1845
2046
|
} catch (error) {
|
|
1846
|
-
console.log(
|
|
2047
|
+
console.log(
|
|
2048
|
+
kleur__default.default.yellow(
|
|
2049
|
+
`\u26A0 Could not remove: ${file} (${error instanceof Error ? error.message : "unknown error"})`
|
|
2050
|
+
)
|
|
2051
|
+
);
|
|
1847
2052
|
}
|
|
1848
2053
|
}
|
|
1849
2054
|
}
|
|
@@ -1865,7 +2070,12 @@ async function uninstall(options = {}) {
|
|
|
1865
2070
|
}
|
|
1866
2071
|
if (!options.keepConfig) {
|
|
1867
2072
|
console.log(kleur__default.default.blue("\\n\u{1F527} Cleaning environment variables...\\n"));
|
|
1868
|
-
const envFiles = [
|
|
2073
|
+
const envFiles = [
|
|
2074
|
+
".env",
|
|
2075
|
+
".env.local",
|
|
2076
|
+
".env.development",
|
|
2077
|
+
".env.production"
|
|
2078
|
+
];
|
|
1869
2079
|
for (const envFile of envFiles) {
|
|
1870
2080
|
const envPath = path.join(projectRoot, envFile);
|
|
1871
2081
|
if (fs.existsSync(envPath)) {
|
|
@@ -1877,14 +2087,22 @@ async function uninstall(options = {}) {
|
|
|
1877
2087
|
if (regex.test(envContent)) {
|
|
1878
2088
|
envContent = envContent.replace(regex, "").replace(/\\n\\n+/g, "\\n").trim();
|
|
1879
2089
|
modified = true;
|
|
1880
|
-
console.log(
|
|
2090
|
+
console.log(
|
|
2091
|
+
kleur__default.default.gray(
|
|
2092
|
+
`\u2713 Removed ${envVar} from ${envFile}`
|
|
2093
|
+
)
|
|
2094
|
+
);
|
|
1881
2095
|
}
|
|
1882
2096
|
}
|
|
1883
2097
|
if (modified) {
|
|
1884
2098
|
fs.writeFileSync(envPath, envContent + "\\n");
|
|
1885
2099
|
}
|
|
1886
2100
|
} catch (error) {
|
|
1887
|
-
console.log(
|
|
2101
|
+
console.log(
|
|
2102
|
+
kleur__default.default.yellow(
|
|
2103
|
+
`\u26A0 Could not clean ${envFile}: ${error instanceof Error ? error.message : "unknown error"}`
|
|
2104
|
+
)
|
|
2105
|
+
);
|
|
1888
2106
|
}
|
|
1889
2107
|
}
|
|
1890
2108
|
}
|
|
@@ -1893,20 +2111,29 @@ async function uninstall(options = {}) {
|
|
|
1893
2111
|
const packageJsonPath = path.join(projectRoot, "package.json");
|
|
1894
2112
|
if (fs.existsSync(packageJsonPath)) {
|
|
1895
2113
|
try {
|
|
1896
|
-
const packageJson = JSON.parse(
|
|
2114
|
+
const packageJson = JSON.parse(
|
|
2115
|
+
fs.readFileSync(packageJsonPath, "utf-8")
|
|
2116
|
+
);
|
|
1897
2117
|
let modified = false;
|
|
1898
2118
|
if (packageJson.dependencies && packageJson.dependencies["@diviswap/sdk"]) {
|
|
1899
2119
|
delete packageJson.dependencies["@diviswap/sdk"];
|
|
1900
2120
|
modified = true;
|
|
1901
|
-
console.log(
|
|
2121
|
+
console.log(
|
|
2122
|
+
kleur__default.default.gray("\u2713 Removed @diviswap/sdk from dependencies")
|
|
2123
|
+
);
|
|
1902
2124
|
}
|
|
1903
2125
|
if (packageJson.devDependencies && packageJson.devDependencies["@diviswap/sdk"]) {
|
|
1904
2126
|
delete packageJson.devDependencies["@diviswap/sdk"];
|
|
1905
2127
|
modified = true;
|
|
1906
|
-
console.log(
|
|
2128
|
+
console.log(
|
|
2129
|
+
kleur__default.default.gray("\u2713 Removed @diviswap/sdk from devDependencies")
|
|
2130
|
+
);
|
|
1907
2131
|
}
|
|
1908
2132
|
if (modified) {
|
|
1909
|
-
fs.writeFileSync(
|
|
2133
|
+
fs.writeFileSync(
|
|
2134
|
+
packageJsonPath,
|
|
2135
|
+
JSON.stringify(packageJson, null, 2) + "\\n"
|
|
2136
|
+
);
|
|
1910
2137
|
const installDeps = await prompts__default.default({
|
|
1911
2138
|
type: "confirm",
|
|
1912
2139
|
name: "installDeps",
|
|
@@ -1917,34 +2144,60 @@ async function uninstall(options = {}) {
|
|
|
1917
2144
|
const { execSync: execSync3 } = __require("child_process");
|
|
1918
2145
|
try {
|
|
1919
2146
|
console.log(kleur__default.default.blue("\\n\u{1F4E6} Running npm install..."));
|
|
1920
|
-
execSync3("npm install", {
|
|
2147
|
+
execSync3("npm install", {
|
|
2148
|
+
stdio: "inherit",
|
|
2149
|
+
cwd: projectRoot
|
|
2150
|
+
});
|
|
1921
2151
|
} catch (error) {
|
|
1922
|
-
console.log(
|
|
2152
|
+
console.log(
|
|
2153
|
+
kleur__default.default.yellow(
|
|
2154
|
+
"\u26A0 Failed to run npm install. Please run it manually."
|
|
2155
|
+
)
|
|
2156
|
+
);
|
|
1923
2157
|
}
|
|
1924
2158
|
}
|
|
1925
2159
|
}
|
|
1926
2160
|
} catch (error) {
|
|
1927
|
-
console.log(
|
|
2161
|
+
console.log(
|
|
2162
|
+
kleur__default.default.yellow(
|
|
2163
|
+
`\u26A0 Could not update package.json: ${error instanceof Error ? error.message : "unknown error"}`
|
|
2164
|
+
)
|
|
2165
|
+
);
|
|
1928
2166
|
}
|
|
1929
2167
|
}
|
|
1930
2168
|
console.log(kleur__default.default.green().bold("\\n\u2705 Uninstall Complete!\\n"));
|
|
1931
2169
|
console.log(kleur__default.default.white(`Files removed: ${filesRemoved}`));
|
|
1932
2170
|
console.log(kleur__default.default.white(`Directories removed: ${dirsRemoved}`));
|
|
1933
2171
|
if (options.keepConfig) {
|
|
1934
|
-
console.log(
|
|
2172
|
+
console.log(
|
|
2173
|
+
kleur__default.default.yellow(
|
|
2174
|
+
"\\n\u26A0 Environment variables were preserved (--keep-config flag)"
|
|
2175
|
+
)
|
|
2176
|
+
);
|
|
1935
2177
|
}
|
|
1936
|
-
console.log(
|
|
2178
|
+
console.log(
|
|
2179
|
+
kleur__default.default.gray("\\nThe Diviswap SDK has been removed from your project.\\n")
|
|
2180
|
+
);
|
|
1937
2181
|
}
|
|
1938
2182
|
|
|
1939
2183
|
// package.json
|
|
1940
|
-
var version = "1.
|
|
2184
|
+
var version = "1.8.1";
|
|
1941
2185
|
|
|
1942
2186
|
// src/cli/index.ts
|
|
1943
2187
|
var program = new commander.Command();
|
|
1944
2188
|
program.name("diviswap-sdk").description("Diviswap SDK CLI - Streamline your crypto rails integration").version(version);
|
|
1945
|
-
program.command("init").description("Initialize Diviswap SDK in your existing project").option(
|
|
1946
|
-
|
|
1947
|
-
|
|
2189
|
+
program.command("init").description("Initialize Diviswap SDK in your existing project").option(
|
|
2190
|
+
"-f, --framework <type>",
|
|
2191
|
+
"Framework type (nextjs-app, nextjs-pages, react, vue3, etc.)"
|
|
2192
|
+
).option("-e, --env <environment>", "Environment (production or sandbox)").option("--skip-install", "Skip automatic dependency installation").option("--skip-env", "Skip environment variable setup").option("--force", "Overwrite existing files").action(init);
|
|
2193
|
+
program.command("create-app [project-name]").alias("create").description("Create a new project with Diviswap SDK pre-configured").option(
|
|
2194
|
+
"-t, --template <type>",
|
|
2195
|
+
"Project template (nextjs, react, vue)",
|
|
2196
|
+
"nextjs"
|
|
2197
|
+
).option("--use-npm", "Use npm instead of detecting package manager").option("--use-yarn", "Use Yarn instead of detecting package manager").option("--use-pnpm", "Use pnpm instead of detecting package manager").option("--typescript", "Use TypeScript (default)", true).option("--javascript", "Use JavaScript instead of TypeScript").option("--eslint", "Include ESLint configuration", true).option("--tailwind", "Include Tailwind CSS", true).option("--app", "Use App Router (Next.js only)", true).option("--src-dir", "Use src directory", true).option("--import-alias <alias>", "Import alias", "@/*").action(createApp);
|
|
2198
|
+
program.command("uninstall").alias("remove").description(
|
|
2199
|
+
"Remove Diviswap SDK files and configuration from your project"
|
|
2200
|
+
).option("--force", "Skip confirmation prompt").option("--keep-config", "Keep environment variables").action(uninstall);
|
|
1948
2201
|
if (!process.argv.slice(2).length) {
|
|
1949
2202
|
program.outputHelp();
|
|
1950
2203
|
}
|