Skip to content

Commit

Permalink
Merge branch 'horuslabsio:main' into frontend-redesign
Browse files Browse the repository at this point in the history
  • Loading branch information
Oshioke-Salaki authored Aug 5, 2024
2 parents d41daae + d1a23c8 commit a76eef8
Show file tree
Hide file tree
Showing 4 changed files with 141 additions and 127 deletions.
10 changes: 1 addition & 9 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,7 @@ git clone [email protected]: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.

Expand Down
250 changes: 136 additions & 114 deletions bin/cli.mjs
Original file line number Diff line number Diff line change
@@ -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();
Binary file modified contracts/.DS_Store
Binary file not shown.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand All @@ -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",
Expand All @@ -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"
}
Expand Down

0 comments on commit a76eef8

Please sign in to comment.