@metacells/mcellui-cli 0.2.0 → 0.2.1
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 +40 -3
- package/package.json +1 -1
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,14 @@ 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
|
+
console.log(chalk4.dim(` Import: import { ${pascalName} } from '${config.alias}/components/${componentName}';`));
|
|
1006
|
+
}
|
|
998
1007
|
if (component.dependencies?.length) {
|
|
999
1008
|
allDependencies.push(...component.dependencies);
|
|
1000
1009
|
}
|
|
@@ -1010,6 +1019,10 @@ var addCommand = new Command2().name("add").description("Add a component to your
|
|
|
1010
1019
|
if (failCount > 0) {
|
|
1011
1020
|
process.exit(1);
|
|
1012
1021
|
}
|
|
1022
|
+
if (options.barrel !== false) {
|
|
1023
|
+
const targetDir = path5.join(projectRoot, config.componentsPath);
|
|
1024
|
+
await generateBarrelFile(targetDir);
|
|
1025
|
+
}
|
|
1013
1026
|
const uniqueDeps = [...new Set(allDependencies)];
|
|
1014
1027
|
const uniqueDevDeps = [...new Set(allDevDependencies)];
|
|
1015
1028
|
if (uniqueDeps.length || uniqueDevDeps.length) {
|
|
@@ -1032,6 +1045,30 @@ var addCommand = new Command2().name("add").description("Add a component to your
|
|
|
1032
1045
|
});
|
|
1033
1046
|
}
|
|
1034
1047
|
});
|
|
1048
|
+
async function generateBarrelFile(componentsDir) {
|
|
1049
|
+
if (!await fs5.pathExists(componentsDir)) {
|
|
1050
|
+
return;
|
|
1051
|
+
}
|
|
1052
|
+
const files = await fs5.readdir(componentsDir);
|
|
1053
|
+
const componentFiles = files.filter((file) => (file.endsWith(".tsx") || file.endsWith(".ts")) && file !== "index.ts" && file !== "index.tsx").sort();
|
|
1054
|
+
if (componentFiles.length === 0) {
|
|
1055
|
+
return;
|
|
1056
|
+
}
|
|
1057
|
+
const exports = componentFiles.map((file) => {
|
|
1058
|
+
const name = file.replace(/\.tsx?$/, "");
|
|
1059
|
+
return `export * from './${name}';`;
|
|
1060
|
+
}).join("\n");
|
|
1061
|
+
const content = `// Auto-generated barrel file - do not edit manually
|
|
1062
|
+
// Re-run \`npx mcellui add\` to regenerate
|
|
1063
|
+
|
|
1064
|
+
${exports}
|
|
1065
|
+
`;
|
|
1066
|
+
const indexPath = path5.join(componentsDir, "index.ts");
|
|
1067
|
+
await fs5.writeFile(indexPath, content);
|
|
1068
|
+
}
|
|
1069
|
+
function toPascalCase(str) {
|
|
1070
|
+
return str.split("-").map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join("");
|
|
1071
|
+
}
|
|
1035
1072
|
|
|
1036
1073
|
// src/commands/list.ts
|
|
1037
1074
|
import { Command as Command3 } from "commander";
|
|
@@ -2064,7 +2101,7 @@ var createCommand = new Command7().name("create").description("Scaffold a new cu
|
|
|
2064
2101
|
if (!config) {
|
|
2065
2102
|
errors.notInitialized();
|
|
2066
2103
|
}
|
|
2067
|
-
const componentName =
|
|
2104
|
+
const componentName = toPascalCase2(name);
|
|
2068
2105
|
const fileName = toKebabCase(name) + ".tsx";
|
|
2069
2106
|
const targetDir = path10.join(projectRoot, config.componentsPath);
|
|
2070
2107
|
const targetPath = path10.join(targetDir, fileName);
|
|
@@ -2117,7 +2154,7 @@ var createCommand = new Command7().name("create").description("Scaffold a new cu
|
|
|
2117
2154
|
});
|
|
2118
2155
|
}
|
|
2119
2156
|
});
|
|
2120
|
-
function
|
|
2157
|
+
function toPascalCase2(str) {
|
|
2121
2158
|
return str.replace(/[-_\s]+(.)?/g, (_, c) => c ? c.toUpperCase() : "").replace(/^(.)/, (c) => c.toUpperCase());
|
|
2122
2159
|
}
|
|
2123
2160
|
function toKebabCase(str) {
|