continum 0.0.5 → 0.0.6

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.
Files changed (2) hide show
  1. package/dist/index.js +290 -0
  2. package/package.json +4 -2
package/dist/index.js CHANGED
@@ -18,6 +18,131 @@ main().catch(console.error);
18
18
  async function main() {
19
19
  console.clear();
20
20
  p.intro(pc.bgCyan(pc.black(" Continum Setup ")));
21
+ const hasPackageJson = existsSync("package.json");
22
+ let detectedFramework = null;
23
+ if (hasPackageJson) {
24
+ detectedFramework = detectFramework();
25
+ if (detectedFramework) {
26
+ p.log.info(`Detected framework: ${pc.cyan(detectedFramework)}`);
27
+ }
28
+ }
29
+ if (!hasPackageJson) {
30
+ p.log.warn("No package.json found in this directory.");
31
+ const shouldSetupFramework = await p.confirm({
32
+ message: "Set up a JavaScript framework first?",
33
+ initialValue: true
34
+ });
35
+ if (p.isCancel(shouldSetupFramework)) {
36
+ p.cancel("Setup cancelled");
37
+ process.exit(0);
38
+ }
39
+ if (shouldSetupFramework) {
40
+ const projectCategory = await p.select({
41
+ message: "What type of project are you building?",
42
+ options: [
43
+ { value: "frontend", label: "\u{1F3A8} Frontend (React, Vue, Svelte, etc.)" },
44
+ { value: "backend", label: "\u2699\uFE0F Backend (API, Server, etc.)" },
45
+ { value: "skip", label: "\u23ED\uFE0F Skip framework setup" }
46
+ ]
47
+ });
48
+ if (p.isCancel(projectCategory)) {
49
+ p.cancel("Setup cancelled");
50
+ process.exit(0);
51
+ }
52
+ if (projectCategory === "skip") {
53
+ const shouldInitNpm = await p.confirm({
54
+ message: "Initialize a basic Node.js project (npm init -y)?",
55
+ initialValue: true
56
+ });
57
+ if (p.isCancel(shouldInitNpm)) {
58
+ p.cancel("Setup cancelled");
59
+ process.exit(0);
60
+ }
61
+ if (shouldInitNpm) {
62
+ const s2 = p.spinner();
63
+ s2.start("Initializing project...");
64
+ try {
65
+ const { execSync } = await import("child_process");
66
+ execSync("npm init -y", { stdio: "ignore" });
67
+ s2.stop("\u2713 Project initialized!");
68
+ } catch (error) {
69
+ s2.stop("Initialization failed");
70
+ p.cancel(
71
+ `Failed to run "npm init -y". Please initialize your project manually:
72
+
73
+ ${pc.cyan("npm init -y")}
74
+
75
+ Then run ${pc.cyan("npx continum init")} again.`
76
+ );
77
+ process.exit(1);
78
+ }
79
+ } else {
80
+ p.cancel(
81
+ `Please initialize your project first:
82
+
83
+ ${pc.cyan("npm init -y")}
84
+
85
+ Then run ${pc.cyan("npx continum init")} again.`
86
+ );
87
+ process.exit(0);
88
+ }
89
+ } else {
90
+ let framework = "";
91
+ if (projectCategory === "frontend") {
92
+ framework = await p.select({
93
+ message: "Choose a frontend framework:",
94
+ options: [
95
+ { value: "nextjs-app", label: "Next.js (App Router)", hint: "React with App Router" },
96
+ { value: "nextjs-pages", label: "Next.js (Pages Router)", hint: "React with Pages Router" },
97
+ { value: "nuxt", label: "Nuxt", hint: "Vue framework" },
98
+ { value: "sveltekit", label: "SvelteKit", hint: "Svelte framework" },
99
+ { value: "astro", label: "Astro", hint: "Content-focused framework" }
100
+ ]
101
+ });
102
+ } else if (projectCategory === "backend") {
103
+ framework = await p.select({
104
+ message: "Choose a backend framework:",
105
+ options: [
106
+ { value: "fastify", label: "Fastify", hint: "Fast and low overhead" },
107
+ { value: "nestjs", label: "NestJS", hint: "Progressive Node.js framework" },
108
+ { value: "hono", label: "Hono", hint: "Ultrafast web framework" },
109
+ { value: "express", label: "Express", hint: "Minimalist web framework" }
110
+ ]
111
+ });
112
+ }
113
+ if (p.isCancel(framework)) {
114
+ p.cancel("Setup cancelled");
115
+ process.exit(0);
116
+ }
117
+ const s2 = p.spinner();
118
+ s2.start(`Setting up ${framework}...`);
119
+ try {
120
+ await installFramework(framework);
121
+ s2.stop(`\u2713 ${framework} installed successfully!`);
122
+ } catch (error) {
123
+ s2.stop("Framework installation failed");
124
+ p.log.error(error instanceof Error ? error.message : "Unknown error");
125
+ const continueAnyway = await p.confirm({
126
+ message: "Continue with Continum setup anyway?",
127
+ initialValue: true
128
+ });
129
+ if (p.isCancel(continueAnyway) || !continueAnyway) {
130
+ p.cancel("Setup cancelled");
131
+ process.exit(0);
132
+ }
133
+ }
134
+ }
135
+ } else {
136
+ p.cancel(
137
+ `Please initialize your project first:
138
+
139
+ ${pc.cyan("npm init -y")}
140
+
141
+ Then run ${pc.cyan("npx continum init")} again.`
142
+ );
143
+ process.exit(0);
144
+ }
145
+ }
21
146
  const shouldContinue = await p.confirm({
22
147
  message: "Set up Continum AI compliance in your project?",
23
148
  initialValue: true
@@ -574,6 +699,53 @@ async function generateExampleFile(config) {
574
699
  `;
575
700
  writeFileSync(filename, content);
576
701
  }
702
+ function detectFramework() {
703
+ try {
704
+ const packageJson = JSON.parse(readFileSync("package.json", "utf-8"));
705
+ const deps = { ...packageJson.dependencies, ...packageJson.devDependencies };
706
+ if (deps["next"]) {
707
+ if (existsSync("app")) {
708
+ return "Next.js (App Router)";
709
+ } else if (existsSync("pages")) {
710
+ return "Next.js (Pages Router)";
711
+ }
712
+ return "Next.js";
713
+ }
714
+ if (deps["nuxt"]) {
715
+ return "Nuxt";
716
+ }
717
+ if (deps["@sveltejs/kit"]) {
718
+ return "SvelteKit";
719
+ }
720
+ if (deps["astro"]) {
721
+ return "Astro";
722
+ }
723
+ if (deps["@nestjs/core"]) {
724
+ return "NestJS";
725
+ }
726
+ if (deps["fastify"]) {
727
+ return "Fastify";
728
+ }
729
+ if (deps["hono"]) {
730
+ return "Hono";
731
+ }
732
+ if (deps["express"]) {
733
+ return "Express";
734
+ }
735
+ if (deps["react"]) {
736
+ return "React";
737
+ }
738
+ if (deps["vue"]) {
739
+ return "Vue";
740
+ }
741
+ if (deps["svelte"]) {
742
+ return "Svelte";
743
+ }
744
+ return null;
745
+ } catch (error) {
746
+ return null;
747
+ }
748
+ }
577
749
  async function installSDK() {
578
750
  const { execSync } = await import("child_process");
579
751
  if (!existsSync("package.json")) {
@@ -601,3 +773,121 @@ async function installSDK() {
601
773
  throw new Error(`Failed to install @continum/sdk using ${packageManager}`);
602
774
  }
603
775
  }
776
+ async function installFramework(framework) {
777
+ const { execSync } = await import("child_process");
778
+ let packageManager = "npm";
779
+ if (existsSync("pnpm-lock.yaml")) {
780
+ packageManager = "pnpm";
781
+ } else if (existsSync("yarn.lock")) {
782
+ packageManager = "yarn";
783
+ } else if (existsSync("bun.lockb")) {
784
+ packageManager = "bun";
785
+ }
786
+ const commands = {
787
+ // Frontend frameworks
788
+ "nextjs-app": 'npx create-next-app@latest . --typescript --tailwind --app --no-src-dir --import-alias "@/*"',
789
+ "nextjs-pages": 'npx create-next-app@latest . --typescript --tailwind --no-app --no-src-dir --import-alias "@/*"',
790
+ "nuxt": "npx nuxi@latest init . --packageManager npm",
791
+ "sveltekit": "npm create svelte@latest .",
792
+ "astro": "npm create astro@latest .",
793
+ // Backend frameworks
794
+ "fastify": "npm init -y && npm install fastify",
795
+ "nestjs": "npx @nestjs/cli@latest new . --skip-git --package-manager npm",
796
+ "hono": "npm init -y && npm install hono",
797
+ "express": "npm init -y && npm install express"
798
+ };
799
+ const command2 = commands[framework];
800
+ if (!command2) {
801
+ throw new Error(`Unknown framework: ${framework}`);
802
+ }
803
+ try {
804
+ if (framework === "nextjs-app" || framework === "nextjs-pages") {
805
+ execSync(command2, { stdio: "inherit" });
806
+ } else if (framework === "nuxt") {
807
+ execSync(command2, { stdio: "inherit" });
808
+ } else if (framework === "sveltekit") {
809
+ execSync(command2, { stdio: "inherit" });
810
+ } else if (framework === "astro") {
811
+ execSync(command2, { stdio: "inherit" });
812
+ } else if (framework === "nestjs") {
813
+ execSync(command2, { stdio: "inherit" });
814
+ } else {
815
+ execSync(command2, { stdio: "ignore" });
816
+ if (framework === "fastify") {
817
+ createFastifyStarter();
818
+ } else if (framework === "hono") {
819
+ createHonoStarter();
820
+ } else if (framework === "express") {
821
+ createExpressStarter();
822
+ }
823
+ }
824
+ } catch (error) {
825
+ throw new Error(`Failed to install ${framework}: ${error instanceof Error ? error.message : "Unknown error"}`);
826
+ }
827
+ }
828
+ function createFastifyStarter() {
829
+ const content = `import Fastify from 'fastify';
830
+
831
+ const fastify = Fastify({
832
+ logger: true
833
+ });
834
+
835
+ fastify.get('/', async (request, reply) => {
836
+ return { hello: 'world' };
837
+ });
838
+
839
+ const start = async () => {
840
+ try {
841
+ await fastify.listen({ port: 3000 });
842
+ } catch (err) {
843
+ fastify.log.error(err);
844
+ process.exit(1);
845
+ }
846
+ };
847
+
848
+ start();
849
+ `;
850
+ writeFileSync("index.js", content);
851
+ const packageJson = JSON.parse(readFileSync("package.json", "utf-8"));
852
+ packageJson.type = "module";
853
+ packageJson.scripts = packageJson.scripts || {};
854
+ packageJson.scripts.start = "node index.js";
855
+ writeFileSync("package.json", JSON.stringify(packageJson, null, 2));
856
+ }
857
+ function createHonoStarter() {
858
+ const content = `import { Hono } from 'hono';
859
+
860
+ const app = new Hono();
861
+
862
+ app.get('/', (c) => {
863
+ return c.json({ hello: 'world' });
864
+ });
865
+
866
+ export default app;
867
+ `;
868
+ writeFileSync("index.js", content);
869
+ const packageJson = JSON.parse(readFileSync("package.json", "utf-8"));
870
+ packageJson.type = "module";
871
+ packageJson.scripts = packageJson.scripts || {};
872
+ packageJson.scripts.start = "node index.js";
873
+ writeFileSync("package.json", JSON.stringify(packageJson, null, 2));
874
+ }
875
+ function createExpressStarter() {
876
+ const content = `const express = require('express');
877
+ const app = express();
878
+ const port = 3000;
879
+
880
+ app.get('/', (req, res) => {
881
+ res.json({ hello: 'world' });
882
+ });
883
+
884
+ app.listen(port, () => {
885
+ console.log(\`Server running at http://localhost:\${port}\`);
886
+ });
887
+ `;
888
+ writeFileSync("index.js", content);
889
+ const packageJson = JSON.parse(readFileSync("package.json", "utf-8"));
890
+ packageJson.scripts = packageJson.scripts || {};
891
+ packageJson.scripts.start = "node index.js";
892
+ writeFileSync("package.json", JSON.stringify(packageJson, null, 2));
893
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "continum",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
4
4
  "description": "Interactive CLI to set up Continum SDK in your project",
5
5
  "type": "module",
6
6
  "bin": {
@@ -12,7 +12,9 @@
12
12
  "scripts": {
13
13
  "build": "tsup src/index.ts --format esm --dts --clean",
14
14
  "dev": "tsup src/index.ts --format esm --watch",
15
- "test": "vitest"
15
+ "test": "vitest",
16
+ "prepublishOnly": "npm run build",
17
+ "publish":"npm run build && npm publish"
16
18
  },
17
19
  "keywords": [
18
20
  "continum",