untitledui 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commands/add.js +339 -0
- package/dist/commands/init.js +436 -0
- package/dist/helper/download-tar-api.js +129 -0
- package/dist/helper/download-tar.js +81 -0
- package/dist/helper/find-css-file.js +19 -0
- package/dist/helper/formatText.js +37 -0
- package/dist/helper/get-components-api.js +47 -0
- package/dist/helper/get-components-list.js +62 -0
- package/dist/helper/get-components.js +19 -0
- package/dist/helper/get-config.js +163 -0
- package/dist/helper/get-package-info.js +99 -0
- package/dist/helper/get-pkg-manager.js +16 -0
- package/dist/helper/get-project.js +176 -0
- package/dist/helper/install-template.js +29 -0
- package/dist/helper/match-color-css.js +82 -0
- package/dist/helper/update-color-css.js +134 -0
- package/dist/index.js +25 -0
- package/dist/package.json +50 -0
- package/dist/res/components.json +520 -0
- package/dist/res/config.json +3 -0
- package/package.json +61 -0
- package/templates/default/.prettierrc +10 -0
- package/templates/default/README.md +36 -0
- package/templates/default/eslint.config.mjs +58 -0
- package/templates/default/next.config.ts +6 -0
- package/templates/default/package.json +57 -0
- package/templates/default/postcss.config.js +5 -0
- package/templates/default/public/favicon.ico +0 -0
- package/templates/default/public/marketing/smiling-girl.png +0 -0
- package/templates/default/public/marketing/spirals.webp +0 -0
- package/templates/default/src/app/home-screen.tsx +109 -0
- package/templates/default/src/app/layout.tsx +42 -0
- package/templates/default/src/app/not-found.tsx +40 -0
- package/templates/default/src/app/page.tsx +3 -0
- package/templates/default/src/components/foundations/dot-icon.tsx +27 -0
- package/templates/default/src/components/foundations/featured-icon/featured-icons.tsx +153 -0
- package/templates/default/src/components/foundations/logo/UntitledLogo.tsx +63 -0
- package/templates/default/src/components/foundations/logo/UntitledLogoMinimal.tsx +164 -0
- package/templates/default/src/components/foundations/payment-icons/amex-icon.tsx +19 -0
- package/templates/default/src/components/foundations/payment-icons/apple-pay-icon.tsx +27 -0
- package/templates/default/src/components/foundations/payment-icons/discover-icon.tsx +34 -0
- package/templates/default/src/components/foundations/payment-icons/index.tsx +10 -0
- package/templates/default/src/components/foundations/payment-icons/mastercard-icon.tsx +39 -0
- package/templates/default/src/components/foundations/payment-icons/paypal-icon.tsx +45 -0
- package/templates/default/src/components/foundations/payment-icons/stripe-icon.tsx +27 -0
- package/templates/default/src/components/foundations/payment-icons/union-pay-icon.tsx +37 -0
- package/templates/default/src/components/foundations/payment-icons/visa-icon.tsx +27 -0
- package/templates/default/src/components/marketing/header-navigation/base-components/nav-menu-item.tsx +41 -0
- package/templates/default/src/components/marketing/header-navigation/components/header.tsx +245 -0
- package/templates/default/src/components/marketing/header-navigation/dropdown-header-navigation.tsx +53 -0
- package/templates/default/src/components/shared/avatar/avatar-label-group.tsx +32 -0
- package/templates/default/src/components/shared/avatar/avatar-profile-photo.tsx +84 -0
- package/templates/default/src/components/shared/avatar/avatar.tsx +131 -0
- package/templates/default/src/components/shared/avatar/base-components/avatar-add-button.tsx +33 -0
- package/templates/default/src/components/shared/avatar/base-components/avatar-company-icon.tsx +26 -0
- package/templates/default/src/components/shared/avatar/base-components/avatar-online-indicator.tsx +31 -0
- package/templates/default/src/components/shared/avatar/base-components/index.ts +4 -0
- package/templates/default/src/components/shared/avatar/base-components/verified-tick.tsx +34 -0
- package/templates/default/src/components/shared/avatar/utils.ts +12 -0
- package/templates/default/src/components/shared/badges/badge-groups.tsx +176 -0
- package/templates/default/src/components/shared/badges/badge-types.ts +264 -0
- package/templates/default/src/components/shared/badges/badges.tsx +479 -0
- package/templates/default/src/components/shared/button-group/button-group.tsx +97 -0
- package/templates/default/src/components/shared/buttons/app-store-buttons-outline.tsx +454 -0
- package/templates/default/src/components/shared/buttons/app-store-buttons.tsx +806 -0
- package/templates/default/src/components/shared/buttons/button-utility.tsx +87 -0
- package/templates/default/src/components/shared/buttons/button.tsx +284 -0
- package/templates/default/src/components/shared/buttons/close-button.tsx +39 -0
- package/templates/default/src/components/shared/buttons/social-button.tsx +135 -0
- package/templates/default/src/components/shared/buttons/social-logos.tsx +115 -0
- package/templates/default/src/components/shared/checkbox/checkbox.tsx +120 -0
- package/templates/default/src/components/shared/dropdown/dropdown.tsx +138 -0
- package/templates/default/src/components/shared/input-dropdown/combobox.tsx +161 -0
- package/templates/default/src/components/shared/input-dropdown/dropdown-item.tsx +98 -0
- package/templates/default/src/components/shared/input-dropdown/input-dropdown.tsx +172 -0
- package/templates/default/src/components/shared/input-dropdown/multi-select.tsx +373 -0
- package/templates/default/src/components/shared/input-dropdown/popover.tsx +36 -0
- package/templates/default/src/components/shared/input-dropdown/select.tsx +63 -0
- package/templates/default/src/components/shared/inputs/file-upload-trigger.tsx +74 -0
- package/templates/default/src/components/shared/inputs/form/form.tsx +10 -0
- package/templates/default/src/components/shared/inputs/hint-text.tsx +34 -0
- package/templates/default/src/components/shared/inputs/input/index.tsx +189 -0
- package/templates/default/src/components/shared/inputs/input/input-payment.tsx +134 -0
- package/templates/default/src/components/shared/inputs/input/input-with-button.tsx +69 -0
- package/templates/default/src/components/shared/inputs/input/input-with-dropdown.tsx +178 -0
- package/templates/default/src/components/shared/inputs/input/input-with-prefix.tsx +74 -0
- package/templates/default/src/components/shared/inputs/label.tsx +46 -0
- package/templates/default/src/components/shared/inputs/textarea/textarea.tsx +82 -0
- package/templates/default/src/components/shared/progress-indicators/progress-circles.tsx +176 -0
- package/templates/default/src/components/shared/progress-indicators/progress-indicators.tsx +86 -0
- package/templates/default/src/components/shared/progress-indicators/simple-circle.tsx +29 -0
- package/templates/default/src/components/shared/radio-buttons/radio-buttons.tsx +125 -0
- package/templates/default/src/components/shared/radio-groups/radio-group-avatar.tsx +62 -0
- package/templates/default/src/components/shared/radio-groups/radio-group-checkbox.tsx +72 -0
- package/templates/default/src/components/shared/radio-groups/radio-group-icon-card.tsx +95 -0
- package/templates/default/src/components/shared/radio-groups/radio-group-icon-simple.tsx +70 -0
- package/templates/default/src/components/shared/radio-groups/radio-group-payment-icon.tsx +71 -0
- package/templates/default/src/components/shared/radio-groups/radio-group-radio-button.tsx +76 -0
- package/templates/default/src/components/shared/radio-groups/radio-groups.tsx +8 -0
- package/templates/default/src/components/shared/slider/slider.tsx +76 -0
- package/templates/default/src/components/shared/tags/base-components/tag-checkbox.tsx +47 -0
- package/templates/default/src/components/shared/tags/base-components/tag-close-x.tsx +34 -0
- package/templates/default/src/components/shared/tags/tags.tsx +162 -0
- package/templates/default/src/components/shared/toggle/toggle.tsx +140 -0
- package/templates/default/src/components/shared/tooltips/tooltips.tsx +140 -0
- package/templates/default/src/components/utils/index.ts +48 -0
- package/templates/default/src/components/utils/isDeepEqual.ts +31 -0
- package/templates/default/src/components/utils/isReactComponent.ts +22 -0
- package/templates/default/src/components/utils/mergeRefs.ts +19 -0
- package/templates/default/src/components/utils/useBreakpoint.ts +36 -0
- package/templates/default/src/components/utils/uuid.ts +9 -0
- package/templates/default/src/fonts/GeistMonoVF.woff +0 -0
- package/templates/default/src/fonts/GeistVF.woff +0 -0
- package/templates/default/src/hooks/use-resize-observer.tsx +55 -0
- package/templates/default/src/providers/theme.tsx +11 -0
- package/templates/default/src/styles/colors.css +805 -0
- package/templates/default/src/styles/globals.css +86 -0
- package/templates/default/src/styles/text-styles.css +177 -0
- package/templates/default/src/styles/theme.css +1310 -0
- package/templates/default/src/styles/typography.css +428 -0
- package/templates/default/tsconfig.json +27 -0
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
+
}) : function(o, v) {
|
|
17
|
+
o["default"] = v;
|
|
18
|
+
});
|
|
19
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
20
|
+
var ownKeys = function(o) {
|
|
21
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
22
|
+
var ar = [];
|
|
23
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
24
|
+
return ar;
|
|
25
|
+
};
|
|
26
|
+
return ownKeys(o);
|
|
27
|
+
};
|
|
28
|
+
return function (mod) {
|
|
29
|
+
if (mod && mod.__esModule) return mod;
|
|
30
|
+
var result = {};
|
|
31
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
32
|
+
__setModuleDefault(result, mod);
|
|
33
|
+
return result;
|
|
34
|
+
};
|
|
35
|
+
})();
|
|
36
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
37
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
38
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
39
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
40
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
41
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
42
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
46
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
47
|
+
};
|
|
48
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
49
|
+
exports.program = void 0;
|
|
50
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
51
|
+
const commander_1 = require("commander");
|
|
52
|
+
const execa_1 = require("execa");
|
|
53
|
+
const fs = __importStar(require("fs"));
|
|
54
|
+
const ora_1 = __importDefault(require("ora"));
|
|
55
|
+
const os_1 = __importDefault(require("os"));
|
|
56
|
+
const path = __importStar(require("path"));
|
|
57
|
+
const prompts_1 = __importDefault(require("prompts"));
|
|
58
|
+
const ts_morph_1 = require("ts-morph");
|
|
59
|
+
const download_tar_api_1 = require("../helper/download-tar-api");
|
|
60
|
+
const get_components_api_1 = require("../helper/get-components-api");
|
|
61
|
+
const get_components_list_1 = require("../helper/get-components-list");
|
|
62
|
+
const get_config_1 = require("../helper/get-config");
|
|
63
|
+
const get_package_info_1 = require("../helper/get-package-info");
|
|
64
|
+
const get_pkg_manager_1 = require("../helper/get-pkg-manager");
|
|
65
|
+
const get_project_1 = require("../helper/get-project");
|
|
66
|
+
const CONFIG_DIR = path.join(os_1.default.homedir(), ".untitledui");
|
|
67
|
+
const CONFIG_PATH = path.join(CONFIG_DIR, "config.json");
|
|
68
|
+
let promptOptions = {
|
|
69
|
+
components: [],
|
|
70
|
+
path: "",
|
|
71
|
+
type: undefined,
|
|
72
|
+
license: "",
|
|
73
|
+
};
|
|
74
|
+
if (fs.existsSync(CONFIG_PATH)) {
|
|
75
|
+
const config = JSON.parse(fs.readFileSync(CONFIG_PATH, "utf-8"));
|
|
76
|
+
promptOptions.license = config.license;
|
|
77
|
+
}
|
|
78
|
+
const onPromptState = (state) => {
|
|
79
|
+
if (state.aborted) {
|
|
80
|
+
// If we don't re-enable the terminal cursor before exiting
|
|
81
|
+
// the program, the cursor will remain hidden
|
|
82
|
+
process.stdout.write("\x1B[?25h");
|
|
83
|
+
process.stdout.write("\n");
|
|
84
|
+
process.exit(1);
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
exports.program = new commander_1.Command()
|
|
88
|
+
.name("add")
|
|
89
|
+
.description("add a component to your project")
|
|
90
|
+
.argument("[components...]", "the components to add")
|
|
91
|
+
.option("-o, --overwrite", "overwrite existing files.", false)
|
|
92
|
+
.option("-a, --all", "add all available components", false)
|
|
93
|
+
.option("-p, --path <path>", "the path to add the component to.")
|
|
94
|
+
.option("-t, --type <shared|marketing|shared-assets|application|foundations>", "the type of the component to add.")
|
|
95
|
+
.option("-l, --license <license-key>", "Add a license key for adding components.")
|
|
96
|
+
.action((components, options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
97
|
+
if (components) {
|
|
98
|
+
promptOptions.components = components;
|
|
99
|
+
}
|
|
100
|
+
if (options) {
|
|
101
|
+
promptOptions.overwrite = options.overwrite;
|
|
102
|
+
promptOptions.all = options.all;
|
|
103
|
+
promptOptions.path = options.path;
|
|
104
|
+
promptOptions.license = options.license || promptOptions.license;
|
|
105
|
+
}
|
|
106
|
+
try {
|
|
107
|
+
yield run(promptOptions);
|
|
108
|
+
}
|
|
109
|
+
catch (e) {
|
|
110
|
+
console.error(chalk_1.default.red(e));
|
|
111
|
+
}
|
|
112
|
+
}));
|
|
113
|
+
function run(opts) {
|
|
114
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
115
|
+
var _a, _b;
|
|
116
|
+
const spinner = (0, ora_1.default)().start();
|
|
117
|
+
const cwd = process.cwd();
|
|
118
|
+
// Check if the current directory is a existing project
|
|
119
|
+
const isExistingProject = fs.existsSync(path.resolve(cwd, "package.json"));
|
|
120
|
+
if (!isExistingProject) {
|
|
121
|
+
spinner.warn("This command should be run in a project directory.");
|
|
122
|
+
process.exit(0);
|
|
123
|
+
}
|
|
124
|
+
// Get the project configuration
|
|
125
|
+
const info = yield (0, get_project_1.getNextjsProjectConfig)(cwd);
|
|
126
|
+
if (promptOptions.license) {
|
|
127
|
+
const isValidKey = yield (0, download_tar_api_1.checkLicenseKey)(promptOptions.license);
|
|
128
|
+
if (!isValidKey) {
|
|
129
|
+
spinner.fail("Invalid license key");
|
|
130
|
+
process.exit(0);
|
|
131
|
+
}
|
|
132
|
+
// Save the license key to the config file
|
|
133
|
+
if (!fs.existsSync(CONFIG_PATH)) {
|
|
134
|
+
const dirs = path.dirname(CONFIG_PATH);
|
|
135
|
+
fs.mkdirSync(dirs, { recursive: true });
|
|
136
|
+
fs.writeFileSync(CONFIG_PATH, JSON.stringify({ license: promptOptions.license }, null, 2));
|
|
137
|
+
}
|
|
138
|
+
const config = JSON.parse(fs.readFileSync(CONFIG_PATH, "utf-8"));
|
|
139
|
+
if (config.license !== promptOptions.license) {
|
|
140
|
+
fs.writeFileSync(CONFIG_PATH, JSON.stringify({ license: promptOptions.license }, null, 2));
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
spinner.stop();
|
|
144
|
+
// If user didn't provide any options, prompt them
|
|
145
|
+
if (!(promptOptions === null || promptOptions === void 0 ? void 0 : promptOptions.type) && !(promptOptions === null || promptOptions === void 0 ? void 0 : promptOptions.components.length)) {
|
|
146
|
+
const typesList = yield (0, get_components_list_1.getComponentTypes)(promptOptions.license);
|
|
147
|
+
if (!typesList) {
|
|
148
|
+
console.log("No component types found");
|
|
149
|
+
process.exit(0);
|
|
150
|
+
}
|
|
151
|
+
const res = yield (0, prompts_1.default)({
|
|
152
|
+
type: "select",
|
|
153
|
+
name: "type",
|
|
154
|
+
onState: onPromptState,
|
|
155
|
+
message: `What type of ${chalk_1.default.cyan("component")} are you adding?`,
|
|
156
|
+
choices: typesList === null || typesList === void 0 ? void 0 : typesList.types.map((type) => ({
|
|
157
|
+
title: type,
|
|
158
|
+
value: type,
|
|
159
|
+
})),
|
|
160
|
+
});
|
|
161
|
+
promptOptions.type = res.type;
|
|
162
|
+
}
|
|
163
|
+
// Components path where user wants to add the components
|
|
164
|
+
// by default it's `components` directory
|
|
165
|
+
if (!(promptOptions === null || promptOptions === void 0 ? void 0 : promptOptions.path)) {
|
|
166
|
+
const res = yield (0, prompts_1.default)({
|
|
167
|
+
type: "text",
|
|
168
|
+
name: "path",
|
|
169
|
+
onState: onPromptState,
|
|
170
|
+
message: `Where would you like to add the ${chalk_1.default.cyan("components")}?`,
|
|
171
|
+
initial: "components",
|
|
172
|
+
});
|
|
173
|
+
promptOptions.path = res.path;
|
|
174
|
+
}
|
|
175
|
+
// If current project does not provide alias prefix, ask user to provide one
|
|
176
|
+
// by default it's `@/*`
|
|
177
|
+
if (info && !(info === null || info === void 0 ? void 0 : info.aliasPrefix)) {
|
|
178
|
+
const importAliasPattern = /^[^*"]+\/\*\s*$/;
|
|
179
|
+
const res = yield (0, prompts_1.default)({
|
|
180
|
+
type: "text",
|
|
181
|
+
name: "aliasPrefix",
|
|
182
|
+
onState: onPromptState,
|
|
183
|
+
initial: "@/*",
|
|
184
|
+
message: `What is the ${chalk_1.default.cyan("import alias")} for your project?`,
|
|
185
|
+
validate: (value) => (importAliasPattern.test(value) ? true : "Import alias must follow the pattern <prefix>/*"),
|
|
186
|
+
});
|
|
187
|
+
// Update the tsconfig file with the alias prefix
|
|
188
|
+
info.aliasPrefix = yield (0, get_config_1.updateTsConfig)(cwd, info === null || info === void 0 ? void 0 : info.isSrcDir, res === null || res === void 0 ? void 0 : res.aliasPrefix);
|
|
189
|
+
}
|
|
190
|
+
if (!(promptOptions === null || promptOptions === void 0 ? void 0 : promptOptions.components.length)) {
|
|
191
|
+
// Get all component names based on the type
|
|
192
|
+
const componentNames = yield (0, get_components_list_1.getComponentsList)(promptOptions === null || promptOptions === void 0 ? void 0 : promptOptions.type, promptOptions.license);
|
|
193
|
+
if (!componentNames) {
|
|
194
|
+
console.log("No components found");
|
|
195
|
+
process.exit(0);
|
|
196
|
+
}
|
|
197
|
+
// Show components list to user
|
|
198
|
+
const res = yield (0, prompts_1.default)({
|
|
199
|
+
type: "multiselect",
|
|
200
|
+
name: "components",
|
|
201
|
+
onState: onPromptState,
|
|
202
|
+
message: `Which ${chalk_1.default.cyan("components")} would you like to add?`,
|
|
203
|
+
choices: (_a = componentNames === null || componentNames === void 0 ? void 0 : componentNames.components) === null || _a === void 0 ? void 0 : _a.map((component) => ({
|
|
204
|
+
title: component || "example",
|
|
205
|
+
value: component || "example",
|
|
206
|
+
selected: promptOptions.components.includes(component),
|
|
207
|
+
})),
|
|
208
|
+
instructions: false,
|
|
209
|
+
hint: "- Space to select. Return to submit",
|
|
210
|
+
});
|
|
211
|
+
promptOptions.components = res.components;
|
|
212
|
+
// If user didn't select any component, exit
|
|
213
|
+
if (!res.components || res.components.length === 0) {
|
|
214
|
+
console.log("No option selected. Exiting...");
|
|
215
|
+
process.exit(0);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
// If user didn't select any component, exit
|
|
219
|
+
if (!((_b = promptOptions.components) === null || _b === void 0 ? void 0 : _b.length)) {
|
|
220
|
+
spinner.warn("No components selected. Exiting.");
|
|
221
|
+
process.exit(0);
|
|
222
|
+
}
|
|
223
|
+
if (!promptOptions.overwrite) {
|
|
224
|
+
const res = yield (0, prompts_1.default)({
|
|
225
|
+
type: "confirm",
|
|
226
|
+
name: "overwrite",
|
|
227
|
+
message: "You are about to add new components to your project. Do you want to overwrite the existing files?",
|
|
228
|
+
initial: true,
|
|
229
|
+
});
|
|
230
|
+
promptOptions.overwrite = res.overwrite;
|
|
231
|
+
}
|
|
232
|
+
// Src directory of the main project
|
|
233
|
+
const srcDir = path.join(path.resolve(__dirname, "../../../../"));
|
|
234
|
+
// Get the configuration file paths of the project
|
|
235
|
+
// tailwind.config.ts, tsconfig.json, layout.tsx, _app.tsx, globals.css
|
|
236
|
+
// package.json, etc
|
|
237
|
+
const configFiles = yield (0, get_config_1.resolveConfigPaths)(cwd);
|
|
238
|
+
const existingFiles = [];
|
|
239
|
+
// Create a new project instance with the tsconfig file
|
|
240
|
+
const project = new ts_morph_1.Project({
|
|
241
|
+
tsConfigFilePath: configFiles === null || configFiles === void 0 ? void 0 : configFiles.tsConfig,
|
|
242
|
+
});
|
|
243
|
+
// Spinner for adding component
|
|
244
|
+
const componentSpinner = (0, ora_1.default)("Adding component\n").start();
|
|
245
|
+
// Get the components data from the API
|
|
246
|
+
const data = yield (0, get_components_api_1.getComponents)(promptOptions.type, promptOptions.components, promptOptions.license);
|
|
247
|
+
if (!data) {
|
|
248
|
+
console.log("No components found");
|
|
249
|
+
process.exit(0);
|
|
250
|
+
}
|
|
251
|
+
// Add the components to the project
|
|
252
|
+
data.components.forEach((component) => __awaiter(this, void 0, void 0, function* () {
|
|
253
|
+
var _a;
|
|
254
|
+
// Get all files that are used in the component from the components.json file
|
|
255
|
+
const files = component.files;
|
|
256
|
+
// Get dependencies of the component
|
|
257
|
+
const dependencies = component.dependencies;
|
|
258
|
+
// Get devDependencies of the component
|
|
259
|
+
const devDependencies = component.devDependencies;
|
|
260
|
+
// Get dependencies from the package.json file in the main repo
|
|
261
|
+
// and with the specified versions
|
|
262
|
+
const packages = (0, get_package_info_1.getDependenciesFromPackageJson)({
|
|
263
|
+
cwd: srcDir,
|
|
264
|
+
dependencies,
|
|
265
|
+
devDependencies,
|
|
266
|
+
});
|
|
267
|
+
// Get the package manager of the project
|
|
268
|
+
// npm, yarn, pnpm or bun
|
|
269
|
+
const pkgManager = (0, get_pkg_manager_1.getPkgManager)();
|
|
270
|
+
const dependencySpinner = (0, ora_1.default)("Installing dependencies\n").start();
|
|
271
|
+
try {
|
|
272
|
+
// Add the component files to the project
|
|
273
|
+
files === null || files === void 0 ? void 0 : files.forEach((_a) => __awaiter(this, [_a], void 0, function* ({ path: file, code }) {
|
|
274
|
+
// Remove the components/ prefix from the file path
|
|
275
|
+
// to replace it with the user provided path
|
|
276
|
+
const relativePath = file.replace("components/", "");
|
|
277
|
+
// Target file path where the component will be added
|
|
278
|
+
const targetFilePath = path.join(process.cwd(), `${(info === null || info === void 0 ? void 0 : info.isSrcDir) && "src"}`, file.replace(/components\//, promptOptions.path + "/"));
|
|
279
|
+
// Get the folders of the target file path
|
|
280
|
+
const folders = path.dirname(targetFilePath);
|
|
281
|
+
// Check if the file already exists in the project directory
|
|
282
|
+
if (fs.existsSync(targetFilePath) && !promptOptions.overwrite) {
|
|
283
|
+
existingFiles.push(relativePath);
|
|
284
|
+
}
|
|
285
|
+
else {
|
|
286
|
+
// Create the directory if it doesn't exist
|
|
287
|
+
fs.mkdirSync(folders, { recursive: true });
|
|
288
|
+
// Create an empty file
|
|
289
|
+
fs.writeFileSync(targetFilePath, code);
|
|
290
|
+
// Get the source file from the project
|
|
291
|
+
const sourceFile = project.addSourceFileAtPath(path.resolve(targetFilePath));
|
|
292
|
+
sourceFile.getImportDeclarations().forEach((importDeclaration) => {
|
|
293
|
+
// Get the module specifier value of the import declaration
|
|
294
|
+
const moduleSpecifier = importDeclaration.getModuleSpecifierValue();
|
|
295
|
+
// Update the module specifier value with the alias prefix
|
|
296
|
+
importDeclaration.setModuleSpecifier((0, get_config_1.updateImportAliases)(moduleSpecifier, info === null || info === void 0 ? void 0 : info.aliasPrefix, promptOptions.path));
|
|
297
|
+
});
|
|
298
|
+
// Save the source file
|
|
299
|
+
yield sourceFile.save();
|
|
300
|
+
}
|
|
301
|
+
}));
|
|
302
|
+
// If the files already exist in the project directory, show the user
|
|
303
|
+
// which files exist
|
|
304
|
+
if (existingFiles.length && !(promptOptions === null || promptOptions === void 0 ? void 0 : promptOptions.overwrite)) {
|
|
305
|
+
console.log("\n");
|
|
306
|
+
componentSpinner.fail(`Following files already exist in the directory. Use ${chalk_1.default.cyan("--overwrite")} or ${chalk_1.default.cyan("-o")} to overwrite existing files, or refer to the documentation ${chalk_1.default.cyan("https://untitled.xyz/docs")} for manual installation. The rest of the files are added.`);
|
|
307
|
+
existingFiles.forEach((file) => {
|
|
308
|
+
console.log(`- ${chalk_1.default.green(file)}`);
|
|
309
|
+
});
|
|
310
|
+
process.exit(0);
|
|
311
|
+
}
|
|
312
|
+
// Install dependencies from the package.json file in the main repo
|
|
313
|
+
if (!packages) {
|
|
314
|
+
dependencySpinner.fail("Failed to get dependencies from package.json\n");
|
|
315
|
+
process.exit(0);
|
|
316
|
+
}
|
|
317
|
+
// Run the package manager install command to install the dependencies
|
|
318
|
+
// and devDependencies
|
|
319
|
+
if ((_a = packages === null || packages === void 0 ? void 0 : packages.dependencies) === null || _a === void 0 ? void 0 : _a.length) {
|
|
320
|
+
yield (0, execa_1.execa)(pkgManager, [pkgManager === "npm" ? "install" : "add", ...packages.dependencies]);
|
|
321
|
+
dependencySpinner.succeed("Dependencies are installed\n");
|
|
322
|
+
}
|
|
323
|
+
// if (devDependencies?.length) {
|
|
324
|
+
// await execa(pkgManager, [pkgManager === "npm" ? "install" : "add", ...packages.devDependencies]);
|
|
325
|
+
// dependencySpinner.succeed("DevDependencies are installed\n");
|
|
326
|
+
// }
|
|
327
|
+
componentSpinner.succeed("Component is added\n");
|
|
328
|
+
// Exit the process with a success status code
|
|
329
|
+
process.exit(1);
|
|
330
|
+
}
|
|
331
|
+
catch (e) {
|
|
332
|
+
dependencySpinner.fail("\nFailed to install dependencies");
|
|
333
|
+
componentSpinner.fail("\nFailed to add component");
|
|
334
|
+
console.error(chalk_1.default.red(e));
|
|
335
|
+
process.exit(0);
|
|
336
|
+
}
|
|
337
|
+
}));
|
|
338
|
+
});
|
|
339
|
+
}
|