@wato787/microcms-cli 0.1.1 → 0.1.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.
@@ -16,12 +16,16 @@ export function resolveConfig(options) {
16
16
  const serviceDomain = toStringValue(options.serviceDomain) ??
17
17
  toStringValue(process.env.MICROCMS_SERVICE_DOMAIN);
18
18
  if (!serviceDomain) {
19
- throw new Error('MICROCMS_SERVICE_DOMAIN is required. You can also pass --service-domain.');
19
+ const envDir = process.env.__MICROCMS_CLI_ENV_DIR ?? process.cwd();
20
+ throw new Error('MICROCMS_SERVICE_DOMAIN is required. You can also pass --service-domain.\n' +
21
+ `(Searched for .env / .env.local in: ${envDir}. CWD: ${process.cwd()})`);
20
22
  }
21
23
  const apiKey = toStringValue(options.apiKey) ??
22
24
  toStringValue(process.env.MICROCMS_MANAGEMENT_API_KEY);
23
25
  if (!apiKey) {
24
- throw new Error('MICROCMS_MANAGEMENT_API_KEY is required. You can also pass --api-key.');
26
+ const envDir = process.env.__MICROCMS_CLI_ENV_DIR ?? process.cwd();
27
+ throw new Error('MICROCMS_MANAGEMENT_API_KEY is required. You can also pass --api-key.\n' +
28
+ `(Searched for .env / .env.local in: ${envDir}. CWD: ${process.cwd()})`);
25
29
  }
26
30
  return { serviceDomain, apiKey };
27
31
  }
package/dist/index.js CHANGED
@@ -1,15 +1,28 @@
1
1
  #!/usr/bin/env node
2
+ import fs from 'node:fs';
2
3
  import path from 'node:path';
3
4
  import dotenv from 'dotenv';
4
- dotenv.config();
5
- dotenv.config({ path: path.resolve(process.cwd(), '.env.local') });
5
+ function findEnvDir(dir) {
6
+ const parent = path.dirname(dir);
7
+ if (dir === parent)
8
+ return null;
9
+ const env = path.join(dir, '.env');
10
+ const envLocal = path.join(dir, '.env.local');
11
+ if (fs.existsSync(env) || fs.existsSync(envLocal))
12
+ return dir;
13
+ return findEnvDir(parent);
14
+ }
15
+ const envDir = findEnvDir(process.cwd()) ?? process.cwd();
16
+ dotenv.config({ path: path.join(envDir, '.env') });
17
+ dotenv.config({ path: path.join(envDir, '.env.local') });
18
+ process.env.__MICROCMS_CLI_ENV_DIR = envDir;
6
19
  import { Command } from 'commander';
7
20
  import { genTypesCommand } from './commands/gen-types/index.js';
8
21
  const program = new Command();
9
22
  program
10
23
  .name('microcms-cli')
11
24
  .description('CLI for microCMS')
12
- .version('0.1.1');
25
+ .version('0.1.2');
13
26
  program
14
27
  .command('gen-types [endpointId]')
15
28
  .description('Fetch API schema from microCMS Management API and generate TypeScript types')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wato787/microcms-cli",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "AI-friendly CLI tool for microCMS, built with Bun",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",