ui-thing 0.1.55 → 0.2.0
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/.husky/pre-commit +1 -0
- package/CHANGELOG.md +80 -0
- package/README.md +4 -3
- package/dist/index.js +1273 -15547
- package/dist/index.js.map +1 -1
- package/package.json +33 -21
- package/src/commands/add.ts +218 -274
- package/src/commands/init.ts +107 -58
- package/src/commands/prettier.ts +6 -8
- package/src/commands/shortcuts.ts +13 -13
- package/src/commands/theme.ts +9 -6
- package/src/index.ts +2 -2
- package/src/templates/css.ts +958 -773
- package/src/templates/prettier.ts +14 -16
- package/src/templates/shortcuts.ts +225 -126
- package/src/templates/tw-helper.ts +8 -0
- package/src/templates/vs-code.ts +24 -0
- package/src/types.ts +74 -3
- package/src/utils/addPrettierConfig.ts +49 -6
- package/src/utils/addShortcutFiles.ts +5 -4
- package/src/utils/addTailwindVitePlugin.ts +35 -0
- package/src/utils/addVSCodeFiles.ts +13 -0
- package/src/utils/compareUIConfig.ts +1 -2
- package/src/utils/config.ts +59 -86
- package/src/utils/constants.ts +67 -13
- package/src/utils/detectNuxtVersion.ts +20 -0
- package/src/utils/fetchComponents.ts +14 -1
- package/src/utils/installPackages.ts +3 -27
- package/src/utils/mergeJsonFile.ts +28 -0
- package/src/utils/printFancyBoxMessage.ts +62 -16
- package/src/utils/promptForComponents.ts +8 -6
- package/src/utils/uiConfigPrompt.ts +12 -37
- package/tsconfig.json +2 -1
- package/dist/chunk-FW4363Y4.js +0 -2
- package/dist/chunk-FW4363Y4.js.map +0 -1
- package/dist/prompt-4NXDAQWE.js +0 -46
- package/dist/prompt-4NXDAQWE.js.map +0 -1
- package/src/comps.ts +0 -3181
- package/src/templates/tailwind.ts +0 -142
package/src/commands/init.ts
CHANGED
|
@@ -1,76 +1,125 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { updateConfig } from "c12/update";
|
|
1
3
|
import { Command } from "commander";
|
|
2
|
-
import { defu } from "defu";
|
|
3
4
|
import fse from "fs-extra";
|
|
4
5
|
import kleur from "kleur";
|
|
6
|
+
import ora from "ora";
|
|
5
7
|
|
|
6
8
|
import { createCSS } from "../templates/css";
|
|
7
|
-
import {
|
|
9
|
+
import { TW_HELPER } from "../templates/tw-helper";
|
|
8
10
|
import { InitOptions, UIConfig } from "../types";
|
|
9
11
|
import { addPrettierConfig } from "../utils/addPrettierConfig";
|
|
10
|
-
import {
|
|
12
|
+
import { addTailwindVitePlugin } from "../utils/addTailwindVitePlugin";
|
|
13
|
+
import { addVSCodeFiles } from "../utils/addVSCodeFiles";
|
|
14
|
+
import { getUIConfig } from "../utils/config";
|
|
11
15
|
import { INIT_DEPS, INIT_DEV_DEPS, INIT_MODULES } from "../utils/constants";
|
|
12
16
|
import { installPackages } from "../utils/installPackages";
|
|
13
17
|
import { printFancyBoxMessage } from "../utils/printFancyBoxMessage";
|
|
14
18
|
|
|
19
|
+
/**
|
|
20
|
+
* Runs the initialization command.
|
|
21
|
+
*/
|
|
22
|
+
const runInitCommand = async (options: InitOptions) => {
|
|
23
|
+
// Get or create the initial configuration file
|
|
24
|
+
let uiConfig: UIConfig = await getUIConfig(options);
|
|
25
|
+
const spinner = ora("Updating nuxt.config...").start();
|
|
26
|
+
// Get nuxt config
|
|
27
|
+
await updateConfig({
|
|
28
|
+
cwd: process.cwd(),
|
|
29
|
+
configFile: "nuxt.config",
|
|
30
|
+
async onUpdate(config: any) {
|
|
31
|
+
// Create modules array if it does not exist
|
|
32
|
+
if (!config.modules) config.modules = [];
|
|
33
|
+
// Create imports object if it does not exist
|
|
34
|
+
if (!config.imports) config.imports = { imports: [] };
|
|
35
|
+
for (const mod of INIT_MODULES) {
|
|
36
|
+
if (!config.modules.includes(mod)) {
|
|
37
|
+
config.modules.push(mod);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
// Add color mode config to nuxt.config file
|
|
41
|
+
if (!config.colorMode) {
|
|
42
|
+
// get the name of the folder(project name)
|
|
43
|
+
const projectName = path.basename(process.cwd());
|
|
44
|
+
config.colorMode = { storageKey: `${projectName}-color-mode` };
|
|
45
|
+
}
|
|
46
|
+
// Add icon config if not present
|
|
47
|
+
if (!config.icon) {
|
|
48
|
+
config.icon = {
|
|
49
|
+
clientBundle: { scan: true, sizeLimitKb: 0 },
|
|
50
|
+
mode: "svg",
|
|
51
|
+
class: "shrink-0",
|
|
52
|
+
fetchTimeout: 2000,
|
|
53
|
+
serverBundle: "local",
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
// Add `tv` auto-import to the config file if it does not exists
|
|
57
|
+
if (
|
|
58
|
+
!config.imports.imports.find((i: any) => i.from === "tailwind-variants" && i.name === "tv")
|
|
59
|
+
) {
|
|
60
|
+
config.imports.imports.push({ from: "tailwind-variants", name: "tv" });
|
|
61
|
+
}
|
|
62
|
+
// Add `VariantProps` auto-import to the config file if it does not exists
|
|
63
|
+
if (
|
|
64
|
+
!config.imports.imports.find(
|
|
65
|
+
(i: any) => i.from === "tailwind-variants" && i.name === "VariantProps"
|
|
66
|
+
)
|
|
67
|
+
) {
|
|
68
|
+
config.imports.imports.push({
|
|
69
|
+
from: "tailwind-variants",
|
|
70
|
+
name: "VariantProps",
|
|
71
|
+
type: true,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
// Add css path to config
|
|
75
|
+
config.css ||= [];
|
|
76
|
+
config.css.push(`~/${uiConfig.tailwindCSSLocation?.split("app/")[1]}`);
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
await addTailwindVitePlugin();
|
|
80
|
+
spinner.succeed("Updated nuxt.config!");
|
|
81
|
+
spinner.start("Adding initial Tailwind CSS file...");
|
|
82
|
+
fse.writeFileSync(
|
|
83
|
+
uiConfig.tailwindCSSLocation,
|
|
84
|
+
createCSS(uiConfig.theme.toUpperCase() as any),
|
|
85
|
+
"utf-8"
|
|
86
|
+
);
|
|
87
|
+
spinner.succeed("Added initial Tailwind CSS file!");
|
|
88
|
+
spinner.start("Adding Autocomplete helper...");
|
|
89
|
+
// Add Autocomplete helper
|
|
90
|
+
fse.writeFileSync(uiConfig.utilsLocation + "/tw-helper.ts", TW_HELPER, "utf-8");
|
|
91
|
+
spinner.succeed("Added Autocomplete helper!");
|
|
92
|
+
spinner.start("Merging VS Code settings...");
|
|
93
|
+
// Add .vscode folder with recommendations & settings
|
|
94
|
+
addVSCodeFiles();
|
|
95
|
+
spinner.succeed("Merged VS Code settings!");
|
|
96
|
+
// Install deps
|
|
97
|
+
await installPackages(uiConfig.packageManager, INIT_DEPS, INIT_DEV_DEPS);
|
|
98
|
+
// Add prettier config
|
|
99
|
+
await addPrettierConfig();
|
|
100
|
+
printFancyBoxMessage(
|
|
101
|
+
"Initialized",
|
|
102
|
+
`Feel free to start adding components with the ${kleur.bgWhite(" add ")} command.`,
|
|
103
|
+
{ box: { title: "Complete" } }
|
|
104
|
+
);
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Command to initialize UI Thing in a Nuxt project.
|
|
109
|
+
*/
|
|
15
110
|
export const init = new Command()
|
|
16
111
|
.command("init")
|
|
17
112
|
.name("init")
|
|
113
|
+
.summary("Initialize UI Thing in your Nuxt project.")
|
|
18
114
|
.description(
|
|
19
|
-
"Initialize UI Thing in your Nuxt project.
|
|
115
|
+
`${kleur.bold("Initialize UI Thing in your Nuxt project.")}
|
|
116
|
+
|
|
117
|
+
✅ Add tailwindcss to your project
|
|
118
|
+
✅ Update your nuxt.config file
|
|
119
|
+
✅ Add the necessary dependencies
|
|
120
|
+
✅ Create a ${kleur.bold("ui-thing.config")} file with the default configuration`
|
|
20
121
|
)
|
|
21
122
|
.option("-f --force", "Overwrite config file if it exists.", false)
|
|
22
123
|
.option("-y --yes", "Skip prompts and use default values.", false)
|
|
23
|
-
.option("-n --nuxtVersion <number>", "Specify the Nuxt version you are using."
|
|
24
|
-
.action(
|
|
25
|
-
// Get nuxt config
|
|
26
|
-
const cfg = await getNuxtConfig();
|
|
27
|
-
// Get ui config
|
|
28
|
-
let uiConfig: UIConfig = await getUIConfig(options);
|
|
29
|
-
// Add tailwindcss
|
|
30
|
-
await fse.writeFile(uiConfig.tailwindConfigLocation, TAILWIND_CONFIG_JS, "utf-8");
|
|
31
|
-
// create css path if it does not exist
|
|
32
|
-
// add css file
|
|
33
|
-
fse.writeFileSync(
|
|
34
|
-
uiConfig.tailwindCSSLocation,
|
|
35
|
-
createCSS(uiConfig.theme.toUpperCase() as any),
|
|
36
|
-
"utf-8"
|
|
37
|
-
);
|
|
38
|
-
// Add init modules ot nuxt cinfig
|
|
39
|
-
addModuleToConfig(cfg.nuxtConfig, INIT_MODULES);
|
|
40
|
-
// Configure modules in nuxt config
|
|
41
|
-
cfg.defaultExport.tailwindcss = defu(cfg.defaultExport.tailwindcss, {
|
|
42
|
-
exposeConfig: true,
|
|
43
|
-
editorSupport: true,
|
|
44
|
-
});
|
|
45
|
-
cfg.defaultExport.colorMode = defu(cfg.defaultExport.colorMode, { classSuffix: "" });
|
|
46
|
-
cfg.defaultExport.imports ||= {};
|
|
47
|
-
cfg.defaultExport.imports.imports ||= [];
|
|
48
|
-
const tvExists = cfg.defaultExport.imports.imports.find(
|
|
49
|
-
(i: any) => i.from === "tailwind-variants" && i.name === "tv"
|
|
50
|
-
);
|
|
51
|
-
if (!tvExists) {
|
|
52
|
-
cfg.defaultExport.imports.imports.push({ from: "tailwind-variants", name: "tv" });
|
|
53
|
-
}
|
|
54
|
-
const variantPropsExists = cfg.defaultExport.imports.imports.find(
|
|
55
|
-
(i: any) => i.from === "tailwind-variants" && i.name === "VariantProps"
|
|
56
|
-
);
|
|
57
|
-
if (!variantPropsExists) {
|
|
58
|
-
cfg.defaultExport.imports.imports.push({
|
|
59
|
-
from: "tailwind-variants",
|
|
60
|
-
name: "VariantProps",
|
|
61
|
-
type: true,
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
// Write changes to nuxt config
|
|
65
|
-
await updateConfig(cfg.nuxtConfig, "nuxt.config.ts");
|
|
66
|
-
// instal deps
|
|
67
|
-
await installPackages(uiConfig.packageManager, INIT_DEPS, INIT_DEV_DEPS);
|
|
68
|
-
// Add prettier config
|
|
69
|
-
await addPrettierConfig();
|
|
70
|
-
|
|
71
|
-
printFancyBoxMessage(
|
|
72
|
-
"Initialized",
|
|
73
|
-
{ title: "Complete" },
|
|
74
|
-
`Feel free to start adding components with the ${kleur.bgWhite(" add ")} command.`
|
|
75
|
-
);
|
|
76
|
-
});
|
|
124
|
+
.option("-n --nuxtVersion <number>", "Specify the Nuxt version you are using.")
|
|
125
|
+
.action(runInitCommand);
|
package/src/commands/prettier.ts
CHANGED
|
@@ -9,15 +9,13 @@ import { printFancyBoxMessage } from "../utils/printFancyBoxMessage";
|
|
|
9
9
|
export const addPrettier = new Command()
|
|
10
10
|
.command("prettier")
|
|
11
11
|
.name("prettier")
|
|
12
|
-
.description("
|
|
12
|
+
.description("Adds prettier config to your project.")
|
|
13
13
|
.action(async () => {
|
|
14
14
|
const added = await addPrettierConfig(undefined, false);
|
|
15
15
|
if (!added) {
|
|
16
|
-
printFancyBoxMessage(
|
|
17
|
-
"Not Added",
|
|
18
|
-
|
|
19
|
-
`Prettier config was not added.`
|
|
20
|
-
);
|
|
16
|
+
printFancyBoxMessage("Not Added", `Prettier config was not added.`, {
|
|
17
|
+
box: { title: "Prettier Not Added", borderColor: "red" },
|
|
18
|
+
});
|
|
21
19
|
return;
|
|
22
20
|
}
|
|
23
21
|
|
|
@@ -37,7 +35,7 @@ export const addPrettier = new Command()
|
|
|
37
35
|
]);
|
|
38
36
|
printFancyBoxMessage(
|
|
39
37
|
"All Done!",
|
|
40
|
-
|
|
41
|
-
|
|
38
|
+
`A .prettierrc file has been added to your project and the code formatted. Enjoy!`,
|
|
39
|
+
{ box: { title: "Prettier Added" } }
|
|
42
40
|
);
|
|
43
41
|
});
|
|
@@ -1,25 +1,22 @@
|
|
|
1
1
|
import { Command } from "commander";
|
|
2
|
+
import { execa } from "execa";
|
|
3
|
+
import ora from "ora";
|
|
2
4
|
import prompts from "prompts";
|
|
3
5
|
|
|
4
6
|
import { addShortcutFiles } from "../utils/addShortcutFiles";
|
|
5
|
-
import { addModuleToConfig, getNuxtConfig, updateConfig } from "../utils/config";
|
|
6
7
|
import { PACKAGE_MANAGER_CHOICES } from "../utils/constants";
|
|
7
|
-
import { installPackages } from "../utils/installPackages";
|
|
8
8
|
import { printFancyBoxMessage } from "../utils/printFancyBoxMessage";
|
|
9
9
|
|
|
10
|
+
/**
|
|
11
|
+
* Adds the shortcuts composables to the project.
|
|
12
|
+
*/
|
|
10
13
|
export const addShortcuts = new Command()
|
|
11
14
|
.command("shortcuts")
|
|
12
15
|
.name("shortcuts")
|
|
13
|
-
.description("Add the
|
|
16
|
+
.description("Add the shortcuts composables to your project.")
|
|
14
17
|
.action(async () => {
|
|
15
18
|
await addShortcutFiles();
|
|
16
19
|
|
|
17
|
-
// Get nuxt config
|
|
18
|
-
const cfg = await getNuxtConfig();
|
|
19
|
-
addModuleToConfig(cfg.nuxtConfig, ["@vueuse/nuxt"]);
|
|
20
|
-
// Write changes to nuxt config
|
|
21
|
-
await updateConfig(cfg.nuxtConfig, "nuxt.config.ts");
|
|
22
|
-
|
|
23
20
|
const { pkgManager } = await prompts({
|
|
24
21
|
name: "pkgManager",
|
|
25
22
|
type: "select",
|
|
@@ -28,11 +25,14 @@ export const addShortcuts = new Command()
|
|
|
28
25
|
});
|
|
29
26
|
if (!pkgManager) return process.exit(0);
|
|
30
27
|
|
|
31
|
-
|
|
32
|
-
|
|
28
|
+
const spinner = ora("Installing vueuse module...").start();
|
|
29
|
+
// install vueuse for nuxt
|
|
30
|
+
await execa`npx -y nuxi@latest module add vueuse`;
|
|
31
|
+
spinner.succeed("VueUse module installed successfully!");
|
|
32
|
+
|
|
33
33
|
printFancyBoxMessage(
|
|
34
34
|
"All Done!",
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
`Check the composables folder for the shortcuts composables.`,
|
|
36
|
+
{ box: { title: "Composable Added" } }
|
|
37
37
|
);
|
|
38
38
|
});
|
package/src/commands/theme.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Command } from "commander";
|
|
2
|
-
import { consola } from "consola";
|
|
3
2
|
import fse from "fs-extra";
|
|
3
|
+
import kleur from "kleur";
|
|
4
4
|
import _ from "lodash";
|
|
5
5
|
import prompts from "prompts";
|
|
6
6
|
|
|
@@ -10,6 +10,9 @@ import { getUIConfig } from "../utils/config";
|
|
|
10
10
|
import { CSS_THEME_OPTIONS } from "../utils/constants";
|
|
11
11
|
import { printFancyBoxMessage } from "../utils/printFancyBoxMessage";
|
|
12
12
|
|
|
13
|
+
/**
|
|
14
|
+
* Adds a new theme to the project.
|
|
15
|
+
*/
|
|
13
16
|
export const theme = new Command()
|
|
14
17
|
.command("theme")
|
|
15
18
|
.name("theme")
|
|
@@ -22,7 +25,7 @@ export const theme = new Command()
|
|
|
22
25
|
uiConfig = await getUIConfig({ force: true });
|
|
23
26
|
}
|
|
24
27
|
if (_.isEmpty(uiConfig)) {
|
|
25
|
-
|
|
28
|
+
console.log(kleur.red("Config file not set. Exiting..."));
|
|
26
29
|
process.exit(0);
|
|
27
30
|
}
|
|
28
31
|
const { theme } = await prompts([
|
|
@@ -34,8 +37,8 @@ export const theme = new Command()
|
|
|
34
37
|
},
|
|
35
38
|
]);
|
|
36
39
|
if (!theme) {
|
|
37
|
-
console.log("No theme selected. Exiting...");
|
|
38
|
-
|
|
40
|
+
console.log(kleur.red("No theme selected. Exiting..."));
|
|
41
|
+
process.exit(0);
|
|
39
42
|
}
|
|
40
43
|
if (fse.existsSync(uiConfig.tailwindCSSLocation)) {
|
|
41
44
|
const { force } = await prompts([
|
|
@@ -55,7 +58,7 @@ export const theme = new Command()
|
|
|
55
58
|
|
|
56
59
|
printFancyBoxMessage(
|
|
57
60
|
`${_.capitalize(theme)}`,
|
|
58
|
-
{
|
|
59
|
-
|
|
61
|
+
`${_.capitalize(theme)} theme has been added to ${uiConfig.tailwindCSSLocation}`,
|
|
62
|
+
{ box: { title: "New Theme Added" } }
|
|
60
63
|
);
|
|
61
64
|
});
|
package/src/index.ts
CHANGED
|
@@ -17,12 +17,12 @@ const program = new Command();
|
|
|
17
17
|
|
|
18
18
|
console.clear();
|
|
19
19
|
|
|
20
|
-
printFancyBoxMessage("UI Thing", { title: "Welcome" });
|
|
20
|
+
printFancyBoxMessage("UI Thing", undefined, { box: { title: "Welcome" } });
|
|
21
21
|
console.log();
|
|
22
22
|
|
|
23
23
|
program
|
|
24
24
|
.name("ui-thing")
|
|
25
|
-
.description("CLI for adding ui-thing components to your Nuxt
|
|
25
|
+
.description("CLI for adding ui-thing components to your Nuxt application")
|
|
26
26
|
.version(version)
|
|
27
27
|
.addCommand(init)
|
|
28
28
|
.addCommand(add)
|