diff --git a/bin/create-maizzle.mjs b/bin/create-maizzle.mjs new file mode 100644 index 0000000..0e415e3 --- /dev/null +++ b/bin/create-maizzle.mjs @@ -0,0 +1,5 @@ +#!/usr/bin/env node + +import { main } from '../src/index.js' + +main().catch(console.error) diff --git a/package-lock.json b/package-lock.json index d916c78..44d5b08 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,6 +10,7 @@ "license": "MIT", "dependencies": { "@clack/prompts": "^0.7.0", + "degit": "^2.8.4", "picocolors": "^1.0.0" } }, @@ -47,6 +48,17 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/degit": { + "version": "2.8.4", + "resolved": "https://registry.npmjs.org/degit/-/degit-2.8.4.tgz", + "integrity": "sha512-vqYuzmSA5I50J882jd+AbAhQtgK6bdKUJIex1JNfEUPENCgYsxugzKVZlFyMwV4i06MmnV47/Iqi5Io86zf3Ng==", + "bin": { + "degit": "degit" + }, + "engines": { + "node": ">=8.0.0" + } + }, "node_modules/picocolors": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.0.0.tgz", diff --git a/package.json b/package.json index 691883a..82e7bb9 100644 --- a/package.json +++ b/package.json @@ -1,20 +1,28 @@ { - "name": "create-maizzle", - "version": "0.0.1", - "description": "Quickly start a new Maizzle project.", - "license": "MIT", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 0" - }, - "repository": { - "type": "git", - "url": "https://github.com/maizzle/framework.git" - }, - "bugs": "https://github.com/maizzle/framework/issues", - "homepage": "https://maizzle.com", - "author": "Cosmin Popovici (https://github.com/cossssmin)", - "dependencies": { - "@clack/prompts": "^0.7.0", - "picocolors": "^1.0.0" - } + "name": "create-maizzle", + "version": "0.0.1", + "description": "Quickly start a new Maizzle project.", + "license": "MIT", + "type": "module", + "bin": { + "create-maizzle": "bin/create-maizzle.mjs" + }, + "files": [ + "bin" + ], + "scripts": { + "test": "echo \"Error: no test specified\" && exit 0" + }, + "repository": { + "type": "git", + "url": "https://github.com/maizzle/framework.git" + }, + "bugs": "https://github.com/maizzle/framework/issues", + "homepage": "https://maizzle.com", + "author": "Cosmin Popovici (https://github.com/cossssmin)", + "dependencies": { + "@clack/prompts": "^0.7.0", + "degit": "^2.8.4", + "picocolors": "^1.0.0" + } } diff --git a/src/index.js b/src/index.js new file mode 100644 index 0000000..9eeb50c --- /dev/null +++ b/src/index.js @@ -0,0 +1,93 @@ +import degit from 'degit'; +import color from 'picocolors'; +import * as p from '@clack/prompts'; +import { setTimeout } from 'node:timers/promises'; + +export async function main() { + console.clear(); + + p.intro(`${color.bgCyan(color.black(' create-maizzle '))}`); + + const project = await p.group( + { + path: () => + p.text({ + message: 'Where should we create your project?', + placeholder: './maizzle', + validate: value => { + if (!value) return 'Please enter a path.'; + if (value[0] !== '.') return 'Please enter a relative path.'; + }, + }), + starter: async () => { + const starter = await p.select({ + message: 'Select a Starter', + initialValue: 'default', + options: [ + { value: 'default', label: 'Default' }, + { value: 'custom', label: 'Custom' }, + ], + }); + + if (starter === 'custom') { + const starters = await p.select({ + message: 'Select a custom Starter', + initialValue: 'default', + options: [ + { value: 'api', label: 'API' }, + { value: 'amp', label: 'AMP4Email' }, + { value: 'mc', label: 'Mailchimp' }, + { value: 'md', label: 'Markdown' }, + { value: 'wp', label: 'WordPress API' }, + { value: 'git', label: 'Git', hint: 'provide a git url' }, + ], + }); + + if (starters === 'git') { + const url = await p.text({ + message: 'Enter a Git repository url', + validate: value => { + if (!value) return 'Please enter a Git repository url.'; + if (!value.endsWith('.git')) return 'Please include the .git extension.'; + }, + }); + return console.log(url); + } + + return starters; + } + }, + install: () => + p.confirm({ + message: 'Install dependencies?', + initialValue: true, + }), + }, + { + onCancel: () => { + p.cancel('💀'); + process.exit(0); + }, + } + ); + + if (project.install) { + const s = p.spinner(); + s.start('Installing dependencies'); + + await setTimeout(2500); + s.stop('Installed dependencies'); + } + + let nextSteps = `cd ${project.path} \n${project.install ? '' : 'npm install\n'}npm run dev`; + + p.note(nextSteps, 'Next steps.'); + + p.outro(`Join the community: ${color.underline(color.cyan('https://maizzle.com/discord'))} + + Documentation: ${color.underline(color.cyan('https://maizzle.com/docs'))} + + Problems? ${color.underline(color.cyan('https://maizzle.com/issues'))}` + ); + +}