ui-thing 0.1.4 → 0.1.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/CHANGELOG.md +415 -399
- package/dist/index.js +1145 -1143
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/commands/add.ts +317 -317
- package/src/commands/init.ts +73 -73
- package/src/comps.ts +2421 -2421
- package/src/types.ts +35 -35
- package/src/utils/config.ts +100 -100
- package/src/utils/promptForComponents.ts +20 -20
package/src/types.ts
CHANGED
|
@@ -1,35 +1,35 @@
|
|
|
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; yes?: boolean };
|
|
14
|
-
|
|
15
|
-
export type Component = {
|
|
16
|
-
name: string;
|
|
17
|
-
value: string;
|
|
18
|
-
deps?: string[];
|
|
19
|
-
devDeps?: string[];
|
|
20
|
-
nuxtModules?: string[];
|
|
21
|
-
instructions?: string[];
|
|
22
|
-
files: Composable[];
|
|
23
|
-
utils: Composable[];
|
|
24
|
-
composables: Composable[];
|
|
25
|
-
plugins: Composable[];
|
|
26
|
-
components?: string[];
|
|
27
|
-
askValidator?: boolean;
|
|
28
|
-
overrides?: Record<string, any>;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
export type Composable = {
|
|
32
|
-
fileName: string;
|
|
33
|
-
dirPath: string;
|
|
34
|
-
fileContent: string;
|
|
35
|
-
};
|
|
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; yes?: boolean };
|
|
14
|
+
|
|
15
|
+
export type Component = {
|
|
16
|
+
name: string;
|
|
17
|
+
value: string;
|
|
18
|
+
deps?: string[];
|
|
19
|
+
devDeps?: string[];
|
|
20
|
+
nuxtModules?: string[];
|
|
21
|
+
instructions?: string[];
|
|
22
|
+
files: Composable[];
|
|
23
|
+
utils: Composable[];
|
|
24
|
+
composables: Composable[];
|
|
25
|
+
plugins: Composable[];
|
|
26
|
+
components?: string[];
|
|
27
|
+
askValidator?: boolean;
|
|
28
|
+
overrides?: Record<string, any>;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export type Composable = {
|
|
32
|
+
fileName: string;
|
|
33
|
+
dirPath: string;
|
|
34
|
+
fileContent: string;
|
|
35
|
+
};
|
package/src/utils/config.ts
CHANGED
|
@@ -1,100 +1,100 @@
|
|
|
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
|
-
const defaultConfig = {
|
|
16
|
-
theme: "zinc",
|
|
17
|
-
tailwindCSSLocation: "assets/css/tailwind.css",
|
|
18
|
-
tailwindConfigLocation: "tailwind.config.js",
|
|
19
|
-
componentsLocation: "components/Ui",
|
|
20
|
-
composablesLocation: "composables",
|
|
21
|
-
utilsLocation: "utils",
|
|
22
|
-
force: true,
|
|
23
|
-
useDefaultFilename: true,
|
|
24
|
-
packageManager: "npm",
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
export const getNuxtConfig = async () => {
|
|
28
|
-
if (!fse.existsSync("nuxt.config.ts")) {
|
|
29
|
-
console.log(kleur.red(`No ${kleur.bgWhite(`nuxt.config.ts`)} file found. Exiting...`));
|
|
30
|
-
return process.exit(0);
|
|
31
|
-
}
|
|
32
|
-
const nuxtConfig = await loadFile(join(currentDir, "nuxt.config.ts"));
|
|
33
|
-
const defaultExport = getDefaultExportOptions(nuxtConfig);
|
|
34
|
-
return { nuxtConfig, defaultExport };
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
export const getUIConfig = async (options?: InitOptions) => {
|
|
38
|
-
const configFileExists = fse.existsSync(uiConfigFilename);
|
|
39
|
-
let uiConfig: UIConfig = {} as UIConfig;
|
|
40
|
-
|
|
41
|
-
if (!configFileExists || options?.force) {
|
|
42
|
-
// if option yes is passed, use default values
|
|
43
|
-
if (options?.yes) {
|
|
44
|
-
uiConfig = defaultConfig;
|
|
45
|
-
} else {
|
|
46
|
-
uiConfig = await initPrompts();
|
|
47
|
-
}
|
|
48
|
-
await fse.writeFile(uiConfigFilename, `export default ${JSON.stringify(uiConfig, null, 2)}`);
|
|
49
|
-
// Check if user chose pnpm as package manager
|
|
50
|
-
if (uiConfig.packageManager === "pnpm") {
|
|
51
|
-
// check if a .npmrc file exists
|
|
52
|
-
const npmrcExists = fse.existsSync(".npmrc");
|
|
53
|
-
// as the user if they want to create a .npmrc file
|
|
54
|
-
if (npmrcExists) {
|
|
55
|
-
const { confirmCreateNpmrc } = await prompts({
|
|
56
|
-
type: "confirm",
|
|
57
|
-
name: "confirmCreateNpmrc",
|
|
58
|
-
message: "A .npmrc file already exists. Do you want to overwrite it?",
|
|
59
|
-
initial: false,
|
|
60
|
-
});
|
|
61
|
-
if (confirmCreateNpmrc) {
|
|
62
|
-
await fse.writeFile(".npmrc", "shamefully-hoist=true\nstrict-peer-dependencies=false\n");
|
|
63
|
-
}
|
|
64
|
-
} else {
|
|
65
|
-
await fse.writeFile(".npmrc", "shamefully-hoist=true\nstrict-peer-dependencies=false\n");
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
} else {
|
|
69
|
-
const data = await loadConfig({
|
|
70
|
-
configFile: uiConfigFilename.replace(".ts", ""),
|
|
71
|
-
});
|
|
72
|
-
uiConfig = data.config as UIConfig;
|
|
73
|
-
}
|
|
74
|
-
if (_.isEmpty(uiConfig)) {
|
|
75
|
-
await getUIConfig({ force: true });
|
|
76
|
-
}
|
|
77
|
-
createConfigPaths(uiConfig);
|
|
78
|
-
return uiConfig;
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
export const createConfigPaths = (uiConfig: UIConfig) => {
|
|
82
|
-
// Esnure files exists
|
|
83
|
-
if (uiConfig.tailwindCSSLocation) fse.ensureFileSync(uiConfig.tailwindConfigLocation);
|
|
84
|
-
if (uiConfig.tailwindConfigLocation) fse.ensureFileSync(uiConfig.tailwindCSSLocation);
|
|
85
|
-
if (uiConfig.componentsLocation) fse.ensureDirSync(uiConfig.componentsLocation);
|
|
86
|
-
if (uiConfig.composablesLocation) fse.ensureDirSync(uiConfig.composablesLocation);
|
|
87
|
-
if (uiConfig.utilsLocation) fse.ensureDirSync(uiConfig.utilsLocation);
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
export const addModuleToConfig = (cfg: ProxifiedModule, modules: string[] | string) => {
|
|
91
|
-
if (typeof modules === "string") {
|
|
92
|
-
modules = [modules];
|
|
93
|
-
}
|
|
94
|
-
modules.forEach((m) => addNuxtModule(cfg, m));
|
|
95
|
-
return cfg;
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
export const updateConfig = async (cfg: ProxifiedModule, fileName = "nuxt.config.ts") => {
|
|
99
|
-
await writeFile(cfg.$ast, fileName);
|
|
100
|
-
};
|
|
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
|
+
const defaultConfig = {
|
|
16
|
+
theme: "zinc",
|
|
17
|
+
tailwindCSSLocation: "assets/css/tailwind.css",
|
|
18
|
+
tailwindConfigLocation: "tailwind.config.js",
|
|
19
|
+
componentsLocation: "components/Ui",
|
|
20
|
+
composablesLocation: "composables",
|
|
21
|
+
utilsLocation: "utils",
|
|
22
|
+
force: true,
|
|
23
|
+
useDefaultFilename: true,
|
|
24
|
+
packageManager: "npm",
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export const getNuxtConfig = async () => {
|
|
28
|
+
if (!fse.existsSync("nuxt.config.ts")) {
|
|
29
|
+
console.log(kleur.red(`No ${kleur.bgWhite(`nuxt.config.ts`)} file found. Exiting...`));
|
|
30
|
+
return process.exit(0);
|
|
31
|
+
}
|
|
32
|
+
const nuxtConfig = await loadFile(join(currentDir, "nuxt.config.ts"));
|
|
33
|
+
const defaultExport = getDefaultExportOptions(nuxtConfig);
|
|
34
|
+
return { nuxtConfig, defaultExport };
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export const getUIConfig = async (options?: InitOptions) => {
|
|
38
|
+
const configFileExists = fse.existsSync(uiConfigFilename);
|
|
39
|
+
let uiConfig: UIConfig = {} as UIConfig;
|
|
40
|
+
|
|
41
|
+
if (!configFileExists || options?.force) {
|
|
42
|
+
// if option yes is passed, use default values
|
|
43
|
+
if (options?.yes) {
|
|
44
|
+
uiConfig = defaultConfig;
|
|
45
|
+
} else {
|
|
46
|
+
uiConfig = await initPrompts();
|
|
47
|
+
}
|
|
48
|
+
await fse.writeFile(uiConfigFilename, `export default ${JSON.stringify(uiConfig, null, 2)}`);
|
|
49
|
+
// Check if user chose pnpm as package manager
|
|
50
|
+
if (uiConfig.packageManager === "pnpm") {
|
|
51
|
+
// check if a .npmrc file exists
|
|
52
|
+
const npmrcExists = fse.existsSync(".npmrc");
|
|
53
|
+
// as the user if they want to create a .npmrc file
|
|
54
|
+
if (npmrcExists) {
|
|
55
|
+
const { confirmCreateNpmrc } = await prompts({
|
|
56
|
+
type: "confirm",
|
|
57
|
+
name: "confirmCreateNpmrc",
|
|
58
|
+
message: "A .npmrc file already exists. Do you want to overwrite it?",
|
|
59
|
+
initial: false,
|
|
60
|
+
});
|
|
61
|
+
if (confirmCreateNpmrc) {
|
|
62
|
+
await fse.writeFile(".npmrc", "shamefully-hoist=true\nstrict-peer-dependencies=false\n");
|
|
63
|
+
}
|
|
64
|
+
} else {
|
|
65
|
+
await fse.writeFile(".npmrc", "shamefully-hoist=true\nstrict-peer-dependencies=false\n");
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
} else {
|
|
69
|
+
const data = await loadConfig({
|
|
70
|
+
configFile: uiConfigFilename.replace(".ts", ""),
|
|
71
|
+
});
|
|
72
|
+
uiConfig = data.config as UIConfig;
|
|
73
|
+
}
|
|
74
|
+
if (_.isEmpty(uiConfig)) {
|
|
75
|
+
await getUIConfig({ force: true });
|
|
76
|
+
}
|
|
77
|
+
createConfigPaths(uiConfig);
|
|
78
|
+
return uiConfig;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
export const createConfigPaths = (uiConfig: UIConfig) => {
|
|
82
|
+
// Esnure files exists
|
|
83
|
+
if (uiConfig.tailwindCSSLocation) fse.ensureFileSync(uiConfig.tailwindConfigLocation);
|
|
84
|
+
if (uiConfig.tailwindConfigLocation) fse.ensureFileSync(uiConfig.tailwindCSSLocation);
|
|
85
|
+
if (uiConfig.componentsLocation) fse.ensureDirSync(uiConfig.componentsLocation);
|
|
86
|
+
if (uiConfig.composablesLocation) fse.ensureDirSync(uiConfig.composablesLocation);
|
|
87
|
+
if (uiConfig.utilsLocation) fse.ensureDirSync(uiConfig.utilsLocation);
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
export const addModuleToConfig = (cfg: ProxifiedModule, modules: string[] | string) => {
|
|
91
|
+
if (typeof modules === "string") {
|
|
92
|
+
modules = [modules];
|
|
93
|
+
}
|
|
94
|
+
modules.forEach((m) => addNuxtModule(cfg, m));
|
|
95
|
+
return cfg;
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
export const updateConfig = async (cfg: ProxifiedModule, fileName = "nuxt.config.ts") => {
|
|
99
|
+
await writeFile(cfg.$ast, fileName);
|
|
100
|
+
};
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import prompts from "prompts";
|
|
2
|
-
|
|
3
|
-
import allComponents from "../comps";
|
|
4
|
-
import { Component } from "../types";
|
|
5
|
-
|
|
6
|
-
export const promptUserForComponents = async (all?: boolean): Promise<string[]> => {
|
|
7
|
-
// If all is true, return all components
|
|
8
|
-
if (all) return allComponents.map((c: Component) => c.value);
|
|
9
|
-
const { components } = await prompts({
|
|
10
|
-
type: "autocompleteMultiselect",
|
|
11
|
-
name: "components",
|
|
12
|
-
message: "Select the components you want to add",
|
|
13
|
-
choices: allComponents.map((c: Component) => ({ title: c.name, value: c.value })),
|
|
14
|
-
onRender(kleur) {
|
|
15
|
-
// @ts-ignore
|
|
16
|
-
this.msg = kleur.bgCyan(" Choose components ") + " Select the components you want to add";
|
|
17
|
-
},
|
|
18
|
-
});
|
|
19
|
-
return components;
|
|
20
|
-
};
|
|
1
|
+
import prompts from "prompts";
|
|
2
|
+
|
|
3
|
+
import allComponents from "../comps";
|
|
4
|
+
import { Component } from "../types";
|
|
5
|
+
|
|
6
|
+
export const promptUserForComponents = async (all?: boolean): Promise<string[]> => {
|
|
7
|
+
// If all is true, return all components
|
|
8
|
+
if (all) return allComponents.map((c: Component) => c.value);
|
|
9
|
+
const { components } = await prompts({
|
|
10
|
+
type: "autocompleteMultiselect",
|
|
11
|
+
name: "components",
|
|
12
|
+
message: "Select the components you want to add",
|
|
13
|
+
choices: allComponents.map((c: Component) => ({ title: c.name, value: c.value })),
|
|
14
|
+
onRender(kleur) {
|
|
15
|
+
// @ts-ignore
|
|
16
|
+
this.msg = kleur.bgCyan(" Choose components ") + " Select the components you want to add";
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
return components;
|
|
20
|
+
};
|