|
@@ -1,30 +1,31 @@
|
|
|
-#!/usr/bin/env node
|
|
|
|
|
|
|
+#!/usr/bin/env -S npx tsx@latest
|
|
|
|
|
|
|
|
-import chalk from 'chalk';
|
|
|
|
|
-import { Command } from 'commander';
|
|
|
|
|
import inquirer from 'inquirer';
|
|
import inquirer from 'inquirer';
|
|
|
|
|
+import { Command } from 'commander';
|
|
|
|
|
+import chalk from 'chalk';
|
|
|
|
|
|
|
|
-import { bfsMaterials, copyMaterial, listAllMaterials } from './materials.js';
|
|
|
|
|
-import { getProjectInfo, installDependencies } from './project.js';
|
|
|
|
|
|
|
+import { getProjectInfo, installDependencies, ProjectInfo } from './project.js';
|
|
|
|
|
+import { bfsMaterials, copyMaterial, listAllMaterials, Material } from './materials.js';
|
|
|
|
|
|
|
|
const program = new Command();
|
|
const program = new Command();
|
|
|
|
|
|
|
|
program
|
|
program
|
|
|
- .version('1.0.0')
|
|
|
|
|
|
|
+ .version('1.0.1')
|
|
|
.description('Add official materials to your project')
|
|
.description('Add official materials to your project')
|
|
|
.argument('[materialName]', 'Optional material name to skip selection (format: type/name)')
|
|
.argument('[materialName]', 'Optional material name to skip selection (format: type/name)')
|
|
|
- .action(async (materialName) => {
|
|
|
|
|
|
|
+ .action(async (materialName?: string) => {
|
|
|
|
|
+ // materialName can be undefined
|
|
|
console.log(chalk.bgGreenBright('Welcome to @flowgram.ai/form-materials CLI!'));
|
|
console.log(chalk.bgGreenBright('Welcome to @flowgram.ai/form-materials CLI!'));
|
|
|
|
|
|
|
|
- const projectInfo = getProjectInfo();
|
|
|
|
|
|
|
+ const projectInfo: ProjectInfo = getProjectInfo();
|
|
|
|
|
|
|
|
console.log(chalk.bold('Project Info:'));
|
|
console.log(chalk.bold('Project Info:'));
|
|
|
console.log(chalk.black(` - Flowgram Version: ${projectInfo.flowgramVersion}`));
|
|
console.log(chalk.black(` - Flowgram Version: ${projectInfo.flowgramVersion}`));
|
|
|
console.log(chalk.black(` - Project Path: ${projectInfo.projectPath}`));
|
|
console.log(chalk.black(` - Project Path: ${projectInfo.projectPath}`));
|
|
|
|
|
|
|
|
- const materials = listAllMaterials();
|
|
|
|
|
|
|
+ const materials: Material[] = listAllMaterials();
|
|
|
|
|
|
|
|
- let material;
|
|
|
|
|
|
|
+ let material: Material | undefined; // material can be undefined
|
|
|
|
|
|
|
|
// Check if materialName is provided and exists in materials
|
|
// Check if materialName is provided and exists in materials
|
|
|
if (materialName) {
|
|
if (materialName) {
|
|
@@ -42,7 +43,9 @@ program
|
|
|
// If material not found or materialName not provided, prompt user to select
|
|
// If material not found or materialName not provided, prompt user to select
|
|
|
if (!material) {
|
|
if (!material) {
|
|
|
// User select one component
|
|
// User select one component
|
|
|
- const result = await inquirer.prompt([
|
|
|
|
|
|
|
+ const result = await inquirer.prompt<{
|
|
|
|
|
+ material: Material; // Specify type for prompt result
|
|
|
|
|
+ }>([
|
|
|
{
|
|
{
|
|
|
type: 'list',
|
|
type: 'list',
|
|
|
name: 'material',
|
|
name: 'material',
|
|
@@ -57,18 +60,23 @@ program
|
|
|
]);
|
|
]);
|
|
|
material = result.material;
|
|
material = result.material;
|
|
|
}
|
|
}
|
|
|
|
|
+ // Ensure material is defined before proceeding
|
|
|
|
|
+ if (!material) {
|
|
|
|
|
+ console.error(chalk.red('No material selected. Exiting.'));
|
|
|
|
|
+ process.exit(1);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
console.log(material);
|
|
console.log(material);
|
|
|
|
|
|
|
|
// 3. Get the component dependencies by BFS (include depMaterials and depPackages)
|
|
// 3. Get the component dependencies by BFS (include depMaterials and depPackages)
|
|
|
- const { allMaterials, allPackages } = bfsMaterials(material, materials);
|
|
|
|
|
|
|
+ const { allMaterials, allPackages } = bfsMaterials(material!, materials);
|
|
|
|
|
|
|
|
// 4. Install the dependencies
|
|
// 4. Install the dependencies
|
|
|
let flowgramPackage = `@flowgram.ai/editor`;
|
|
let flowgramPackage = `@flowgram.ai/editor`;
|
|
|
if (projectInfo.flowgramVersion !== 'workspace:*') {
|
|
if (projectInfo.flowgramVersion !== 'workspace:*') {
|
|
|
flowgramPackage = `@flowgram.ai/editor@${projectInfo.flowgramVersion}`;
|
|
flowgramPackage = `@flowgram.ai/editor@${projectInfo.flowgramVersion}`;
|
|
|
}
|
|
}
|
|
|
- const packagesToInstall = [flowgramPackage, ...allPackages];
|
|
|
|
|
|
|
+ const packagesToInstall: string[] = [flowgramPackage, ...allPackages];
|
|
|
|
|
|
|
|
console.log(chalk.bold('These npm dependencies will be added to your project'));
|
|
console.log(chalk.bold('These npm dependencies will be added to your project'));
|
|
|
console.log(packagesToInstall);
|
|
console.log(packagesToInstall);
|
|
@@ -77,8 +85,9 @@ program
|
|
|
// 5. Copy the materials to the project
|
|
// 5. Copy the materials to the project
|
|
|
console.log(chalk.bold('These Materials will be added to your project'));
|
|
console.log(chalk.bold('These Materials will be added to your project'));
|
|
|
console.log(allMaterials);
|
|
console.log(allMaterials);
|
|
|
- allMaterials.forEach((material) => {
|
|
|
|
|
- copyMaterial(material, projectInfo);
|
|
|
|
|
|
|
+ allMaterials.forEach((mat: Material) => {
|
|
|
|
|
+ // Add type for mat
|
|
|
|
|
+ copyMaterial(mat, projectInfo);
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
|
|
|