ui-thing 0.0.4 → 0.0.5
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/.github/workflows/main.yml +19 -0
- package/.prettierrc +12 -12
- package/CHANGELOG.md +32 -129
- package/README.md +69 -69
- package/dist/index.d.ts +0 -0
- package/dist/index.js +0 -0
- package/dist/index.js.map +1 -1
- package/package.json +5 -2
- package/src/commands/add.ts +237 -237
- package/src/commands/init.ts +72 -72
- package/src/commands/prettier.ts +47 -47
- package/src/commands/theme.ts +61 -61
- package/src/comp.ts +2134 -2134
- package/src/index.ts +30 -30
- package/src/templates/css.ts +641 -641
- package/src/templates/prettier.ts +16 -16
- package/src/templates/tailwind.ts +101 -101
- package/src/types.ts +13 -13
- package/src/utils/addPrettierConfig.ts +24 -24
- package/src/utils/compareUIConfig.ts +35 -35
- package/src/utils/config.ts +84 -84
- package/src/utils/constants.ts +36 -36
- package/src/utils/fileExists.ts +10 -10
- package/src/utils/installPackages.ts +28 -28
- package/src/utils/printFancyBoxMessage.ts +19 -19
- package/src/utils/promptForComponents.ts +17 -17
- package/src/utils/uiConfigPrompt.ts +73 -73
- package/src/utils/writeFile.ts +18 -18
- package/tsconfig.json +16 -16
- package/tsup.config.ts +12 -12
package/package.json
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ui-thing",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"description": "CLI used to add Nuxt 3 components to a project",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
7
|
"main": "./dist/index.js",
|
|
8
|
+
"repository": {
|
|
9
|
+
"url": "https://github.com/BayBreezy/ui-thing-cli"
|
|
10
|
+
},
|
|
8
11
|
"publishConfig": {
|
|
9
12
|
"access": "public"
|
|
10
13
|
},
|
|
@@ -50,7 +53,7 @@
|
|
|
50
53
|
},
|
|
51
54
|
"devDependencies": {
|
|
52
55
|
"@ianvs/prettier-plugin-sort-imports": "^4.1.1",
|
|
53
|
-
"@types/figlet": "^1.5.
|
|
56
|
+
"@types/figlet": "^1.5.8",
|
|
54
57
|
"@types/fs-extra": "^11.0.3",
|
|
55
58
|
"@types/lodash": "^4.14.200",
|
|
56
59
|
"@types/node": "^20.8.10",
|
package/src/commands/add.ts
CHANGED
|
@@ -1,237 +1,237 @@
|
|
|
1
|
-
import path from "node:path";
|
|
2
|
-
import { Command } from "commander";
|
|
3
|
-
import { consola } from "consola";
|
|
4
|
-
import kleur from "kleur";
|
|
5
|
-
import _ from "lodash";
|
|
6
|
-
import prompts from "prompts";
|
|
7
|
-
|
|
8
|
-
import allComponents from "../comp";
|
|
9
|
-
import { compareUIConfig } from "../utils/compareUIConfig";
|
|
10
|
-
import { addModuleToConfig, getNuxtConfig, getUIConfig, updateConfig } from "../utils/config";
|
|
11
|
-
import { fileExists } from "../utils/fileExists";
|
|
12
|
-
import { installPackages } from "../utils/installPackages";
|
|
13
|
-
import { printFancyBoxMessage } from "../utils/printFancyBoxMessage";
|
|
14
|
-
import { promptUserForComponents } from "../utils/promptForComponents";
|
|
15
|
-
import { writeFile } from "../utils/writeFile";
|
|
16
|
-
|
|
17
|
-
const currentDirectory = process.cwd();
|
|
18
|
-
|
|
19
|
-
const findComponent = (name: string) => {
|
|
20
|
-
return allComponents.find((c) => c.value.toLowerCase() === name.toLowerCase());
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Adds a component to your project
|
|
25
|
-
*/
|
|
26
|
-
export const add = new Command()
|
|
27
|
-
.name("add")
|
|
28
|
-
.command("add")
|
|
29
|
-
.description("Add a list of components to your project.")
|
|
30
|
-
.argument("[componentNames...]", "Components that you want to add.")
|
|
31
|
-
.action(async (components: Array<string>) => {
|
|
32
|
-
// Get nuxt config
|
|
33
|
-
const cfg = await getNuxtConfig();
|
|
34
|
-
// Get ui config
|
|
35
|
-
let uiConfig = await getUIConfig();
|
|
36
|
-
let uiConfigIsCorrect = await compareUIConfig();
|
|
37
|
-
if (!uiConfigIsCorrect) {
|
|
38
|
-
uiConfig = await getUIConfig({ force: true });
|
|
39
|
-
}
|
|
40
|
-
if (_.isEmpty(uiConfig)) {
|
|
41
|
-
consola.info("Config file not set. Exiting...");
|
|
42
|
-
process.exit(0);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
let componentNames = components;
|
|
46
|
-
// if no components are passed, prompt the user to select components
|
|
47
|
-
if (componentNames.length === 0) {
|
|
48
|
-
const response = await promptUserForComponents();
|
|
49
|
-
if ((response && response.length === 0) || !response) {
|
|
50
|
-
consola.info("No components selected. Exiting...");
|
|
51
|
-
process.exit(0);
|
|
52
|
-
}
|
|
53
|
-
componentNames = response;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// store the components that are not found
|
|
57
|
-
let notFound: string[] = [];
|
|
58
|
-
componentNames.forEach((c) => {
|
|
59
|
-
if (!findComponent(c)) {
|
|
60
|
-
notFound.push(c);
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
if (notFound.length > 0) {
|
|
64
|
-
consola.error(`The following components were not found: ${kleur.bgRed(notFound.join(", "))}`);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// store the components that are found
|
|
68
|
-
let found: typeof allComponents = [];
|
|
69
|
-
componentNames.forEach((c) => {
|
|
70
|
-
if (findComponent(c)) {
|
|
71
|
-
found.push(findComponent(c)!);
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
// check if the found components depends on other components and add them to the list
|
|
75
|
-
for (let i = 0; i < found.length; i++) {
|
|
76
|
-
const component = found[i];
|
|
77
|
-
if (component.components) {
|
|
78
|
-
for (let j = 0; j < component.components.length; j++) {
|
|
79
|
-
const comp = component.components[j];
|
|
80
|
-
if (!found.find((c) => c.value === comp)) {
|
|
81
|
-
found.push(findComponent(comp)!);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// add the components & files associated with them
|
|
88
|
-
for (let i = 0; i < found.length; i++) {
|
|
89
|
-
const component = found[i];
|
|
90
|
-
loop2: for (let k = 0; k < component.files.length; k++) {
|
|
91
|
-
const file = component.files[k];
|
|
92
|
-
let fileName = file.fileName;
|
|
93
|
-
let dirPath = uiConfig.componentsLocation;
|
|
94
|
-
let filePath = path.join(currentDirectory, dirPath, fileName);
|
|
95
|
-
if (!uiConfig.useDefaultFilename) {
|
|
96
|
-
const res = await prompts({
|
|
97
|
-
type: "text",
|
|
98
|
-
name: "value",
|
|
99
|
-
message: `Where should we add the file`,
|
|
100
|
-
initial: dirPath,
|
|
101
|
-
onRender(kleur) {
|
|
102
|
-
//@ts-ignore
|
|
103
|
-
this.msg =
|
|
104
|
-
kleur.bgCyan(" Location ") +
|
|
105
|
-
` Where should we add the file ${kleur.cyan(`${fileName}`)} `;
|
|
106
|
-
},
|
|
107
|
-
});
|
|
108
|
-
if (res.value) {
|
|
109
|
-
dirPath = res.value;
|
|
110
|
-
filePath = path.join(currentDirectory, res.value, fileName);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
// Check if the file exists
|
|
114
|
-
const exists = await fileExists(filePath);
|
|
115
|
-
// if it exists & the force option was not passed, ask the user to confirm overwriting the file
|
|
116
|
-
if (exists && !uiConfig.force) {
|
|
117
|
-
const res = await prompts({
|
|
118
|
-
type: "confirm",
|
|
119
|
-
name: "value",
|
|
120
|
-
message: `The file that we are trying to add ${kleur.bold(
|
|
121
|
-
fileName
|
|
122
|
-
)} to is already taken. Overwrite?`,
|
|
123
|
-
initial: false,
|
|
124
|
-
});
|
|
125
|
-
if (!res.value) {
|
|
126
|
-
consola.info(`We will not overwrite the file for ${kleur.cyan(fileName)}`);
|
|
127
|
-
continue loop2;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
await writeFile(filePath, file.fileContent);
|
|
131
|
-
|
|
132
|
-
// This is not scalable. We need to find a better way to do this
|
|
133
|
-
if (component.value === "vue-sonner") {
|
|
134
|
-
// Update the nuxt config
|
|
135
|
-
cfg.defaultExport.imports ||= {};
|
|
136
|
-
cfg.defaultExport.build ||= {};
|
|
137
|
-
cfg.defaultExport.imports.imports ||= [];
|
|
138
|
-
cfg.defaultExport.build.transpile ||= [];
|
|
139
|
-
const sonnerExists = cfg.defaultExport.imports.imports.find(
|
|
140
|
-
(i: any) => i.from === "vue-sonner" && i.name === "toast"
|
|
141
|
-
);
|
|
142
|
-
if (!sonnerExists) {
|
|
143
|
-
cfg.defaultExport.imports.imports.push({
|
|
144
|
-
from: "vue-sonner",
|
|
145
|
-
name: "toast",
|
|
146
|
-
as: "useSonner",
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
const transpileExists = cfg.defaultExport.build.transpile.find((i: any) => "vue-sonner");
|
|
150
|
-
if (!transpileExists) {
|
|
151
|
-
cfg.defaultExport.build.transpile.push("vue-sonner");
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
// add utils attached to the component
|
|
156
|
-
loop3: for (let j = 0; j < component.utils.length; j++) {
|
|
157
|
-
const util = component.utils[j];
|
|
158
|
-
const filePath = path.join(currentDirectory, uiConfig.utilsLocation, util.fileName);
|
|
159
|
-
// Check if the file exists
|
|
160
|
-
const exists = await fileExists(filePath);
|
|
161
|
-
if (exists && !uiConfig.force) {
|
|
162
|
-
const res = await prompts({
|
|
163
|
-
type: "confirm",
|
|
164
|
-
name: "value",
|
|
165
|
-
message: `The utils file that we are trying to add ${kleur.bold(
|
|
166
|
-
util.fileName
|
|
167
|
-
)} already exists. Overwrite?`,
|
|
168
|
-
initial: true,
|
|
169
|
-
});
|
|
170
|
-
if (!res.value) {
|
|
171
|
-
consola.info(`We will not overwrite the file for ${kleur.cyan(util.fileName)}`);
|
|
172
|
-
continue loop3;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
await writeFile(filePath, util.fileContent);
|
|
176
|
-
}
|
|
177
|
-
// add composables attached to the component
|
|
178
|
-
loop4: for (let j = 0; j < component.composables.length; j++) {
|
|
179
|
-
const composable = component.composables[j];
|
|
180
|
-
const filePath = path.join(
|
|
181
|
-
currentDirectory,
|
|
182
|
-
uiConfig.composablesLocation,
|
|
183
|
-
composable.fileName
|
|
184
|
-
);
|
|
185
|
-
// Check if the file exists
|
|
186
|
-
const exists = await fileExists(filePath);
|
|
187
|
-
if (exists && !uiConfig.force) {
|
|
188
|
-
const res = await prompts({
|
|
189
|
-
type: "confirm",
|
|
190
|
-
name: "value",
|
|
191
|
-
message: `The composables file that we are trying to add ${kleur.bold(
|
|
192
|
-
composable.fileName
|
|
193
|
-
)} already exists. Overwrite?`,
|
|
194
|
-
initial: true,
|
|
195
|
-
});
|
|
196
|
-
if (!res.value) {
|
|
197
|
-
consola.info(`We will not overwrite the file for ${kleur.cyan(composable.fileName)}`);
|
|
198
|
-
continue loop4;
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
await writeFile(filePath, composable.fileContent);
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
// Add modules to nuxt config
|
|
206
|
-
addModuleToConfig(cfg.nuxtConfig, _.uniq(found.map((c) => c.nuxtModules).flat()));
|
|
207
|
-
// Write the changes to the nuxt config
|
|
208
|
-
await updateConfig(cfg.nuxtConfig, "nuxt.config.ts");
|
|
209
|
-
const foundDeps = _.uniq(found.map((c) => c.deps).flat());
|
|
210
|
-
const foundDevDeps = _.uniq(found.map((c) => c.devDeps).flat());
|
|
211
|
-
const { confirmInstall } = await prompts({
|
|
212
|
-
type: "confirm",
|
|
213
|
-
name: "confirmInstall",
|
|
214
|
-
message: `Do you want to install the following packages: ${kleur.cyan(
|
|
215
|
-
foundDeps.join(", ")
|
|
216
|
-
)} ${kleur.cyan(foundDevDeps.join(", "))}`,
|
|
217
|
-
initial: true,
|
|
218
|
-
});
|
|
219
|
-
if (confirmInstall) {
|
|
220
|
-
await installPackages(uiConfig.packageManager, foundDeps, foundDevDeps);
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
printFancyBoxMessage(
|
|
224
|
-
"All Done!",
|
|
225
|
-
{ title: "Components Added" },
|
|
226
|
-
`Run the ${kleur.cyan("ui-thing@latest --help")} command to learn more.\n`
|
|
227
|
-
);
|
|
228
|
-
const combinedInstructions = found.map((c) => c.instructions).flat();
|
|
229
|
-
// remove undefined from the array
|
|
230
|
-
_.remove(combinedInstructions, (i) => !i);
|
|
231
|
-
if (combinedInstructions.length > 0) {
|
|
232
|
-
console.log(kleur.bgCyan(" Instructions "));
|
|
233
|
-
combinedInstructions.forEach((i) => {
|
|
234
|
-
console.log(`${kleur.cyan("-")} ${i}`);
|
|
235
|
-
});
|
|
236
|
-
}
|
|
237
|
-
});
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { Command } from "commander";
|
|
3
|
+
import { consola } from "consola";
|
|
4
|
+
import kleur from "kleur";
|
|
5
|
+
import _ from "lodash";
|
|
6
|
+
import prompts from "prompts";
|
|
7
|
+
|
|
8
|
+
import allComponents from "../comp";
|
|
9
|
+
import { compareUIConfig } from "../utils/compareUIConfig";
|
|
10
|
+
import { addModuleToConfig, getNuxtConfig, getUIConfig, updateConfig } from "../utils/config";
|
|
11
|
+
import { fileExists } from "../utils/fileExists";
|
|
12
|
+
import { installPackages } from "../utils/installPackages";
|
|
13
|
+
import { printFancyBoxMessage } from "../utils/printFancyBoxMessage";
|
|
14
|
+
import { promptUserForComponents } from "../utils/promptForComponents";
|
|
15
|
+
import { writeFile } from "../utils/writeFile";
|
|
16
|
+
|
|
17
|
+
const currentDirectory = process.cwd();
|
|
18
|
+
|
|
19
|
+
const findComponent = (name: string) => {
|
|
20
|
+
return allComponents.find((c) => c.value.toLowerCase() === name.toLowerCase());
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Adds a component to your project
|
|
25
|
+
*/
|
|
26
|
+
export const add = new Command()
|
|
27
|
+
.name("add")
|
|
28
|
+
.command("add")
|
|
29
|
+
.description("Add a list of components to your project.")
|
|
30
|
+
.argument("[componentNames...]", "Components that you want to add.")
|
|
31
|
+
.action(async (components: Array<string>) => {
|
|
32
|
+
// Get nuxt config
|
|
33
|
+
const cfg = await getNuxtConfig();
|
|
34
|
+
// Get ui config
|
|
35
|
+
let uiConfig = await getUIConfig();
|
|
36
|
+
let uiConfigIsCorrect = await compareUIConfig();
|
|
37
|
+
if (!uiConfigIsCorrect) {
|
|
38
|
+
uiConfig = await getUIConfig({ force: true });
|
|
39
|
+
}
|
|
40
|
+
if (_.isEmpty(uiConfig)) {
|
|
41
|
+
consola.info("Config file not set. Exiting...");
|
|
42
|
+
process.exit(0);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
let componentNames = components;
|
|
46
|
+
// if no components are passed, prompt the user to select components
|
|
47
|
+
if (componentNames.length === 0) {
|
|
48
|
+
const response = await promptUserForComponents();
|
|
49
|
+
if ((response && response.length === 0) || !response) {
|
|
50
|
+
consola.info("No components selected. Exiting...");
|
|
51
|
+
process.exit(0);
|
|
52
|
+
}
|
|
53
|
+
componentNames = response;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// store the components that are not found
|
|
57
|
+
let notFound: string[] = [];
|
|
58
|
+
componentNames.forEach((c) => {
|
|
59
|
+
if (!findComponent(c)) {
|
|
60
|
+
notFound.push(c);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
if (notFound.length > 0) {
|
|
64
|
+
consola.error(`The following components were not found: ${kleur.bgRed(notFound.join(", "))}`);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// store the components that are found
|
|
68
|
+
let found: typeof allComponents = [];
|
|
69
|
+
componentNames.forEach((c) => {
|
|
70
|
+
if (findComponent(c)) {
|
|
71
|
+
found.push(findComponent(c)!);
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
// check if the found components depends on other components and add them to the list
|
|
75
|
+
for (let i = 0; i < found.length; i++) {
|
|
76
|
+
const component = found[i];
|
|
77
|
+
if (component.components) {
|
|
78
|
+
for (let j = 0; j < component.components.length; j++) {
|
|
79
|
+
const comp = component.components[j];
|
|
80
|
+
if (!found.find((c) => c.value === comp)) {
|
|
81
|
+
found.push(findComponent(comp)!);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// add the components & files associated with them
|
|
88
|
+
for (let i = 0; i < found.length; i++) {
|
|
89
|
+
const component = found[i];
|
|
90
|
+
loop2: for (let k = 0; k < component.files.length; k++) {
|
|
91
|
+
const file = component.files[k];
|
|
92
|
+
let fileName = file.fileName;
|
|
93
|
+
let dirPath = uiConfig.componentsLocation;
|
|
94
|
+
let filePath = path.join(currentDirectory, dirPath, fileName);
|
|
95
|
+
if (!uiConfig.useDefaultFilename) {
|
|
96
|
+
const res = await prompts({
|
|
97
|
+
type: "text",
|
|
98
|
+
name: "value",
|
|
99
|
+
message: `Where should we add the file`,
|
|
100
|
+
initial: dirPath,
|
|
101
|
+
onRender(kleur) {
|
|
102
|
+
//@ts-ignore
|
|
103
|
+
this.msg =
|
|
104
|
+
kleur.bgCyan(" Location ") +
|
|
105
|
+
` Where should we add the file ${kleur.cyan(`${fileName}`)} `;
|
|
106
|
+
},
|
|
107
|
+
});
|
|
108
|
+
if (res.value) {
|
|
109
|
+
dirPath = res.value;
|
|
110
|
+
filePath = path.join(currentDirectory, res.value, fileName);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
// Check if the file exists
|
|
114
|
+
const exists = await fileExists(filePath);
|
|
115
|
+
// if it exists & the force option was not passed, ask the user to confirm overwriting the file
|
|
116
|
+
if (exists && !uiConfig.force) {
|
|
117
|
+
const res = await prompts({
|
|
118
|
+
type: "confirm",
|
|
119
|
+
name: "value",
|
|
120
|
+
message: `The file that we are trying to add ${kleur.bold(
|
|
121
|
+
fileName
|
|
122
|
+
)} to is already taken. Overwrite?`,
|
|
123
|
+
initial: false,
|
|
124
|
+
});
|
|
125
|
+
if (!res.value) {
|
|
126
|
+
consola.info(`We will not overwrite the file for ${kleur.cyan(fileName)}`);
|
|
127
|
+
continue loop2;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
await writeFile(filePath, file.fileContent);
|
|
131
|
+
|
|
132
|
+
// This is not scalable. We need to find a better way to do this
|
|
133
|
+
if (component.value === "vue-sonner") {
|
|
134
|
+
// Update the nuxt config
|
|
135
|
+
cfg.defaultExport.imports ||= {};
|
|
136
|
+
cfg.defaultExport.build ||= {};
|
|
137
|
+
cfg.defaultExport.imports.imports ||= [];
|
|
138
|
+
cfg.defaultExport.build.transpile ||= [];
|
|
139
|
+
const sonnerExists = cfg.defaultExport.imports.imports.find(
|
|
140
|
+
(i: any) => i.from === "vue-sonner" && i.name === "toast"
|
|
141
|
+
);
|
|
142
|
+
if (!sonnerExists) {
|
|
143
|
+
cfg.defaultExport.imports.imports.push({
|
|
144
|
+
from: "vue-sonner",
|
|
145
|
+
name: "toast",
|
|
146
|
+
as: "useSonner",
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
const transpileExists = cfg.defaultExport.build.transpile.find((i: any) => "vue-sonner");
|
|
150
|
+
if (!transpileExists) {
|
|
151
|
+
cfg.defaultExport.build.transpile.push("vue-sonner");
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// add utils attached to the component
|
|
156
|
+
loop3: for (let j = 0; j < component.utils.length; j++) {
|
|
157
|
+
const util = component.utils[j];
|
|
158
|
+
const filePath = path.join(currentDirectory, uiConfig.utilsLocation, util.fileName);
|
|
159
|
+
// Check if the file exists
|
|
160
|
+
const exists = await fileExists(filePath);
|
|
161
|
+
if (exists && !uiConfig.force) {
|
|
162
|
+
const res = await prompts({
|
|
163
|
+
type: "confirm",
|
|
164
|
+
name: "value",
|
|
165
|
+
message: `The utils file that we are trying to add ${kleur.bold(
|
|
166
|
+
util.fileName
|
|
167
|
+
)} already exists. Overwrite?`,
|
|
168
|
+
initial: true,
|
|
169
|
+
});
|
|
170
|
+
if (!res.value) {
|
|
171
|
+
consola.info(`We will not overwrite the file for ${kleur.cyan(util.fileName)}`);
|
|
172
|
+
continue loop3;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
await writeFile(filePath, util.fileContent);
|
|
176
|
+
}
|
|
177
|
+
// add composables attached to the component
|
|
178
|
+
loop4: for (let j = 0; j < component.composables.length; j++) {
|
|
179
|
+
const composable = component.composables[j];
|
|
180
|
+
const filePath = path.join(
|
|
181
|
+
currentDirectory,
|
|
182
|
+
uiConfig.composablesLocation,
|
|
183
|
+
composable.fileName
|
|
184
|
+
);
|
|
185
|
+
// Check if the file exists
|
|
186
|
+
const exists = await fileExists(filePath);
|
|
187
|
+
if (exists && !uiConfig.force) {
|
|
188
|
+
const res = await prompts({
|
|
189
|
+
type: "confirm",
|
|
190
|
+
name: "value",
|
|
191
|
+
message: `The composables file that we are trying to add ${kleur.bold(
|
|
192
|
+
composable.fileName
|
|
193
|
+
)} already exists. Overwrite?`,
|
|
194
|
+
initial: true,
|
|
195
|
+
});
|
|
196
|
+
if (!res.value) {
|
|
197
|
+
consola.info(`We will not overwrite the file for ${kleur.cyan(composable.fileName)}`);
|
|
198
|
+
continue loop4;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
await writeFile(filePath, composable.fileContent);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
// Add modules to nuxt config
|
|
206
|
+
addModuleToConfig(cfg.nuxtConfig, _.uniq(found.map((c) => c.nuxtModules).flat()));
|
|
207
|
+
// Write the changes to the nuxt config
|
|
208
|
+
await updateConfig(cfg.nuxtConfig, "nuxt.config.ts");
|
|
209
|
+
const foundDeps = _.uniq(found.map((c) => c.deps).flat());
|
|
210
|
+
const foundDevDeps = _.uniq(found.map((c) => c.devDeps).flat());
|
|
211
|
+
const { confirmInstall } = await prompts({
|
|
212
|
+
type: "confirm",
|
|
213
|
+
name: "confirmInstall",
|
|
214
|
+
message: `Do you want to install the following packages: ${kleur.cyan(
|
|
215
|
+
foundDeps.join(", ")
|
|
216
|
+
)} ${kleur.cyan(foundDevDeps.join(", "))}`,
|
|
217
|
+
initial: true,
|
|
218
|
+
});
|
|
219
|
+
if (confirmInstall) {
|
|
220
|
+
await installPackages(uiConfig.packageManager, foundDeps, foundDevDeps);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
printFancyBoxMessage(
|
|
224
|
+
"All Done!",
|
|
225
|
+
{ title: "Components Added" },
|
|
226
|
+
`Run the ${kleur.cyan("ui-thing@latest --help")} command to learn more.\n`
|
|
227
|
+
);
|
|
228
|
+
const combinedInstructions = found.map((c) => c.instructions).flat();
|
|
229
|
+
// remove undefined from the array
|
|
230
|
+
_.remove(combinedInstructions, (i) => !i);
|
|
231
|
+
if (combinedInstructions.length > 0) {
|
|
232
|
+
console.log(kleur.bgCyan(" Instructions "));
|
|
233
|
+
combinedInstructions.forEach((i) => {
|
|
234
|
+
console.log(`${kleur.cyan("-")} ${i}`);
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
});
|
package/src/commands/init.ts
CHANGED
|
@@ -1,72 +1,72 @@
|
|
|
1
|
-
import { Command } from "commander";
|
|
2
|
-
import { defu } from "defu";
|
|
3
|
-
import fse from "fs-extra";
|
|
4
|
-
import kleur from "kleur";
|
|
5
|
-
|
|
6
|
-
import { createCSS } from "../templates/css";
|
|
7
|
-
import { TAILWIND_CONFIG_JS } from "../templates/tailwind";
|
|
8
|
-
import { InitOptions, UIConfig } from "../types";
|
|
9
|
-
import { addPrettierConfig } from "../utils/addPrettierConfig";
|
|
10
|
-
import { addModuleToConfig, getNuxtConfig, getUIConfig, updateConfig } from "../utils/config";
|
|
11
|
-
import { INIT_DEPS, INIT_DEV_DEPS, INIT_MODULES } from "../utils/constants";
|
|
12
|
-
import { installPackages } from "../utils/installPackages";
|
|
13
|
-
import { printFancyBoxMessage } from "../utils/printFancyBoxMessage";
|
|
14
|
-
|
|
15
|
-
export const init = new Command()
|
|
16
|
-
.command("init")
|
|
17
|
-
.name("init")
|
|
18
|
-
.description(
|
|
19
|
-
"Initialize UI Thing in your Nuxt3 project. This will: 1. Create a tailwind.config.js file 2. Update your nuxt.config.ts file 3. Add the necessary dependencies 4. Create a ui-thing.config.ts file with the default configuration"
|
|
20
|
-
)
|
|
21
|
-
.option("-f --force", "Overwrite config file if it exists.", false)
|
|
22
|
-
.action(async (options: InitOptions) => {
|
|
23
|
-
// Get nuxt config
|
|
24
|
-
const cfg = await getNuxtConfig();
|
|
25
|
-
// Get ui config
|
|
26
|
-
let uiConfig: UIConfig = await getUIConfig(options);
|
|
27
|
-
// Add tailwindcss
|
|
28
|
-
await fse.writeFile(uiConfig.tailwindConfigLocation, TAILWIND_CONFIG_JS, "utf-8");
|
|
29
|
-
// create css path if it does not exist
|
|
30
|
-
// add css file
|
|
31
|
-
fse.writeFileSync(
|
|
32
|
-
uiConfig.tailwindCSSLocation,
|
|
33
|
-
createCSS(uiConfig.theme.toUpperCase() as any),
|
|
34
|
-
"utf-8"
|
|
35
|
-
);
|
|
36
|
-
// Add init modules ot nuxt cinfig
|
|
37
|
-
addModuleToConfig(cfg.nuxtConfig, INIT_MODULES);
|
|
38
|
-
// Configure modules in nuxt config
|
|
39
|
-
cfg.defaultExport.tailwindcss = defu(cfg.defaultExport.tailwindcss, { exposeConfig: true });
|
|
40
|
-
cfg.defaultExport.colorMode = defu(cfg.defaultExport.colorMode, { classSuffix: "" });
|
|
41
|
-
cfg.defaultExport.typescript = defu(cfg.defaultExport.typescript, { shim: false });
|
|
42
|
-
cfg.defaultExport.imports ||= {};
|
|
43
|
-
cfg.defaultExport.imports.imports ||= [];
|
|
44
|
-
const tvExists = cfg.defaultExport.imports.imports.find(
|
|
45
|
-
(i: any) => i.from === "tailwind-variants" && i.name === "tv"
|
|
46
|
-
);
|
|
47
|
-
if (!tvExists) {
|
|
48
|
-
cfg.defaultExport.imports.imports.push({ from: "tailwind-variants", name: "tv" });
|
|
49
|
-
}
|
|
50
|
-
const variantPropsExists = cfg.defaultExport.imports.imports.find(
|
|
51
|
-
(i: any) => i.from === "tailwind-variants" && i.name === "VariantProps"
|
|
52
|
-
);
|
|
53
|
-
if (!variantPropsExists) {
|
|
54
|
-
cfg.defaultExport.imports.imports.push({
|
|
55
|
-
from: "tailwind-variants",
|
|
56
|
-
name: "VariantProps",
|
|
57
|
-
type: true,
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
// Wriet changes to nuxt config
|
|
61
|
-
await updateConfig(cfg.nuxtConfig, "nuxt.config.ts");
|
|
62
|
-
// instal deps
|
|
63
|
-
await installPackages(uiConfig.packageManager, INIT_DEPS, INIT_DEV_DEPS);
|
|
64
|
-
// Add prettier config
|
|
65
|
-
await addPrettierConfig();
|
|
66
|
-
|
|
67
|
-
printFancyBoxMessage(
|
|
68
|
-
"Initialized",
|
|
69
|
-
{ title: "Complete" },
|
|
70
|
-
`Feel free to start adding components with the ${kleur.bgWhite(" add ")} command.`
|
|
71
|
-
);
|
|
72
|
-
});
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import { defu } from "defu";
|
|
3
|
+
import fse from "fs-extra";
|
|
4
|
+
import kleur from "kleur";
|
|
5
|
+
|
|
6
|
+
import { createCSS } from "../templates/css";
|
|
7
|
+
import { TAILWIND_CONFIG_JS } from "../templates/tailwind";
|
|
8
|
+
import { InitOptions, UIConfig } from "../types";
|
|
9
|
+
import { addPrettierConfig } from "../utils/addPrettierConfig";
|
|
10
|
+
import { addModuleToConfig, getNuxtConfig, getUIConfig, updateConfig } from "../utils/config";
|
|
11
|
+
import { INIT_DEPS, INIT_DEV_DEPS, INIT_MODULES } from "../utils/constants";
|
|
12
|
+
import { installPackages } from "../utils/installPackages";
|
|
13
|
+
import { printFancyBoxMessage } from "../utils/printFancyBoxMessage";
|
|
14
|
+
|
|
15
|
+
export const init = new Command()
|
|
16
|
+
.command("init")
|
|
17
|
+
.name("init")
|
|
18
|
+
.description(
|
|
19
|
+
"Initialize UI Thing in your Nuxt3 project. This will: 1. Create a tailwind.config.js file 2. Update your nuxt.config.ts file 3. Add the necessary dependencies 4. Create a ui-thing.config.ts file with the default configuration"
|
|
20
|
+
)
|
|
21
|
+
.option("-f --force", "Overwrite config file if it exists.", false)
|
|
22
|
+
.action(async (options: InitOptions) => {
|
|
23
|
+
// Get nuxt config
|
|
24
|
+
const cfg = await getNuxtConfig();
|
|
25
|
+
// Get ui config
|
|
26
|
+
let uiConfig: UIConfig = await getUIConfig(options);
|
|
27
|
+
// Add tailwindcss
|
|
28
|
+
await fse.writeFile(uiConfig.tailwindConfigLocation, TAILWIND_CONFIG_JS, "utf-8");
|
|
29
|
+
// create css path if it does not exist
|
|
30
|
+
// add css file
|
|
31
|
+
fse.writeFileSync(
|
|
32
|
+
uiConfig.tailwindCSSLocation,
|
|
33
|
+
createCSS(uiConfig.theme.toUpperCase() as any),
|
|
34
|
+
"utf-8"
|
|
35
|
+
);
|
|
36
|
+
// Add init modules ot nuxt cinfig
|
|
37
|
+
addModuleToConfig(cfg.nuxtConfig, INIT_MODULES);
|
|
38
|
+
// Configure modules in nuxt config
|
|
39
|
+
cfg.defaultExport.tailwindcss = defu(cfg.defaultExport.tailwindcss, { exposeConfig: true });
|
|
40
|
+
cfg.defaultExport.colorMode = defu(cfg.defaultExport.colorMode, { classSuffix: "" });
|
|
41
|
+
cfg.defaultExport.typescript = defu(cfg.defaultExport.typescript, { shim: false });
|
|
42
|
+
cfg.defaultExport.imports ||= {};
|
|
43
|
+
cfg.defaultExport.imports.imports ||= [];
|
|
44
|
+
const tvExists = cfg.defaultExport.imports.imports.find(
|
|
45
|
+
(i: any) => i.from === "tailwind-variants" && i.name === "tv"
|
|
46
|
+
);
|
|
47
|
+
if (!tvExists) {
|
|
48
|
+
cfg.defaultExport.imports.imports.push({ from: "tailwind-variants", name: "tv" });
|
|
49
|
+
}
|
|
50
|
+
const variantPropsExists = cfg.defaultExport.imports.imports.find(
|
|
51
|
+
(i: any) => i.from === "tailwind-variants" && i.name === "VariantProps"
|
|
52
|
+
);
|
|
53
|
+
if (!variantPropsExists) {
|
|
54
|
+
cfg.defaultExport.imports.imports.push({
|
|
55
|
+
from: "tailwind-variants",
|
|
56
|
+
name: "VariantProps",
|
|
57
|
+
type: true,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
// Wriet changes to nuxt config
|
|
61
|
+
await updateConfig(cfg.nuxtConfig, "nuxt.config.ts");
|
|
62
|
+
// instal deps
|
|
63
|
+
await installPackages(uiConfig.packageManager, INIT_DEPS, INIT_DEV_DEPS);
|
|
64
|
+
// Add prettier config
|
|
65
|
+
await addPrettierConfig();
|
|
66
|
+
|
|
67
|
+
printFancyBoxMessage(
|
|
68
|
+
"Initialized",
|
|
69
|
+
{ title: "Complete" },
|
|
70
|
+
`Feel free to start adding components with the ${kleur.bgWhite(" add ")} command.`
|
|
71
|
+
);
|
|
72
|
+
});
|