diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..eae14d7 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2021 Ayo Ayco + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/package-lock.json b/package-lock.json index 1934aa1..f751748 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3978,6 +3978,7 @@ "version": "0.1.2", "license": "MIT", "dependencies": { + "consola": "^3.2.3", "giget": "^1.1.3" }, "bin": { diff --git a/package.json b/package.json index 37f6fa9..9aa405c 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,8 @@ "start": "npm start -w @mcflyjs/landing-page", "build": "npm run build -w @mcflyjs/landing-page", "build:preview": "npm run build:preview -w @mcflyjs/landing-page", - "template:basic": "npm run dev -w @templates/basic" + "template:basic": "npm run dev -w @templates/basic", + "create": "node ./packages/create-mcfly" }, "workspaces": [ "packages/config", diff --git a/packages/create-mcfly/index.js b/packages/create-mcfly/index.js index 37b87c1..af344b2 100755 --- a/packages/create-mcfly/index.js +++ b/packages/create-mcfly/index.js @@ -1,18 +1,58 @@ #!/usr/bin/env node const { downloadTemplate } = require("giget"); +const { consola } = require("consola"); +const { exec } = require("node:child_process"); create(); async function create() { + console.clear(); + let hasErrors = false; + const directory = + (await consola.prompt("Name your new vanilla web app:", { + placeholder: "./mcfly-app", + })) ?? "mcfly-app"; try { - const { source, dir } = await downloadTemplate( - "github:ayoayco/mcfly/templates/basic", + await consola.start(`Copying template to ${directory}...`); + await downloadTemplate("github:ayoayco/mcfly/templates/basic", { + dir: directory, + }); + } catch (e) { + consola.error(e); + hasErrors = true; + } + + if (!hasErrors) { + const installDeps = await consola.prompt( + "Would you like to install the dependencies?", { - dir: "mcfly-app", + type: "confirm", } ); - console.log(`✨ New McFly app created: ${dir}`); - } catch (e) { - console.error('😱 "mcfly-app" directory already exists'); + if (installDeps) { + await consola.start("Installing dependencies..."); + try { + await exec(`npm --prefix ${directory} install`); + } catch (e) { + consola.error(e); + } + } + + const initializeGit = await consola.prompt( + "Would you like to initialize your git repository?", + { + type: "confirm", + } + ); + if (initializeGit) { + await consola.start("Initializing git repository..."); + try { + await exec(`git -C ${directory} init`); + } catch (e) { + consola.error(e); + } + } + + consola.box(`McFly app created: ${directory}`); } return 1; } diff --git a/packages/create-mcfly/package.json b/packages/create-mcfly/package.json index e6612f4..208fc6a 100644 --- a/packages/create-mcfly/package.json +++ b/packages/create-mcfly/package.json @@ -27,6 +27,7 @@ }, "homepage": "https://github.com/ayoayco/McFly#readme", "dependencies": { + "consola": "^3.2.3", "giget": "^1.1.3" } }