builda
Version:
The everything generator
1,660 lines (1,614 loc) • 126 kB
JavaScript
#! /usr/bin/env node
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __defProps = Object.defineProperties;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
for (var prop in b || (b = {}))
if (__hasOwnProp.call(b, prop))
__defNormalProp(a, prop, b[prop]);
if (__getOwnPropSymbols)
for (var prop of __getOwnPropSymbols(b)) {
if (__propIsEnum.call(b, prop))
__defNormalProp(a, prop, b[prop]);
}
return a;
};
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
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
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/index.ts
var src_exports = {};
__export(src_exports, {
builda: () => builda,
buildaQuestion: () => question_default,
buildaSubstitute: () => substitute_default,
changeCase: () => change_case_default,
default: () => src_default,
printMessage: () => print_message_default,
throwError: () => throw_error_default
});
module.exports = __toCommonJS(src_exports);
var import_yargs = __toESM(require("yargs"));
var import_chalk12 = __toESM(require("chalk"));
// src/data/globals.ts
var globals_default = {
version: "5.2.3",
buildaDir: ".builda",
websiteUrl: "https://www.builda.app",
buildaReadmeFileName: "getting-started.md",
repository: {
type: "git",
url: "git+https://github.com/spacenectar/builda"
}
};
// src/scripts/builda-project/project.ts
var import_execa = __toESM(require("execa"));
var import_inquirer6 = __toESM(require("inquirer"));
var import_node_fs16 = __toESM(require("fs"));
var import_node_path14 = __toESM(require("path"));
var import_node_process4 = __toESM(require("process"));
// src/helpers/console/print-logo.ts
var import_chalk = __toESM(require("chalk"));
var print_logo_default = () => {
return console.log(
import_chalk.default.magenta(`
\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588 ${import_chalk.default.white(
`v${globals_default.version}
`
)}
\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2584 \u2588\u2588\u2588 \u2588\u2588\u2588 \u2588\u2588\u2588 \u2588\u2588\u2588 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2584 \u2584\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588
\u2588\u2588\u2588 \u2588\u2588\u2588 \u2588\u2588\u2588 \u2588\u2588\u2588 \u2588\u2588\u2588 \u2588\u2588\u2588 \u2588\u2588\u2588 \u2580\u2588\u2588\u2588 \u2588\u2588\u2588\u2580 \u2588\u2588\u2588
\u2588\u2588\u2588 \u2588\u2588\u2588 \u2588\u2588\u2588 \u2588\u2588\u2588 \u2588\u2588\u2588 \u2588\u2588\u2588 \u2588\u2588\u2588 \u2588\u2588\u2588 \u2588\u2588\u2588 \u2588\u2588\u2588
\u2588\u2588\u2588\u2584\u2584\u2584\u2588\u2588\u2580 \u2588\u2588\u2588 \u2588\u2588\u2588 \u2588\u2588\u2588 \u2588\u2588\u2588 \u2588\u2588\u2588 \u2588\u2588\u2588 \u2588\u2588\u2588 \u2588\u2588\u2588
\u2588\u2588\u2588\u2580\u2580\u2580\u2588\u2588\u2584 \u2588\u2588\u2588 \u2588\u2588\u2588 \u2588\u2588\u2588 \u2588\u2588\u2588 \u2588\u2588\u2588 \u2588\u2588\u2588 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588
\u2588\u2588\u2588 \u2588\u2588\u2584 \u2588\u2588\u2588 \u2588\u2588\u2588 \u2588\u2588\u2588 \u2588\u2588\u2588 \u2588\u2588\u2588 \u2588\u2588\u2588 \u2588\u2588\u2588 \u2588\u2588\u2588
\u2588\u2588\u2588 \u2588\u2588\u2588 \u2588\u2588\u2588 \u2588\u2588\u2588 \u2588\u2588\u2588 \u2588\u2588\u2588 \u2588\u2588\u2588 \u2584\u2588\u2588\u2588 \u2588\u2588\u2588 \u2588\u2588\u2588
\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2580 \u2580\u2588\u2588\u2588\u2588\u2588\u2588\u2580 \u2588\u2588\u2588 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2580 \u2588\u2588\u2588 \u2588\u2588\u2588 \u2588\u2588\u2588\u2588\u2588\u2588
${import_chalk.default.white.bold(
"The Everything Generator"
)} \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588
`)
);
};
// src/helpers/console/print-message.ts
var import_chalk2 = __toESM(require("chalk"));
var import_process = __toESM(require("process"));
var import_readline = __toESM(require("readline"));
var dots = {
interval: 80,
frames: ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"]
};
var stdOut = import_process.default.stdout;
var stderr = import_process.default.stderr;
var timer = void 0;
var printMessage = (message2, type, returnstring) => {
let newMessage = null;
if (type && type === "error") {
if (timer !== void 0) {
clearInterval(timer);
}
newMessage = import_chalk2.default.red(`\u{1F6A8} ${message2}`);
}
if (type && type === "danger") {
newMessage = import_chalk2.default.red(`${message2}`);
}
if (type && type === "warning") {
newMessage = import_chalk2.default.yellow(`\u{1F514} ${message2}`);
}
if (type && type === "config") {
newMessage = import_chalk2.default.blue(`\u{1F527} ${message2}`);
}
if (type && type === "downloading") {
newMessage = import_chalk2.default.blue(`\u{1F30D} ${message2}`);
}
if (type && type === "copying") {
newMessage = import_chalk2.default.blue(`\u{1F4C2} ${message2}`);
}
if (type && type === "installing") {
newMessage = import_chalk2.default.blue(`\u{1F4E6} ${message2}`);
}
if (type && type === "notice") {
newMessage = import_chalk2.default.blue(`\u{1F4DD} ${message2}`);
}
if (type && type === "info") {
newMessage = import_chalk2.default.bgHex("#6699CC").white.bold(" i ") + " " + import_chalk2.default.reset.blue(message2);
}
if (type && type === "success") {
if (timer !== void 0) {
clearInterval(timer);
}
newMessage = import_chalk2.default.green(`\u2705 ${message2}`);
}
if (type && type === "watch") {
newMessage = import_chalk2.default.magenta(`\u{1F440} ${message2}`);
}
if (type && type === "build") {
newMessage = import_chalk2.default.magenta(`\u{1F3D7} ${message2}`);
}
if (type && type === "run") {
newMessage = import_chalk2.default.magenta(`\u{1F3C3} ${message2}`);
}
if (type && type === "primary") {
newMessage = import_chalk2.default.magenta(`${message2}`);
}
if (type && type === "secondary") {
newMessage = import_chalk2.default.white(`${message2}`);
}
if (type && type === "processing") {
const spin = dots;
const spinnerFrames = spin.frames;
const spinnerTimeInterval = spin.interval;
let index = 0;
if (timer !== void 0) {
clearInterval(timer);
}
timer = setInterval(() => {
let now = spinnerFrames[index];
if (now == void 0) {
index = 0;
now = spinnerFrames[index];
}
import_readline.default.clearLine(stdOut, 0);
import_readline.default.cursorTo(stdOut, 0);
stdOut.write(now);
index = index >= spinnerFrames.length ? 0 : index + 1;
}, spinnerTimeInterval);
newMessage = import_chalk2.default.blue(`${message2}`);
}
if (!type) {
newMessage = message2;
}
const returnType = type === "error" ? stderr : stdOut;
return returnstring ? newMessage : returnType.write(`${newMessage}
`);
};
var print_message_default = printMessage;
// src/helpers/console/print-site-link.ts
var import_chalk3 = __toESM(require("chalk"));
// src/data/words.json
var adjectives = [
"adorable",
"adventurous",
"aggressive",
"agreeable",
"alert",
"alive",
"amused",
"angry",
"annoyed",
"annoying",
"anxious",
"arrogant",
"ashamed",
"attractive",
"average",
"awful",
"bad",
"beautiful",
"better",
"bewildered",
"black",
"bloody",
"blue",
"blue-eyed",
"blushing",
"bored",
"brainy",
"brave",
"breakable",
"bright",
"busy",
"calm",
"careful",
"cautious",
"charming",
"cheerful",
"clean",
"clear",
"clever",
"cloudy",
"clumsy",
"colorful",
"combative",
"comfortable",
"concerned",
"condemned",
"confused",
"cooperative",
"courageous",
"crazy",
"creepy",
"crowded",
"cruel",
"curious",
"cute",
"dangerous",
"dark",
"dead",
"defeated",
"defiant",
"delightful",
"depressed",
"determined",
"different",
"difficult",
"disgusted",
"distinct",
"disturbed",
"dizzy",
"doubtful",
"drab",
"dull",
"eager",
"easy",
"elated",
"elegant",
"embarrassed",
"enchanting",
"encouraging",
"energetic",
"enthusiastic",
"envious",
"evil",
"excited",
"expensive",
"exuberant",
"fair",
"faithful",
"famous",
"fancy",
"fantastic",
"fierce",
"filthy",
"fine",
"foolish",
"fragile",
"frail",
"frantic",
"friendly",
"frightened",
"funny",
"gentle",
"gifted",
"glamorous",
"gleaming",
"glorious",
"good",
"gorgeous",
"graceful",
"grieving",
"grotesque",
"grumpy",
"handsome",
"happy",
"healthy",
"helpful",
"helpless",
"hilarious",
"homeless",
"homely",
"horrible",
"hungry",
"hurt",
"ill",
"important",
"impossible",
"inexpensive",
"innocent",
"inquisitive",
"itchy",
"jealous",
"jittery",
"jolly",
"joyous",
"kind",
"lazy",
"light",
"lively",
"lonely",
"long",
"lovely",
"lucky",
"magnificent",
"misty",
"modern",
"motionless",
"muddy",
"mushy",
"mysterious",
"nasty",
"naughty",
"nervous",
"nice",
"nutty",
"obedient",
"obnoxious",
"odd",
"old-fashioned",
"open",
"outrageous",
"outstanding",
"panicky",
"perfect",
"plain",
"pleasant",
"poised",
"poor",
"powerful",
"precious",
"prickly",
"proud",
"putrid",
"puzzled",
"quaint",
"real",
"relieved",
"repulsive",
"rich",
"scary",
"selfish",
"shiny",
"shy",
"silly",
"sleepy",
"smiling",
"smoggy",
"sore",
"sparkling",
"splendid",
"spotless",
"stormy",
"strange",
"stupid",
"successful",
"super",
"talented",
"tame",
"tasty",
"tender",
"tense",
"terrible",
"thankful",
"thoughtful",
"thoughtless",
"tired",
"tough",
"troubled",
"ugliest",
"ugly",
"uninterested",
"unsightly",
"unusual",
"upset",
"uptight",
"vast",
"victorious",
"vivacious",
"wandering",
"weary",
"wicked",
"wide-eyed",
"wild",
"witty",
"worried",
"worrisome",
"wrong",
"zany",
"zealous"
];
var nouns = [
"Actor",
"Gold",
"Painting",
"Advertisement",
"Grass",
"Parrot",
"Afternoon",
"Greece",
"Pencil",
"Airport",
"Guitar",
"Piano",
"Ambulance",
"Hair",
"Pillow",
"Animal",
"Hamburger",
"Pizza",
"Answer",
"Helicopter",
"Planet",
"Apple",
"Helmet",
"Plastic",
"Army",
"Holiday",
"Portugal",
"Australia",
"Honey",
"Potato",
"Balloon",
"Horse",
"Queen",
"Banana",
"Hospital",
"Quill",
"Battery",
"House",
"Rain",
"Beach",
"Hydrogen",
"Rainbow",
"Beard",
"Ice",
"Raincoat",
"Bed",
"Insect",
"Refrigerator",
"Belgium",
"Insurance",
"Restaurant",
"Boy",
"Iron",
"River",
"Branch",
"Island",
"Rocket",
"Breakfast",
"Jackal",
"Room",
"Brother",
"Jelly",
"Rose",
"Camera",
"Jewellery",
"Russia",
"Candle",
"Jordan",
"Sandwich",
"Car",
"Juice",
"School",
"Caravan",
"Kangaroo",
"Scooter",
"Carpet",
"King",
"Shampoo",
"Cartoon",
"Kitchen",
"Shoe",
"China",
"Kite",
"Soccer",
"Church",
"Knife",
"Spoon",
"Crayon",
"Lamp",
"Stone",
"Crowd",
"Lawyer",
"Sugar",
"Daughter",
"Leather",
"Sweden",
"Death",
"Library",
"Teacher",
"Denmark",
"Lighter",
"Telephone",
"Diamond",
"Lion",
"Television",
"Dinner",
"Lizard",
"Tent",
"Disease",
"Lock",
"Thailand",
"Doctor",
"London",
"Tomato",
"Dog",
"Lunch",
"Toothbrush",
"Dream",
"Machine",
"Traffic",
"Dress",
"Magazine",
"Train",
"Easter",
"Magician",
"Truck",
"Egg",
"Manchester",
"Uganda",
"Eggplant",
"Market",
"Umbrella",
"Egypt",
"Match",
"Van",
"Elephant",
"Microphone",
"Vase",
"Energy",
"Monkey",
"Vegetable",
"Engine",
"Morning",
"Vulture",
"England",
"Motorcycle",
"Wall",
"Evening",
"Nail",
"Whale",
"Eye",
"Napkin",
"Window",
"Family",
"Needle",
"Wire",
"Finland",
"Nest",
"Xylophone",
"Fish",
"Nigeria",
"Yacht",
"Flag",
"Night",
"Yak",
"Flower",
"Notebook",
"Zebra",
"Football",
"Ocean",
"Zoo",
"Forest",
"Oil",
"Garden",
"Fountain",
"Orange",
"Gas",
"France",
"Oxygen",
"Girl",
"Furniture",
"Oyster",
"Glass",
"Garage",
"Ghost"
];
// src/helpers/string/random-word-generator.ts
var randomNameGenerator = () => {
const adjective = adjectives[Math.floor(Math.random() * adjectives.length)];
const noun = nouns[Math.floor(Math.random() * nouns.length)];
return `${adjective.toLowerCase()}-${noun.toLowerCase()}`;
};
var random_word_generator_default = randomNameGenerator;
// src/data/website-paths.json
var website_paths_default = {
root: {
root: "/"
},
tradeStore: {
root: "trade-store",
prefabs: "prefabs",
blueprints: "blueprints"
},
docs: {
root: "docs",
gettingStarted: "getting-started",
prefabs: "prefabs",
config: "config-file",
blueprints: "blueprints",
telemetry: "telemetry",
init: "initialise-a-project",
resolvers: "resolvers",
indexes: "indexes"
}
};
// src/helpers/string/get-site-link.ts
var get_site_link_default = (slug, anchor) => {
const { websiteUrl: websiteUrl3 } = globals_default;
const pathParts = slug.split("/");
const paths = website_paths_default;
const rootPath = pathParts[0] || "./";
const outputPaths = pathParts.map((pathPart) => {
var _a;
if (pathPart === rootPath) {
return pathPart;
}
return (_a = paths[rootPath]) == null ? void 0 : _a[pathPart];
});
return `${websiteUrl3}/${outputPaths.join("/")}${anchor ? `#${anchor}` : ""}`;
};
// src/helpers/string/detect-path-type.ts
var detectPathType = (pathString) => {
if (pathString.startsWith("/") || pathString.startsWith("./") || pathString.startsWith("..") || pathString.startsWith("~")) {
return "local";
}
return "remote";
};
var detect_path_type_default = detectPathType;
// src/helpers/string/detect-case.ts
var detectCase = (input) => {
const snakeCaseRegex = /^(?:[a-zA-Z:]+_[a-zA-Z:]+)+$/;
const pascalCaseRegex = /^(?:[A-Z]{1}[a-zA-Z:]+[A-Z]{1}[a-zA-Z:]+)+$/;
const camelCaseRegex = /^(?:[a-z]{1}[a-zA-Z:]+[A-Z]{1}[a-zA-Z:]+)+$/;
const sentenceCaseRegex = /^(?:[a-zA-Z:]+ [a-zA-Z:]+)+$/;
const kebabCaseRegex = /^(?:[a-zA-Z:]+-[a-zA-Z:]+)+$/;
if (snakeCaseRegex.test(input)) {
return "snake";
}
if (pascalCaseRegex.test(input)) {
return "pascal";
}
if (camelCaseRegex.test(input)) {
return "camel";
}
if (sentenceCaseRegex.test(input)) {
return "sentence";
}
if (kebabCaseRegex.test(input)) {
return "kebab";
}
return "unknown";
};
// src/helpers/string/normalise-case.ts
var removeExtraSpaces = (input) => {
return input.replace(/\s{2,}/g, " ").trim();
};
var normalizeCase = (input) => {
const caseType = detectCase(input);
const words = input.split(/(?=[A-Z:])/).filter((word) => word !== ":");
const lowerCasedWords = words.slice(1).map((word) => word.toLowerCase());
if (caseType === "snake") {
const str = input.replace(/_/g, " ").toLowerCase().replace(/:/g, " ");
return removeExtraSpaces(str);
}
if (caseType === "pascal") {
const str = input.split(/(?=[A-Z])/).map((word) => word.toLowerCase()).join(" ").replace(/:/g, " ");
return removeExtraSpaces(str);
}
if (caseType === "camel") {
const firstWord = words[0] || "";
lowerCasedWords.unshift(firstWord.toLowerCase());
const str = lowerCasedWords.join(" ");
return removeExtraSpaces(str);
}
if (caseType === "kebab") {
const str = input.replace(/-/g, " ").replace(/:/g, " ").toLowerCase();
return removeExtraSpaces(str);
}
if (caseType === "sentence") {
return removeExtraSpaces(input.replace(/:/g, ""));
}
return input;
};
// src/helpers/string/convert-numbers-to-words.ts
var ONES = [
"Zero",
"One",
"Two",
"Three",
"Four",
"Five",
"Six",
"Seven",
"Eight",
"Nine"
];
var TEENS = [
"Ten",
"Eleven",
"Twelve",
"Thirteen",
"Fourteen",
"Fifteen",
"Sixteen",
"Seventeen",
"Eighteen",
"Nineteen"
];
var TENS = [
"",
"",
"Twenty",
"Thirty",
"Fourty",
"Fifty",
"Sixty",
"Seventy",
"Eighty",
"Ninety"
];
var convertNumbersToWords = (input) => {
const findNumbers = /\d+/g;
const numbers = input.match(findNumbers);
if (numbers) {
const numberString = numbers.map((number) => {
const numberIndex = parseInt(number, 10);
if (numberIndex < 10) {
return ":" + ONES[numberIndex];
}
if (numberIndex < 20) {
return ":" + TEENS[numberIndex - 10];
}
if (numberIndex < 100) {
return ":" + TENS[Math.floor(numberIndex / 10)] + ONES[numberIndex % 10];
}
if (numberIndex < 1e3) {
const isWholeHundred = numberIndex % 100 === 0;
let numberString2 = ":" + ONES[Math.floor(numberIndex / 100)] + ":Hundred";
if (!isWholeHundred) {
numberString2 += ":And:" + TENS[Math.floor(numberIndex % 100 / 10)] + ":" + ONES[numberIndex % 10];
}
return numberString2;
}
if (numberIndex < 1e6) {
return convertNumbersToWords(Math.floor(numberIndex / 1e3).toString()) + ":Thousand" + convertNumbersToWords((numberIndex % 1e3).toString());
}
throw new Error("Numbers larger than 1 million are not supported");
}).join(":");
return input.replace(findNumbers, numberString);
}
return input;
};
// src/helpers/string/convert-symbols-to-words.ts
var convertSymbolsToWords = (input) => {
return input.replace(/&/g, ":And").replace(/@/g, ":At").replace(/#/g, ":Hash").replace(/\$/g, ":Dollar").replace(/£/g, ":Pound").replace(/%/g, ":Percent").replace(/\+/g, ":Plus").replace(/\*/g, ":Asterisk");
};
// src/helpers/string/convert-to-builda-script.ts
var convertToBuildaScript = (key, value) => {
if (value.startsWith("builda") || value.startsWith("run-s") || value.startsWith("run-p") || value.startsWith("npm-run-all") || value.startsWith("concurrently")) {
return value;
}
return `builda x ${key}`;
};
var convert_to_builda_script_default = convertToBuildaScript;
// src/helpers/string/change-case.ts
var changeCase = (input, type) => {
const str = input;
const firstPass = convertSymbolsToWords(str);
const secondPass = convertNumbersToWords(firstPass);
const normalisedStr = normalizeCase(secondPass);
const wordArray = normalisedStr.split(" ");
switch (type) {
case "snakeCase":
return wordArray.join("_").toLowerCase();
case "kebabCase":
return wordArray.join("-").toLowerCase();
case "pascalCase":
return wordArray.map((word) => {
return word.charAt(0).toUpperCase() + word.slice(1);
}).join("");
case "camelCase":
return wordArray.map((word, index) => {
if (index === 0) {
return word.charAt(0).toLowerCase() + word.slice(1);
}
return word.charAt(0).toUpperCase() + word.slice(1);
}).join("");
case "sentenceCase":
default:
return wordArray.map((word, index) => {
if (index === 0) {
return word.charAt(0).toUpperCase() + word.slice(1);
}
return word.charAt(0).toLowerCase() + word.slice(1);
}).join(" ");
}
};
var change_case_default = changeCase;
// src/helpers/console/print-site-link.ts
var print_site_link_default = ({ link, anchor, endText }) => {
endText = endText || "for more information.";
return "\n\nSee " + import_chalk3.default.blue.underline(get_site_link_default(link, anchor)) + " " + endText;
};
// src/helpers/console/show-help.ts
var import_chalk4 = __toESM(require("chalk"));
var import_inquirer = __toESM(require("inquirer"));
var show_help_default = (message2, type) => {
console.clear();
print_logo_default();
const ui = new import_inquirer.default.ui.BottomBar();
const consoleWidth = process.stdout.columns;
type = type || "info";
let colour = "bgBlue";
let icon = "i";
if (type === "error") {
colour = "bgRed";
icon = "\u2716";
}
if (type === "success") {
colour = "bgGreen";
icon = "\u2714";
}
if (type === "warning") {
colour = "bgYellow";
icon = "\u26A0";
}
if (type === "builda") {
colour = "bgMagenta";
icon = "B\u0333";
}
const iconTag = " " + import_chalk4.default.bold.white[colour](` ${icon} `);
const paddingLine = " " + // @ts-ignore-implicit-any - chalk typings are wrong
import_chalk4.default[colour](" ".repeat(5)) + " " + // @ts-ignore-implicit-any - chalk typings are wrong
import_chalk4.default[colour](" ".repeat(consoleWidth - 10)) + "\n";
const tag = paddingLine + iconTag + " " + // @ts-ignore-implicit-any - chalk typings are wrong
import_chalk4.default.bold.white[colour](
` ${type.toUpperCase()}${" ".repeat(consoleWidth - type.length - 12)}
`
) + paddingLine;
const line = import_chalk4.default.white("\u2500".repeat(consoleWidth));
const paddedMessage = message2.replace(/\n/g, "\n ");
const wrappedMessage = paddedMessage.replace(
new RegExp(`(.{${consoleWidth - 20}})(\\s|$)`, "g"),
"$1\n "
);
ui.log.write(
`
${tag}\r
${import_chalk4.default.white(wrappedMessage)}\r
${line}\r
`
);
};
// src/helpers/console/throw-error.ts
var throw_error_default = (message2) => {
const newMessage = print_message_default(message2, "danger", true);
throw new Error(newMessage);
};
// src/helpers/console/confirm.ts
var import_chalk5 = __toESM(require("chalk"));
var import_process2 = __toESM(require("process"));
var import_readline2 = __toESM(require("readline"));
var confirm = (message2) => {
return new Promise((resolve) => {
const rl = import_readline2.default.createInterface({
input: import_process2.default.stdin,
output: import_process2.default.stdout
});
rl.question(import_chalk5.default.blue(`\u{1F914} ${message2} [y/N] `), (answer) => {
answer = answer.toLowerCase();
rl.close();
if (answer === "y") {
resolve(true);
} else {
resolve(false);
}
});
});
};
var confirm_default = confirm;
// src/helpers/file/check-and-copy-path.ts
var import_fs = __toESM(require("fs"));
var copyPath = (sourcePath, destinationPath) => {
return import_fs.default.cpSync(sourcePath, destinationPath, {
dereference: true,
recursive: true,
force: true
});
};
var check_and_copy_path_default = copyPath;
// src/helpers/file/copy-dir.ts
var import_node_fs = __toESM(require("fs"));
var import_node_path = __toESM(require("path"));
var copyDir = (source, destination) => {
if (!import_node_fs.default.existsSync(destination)) {
import_node_fs.default.mkdirSync(destination, { recursive: true });
}
import_node_fs.default.readdirSync(source).forEach((file) => {
const srcPath = import_node_path.default.resolve(source, file);
const destPath = import_node_path.default.join(destination, file);
if (import_node_fs.default.lstatSync(srcPath).isDirectory()) {
copyDir(srcPath, destPath);
} else {
import_node_fs.default.cpSync(srcPath, destPath, {
recursive: true,
dereference: true
});
}
});
};
var copy_dir_default = copyDir;
// src/helpers/file/update-config.ts
var import_fs2 = __toESM(require("fs"));
var import_path = __toESM(require("path"));
var updateConfig = (update) => {
if (import_fs2.default.existsSync(import_path.default.resolve(process.cwd(), "package.json"))) {
const configFile = JSON.parse(
import_fs2.default.readFileSync(import_path.default.resolve(process.cwd(), "package.json"), "utf8")
);
const config = configFile;
const newConfig = __spreadProps(__spreadValues({}, config), {
builda: update === null ? void 0 : __spreadValues({}, update)
});
import_fs2.default.writeFileSync(
import_path.default.resolve(process.cwd(), "package.json"),
JSON.stringify(newConfig, null, 2)
);
} else {
throw_error_default("No package.json found in project");
}
};
var update_config_default = updateConfig;
// src/helpers/file/create-dir.ts
var import_fs3 = __toESM(require("fs"));
var createDir = async (dirPath) => {
try {
if (!import_fs3.default.existsSync(dirPath)) {
import_fs3.default.mkdirSync(dirPath, { recursive: true });
}
return true;
} catch (err) {
return false;
}
};
var create_dir_default = createDir;
// src/helpers/file/get-config.ts
var import_fs4 = __toESM(require("fs"));
var import_path2 = __toESM(require("path"));
var getConfig = (allowFailure) => {
if (import_fs4.default.existsSync(import_path2.default.resolve(process.cwd(), "package.json"))) {
const configFile = JSON.parse(
import_fs4.default.readFileSync(import_path2.default.resolve(process.cwd(), "package.json"), "utf8")
);
const config = configFile.builda;
if (!config && !allowFailure) {
throw_error_default('No "builda" entry found in package.json');
} else if (!config && allowFailure) {
return {};
}
return config;
}
return throw_error_default("No package.json found in project");
};
var get_config_default = getConfig;
// src/helpers/file/get-ignore-list.ts
var import_fs5 = __toESM(require("fs"));
var import_path3 = __toESM(require("path"));
var getInitialList = (ignoreFilePath, prefabDir) => {
const ignoreList = [];
const ignoreFile = import_fs5.default.readFileSync(ignoreFilePath, "utf8");
const lines = ignoreFile.split("\n");
for (const line of lines) {
if (line !== "" && line.startsWith("@extends")) {
const extendsFile = line.split(" ")[1];
if (import_fs5.default.existsSync(import_path3.default.resolve(prefabDir, extendsFile))) {
const extendsIgnoreFile = import_fs5.default.readFileSync(
import_path3.default.resolve(prefabDir, extendsFile),
"utf8"
);
const extendsLines = extendsIgnoreFile.split("\n");
for (const extendsLine of extendsLines) {
if (extendsLine !== "" && !extendsLine.startsWith("#")) {
if (extendsFile == null ? void 0 : extendsFile.includes("/")) {
const fileName = extendsFile.split("/").pop();
const directoryPath = extendsFile.replace(fileName, "");
ignoreList.push(import_path3.default.join(directoryPath, extendsLine));
} else {
ignoreList.push(extendsLine);
}
}
}
} else {
throw_error_default(
`File ${extendsFile} does not exist. Please check your .buildaignore file.`
);
}
} else if (line !== "" && line.startsWith("@")) {
throw_error_default(
`Invalid line in .buildaignore file: ${line}. Only @extends is allowed to start with @.`
);
} else if (line !== "" && line.startsWith("!")) {
continue;
} else if (line !== "" && !line.startsWith("#")) {
ignoreList.push(line);
}
}
return [...new Set(ignoreList)];
};
var extendIgnoreList = (prefabDir, ignoreList) => {
const extendedIgnoreList = [];
for (const ignoreItem of ignoreList) {
const ignoreItemPath = import_path3.default.join(prefabDir, ignoreItem);
if (ignoreItem.includes("*")) {
continue;
} else if (ignoreItem.includes("/")) {
extendedIgnoreList.push(ignoreItemPath);
} else {
extendedIgnoreList.push(`**/${ignoreItem}`);
}
}
return extendedIgnoreList;
};
var getIgnoreList = (workingDir, fromModule) => {
const prefabDir = fromModule ? "module" : import_path3.default.join(workingDir, "modules", "prefab");
const ignoreFile = import_path3.default.resolve(prefabDir, ".buildaignore");
if (import_fs5.default.existsSync(ignoreFile)) {
const initialList = getInitialList(ignoreFile, prefabDir);
return extendIgnoreList(prefabDir, initialList);
}
return [];
};
var get_ignore_list_default = getIgnoreList;
// src/helpers/file/loop-and-rewrite-files.ts
var import_node_path2 = __toESM(require("path"));
var import_node_fs2 = __toESM(require("fs"));
var import_glob = __toESM(require("glob"));
var loopAndRewriteFiles = async ({
log,
name,
paths,
substitute,
source,
destination
}) => {
const { buildaDir: buildaDir2 } = globals_default;
const prefabDir = import_node_path2.default.join(buildaDir2, "modules", "prefab");
const propsList = {
log,
name,
paths,
substitute,
source,
destination
};
const promises = [];
for (const file of paths) {
const filePath = import_node_path2.default.join(source, file);
if (check_if_ignored_default(buildaDir2, filePath)) {
continue;
}
if (file.includes("*")) {
const globFiles = import_glob.default.sync(filePath).map((f) => import_node_path2.default.relative(prefabDir, f));
promises.push(
await loopAndRewriteFiles(__spreadProps(__spreadValues({}, propsList), {
paths: globFiles
}))
);
} else if (import_node_fs2.default.lstatSync(filePath).isDirectory()) {
const files = import_node_fs2.default.readdirSync(filePath);
const newFiles = files.map((f) => import_node_path2.default.join(file, f));
promises.push(
await loopAndRewriteFiles(__spreadProps(__spreadValues({}, propsList), {
paths: newFiles
}))
);
} else {
promises.push(
new Promise((resolve) => {
const basePath = import_node_path2.default.dirname(file);
const directoryPath = import_node_path2.default.join(destination, basePath);
if (check_if_ignored_default(buildaDir2, filePath)) {
return;
}
create_dir_default(directoryPath);
if (import_node_fs2.default.existsSync(filePath)) {
const subs = substitute.map((substitution) => {
if (substitution.reverseInExport && (directoryPath.includes("export") || directoryPath.includes("prefab"))) {
return __spreadProps(__spreadValues({}, substitution), {
replace: substitution.with,
with: substitution.replace
});
}
return substitution;
});
write_file_default({
file: filePath,
outputDir: directoryPath,
substitute: subs,
name
});
}
resolve(filePath);
})
);
}
}
await Promise.all(promises);
};
var loop_and_rewrite_files_default = loopAndRewriteFiles;
// src/helpers/file/write-file.ts
var import_fs6 = __toESM(require("fs"));
var import_path4 = __toESM(require("path"));
var import_prettier = __toESM(require("prettier"));
var prettierAllowedFileTypes = [
"css",
"html",
"js",
"jsx",
"json",
"less",
"md",
"mdx",
"scss",
"sass",
"ts",
"tsx",
"yaml",
"yml",
"graphql"
];
var writeFile = ({
file,
rename,
content,
outputDir,
substitute,
name
}) => {
let fileName = file;
if (rename) {
fileName = rename;
}
fileName = fileName == null ? void 0 : fileName.split("/").pop();
const fileContent = file ? import_fs6.default.readFileSync(import_path4.default.resolve(file), "utf8") : "";
let newContent = content != null ? content : fileContent;
if (name) {
newContent = fileContent.replace(/prefab-name-replace-string/g, change_case_default(name, "kebabCase")).replace(/%KEBAB_CASE%/g, change_case_default(name, "kebabCase")).replace(/%CAMEL_CASE%/g, change_case_default(name, "camelCase")).replace(/%SNAKE_CASE%/g, change_case_default(name, "snakeCase")).replace(/%PASCAL_CASE%/g, change_case_default(name, "pascalCase")).replace(/%SENTENCE_CASE%/g, change_case_default(name, "sentenceCase"));
}
if (substitute && substitute.length > 0) {
substitute.forEach((sub) => {
const needle = `${sub.replace}`;
const regex = new RegExp(needle, "g");
newContent = newContent.replace(regex, sub.with);
});
}
const fileType = fileName == null ? void 0 : fileName.split(".").pop();
if (fileType && prettierAllowedFileTypes.includes(fileType)) {
newContent = file ? import_prettier.default.format(newContent, {
filepath: import_path4.default.resolve(file)
}) : newContent;
}
if (newContent) {
return import_fs6.default.writeFileSync(`${outputDir}/${fileName}`, newContent);
}
throw new Error(`Could not write file ${fileName}`);
};
var write_file_default = writeFile;
// src/helpers/file/write-log-file.ts
var import_node_fs3 = __toESM(require("fs"));
var import_node_path3 = __toESM(require("path"));
var import_node_process = __toESM(require("process"));
// src/helpers/file/copy-paths-to-root.ts
var import_node_fs4 = __toESM(require("fs"));
var import_node_path4 = __toESM(require("path"));
var { buildaDir } = globals_default;
var copy_paths_to_root_default = async (paths, rootDir, deleteOriginal) => {
const prefabDir = import_node_path4.default.join(rootDir, buildaDir, "modules", "prefab");
paths.forEach(async (file) => {
const filePath = import_node_path4.default.join(prefabDir, file);
import_node_fs4.default.cpSync(filePath, import_node_path4.default.join(rootDir, file), { recursive: true });
if (deleteOriginal) {
import_node_fs4.default.rmSync(filePath, { recursive: true, force: true });
}
});
};
// src/helpers/file/sync-with-export.ts
var import_node_path6 = __toESM(require("path"));
var import_node_fs6 = __toESM(require("fs"));
// src/helpers/file/sync-package-json.ts
var import_node_path5 = __toESM(require("path"));
var import_node_fs5 = __toESM(require("fs"));
var syncPackageJson = async () => {
if (import_node_fs5.default.existsSync(import_node_path5.default.resolve(process.cwd(), "package.json"))) {
const packageJsonFile = JSON.parse(
import_node_fs5.default.readFileSync(import_node_path5.default.resolve(process.cwd(), "package.json"), "utf8")
);
const prefabPackageJsonFile = JSON.parse(
import_node_fs5.default.readFileSync(
import_node_path5.default.resolve(
process.cwd(),
globals_default.buildaDir,
"modules",
"prefab",
"package.json"
),
"utf8"
)
);
const prefabScripts = prefabPackageJsonFile.scripts;
const updatedScripts = packageJsonFile.scripts;
const newScripts = Object.keys(updatedScripts).filter((script) => {
return !Object.keys(prefabScripts).includes(script);
});
const scripts = __spreadValues({}, prefabScripts);
newScripts.forEach((script) => {
scripts[script] = updatedScripts[script];
});
const newPackageJson = __spreadProps(__spreadValues({}, packageJsonFile), {
scripts,
dependencies: __spreadValues({}, packageJsonFile.dependencies),
devDependencies: packageJsonFile.devDependencies ? __spreadValues({}, packageJsonFile.devDependencies) : void 0,
peerDependencies: packageJsonFile.peerDependencies ? __spreadValues({}, packageJsonFile.peerDependencies) : void 0
});
import_node_fs5.default.writeFileSync(
import_node_path5.default.resolve(process.cwd(), globals_default.buildaDir, "export", "package.json"),
JSON.stringify(newPackageJson, null, 2)
);
} else {
throw_error_default("No package.json found in project");
}
};
var sync_package_json_default = syncPackageJson;
// src/helpers/file/sync-with-export.ts
var syncWithExport = async ({ type, pathString }) => {
var _a, _b;
const root = process.cwd();
const exportRoot = import_node_path6.default.join(root, globals_default.buildaDir, "export");
const registry = await get_registry_default(exportRoot);
if (type === "copy") {
if (pathString === "package.json") {
return;
}
return check_and_copy_path_default(`${root}/${pathString}`, import_node_path6.default.join(exportRoot, pathString));
}
if (type === "update") {
if (pathString === "package.json") {
return syncPackageJson();
}
const fileWithSubstitutions = (_b = (_a = registry.generatorOptions) == null ? void 0 : _a.rootFiles) == null ? void 0 : _b.find(
(rootFile) => {
if (typeof rootFile === "string") {
return false;
} else if (!rootFile.substitutions || rootFile.substitutions.length === 0) {
return false;
} else {
return rootFile.path === pathString;
}
}
);
if (fileWithSubstitutions) {
await loop_and_rewrite_files_default({
log: true,
name: registry.name,
paths: [pathString],
substitute: fileWithSubstitutions.substitutions,
source: root,
destination: exportRoot
});
} else {
return check_and_copy_path_default(
`${root}/${pathString}`,
import_node_path6.default.join(exportRoot, pathString)
);
}
}
if (type === "delete") {
if (pathString === "package.json") {
throw_error_default("package.json deleted. This will break your project");
}
return import_node_fs6.default.rmSync(import_node_path6.default.join(exportRoot, pathString), {
recursive: true,
force: true
});
}
};
var sync_with_export_default = syncWithExport;
// src/helpers/file/check-if-ignored.ts
var checkIfIgnored = (workingDir, filePath) => {
const ignoreList = get_ignore_list_default(workingDir);
for (const ignore of ignoreList) {
if (ignore.startsWith("**/")) {
const ignorePath = ignore.replace("**/", "");
const baseFileName = filePath.split("/").pop();
if (ignorePath === baseFileName) {
return true;
}
} else if (ignore === filePath) {
return true;
}
}
return false;
};
var check_if_ignored_default = checkIfIgnored;
// src/helpers/file/generate-export.ts
var import_node_fs7 = __toESM(require("fs"));
var import_node_path7 = __toESM(require("path"));
async function generateExport({
buildaDir: buildaDir2,
prefabDir
}) {
if (!import_node_fs7.default.existsSync(prefabDir)) {
throw_error_default("No prefab found, cannot export");
}
const workingDir = import_node_path7.default.join(buildaDir2, "export");
print_message_default("Creating export path...", "processing");
if (import_node_fs7.default.existsSync(workingDir)) {
import_node_fs7.default.rmSync(workingDir, { recursive: true });
}
copy_dir_default(prefabDir, workingDir);
print_message_default("Export path created", "success");
const exportBuildaDir = import_node_path7.default.join(workingDir, ".builda");
if (import_node_fs7.default.existsSync(exportBuildaDir)) {
import_node_fs7.default.rmSync(exportBuildaDir, { recursive: true });
}
print_message_default("Initial export created", "success");
}
var generate_export_default = generateExport;
// src/helpers/file/generate-from-prefab.ts
var import_node_fs8 = __toESM(require("fs"));
var import_node_path8 = __toESM(require("path"));
async function generateFromPrefab({
prefabPath,
rootDir,
prefabDir,
name,
buildaDir: buildaDir2
}) {
var _a, _b;
let module2;
if (detect_path_type_default(prefabPath) === "remote") {
const registry = convert_registry_path_to_url_default({
registryPath: prefabPath
}).url;
if (!registry) {
throw_error_default("No registry found");
}
module2 = await add_remote_module_default(registry, rootDir);
} else {
module2 = await add_local_module_default(prefabPath, rootDir);
}
if (!(module2 == null ? void 0 : module2.name)) {
throw_error_default("No prefab found");
}
const prefabName = module2.name;
const version = module2.version;
print_message_default(`Installed ${prefabName}@${version}`, "success");
(_b = (_a = module2 == null ? void 0 : module2.generatorOptions) == null ? void 0 : _a.rootFiles) == null ? void 0 : _b.forEach(async (file) => {
var _a2;
if (typeof file !== "string") {
const substitute = (_a2 = file.substitutions) != null ? _a2 : [];
await loop_and_rewrite_files_default({
name,
paths: [file.path],
substitute,
source: prefabDir,
destination: prefabDir
});
}
});
if (module2.blueprints) {
print_message_default("Installing prefab blueprints...", "installing");
const blueprintPromises = [];
const blueprints = Object.keys(module2.blueprints);
for (const blueprint of blueprints) {
const bp = module2.blueprints[blueprint];
print_message_default(`Installing blueprint: "${blueprint}"`, "processing");
const blueprintDest = import_node_path8.default.join(
rootDir,
buildaDir2,
"modules",
"blueprints"
);
create_dir_default(blueprintDest);
if (bp.location === "prefab") {
const blueprintSrc = import_node_path8.default.join(
prefabDir,
buildaDir2,
"modules",
"blueprints",
blueprint
);
if (import_node_fs8.default.existsSync(blueprintSrc)) {
copy_dir_default(blueprintSrc, import_node_path8.default.join(blueprintDest, blueprint));
}
} else {
const bluePrintType = detect_path_type_default(bp.location);
blueprintPromises.push(
new Promise((resolve) => {
if (bluePrintType === "local") {
add_local_module_default(bp.location, rootDir);
}
if (bluePrintType === "remote") {
const registry = convert_registry_path_to_url_default({
registryPath: bp.location
}).url;
if (!registry) {
throw_error_default("No registry found");
}
add_remote_module_default(registry, rootDir);
}
resolve(blueprint);
})
);
}
print_message_default(`${blueprint} installed`, "success");
}
await Promise.all(blueprintPromises);
}
print_message_default("Prefab has been set up.", "success");
return module2;
}
var generate_from_prefab_default = generateFromPrefab;
// src/helpers/file/recurse-directories.ts
var import_node_path9 = __toESM(require("path"));
var import_node_fs9 = __toESM(require("fs"));
var import_glob2 = __toESM(require("glob"));
var recurseDirectories = async ({
log,
paths,
source
}) => {
const { buildaDir: buildaDir2 } = globals_default;
const prefabDir = import_node_path9.default.join(buildaDir2, "modules", "prefab");
const propsList = {
log,
paths,
source
};
const promises = [];
for (const file of paths) {
const filePath = import_node_path9.default.join(source, file);
if (check_if_ignored_default(buildaDir2, filePath)) {
continue;
}
if (file.includes("*")) {
const globFiles = import_glob2.default.sync(filePath).map((f) => import_node_path9.default.relative(prefabDir, f));
promises.push(
await recurseDirectories(__spreadProps(__spreadValues({}, propsList), {
paths: globFiles
}))
);
} else if (import_node_fs9.default.lstatSync(filePath).isDirectory()) {
const files = import_node_fs9.default.readdirSync(filePath);
const newFiles = files.map((f) => import_node_path9.default.join(file, f));
promises.push(
await recurseDirectories(__spreadProps(__spreadValues({}, propsList), {
paths: newFiles
}))
);
} else {
promises.push(
new Promise((resolve) => {
resolve(filePath);
})
);
}
}
return Promise.all(promises.flat());
};
var recurse_directories_default = recurseDirectories;
// src/helpers/module/add-local-module.ts
var import_node_fs10 = __toESM(require("fs"));
var import_tar = __toESM(require("tar"));
var import_node_path10 = __toESM(require("path"));
var getFiles = async (modulePath, outputPath, location) => {
const tarball = import_node_fs10.default.existsSync(`${modulePath}/${location}.tgz`);
if (tarball) {
import_node_fs10.default.copyFileSync(
`${modulePath}/${location}.tgz`,
`${outputPath}/${location}.tgz`
);
await import_tar.default.extract({
file: `${outputPath}/${location}.tgz`,
cwd: outputPath
});
import_node_fs10.default.unlinkSync(`${outputPath}/${location}.tgz`);
} else {
throw_error_default("No tarball found. Please run `builda package` first");
}
};
var addLocalModule = async (modulePath, output) => {
const buildaDir2 = import_node_path10.default.join(output || "./", globals_default.buildaDir);
const registry = await get_registry_default(modulePath);
const outputPath = registry.type === "blueprint" ? `${buildaDir2}/modules/blueprints/${registry.name}` : `${buildaDir2}/modules/prefab`;
await create_dir_default(outputPath);
await getFiles(modulePath, outputPath, "module");
import_node_fs10.default.writeFileSync(`${outputPath}/registry.json`, JSON.stringify(registry));
return registry;
};
var add_local_module_default = addLocalModule;
// src/helpers/module/add-remote-module.ts
var import_node_fs12 = __toESM(require("fs"));
var import_node_path11 = __toESM(require("path"));
var import_axios2 = __toESM(require("axios"));
var import_tar2 = __toESM(require("tar"));
// src/helpers/module/get-registry.ts
var import_node_fs11 = __toESM(require("fs"));
var import_node_process2 = __toESM(require("process"));
var import_axios = __toESM(require("axios"));
var getRegistry = async (registryPath) => {
const REGISTRYFILE = "registry.json";
registryPath = registryPath || import_node_process2.default.cwd();
const pathType = detect_path_type_default(registryPath);
if (pathType === "local") {
return JSON.parse(
import_node_fs11.default.readFileSync(`${registryPath}/${REGISTRYFILE}`, "utf8")
);
}
const resolved = convert_registry_path_to_url_default({ registryPath });
if (resolved.error) {
throw_error_default(resolved.error);
}
let url = resolved.url;
if (url.includes("%FILE_NAME%")) {
url = url.replace("%FILE_NAME%", REGISTRYFILE);
} else {
url = `${url}/${REGISTRYFILE}`;
}
const validModule = await validate_module_path_default(url, true);
if (!validModule.status) {
throw_error_default(validModule.message);
}
return import_axios.default.get(url, {
responseType: "json"
}).then((response) => {
return response.data;
}).catch((error) => {
throw_error_default(error.message);
});
};
var get_registry_default = getRegistry;
// src/helpers/module/add-remote-module.ts
var addRemoteModule = async (modulePath, output) => {
const buildaDir2 = import_node_path11.default.join(output || "./", globals_default.buildaDir);
const registry = await get_registry_default(modulePath);
const outputPath = registry.type === "blueprint" ? `${buildaDir2}/modules/blueprints/${registry.name}` : `${buildaDir2}/modules/prefab`;
await create_dir_default(outputPath);
print_message_default(`Downloading ${registry.name}...`, "downloading");
await import_axios2.default.get(`${modulePath}/module.tgz`, {
responseType: "arraybuffer",
headers: {
"Content-Type": "application/gzip"
}
}).then(
(res) => import_node_fs12.default.writeFileSync(`${outputPath}/module.tgz`, res.data, {
encoding: "binary"
})
).then(async () => {
if (import_node_fs12.default.existsSync(`${outputPath}/module.tgz`)) {
print_message_default("Extracting module files...", "config");
try {
await import_tar2.default.extract({
file: `${outputPath}/module.tgz`,
cwd: outputPath
});
import_node_fs12.default.unlinkSync(`${outputPath}/module.tgz`);
} catch (err) {
throw_error_default(err);
}
}
}).catch((err) => {
throw_error_default(
`There was an error downloading the tarball. Please check the URL and try again.
${err}`
);
}).finally(() => {
print_message_defau