@lorenzo.franzone/tws
Version:
Tailwind 4 Styles Generator
90 lines (89 loc) • 3.96 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.initCommand = initCommand;
const chalk_1 = __importDefault(require("chalk"));
const fs = __importStar(require("fs-extra"));
const promises_1 = require("node:timers/promises");
const prompts_1 = require("@clack/prompts");
const consts_1 = require("../../data/consts");
const logger_1 = require("../../utils/logger");
const ConfigCommand_1 = require("./ConfigCommand");
// Main function to initialize a new project configuration
async function initCommand(options) {
console.clear();
// Display a cool intro banner
(0, prompts_1.intro)(chalk_1.default.bgBlue.white(` ${consts_1.APP_NAME.toUpperCase()} - Project initialization `));
// Check if config folder already exists
const exists = await fs.pathExists(consts_1.CONFIG_DIR);
if (exists) {
// Ask the user if we should overwrite the existing folder (unless 'force' is passed)
const overwrite = options.force
? true
: await (0, prompts_1.confirm)({
message: `Heads up! Looks like the "${consts_1.CONFIG_DIR_NAME}" folder already exists. Want to start fresh?`,
});
if ((0, prompts_1.isCancel)(overwrite)) {
(0, prompts_1.cancel)('Got it. No changes made - you’re in control.');
return;
}
if (!overwrite) {
(0, logger_1.logError)('No worries. Setup was skipped - nothing changed.');
return;
}
// Remove the existing config directory before proceeding
await fs.remove(consts_1.CONFIG_DIR);
}
// Start a spinner to indicate progress
const s = (0, prompts_1.spinner)();
s.start(`Hang tight... we're setting up the "${consts_1.CONFIG_DIR_NAME}" folder 🛠️`);
await (0, promises_1.setTimeout)(1000); // Small delay for UX feel
try {
// Create the new config directory
await fs.mkdir(consts_1.CONFIG_DIR);
s.stop(chalk_1.default.green(`Nice! The "${consts_1.CONFIG_DIR_NAME}" folder is ready to roll.`));
// Outro message to signal success
(0, prompts_1.outro)(chalk_1.default.blue.bold.underline(`All done! Your project is good to go.`));
}
catch (error) {
s.stop('Uh-oh... something went wrong while creating the folder.');
throw error;
}
// Continue with additional config setup
await (0, ConfigCommand_1.configCommand)(options);
}