Skip to content
This repository has been archived by the owner on Oct 30, 2024. It is now read-only.

Commit

Permalink
commands: add create
Browse files Browse the repository at this point in the history
  • Loading branch information
matildepark committed Apr 10, 2024
1 parent bf094f1 commit 88641b5
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/bin/commands/create.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { GluegunToolbox } from "gluegun"
import { simpleGit } from 'simple-git'

module.exports = {
name: 'create',
run: async (toolbox: GluegunToolbox) => {
const { filesystem, prompt } = toolbox

const name = await prompt.ask({
type: 'input',
name: 'name',
message: 'What do you want to name this project?',
}).then((answers) => answers.name)

// Ensure the folder doesn't already exist
if (filesystem.exists(name)) {
return toolbox.print.error(`Folder ${name} already exists`)
}

// validate the name to ensure it's npm compatible
if (!/^[a-z0-9-@]+$/.test(name)) {
return toolbox.print.error('Invalid folder name. Use @, lowercase, and dashes only.')
}
await simpleGit({
baseDir: process.cwd(),
binary: 'git',
maxConcurrentProcesses: 6,
}).clone('git@github.com:hdresearch/create.git', name)
filesystem.remove(`${name}/.git`)
},
}

0 comments on commit 88641b5

Please sign in to comment.