@metacells/mcellui-cli 0.2.0 → 0.2.2
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/index.js +41 -3
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -883,7 +883,7 @@ function getInstalledNames(installedFiles) {
|
|
|
883
883
|
}
|
|
884
884
|
|
|
885
885
|
// src/commands/add.ts
|
|
886
|
-
var addCommand = new Command2().name("add").description("Add a component to your project").argument("[components...]", "Components to add").option("-y, --yes", "Skip confirmation").option("-o, --overwrite", "Overwrite existing files").option("--cwd <path>", "Working directory", process.cwd()).action(async (components, options) => {
|
|
886
|
+
var addCommand = new Command2().name("add").description("Add a component to your project").argument("[components...]", "Components to add").option("-y, --yes", "Skip confirmation").option("-o, --overwrite", "Overwrite existing files").option("--no-barrel", "Skip index.ts barrel file generation").option("--cwd <path>", "Working directory", process.cwd()).action(async (components, options) => {
|
|
887
887
|
const spinner = ora2();
|
|
888
888
|
try {
|
|
889
889
|
const cwd = path5.resolve(options.cwd);
|
|
@@ -974,6 +974,7 @@ var addCommand = new Command2().name("add").description("Add a component to your
|
|
|
974
974
|
const allDependencies = [];
|
|
975
975
|
const allDevDependencies = [];
|
|
976
976
|
let failCount = 0;
|
|
977
|
+
const registryMap = new Map(registry.map((item) => [item.name, item]));
|
|
977
978
|
for (const componentName of toInstall) {
|
|
978
979
|
spinner.start(`Fetching ${componentName}...`);
|
|
979
980
|
try {
|
|
@@ -995,6 +996,15 @@ var addCommand = new Command2().name("add").description("Add a component to your
|
|
|
995
996
|
await fs5.writeFile(targetPath, transformedContent);
|
|
996
997
|
}
|
|
997
998
|
spinner.succeed(`Added ${componentName}`);
|
|
999
|
+
if (requested.has(componentName)) {
|
|
1000
|
+
const registryItem = registryMap.get(componentName);
|
|
1001
|
+
if (registryItem?.props?.length) {
|
|
1002
|
+
console.log(chalk4.dim(` Props: ${registryItem.props.join(", ")}`));
|
|
1003
|
+
}
|
|
1004
|
+
const pascalName = toPascalCase(componentName);
|
|
1005
|
+
const importPath = config.aliases.components || "@/components";
|
|
1006
|
+
console.log(chalk4.dim(` Import: import { ${pascalName} } from '${importPath}/${componentName}';`));
|
|
1007
|
+
}
|
|
998
1008
|
if (component.dependencies?.length) {
|
|
999
1009
|
allDependencies.push(...component.dependencies);
|
|
1000
1010
|
}
|
|
@@ -1010,6 +1020,10 @@ var addCommand = new Command2().name("add").description("Add a component to your
|
|
|
1010
1020
|
if (failCount > 0) {
|
|
1011
1021
|
process.exit(1);
|
|
1012
1022
|
}
|
|
1023
|
+
if (options.barrel !== false) {
|
|
1024
|
+
const targetDir = path5.join(projectRoot, config.componentsPath);
|
|
1025
|
+
await generateBarrelFile(targetDir);
|
|
1026
|
+
}
|
|
1013
1027
|
const uniqueDeps = [...new Set(allDependencies)];
|
|
1014
1028
|
const uniqueDevDeps = [...new Set(allDevDependencies)];
|
|
1015
1029
|
if (uniqueDeps.length || uniqueDevDeps.length) {
|
|
@@ -1032,6 +1046,30 @@ var addCommand = new Command2().name("add").description("Add a component to your
|
|
|
1032
1046
|
});
|
|
1033
1047
|
}
|
|
1034
1048
|
});
|
|
1049
|
+
async function generateBarrelFile(componentsDir) {
|
|
1050
|
+
if (!await fs5.pathExists(componentsDir)) {
|
|
1051
|
+
return;
|
|
1052
|
+
}
|
|
1053
|
+
const files = await fs5.readdir(componentsDir);
|
|
1054
|
+
const componentFiles = files.filter((file) => (file.endsWith(".tsx") || file.endsWith(".ts")) && file !== "index.ts" && file !== "index.tsx").sort();
|
|
1055
|
+
if (componentFiles.length === 0) {
|
|
1056
|
+
return;
|
|
1057
|
+
}
|
|
1058
|
+
const exports = componentFiles.map((file) => {
|
|
1059
|
+
const name = file.replace(/\.tsx?$/, "");
|
|
1060
|
+
return `export * from './${name}';`;
|
|
1061
|
+
}).join("\n");
|
|
1062
|
+
const content = `// Auto-generated barrel file - do not edit manually
|
|
1063
|
+
// Re-run \`npx mcellui add\` to regenerate
|
|
1064
|
+
|
|
1065
|
+
${exports}
|
|
1066
|
+
`;
|
|
1067
|
+
const indexPath = path5.join(componentsDir, "index.ts");
|
|
1068
|
+
await fs5.writeFile(indexPath, content);
|
|
1069
|
+
}
|
|
1070
|
+
function toPascalCase(str) {
|
|
1071
|
+
return str.split("-").map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join("");
|
|
1072
|
+
}
|
|
1035
1073
|
|
|
1036
1074
|
// src/commands/list.ts
|
|
1037
1075
|
import { Command as Command3 } from "commander";
|
|
@@ -2064,7 +2102,7 @@ var createCommand = new Command7().name("create").description("Scaffold a new cu
|
|
|
2064
2102
|
if (!config) {
|
|
2065
2103
|
errors.notInitialized();
|
|
2066
2104
|
}
|
|
2067
|
-
const componentName =
|
|
2105
|
+
const componentName = toPascalCase2(name);
|
|
2068
2106
|
const fileName = toKebabCase(name) + ".tsx";
|
|
2069
2107
|
const targetDir = path10.join(projectRoot, config.componentsPath);
|
|
2070
2108
|
const targetPath = path10.join(targetDir, fileName);
|
|
@@ -2117,7 +2155,7 @@ var createCommand = new Command7().name("create").description("Scaffold a new cu
|
|
|
2117
2155
|
});
|
|
2118
2156
|
}
|
|
2119
2157
|
});
|
|
2120
|
-
function
|
|
2158
|
+
function toPascalCase2(str) {
|
|
2121
2159
|
return str.replace(/[-_\s]+(.)?/g, (_, c) => c ? c.toUpperCase() : "").replace(/^(.)/, (c) => c.toUpperCase());
|
|
2122
2160
|
}
|
|
2123
2161
|
function toKebabCase(str) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metacells/mcellui-cli",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "CLI for mcellui - add beautiful, accessible UI components to your Expo/React Native project",
|
|
5
5
|
"author": "metacells",
|
|
6
6
|
"license": "MIT",
|
|
@@ -49,15 +49,15 @@
|
|
|
49
49
|
"lint": "eslint src/"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"commander": "^12.0.0",
|
|
53
52
|
"chalk": "^5.3.0",
|
|
53
|
+
"commander": "^12.0.0",
|
|
54
|
+
"detect-indent": "^7.0.1",
|
|
54
55
|
"diff": "^7.0.0",
|
|
55
|
-
"ora": "^8.0.0",
|
|
56
|
-
"prompts": "^2.4.2",
|
|
57
56
|
"fs-extra": "^11.2.0",
|
|
58
57
|
"glob": "^10.3.0",
|
|
59
|
-
"detect-indent": "^7.0.1",
|
|
60
58
|
"jiti": "^1.21.0",
|
|
59
|
+
"ora": "^8.0.0",
|
|
60
|
+
"prompts": "^2.4.2",
|
|
61
61
|
"zod": "^3.23.0"
|
|
62
62
|
},
|
|
63
63
|
"devDependencies": {
|