dev 11, a bunch of changing of names

This commit is contained in:
Adam Matthiesen 2024-01-27 16:56:15 -08:00
parent 1373db171c
commit e7aa5f69cf
4 changed files with 34 additions and 35 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "@matthiesenxyz/create-astro-ghostcms", "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", "description": "Utility to quickly get started with our Integration and astro",
"type": "module", "type": "module",
"main": "./create-astro-ghostcms.mjs", "main": "./create-astro-ghostcms.mjs",

View File

@ -1,7 +1,7 @@
import path from "node:path"; import path from "node:path";
import os from "node:os"; import os from "node:os";
import * as prompts from "@clack/prompts"; import * as p from "@clack/prompts";
import color from "picocolors"; import c from "picocolors";
import { fileURLToPath } from "node:url"; import { fileURLToPath } from "node:url";
/** /**
@ -19,7 +19,7 @@ export function getModulePaths(url) {
* @returns {never} * @returns {never}
*/ */
export function exitPrompt() { export function exitPrompt() {
prompts.cancel(color.red("Operation Cancelled")); p.cancel(c.red("Operation Cancelled"));
process.exit(0); process.exit(0);
} }

View File

@ -1,8 +1,8 @@
import arg from "arg"; import arg from "arg";
import * as prompts from "@clack/prompts"; import * as p from "@clack/prompts";
import { exitPrompt, isPackageManager } from "./lib/utils.js"; import { exitPrompt, isPackageManager } from "./lib/utils.js";
import { createBasic } from "./runners/basic.js"; import { createBasic } from "./runners/basic.js";
import color from 'picocolors'; import c from 'picocolors';
export async function main() { export async function main() {
@ -43,26 +43,26 @@ export async function main() {
} }
// 1. Say hello! // 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 // 2. Get template to set up
let [template, ...args] = flags._; let [template, ...args] = flags._;
if (template && !isValidTemplate(template)) { 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; template = null;
} }
if (!template) { if (!template) {
const answer = await prompts.select({ const answer = await p.select({
message: `${color.cyan('Which template would you like to use?')}`, message: `${c.cyan('Which template would you like to use?')}`,
options: [ options: [
{ {
value: "basic", 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", initialValue: "basic",
}); });
if (prompts.isCancel(answer)) exitPrompt(); if (p.isCancel(answer)) exitPrompt();
template = answer; template = answer;
} }
@ -82,15 +82,15 @@ export async function main() {
await createBasic(ctx).catch(console.error); await createBasic(ctx).catch(console.error);
break; break;
default: default:
throw new Error(color.red(`Unknown template: ${template}`)); throw new Error(c.red(`Unknown template: ${template}`));
} }
// 4. Huzzah! // 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() { 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'))}`;
} }
/** /**

View File

@ -2,7 +2,7 @@ import path from "node:path";
import fse from "fs-extra"; import fse from "fs-extra";
import c from 'picocolors'; import c from 'picocolors';
import { execa } from "execa"; import { execa } from "execa";
import * as prompts from "@clack/prompts"; import * as p from "@clack/prompts";
import { exitPrompt, getModulePaths, isPathname, import { exitPrompt, getModulePaths, isPathname,
normalizePath, wait } from "../lib/utils.js"; normalizePath, wait } from "../lib/utils.js";
@ -10,7 +10,7 @@ import { exitPrompt, getModulePaths, isPathname,
export async function createBasic(ctx) { export async function createBasic(ctx) {
let { args, dryRun, initGitRepo, installDeps } = ctx; let { args, dryRun, initGitRepo, installDeps } = ctx;
const spinner = prompts.spinner(); const s = p.spinner();
let cwd = process.cwd(); let cwd = process.cwd();
// 1. Set up project directory // 1. Set up project directory
@ -24,34 +24,33 @@ export async function createBasic(ctx) {
// 2. Create the damned thing // 2. Create the damned thing
cwd = project.pathname; cwd = project.pathname;
const relativePath = path.relative(process.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) { if (dryRun) {
await wait(2000); await wait(2000);
} else { } else {
await createApp(project.name, project.pathname, { await createApp(project.name, project.pathname, {
onError(error) { onError(error) {
spinner.stop(`${c.red('Failed to create new project')}`); s.stop(`${c.red('Failed to create new project')}`);
prompts.cancel(); p.cancel();
console.error(error); console.error(error);
process.exit(1); process.exit(1);
}, },
}); });
} }
spinner.stop(`${c.green('New Astro-GhostCMS project')} '${project.name}' ${c.green('created')} 🚀`); s.stop(`${c.green('New Astro-GhostCMS project')} '${project.name}' ${c.green('created')} 🚀`);
const fCheck = await prompts.group( const fCheck = await p.group(
{ installDeps: () => { installDeps: () =>
prompts.confirm({ p.confirm({
message: `${c.cyan('Install dependencies? (Recommended)')}`, message: `${c.cyan('Install dependencies? (Recommended)')}`,
initialValue: false, initialValue: false,
}), initGitRepo: () => }), 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! )`))}`, 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, initialValue: false,
}), }),
}, },
{ onCancel: () => { { onCancel: () => {
prompts.cancel(`${c.red('Operation Cancelled!')}`); exitPrompt();
process.exit(0);
} }
} }
); );
@ -64,9 +63,9 @@ export async function createBasic(ctx) {
} else { } else {
await exec("git", ["init"], { cwd }); await exec("git", ["init"], { cwd });
} }
prompts.log.success(c.green("Initialized Git repository")); p.log.success(c.green("Initialized Git repository"));
} else { } 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!"))} ` 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; installDeps = installDeps ?? fCheck.installDeps;
const pm = ctx.pkgManager ?? "pnpm"; const pm = ctx.pkgManager ?? "pnpm";
if (installDeps) { if (installDeps) {
spinner.start(`${c.cyan(`Installing dependencies with ${pm}`)} `); s.start(`${c.cyan(`Installing dependencies with ${pm}`)} `);
if (dryRun) { if (dryRun) {
await wait(1); await wait(1);
} else { } else {
await installDependencies(pm, { cwd }); await installDependencies(pm, { cwd });
} }
spinner.stop(`${c.green(`Dependencies installed with ${pm}`)}`); s.stop(`${c.green(`Dependencies installed with ${pm}`)}`);
success() success()
} else { } else {
prompts.log.info(`${c.gray('Skipped dependency installation')}`); p.log.info(`${c.gray('Skipped dependency installation')}`);
success() success()
} }
async function success() { async function success() {
prompts.note(nextSteps); p.note(nextSteps);
prompts.outro(c.green("Deployment Complete!")); p.outro(c.green("Deployment Complete!"));
} }
} }
@ -152,11 +151,11 @@ async function getProjectDetails(projectNameInput, opts) {
let projectName = projectNameInput; let projectName = projectNameInput;
if (!projectName) { if (!projectName) {
const defaultProjectName = "my-astro-ghost"; 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?")}`, message: `${c.cyan("Where would you like to create your project?")}`,
placeholder: `.${path.sep}${defaultProjectName}`, placeholder: `.${path.sep}${defaultProjectName}`,
}); });
if (prompts.isCancel(answer)) exitPrompt(); if (p.isCancel(answer)) exitPrompt();
answer = answer?.trim(); answer = answer?.trim();
projectName = answer || defaultProjectName; projectName = answer || defaultProjectName;