Browse Source

fix(cli): Fix package location in monorepos

Michael Bromley 3 months ago
parent
commit
39fce1c017

+ 1 - 1
packages/cli/src/commands/schema/generate-schema/generate-schema.ts

@@ -28,7 +28,7 @@ export async function generateSchema(options: SchemaOptions) {
         const config = await loadVendureConfigFile(vendureConfig, tsConfigPath);
         await setConfig(config);
 
-        const apiType = options.api === 'admin' ? 'admin' : 'shop';
+        const apiType = options.api === 'shop' ? 'shop' : 'admin';
 
         const runtimeConfig = await runPluginConfigurations(getConfig() as any);
         const typesLoader = new GraphQLTypesLoader();

+ 2 - 2
packages/cli/src/commands/schema/schema.ts

@@ -6,7 +6,7 @@ import { withInteractiveTimeout } from '../../utilities/utils';
 const cancelledMessage = 'Schema generation cancelled.';
 
 export interface SchemaOptions {
-    api: 'admin' | 'shop';
+    api?: 'admin' | 'shop';
     format?: 'sdl' | 'json';
     fileName?: string;
     outputDir?: string;
@@ -18,7 +18,7 @@ export interface SchemaOptions {
  */
 export async function schemaCommand(options?: SchemaOptions) {
     // Check if any non-interactive options are provided
-    if (options?.api) {
+    if (options) {
         // Non-interactive mode
         await handleNonInteractiveMode(options);
         return;

+ 7 - 5
packages/cli/src/shared/package-json-ref.ts

@@ -125,11 +125,13 @@ export class PackageJson {
         for (const dir of potentialMonorepoDirs) {
             const monorepoDir = path.join(rootDir, dir);
             // Check for a package.json in all subdirs
-            for (const subDir of fs.readdirSync(monorepoDir)) {
-                const packageJsonPath = path.join(monorepoDir, subDir, 'package.json');
-                if (this.hasVendureDependency(packageJsonPath)) {
-                    this._vendurePackageJsonPath = packageJsonPath;
-                    return packageJsonPath;
+            if (fs.existsSync(monorepoDir)) {
+                for (const subDir of fs.readdirSync(monorepoDir)) {
+                    const packageJsonPath = path.join(monorepoDir, subDir, 'package.json');
+                    if (this.hasVendureDependency(packageJsonPath)) {
+                        this._vendurePackageJsonPath = packageJsonPath;
+                        return packageJsonPath;
+                    }
                 }
             }
         }