@reactor-team/js-sdk 1.0.3 → 1.0.4

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.
@@ -0,0 +1,140 @@
1
+ #!/usr/bin/env node
2
+ import inquirer from "inquirer";
3
+ import { execSync } from "child_process";
4
+ import simpleGit from "simple-git";
5
+ import fs from "fs";
6
+ import path from "path";
7
+ import chalk from "chalk";
8
+
9
+ const REPO = "https://github.com/reactor-team/js-sdk.git";
10
+ const EXAMPLES_PATH = "examples";
11
+
12
+ async function getTemplates(): Promise<string[]> {
13
+ try {
14
+ const res = await fetch(
15
+ `https://api.github.com/repos/reactor-team/js-sdk/contents/${EXAMPLES_PATH}`
16
+ );
17
+ const data = (await res.json()) as { name: string; type: string }[];
18
+ return data.filter((item) => item.type === "dir").map((item) => item.name);
19
+ } catch {
20
+ console.log(
21
+ chalk.yellow("⚠️ Could not fetch from GitHub, using fallback templates.")
22
+ );
23
+ return ["longlive", "matrix-2"];
24
+ }
25
+ }
26
+
27
+ function showUsage(): void {
28
+ console.log(chalk.cyan("\n🧩 Create Reactor App\n"));
29
+ console.log(chalk.white("Usage:"));
30
+ console.log(chalk.white(" create-reactor-app [project-name] [template]\n"));
31
+ console.log(chalk.white("Arguments:"));
32
+ console.log(chalk.white(" project-name Name of the project to create"));
33
+ console.log(
34
+ chalk.white(
35
+ " template Template to use (longlive, matrix-2, mk64, etc.)\n"
36
+ )
37
+ );
38
+ console.log(
39
+ chalk.white(
40
+ "If arguments are not provided, you will be prompted interactively.\n"
41
+ )
42
+ );
43
+ }
44
+
45
+ async function main(): Promise<void> {
46
+ const args = process.argv.slice(2);
47
+
48
+ // Show help if requested
49
+ if (args.includes("--help") || args.includes("-h")) {
50
+ showUsage();
51
+ process.exit(0);
52
+ }
53
+
54
+ console.log(chalk.cyan("\n🧩 Create Reactor App\n"));
55
+
56
+ const templates = await getTemplates();
57
+
58
+ // Parse command line arguments
59
+ const [argProjectName, argTemplate] = args;
60
+
61
+ // Validate template argument if provided
62
+ if (argTemplate && !templates.includes(argTemplate)) {
63
+ console.error(chalk.red(`Template "${argTemplate}" is not available.`));
64
+ console.log(chalk.white("Available templates:"), templates.join(", "));
65
+ process.exit(1);
66
+ }
67
+
68
+ // Prepare prompts, skipping those with provided arguments
69
+ const prompts: any[] = [];
70
+
71
+ if (!argProjectName) {
72
+ prompts.push({
73
+ type: "input",
74
+ name: "projectName",
75
+ message: "Enter your project name:",
76
+ validate: (input: string) =>
77
+ input ? true : "Project name cannot be empty.",
78
+ });
79
+ }
80
+
81
+ if (!argTemplate) {
82
+ prompts.push({
83
+ type: "list",
84
+ name: "template",
85
+ message: "Select a template:",
86
+ choices: templates,
87
+ });
88
+ }
89
+
90
+ // Get answers from prompts (if any are needed)
91
+ const answers = prompts.length > 0 ? await inquirer.prompt(prompts) : {};
92
+
93
+ // Use provided arguments or prompted answers
94
+ const projectName = argProjectName || answers.projectName;
95
+ const template = argTemplate || answers.template;
96
+ const dest = path.resolve(process.cwd(), projectName);
97
+
98
+ if (fs.existsSync(dest)) {
99
+ console.error(chalk.red(`Folder "${projectName}" already exists.`));
100
+ process.exit(1);
101
+ }
102
+
103
+ console.log(chalk.green(`\nCloning template "${template}"...\n`));
104
+
105
+ const git = simpleGit();
106
+ await git.clone(REPO, projectName, ["--depth", "1"]);
107
+
108
+ const examplesDir = path.join(dest, EXAMPLES_PATH);
109
+ const templateDir = path.join(examplesDir, template);
110
+
111
+ if (!fs.existsSync(templateDir)) {
112
+ console.error(chalk.red(`Template "${template}" not found.`));
113
+ process.exit(1);
114
+ }
115
+
116
+ // Move files up
117
+ for (const file of fs.readdirSync(templateDir)) {
118
+ fs.renameSync(path.join(templateDir, file), path.join(dest, file));
119
+ }
120
+
121
+ fs.rmSync(examplesDir, { recursive: true, force: true });
122
+ fs.rmSync(path.join(dest, ".git"), { recursive: true, force: true });
123
+
124
+ console.log(chalk.yellow("\nInstalling dependencies...\n"));
125
+ execSync("pnpm install", { cwd: dest, stdio: "inherit" });
126
+
127
+ console.log(
128
+ chalk.green(
129
+ `\n✅ Project "${projectName}" created successfully using "${template}" template!\n`
130
+ )
131
+ );
132
+ console.log(chalk.cyan("Next steps:"));
133
+ console.log(chalk.white(` cd ${projectName}`));
134
+ console.log(chalk.white(` pnpm dev\n`));
135
+ }
136
+
137
+ main().catch((err) => {
138
+ console.error(chalk.red("Error:"), err);
139
+ process.exit(1);
140
+ });
@@ -0,0 +1,137 @@
1
+ #!/usr/bin/env node
2
+ var __async = (__this, __arguments, generator) => {
3
+ return new Promise((resolve, reject) => {
4
+ var fulfilled = (value) => {
5
+ try {
6
+ step(generator.next(value));
7
+ } catch (e) {
8
+ reject(e);
9
+ }
10
+ };
11
+ var rejected = (value) => {
12
+ try {
13
+ step(generator.throw(value));
14
+ } catch (e) {
15
+ reject(e);
16
+ }
17
+ };
18
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
19
+ step((generator = generator.apply(__this, __arguments)).next());
20
+ });
21
+ };
22
+ import inquirer from "inquirer";
23
+ import { execSync } from "child_process";
24
+ import simpleGit from "simple-git";
25
+ import fs from "fs";
26
+ import path from "path";
27
+ import chalk from "chalk";
28
+ const REPO = "https://github.com/reactor-team/js-sdk.git";
29
+ const EXAMPLES_PATH = "examples";
30
+ function getTemplates() {
31
+ return __async(this, null, function* () {
32
+ try {
33
+ const res = yield fetch(
34
+ `https://api.github.com/repos/reactor-team/js-sdk/contents/${EXAMPLES_PATH}`
35
+ );
36
+ const data = yield res.json();
37
+ return data.filter((item) => item.type === "dir").map((item) => item.name);
38
+ } catch (e) {
39
+ console.log(
40
+ chalk.yellow("\u26A0\uFE0F Could not fetch from GitHub, using fallback templates.")
41
+ );
42
+ return ["longlive", "matrix-2"];
43
+ }
44
+ });
45
+ }
46
+ function showUsage() {
47
+ console.log(chalk.cyan("\n\u{1F9E9} Create Reactor App\n"));
48
+ console.log(chalk.white("Usage:"));
49
+ console.log(chalk.white(" create-reactor-app [project-name] [template]\n"));
50
+ console.log(chalk.white("Arguments:"));
51
+ console.log(chalk.white(" project-name Name of the project to create"));
52
+ console.log(
53
+ chalk.white(
54
+ " template Template to use (longlive, matrix-2, mk64, etc.)\n"
55
+ )
56
+ );
57
+ console.log(
58
+ chalk.white(
59
+ "If arguments are not provided, you will be prompted interactively.\n"
60
+ )
61
+ );
62
+ }
63
+ function main() {
64
+ return __async(this, null, function* () {
65
+ const args = process.argv.slice(2);
66
+ if (args.includes("--help") || args.includes("-h")) {
67
+ showUsage();
68
+ process.exit(0);
69
+ }
70
+ console.log(chalk.cyan("\n\u{1F9E9} Create Reactor App\n"));
71
+ const templates = yield getTemplates();
72
+ const [argProjectName, argTemplate] = args;
73
+ if (argTemplate && !templates.includes(argTemplate)) {
74
+ console.error(chalk.red(`Template "${argTemplate}" is not available.`));
75
+ console.log(chalk.white("Available templates:"), templates.join(", "));
76
+ process.exit(1);
77
+ }
78
+ const prompts = [];
79
+ if (!argProjectName) {
80
+ prompts.push({
81
+ type: "input",
82
+ name: "projectName",
83
+ message: "Enter your project name:",
84
+ validate: (input) => input ? true : "Project name cannot be empty."
85
+ });
86
+ }
87
+ if (!argTemplate) {
88
+ prompts.push({
89
+ type: "list",
90
+ name: "template",
91
+ message: "Select a template:",
92
+ choices: templates
93
+ });
94
+ }
95
+ const answers = prompts.length > 0 ? yield inquirer.prompt(prompts) : {};
96
+ const projectName = argProjectName || answers.projectName;
97
+ const template = argTemplate || answers.template;
98
+ const dest = path.resolve(process.cwd(), projectName);
99
+ if (fs.existsSync(dest)) {
100
+ console.error(chalk.red(`Folder "${projectName}" already exists.`));
101
+ process.exit(1);
102
+ }
103
+ console.log(chalk.green(`
104
+ Cloning template "${template}"...
105
+ `));
106
+ const git = simpleGit();
107
+ yield git.clone(REPO, projectName, ["--depth", "1"]);
108
+ const examplesDir = path.join(dest, EXAMPLES_PATH);
109
+ const templateDir = path.join(examplesDir, template);
110
+ if (!fs.existsSync(templateDir)) {
111
+ console.error(chalk.red(`Template "${template}" not found.`));
112
+ process.exit(1);
113
+ }
114
+ for (const file of fs.readdirSync(templateDir)) {
115
+ fs.renameSync(path.join(templateDir, file), path.join(dest, file));
116
+ }
117
+ fs.rmSync(examplesDir, { recursive: true, force: true });
118
+ fs.rmSync(path.join(dest, ".git"), { recursive: true, force: true });
119
+ console.log(chalk.yellow("\nInstalling dependencies...\n"));
120
+ execSync("pnpm install", { cwd: dest, stdio: "inherit" });
121
+ console.log(
122
+ chalk.green(
123
+ `
124
+ \u2705 Project "${projectName}" created successfully using "${template}" template!
125
+ `
126
+ )
127
+ );
128
+ console.log(chalk.cyan("Next steps:"));
129
+ console.log(chalk.white(` cd ${projectName}`));
130
+ console.log(chalk.white(` pnpm dev
131
+ `));
132
+ });
133
+ }
134
+ main().catch((err) => {
135
+ console.error(chalk.red("Error:"), err);
136
+ process.exit(1);
137
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reactor-team/js-sdk",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "Reactor JavaScript frontend SDK",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -12,6 +12,9 @@
12
12
  "require": "./dist/index.js"
13
13
  }
14
14
  },
15
+ "bin": {
16
+ "create-reactor-app": "dist/bin/create-reactor-app.mjs"
17
+ },
15
18
  "keywords": [
16
19
  "reactor",
17
20
  "frontend",
@@ -20,15 +23,19 @@
20
23
  "author": "Reactor Technologies, Inc.",
21
24
  "license": "ISC",
22
25
  "devDependencies": {
26
+ "@types/inquirer": "^9.0.9",
23
27
  "@types/node": "^20",
24
- "@types/ws": "^8.18.1",
25
28
  "@types/react": "^18.2.8",
29
+ "@types/ws": "^8.18.1",
26
30
  "prettier": "^3.6.2",
27
31
  "tsup": "^8.5.0",
28
32
  "typescript": "^5.8.3"
29
33
  },
30
34
  "dependencies": {
35
+ "chalk": "^5.3.0",
36
+ "inquirer": "^9.3.0",
31
37
  "livekit-client": "^2.15.7",
38
+ "simple-git": "^3.24.0",
32
39
  "ws": "^8.18.3",
33
40
  "zod": "^4.0.5"
34
41
  },
package/tsconfig.json CHANGED
@@ -15,5 +15,5 @@
15
15
  "strict": true,
16
16
  "stripInternal": true
17
17
  },
18
- "include": ["src"]
18
+ "include": ["src", "bin"]
19
19
  }
package/tsup.config.ts CHANGED
@@ -1,15 +1,32 @@
1
1
  import { defineConfig } from "tsup";
2
2
 
3
- export default defineConfig({
4
- entry: ["src/index.ts"],
5
- format: ["cjs", "esm"],
6
- dts: {
3
+ export default defineConfig([
4
+ // Build the SDK
5
+ {
7
6
  entry: ["src/index.ts"],
8
- resolve: true,
7
+ format: ["cjs", "esm"],
8
+ dts: {
9
+ entry: ["src/index.ts"],
10
+ resolve: true,
11
+ },
12
+ splitting: false,
13
+ sourcemap: true,
14
+ clean: true,
15
+ outDir: "dist",
16
+ tsconfig: "tsconfig.json",
9
17
  },
10
- splitting: false,
11
- sourcemap: true,
12
- clean: true,
13
- outDir: "dist",
14
- tsconfig: "tsconfig.json",
15
- });
18
+
19
+ // Build the CLI (create-reactor-app)
20
+ {
21
+ entry: {
22
+ "bin/create-reactor-app": "bin/create-reactor-app.ts",
23
+ },
24
+ format: ["esm"],
25
+ splitting: false,
26
+ sourcemap: false,
27
+ clean: false,
28
+ outDir: "dist",
29
+ bundle: false,
30
+ tsconfig: "tsconfig.json",
31
+ },
32
+ ]);