@tscircuit/cli 0.1.26 → 0.1.28

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,15 @@
1
+ import fs from "fs"
2
+
3
+ // Detect the package manager being used in the project
4
+ export const detectPackageManager = (): string => {
5
+ const userAgent = process.env.npm_config_user_agent || ""
6
+ if (userAgent.startsWith("yarn")) return "yarn"
7
+ if (userAgent.startsWith("pnpm")) return "pnpm"
8
+ if (userAgent.startsWith("bun")) return "bun"
9
+
10
+ if (fs.existsSync("yarn.lock")) return "yarn"
11
+ if (fs.existsSync("pnpm-lock.yaml")) return "pnpm"
12
+ if (fs.existsSync("bun.lockb")) return "bun"
13
+
14
+ return "npm" // Default to npm
15
+ }
@@ -0,0 +1,34 @@
1
+ import path from "path"
2
+ import fs from "fs"
3
+
4
+ // Generate a React-compatible tsconfig.json
5
+ export const generateTsConfig = (dir: string) => {
6
+ const tsconfigPath = path.join(dir, "tsconfig.json")
7
+ const tsconfigContent = JSON.stringify(
8
+ {
9
+ compilerOptions: {
10
+ target: "ES6",
11
+ module: "ESNext",
12
+ jsx: "react-jsx",
13
+ outDir: "dist",
14
+ strict: true,
15
+ esModuleInterop: true,
16
+ moduleResolution: "node",
17
+ skipLibCheck: true,
18
+ forceConsistentCasingInFileNames: true,
19
+ resolveJsonModule: true,
20
+ sourceMap: true,
21
+ allowSyntheticDefaultImports: true,
22
+ experimentalDecorators: true,
23
+ },
24
+ },
25
+ null,
26
+ 2,
27
+ )
28
+ if (!fs.existsSync(tsconfigPath)) {
29
+ fs.writeFileSync(tsconfigPath, tsconfigContent.trimStart())
30
+ console.log(`Created: ${tsconfigPath}`)
31
+ } else {
32
+ console.log(`Skipped: ${tsconfigPath} already exists`)
33
+ }
34
+ }
@@ -0,0 +1,68 @@
1
+ import { detectPackageManager } from "./detect-pkg-manager"
2
+ const fs = require("fs")
3
+ const path = require("path")
4
+ const { execSync } = require("child_process")
5
+
6
+ /**
7
+ * Initializes a project in the specified directory, reads its name, and installs dependencies.
8
+ *
9
+ * @param {string} packageManager - Package manager to use (npm, yarn, pnpm, bun).
10
+ * @param {string[]} dependencies - List of dependencies to install.
11
+ * @param {string} directory - Directory where the project should be initialized.
12
+ */
13
+ export function setupTsciProject(
14
+ directory = process.cwd(),
15
+ dependencies = ["@types/react", "@tscircuit/core"],
16
+ ) {
17
+ const projectPath = path.resolve(directory)
18
+ if (!fs.existsSync(projectPath)) {
19
+ fs.mkdirSync(projectPath, { recursive: true })
20
+ }
21
+ const packageManager = detectPackageManager()
22
+
23
+ console.log(`Initializing project in ${projectPath}...`)
24
+ process.chdir(projectPath)
25
+
26
+ if (!fs.existsSync("package.json")) {
27
+ const initCommand =
28
+ packageManager === "yarn"
29
+ ? "yarn init -y"
30
+ : packageManager === "pnpm"
31
+ ? "pnpm init"
32
+ : packageManager === "bun"
33
+ ? "bun init -y"
34
+ : "npm init -y"
35
+
36
+ execSync(initCommand, { stdio: "inherit" })
37
+ console.log("Project initialized successfully.")
38
+ }
39
+
40
+ // Read and modify package.json
41
+ const packageJsonPath = path.join(projectPath, "package.json")
42
+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf-8"))
43
+
44
+ // Remove unwanted fields
45
+ delete packageJson.keywords
46
+ delete packageJson.author
47
+ delete packageJson.main
48
+
49
+ fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2))
50
+ console.log("Updated package.json to remove unnecessary fields.")
51
+
52
+ if (dependencies.length > 0) {
53
+ console.log("Installing dependencies...")
54
+ const installCommand =
55
+ packageManager === "yarn"
56
+ ? `yarn add -D ${dependencies.join(" ")}`
57
+ : packageManager === "pnpm"
58
+ ? `pnpm add -D ${dependencies.join(" ")}`
59
+ : packageManager === "bun"
60
+ ? `bun add -D ${dependencies.join(" ")}`
61
+ : `npm install -D ${dependencies.join(" ")}`
62
+
63
+ execSync(installCommand, { stdio: "inherit" })
64
+ console.log("Dependencies installed successfully.")
65
+ }
66
+
67
+ return packageJson.name || "unknown"
68
+ }
@@ -0,0 +1,10 @@
1
+ import fs from "fs"
2
+
3
+ export const writeFileIfNotExists = (filePath: string, content: string) => {
4
+ if (!fs.existsSync(filePath)) {
5
+ fs.writeFileSync(filePath, content.trimStart(), "utf-8")
6
+ console.info(`Created: ${filePath}`)
7
+ } else {
8
+ console.info(`Skipped: ${filePath} already exists`)
9
+ }
10
+ }
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@tscircuit/cli",
3
3
  "main": "dist/main.js",
4
4
  "type": "module",
5
- "version": "0.1.26",
5
+ "version": "0.1.28",
6
6
  "bin": {
7
7
  "tsci": "./dist/main.js"
8
8
  },