feat(create-mcfly): install deps & init git
This commit is contained in:
parent
9a855041b3
commit
5095f504e7
5 changed files with 71 additions and 7 deletions
21
LICENSE
Normal file
21
LICENSE
Normal file
|
@ -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.
|
1
package-lock.json
generated
1
package-lock.json
generated
|
@ -3978,6 +3978,7 @@
|
||||||
"version": "0.1.2",
|
"version": "0.1.2",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"consola": "^3.2.3",
|
||||||
"giget": "^1.1.3"
|
"giget": "^1.1.3"
|
||||||
},
|
},
|
||||||
"bin": {
|
"bin": {
|
||||||
|
|
|
@ -4,7 +4,8 @@
|
||||||
"start": "npm start -w @mcflyjs/landing-page",
|
"start": "npm start -w @mcflyjs/landing-page",
|
||||||
"build": "npm run build -w @mcflyjs/landing-page",
|
"build": "npm run build -w @mcflyjs/landing-page",
|
||||||
"build:preview": "npm run build:preview -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": [
|
"workspaces": [
|
||||||
"packages/config",
|
"packages/config",
|
||||||
|
|
|
@ -1,18 +1,58 @@
|
||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
|
||||||
const { downloadTemplate } = require("giget");
|
const { downloadTemplate } = require("giget");
|
||||||
|
const { consola } = require("consola");
|
||||||
|
const { exec } = require("node:child_process");
|
||||||
create();
|
create();
|
||||||
async function 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 {
|
try {
|
||||||
const { source, dir } = await downloadTemplate(
|
await consola.start(`Copying template to ${directory}...`);
|
||||||
"github:ayoayco/mcfly/templates/basic",
|
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}`);
|
if (installDeps) {
|
||||||
} catch (e) {
|
await consola.start("Installing dependencies...");
|
||||||
console.error('😱 "mcfly-app" directory already exists');
|
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;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
},
|
},
|
||||||
"homepage": "https://github.com/ayoayco/McFly#readme",
|
"homepage": "https://github.com/ayoayco/McFly#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"consola": "^3.2.3",
|
||||||
"giget": "^1.1.3"
|
"giget": "^1.1.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue