Comparing version 1.0.0 to 1.0.15
#!/usr/bin/env node | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
@@ -12,188 +11,103 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const commander_1 = require("commander"); | ||
const promises_1 = __importDefault(require("fs/promises")); | ||
const path_1 = __importDefault(require("path")); | ||
const child_process_1 = require("child_process"); | ||
const chalk_1 = __importDefault(require("chalk")); | ||
function createProjectStructure(projectPath, projectName, options) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
// Create project directory | ||
yield promises_1.default.mkdir(projectPath, { recursive: true }); | ||
// Create package.json | ||
const packageJson = { | ||
name: projectName, | ||
version: "1.0.0", | ||
private: true, | ||
scripts: { | ||
start: options.template === "react" | ||
? "react-scripts start" | ||
: "ts-node src/index.ts", | ||
build: options.template === "react" ? "react-scripts build" : "tsc", | ||
test: "jest", | ||
eject: options.template === "react" ? "react-scripts eject" : "", | ||
}, | ||
}; | ||
// Add dependencies based on template | ||
packageJson.dependencies = {}; | ||
packageJson.devDependencies = { | ||
typescript: "^5.0.0", | ||
"@types/node": "^18.0.0", | ||
"ts-node": "^10.9.0", | ||
jest: "^29.0.0", | ||
"@types/jest": "^29.0.0", | ||
}; | ||
if (options.template === "react") { | ||
packageJson.dependencies = { | ||
react: "^18.2.0", | ||
"react-dom": "^18.2.0", | ||
"react-scripts": "^5.0.1", | ||
}; | ||
packageJson.devDependencies = Object.assign(Object.assign({}, packageJson.devDependencies), { "@types/react": "^18.2.0", "@types/react-dom": "^18.2.0" }); | ||
} | ||
// Write package.json | ||
yield promises_1.default.writeFile(path_1.default.join(projectPath, "package.json"), JSON.stringify(packageJson, null, 2)); | ||
// Create TypeScript configuration | ||
const tsConfig = { | ||
compilerOptions: { | ||
target: "es2020", | ||
module: "commonjs", | ||
strict: true, | ||
esModuleInterop: true, | ||
skipLibCheck: true, | ||
forceConsistentCasingInFileNames: true, | ||
outDir: "./dist", | ||
rootDir: "./src", | ||
jsx: options.template === "react" ? "react-jsx" : undefined, | ||
}, | ||
include: ["src/**/*"], | ||
exclude: ["node_modules", "**/*.test.ts"], | ||
}; | ||
yield promises_1.default.writeFile(path_1.default.join(projectPath, "tsconfig.json"), JSON.stringify(tsConfig, null, 2)); | ||
// Create project structure | ||
yield promises_1.default.mkdir(path_1.default.join(projectPath, "src")); | ||
yield promises_1.default.mkdir(path_1.default.join(projectPath, "src", "components"), { | ||
recursive: true, | ||
}); | ||
yield promises_1.default.mkdir(path_1.default.join(projectPath, "src", "types"), { recursive: true }); | ||
// Create template files | ||
if (options.template === "react") { | ||
// Create App.tsx | ||
yield promises_1.default.writeFile(path_1.default.join(projectPath, "src", "App.tsx"), `import React from 'react'; | ||
interface AppProps { | ||
title?: string; | ||
} | ||
export default function App({ title = '${projectName}' }: AppProps): JSX.Element { | ||
return ( | ||
<div> | ||
<h1>Welcome to {title}</h1> | ||
</div> | ||
); | ||
} | ||
`); | ||
// Create index.tsx | ||
yield promises_1.default.writeFile(path_1.default.join(projectPath, "src", "index.tsx"), `import React from 'react'; | ||
import ReactDOM from 'react-dom/client'; | ||
import App from './App'; | ||
const root = ReactDOM.createRoot( | ||
document.getElementById('root') as HTMLElement | ||
); | ||
root.render( | ||
<React.StrictMode> | ||
<App /> | ||
</React.StrictMode> | ||
); | ||
`); | ||
} | ||
else { | ||
// Create index.ts for Node projects | ||
yield promises_1.default.writeFile(path_1.default.join(projectPath, "src", "index.ts"), `interface AppConfig { | ||
name: string; | ||
version: string; | ||
} | ||
const config: AppConfig = { | ||
name: '${projectName}', | ||
version: '1.0.0' | ||
}; | ||
console.log(\`Welcome to \${config.name} v\${config.version}\`); | ||
`); | ||
} | ||
// Create types file | ||
yield promises_1.default.writeFile(path_1.default.join(projectPath, "src", "types", "index.ts"), `export interface CommonTypes { | ||
id: string; | ||
createdAt: Date; | ||
updatedAt: Date; | ||
} | ||
`); | ||
// Initialize git if requested | ||
if (options.git) { | ||
(0, child_process_1.execSync)("git init", { cwd: projectPath }); | ||
yield promises_1.default.writeFile(path_1.default.join(projectPath, ".gitignore"), "node_modules\ndist\n.DS_Store\n*.log\n"); | ||
} | ||
// Create README.md | ||
yield promises_1.default.writeFile(path_1.default.join(projectPath, "README.md"), `# ${projectName} | ||
## Description | ||
A TypeScript ${options.template} project. | ||
## Installation | ||
\`\`\`bash | ||
npm install | ||
\`\`\` | ||
## Development | ||
\`\`\`bash | ||
npm start | ||
\`\`\` | ||
## Build | ||
\`\`\`bash | ||
npm run build | ||
\`\`\` | ||
## Test | ||
\`\`\`bash | ||
npm test | ||
\`\`\` | ||
`); | ||
import { program } from "commander"; | ||
import fs from "fs-extra/esm"; | ||
import { existsSync, readdirSync, readFileSync } from "fs"; | ||
import path from "path"; | ||
import { fileURLToPath } from "url"; | ||
import { dirname } from "path"; | ||
import chalk from "chalk"; | ||
import { execSync } from "child_process"; | ||
import os from "os"; | ||
import ignore from "ignore"; | ||
const __filename = fileURLToPath(import.meta.url); | ||
const __dirname = dirname(__filename); | ||
console.log("Welcome to bb9!"); | ||
program | ||
.name("bb9") | ||
.description("CLI to run stagehand projects in NextJS") | ||
.version("1.0.0"); | ||
program | ||
.command("run") | ||
.description("Run the current stagehand project in NextJS") | ||
.action(() => __awaiter(void 0, void 0, void 0, function* () { | ||
try { | ||
const currentDir = process.cwd(); | ||
const bb9Dir = path.join(os.homedir(), ".bb9"); | ||
const nextAppDir = path.join(bb9Dir, "next-app"); | ||
const stagehandDir = path.join(nextAppDir, "stagehand"); | ||
// Create bb9 directory if it doesn't exist | ||
if (!existsSync(bb9Dir)) { | ||
console.log(chalk.blue("Creating bb9 directory...")); | ||
fs.mkdirsSync(bb9Dir); | ||
} | ||
catch (error) { | ||
throw new Error(`Failed to create project structure: ${error}`); | ||
else { | ||
console.log(chalk.blue("bb9 directory already exists")); | ||
} | ||
}); | ||
} | ||
commander_1.program | ||
.name("create-my-app") | ||
.description("CLI to scaffold a new TypeScript application") | ||
.version("1.0.0") | ||
.argument("<project-name>", "Name of the project") | ||
.option("-t, --template <type>", "project template type (react, node)", "react") | ||
.option("--git", "initialize git repository", false) | ||
.action((projectName, options) => __awaiter(void 0, void 0, void 0, function* () { | ||
try { | ||
const projectPath = path_1.default.join(process.cwd(), projectName); | ||
// Force typescript to true since this is a TypeScript template | ||
options.typescript = true; | ||
yield createProjectStructure(projectPath, projectName, options); | ||
console.log(chalk_1.default.green(`✨ Successfully created TypeScript project ${projectName}`)); | ||
console.log(chalk_1.default.blue("\nNext steps:")); | ||
console.log(` cd ${projectName}`); | ||
console.log(" npm install"); | ||
console.log(" npm start"); | ||
// Verify or create NextJS app | ||
if (existsSync(nextAppDir)) { | ||
console.log(chalk.blue("Removing existing Next.js app...")); | ||
fs.removeSync(nextAppDir); | ||
} | ||
console.log(chalk.blue("Setting up Next.js app...")); | ||
fs.mkdirsSync(bb9Dir); | ||
// Clone the stagehand-nextjs-starter repo | ||
const tmpDir = path.join(bb9Dir, "tmp"); | ||
fs.mkdirsSync(tmpDir); | ||
process.chdir(tmpDir); | ||
console.log(chalk.blue("Cloning stagehand-nextjs-starter...")); | ||
execSync("git clone https://github.com/browserbase/stagehand-next-starter.git next-app", { stdio: "inherit" }); | ||
// Move the next-app to bb9 directory | ||
fs.moveSync(path.join(tmpDir, "next-app"), nextAppDir, { | ||
overwrite: true, | ||
}); | ||
fs.removeSync(tmpDir); | ||
// Install dependencies | ||
process.chdir(nextAppDir); | ||
console.log(chalk.blue("Installing dependencies...")); | ||
execSync("npm install", { stdio: "inherit" }); | ||
// Create stagehand directory if it doesn't exist | ||
if (!existsSync(stagehandDir)) { | ||
fs.mkdirsSync(stagehandDir); | ||
} | ||
// Initialize ignore patterns | ||
const ig = ignore.default(); | ||
// Add default ignore patterns | ||
ig.add([ | ||
"package.json", | ||
"package-lock.json", | ||
"yarn.lock", | ||
"pnpm-lock.yaml", | ||
".DS_Store", | ||
"node_modules", | ||
".git", | ||
]); | ||
// Add patterns from .gitignore if it exists | ||
if (existsSync(path.join(currentDir, ".gitignore"))) { | ||
const gitignoreContent = readFileSync(path.join(currentDir, ".gitignore"), "utf8"); | ||
ig.add(gitignoreContent); | ||
} | ||
// Get list of files to copy | ||
const allFiles = readdirSync(currentDir); | ||
const filesToCopy = allFiles.filter((file) => !ig.ignores(file)); | ||
// Clear existing stagehand directory | ||
fs.emptyDirSync(stagehandDir); | ||
// Copy files to stagehand directory | ||
console.log(chalk.blue("Copying project to stagehand directory...")); | ||
for (const file of filesToCopy) { | ||
const sourcePath = path.join(currentDir, file); | ||
const destPath = path.join(stagehandDir, file); | ||
fs.copySync(sourcePath, destPath); | ||
} | ||
// Start the Next.js development server | ||
console.log(chalk.green("Starting Next.js development server...")); | ||
process.chdir(nextAppDir); | ||
execSync("npm run build", { stdio: "inherit" }); | ||
execSync("npm run dev", { stdio: "inherit" }); | ||
} | ||
catch (error) { | ||
console.error(chalk_1.default.red("Error creating project:"), error); | ||
if (error instanceof Error) | ||
console.error(chalk.red("Error:", error.message)); | ||
process.exit(1); | ||
} | ||
})); | ||
commander_1.program.parse(); | ||
program.parse(); |
{ | ||
"name": "bb9", | ||
"version": "1.0.0", | ||
"version": "1.0.15", | ||
"description": "", | ||
@@ -13,2 +13,4 @@ "main": "index.js", | ||
"commander": "^12.1.0", | ||
"fs-extra": "^11.3.0", | ||
"ignore": "^5.3.1", | ||
"path": "^0.12.7", | ||
@@ -18,3 +20,7 @@ "typescript": "^5.7.2" | ||
"devDependencies": { | ||
"@types/node": "^22.10.2" | ||
"@browserbasehq/stagehand": "^1.6.0", | ||
"@changesets/cli": "^2.27.10", | ||
"@types/fs-extra": "^11.0.4", | ||
"@types/node": "^22.10.2", | ||
"tsx": "^4.19.2" | ||
}, | ||
@@ -25,8 +31,18 @@ "bin": { | ||
"files": [ | ||
"dist" | ||
"dist", | ||
"examples" | ||
], | ||
"scripts": { | ||
"build": "tsc", | ||
"prepare": "npm run build" | ||
"postbuild": "node -e \"require('fs').chmodSync('./dist/index.js', '755')\"", | ||
"prepare": "npm run build", | ||
"changeset": "changeset", | ||
"version": "changeset version", | ||
"release": "npm run version && npm run build && changeset publish", | ||
"dev": "tsx src/index.ts" | ||
}, | ||
"type": "module", | ||
"publishConfig": { | ||
"access": "public" | ||
} | ||
} |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 2 instances in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Yes
5767
7
5
112
3
2
+ Addedfs-extra@^11.3.0
+ Addedignore@^5.3.1
+ Addedfs-extra@11.3.0(transitive)
+ Addedgraceful-fs@4.2.11(transitive)
+ Addedignore@5.3.2(transitive)
+ Addedjsonfile@6.1.0(transitive)
+ Addeduniversalify@2.0.1(transitive)