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
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
export const PRETTIER_CONFIG = `{
|
|
2
|
-
"arrowParens": "always",
|
|
3
|
-
"endOfLine": "lf",
|
|
4
|
-
"plugins": ["@ianvs/prettier-plugin-sort-imports", "prettier-plugin-tailwindcss"],
|
|
5
|
-
"printWidth": 100,
|
|
6
|
-
"semi": true,
|
|
7
|
-
"singleQuote": false,
|
|
8
|
-
"tabWidth": 2,
|
|
9
|
-
"trailingComma": "es5",
|
|
10
|
-
"useTabs": false,
|
|
11
|
-
"vueIndentScriptAndStyle": true,
|
|
12
|
-
"tailwindFunctions": ["tv"],
|
|
13
|
-
"importOrder": ["<BUILTIN_MODULES>", "<THIRD_PARTY_MODULES>", "<TYPES>", "", "^[.]"]
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
`;
|
|
1
|
+
export const PRETTIER_CONFIG = `{
|
|
2
|
+
"arrowParens": "always",
|
|
3
|
+
"endOfLine": "lf",
|
|
4
|
+
"plugins": ["@ianvs/prettier-plugin-sort-imports", "prettier-plugin-tailwindcss"],
|
|
5
|
+
"printWidth": 100,
|
|
6
|
+
"semi": true,
|
|
7
|
+
"singleQuote": false,
|
|
8
|
+
"tabWidth": 2,
|
|
9
|
+
"trailingComma": "es5",
|
|
10
|
+
"useTabs": false,
|
|
11
|
+
"vueIndentScriptAndStyle": true,
|
|
12
|
+
"tailwindFunctions": ["tv"],
|
|
13
|
+
"importOrder": ["<BUILTIN_MODULES>", "<THIRD_PARTY_MODULES>", "<TYPES>", "", "^[.]"]
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
`;
|
|
@@ -1,101 +1,101 @@
|
|
|
1
|
-
export const TAILWIND_CONFIG_JS = `const { fontFamily } = require("tailwindcss/defaultTheme");
|
|
2
|
-
|
|
3
|
-
/**@type {import('tailwindcss').Config} */
|
|
4
|
-
module.exports = {
|
|
5
|
-
darkMode: "class",
|
|
6
|
-
theme: {
|
|
7
|
-
extend: {
|
|
8
|
-
container: {
|
|
9
|
-
center: true,
|
|
10
|
-
padding: {
|
|
11
|
-
DEFAULT: "1rem",
|
|
12
|
-
sm: "2rem",
|
|
13
|
-
lg: "4rem",
|
|
14
|
-
},
|
|
15
|
-
screens: {
|
|
16
|
-
"2xl": "1440px",
|
|
17
|
-
},
|
|
18
|
-
},
|
|
19
|
-
fontFamily: {
|
|
20
|
-
sans: ["Inter var", "Inter", ...fontFamily.sans],
|
|
21
|
-
},
|
|
22
|
-
borderRadius: {
|
|
23
|
-
lg: "var(--radius)",
|
|
24
|
-
md: "calc(var(--radius) - 2px)",
|
|
25
|
-
sm: "calc(var(--radius) - 4px)",
|
|
26
|
-
},
|
|
27
|
-
keyframes: {
|
|
28
|
-
"accordion-down": {
|
|
29
|
-
from: { height: "0px" },
|
|
30
|
-
to: { height: "var(--radix-accordion-content-height)" },
|
|
31
|
-
},
|
|
32
|
-
"accordion-up": {
|
|
33
|
-
from: { height: "var(--radix-accordion-content-height)" },
|
|
34
|
-
to: { height: "0px" },
|
|
35
|
-
},
|
|
36
|
-
fadeIn: {
|
|
37
|
-
from: { opacity: "0" },
|
|
38
|
-
to: { opacity: "1" },
|
|
39
|
-
},
|
|
40
|
-
fadeOut: {
|
|
41
|
-
from: { opacity: "1" },
|
|
42
|
-
to: { opacity: "0" },
|
|
43
|
-
},
|
|
44
|
-
"collapse-down": {
|
|
45
|
-
from: { height: "0px" },
|
|
46
|
-
to: { height: "var(--radix-collapsible-content-height)" },
|
|
47
|
-
},
|
|
48
|
-
"collapse-up": {
|
|
49
|
-
from: { height: "var(--radix-collapsible-content-height)" },
|
|
50
|
-
to: { height: "0px" },
|
|
51
|
-
},
|
|
52
|
-
},
|
|
53
|
-
animation: {
|
|
54
|
-
"accordion-down": "accordion-down 0.2s ease-out",
|
|
55
|
-
"accordion-up": "accordion-up 0.2s ease-out",
|
|
56
|
-
fadeIn: "fadeIn 0.2s ease-out",
|
|
57
|
-
fadeOut: "fadeOut 0.2s ease-out",
|
|
58
|
-
"collapse-down": "collapse-down 0.2s ease-out",
|
|
59
|
-
"collapse-up": "collapse-up 0.2s ease-out",
|
|
60
|
-
},
|
|
61
|
-
colors: {
|
|
62
|
-
border: "hsl(var(--border))",
|
|
63
|
-
input: "hsl(var(--input))",
|
|
64
|
-
ring: "hsl(var(--ring))",
|
|
65
|
-
background: "hsl(var(--background))",
|
|
66
|
-
foreground: "hsl(var(--foreground))",
|
|
67
|
-
primary: {
|
|
68
|
-
DEFAULT: "hsl(var(--primary))",
|
|
69
|
-
foreground: "hsl(var(--primary-foreground))",
|
|
70
|
-
},
|
|
71
|
-
secondary: {
|
|
72
|
-
DEFAULT: "hsl(var(--secondary))",
|
|
73
|
-
foreground: "hsl(var(--secondary-foreground))",
|
|
74
|
-
},
|
|
75
|
-
destructive: {
|
|
76
|
-
DEFAULT: "hsl(var(--destructive))",
|
|
77
|
-
foreground: "hsl(var(--destructive-foreground))",
|
|
78
|
-
},
|
|
79
|
-
muted: {
|
|
80
|
-
DEFAULT: "hsl(var(--muted))",
|
|
81
|
-
foreground: "hsl(var(--muted-foreground))",
|
|
82
|
-
},
|
|
83
|
-
accent: {
|
|
84
|
-
DEFAULT: "hsl(var(--accent))",
|
|
85
|
-
foreground: "hsl(var(--accent-foreground))",
|
|
86
|
-
},
|
|
87
|
-
popover: {
|
|
88
|
-
DEFAULT: "hsl(var(--popover))",
|
|
89
|
-
foreground: "hsl(var(--popover-foreground))",
|
|
90
|
-
},
|
|
91
|
-
card: {
|
|
92
|
-
DEFAULT: "hsl(var(--card))",
|
|
93
|
-
foreground: "hsl(var(--card-foreground))",
|
|
94
|
-
},
|
|
95
|
-
},
|
|
96
|
-
},
|
|
97
|
-
},
|
|
98
|
-
plugins: [require("tailwindcss-animate")],
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
`;
|
|
1
|
+
export const TAILWIND_CONFIG_JS = `const { fontFamily } = require("tailwindcss/defaultTheme");
|
|
2
|
+
|
|
3
|
+
/**@type {import('tailwindcss').Config} */
|
|
4
|
+
module.exports = {
|
|
5
|
+
darkMode: "class",
|
|
6
|
+
theme: {
|
|
7
|
+
extend: {
|
|
8
|
+
container: {
|
|
9
|
+
center: true,
|
|
10
|
+
padding: {
|
|
11
|
+
DEFAULT: "1rem",
|
|
12
|
+
sm: "2rem",
|
|
13
|
+
lg: "4rem",
|
|
14
|
+
},
|
|
15
|
+
screens: {
|
|
16
|
+
"2xl": "1440px",
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
fontFamily: {
|
|
20
|
+
sans: ["Inter var", "Inter", ...fontFamily.sans],
|
|
21
|
+
},
|
|
22
|
+
borderRadius: {
|
|
23
|
+
lg: "var(--radius)",
|
|
24
|
+
md: "calc(var(--radius) - 2px)",
|
|
25
|
+
sm: "calc(var(--radius) - 4px)",
|
|
26
|
+
},
|
|
27
|
+
keyframes: {
|
|
28
|
+
"accordion-down": {
|
|
29
|
+
from: { height: "0px" },
|
|
30
|
+
to: { height: "var(--radix-accordion-content-height)" },
|
|
31
|
+
},
|
|
32
|
+
"accordion-up": {
|
|
33
|
+
from: { height: "var(--radix-accordion-content-height)" },
|
|
34
|
+
to: { height: "0px" },
|
|
35
|
+
},
|
|
36
|
+
fadeIn: {
|
|
37
|
+
from: { opacity: "0" },
|
|
38
|
+
to: { opacity: "1" },
|
|
39
|
+
},
|
|
40
|
+
fadeOut: {
|
|
41
|
+
from: { opacity: "1" },
|
|
42
|
+
to: { opacity: "0" },
|
|
43
|
+
},
|
|
44
|
+
"collapse-down": {
|
|
45
|
+
from: { height: "0px" },
|
|
46
|
+
to: { height: "var(--radix-collapsible-content-height)" },
|
|
47
|
+
},
|
|
48
|
+
"collapse-up": {
|
|
49
|
+
from: { height: "var(--radix-collapsible-content-height)" },
|
|
50
|
+
to: { height: "0px" },
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
animation: {
|
|
54
|
+
"accordion-down": "accordion-down 0.2s ease-out",
|
|
55
|
+
"accordion-up": "accordion-up 0.2s ease-out",
|
|
56
|
+
fadeIn: "fadeIn 0.2s ease-out",
|
|
57
|
+
fadeOut: "fadeOut 0.2s ease-out",
|
|
58
|
+
"collapse-down": "collapse-down 0.2s ease-out",
|
|
59
|
+
"collapse-up": "collapse-up 0.2s ease-out",
|
|
60
|
+
},
|
|
61
|
+
colors: {
|
|
62
|
+
border: "hsl(var(--border))",
|
|
63
|
+
input: "hsl(var(--input))",
|
|
64
|
+
ring: "hsl(var(--ring))",
|
|
65
|
+
background: "hsl(var(--background))",
|
|
66
|
+
foreground: "hsl(var(--foreground))",
|
|
67
|
+
primary: {
|
|
68
|
+
DEFAULT: "hsl(var(--primary))",
|
|
69
|
+
foreground: "hsl(var(--primary-foreground))",
|
|
70
|
+
},
|
|
71
|
+
secondary: {
|
|
72
|
+
DEFAULT: "hsl(var(--secondary))",
|
|
73
|
+
foreground: "hsl(var(--secondary-foreground))",
|
|
74
|
+
},
|
|
75
|
+
destructive: {
|
|
76
|
+
DEFAULT: "hsl(var(--destructive))",
|
|
77
|
+
foreground: "hsl(var(--destructive-foreground))",
|
|
78
|
+
},
|
|
79
|
+
muted: {
|
|
80
|
+
DEFAULT: "hsl(var(--muted))",
|
|
81
|
+
foreground: "hsl(var(--muted-foreground))",
|
|
82
|
+
},
|
|
83
|
+
accent: {
|
|
84
|
+
DEFAULT: "hsl(var(--accent))",
|
|
85
|
+
foreground: "hsl(var(--accent-foreground))",
|
|
86
|
+
},
|
|
87
|
+
popover: {
|
|
88
|
+
DEFAULT: "hsl(var(--popover))",
|
|
89
|
+
foreground: "hsl(var(--popover-foreground))",
|
|
90
|
+
},
|
|
91
|
+
card: {
|
|
92
|
+
DEFAULT: "hsl(var(--card))",
|
|
93
|
+
foreground: "hsl(var(--card-foreground))",
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
plugins: [require("tailwindcss-animate")],
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
`;
|
package/src/types.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
export type UIConfig = {
|
|
2
|
-
theme: string;
|
|
3
|
-
tailwindCSSLocation: string;
|
|
4
|
-
tailwindConfigLocation: string;
|
|
5
|
-
componentsLocation: string;
|
|
6
|
-
composablesLocation: string;
|
|
7
|
-
utilsLocation: string;
|
|
8
|
-
force: boolean;
|
|
9
|
-
useDefaultFilename: boolean;
|
|
10
|
-
packageManager: string;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export type InitOptions = { force?: boolean };
|
|
1
|
+
export type UIConfig = {
|
|
2
|
+
theme: string;
|
|
3
|
+
tailwindCSSLocation: string;
|
|
4
|
+
tailwindConfigLocation: string;
|
|
5
|
+
componentsLocation: string;
|
|
6
|
+
composablesLocation: string;
|
|
7
|
+
utilsLocation: string;
|
|
8
|
+
force: boolean;
|
|
9
|
+
useDefaultFilename: boolean;
|
|
10
|
+
packageManager: string;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export type InitOptions = { force?: boolean };
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import { $ } from "execa";
|
|
2
|
-
import fse from "fs-extra";
|
|
3
|
-
import ora from "ora";
|
|
4
|
-
import prompts from "prompts";
|
|
5
|
-
|
|
6
|
-
import { PRETTIER_CONFIG } from "../templates/prettier";
|
|
7
|
-
|
|
8
|
-
export const addPrettierConfig = async (cwd = process.cwd(), format: boolean = true) => {
|
|
9
|
-
if (fse.existsSync(`${cwd}/.prettierrc`)) {
|
|
10
|
-
const res = await prompts({
|
|
11
|
-
name: "overwrite",
|
|
12
|
-
type: "confirm",
|
|
13
|
-
message: "A prettier config file already exists. Overwrite?",
|
|
14
|
-
initial: true,
|
|
15
|
-
});
|
|
16
|
-
if (!res.overwrite) return false;
|
|
17
|
-
}
|
|
18
|
-
await fse.writeFile(`${cwd}/.prettierrc`, PRETTIER_CONFIG, "utf-8");
|
|
19
|
-
if (!format) return true;
|
|
20
|
-
const spinner = ora("Formatting files with prettier...").start();
|
|
21
|
-
await $`npx prettier --write .`;
|
|
22
|
-
spinner.succeed("Files formatted with prettier");
|
|
23
|
-
return true;
|
|
24
|
-
};
|
|
1
|
+
import { $ } from "execa";
|
|
2
|
+
import fse from "fs-extra";
|
|
3
|
+
import ora from "ora";
|
|
4
|
+
import prompts from "prompts";
|
|
5
|
+
|
|
6
|
+
import { PRETTIER_CONFIG } from "../templates/prettier";
|
|
7
|
+
|
|
8
|
+
export const addPrettierConfig = async (cwd = process.cwd(), format: boolean = true) => {
|
|
9
|
+
if (fse.existsSync(`${cwd}/.prettierrc`)) {
|
|
10
|
+
const res = await prompts({
|
|
11
|
+
name: "overwrite",
|
|
12
|
+
type: "confirm",
|
|
13
|
+
message: "A prettier config file already exists. Overwrite?",
|
|
14
|
+
initial: true,
|
|
15
|
+
});
|
|
16
|
+
if (!res.overwrite) return false;
|
|
17
|
+
}
|
|
18
|
+
await fse.writeFile(`${cwd}/.prettierrc`, PRETTIER_CONFIG, "utf-8");
|
|
19
|
+
if (!format) return true;
|
|
20
|
+
const spinner = ora("Formatting files with prettier...").start();
|
|
21
|
+
await $`npx prettier --write .`;
|
|
22
|
+
spinner.succeed("Files formatted with prettier");
|
|
23
|
+
return true;
|
|
24
|
+
};
|
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
import { UIConfig } from "../types";
|
|
2
|
-
import { getUIConfig } from "./config";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Compares the UI config with a temporary config to see if any properties are missing
|
|
6
|
-
* @returns {boolean} - Returns true if all properties are present
|
|
7
|
-
*/
|
|
8
|
-
export const compareUIConfig = async () => {
|
|
9
|
-
// Get ui config
|
|
10
|
-
let userConfig: UIConfig = await getUIConfig();
|
|
11
|
-
const tempConfig: UIConfig = {
|
|
12
|
-
theme: "string",
|
|
13
|
-
tailwindCSSLocation: "string",
|
|
14
|
-
tailwindConfigLocation: "string",
|
|
15
|
-
componentsLocation: "string",
|
|
16
|
-
composablesLocation: "string",
|
|
17
|
-
utilsLocation: "string",
|
|
18
|
-
force: true,
|
|
19
|
-
useDefaultFilename: true,
|
|
20
|
-
packageManager: "string",
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
const missingProperties: string[] = [];
|
|
24
|
-
|
|
25
|
-
for (const key of Object.keys(tempConfig)) {
|
|
26
|
-
if (userConfig[key as keyof UIConfig] === undefined) {
|
|
27
|
-
missingProperties.push(key);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
if (missingProperties.length > 0) {
|
|
32
|
-
return false;
|
|
33
|
-
}
|
|
34
|
-
return true;
|
|
35
|
-
};
|
|
1
|
+
import { UIConfig } from "../types";
|
|
2
|
+
import { getUIConfig } from "./config";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Compares the UI config with a temporary config to see if any properties are missing
|
|
6
|
+
* @returns {boolean} - Returns true if all properties are present
|
|
7
|
+
*/
|
|
8
|
+
export const compareUIConfig = async () => {
|
|
9
|
+
// Get ui config
|
|
10
|
+
let userConfig: UIConfig = await getUIConfig();
|
|
11
|
+
const tempConfig: UIConfig = {
|
|
12
|
+
theme: "string",
|
|
13
|
+
tailwindCSSLocation: "string",
|
|
14
|
+
tailwindConfigLocation: "string",
|
|
15
|
+
componentsLocation: "string",
|
|
16
|
+
composablesLocation: "string",
|
|
17
|
+
utilsLocation: "string",
|
|
18
|
+
force: true,
|
|
19
|
+
useDefaultFilename: true,
|
|
20
|
+
packageManager: "string",
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const missingProperties: string[] = [];
|
|
24
|
+
|
|
25
|
+
for (const key of Object.keys(tempConfig)) {
|
|
26
|
+
if (userConfig[key as keyof UIConfig] === undefined) {
|
|
27
|
+
missingProperties.push(key);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (missingProperties.length > 0) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
return true;
|
|
35
|
+
};
|
package/src/utils/config.ts
CHANGED
|
@@ -1,84 +1,84 @@
|
|
|
1
|
-
import { join } from "path";
|
|
2
|
-
import { loadConfig } from "c12";
|
|
3
|
-
import fse from "fs-extra";
|
|
4
|
-
import kleur from "kleur";
|
|
5
|
-
import _ from "lodash";
|
|
6
|
-
import { loadFile, ProxifiedModule, writeFile } from "magicast";
|
|
7
|
-
import { addNuxtModule, getDefaultExportOptions } from "magicast/helpers";
|
|
8
|
-
import prompts from "prompts";
|
|
9
|
-
|
|
10
|
-
import { InitOptions, UIConfig } from "../types";
|
|
11
|
-
import { initPrompts } from "./uiConfigPrompt";
|
|
12
|
-
|
|
13
|
-
const currentDir = process.cwd();
|
|
14
|
-
const uiConfigFilename = "ui-thing.config.ts";
|
|
15
|
-
|
|
16
|
-
export const getNuxtConfig = async () => {
|
|
17
|
-
if (!fse.existsSync("nuxt.config.ts")) {
|
|
18
|
-
console.log(kleur.red(`No ${kleur.bgWhite(`nuxt.config.ts`)} file found. Exiting...`));
|
|
19
|
-
return process.exit(0);
|
|
20
|
-
}
|
|
21
|
-
const nuxtConfig = await loadFile(join(currentDir, "nuxt.config.ts"));
|
|
22
|
-
const defaultExport = getDefaultExportOptions(nuxtConfig);
|
|
23
|
-
return { nuxtConfig, defaultExport };
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
export const getUIConfig = async (options?: InitOptions) => {
|
|
27
|
-
const configFileExists = fse.existsSync(uiConfigFilename);
|
|
28
|
-
let uiConfig: UIConfig = {} as UIConfig;
|
|
29
|
-
|
|
30
|
-
if (!configFileExists || options?.force) {
|
|
31
|
-
uiConfig = await initPrompts();
|
|
32
|
-
await fse.writeFile(uiConfigFilename, `export default ${JSON.stringify(uiConfig, null, 2)}`);
|
|
33
|
-
// Check if user chose pnpm as package manager
|
|
34
|
-
if (uiConfig.packageManager === "pnpm") {
|
|
35
|
-
// check if a .npmrc file exists
|
|
36
|
-
const npmrcExists = fse.existsSync(".npmrc");
|
|
37
|
-
// as the user if they want to create a .npmrc file
|
|
38
|
-
if (npmrcExists) {
|
|
39
|
-
const { confirmCreateNpmrc } = await prompts({
|
|
40
|
-
type: "confirm",
|
|
41
|
-
name: "confirmCreateNpmrc",
|
|
42
|
-
message: "A .npmrc file already exists. Do you want to overwrite it?",
|
|
43
|
-
initial: false,
|
|
44
|
-
});
|
|
45
|
-
if (confirmCreateNpmrc) {
|
|
46
|
-
await fse.writeFile(".npmrc", "shamefully-hoist=true\nstrict-peer-dependencies=false\n");
|
|
47
|
-
}
|
|
48
|
-
} else {
|
|
49
|
-
await fse.writeFile(".npmrc", "shamefully-hoist=true\nstrict-peer-dependencies=false\n");
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
} else {
|
|
53
|
-
const data = await loadConfig({
|
|
54
|
-
configFile: uiConfigFilename.replace(".ts", ""),
|
|
55
|
-
});
|
|
56
|
-
uiConfig = data.config as UIConfig;
|
|
57
|
-
}
|
|
58
|
-
if (_.isEmpty(uiConfig)) {
|
|
59
|
-
await getUIConfig({ force: true });
|
|
60
|
-
}
|
|
61
|
-
createConfigPaths(uiConfig);
|
|
62
|
-
return uiConfig;
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
export const createConfigPaths = (uiConfig: UIConfig) => {
|
|
66
|
-
// Esnure files exists
|
|
67
|
-
if (uiConfig.tailwindCSSLocation) fse.ensureFileSync(uiConfig.tailwindConfigLocation);
|
|
68
|
-
if (uiConfig.tailwindConfigLocation) fse.ensureFileSync(uiConfig.tailwindCSSLocation);
|
|
69
|
-
if (uiConfig.componentsLocation) fse.ensureDirSync(uiConfig.componentsLocation);
|
|
70
|
-
if (uiConfig.composablesLocation) fse.ensureDirSync(uiConfig.composablesLocation);
|
|
71
|
-
if (uiConfig.utilsLocation) fse.ensureDirSync(uiConfig.utilsLocation);
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
export const addModuleToConfig = (cfg: ProxifiedModule, modules: string[] | string) => {
|
|
75
|
-
if (typeof modules === "string") {
|
|
76
|
-
modules = [modules];
|
|
77
|
-
}
|
|
78
|
-
modules.forEach((m) => addNuxtModule(cfg, m));
|
|
79
|
-
return cfg;
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
export const updateConfig = async (cfg: ProxifiedModule, fileName = "nuxt.config.ts") => {
|
|
83
|
-
await writeFile(cfg.$ast, fileName);
|
|
84
|
-
};
|
|
1
|
+
import { join } from "path";
|
|
2
|
+
import { loadConfig } from "c12";
|
|
3
|
+
import fse from "fs-extra";
|
|
4
|
+
import kleur from "kleur";
|
|
5
|
+
import _ from "lodash";
|
|
6
|
+
import { loadFile, ProxifiedModule, writeFile } from "magicast";
|
|
7
|
+
import { addNuxtModule, getDefaultExportOptions } from "magicast/helpers";
|
|
8
|
+
import prompts from "prompts";
|
|
9
|
+
|
|
10
|
+
import { InitOptions, UIConfig } from "../types";
|
|
11
|
+
import { initPrompts } from "./uiConfigPrompt";
|
|
12
|
+
|
|
13
|
+
const currentDir = process.cwd();
|
|
14
|
+
const uiConfigFilename = "ui-thing.config.ts";
|
|
15
|
+
|
|
16
|
+
export const getNuxtConfig = async () => {
|
|
17
|
+
if (!fse.existsSync("nuxt.config.ts")) {
|
|
18
|
+
console.log(kleur.red(`No ${kleur.bgWhite(`nuxt.config.ts`)} file found. Exiting...`));
|
|
19
|
+
return process.exit(0);
|
|
20
|
+
}
|
|
21
|
+
const nuxtConfig = await loadFile(join(currentDir, "nuxt.config.ts"));
|
|
22
|
+
const defaultExport = getDefaultExportOptions(nuxtConfig);
|
|
23
|
+
return { nuxtConfig, defaultExport };
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export const getUIConfig = async (options?: InitOptions) => {
|
|
27
|
+
const configFileExists = fse.existsSync(uiConfigFilename);
|
|
28
|
+
let uiConfig: UIConfig = {} as UIConfig;
|
|
29
|
+
|
|
30
|
+
if (!configFileExists || options?.force) {
|
|
31
|
+
uiConfig = await initPrompts();
|
|
32
|
+
await fse.writeFile(uiConfigFilename, `export default ${JSON.stringify(uiConfig, null, 2)}`);
|
|
33
|
+
// Check if user chose pnpm as package manager
|
|
34
|
+
if (uiConfig.packageManager === "pnpm") {
|
|
35
|
+
// check if a .npmrc file exists
|
|
36
|
+
const npmrcExists = fse.existsSync(".npmrc");
|
|
37
|
+
// as the user if they want to create a .npmrc file
|
|
38
|
+
if (npmrcExists) {
|
|
39
|
+
const { confirmCreateNpmrc } = await prompts({
|
|
40
|
+
type: "confirm",
|
|
41
|
+
name: "confirmCreateNpmrc",
|
|
42
|
+
message: "A .npmrc file already exists. Do you want to overwrite it?",
|
|
43
|
+
initial: false,
|
|
44
|
+
});
|
|
45
|
+
if (confirmCreateNpmrc) {
|
|
46
|
+
await fse.writeFile(".npmrc", "shamefully-hoist=true\nstrict-peer-dependencies=false\n");
|
|
47
|
+
}
|
|
48
|
+
} else {
|
|
49
|
+
await fse.writeFile(".npmrc", "shamefully-hoist=true\nstrict-peer-dependencies=false\n");
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
} else {
|
|
53
|
+
const data = await loadConfig({
|
|
54
|
+
configFile: uiConfigFilename.replace(".ts", ""),
|
|
55
|
+
});
|
|
56
|
+
uiConfig = data.config as UIConfig;
|
|
57
|
+
}
|
|
58
|
+
if (_.isEmpty(uiConfig)) {
|
|
59
|
+
await getUIConfig({ force: true });
|
|
60
|
+
}
|
|
61
|
+
createConfigPaths(uiConfig);
|
|
62
|
+
return uiConfig;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export const createConfigPaths = (uiConfig: UIConfig) => {
|
|
66
|
+
// Esnure files exists
|
|
67
|
+
if (uiConfig.tailwindCSSLocation) fse.ensureFileSync(uiConfig.tailwindConfigLocation);
|
|
68
|
+
if (uiConfig.tailwindConfigLocation) fse.ensureFileSync(uiConfig.tailwindCSSLocation);
|
|
69
|
+
if (uiConfig.componentsLocation) fse.ensureDirSync(uiConfig.componentsLocation);
|
|
70
|
+
if (uiConfig.composablesLocation) fse.ensureDirSync(uiConfig.composablesLocation);
|
|
71
|
+
if (uiConfig.utilsLocation) fse.ensureDirSync(uiConfig.utilsLocation);
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
export const addModuleToConfig = (cfg: ProxifiedModule, modules: string[] | string) => {
|
|
75
|
+
if (typeof modules === "string") {
|
|
76
|
+
modules = [modules];
|
|
77
|
+
}
|
|
78
|
+
modules.forEach((m) => addNuxtModule(cfg, m));
|
|
79
|
+
return cfg;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
export const updateConfig = async (cfg: ProxifiedModule, fileName = "nuxt.config.ts") => {
|
|
83
|
+
await writeFile(cfg.$ast, fileName);
|
|
84
|
+
};
|
package/src/utils/constants.ts
CHANGED
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
export const INIT_DEPS = ["radix-vue", "tailwind-variants"];
|
|
2
|
-
export const INIT_DEV_DEPS = [
|
|
3
|
-
"typescript",
|
|
4
|
-
"tailwindcss-animate",
|
|
5
|
-
"nuxt-icon",
|
|
6
|
-
"nuxt-lodash",
|
|
7
|
-
"prettier-plugin-tailwindcss",
|
|
8
|
-
"prettier",
|
|
9
|
-
"@nuxtjs/tailwindcss",
|
|
10
|
-
"@nuxtjs/color-mode",
|
|
11
|
-
"@ianvs/prettier-plugin-sort-imports",
|
|
12
|
-
"@vueuse/nuxt",
|
|
13
|
-
];
|
|
14
|
-
|
|
15
|
-
export const INIT_MODULES = [
|
|
16
|
-
"@nuxtjs/tailwindcss",
|
|
17
|
-
"@nuxtjs/color-mode",
|
|
18
|
-
"@vueuse/nuxt",
|
|
19
|
-
"nuxt-lodash",
|
|
20
|
-
"nuxt-icon",
|
|
21
|
-
];
|
|
22
|
-
|
|
23
|
-
export const CSS_THEME_OPTIONS = [
|
|
24
|
-
{ title: "Zinc", value: "zinc" },
|
|
25
|
-
{ title: "Slate", value: "slate" },
|
|
26
|
-
{ title: "Stone", value: "stone" },
|
|
27
|
-
{ title: "Gray", value: "gray" },
|
|
28
|
-
{ title: "Neutral", value: "neutral" },
|
|
29
|
-
{ title: "Red", value: "red" },
|
|
30
|
-
{ title: "Rose", value: "rose" },
|
|
31
|
-
{ title: "Orange", value: "orange" },
|
|
32
|
-
{ title: "Green", value: "green" },
|
|
33
|
-
{ title: "Blue", value: "blue" },
|
|
34
|
-
{ title: "Yellow", value: "yellow" },
|
|
35
|
-
{ title: "Violet", value: "violet" },
|
|
36
|
-
];
|
|
1
|
+
export const INIT_DEPS = ["radix-vue", "tailwind-variants"];
|
|
2
|
+
export const INIT_DEV_DEPS = [
|
|
3
|
+
"typescript",
|
|
4
|
+
"tailwindcss-animate",
|
|
5
|
+
"nuxt-icon",
|
|
6
|
+
"nuxt-lodash",
|
|
7
|
+
"prettier-plugin-tailwindcss",
|
|
8
|
+
"prettier",
|
|
9
|
+
"@nuxtjs/tailwindcss",
|
|
10
|
+
"@nuxtjs/color-mode",
|
|
11
|
+
"@ianvs/prettier-plugin-sort-imports",
|
|
12
|
+
"@vueuse/nuxt",
|
|
13
|
+
];
|
|
14
|
+
|
|
15
|
+
export const INIT_MODULES = [
|
|
16
|
+
"@nuxtjs/tailwindcss",
|
|
17
|
+
"@nuxtjs/color-mode",
|
|
18
|
+
"@vueuse/nuxt",
|
|
19
|
+
"nuxt-lodash",
|
|
20
|
+
"nuxt-icon",
|
|
21
|
+
];
|
|
22
|
+
|
|
23
|
+
export const CSS_THEME_OPTIONS = [
|
|
24
|
+
{ title: "Zinc", value: "zinc" },
|
|
25
|
+
{ title: "Slate", value: "slate" },
|
|
26
|
+
{ title: "Stone", value: "stone" },
|
|
27
|
+
{ title: "Gray", value: "gray" },
|
|
28
|
+
{ title: "Neutral", value: "neutral" },
|
|
29
|
+
{ title: "Red", value: "red" },
|
|
30
|
+
{ title: "Rose", value: "rose" },
|
|
31
|
+
{ title: "Orange", value: "orange" },
|
|
32
|
+
{ title: "Green", value: "green" },
|
|
33
|
+
{ title: "Blue", value: "blue" },
|
|
34
|
+
{ title: "Yellow", value: "yellow" },
|
|
35
|
+
{ title: "Violet", value: "violet" },
|
|
36
|
+
];
|
package/src/utils/fileExists.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import fs from "node:fs";
|
|
2
|
-
|
|
3
|
-
export const fileExists = async (path: string) => {
|
|
4
|
-
try {
|
|
5
|
-
await fs.promises.access(path, fs.constants.F_OK || fs.constants.W_OK);
|
|
6
|
-
return true;
|
|
7
|
-
} catch (error) {
|
|
8
|
-
return false;
|
|
9
|
-
}
|
|
10
|
-
};
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
|
|
3
|
+
export const fileExists = async (path: string) => {
|
|
4
|
+
try {
|
|
5
|
+
await fs.promises.access(path, fs.constants.F_OK || fs.constants.W_OK);
|
|
6
|
+
return true;
|
|
7
|
+
} catch (error) {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
};
|