@diviswap/sdk 1.8.0 → 1.9.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/LICENSE +1 -1
- package/README.md +73 -82
- package/bin/create-diviswap-app.js +5 -5
- package/dist/cli/index.js +442 -185
- package/dist/cli/templates/nextjs-app/api-route.ts.hbs +8 -52
- package/dist/cli/templates/nextjs-app/types.ts.hbs +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +333 -215
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +333 -215
- 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-Cohx6L51.d.mts} +12 -24
- package/dist/{wallet-DZymADRo.d.ts → wallet-Cohx6L51.d.ts} +12 -24
- package/package.json +98 -97
- package/src/cli/templates/index.ts +86 -54
- package/src/cli/templates/nextjs-app/api-route.ts.hbs +8 -52
- package/src/cli/templates/nextjs-app/types.ts.hbs +1 -1
- 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,12 @@ async function init(options) {
|
|
|
631
680
|
framework = response2.selectedFramework;
|
|
632
681
|
}
|
|
633
682
|
}
|
|
683
|
+
if (!framework) {
|
|
684
|
+
console.log(
|
|
685
|
+
kleur__default.default.yellow("\nNo framework selected. Aborting setup.")
|
|
686
|
+
);
|
|
687
|
+
process.exit(1);
|
|
688
|
+
}
|
|
634
689
|
let environment = options.env || "sandbox";
|
|
635
690
|
if (!options.skipEnv && !options.env) {
|
|
636
691
|
const envResponse = await prompts__default.default({
|
|
@@ -638,8 +693,16 @@ async function init(options) {
|
|
|
638
693
|
name: "environment",
|
|
639
694
|
message: "Which environment are you using?",
|
|
640
695
|
choices: [
|
|
641
|
-
{
|
|
642
|
-
|
|
696
|
+
{
|
|
697
|
+
title: "Production",
|
|
698
|
+
value: "production",
|
|
699
|
+
description: "Live environment for real transactions"
|
|
700
|
+
},
|
|
701
|
+
{
|
|
702
|
+
title: "Sandbox",
|
|
703
|
+
value: "sandbox",
|
|
704
|
+
description: "Testing environment with simulated transactions (uses sandbox credentials)"
|
|
705
|
+
}
|
|
643
706
|
],
|
|
644
707
|
initial: 1
|
|
645
708
|
// Default to sandbox for safety
|
|
@@ -650,8 +713,12 @@ async function init(options) {
|
|
|
650
713
|
let secretKey;
|
|
651
714
|
let authMethod = "hmac";
|
|
652
715
|
if (!options.skipEnv) {
|
|
653
|
-
console.log(
|
|
654
|
-
|
|
716
|
+
console.log(
|
|
717
|
+
kleur__default.default.yellow("\n\u{1F4DD} Partner Authentication Credentials\n")
|
|
718
|
+
);
|
|
719
|
+
console.log(
|
|
720
|
+
"Partner credentials are provided by Diviswap after approval."
|
|
721
|
+
);
|
|
655
722
|
console.log("Contact Diviswap support if you need partner access.");
|
|
656
723
|
const authMethodResponse = await prompts__default.default({
|
|
657
724
|
type: "select",
|
|
@@ -704,9 +771,22 @@ async function init(options) {
|
|
|
704
771
|
]);
|
|
705
772
|
keyId = partnerCredentials.keyId;
|
|
706
773
|
secretKey = partnerCredentials.secretKey;
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
774
|
+
if (!keyId || !secretKey) {
|
|
775
|
+
console.log(
|
|
776
|
+
kleur__default.default.yellow("\nCredentials not provided. Aborting setup.")
|
|
777
|
+
);
|
|
778
|
+
process.exit(1);
|
|
779
|
+
}
|
|
780
|
+
console.log(
|
|
781
|
+
`
|
|
782
|
+
Validating partner credentials with ${environment} API...`
|
|
783
|
+
);
|
|
784
|
+
const validation = await validatePartnerCredentials(
|
|
785
|
+
keyId,
|
|
786
|
+
secretKey,
|
|
787
|
+
authMethod,
|
|
788
|
+
environment
|
|
789
|
+
);
|
|
710
790
|
if (validation.valid) {
|
|
711
791
|
console.log(kleur__default.default.green(`\u2705 ${validation.message}`));
|
|
712
792
|
} else {
|
|
@@ -718,7 +798,11 @@ Validating partner credentials with ${environment} API...`);
|
|
|
718
798
|
initial: false
|
|
719
799
|
});
|
|
720
800
|
if (!continueResponse.continue) {
|
|
721
|
-
console.log(
|
|
801
|
+
console.log(
|
|
802
|
+
kleur__default.default.yellow(
|
|
803
|
+
"\nAborted. Please check your partner credentials and try again."
|
|
804
|
+
)
|
|
805
|
+
);
|
|
722
806
|
process.exit(1);
|
|
723
807
|
}
|
|
724
808
|
}
|
|
@@ -732,25 +816,56 @@ Validating partner credentials with ${environment} API...`);
|
|
|
732
816
|
name: "features",
|
|
733
817
|
message: "Select features to include:",
|
|
734
818
|
choices: [
|
|
735
|
-
{
|
|
736
|
-
|
|
819
|
+
{
|
|
820
|
+
title: "On-ramp (Crypto purchases)",
|
|
821
|
+
value: "onramp",
|
|
822
|
+
selected: true
|
|
823
|
+
},
|
|
824
|
+
{
|
|
825
|
+
title: "Off-ramp (Crypto withdrawals)",
|
|
826
|
+
value: "offramp",
|
|
827
|
+
selected: true
|
|
828
|
+
},
|
|
737
829
|
{ title: "Integrator Fees", value: "fees", selected: true },
|
|
738
|
-
{
|
|
739
|
-
|
|
740
|
-
|
|
830
|
+
{
|
|
831
|
+
title: "Webhook Support",
|
|
832
|
+
value: "webhooks",
|
|
833
|
+
selected: false
|
|
834
|
+
},
|
|
835
|
+
{
|
|
836
|
+
title: "Real-time Updates (WebSocket)",
|
|
837
|
+
value: "realtime",
|
|
838
|
+
selected: false
|
|
839
|
+
},
|
|
840
|
+
{
|
|
841
|
+
title: "Example Page (Demo implementation)",
|
|
842
|
+
value: "example",
|
|
843
|
+
selected: false
|
|
844
|
+
}
|
|
741
845
|
],
|
|
742
846
|
hint: "- Space to select. Return to submit",
|
|
743
847
|
instructions: false
|
|
744
848
|
});
|
|
745
849
|
const features = response.features || ["onramp", "offramp", "fees"];
|
|
746
850
|
if (!response.features) {
|
|
747
|
-
console.log(
|
|
851
|
+
console.log(
|
|
852
|
+
kleur__default.default.yellow(
|
|
853
|
+
"\nNo features selected, using defaults: onramp, offramp, fees"
|
|
854
|
+
)
|
|
855
|
+
);
|
|
748
856
|
}
|
|
749
857
|
if (!options.force) {
|
|
750
|
-
const existingFiles = await checkExistingFiles(
|
|
858
|
+
const existingFiles = await checkExistingFiles(
|
|
859
|
+
framework,
|
|
860
|
+
process.cwd()
|
|
861
|
+
);
|
|
751
862
|
if (existingFiles.length > 0) {
|
|
752
|
-
console.log(
|
|
753
|
-
|
|
863
|
+
console.log(
|
|
864
|
+
kleur__default.default.yellow("\n\u26A0\uFE0F The following files already exist:\n")
|
|
865
|
+
);
|
|
866
|
+
existingFiles.forEach(
|
|
867
|
+
(file) => console.log(kleur__default.default.gray(` - ${file}`))
|
|
868
|
+
);
|
|
754
869
|
const response2 = await prompts__default.default({
|
|
755
870
|
type: "confirm",
|
|
756
871
|
name: "confirmOverwrite",
|
|
@@ -758,7 +873,9 @@ Validating partner credentials with ${environment} API...`);
|
|
|
758
873
|
initial: false
|
|
759
874
|
});
|
|
760
875
|
if (!response2.confirmOverwrite) {
|
|
761
|
-
console.log(
|
|
876
|
+
console.log(
|
|
877
|
+
kleur__default.default.yellow("\nAborted. No files were modified.")
|
|
878
|
+
);
|
|
762
879
|
process.exit(0);
|
|
763
880
|
}
|
|
764
881
|
}
|
|
@@ -787,31 +904,53 @@ Validating partner credentials with ${environment} API...`);
|
|
|
787
904
|
});
|
|
788
905
|
if (newEnvVars.length > 0) {
|
|
789
906
|
const separator = envContent && !envContent.endsWith("\n") ? "\n" : "";
|
|
790
|
-
fs.appendFileSync(
|
|
791
|
-
|
|
907
|
+
fs.appendFileSync(
|
|
908
|
+
envPath,
|
|
909
|
+
separator + "# Diviswap SDK Configuration (Partner Authentication)\n" + newEnvVars.join("\n") + "\n"
|
|
910
|
+
);
|
|
911
|
+
console.log(
|
|
912
|
+
kleur__default.default.green(
|
|
913
|
+
`\u2705 Updated ${envFile} with partner authentication credentials`
|
|
914
|
+
)
|
|
915
|
+
);
|
|
792
916
|
}
|
|
793
917
|
}
|
|
794
918
|
if (framework.includes("nextjs")) {
|
|
795
919
|
console.log("\nUpdating Next.js configuration...");
|
|
796
920
|
const configUpdated = updateNextConfig(process.cwd());
|
|
797
921
|
if (configUpdated) {
|
|
798
|
-
console.log(
|
|
922
|
+
console.log(
|
|
923
|
+
kleur__default.default.green(
|
|
924
|
+
"\u2705 Updated next.config with Diviswap environment variables"
|
|
925
|
+
)
|
|
926
|
+
);
|
|
799
927
|
}
|
|
800
928
|
}
|
|
801
929
|
if (!options.skipInstall) {
|
|
802
930
|
console.log("Installing dependencies...");
|
|
803
931
|
try {
|
|
804
|
-
const packageManager = fs.existsSync(
|
|
932
|
+
const packageManager = fs.existsSync(
|
|
933
|
+
path.join(process.cwd(), "yarn.lock")
|
|
934
|
+
) ? "yarn" : fs.existsSync(path.join(process.cwd(), "pnpm-lock.yaml")) ? "pnpm" : "npm";
|
|
805
935
|
const deps = ["@diviswap/sdk"];
|
|
806
936
|
if (features.includes("realtime")) {
|
|
807
937
|
deps.push("socket.io-client");
|
|
808
938
|
}
|
|
809
|
-
child_process.execSync(
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
939
|
+
child_process.execSync(
|
|
940
|
+
`${packageManager} ${packageManager === "npm" ? "install" : "add"} ${deps.join(" ")}`,
|
|
941
|
+
{
|
|
942
|
+
stdio: "inherit"
|
|
943
|
+
}
|
|
944
|
+
);
|
|
945
|
+
console.log(
|
|
946
|
+
kleur__default.default.green("\u2705 Dependencies installed successfully!")
|
|
947
|
+
);
|
|
813
948
|
} catch (error) {
|
|
814
|
-
console.log(
|
|
949
|
+
console.log(
|
|
950
|
+
kleur__default.default.red(
|
|
951
|
+
"\u274C Failed to install dependencies. Please run npm/yarn/pnpm install manually."
|
|
952
|
+
)
|
|
953
|
+
);
|
|
815
954
|
}
|
|
816
955
|
}
|
|
817
956
|
console.log(kleur__default.default.green().bold("\n\u2728 Diviswap SDK setup complete!\n"));
|
|
@@ -822,8 +961,14 @@ Validating partner credentials with ${environment} API...`);
|
|
|
822
961
|
console.log(kleur__default.default.cyan("\n\u{1F4D6} Next steps:\n"));
|
|
823
962
|
if (framework.includes("nextjs")) {
|
|
824
963
|
console.log("1. Add DiviswapClientProvider to your providers:");
|
|
825
|
-
console.log(
|
|
826
|
-
|
|
964
|
+
console.log(
|
|
965
|
+
kleur__default.default.gray(" // app/providers.tsx or app/layout.tsx")
|
|
966
|
+
);
|
|
967
|
+
console.log(
|
|
968
|
+
kleur__default.default.gray(
|
|
969
|
+
' import { DiviswapClientProvider } from "./components/diviswap-provider"'
|
|
970
|
+
)
|
|
971
|
+
);
|
|
827
972
|
console.log(kleur__default.default.gray(" "));
|
|
828
973
|
console.log(kleur__default.default.gray(" // In your providers chain:"));
|
|
829
974
|
console.log(kleur__default.default.gray(" <DiviswapClientProvider>"));
|
|
@@ -836,20 +981,37 @@ Validating partner credentials with ${environment} API...`);
|
|
|
836
981
|
console.log(kleur__default.default.gray(" http://localhost:3000/diviswap"));
|
|
837
982
|
} else {
|
|
838
983
|
console.log("\n3. Use the Diviswap hooks in your components:");
|
|
839
|
-
console.log(
|
|
984
|
+
console.log(
|
|
985
|
+
kleur__default.default.gray(
|
|
986
|
+
' import { useDiviswap } from "@diviswap/sdk/react"'
|
|
987
|
+
)
|
|
988
|
+
);
|
|
840
989
|
}
|
|
841
990
|
} else if (framework === "react") {
|
|
842
991
|
console.log("1. Import and use the Diviswap provider:");
|
|
843
|
-
console.log(
|
|
992
|
+
console.log(
|
|
993
|
+
kleur__default.default.gray(
|
|
994
|
+
' import { DiviswapProvider } from "@diviswap/sdk/react"'
|
|
995
|
+
)
|
|
996
|
+
);
|
|
844
997
|
console.log("\n2. Wrap your app with the provider:");
|
|
845
|
-
console.log(
|
|
998
|
+
console.log(
|
|
999
|
+
kleur__default.default.gray(" <DiviswapProvider><App /></DiviswapProvider>")
|
|
1000
|
+
);
|
|
846
1001
|
console.log("\n3. Use the hooks in your components:");
|
|
847
|
-
console.log(
|
|
1002
|
+
console.log(
|
|
1003
|
+
kleur__default.default.gray(
|
|
1004
|
+
' import { useDiviswap } from "@diviswap/sdk/react"'
|
|
1005
|
+
)
|
|
1006
|
+
);
|
|
848
1007
|
}
|
|
849
1008
|
console.log("\n\u{1F4DA} Documentation: https://docs.diviswap.io");
|
|
850
1009
|
console.log("\u{1F4AC} Support: support@diviswap.io\n");
|
|
851
1010
|
} catch (error) {
|
|
852
|
-
console.error(
|
|
1011
|
+
console.error(
|
|
1012
|
+
kleur__default.default.red("\n\u274C Setup failed:"),
|
|
1013
|
+
error instanceof Error ? error.message : error
|
|
1014
|
+
);
|
|
853
1015
|
process.exit(1);
|
|
854
1016
|
}
|
|
855
1017
|
}
|
|
@@ -862,7 +1024,9 @@ async function createApp(projectName, options) {
|
|
|
862
1024
|
message: "What is your project name?",
|
|
863
1025
|
initial: "diviswap-app",
|
|
864
1026
|
validate: (input) => {
|
|
865
|
-
if (/^(?:@[a-z0-9-*~][a-z0-9-*._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/.test(
|
|
1027
|
+
if (/^(?:@[a-z0-9-*~][a-z0-9-*._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/.test(
|
|
1028
|
+
input
|
|
1029
|
+
)) {
|
|
866
1030
|
return true;
|
|
867
1031
|
}
|
|
868
1032
|
return "Project name must be a valid npm package name";
|
|
@@ -870,6 +1034,10 @@ async function createApp(projectName, options) {
|
|
|
870
1034
|
});
|
|
871
1035
|
projectName = response.name;
|
|
872
1036
|
}
|
|
1037
|
+
if (!projectName) {
|
|
1038
|
+
console.log(kleur__default.default.yellow("\nNo project name provided. Aborting."));
|
|
1039
|
+
process.exit(1);
|
|
1040
|
+
}
|
|
873
1041
|
const projectPath = path.join(process.cwd(), projectName);
|
|
874
1042
|
if (fs.existsSync(projectPath)) {
|
|
875
1043
|
const response = await prompts__default.default({
|
|
@@ -887,8 +1055,10 @@ async function createApp(projectName, options) {
|
|
|
887
1055
|
if (options.useYarn) packageManager = "yarn";
|
|
888
1056
|
else if (options.usePnpm) packageManager = "pnpm";
|
|
889
1057
|
else if (!options.useNpm) {
|
|
890
|
-
if (fs.existsSync(path.join(process.cwd(), "yarn.lock")))
|
|
891
|
-
|
|
1058
|
+
if (fs.existsSync(path.join(process.cwd(), "yarn.lock")))
|
|
1059
|
+
packageManager = "yarn";
|
|
1060
|
+
else if (fs.existsSync(path.join(process.cwd(), "pnpm-lock.yaml")))
|
|
1061
|
+
packageManager = "pnpm";
|
|
892
1062
|
}
|
|
893
1063
|
let template = options.template || "nextjs";
|
|
894
1064
|
if (!["nextjs", "react", "vue"].includes(template)) {
|
|
@@ -897,13 +1067,20 @@ async function createApp(projectName, options) {
|
|
|
897
1067
|
name: "selectedTemplate",
|
|
898
1068
|
message: "Select a project template:",
|
|
899
1069
|
choices: [
|
|
900
|
-
{
|
|
1070
|
+
{
|
|
1071
|
+
title: "Next.js (Full-stack React framework)",
|
|
1072
|
+
value: "nextjs"
|
|
1073
|
+
},
|
|
901
1074
|
{ title: "React (Single-page application)", value: "react" },
|
|
902
1075
|
{ title: "Vue 3 (Progressive framework)", value: "vue" }
|
|
903
1076
|
]
|
|
904
1077
|
});
|
|
905
1078
|
template = response.selectedTemplate;
|
|
906
1079
|
}
|
|
1080
|
+
if (!template) {
|
|
1081
|
+
console.log(kleur__default.default.yellow("\nNo template selected. Aborting."));
|
|
1082
|
+
process.exit(1);
|
|
1083
|
+
}
|
|
907
1084
|
const useTypeScript = !options.javascript;
|
|
908
1085
|
console.log(kleur__default.default.cyan("\n\u{1F4CB} Project Configuration:"));
|
|
909
1086
|
console.log(` Name: ${kleur__default.default.white(projectName)}`);
|
|
@@ -942,19 +1119,25 @@ async function createApp(projectName, options) {
|
|
|
942
1119
|
console.log(kleur__default.default.green("\u2705 Project created successfully!"));
|
|
943
1120
|
console.log(kleur__default.default.blue("\n\u{1F527} Setting up Diviswap SDK...\n"));
|
|
944
1121
|
const frameworkMap = {
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
1122
|
+
nextjs: options.app ? "nextjs-app" : "nextjs-pages",
|
|
1123
|
+
react: "react",
|
|
1124
|
+
vue: "vue3"
|
|
948
1125
|
};
|
|
949
1126
|
await init({
|
|
950
1127
|
framework: frameworkMap[template],
|
|
951
1128
|
skipInstall: false,
|
|
952
1129
|
skipEnv: false
|
|
953
1130
|
});
|
|
954
|
-
console.log(
|
|
1131
|
+
console.log(
|
|
1132
|
+
kleur__default.default.green().bold("\n\u2728 Your Diviswap-powered app is ready!\n")
|
|
1133
|
+
);
|
|
955
1134
|
console.log("Next steps:");
|
|
956
1135
|
console.log(kleur__default.default.gray(` cd ${projectName}`));
|
|
957
|
-
console.log(
|
|
1136
|
+
console.log(
|
|
1137
|
+
kleur__default.default.gray(
|
|
1138
|
+
` ${packageManager} ${packageManager === "npm" ? "run dev" : "dev"}`
|
|
1139
|
+
)
|
|
1140
|
+
);
|
|
958
1141
|
console.log();
|
|
959
1142
|
console.log("Visit your app at:");
|
|
960
1143
|
console.log(kleur__default.default.cyan(" http://localhost:3000"));
|
|
@@ -971,7 +1154,31 @@ async function createApp(projectName, options) {
|
|
|
971
1154
|
}
|
|
972
1155
|
}
|
|
973
1156
|
async function createNextJsProject(projectPath, options) {
|
|
974
|
-
const {
|
|
1157
|
+
const {
|
|
1158
|
+
typescript,
|
|
1159
|
+
packageManager,
|
|
1160
|
+
eslint,
|
|
1161
|
+
tailwind,
|
|
1162
|
+
app,
|
|
1163
|
+
srcDir,
|
|
1164
|
+
importAlias
|
|
1165
|
+
} = options;
|
|
1166
|
+
const devDeps = {};
|
|
1167
|
+
if (typescript) {
|
|
1168
|
+
devDeps["@types/node"] = "^20.0.0";
|
|
1169
|
+
devDeps["@types/react"] = "^18.2.0";
|
|
1170
|
+
devDeps["@types/react-dom"] = "^18.2.0";
|
|
1171
|
+
devDeps["typescript"] = "^5.0.0";
|
|
1172
|
+
}
|
|
1173
|
+
if (eslint) {
|
|
1174
|
+
devDeps["eslint"] = "^8.0.0";
|
|
1175
|
+
devDeps["eslint-config-next"] = "^14.0.0";
|
|
1176
|
+
}
|
|
1177
|
+
if (tailwind) {
|
|
1178
|
+
devDeps["tailwindcss"] = "^3.3.0";
|
|
1179
|
+
devDeps["postcss"] = "^8.4.0";
|
|
1180
|
+
devDeps["autoprefixer"] = "^10.4.0";
|
|
1181
|
+
}
|
|
975
1182
|
const packageJson = {
|
|
976
1183
|
name: path.basename(projectPath),
|
|
977
1184
|
version: "0.1.0",
|
|
@@ -983,33 +1190,13 @@ async function createNextJsProject(projectPath, options) {
|
|
|
983
1190
|
lint: "next lint"
|
|
984
1191
|
},
|
|
985
1192
|
dependencies: {
|
|
986
|
-
|
|
1193
|
+
react: "^18.2.0",
|
|
987
1194
|
"react-dom": "^18.2.0",
|
|
988
|
-
|
|
1195
|
+
next: "^14.0.0",
|
|
989
1196
|
"@diviswap/sdk": "latest"
|
|
990
1197
|
},
|
|
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
|
-
} : {}
|
|
1198
|
+
devDependencies: devDeps
|
|
997
1199
|
};
|
|
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
1200
|
fs.writeFileSync("package.json", JSON.stringify(packageJson, null, 2));
|
|
1014
1201
|
if (typescript) {
|
|
1015
1202
|
const tsConfig = {
|
|
@@ -1029,7 +1216,9 @@ async function createNextJsProject(projectPath, options) {
|
|
|
1029
1216
|
jsx: "preserve",
|
|
1030
1217
|
incremental: true,
|
|
1031
1218
|
paths: importAlias ? {
|
|
1032
|
-
[importAlias.replace("/*", "/*")]: [
|
|
1219
|
+
[importAlias.replace("/*", "/*")]: [
|
|
1220
|
+
`./${srcDir ? "src/" : ""}*`
|
|
1221
|
+
]
|
|
1033
1222
|
} : {}
|
|
1034
1223
|
},
|
|
1035
1224
|
include: ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
|
|
@@ -1063,7 +1252,10 @@ export default function RootLayout({
|
|
|
1063
1252
|
</html>
|
|
1064
1253
|
)
|
|
1065
1254
|
}`;
|
|
1066
|
-
fs.writeFileSync(
|
|
1255
|
+
fs.writeFileSync(
|
|
1256
|
+
srcDir ? "src/app/layout.tsx" : "app/layout.tsx",
|
|
1257
|
+
layoutContent
|
|
1258
|
+
);
|
|
1067
1259
|
const pageContent = `export default function Home() {
|
|
1068
1260
|
return (
|
|
1069
1261
|
<main className="flex min-h-screen flex-col items-center justify-center p-24">
|
|
@@ -1078,8 +1270,11 @@ export default function RootLayout({
|
|
|
1078
1270
|
</main>
|
|
1079
1271
|
)
|
|
1080
1272
|
}`;
|
|
1081
|
-
fs.writeFileSync(
|
|
1082
|
-
|
|
1273
|
+
fs.writeFileSync(
|
|
1274
|
+
srcDir ? "src/app/page.tsx" : "app/page.tsx",
|
|
1275
|
+
pageContent
|
|
1276
|
+
);
|
|
1277
|
+
const globalsContent = tailwind ? `@tailwind base;
|
|
1083
1278
|
@tailwind components;
|
|
1084
1279
|
@tailwind utilities;` : `html, body {
|
|
1085
1280
|
padding: 0;
|
|
@@ -1091,7 +1286,10 @@ export default function RootLayout({
|
|
|
1091
1286
|
* {
|
|
1092
1287
|
box-sizing: border-box;
|
|
1093
1288
|
}`;
|
|
1094
|
-
fs.writeFileSync(
|
|
1289
|
+
fs.writeFileSync(
|
|
1290
|
+
srcDir ? "src/app/globals.css" : "app/globals.css",
|
|
1291
|
+
globalsContent
|
|
1292
|
+
);
|
|
1095
1293
|
} else {
|
|
1096
1294
|
fs.mkdirSync(srcDir ? "src/pages" : "pages", { recursive: true });
|
|
1097
1295
|
fs.mkdirSync(srcDir ? "src/styles" : "styles", { recursive: true });
|
|
@@ -1100,7 +1298,10 @@ export default function RootLayout({
|
|
|
1100
1298
|
export default function App(${typescript ? "{ Component, pageProps }: AppProps" : "{ Component, pageProps }"}) {
|
|
1101
1299
|
return <Component {...pageProps} />
|
|
1102
1300
|
}`;
|
|
1103
|
-
fs.writeFileSync(
|
|
1301
|
+
fs.writeFileSync(
|
|
1302
|
+
srcDir ? "src/pages/_app.tsx" : "pages/_app.tsx",
|
|
1303
|
+
appContent
|
|
1304
|
+
);
|
|
1104
1305
|
const indexContent = `export default function Home() {
|
|
1105
1306
|
return (
|
|
1106
1307
|
<main className="flex min-h-screen flex-col items-center justify-center p-24">
|
|
@@ -1115,8 +1316,26 @@ export default function App(${typescript ? "{ Component, pageProps }: AppProps"
|
|
|
1115
1316
|
</main>
|
|
1116
1317
|
)
|
|
1117
1318
|
}`;
|
|
1118
|
-
fs.writeFileSync(
|
|
1119
|
-
|
|
1319
|
+
fs.writeFileSync(
|
|
1320
|
+
srcDir ? "src/pages/index.tsx" : "pages/index.tsx",
|
|
1321
|
+
indexContent
|
|
1322
|
+
);
|
|
1323
|
+
const pagesGlobalsCss = tailwind ? `@tailwind base;
|
|
1324
|
+
@tailwind components;
|
|
1325
|
+
@tailwind utilities;` : `html, body {
|
|
1326
|
+
padding: 0;
|
|
1327
|
+
margin: 0;
|
|
1328
|
+
font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen,
|
|
1329
|
+
Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, sans-serif;
|
|
1330
|
+
}
|
|
1331
|
+
|
|
1332
|
+
* {
|
|
1333
|
+
box-sizing: border-box;
|
|
1334
|
+
}`;
|
|
1335
|
+
fs.writeFileSync(
|
|
1336
|
+
srcDir ? "src/styles/globals.css" : "styles/globals.css",
|
|
1337
|
+
pagesGlobalsCss
|
|
1338
|
+
);
|
|
1120
1339
|
}
|
|
1121
1340
|
if (tailwind) {
|
|
1122
1341
|
const tailwindConfig = `/** @type {import('tailwindcss').Config} */
|
|
@@ -1212,20 +1431,36 @@ The easiest way to deploy your Next.js app is to use the [Vercel Platform](https
|
|
|
1212
1431
|
}
|
|
1213
1432
|
async function createReactProject(projectPath, options) {
|
|
1214
1433
|
const { typescript, packageManager, eslint, tailwind } = options;
|
|
1434
|
+
const devDeps = {
|
|
1435
|
+
"@vitejs/plugin-react": "^4.2.0",
|
|
1436
|
+
vite: "^5.0.0"
|
|
1437
|
+
};
|
|
1438
|
+
if (typescript) {
|
|
1439
|
+
devDeps["@types/react"] = "^18.2.0";
|
|
1440
|
+
devDeps["@types/react-dom"] = "^18.2.0";
|
|
1441
|
+
devDeps["typescript"] = "^5.0.0";
|
|
1442
|
+
}
|
|
1443
|
+
if (eslint) {
|
|
1444
|
+
devDeps["eslint"] = "^8.0.0";
|
|
1445
|
+
devDeps["eslint-plugin-react"] = "^7.33.0";
|
|
1446
|
+
devDeps["eslint-plugin-react-hooks"] = "^4.6.0";
|
|
1447
|
+
}
|
|
1448
|
+
if (tailwind) {
|
|
1449
|
+
devDeps["tailwindcss"] = "^3.3.0";
|
|
1450
|
+
devDeps["postcss"] = "^8.4.0";
|
|
1451
|
+
devDeps["autoprefixer"] = "^10.4.0";
|
|
1452
|
+
}
|
|
1215
1453
|
const packageJson = {
|
|
1216
1454
|
name: path.basename(projectPath),
|
|
1217
1455
|
version: "0.1.0",
|
|
1218
1456
|
private: true,
|
|
1219
1457
|
dependencies: {
|
|
1220
|
-
|
|
1458
|
+
react: "^18.2.0",
|
|
1221
1459
|
"react-dom": "^18.2.0",
|
|
1222
1460
|
"react-router-dom": "^6.20.0",
|
|
1223
1461
|
"@diviswap/sdk": "latest"
|
|
1224
1462
|
},
|
|
1225
|
-
devDependencies:
|
|
1226
|
-
"@vitejs/plugin-react": "^4.2.0",
|
|
1227
|
-
"vite": "^5.0.0"
|
|
1228
|
-
},
|
|
1463
|
+
devDependencies: devDeps,
|
|
1229
1464
|
scripts: {
|
|
1230
1465
|
dev: "vite",
|
|
1231
1466
|
build: "vite build",
|
|
@@ -1233,30 +1468,6 @@ async function createReactProject(projectPath, options) {
|
|
|
1233
1468
|
lint: eslint ? "eslint . --ext .js,.jsx,.ts,.tsx" : 'echo "No linting configured"'
|
|
1234
1469
|
}
|
|
1235
1470
|
};
|
|
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
1471
|
fs.writeFileSync("package.json", JSON.stringify(packageJson, null, 2));
|
|
1261
1472
|
const viteConfig = `import { defineConfig } from 'vite'
|
|
1262
1473
|
import react from '@vitejs/plugin-react'
|
|
@@ -1298,7 +1509,10 @@ export default defineConfig({
|
|
|
1298
1509
|
},
|
|
1299
1510
|
include: ["vite.config.ts"]
|
|
1300
1511
|
};
|
|
1301
|
-
fs.writeFileSync(
|
|
1512
|
+
fs.writeFileSync(
|
|
1513
|
+
"tsconfig.node.json",
|
|
1514
|
+
JSON.stringify(tsConfigNode, null, 2)
|
|
1515
|
+
);
|
|
1302
1516
|
}
|
|
1303
1517
|
fs.mkdirSync("src", { recursive: true });
|
|
1304
1518
|
fs.mkdirSync("public", { recursive: true });
|
|
@@ -1461,6 +1675,28 @@ The Diviswap SDK has been pre-configured in this project. Visit [http://localhos
|
|
|
1461
1675
|
}
|
|
1462
1676
|
async function createVueProject(projectPath, options) {
|
|
1463
1677
|
const { typescript, packageManager, eslint, tailwind } = options;
|
|
1678
|
+
const devDeps = {
|
|
1679
|
+
"@vitejs/plugin-vue": "^4.5.0",
|
|
1680
|
+
vite: "^5.0.0"
|
|
1681
|
+
};
|
|
1682
|
+
if (typescript) {
|
|
1683
|
+
devDeps["@vue/tsconfig"] = "^0.5.0";
|
|
1684
|
+
devDeps["typescript"] = "^5.0.0";
|
|
1685
|
+
devDeps["vue-tsc"] = "^1.8.0";
|
|
1686
|
+
}
|
|
1687
|
+
if (eslint) {
|
|
1688
|
+
devDeps["@rushstack/eslint-patch"] = "^1.3.0";
|
|
1689
|
+
if (typescript) {
|
|
1690
|
+
devDeps["@vue/eslint-config-typescript"] = "^12.0.0";
|
|
1691
|
+
}
|
|
1692
|
+
devDeps["eslint"] = "^8.0.0";
|
|
1693
|
+
devDeps["eslint-plugin-vue"] = "^9.0.0";
|
|
1694
|
+
}
|
|
1695
|
+
if (tailwind) {
|
|
1696
|
+
devDeps["tailwindcss"] = "^3.3.0";
|
|
1697
|
+
devDeps["postcss"] = "^8.4.0";
|
|
1698
|
+
devDeps["autoprefixer"] = "^10.4.0";
|
|
1699
|
+
}
|
|
1464
1700
|
const packageJson = {
|
|
1465
1701
|
name: path.basename(projectPath),
|
|
1466
1702
|
version: "0.1.0",
|
|
@@ -1472,45 +1708,12 @@ async function createVueProject(projectPath, options) {
|
|
|
1472
1708
|
lint: eslint ? "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore" : 'echo "No linting configured"'
|
|
1473
1709
|
},
|
|
1474
1710
|
dependencies: {
|
|
1475
|
-
|
|
1711
|
+
vue: "^3.3.0",
|
|
1476
1712
|
"vue-router": "^4.2.0",
|
|
1477
1713
|
"@diviswap/sdk": "latest"
|
|
1478
1714
|
},
|
|
1479
|
-
devDependencies:
|
|
1480
|
-
"@vitejs/plugin-vue": "^4.5.0",
|
|
1481
|
-
"vite": "^5.0.0"
|
|
1482
|
-
}
|
|
1715
|
+
devDependencies: devDeps
|
|
1483
1716
|
};
|
|
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
1717
|
fs.writeFileSync("package.json", JSON.stringify(packageJson, null, 2));
|
|
1515
1718
|
const viteConfig = `import { fileURLToPath, URL } from 'node:url'
|
|
1516
1719
|
import { defineConfig } from 'vite'
|
|
@@ -1605,7 +1808,10 @@ const router = createRouter({
|
|
|
1605
1808
|
})
|
|
1606
1809
|
|
|
1607
1810
|
export default router`;
|
|
1608
|
-
fs.writeFileSync(
|
|
1811
|
+
fs.writeFileSync(
|
|
1812
|
+
`src/router/index.${typescript ? "ts" : "js"}`,
|
|
1813
|
+
routerContent
|
|
1814
|
+
);
|
|
1609
1815
|
const homeView = `<template>
|
|
1610
1816
|
<div class="flex min-h-screen flex-col items-center justify-center p-24">
|
|
1611
1817
|
<h1 class="text-4xl font-bold mb-8">Welcome to Diviswap</h1>
|
|
@@ -1771,11 +1977,8 @@ var SCAFFOLDED_FILES = {
|
|
|
1771
1977
|
"src/pages/api/webhooks/diviswap.ts",
|
|
1772
1978
|
"pages/api/webhooks/diviswap.ts"
|
|
1773
1979
|
],
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
"src/diviswap/example.tsx"
|
|
1777
|
-
],
|
|
1778
|
-
"vue3": [
|
|
1980
|
+
react: ["src/diviswap/api-client.ts", "src/diviswap/example.tsx"],
|
|
1981
|
+
vue3: [
|
|
1779
1982
|
"src/plugins/diviswap.ts",
|
|
1780
1983
|
"src/composables/useDiviswap.ts",
|
|
1781
1984
|
"src/components/DiviswapProvider.vue",
|
|
@@ -1784,7 +1987,7 @@ var SCAFFOLDED_FILES = {
|
|
|
1784
1987
|
"src/views/DiviswapExample.vue",
|
|
1785
1988
|
"src/diviswap/types.ts"
|
|
1786
1989
|
],
|
|
1787
|
-
|
|
1990
|
+
vanilla: [
|
|
1788
1991
|
"diviswap/client.js",
|
|
1789
1992
|
"diviswap/example.html",
|
|
1790
1993
|
"diviswap/example.js",
|
|
@@ -1823,7 +2026,9 @@ async function uninstall(options = {}) {
|
|
|
1823
2026
|
const confirmation = await prompts__default.default({
|
|
1824
2027
|
type: "confirm",
|
|
1825
2028
|
name: "confirmUninstall",
|
|
1826
|
-
message: kleur__default.default.yellow(
|
|
2029
|
+
message: kleur__default.default.yellow(
|
|
2030
|
+
"Are you sure you want to remove all Diviswap SDK files and configuration?"
|
|
2031
|
+
),
|
|
1827
2032
|
initial: false
|
|
1828
2033
|
});
|
|
1829
2034
|
if (!confirmation.confirmUninstall) {
|
|
@@ -1834,7 +2039,7 @@ async function uninstall(options = {}) {
|
|
|
1834
2039
|
console.log(kleur__default.default.blue("\u{1F50D} Scanning for Diviswap files...\\n"));
|
|
1835
2040
|
let filesRemoved = 0;
|
|
1836
2041
|
let dirsRemoved = 0;
|
|
1837
|
-
for (const [
|
|
2042
|
+
for (const [_framework, files] of Object.entries(SCAFFOLDED_FILES)) {
|
|
1838
2043
|
for (const file of files) {
|
|
1839
2044
|
const filePath = path.join(projectRoot, file);
|
|
1840
2045
|
if (fs.existsSync(filePath)) {
|
|
@@ -1843,7 +2048,11 @@ async function uninstall(options = {}) {
|
|
|
1843
2048
|
console.log(kleur__default.default.gray(`\u2713 Removed: ${file}`));
|
|
1844
2049
|
filesRemoved++;
|
|
1845
2050
|
} catch (error) {
|
|
1846
|
-
console.log(
|
|
2051
|
+
console.log(
|
|
2052
|
+
kleur__default.default.yellow(
|
|
2053
|
+
`\u26A0 Could not remove: ${file} (${error instanceof Error ? error.message : "unknown error"})`
|
|
2054
|
+
)
|
|
2055
|
+
);
|
|
1847
2056
|
}
|
|
1848
2057
|
}
|
|
1849
2058
|
}
|
|
@@ -1865,7 +2074,12 @@ async function uninstall(options = {}) {
|
|
|
1865
2074
|
}
|
|
1866
2075
|
if (!options.keepConfig) {
|
|
1867
2076
|
console.log(kleur__default.default.blue("\\n\u{1F527} Cleaning environment variables...\\n"));
|
|
1868
|
-
const envFiles = [
|
|
2077
|
+
const envFiles = [
|
|
2078
|
+
".env",
|
|
2079
|
+
".env.local",
|
|
2080
|
+
".env.development",
|
|
2081
|
+
".env.production"
|
|
2082
|
+
];
|
|
1869
2083
|
for (const envFile of envFiles) {
|
|
1870
2084
|
const envPath = path.join(projectRoot, envFile);
|
|
1871
2085
|
if (fs.existsSync(envPath)) {
|
|
@@ -1877,14 +2091,22 @@ async function uninstall(options = {}) {
|
|
|
1877
2091
|
if (regex.test(envContent)) {
|
|
1878
2092
|
envContent = envContent.replace(regex, "").replace(/\\n\\n+/g, "\\n").trim();
|
|
1879
2093
|
modified = true;
|
|
1880
|
-
console.log(
|
|
2094
|
+
console.log(
|
|
2095
|
+
kleur__default.default.gray(
|
|
2096
|
+
`\u2713 Removed ${envVar} from ${envFile}`
|
|
2097
|
+
)
|
|
2098
|
+
);
|
|
1881
2099
|
}
|
|
1882
2100
|
}
|
|
1883
2101
|
if (modified) {
|
|
1884
2102
|
fs.writeFileSync(envPath, envContent + "\\n");
|
|
1885
2103
|
}
|
|
1886
2104
|
} catch (error) {
|
|
1887
|
-
console.log(
|
|
2105
|
+
console.log(
|
|
2106
|
+
kleur__default.default.yellow(
|
|
2107
|
+
`\u26A0 Could not clean ${envFile}: ${error instanceof Error ? error.message : "unknown error"}`
|
|
2108
|
+
)
|
|
2109
|
+
);
|
|
1888
2110
|
}
|
|
1889
2111
|
}
|
|
1890
2112
|
}
|
|
@@ -1893,20 +2115,29 @@ async function uninstall(options = {}) {
|
|
|
1893
2115
|
const packageJsonPath = path.join(projectRoot, "package.json");
|
|
1894
2116
|
if (fs.existsSync(packageJsonPath)) {
|
|
1895
2117
|
try {
|
|
1896
|
-
const packageJson = JSON.parse(
|
|
2118
|
+
const packageJson = JSON.parse(
|
|
2119
|
+
fs.readFileSync(packageJsonPath, "utf-8")
|
|
2120
|
+
);
|
|
1897
2121
|
let modified = false;
|
|
1898
2122
|
if (packageJson.dependencies && packageJson.dependencies["@diviswap/sdk"]) {
|
|
1899
2123
|
delete packageJson.dependencies["@diviswap/sdk"];
|
|
1900
2124
|
modified = true;
|
|
1901
|
-
console.log(
|
|
2125
|
+
console.log(
|
|
2126
|
+
kleur__default.default.gray("\u2713 Removed @diviswap/sdk from dependencies")
|
|
2127
|
+
);
|
|
1902
2128
|
}
|
|
1903
2129
|
if (packageJson.devDependencies && packageJson.devDependencies["@diviswap/sdk"]) {
|
|
1904
2130
|
delete packageJson.devDependencies["@diviswap/sdk"];
|
|
1905
2131
|
modified = true;
|
|
1906
|
-
console.log(
|
|
2132
|
+
console.log(
|
|
2133
|
+
kleur__default.default.gray("\u2713 Removed @diviswap/sdk from devDependencies")
|
|
2134
|
+
);
|
|
1907
2135
|
}
|
|
1908
2136
|
if (modified) {
|
|
1909
|
-
fs.writeFileSync(
|
|
2137
|
+
fs.writeFileSync(
|
|
2138
|
+
packageJsonPath,
|
|
2139
|
+
JSON.stringify(packageJson, null, 2) + "\\n"
|
|
2140
|
+
);
|
|
1910
2141
|
const installDeps = await prompts__default.default({
|
|
1911
2142
|
type: "confirm",
|
|
1912
2143
|
name: "installDeps",
|
|
@@ -1917,34 +2148,60 @@ async function uninstall(options = {}) {
|
|
|
1917
2148
|
const { execSync: execSync3 } = __require("child_process");
|
|
1918
2149
|
try {
|
|
1919
2150
|
console.log(kleur__default.default.blue("\\n\u{1F4E6} Running npm install..."));
|
|
1920
|
-
execSync3("npm install", {
|
|
2151
|
+
execSync3("npm install", {
|
|
2152
|
+
stdio: "inherit",
|
|
2153
|
+
cwd: projectRoot
|
|
2154
|
+
});
|
|
1921
2155
|
} catch (error) {
|
|
1922
|
-
console.log(
|
|
2156
|
+
console.log(
|
|
2157
|
+
kleur__default.default.yellow(
|
|
2158
|
+
"\u26A0 Failed to run npm install. Please run it manually."
|
|
2159
|
+
)
|
|
2160
|
+
);
|
|
1923
2161
|
}
|
|
1924
2162
|
}
|
|
1925
2163
|
}
|
|
1926
2164
|
} catch (error) {
|
|
1927
|
-
console.log(
|
|
2165
|
+
console.log(
|
|
2166
|
+
kleur__default.default.yellow(
|
|
2167
|
+
`\u26A0 Could not update package.json: ${error instanceof Error ? error.message : "unknown error"}`
|
|
2168
|
+
)
|
|
2169
|
+
);
|
|
1928
2170
|
}
|
|
1929
2171
|
}
|
|
1930
2172
|
console.log(kleur__default.default.green().bold("\\n\u2705 Uninstall Complete!\\n"));
|
|
1931
2173
|
console.log(kleur__default.default.white(`Files removed: ${filesRemoved}`));
|
|
1932
2174
|
console.log(kleur__default.default.white(`Directories removed: ${dirsRemoved}`));
|
|
1933
2175
|
if (options.keepConfig) {
|
|
1934
|
-
console.log(
|
|
2176
|
+
console.log(
|
|
2177
|
+
kleur__default.default.yellow(
|
|
2178
|
+
"\\n\u26A0 Environment variables were preserved (--keep-config flag)"
|
|
2179
|
+
)
|
|
2180
|
+
);
|
|
1935
2181
|
}
|
|
1936
|
-
console.log(
|
|
2182
|
+
console.log(
|
|
2183
|
+
kleur__default.default.gray("\\nThe Diviswap SDK has been removed from your project.\\n")
|
|
2184
|
+
);
|
|
1937
2185
|
}
|
|
1938
2186
|
|
|
1939
2187
|
// package.json
|
|
1940
|
-
var version = "1.
|
|
2188
|
+
var version = "1.9.0";
|
|
1941
2189
|
|
|
1942
2190
|
// src/cli/index.ts
|
|
1943
2191
|
var program = new commander.Command();
|
|
1944
2192
|
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
|
-
|
|
2193
|
+
program.command("init").description("Initialize Diviswap SDK in your existing project").option(
|
|
2194
|
+
"-f, --framework <type>",
|
|
2195
|
+
"Framework type (nextjs-app, nextjs-pages, react, vue3, etc.)"
|
|
2196
|
+
).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);
|
|
2197
|
+
program.command("create-app [project-name]").alias("create").description("Create a new project with Diviswap SDK pre-configured").option(
|
|
2198
|
+
"-t, --template <type>",
|
|
2199
|
+
"Project template (nextjs, react, vue)",
|
|
2200
|
+
"nextjs"
|
|
2201
|
+
).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);
|
|
2202
|
+
program.command("uninstall").alias("remove").description(
|
|
2203
|
+
"Remove Diviswap SDK files and configuration from your project"
|
|
2204
|
+
).option("--force", "Skip confirmation prompt").option("--keep-config", "Keep environment variables").action(uninstall);
|
|
1948
2205
|
if (!process.argv.slice(2).length) {
|
|
1949
2206
|
program.outputHelp();
|
|
1950
2207
|
}
|