@wato787/microcms-cli 0.1.0 → 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.
- package/README.md +1 -0
- package/dist/commands/gen-types/config.js +6 -2
- package/dist/index.js +18 -1
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -64,6 +64,7 @@ microcms-cli gen-types blog
|
|
|
64
64
|
#### Required environment variables
|
|
65
65
|
|
|
66
66
|
`gen-types` は **実行した利用者の環境変数** から設定を読み取ります。
|
|
67
|
+
カレントディレクトリの `.env` と `.env.local` を自動で読み込みます(`.env.local` は後から読み込むため、同名の変数を上書きします)。[dotenv](https://github.com/motdotla/dotenv) 使用。
|
|
67
68
|
CLI引数で指定しない場合、以下の環境変数が必要です。
|
|
68
69
|
|
|
69
70
|
```bash
|
|
@@ -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
|
-
|
|
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
|
-
|
|
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,11 +1,28 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import dotenv from 'dotenv';
|
|
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;
|
|
2
19
|
import { Command } from 'commander';
|
|
3
20
|
import { genTypesCommand } from './commands/gen-types/index.js';
|
|
4
21
|
const program = new Command();
|
|
5
22
|
program
|
|
6
23
|
.name('microcms-cli')
|
|
7
24
|
.description('CLI for microCMS')
|
|
8
|
-
.version('0.1.
|
|
25
|
+
.version('0.1.2');
|
|
9
26
|
program
|
|
10
27
|
.command('gen-types [endpointId]')
|
|
11
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.
|
|
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",
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"commander": "^12.0.0",
|
|
27
|
+
"dotenv": "^17.3.1",
|
|
27
28
|
"picocolors": "^1.0.0"
|
|
28
29
|
},
|
|
29
30
|
"devDependencies": {
|