apiskill 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/dist/index.html CHANGED
@@ -4,8 +4,8 @@
4
4
  <meta charset="UTF-8" />
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
6
  <title>API Skill Console</title>
7
- <script type="module" crossorigin src="/assets/index-DH0wsJCI.js"></script>
8
- <link rel="stylesheet" crossorigin href="/assets/index-vocUDpcf.css">
7
+ <script type="module" crossorigin src="/assets/index-CPxVZ06Y.js"></script>
8
+ <link rel="stylesheet" crossorigin href="/assets/index-BeAJ1G-n.css">
9
9
  </head>
10
10
  <body>
11
11
  <div id="root"></div>
package/docs/cli.md CHANGED
@@ -12,7 +12,7 @@ apiskill --help
12
12
  apiskill run web
13
13
  ```
14
14
 
15
- `apiskill run web` starts the web console and writes cache data to `cache/` under the current directory by default. Use `--port`, `--host`, `--cwd`, or `--cache-dir` to adjust startup paths:
15
+ `apiskill run web` starts the web console and writes cache data to the user-writable `~/.apiskill/cache` directory by default. `--cwd` uses `<cwd>/cache`; `--cache-dir` selects an explicit location:
16
16
 
17
17
  ```bash
18
18
  apiskill run web --port 8890
package/docs/cli.zh.md CHANGED
@@ -12,7 +12,7 @@ apiskill --help
12
12
  apiskill run web
13
13
  ```
14
14
 
15
- `apiskill run web` 会启动 Web 控制台,默认把缓存写入当前目录的 `cache/`。可以用 `--port`、`--host`、`--cwd` 或 `--cache-dir` 调整启动参数:
15
+ `apiskill run web` 会启动 Web 控制台,默认把缓存写入用户可写的 `~/.apiskill/cache`。使用 `--cwd` 时缓存位于 `<cwd>/cache`,也可以用 `--cache-dir` 指定其他目录:
16
16
 
17
17
  ```bash
18
18
  apiskill run web --port 8890
package/docs/web.md CHANGED
@@ -11,7 +11,7 @@ npm install -g apiskill
11
11
  apiskill run web
12
12
  ```
13
13
 
14
- The default cache directory is `cache/` under the current directory. When developing this repository, you can also use:
14
+ Global npm installations use the user-writable `~/.apiskill/cache` directory by default. Use `--cwd` for a project-local `<cwd>/cache`, or `--cache-dir` for an explicit path. When developing this repository, you can also use:
15
15
 
16
16
  ```bash
17
17
  npm install
package/docs/web.zh.md CHANGED
@@ -11,7 +11,7 @@ npm install -g apiskill
11
11
  apiskill run web
12
12
  ```
13
13
 
14
- 默认缓存目录是当前目录下的 `cache/`。开发本仓库时也可以使用:
14
+ 通过 npm 全局安装时,默认缓存目录是用户可写的 `~/.apiskill/cache`。使用 `--cwd` 可切换为项目目录下的 `<cwd>/cache`,使用 `--cache-dir` 可指定其他位置。开发本仓库时也可以使用:
15
15
 
16
16
  ```bash
17
17
  npm install
@@ -22,7 +22,7 @@ npm run dev
22
22
 
23
23
  ## 导入来源
24
24
 
25
- Web 端支持四种导入方式:
25
+ “新建文档”弹窗通过 Tab 支持空白文档和四种导入方式:
26
26
 
27
27
  - 直接导入 OpenAPI/Swagger JSON 或 YAML 地址。
28
28
  - 爬取 Swagger UI、Knife4j、Redoc 页面。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apiskill",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "src",
@@ -19,14 +19,17 @@ import {
19
19
  import { crawlOpenApi, importFromCurl, importFromLocalFile, importFromUrl } from './lib/openapi-importer.mjs';
20
20
  import { checkCache, formatCheckText, queryEndpoints } from './lib/apiskill-core.mjs';
21
21
  import { startMockServer } from './lib/mock-server.mjs';
22
+ import { getDefaultCacheDir } from './lib/cache-paths.mjs';
22
23
 
23
24
  const program = new Command();
24
25
  const packageRoot = resolve(dirname(fileURLToPath(import.meta.url)), '..');
26
+ const packageJson = JSON.parse(await readFile(resolve(packageRoot, 'package.json'), 'utf8'));
27
+ const cliVersion = typeof packageJson.version === 'string' ? packageJson.version : '0.0.0';
25
28
 
26
29
  program
27
30
  .name('apiskill')
28
31
  .description('API Skill CLI: import OpenAPI docs and create/query/edit/delete local API configs.')
29
- .version('0.1.0', '-V, --cli-version', 'Print CLI version')
32
+ .version(cliVersion, '-V, --cli-version', 'Print CLI version')
30
33
  .showHelpAfterError()
31
34
  .addHelpText(
32
35
  'after',
@@ -64,8 +67,8 @@ run
64
67
  .option('-p, --port <number>', 'Web server port', '8888')
65
68
  .option('--host <host>', 'Host to bind', '127.0.0.1')
66
69
  .option('--strict-port', 'Fail if the requested port is already in use')
67
- .option('--cwd <dir>', 'Project directory used for the default cache location')
68
- .option('--cache-dir <dir>', 'Cache directory. Defaults to <cwd>/cache')
70
+ .option('--cwd <dir>', 'Project directory. Uses <cwd>/cache unless --cache-dir is provided')
71
+ .option('--cache-dir <dir>', 'Cache directory. Defaults to ~/.apiskill/cache')
69
72
  .action(async (options) => {
70
73
  await runWeb(options);
71
74
  });
@@ -294,7 +297,11 @@ function registerMockCommand(command) {
294
297
 
295
298
  async function runWeb(options) {
296
299
  const projectRoot = resolve(options.cwd || process.cwd());
297
- const cacheDir = options.cacheDir ? resolve(projectRoot, options.cacheDir) : process.env.APISKILL_CACHE_DIR || resolve(projectRoot, 'cache');
300
+ const cacheDir = options.cacheDir
301
+ ? resolve(projectRoot, options.cacheDir)
302
+ : options.cwd
303
+ ? resolve(projectRoot, 'cache')
304
+ : getDefaultCacheDir();
298
305
  const port = Number(options.port) || 8888;
299
306
  const host = options.host || '127.0.0.1';
300
307
 
@@ -305,6 +312,8 @@ async function runWeb(options) {
305
312
  const server = await createServer({
306
313
  root: packageRoot,
307
314
  configFile: resolve(packageRoot, 'vite.config.ts'),
315
+ configLoader: 'runner',
316
+ cacheDir: resolve(cacheDir, '.vite'),
308
317
  clearScreen: false,
309
318
  server: {
310
319
  host,
@@ -0,0 +1,8 @@
1
+ import { homedir } from 'node:os';
2
+ import { resolve } from 'node:path';
3
+
4
+ export function getDefaultCacheDir(env = process.env) {
5
+ if (env.APISKILL_CACHE_DIR) return resolve(env.APISKILL_CACHE_DIR);
6
+ if (env.APISKILL_ROOT) return resolve(env.APISKILL_ROOT, 'cache');
7
+ return resolve(homedir(), '.apiskill', 'cache');
8
+ }
@@ -1,13 +1,12 @@
1
1
  import { existsSync } from 'node:fs';
2
2
  import { mkdir, readFile, readdir, stat, writeFile } from 'node:fs/promises';
3
3
  import { basename, dirname, resolve } from 'node:path';
4
- import { fileURLToPath } from 'node:url';
5
4
  import { parse as parseYaml } from 'yaml';
5
+ import { getDefaultCacheDir } from './cache-paths.mjs';
6
6
 
7
7
  export const METHODS = ['get', 'post', 'put', 'delete', 'patch', 'options', 'head'];
8
8
 
9
- const rootDir = process.env.APISKILL_ROOT || resolve(dirname(fileURLToPath(import.meta.url)), '../..');
10
- const cacheDir = process.env.APISKILL_CACHE_DIR || resolve(rootDir, 'cache');
9
+ const cacheDir = getDefaultCacheDir();
11
10
  const versionsDir = resolve(cacheDir, 'versions');
12
11
  const latestMetaPath = resolve(cacheDir, 'latest-import.json');
13
12
  const legacyCachePath = resolve(cacheDir, 'openapi-cache.json');
@@ -17,6 +17,7 @@ import {
17
17
  queryApi,
18
18
  searchEndpoints,
19
19
  } from './lib/apiskill-core.mjs';
20
+ import { getDefaultCacheDir } from './lib/cache-paths.mjs';
20
21
 
21
22
  const SERVER_VERSION = '0.1.0';
22
23
 
@@ -238,7 +239,7 @@ const handlers = {
238
239
 
239
240
  function buildHelp() {
240
241
  const rootDir = process.env.APISKILL_ROOT || '/Users/dobby/dev/apiskill';
241
- const cacheDir = process.env.APISKILL_CACHE_DIR || `${rootDir}/cache`;
242
+ const cacheDir = getDefaultCacheDir();
242
243
  const readTools = [
243
244
  'apiskill_check',
244
245
  'apiskill_help',