diff --git a/Readme.md b/Readme.md index 35019dc..51308b2 100644 --- a/Readme.md +++ b/Readme.md @@ -23,15 +23,7 @@ git clone git@github.com:argentlabs/Starknet-Scaffold.git cd Starknet-Scaffold ``` -Or install using create-starknet-app (recommended). This takes in the name and boilerplate type. If you need a basic boilerplate with frontend UI components, specify the `basic` type else for full debugging suite, use `debugger`. e.g - -``` -npx create-starknet-app my-app debugger -``` -or -``` -npx create-starknet-app my-app basic -``` +Or install using create-starknet-app (recommended). This takes in the name and boilerplate type. If you need a basic fullstack boilerplate with frontend UI components, specify the `fullstack` type, if you need just contracts specify, `contract_only`, else for full debugging suite, use `debugger`. PS: defaults to debugger mode, if no type is specified. diff --git a/bin/cli.mjs b/bin/cli.mjs index a28b4b3..19cdc64 100755 --- a/bin/cli.mjs +++ b/bin/cli.mjs @@ -1,129 +1,151 @@ #!/usr/bin/env node +import readline from "readline"; import { promisify } from "util"; import cp from "child_process"; -import path from "path"; import fs from "fs"; -// cli spinners +import path from "path"; import ora from "ora"; +const git_repo = "https://github.com/horuslabsio/Starknet-Scaffold"; + // convert libs to promises const exec = promisify(cp.exec); const rm = promisify(fs.rm); -if (process.argv.length < 3) { - console.log("You have to provide an app name and optionally choose if you need a basic boilerplate or a full debugger."); - console.log("For example :"); - console.log(" npx create-starknetkit-app my-app basic"); - process.exit(1); -} - -const projectName = process.argv[2]; -const projectType = process.argv[3]; -const currentPath = process.cwd(); - -const projectPath = path.join(currentPath, projectName); - -// get github repo -const git_repo = "https://github.com/argentlabs/Starknet-Scaffold.git"; - -// create project directory -if (fs.existsSync(projectPath)) { - console.log(`The file ${projectName} already exist in the current directory, please give it another name.`); - process.exit(1); -} -else { - fs.mkdirSync(projectPath); -} - -try { - const gitSpinner = ora("Downloading files...").start(); - // clone the repo into the project folder -> creates the new boilerplate - await exec(`git clone --depth 1 ${git_repo} ${projectPath} --quiet`); - gitSpinner.succeed(); - - let basicCleanupTasks = []; - if (projectType === "basic") { - const FRONTEND_BASE_PATH = "frontend/src/app"; - const componentsToRemove = [ - "devnet", - `${FRONTEND_BASE_PATH}/burner`, - `${FRONTEND_BASE_PATH}/wikipedia`, - `${FRONTEND_BASE_PATH}/scaffold-deployer`, - `${FRONTEND_BASE_PATH}/address-book`, - `${FRONTEND_BASE_PATH}/components/Burner`, - `${FRONTEND_BASE_PATH}/components/BurnerWallet`, - `${FRONTEND_BASE_PATH}/components/ScaffoldDeployer`, - `${FRONTEND_BASE_PATH}/components/AssetTransferModal.tsx`, - `${FRONTEND_BASE_PATH}/components/ConnectionModal.tsx`, - `${FRONTEND_BASE_PATH}/components/ContractExecutionModal.tsx`, - ]; - basicCleanupTasks.push( - ...componentsToRemove.map((comp) => - rm(path.join(projectPath, comp), { +// Initialize readline interface +const rl = readline.createInterface({ + input: process.stdin, + output: process.stdout +}); + +// Function to ask questions in the terminal +const askQuestion = (question) => { + return new Promise((resolve) => rl.question(question, resolve)); +}; + +// Main function to clone the repo and setup the package +let projectPath; +const installPackage = async () => { + try { + // Ask for package name + const packageName = await askQuestion('Enter your package name: '); + + // Ask for package type + const packageTypeChoices = ['contract_only', 'fullstack', 'debugger']; + console.log('Available package types:'); + packageTypeChoices.forEach((type, index) => console.log(`${index + 1}. ${type}`)); + + let packageType; + while (!packageType) { + const packageTypeChoice = await askQuestion('Select the package type (1-3): '); + packageType = packageTypeChoices[parseInt(packageTypeChoice) - 1]; + if (!packageType) { + console.log('Invalid choice. Please select a valid package type.'); + } + } + + // create project directory + const currentPath = process.cwd(); + projectPath = path.join(currentPath, packageName); + + if (fs.existsSync(projectPath)) { + console.log(`The file ${projectName} already exist in the current directory, please give it another name.`); + process.exit(1); + } + else { + fs.mkdirSync(projectPath); + } + + // Clone the repository + const gitSpinner = ora("Downloading files...").start(); + // clone the repo into the project folder -> creates the new boilerplate + await exec(`git clone --depth 1 ${git_repo} ${projectPath} --quiet`); + gitSpinner.succeed(); + + let cleanupTasks = []; + let excluded_files = [".git", ".github", "CONTRIBUTING.md", "bin", "burner", "website", "docs", "CNAME"]; + + if (packageType === "fullstack") { + const FRONTEND_BASE_PATH = "frontend/src/app"; + const componentsToRemove = [ + `${FRONTEND_BASE_PATH}/burner`, + `${FRONTEND_BASE_PATH}/wikipedia`, + `${FRONTEND_BASE_PATH}/scaffold-deployer`, + `${FRONTEND_BASE_PATH}/address-book`, + `${FRONTEND_BASE_PATH}/components/Burner`, + `${FRONTEND_BASE_PATH}/components/BurnerWallet`, + `${FRONTEND_BASE_PATH}/components/ScaffoldDeployer`, + `${FRONTEND_BASE_PATH}/components/AssetTransferModal.tsx`, + `${FRONTEND_BASE_PATH}/components/ConnectionModal.tsx`, + `${FRONTEND_BASE_PATH}/components/ContractExecutionModal.tsx`, + ]; + cleanupTasks.push( + ...componentsToRemove.map((comp) => + rm(path.join(projectPath, comp), { + recursive: true, + force: true, + }), + ), + ...excluded_files.map((comp) => + rm(path.join(projectPath, comp), { + recursive: true, + force: true, + }), + ), + ); + } + else if (packageType == "contract_only") { + let componentsToRemove = [...excluded_files, "frontend", ".editorconfig"]; + cleanupTasks.push( + ...componentsToRemove.map((comp) => + rm(path.join(projectPath, comp), { recursive: true, force: true, - }), + }), ), - ); + ) + } + else { + cleanupTasks.push( + ...excluded_files.map((comp) => + rm(path.join(projectPath, comp), { + recursive: true, + force: true, + }), + ), + ); + } + + // remove useless files + const cleanSpinner = ora("Removing useless files").start(); + await Promise.all([ + ...cleanupTasks, + ]); + + process.chdir(projectPath); + // remove the packages needed for cli + await exec("npm uninstall ora cli-spinners"); + cleanSpinner.succeed(); + + // install dependencies + const npmSpinner = ora("Installing dependencies...").start(); + if(packageType !== "contract_only") { + await exec("npm run install --legacy-peer-deps"); + } + npmSpinner.succeed(); + + console.log("The installation is done!"); + console.log("You can now run the scaffold with:"); + console.log(` cd ${packageName}`); + console.log(` npm run start`); + + } catch (err) { + // clean up in case of error, so the user does not have to do it manually + fs.rmSync(projectPath, { recursive: true, force: true }); + console.error(`Error: ${err.message}`); + } finally { + rl.close(); } +}; - // remove useless files - const cleanSpinner = ora("Removing useless files").start(); - const rmGit = rm(path.join(projectPath, ".git"), { - recursive: true, - force: true, - }); - const rmGithub = rm(path.join(projectPath, ".github"), { - recursive: true, - force: true, - }); - const rmContributing = rm(path.join(projectPath, "CONTRIBUTING.md"), { - recursive: true, - force: true, - }); - const rmBin = rm(path.join(projectPath, "bin"), { - recursive: true, - force: true, - }); - const rmBurner = rm(path.join(projectPath, "burner"), { - recursive: true, - force: true, - }); - const rmWebsite = rm(path.join(projectPath, "website"), { - recursive: true, - force: true, - }); - const rmDocs = rm(path.join(projectPath, "docs"), { - recursive: true, - force: true, - }); - await Promise.all([ - rmGit, - rmBin, - rmGithub, - rmContributing, - rmBurner, - rmWebsite, - rmDocs, - ...basicCleanupTasks, - ]); - - process.chdir(projectPath); - // remove the packages needed for cli - await exec("npm uninstall ora cli-spinners"); - cleanSpinner.succeed(); - - // install dependencies - const npmSpinner = ora("Installing dependencies...").start(); - await exec("npm run install"); - npmSpinner.succeed(); - - console.log("The installation is done!"); - console.log("You can now run the scaffold with:"); - console.log(` cd ${projectName}`); - console.log(` npm run start`); -} catch (error) { - // clean up in case of error, so the user does not have to do it manually - fs.rmSync(projectPath, { recursive: true, force: true }); - console.log(error); -} +installPackage(); diff --git a/contracts/.DS_Store b/contracts/.DS_Store index 5d0b36c..23ff664 100644 Binary files a/contracts/.DS_Store and b/contracts/.DS_Store differ diff --git a/package.json b/package.json index a1a159e..31d176e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "create-starknet-app", - "version": "0.4.2", + "version": "0.4.5", "description": "An open-source starknet development stack", "bin": "./bin/cli.mjs", "scripts": { @@ -21,7 +21,7 @@ }, "repository": { "type": "git", - "url": "git+https://github.com/argentlabs/Starknet-Scaffold.git" + "url": "git+https://github.com/horuslabsio/Starknet-Scaffold" }, "keywords": [ "Starknet", @@ -32,9 +32,9 @@ "author": "Darlington Nnam", "license": "ISC", "bugs": { - "url": "https://github.com/argentlabs/Starknet-Scaffold/issues" + "url": "https://github.com/horuslabsio/Starknet-Scaffold/issues" }, - "homepage": "https://github.com/argentlabs/Starknet-Scaffold#readme", + "homepage": "https://github.com/horuslabsio/Starknet-Scaffold#readme", "dependencies": { "ora": "^8.0.1" }