gluestack-ui
Version:
A CLI tool for easily adding components from gluestack to your projects.
90 lines (89 loc) • 4.79 kB
JavaScript
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
(function (factory) {
if (typeof module === "object" && typeof module.exports === "object") {
var v = factory(require, exports);
if (v !== undefined) module.exports = v;
}
else if (typeof define === "function" && define.amd) {
define(["require", "exports", "commander", "zod", "../util/handle-error", "@clack/prompts", "../util/init", "../config", "../util", "path", "fs"], factory);
}
})(function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.init = void 0;
const commander_1 = require("commander");
const zod_1 = require("zod");
const handle_error_1 = require("../util/handle-error");
const prompts_1 = require("@clack/prompts");
const init_1 = require("../util/init");
const config_1 = require("../config");
const util_1 = require("../util");
const path_1 = __importDefault(require("path"));
const fs_1 = __importDefault(require("fs"));
const initOptionsSchema = zod_1.z.object({
useNpm: zod_1.z.boolean(),
useYarn: zod_1.z.boolean(),
usePnpm: zod_1.z.boolean(),
useBun: zod_1.z.boolean(),
path: zod_1.z.string().optional(),
templateOnly: zod_1.z.boolean(),
projectType: zod_1.z.string(),
});
exports.init = new commander_1.Command()
.name('init')
.description('Initialize gluestack into your project')
.option('--use-npm ,useNpm', 'use npm to install dependencies', false)
.option('--use-yarn, useYarn', 'use yarn to install dependencies', false)
.option('--use-pnpm, usePnpm', 'use pnpm to install dependencies', false)
.option('--use-bun, useBun', 'use bun to install dependencies', false)
.option('--path <path>', 'path to the components directory. defaults to components/ui')
.option('--template-only templateOnly', 'Only install the template without installing dependencies', false)
.option('--projectType <projectType>', 'Type of project to initialize', 'library')
.action((opts) => __awaiter(void 0, void 0, void 0, function* () {
try {
const options = initOptionsSchema.parse(Object.assign({}, opts));
const isTemplate = options.templateOnly;
console.log('\n\x1b[1mWelcome to gluestack-ui v3!\x1b[0m\n');
const cwd = process.cwd();
if (!fs_1.default.existsSync(path_1.default.join(cwd, 'package.json'))) {
prompts_1.log.error(`\x1b[31mNo package.json found in the current directory. Please run this command in a directory with a package.json file.\x1b[0m`);
process.exit(1);
}
if ((options.useNpm && options.useYarn) ||
(options.useNpm && options.usePnpm) ||
(options.useYarn && options.usePnpm)) {
prompts_1.log.error(`\x1b[31mMultiple package managers selected. Please select only one package manager.\x1b[0m`);
process.exit(1);
}
(0, util_1.getPackageMangerFlag)(options);
if (options.path) {
if (!(0, util_1.isValidPath)(options.path)) {
prompts_1.log.error(`\x1b[31mInvalid path "${options.path}". Please provide a valid path for installing components.\x1b[0m`);
process.exit(1);
}
if (options.path !== config_1.config.writableComponentsPath) {
yield (0, util_1.checkWritablePath)(options.path);
config_1.config.writableComponentsPath = options.path;
}
}
const projectType = isTemplate
? options.projectType
: yield (0, util_1.detectProjectType)(cwd);
(0, init_1.InitializeGlueStack)({ projectType, isTemplate });
}
catch (err) {
(0, handle_error_1.handleError)(err);
}
}));
});