Merge Branch create-util #19
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@matthiesenxyz/create-astro-ghostcms",
|
||||
"version": "0.0.1-dev10",
|
||||
"version": "0.0.1-dev11",
|
||||
"description": "Utility to quickly get started with our Integration and astro",
|
||||
"type": "module",
|
||||
"main": "./create-astro-ghostcms.mjs",
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import path from "node:path";
|
||||
import os from "node:os";
|
||||
import * as prompts from "@clack/prompts";
|
||||
import color from "picocolors";
|
||||
import * as p from "@clack/prompts";
|
||||
import c from "picocolors";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
/**
|
||||
|
@ -19,7 +19,7 @@ export function getModulePaths(url) {
|
|||
* @returns {never}
|
||||
*/
|
||||
export function exitPrompt() {
|
||||
prompts.cancel(color.red("Operation Cancelled"));
|
||||
p.cancel(c.red("Operation Cancelled"));
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import arg from "arg";
|
||||
import * as prompts from "@clack/prompts";
|
||||
import * as p from "@clack/prompts";
|
||||
import { exitPrompt, isPackageManager } from "./lib/utils.js";
|
||||
import { createBasic } from "./runners/basic.js";
|
||||
import color from 'picocolors';
|
||||
import c from 'picocolors';
|
||||
|
||||
|
||||
export async function main() {
|
||||
|
@ -43,26 +43,26 @@ export async function main() {
|
|||
}
|
||||
|
||||
// 1. Say hello!
|
||||
prompts.intro(color.bgMagenta(color.black(` ${color.bold("Astro-GhostCMS Create Utility - By MatthiesenXYZ")} ${color.italic(dryRun ? "[Dry Run] ":" ")}`)))
|
||||
p.intro(c.bgMagenta(c.black(` ${c.bold("Astro-GhostCMS Create Utility - By MatthiesenXYZ")} ${c.italic(dryRun ? "[Dry Run] ":" ")}`)))
|
||||
|
||||
// 2. Get template to set up
|
||||
let [template, ...args] = flags._;
|
||||
if (template && !isValidTemplate(template)) {
|
||||
prompts.log.warning(color.red(`"${template}" isn't a valid template`));
|
||||
p.log.warning(c.red(`"${template}" isn't a valid template`));
|
||||
template = null;
|
||||
}
|
||||
if (!template) {
|
||||
const answer = await prompts.select({
|
||||
message: `${color.cyan('Which template would you like to use?')}`,
|
||||
const answer = await p.select({
|
||||
message: `${c.cyan('Which template would you like to use?')}`,
|
||||
options: [
|
||||
{
|
||||
value: "basic",
|
||||
label: `${color.magenta('Basic')} - ${color.cyan(color.italic('Integration w/ Default Theme'))}`
|
||||
label: `${c.magenta('Basic')} - ${c.cyan(c.italic('Integration w/ Default Theme'))}`
|
||||
},
|
||||
],
|
||||
initialValue: "basic",
|
||||
});
|
||||
if (prompts.isCancel(answer)) exitPrompt();
|
||||
if (p.isCancel(answer)) exitPrompt();
|
||||
template = answer;
|
||||
}
|
||||
|
||||
|
@ -82,15 +82,15 @@ export async function main() {
|
|||
await createBasic(ctx).catch(console.error);
|
||||
break;
|
||||
default:
|
||||
throw new Error(color.red(`Unknown template: ${template}`));
|
||||
throw new Error(c.red(`Unknown template: ${template}`));
|
||||
}
|
||||
|
||||
// 4. Huzzah!
|
||||
prompts.outro(color.reset(`Problems? ${color.underline(color.cyan('https://github.com/MatthiesenXYZ/astro-ghostcms/issues'))}`));
|
||||
p.outro(c.reset(`Problems? ${c.underline(c.cyan('https://github.com/MatthiesenXYZ/astro-ghostcms/issues'))}`));
|
||||
}
|
||||
|
||||
function getHelp() {
|
||||
return `${color.yellow('Need Help? Check the Docs!')} ${color.underline(color.cyan('https://astro-ghostcms.xyz/docs'))}`;
|
||||
return `${c.yellow('Need Help? Check the Docs!')} ${c.underline(c.cyan('https://astro-ghostcms.xyz/docs'))}`;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -2,7 +2,7 @@ import path from "node:path";
|
|||
import fse from "fs-extra";
|
||||
import c from 'picocolors';
|
||||
import { execa } from "execa";
|
||||
import * as prompts from "@clack/prompts";
|
||||
import * as p from "@clack/prompts";
|
||||
import { exitPrompt, getModulePaths, isPathname,
|
||||
normalizePath, wait } from "../lib/utils.js";
|
||||
|
||||
|
@ -10,7 +10,7 @@ import { exitPrompt, getModulePaths, isPathname,
|
|||
export async function createBasic(ctx) {
|
||||
let { args, dryRun, initGitRepo, installDeps } = ctx;
|
||||
|
||||
const spinner = prompts.spinner();
|
||||
const s = p.spinner();
|
||||
let cwd = process.cwd();
|
||||
|
||||
// 1. Set up project directory
|
||||
|
@ -24,34 +24,33 @@ export async function createBasic(ctx) {
|
|||
// 2. Create the damned thing
|
||||
cwd = project.pathname;
|
||||
const relativePath = path.relative(process.cwd(), project.pathname);
|
||||
spinner.start(`${c.yellow(`Creating a new Astro-GhostCMS project in ${relativePath}`)}`);
|
||||
s.start(`${c.yellow(`Creating a new Astro-GhostCMS project in ${relativePath}`)}`);
|
||||
if (dryRun) {
|
||||
await wait(2000);
|
||||
} else {
|
||||
await createApp(project.name, project.pathname, {
|
||||
onError(error) {
|
||||
spinner.stop(`${c.red('Failed to create new project')}`);
|
||||
prompts.cancel();
|
||||
s.stop(`${c.red('Failed to create new project')}`);
|
||||
p.cancel();
|
||||
console.error(error);
|
||||
process.exit(1);
|
||||
},
|
||||
});
|
||||
}
|
||||
spinner.stop(`${c.green('New Astro-GhostCMS project')} '${project.name}' ${c.green('created')} 🚀`);
|
||||
const fCheck = await prompts.group(
|
||||
s.stop(`${c.green('New Astro-GhostCMS project')} '${project.name}' ${c.green('created')} 🚀`);
|
||||
const fCheck = await p.group(
|
||||
{ installDeps: () =>
|
||||
prompts.confirm({
|
||||
p.confirm({
|
||||
message: `${c.cyan('Install dependencies? (Recommended)')}`,
|
||||
initialValue: false,
|
||||
}), initGitRepo: () =>
|
||||
prompts.confirm({
|
||||
p.confirm({
|
||||
message: `${c.cyan('Initialize a Git repository?')} ${c.italic(c.gray(`( Tip: If this option gets 'stuck' press the enter button a second time! )`))}`,
|
||||
initialValue: false,
|
||||
}),
|
||||
},
|
||||
{ onCancel: () => {
|
||||
prompts.cancel(`${c.red('Operation Cancelled!')}`);
|
||||
process.exit(0);
|
||||
exitPrompt();
|
||||
}
|
||||
}
|
||||
);
|
||||
|
@ -64,9 +63,9 @@ export async function createBasic(ctx) {
|
|||
} else {
|
||||
await exec("git", ["init"], { cwd });
|
||||
}
|
||||
prompts.log.success(c.green("Initialized Git repository"));
|
||||
p.log.success(c.green("Initialized Git repository"));
|
||||
} else {
|
||||
prompts.log.info(`${c.gray("Skipped Git initialization")}`);
|
||||
p.log.info(`${c.gray("Skipped Git initialization")}`);
|
||||
}
|
||||
|
||||
const nextSteps = `If you didnt opt to install Dependencies dont forget to run: \n ${c.yellow('npm install')} / ${c.yellow('pnpm install')} / ${c.yellow('yarn install')} inside your project directory! \n \n ${c.bgYellow(c.black("Dont forget to modify your .env file for YOUR ghost install!"))} `
|
||||
|
@ -75,22 +74,22 @@ const nextSteps = `If you didnt opt to install Dependencies dont forget to run:
|
|||
installDeps = installDeps ?? fCheck.installDeps;
|
||||
const pm = ctx.pkgManager ?? "pnpm";
|
||||
if (installDeps) {
|
||||
spinner.start(`${c.cyan(`Installing dependencies with ${pm}`)} `);
|
||||
s.start(`${c.cyan(`Installing dependencies with ${pm}`)} `);
|
||||
if (dryRun) {
|
||||
await wait(1);
|
||||
} else {
|
||||
await installDependencies(pm, { cwd });
|
||||
}
|
||||
spinner.stop(`${c.green(`Dependencies installed with ${pm}`)}`);
|
||||
s.stop(`${c.green(`Dependencies installed with ${pm}`)}`);
|
||||
success()
|
||||
} else {
|
||||
prompts.log.info(`${c.gray('Skipped dependency installation')}`);
|
||||
p.log.info(`${c.gray('Skipped dependency installation')}`);
|
||||
success()
|
||||
}
|
||||
|
||||
async function success() {
|
||||
prompts.note(nextSteps);
|
||||
prompts.outro(c.green("Deployment Complete!"));
|
||||
p.note(nextSteps);
|
||||
p.outro(c.green("Deployment Complete!"));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -152,11 +151,11 @@ async function getProjectDetails(projectNameInput, opts) {
|
|||
let projectName = projectNameInput;
|
||||
if (!projectName) {
|
||||
const defaultProjectName = "my-astro-ghost";
|
||||
let answer = await prompts.text({
|
||||
let answer = await p.text({
|
||||
message: `${c.cyan("Where would you like to create your project?")}`,
|
||||
placeholder: `.${path.sep}${defaultProjectName}`,
|
||||
});
|
||||
if (prompts.isCancel(answer)) exitPrompt();
|
||||
if (p.isCancel(answer)) exitPrompt();
|
||||
|
||||
answer = answer?.trim();
|
||||
projectName = answer || defaultProjectName;
|
||||
|
|
Loading…
Reference in New Issue