create-apppaaaul
Version:
Create projects as paaauldev would
168 lines (164 loc) • 6 kB
JavaScript
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
// node_modules/.pnpm/tsup@8.4.0_typescript@5.8.2_yaml@2.4.5/node_modules/tsup/assets/cjs_shims.js
var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.src || new URL("main.js", document.baseURI).href;
var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
// index.ts
var import_node_path = __toESM(require("path"));
var import_node_url = require("url");
var import_promises = require("fs/promises");
var import_child_process = require("child_process");
var import_util = require("util");
var import_picocolors = require("picocolors");
var import_glob = require("glob");
var import_picocolors2 = __toESM(require("picocolors"));
var import_prompts = __toESM(require("prompts"));
var import_yargs = __toESM(require("yargs"));
var import_helpers = require("yargs/helpers");
// helpers/install.ts
var import_cross_spawn = __toESM(require("cross-spawn"));
async function install() {
const packageManager = "pnpm";
const args2 = ["install"];
return new Promise((resolve, reject) => {
const child = (0, import_cross_spawn.default)(packageManager, args2, {
stdio: "inherit",
env: {
...process.env,
ADBLOCK: "1",
// we set NODE_ENV to development as pnpm skips dev
// dependencies when production
NODE_ENV: "development",
DISABLE_OPENCOLLECTIVE: "1"
}
});
child.on("close", (code) => {
if (code !== 0) {
reject({ command: `${packageManager} ${args2.join(" ")}` });
return;
}
resolve();
});
});
}
// index.ts
var execAsync = (0, import_util.promisify)(import_child_process.exec);
var TEMPLATES = [
{
title: "Nextjs ts with db setup Landing with prisma",
value: "nextjs-ts-landing-prisma"
},
{
title: "Nextjs ts with db setup Landing with drizzle",
value: "nextjs-ts-landing-drizzle"
},
{
title: "Nextjs ts clean",
value: "nextjs-ts-clean"
}
];
var args = (0, import_yargs.default)((0, import_helpers.hideBin)(process.argv)).options({
name: {
alias: "n",
type: "string",
description: "Name of the project"
},
template: {
alias: "t",
type: "string",
description: "Template to use"
}
});
import_prompts.default.override(args.argv);
async function main() {
const {
_: [initialName, initialProject]
} = await args.argv;
const project = await (0, import_prompts.default)(
[
{
type: "text",
name: "name",
message: "What is the name of your project?",
initial: initialName || "apppaaaul-project",
validate: (value) => {
if (value !== "." && value.match(/[^a-zA-Z0-9-_]+/g)) {
return "Project name can only contain letters, numbers, dashes, underscores, or be '.' for the current directory";
}
return true;
}
},
{
type: "select",
name: "template",
message: `Which template would you like to use?`,
initial: initialProject || 0,
choices: TEMPLATES
}
],
{
onCancel: () => {
console.log("\nBye \u{1F44B}\n");
process.exit(0);
}
}
);
const template = import_node_path.default.join(
import_node_path.default.dirname((0, import_node_url.fileURLToPath)(importMetaUrl)),
"templates",
project.template
);
const destination = project.name === "." ? process.cwd() : import_node_path.default.join(process.cwd(), project.name);
await (0, import_promises.cp)(import_node_path.default.join(template, "project"), destination, { recursive: true });
const files = await (0, import_glob.glob)(`**/*`, { nodir: true, cwd: destination, absolute: true });
for await (const file of files) {
const data = await (0, import_promises.readFile)(file, "utf8");
const draft = data.replace(/{{name}}/g, project.name);
await (0, import_promises.writeFile)(file, draft, "utf8");
}
console.log("\n\u2728 Project created \u2728");
if (project.name !== ".") {
try {
await execAsync(`cd ${project.name}`);
console.log(`
${import_picocolors2.default.green(`cd`)} ${project.name}`);
} catch (error) {
console.error(`Error executing commands: ${error}`);
}
}
try {
await execAsync("cursor .");
console.log("Installing packages. This might take a couple of minutes.");
console.log();
await install();
console.log();
console.log(`${(0, import_picocolors.green)("Success!")} App installed successfully.`);
console.log((0, import_picocolors.cyan)("Initializing the development server..."));
await execAsync("pnpm dev");
} catch (error) {
console.error(`Error executing commands: ${error}`);
}
}
main().catch(console.error);
//# sourceMappingURL=index.js.map