Skip to content

Commit

Permalink
Move project prompts to rust
Browse files Browse the repository at this point in the history
  • Loading branch information
oovm committed Jan 29, 2025
1 parent 6cb4277 commit 2998089
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 60 deletions.
8 changes: 7 additions & 1 deletion projects/npx-create-rs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,17 @@ use clap::Parser;

mod types;

pub use crate::types::{ProjectType, PackageType};
pub use crate::types::{PackageType, ProjectType};

#[derive(Debug, Parser)]
#[command(version, about, long_about = None)]
pub struct LegionCLI {
/// The project directory
target: Option<String>,
#[arg(long)]
name: Option<String>,
#[arg(long)]
project_type: Option<ProjectType>,
#[arg(long)]
package_type: Option<PackageType>,
}
5 changes: 3 additions & 2 deletions projects/npx-create-rs/src/types/mod.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
use crate::NpxError;
use dialoguer::{Select, theme::ColorfulTheme};
use std::fmt::{Display, Formatter};
use clap::ValueEnum;

mod package_type;
mod project_type;

#[derive(Copy, Clone, Debug)]
#[derive(Copy, Clone, Debug, ValueEnum)]
pub enum ProjectType {
Workspace,
Package,
}
#[derive(Copy, Clone, Debug)]
#[derive(Copy, Clone, Debug, ValueEnum)]
pub enum PackageType {
Library,
Commands,
Expand Down
58 changes: 1 addition & 57 deletions projects/npx-wasm32-wasi/src/copyTemplate.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import prompts from "prompts";
import {basename, dirname, resolve} from "node:path";
import {fileURLToPath} from "node:url";
import {basename, resolve} from "node:path";
import {cp, readFile, writeFile} from "node:fs/promises";
import chalk from "chalk";

Expand All @@ -19,60 +17,6 @@ import chalk from "chalk";
* @returns {Promise<CopyTemplate>}
*/
export async function copyTemplate (target, here, pkg) {
const {name, useWorkspace} = await prompts([
{
name: "name",
type: "text",
message: "What is the project name?",
initial: pkg,
},
{
name: "useWorkspace",
type: "select",
initial: 1,
message: "Do you want to make a workspace?",
choices: [
{
title: "πŸ“š Workspace",
value: true,
},
{
title: "πŸ“— Package",
value: false,
},
],
}
]);
let isBinary = false;

if (!useWorkspace) {
const {isLibrary} = await prompts([
{
name: "isLibrary",
type: "select",
initial: 0,
message: "What kind of project is this?",
choices: [
{
title: "πŸŽ“ Library",
value: false,
},
{
title: "πŸ“Ÿ Commands",
value: true,
},
],
}
]
)
isBinary = !isLibrary
}
const options = {
name,
useWorkspace,
isBinary
}

let source;
if (options.useWorkspace) {
source = resolve(here, "template/workspace");
Expand Down

0 comments on commit 2998089

Please sign in to comment.