@webneat/codewiki 0.0.6 → 0.0.8

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/bin.cjs CHANGED
@@ -1193,12 +1193,6 @@ async function create_context(sqlite, db6, config) {
1193
1193
  );
1194
1194
  return ctx;
1195
1195
  }
1196
- async function context_from_config(config) {
1197
- const sqlite = new import_better_sqlite3.default(config.db_path);
1198
- sqlite.pragma("foreign_keys = ON");
1199
- const db6 = (0, import_better_sqlite32.drizzle)(sqlite, { schema: schema_exports });
1200
- return create_context(sqlite, db6, config);
1201
- }
1202
1196
  async function context_from_db(db_path) {
1203
1197
  const sqlite = new import_better_sqlite3.default(db_path);
1204
1198
  sqlite.pragma("foreign_keys = ON");
@@ -1255,6 +1249,7 @@ async function get_github_repo(node_modules_paths, package_name) {
1255
1249
  // src/cli/env.ts
1256
1250
  var env = {
1257
1251
  read_file,
1252
+ cwd: () => process.cwd(),
1258
1253
  file_exists: (path6) => (0, import_node_fs2.existsSync)(path6),
1259
1254
  argv: () => process.argv,
1260
1255
  log: (...args) => console.log(...args),
@@ -1269,120 +1264,7 @@ var import_commander30 = require("commander");
1269
1264
  var import_commander = require("commander");
1270
1265
 
1271
1266
  // src/cli/commands/_common.ts
1272
- var import_zod2 = require("zod");
1273
-
1274
- // src/cli/schema.ts
1275
1267
  var import_zod = require("zod");
1276
- var Config = import_zod.z.object({
1277
- db_path: import_zod.z.string().describe("Path to SQLite database"),
1278
- project_path: import_zod.z.string().describe("Path to TypeScript project"),
1279
- description: import_zod.z.string().optional(),
1280
- package_json_path: import_zod.z.string().optional(),
1281
- node_modules_paths: import_zod.z.array(import_zod.z.string()).optional()
1282
- });
1283
- var StringFilter = import_zod.z.union([
1284
- import_zod.z.string(),
1285
- import_zod.z.object({ contains: import_zod.z.string() }),
1286
- import_zod.z.object({ starts_with: import_zod.z.string() }),
1287
- import_zod.z.object({ ends_with: import_zod.z.string() })
1288
- ]);
1289
- var OrderDirection = import_zod.z.enum(["asc", "desc"]);
1290
- var FileField = import_zod.z.enum(["id", "directory_id", "path", "description", "state", "error"]);
1291
- var FileState = import_zod.z.enum(["to_scan", "to_describe", "ready"]);
1292
- var FileSearchOptions = import_zod.z.object({
1293
- select: import_zod.z.array(FileField).optional(),
1294
- limit: import_zod.z.number().int().positive().optional(),
1295
- offset: import_zod.z.number().int().nonnegative().optional(),
1296
- where: import_zod.z.object({
1297
- id: import_zod.z.number().optional(),
1298
- directory_id: import_zod.z.number().optional(),
1299
- path: StringFilter.optional(),
1300
- description: StringFilter.optional(),
1301
- state: import_zod.z.union([FileState, import_zod.z.object({ contains: import_zod.z.string() })]).optional(),
1302
- error: StringFilter.optional()
1303
- }).optional(),
1304
- order_by: import_zod.z.tuple([FileField, OrderDirection]).optional()
1305
- });
1306
- var FileRelationOptions = import_zod.z.object({
1307
- select: import_zod.z.array(FileField).optional(),
1308
- limit: import_zod.z.number().int().positive().optional(),
1309
- offset: import_zod.z.number().int().nonnegative().optional(),
1310
- deep: import_zod.z.boolean().optional()
1311
- });
1312
- var SymbolField = import_zod.z.enum(["id", "file_id", "type", "name", "text", "meta", "description", "is_exported", "state", "error"]);
1313
- var SymbolType = import_zod.z.enum(["function", "class", "class_method", "class_property", "variable", "type"]);
1314
- var SymbolState = import_zod.z.enum(["to_link", "to_describe", "ready"]);
1315
- var SymbolSearchOptions = import_zod.z.object({
1316
- select: import_zod.z.array(SymbolField).optional(),
1317
- limit: import_zod.z.number().int().positive().optional(),
1318
- offset: import_zod.z.number().int().nonnegative().optional(),
1319
- where: import_zod.z.object({
1320
- id: import_zod.z.number().optional(),
1321
- file_id: import_zod.z.number().optional(),
1322
- type: import_zod.z.union([SymbolType, import_zod.z.object({ contains: import_zod.z.string() })]).optional(),
1323
- name: StringFilter.optional(),
1324
- text: StringFilter.optional(),
1325
- meta: StringFilter.optional(),
1326
- description: StringFilter.optional(),
1327
- is_exported: import_zod.z.boolean().optional(),
1328
- state: import_zod.z.union([SymbolState, import_zod.z.object({ contains: import_zod.z.string() })]).optional(),
1329
- error: StringFilter.optional()
1330
- }).optional(),
1331
- order_by: import_zod.z.tuple([SymbolField, OrderDirection]).optional()
1332
- });
1333
- var SymbolRelationOptions = import_zod.z.object({
1334
- select: import_zod.z.array(SymbolField).optional(),
1335
- limit: import_zod.z.number().int().positive().optional(),
1336
- offset: import_zod.z.number().int().nonnegative().optional(),
1337
- deep: import_zod.z.boolean().optional()
1338
- });
1339
- var DirectoryField = import_zod.z.enum(["id", "parent_id", "path", "description", "state", "error"]);
1340
- var DirectoryState = import_zod.z.enum(["to_describe", "ready"]);
1341
- var DirectorySearchOptions = import_zod.z.object({
1342
- select: import_zod.z.array(DirectoryField).optional(),
1343
- limit: import_zod.z.number().int().positive().optional(),
1344
- offset: import_zod.z.number().int().nonnegative().optional(),
1345
- where: import_zod.z.object({
1346
- id: import_zod.z.number().optional(),
1347
- parent_id: import_zod.z.number().optional(),
1348
- path: StringFilter.optional(),
1349
- description: StringFilter.optional(),
1350
- state: import_zod.z.union([DirectoryState, import_zod.z.object({ contains: import_zod.z.string() })]).optional(),
1351
- error: StringFilter.optional()
1352
- }).optional(),
1353
- order_by: import_zod.z.tuple([DirectoryField, OrderDirection]).optional()
1354
- });
1355
- var DirectoryRelationOptions = import_zod.z.object({
1356
- select: import_zod.z.array(DirectoryField).optional(),
1357
- limit: import_zod.z.number().int().positive().optional(),
1358
- offset: import_zod.z.number().int().nonnegative().optional(),
1359
- deep: import_zod.z.boolean().optional()
1360
- });
1361
- var DependencyField = import_zod.z.enum(["id", "package", "subpath", "name", "version", "github_repo", "is_builtin", "description", "state", "error"]);
1362
- var DependencyState = import_zod.z.enum(["to_describe", "ready"]);
1363
- var DependencySearchOptions = import_zod.z.object({
1364
- select: import_zod.z.array(DependencyField).optional(),
1365
- limit: import_zod.z.number().int().positive().optional(),
1366
- offset: import_zod.z.number().int().nonnegative().optional(),
1367
- where: import_zod.z.object({
1368
- id: import_zod.z.number().optional(),
1369
- package: StringFilter.optional(),
1370
- subpath: StringFilter.optional(),
1371
- name: StringFilter.optional(),
1372
- version: StringFilter.optional(),
1373
- github_repo: StringFilter.optional(),
1374
- is_builtin: import_zod.z.boolean().optional(),
1375
- description: StringFilter.optional(),
1376
- state: import_zod.z.union([DependencyState, import_zod.z.object({ contains: import_zod.z.string() })]).optional(),
1377
- error: StringFilter.optional()
1378
- }).optional(),
1379
- order_by: import_zod.z.tuple([DependencyField, OrderDirection]).optional()
1380
- });
1381
- var DependencySelectOptions = import_zod.z.object({
1382
- select: import_zod.z.array(DependencyField).optional(),
1383
- limit: import_zod.z.number().int().positive().optional(),
1384
- offset: import_zod.z.number().int().nonnegative().optional()
1385
- });
1386
1268
 
1387
1269
  // src/update/track_changes.ts
1388
1270
  var import_node_path3 = __toESM(require("path"), 1);
@@ -1534,6 +1416,7 @@ var import_typescript4 = __toESM(require("typescript"), 1);
1534
1416
  var import_node_path4 = __toESM(require("path"), 1);
1535
1417
  var import_typescript3 = __toESM(require("typescript"), 1);
1536
1418
  function is_external_module(ctx, source_file, module_path) {
1419
+ if (module_path.startsWith("#")) return false;
1537
1420
  const resolved = import_typescript3.default.resolveModuleName(module_path, source_file.fileName, ctx.program.getCompilerOptions(), import_typescript3.default.sys);
1538
1421
  if (!resolved.resolvedModule) return true;
1539
1422
  const resolved_path = import_node_path4.default.resolve(resolved.resolvedModule.resolvedFileName);
@@ -2480,6 +2363,21 @@ async function update6(ctx) {
2480
2363
  await link_symbols(ctx);
2481
2364
  }
2482
2365
 
2366
+ // src/update_config.ts
2367
+ function update_config(ctx, config, updates) {
2368
+ if (Object.keys(updates).length === 0) return;
2369
+ const new_config = { ...config, ...updates };
2370
+ err.or_throw(
2371
+ configs_exports.upsert(ctx, {
2372
+ project_path: new_config.project_path,
2373
+ description: new_config.description ?? null,
2374
+ package_json_path: new_config.package_json_path ?? null,
2375
+ node_modules_paths: new_config.node_modules_paths ? JSON.stringify(new_config.node_modules_paths) : null
2376
+ })
2377
+ );
2378
+ Object.assign(config, updates);
2379
+ }
2380
+
2483
2381
  // src/counts.ts
2484
2382
  var import_drizzle_orm13 = require("drizzle-orm");
2485
2383
  function counts(ctx) {
@@ -2795,19 +2693,6 @@ function directories_to_describe(ctx, limit) {
2795
2693
  }
2796
2694
 
2797
2695
  // src/index.ts
2798
- async function create(config) {
2799
- const ctx = await context_from_config(config);
2800
- return {
2801
- config,
2802
- update: () => update6(ctx),
2803
- counts: () => counts(ctx),
2804
- to_describe: (limit) => to_describe(ctx, limit),
2805
- files: files_wiki(ctx),
2806
- symbols: symbols_wiki(ctx),
2807
- directories: directories_wiki(ctx),
2808
- dependencies: dependencies_wiki(ctx)
2809
- };
2810
- }
2811
2696
  async function load(db_path) {
2812
2697
  const ctx = await context_from_db(db_path);
2813
2698
  const stored = ctx.db.select().from(schema_exports.configs).get();
@@ -2820,6 +2705,7 @@ async function load(db_path) {
2820
2705
  };
2821
2706
  return {
2822
2707
  config,
2708
+ update_config: (updates) => update_config(ctx, config, updates),
2823
2709
  update: () => update6(ctx),
2824
2710
  counts: () => counts(ctx),
2825
2711
  to_describe: (limit) => to_describe(ctx, limit),
@@ -2831,30 +2717,18 @@ async function load(db_path) {
2831
2717
  }
2832
2718
 
2833
2719
  // src/cli/commands/_common.ts
2834
- var config_path = "codewiki.json";
2835
- async function load_wiki() {
2836
- try {
2837
- const content = err.or_throw(env.read_file(config_path));
2838
- const raw_config = err.or_throw(parse_json(content));
2839
- const res = Config.safeParse(raw_config);
2840
- if (!res.success) throw err.new("invalid_config", { errors: res.error.issues });
2841
- const config = res.data;
2842
- if (env.file_exists(config.db_path)) return load(config.db_path);
2843
- return create(config);
2844
- } catch (error) {
2845
- if (error.type === "could_not_read_file") {
2846
- env.error(`Error: Configuration file ${config_path} not found`);
2847
- } else if (error.type === "invalid_json") {
2848
- env.error(`Error: Invalid JSON in ${config_path}`);
2849
- } else if (error.type === "invalid_config") {
2850
- env.error("Error: Invalid configuration");
2851
- } else if (error.message) {
2852
- env.error(`Error: ${error.message}`);
2853
- } else {
2854
- env.error(`Error: ${String(error)}`);
2855
- }
2856
- process.exit(1);
2720
+ function get_db_path(...args) {
2721
+ const cmd = args[args.length - 1];
2722
+ return cmd.optsWithGlobals().db;
2723
+ }
2724
+ async function load_wiki(db_path) {
2725
+ if (!env.file_exists(db_path)) {
2726
+ env.error(`Error: No wiki found at ${db_path}`);
2727
+ env.error(`Run \`codewiki init\` to create one.`);
2728
+ env.exit(1);
2729
+ return void 0;
2857
2730
  }
2731
+ return load(db_path);
2858
2732
  }
2859
2733
  function parse_options(options_json, schema, context) {
2860
2734
  let parsed_json;
@@ -2902,8 +2776,8 @@ function count_text({ total, ...states }) {
2902
2776
  // src/cli/commands/update.ts
2903
2777
  var update7 = new import_commander.Command("update");
2904
2778
  update7.description("Reads current files and updates the wiki database");
2905
- update7.action(async () => {
2906
- const wiki = await load_wiki();
2779
+ update7.action(async (...args) => {
2780
+ const wiki = await load_wiki(get_db_path(...args));
2907
2781
  await wiki.update();
2908
2782
  env.log("Update complete.\n");
2909
2783
  const counts2 = wiki.counts();
@@ -2915,8 +2789,8 @@ update7.action(async () => {
2915
2789
  var import_commander2 = require("commander");
2916
2790
  var status = new import_commander2.Command("status");
2917
2791
  status.description("Show the status of the wiki");
2918
- status.action(async () => {
2919
- const wiki = await load_wiki();
2792
+ status.action(async (...args) => {
2793
+ const wiki = await load_wiki(get_db_path(...args));
2920
2794
  const counts2 = wiki.counts();
2921
2795
  env.log(format_counts(counts2));
2922
2796
  });
@@ -2926,8 +2800,8 @@ var import_dedent2 = __toESM(require("dedent"), 1);
2926
2800
  var import_commander3 = require("commander");
2927
2801
  var describe = new import_commander3.Command("describe");
2928
2802
  describe.description("Show the next item to describe");
2929
- describe.action(async () => {
2930
- const wiki = await load_wiki();
2803
+ describe.action(async (...args) => {
2804
+ const wiki = await load_wiki(get_db_path(...args));
2931
2805
  const result = wiki.to_describe(1);
2932
2806
  if (result.type === "none") {
2933
2807
  return env.log("All items are described!");
@@ -3007,19 +2881,136 @@ var import_commander4 = require("commander");
3007
2881
  var get6 = new import_commander4.Command("get");
3008
2882
  get6.description("Get a file by ID");
3009
2883
  get6.argument("<id>", "File ID");
3010
- get6.action(async (id) => {
3011
- const wiki = await load_wiki();
2884
+ get6.action(async (...args) => {
2885
+ const [id] = args;
2886
+ const wiki = await load_wiki(get_db_path(...args));
3012
2887
  const file = wiki.files.get(Number(id));
3013
2888
  env.log(JSON.stringify(file, null, 2));
3014
2889
  });
3015
2890
 
3016
2891
  // src/cli/commands/files/search.ts
3017
2892
  var import_commander5 = require("commander");
2893
+
2894
+ // src/cli/schema.ts
2895
+ var import_zod2 = require("zod");
2896
+ var Config = import_zod2.z.object({
2897
+ db_path: import_zod2.z.string().describe("Path to SQLite database"),
2898
+ project_path: import_zod2.z.string().describe("Path to TypeScript project"),
2899
+ description: import_zod2.z.string().optional(),
2900
+ package_json_path: import_zod2.z.string().optional(),
2901
+ node_modules_paths: import_zod2.z.array(import_zod2.z.string()).optional()
2902
+ });
2903
+ var StringFilter = import_zod2.z.union([
2904
+ import_zod2.z.string(),
2905
+ import_zod2.z.object({ contains: import_zod2.z.string() }),
2906
+ import_zod2.z.object({ starts_with: import_zod2.z.string() }),
2907
+ import_zod2.z.object({ ends_with: import_zod2.z.string() })
2908
+ ]);
2909
+ var OrderDirection = import_zod2.z.enum(["asc", "desc"]);
2910
+ var FileField = import_zod2.z.enum(["id", "directory_id", "path", "description", "state", "error"]);
2911
+ var FileState = import_zod2.z.enum(["to_scan", "to_describe", "ready"]);
2912
+ var FileSearchOptions = import_zod2.z.object({
2913
+ select: import_zod2.z.array(FileField).optional(),
2914
+ limit: import_zod2.z.number().int().positive().optional(),
2915
+ offset: import_zod2.z.number().int().nonnegative().optional(),
2916
+ where: import_zod2.z.object({
2917
+ id: import_zod2.z.number().optional(),
2918
+ directory_id: import_zod2.z.number().optional(),
2919
+ path: StringFilter.optional(),
2920
+ description: StringFilter.optional(),
2921
+ state: import_zod2.z.union([FileState, import_zod2.z.object({ contains: import_zod2.z.string() })]).optional(),
2922
+ error: StringFilter.optional()
2923
+ }).optional(),
2924
+ order_by: import_zod2.z.tuple([FileField, OrderDirection]).optional()
2925
+ });
2926
+ var FileRelationOptions = import_zod2.z.object({
2927
+ select: import_zod2.z.array(FileField).optional(),
2928
+ limit: import_zod2.z.number().int().positive().optional(),
2929
+ offset: import_zod2.z.number().int().nonnegative().optional(),
2930
+ deep: import_zod2.z.boolean().optional()
2931
+ });
2932
+ var SymbolField = import_zod2.z.enum(["id", "file_id", "type", "name", "text", "meta", "description", "is_exported", "state", "error"]);
2933
+ var SymbolType = import_zod2.z.enum(["function", "class", "class_method", "class_property", "variable", "type"]);
2934
+ var SymbolState = import_zod2.z.enum(["to_link", "to_describe", "ready"]);
2935
+ var SymbolSearchOptions = import_zod2.z.object({
2936
+ select: import_zod2.z.array(SymbolField).optional(),
2937
+ limit: import_zod2.z.number().int().positive().optional(),
2938
+ offset: import_zod2.z.number().int().nonnegative().optional(),
2939
+ where: import_zod2.z.object({
2940
+ id: import_zod2.z.number().optional(),
2941
+ file_id: import_zod2.z.number().optional(),
2942
+ type: import_zod2.z.union([SymbolType, import_zod2.z.object({ contains: import_zod2.z.string() })]).optional(),
2943
+ name: StringFilter.optional(),
2944
+ text: StringFilter.optional(),
2945
+ meta: StringFilter.optional(),
2946
+ description: StringFilter.optional(),
2947
+ is_exported: import_zod2.z.boolean().optional(),
2948
+ state: import_zod2.z.union([SymbolState, import_zod2.z.object({ contains: import_zod2.z.string() })]).optional(),
2949
+ error: StringFilter.optional()
2950
+ }).optional(),
2951
+ order_by: import_zod2.z.tuple([SymbolField, OrderDirection]).optional()
2952
+ });
2953
+ var SymbolRelationOptions = import_zod2.z.object({
2954
+ select: import_zod2.z.array(SymbolField).optional(),
2955
+ limit: import_zod2.z.number().int().positive().optional(),
2956
+ offset: import_zod2.z.number().int().nonnegative().optional(),
2957
+ deep: import_zod2.z.boolean().optional()
2958
+ });
2959
+ var DirectoryField = import_zod2.z.enum(["id", "parent_id", "path", "description", "state", "error"]);
2960
+ var DirectoryState = import_zod2.z.enum(["to_describe", "ready"]);
2961
+ var DirectorySearchOptions = import_zod2.z.object({
2962
+ select: import_zod2.z.array(DirectoryField).optional(),
2963
+ limit: import_zod2.z.number().int().positive().optional(),
2964
+ offset: import_zod2.z.number().int().nonnegative().optional(),
2965
+ where: import_zod2.z.object({
2966
+ id: import_zod2.z.number().optional(),
2967
+ parent_id: import_zod2.z.number().optional(),
2968
+ path: StringFilter.optional(),
2969
+ description: StringFilter.optional(),
2970
+ state: import_zod2.z.union([DirectoryState, import_zod2.z.object({ contains: import_zod2.z.string() })]).optional(),
2971
+ error: StringFilter.optional()
2972
+ }).optional(),
2973
+ order_by: import_zod2.z.tuple([DirectoryField, OrderDirection]).optional()
2974
+ });
2975
+ var DirectoryRelationOptions = import_zod2.z.object({
2976
+ select: import_zod2.z.array(DirectoryField).optional(),
2977
+ limit: import_zod2.z.number().int().positive().optional(),
2978
+ offset: import_zod2.z.number().int().nonnegative().optional(),
2979
+ deep: import_zod2.z.boolean().optional()
2980
+ });
2981
+ var DependencyField = import_zod2.z.enum(["id", "package", "subpath", "name", "version", "github_repo", "is_builtin", "description", "state", "error"]);
2982
+ var DependencyState = import_zod2.z.enum(["to_describe", "ready"]);
2983
+ var DependencySearchOptions = import_zod2.z.object({
2984
+ select: import_zod2.z.array(DependencyField).optional(),
2985
+ limit: import_zod2.z.number().int().positive().optional(),
2986
+ offset: import_zod2.z.number().int().nonnegative().optional(),
2987
+ where: import_zod2.z.object({
2988
+ id: import_zod2.z.number().optional(),
2989
+ package: StringFilter.optional(),
2990
+ subpath: StringFilter.optional(),
2991
+ name: StringFilter.optional(),
2992
+ version: StringFilter.optional(),
2993
+ github_repo: StringFilter.optional(),
2994
+ is_builtin: import_zod2.z.boolean().optional(),
2995
+ description: StringFilter.optional(),
2996
+ state: import_zod2.z.union([DependencyState, import_zod2.z.object({ contains: import_zod2.z.string() })]).optional(),
2997
+ error: StringFilter.optional()
2998
+ }).optional(),
2999
+ order_by: import_zod2.z.tuple([DependencyField, OrderDirection]).optional()
3000
+ });
3001
+ var DependencySelectOptions = import_zod2.z.object({
3002
+ select: import_zod2.z.array(DependencyField).optional(),
3003
+ limit: import_zod2.z.number().int().positive().optional(),
3004
+ offset: import_zod2.z.number().int().nonnegative().optional()
3005
+ });
3006
+
3007
+ // src/cli/commands/files/search.ts
3018
3008
  var search13 = new import_commander5.Command("search");
3019
3009
  search13.description("Search files with JSON options");
3020
3010
  search13.argument("<options>", "JSON options for search");
3021
- search13.action(async (options_json) => {
3022
- const wiki = await load_wiki();
3011
+ search13.action(async (...args) => {
3012
+ const [options_json] = args;
3013
+ const wiki = await load_wiki(get_db_path(...args));
3023
3014
  const options = parse_options(options_json, FileSearchOptions, "files search");
3024
3015
  const results = wiki.files.search(options);
3025
3016
  env.log(JSON.stringify(results, null, 2));
@@ -3032,8 +3023,9 @@ var set_description5 = new import_commander6.Command("set-description");
3032
3023
  set_description5.description("Set description for a file");
3033
3024
  set_description5.argument("<file-id>", "File ID");
3034
3025
  set_description5.argument("<markdown-file>", "Path to markdown file");
3035
- set_description5.action(async (id, file) => {
3036
- const wiki = await load_wiki();
3026
+ set_description5.action(async (...args) => {
3027
+ const [id, file] = args;
3028
+ const wiki = await load_wiki(get_db_path(...args));
3037
3029
  try {
3038
3030
  const content = (0, import_node_fs3.readFileSync)(file, "utf-8");
3039
3031
  wiki.files.set_description(Number(id), content);
@@ -3050,8 +3042,9 @@ var imported_by_file2 = new import_commander7.Command("imported-by-file");
3050
3042
  imported_by_file2.description("Files imported by the given file");
3051
3043
  imported_by_file2.argument("<file-id>", "File ID");
3052
3044
  imported_by_file2.argument("<options>", "JSON options");
3053
- imported_by_file2.action(async (file_id, options_json) => {
3054
- const wiki = await load_wiki();
3045
+ imported_by_file2.action(async (...args) => {
3046
+ const [file_id, options_json] = args;
3047
+ const wiki = await load_wiki(get_db_path(...args));
3055
3048
  const options = parse_options(options_json, FileRelationOptions, "files imported-by-file");
3056
3049
  const results = wiki.files.imported_by_file(Number(file_id), options);
3057
3050
  env.log(JSON.stringify(results, null, 2));
@@ -3063,8 +3056,9 @@ var importing_file2 = new import_commander8.Command("importing-file");
3063
3056
  importing_file2.description("Files importing the given file");
3064
3057
  importing_file2.argument("<file-id>", "File ID");
3065
3058
  importing_file2.argument("<options>", "JSON options");
3066
- importing_file2.action(async (file_id, options_json) => {
3067
- const wiki = await load_wiki();
3059
+ importing_file2.action(async (...args) => {
3060
+ const [file_id, options_json] = args;
3061
+ const wiki = await load_wiki(get_db_path(...args));
3068
3062
  const options = parse_options(options_json, FileRelationOptions, "files importing-file");
3069
3063
  const results = wiki.files.importing_file(Number(file_id), options);
3070
3064
  env.log(JSON.stringify(results, null, 2));
@@ -3076,8 +3070,9 @@ var importing_dependency2 = new import_commander9.Command("importing-dependency"
3076
3070
  importing_dependency2.description("Files importing the given dependency");
3077
3071
  importing_dependency2.argument("<dep-id>", "Dependency ID");
3078
3072
  importing_dependency2.argument("<options>", "JSON options");
3079
- importing_dependency2.action(async (dep_id, options_json) => {
3080
- const wiki = await load_wiki();
3073
+ importing_dependency2.action(async (...args) => {
3074
+ const [dep_id, options_json] = args;
3075
+ const wiki = await load_wiki(get_db_path(...args));
3081
3076
  const options = parse_options(options_json, FileRelationOptions, "files importing-dependency");
3082
3077
  const results = wiki.files.importing_dependency(Number(dep_id), options);
3083
3078
  env.log(JSON.stringify(results, null, 2));
@@ -3130,8 +3125,9 @@ var import_commander11 = require("commander");
3130
3125
  var get7 = new import_commander11.Command("get");
3131
3126
  get7.description("Get a symbol by ID");
3132
3127
  get7.argument("<id>", "Symbol ID");
3133
- get7.action(async (id) => {
3134
- const wiki = await load_wiki();
3128
+ get7.action(async (...args) => {
3129
+ const [id] = args;
3130
+ const wiki = await load_wiki(get_db_path(...args));
3135
3131
  const symbol = wiki.symbols.get(Number(id));
3136
3132
  env.log(JSON.stringify(symbol, null, 2));
3137
3133
  });
@@ -3141,8 +3137,9 @@ var import_commander12 = require("commander");
3141
3137
  var search14 = new import_commander12.Command("search");
3142
3138
  search14.description("Search symbols with JSON options");
3143
3139
  search14.argument("<options>", "JSON options");
3144
- search14.action(async (options_json) => {
3145
- const wiki = await load_wiki();
3140
+ search14.action(async (...args) => {
3141
+ const [options_json] = args;
3142
+ const wiki = await load_wiki(get_db_path(...args));
3146
3143
  const options = parse_options(options_json, SymbolSearchOptions, "symbols search");
3147
3144
  const results = wiki.symbols.search(options);
3148
3145
  env.log(JSON.stringify(results, null, 2));
@@ -3155,8 +3152,9 @@ var set_description6 = new import_commander13.Command("set-description");
3155
3152
  set_description6.description("Set description for a symbol");
3156
3153
  set_description6.argument("<symbol-id>", "Symbol ID");
3157
3154
  set_description6.argument("<markdown-file>", "Path to markdown file");
3158
- set_description6.action(async (id, file) => {
3159
- const wiki = await load_wiki();
3155
+ set_description6.action(async (...args) => {
3156
+ const [id, file] = args;
3157
+ const wiki = await load_wiki(get_db_path(...args));
3160
3158
  try {
3161
3159
  const content = (0, import_node_fs4.readFileSync)(file, "utf-8");
3162
3160
  wiki.symbols.set_description(Number(id), content);
@@ -3173,8 +3171,9 @@ var referencing_symbol2 = new import_commander14.Command("referencing-symbol");
3173
3171
  referencing_symbol2.description("Symbols referencing the given symbol");
3174
3172
  referencing_symbol2.argument("<symbol-id>", "Symbol ID");
3175
3173
  referencing_symbol2.argument("<options>", "JSON options");
3176
- referencing_symbol2.action(async (symbol_id, options_json) => {
3177
- const wiki = await load_wiki();
3174
+ referencing_symbol2.action(async (...args) => {
3175
+ const [symbol_id, options_json] = args;
3176
+ const wiki = await load_wiki(get_db_path(...args));
3178
3177
  const options = parse_options(options_json, SymbolRelationOptions, "symbols referencing-symbol");
3179
3178
  const results = wiki.symbols.referencing_symbol(Number(symbol_id), options);
3180
3179
  env.log(JSON.stringify(results, null, 2));
@@ -3186,8 +3185,9 @@ var referenced_by_symbol2 = new import_commander15.Command("referenced-by-symbol
3186
3185
  referenced_by_symbol2.description("Symbols referenced by the given symbol");
3187
3186
  referenced_by_symbol2.argument("<symbol-id>", "Symbol ID");
3188
3187
  referenced_by_symbol2.argument("<options>", "JSON options");
3189
- referenced_by_symbol2.action(async (symbol_id, options_json) => {
3190
- const wiki = await load_wiki();
3188
+ referenced_by_symbol2.action(async (...args) => {
3189
+ const [symbol_id, options_json] = args;
3190
+ const wiki = await load_wiki(get_db_path(...args));
3191
3191
  const options = parse_options(options_json, SymbolRelationOptions, "symbols referenced-by-symbol");
3192
3192
  const results = wiki.symbols.referenced_by_symbol(Number(symbol_id), options);
3193
3193
  env.log(JSON.stringify(results, null, 2));
@@ -3199,8 +3199,9 @@ var using_dependency4 = new import_commander16.Command("using-dependency");
3199
3199
  using_dependency4.description("Symbols using the given dependency");
3200
3200
  using_dependency4.argument("<dep-id>", "Dependency ID");
3201
3201
  using_dependency4.argument("<options>", "JSON options");
3202
- using_dependency4.action(async (dep_id, options_json) => {
3203
- const wiki = await load_wiki();
3202
+ using_dependency4.action(async (...args) => {
3203
+ const [dep_id, options_json] = args;
3204
+ const wiki = await load_wiki(get_db_path(...args));
3204
3205
  const options = parse_options(options_json, SymbolRelationOptions, "symbols using-dependency");
3205
3206
  const results = wiki.symbols.using_dependency(Number(dep_id), options);
3206
3207
  env.log(JSON.stringify(results, null, 2));
@@ -3253,8 +3254,9 @@ var import_commander18 = require("commander");
3253
3254
  var get8 = new import_commander18.Command("get");
3254
3255
  get8.description("Get a directory by ID");
3255
3256
  get8.argument("<id>", "Directory ID");
3256
- get8.action(async (id) => {
3257
- const wiki = await load_wiki();
3257
+ get8.action(async (...args) => {
3258
+ const [id] = args;
3259
+ const wiki = await load_wiki(get_db_path(...args));
3258
3260
  const directory = wiki.directories.get(Number(id));
3259
3261
  env.log(JSON.stringify(directory, null, 2));
3260
3262
  });
@@ -3264,8 +3266,9 @@ var import_commander19 = require("commander");
3264
3266
  var search15 = new import_commander19.Command("search");
3265
3267
  search15.description("Search directories with JSON options");
3266
3268
  search15.argument("<options>", "JSON options");
3267
- search15.action(async (options_json) => {
3268
- const wiki = await load_wiki();
3269
+ search15.action(async (...args) => {
3270
+ const [options_json] = args;
3271
+ const wiki = await load_wiki(get_db_path(...args));
3269
3272
  const options = parse_options(options_json, DirectorySearchOptions, "directories search");
3270
3273
  const results = wiki.directories.search(options);
3271
3274
  env.log(JSON.stringify(results, null, 2));
@@ -3278,8 +3281,9 @@ var set_description7 = new import_commander20.Command("set-description");
3278
3281
  set_description7.description("Set description for a directory");
3279
3282
  set_description7.argument("<directory-id>", "Directory ID");
3280
3283
  set_description7.argument("<markdown-file>", "Path to markdown file");
3281
- set_description7.action(async (id, file) => {
3282
- const wiki = await load_wiki();
3284
+ set_description7.action(async (...args) => {
3285
+ const [id, file] = args;
3286
+ const wiki = await load_wiki(get_db_path(...args));
3283
3287
  try {
3284
3288
  const content = (0, import_node_fs5.readFileSync)(file, "utf-8");
3285
3289
  wiki.directories.set_description(Number(id), content);
@@ -3296,8 +3300,9 @@ var children2 = new import_commander21.Command("children");
3296
3300
  children2.description("Child directories of the given directory");
3297
3301
  children2.argument("<parent-id>", "Parent directory ID");
3298
3302
  children2.argument("<options>", "JSON options");
3299
- children2.action(async (parent_id, options_json) => {
3300
- const wiki = await load_wiki();
3303
+ children2.action(async (...args) => {
3304
+ const [parent_id, options_json] = args;
3305
+ const wiki = await load_wiki(get_db_path(...args));
3301
3306
  const options = parse_options(options_json, DirectoryRelationOptions, "directories children");
3302
3307
  const results = wiki.directories.children(Number(parent_id), options);
3303
3308
  env.log(JSON.stringify(results, null, 2));
@@ -3309,8 +3314,9 @@ var files4 = new import_commander22.Command("files");
3309
3314
  files4.description("Files in the given directory");
3310
3315
  files4.argument("<directory-id>", "Directory ID");
3311
3316
  files4.argument("<options>", "JSON options");
3312
- files4.action(async (directory_id, options_json) => {
3313
- const wiki = await load_wiki();
3317
+ files4.action(async (...args) => {
3318
+ const [directory_id, options_json] = args;
3319
+ const wiki = await load_wiki(get_db_path(...args));
3314
3320
  const options = parse_options(options_json, FileRelationOptions, "directories files");
3315
3321
  const results = wiki.directories.files(Number(directory_id), options);
3316
3322
  env.log(JSON.stringify(results, null, 2));
@@ -3362,8 +3368,9 @@ var import_commander24 = require("commander");
3362
3368
  var get9 = new import_commander24.Command("get");
3363
3369
  get9.description("Get a dependency by ID");
3364
3370
  get9.argument("<id>", "Dependency ID");
3365
- get9.action(async (id) => {
3366
- const wiki = await load_wiki();
3371
+ get9.action(async (...args) => {
3372
+ const [id] = args;
3373
+ const wiki = await load_wiki(get_db_path(...args));
3367
3374
  const dependency = wiki.dependencies.get(Number(id));
3368
3375
  env.log(JSON.stringify(dependency, null, 2));
3369
3376
  });
@@ -3373,8 +3380,9 @@ var import_commander25 = require("commander");
3373
3380
  var search16 = new import_commander25.Command("search");
3374
3381
  search16.description("Search dependencies with JSON options");
3375
3382
  search16.argument("<options>", "JSON options");
3376
- search16.action(async (options_json) => {
3377
- const wiki = await load_wiki();
3383
+ search16.action(async (...args) => {
3384
+ const [options_json] = args;
3385
+ const wiki = await load_wiki(get_db_path(...args));
3378
3386
  const options = parse_options(options_json, DependencySearchOptions, "dependencies search");
3379
3387
  const results = wiki.dependencies.search(options);
3380
3388
  env.log(JSON.stringify(results, null, 2));
@@ -3387,8 +3395,9 @@ var set_description8 = new import_commander26.Command("set-description");
3387
3395
  set_description8.description("Set description for a dependency");
3388
3396
  set_description8.argument("<dependency-id>", "Dependency ID");
3389
3397
  set_description8.argument("<markdown-file>", "Path to markdown file");
3390
- set_description8.action(async (id, file) => {
3391
- const wiki = await load_wiki();
3398
+ set_description8.action(async (...args) => {
3399
+ const [id, file] = args;
3400
+ const wiki = await load_wiki(get_db_path(...args));
3392
3401
  try {
3393
3402
  const content = (0, import_node_fs6.readFileSync)(file, "utf-8");
3394
3403
  wiki.dependencies.set_description(Number(id), content);
@@ -3405,8 +3414,9 @@ var used_by_file3 = new import_commander27.Command("used-by-file");
3405
3414
  used_by_file3.description("Dependencies used by the given file");
3406
3415
  used_by_file3.argument("<file-id>", "File ID");
3407
3416
  used_by_file3.argument("<options>", "JSON options");
3408
- used_by_file3.action(async (file_id, options_json) => {
3409
- const wiki = await load_wiki();
3417
+ used_by_file3.action(async (...args) => {
3418
+ const [file_id, options_json] = args;
3419
+ const wiki = await load_wiki(get_db_path(...args));
3410
3420
  const options = parse_options(options_json, DependencySelectOptions, "dependencies used-by-file");
3411
3421
  const results = wiki.dependencies.used_by_file(Number(file_id), options);
3412
3422
  env.log(JSON.stringify(results, null, 2));
@@ -3418,8 +3428,9 @@ var used_by_symbol3 = new import_commander28.Command("used-by-symbol");
3418
3428
  used_by_symbol3.description("Dependencies used by the given symbol");
3419
3429
  used_by_symbol3.argument("<symbol-id>", "Symbol ID");
3420
3430
  used_by_symbol3.argument("<options>", "JSON options");
3421
- used_by_symbol3.action(async (symbol_id, options_json) => {
3422
- const wiki = await load_wiki();
3431
+ used_by_symbol3.action(async (...args) => {
3432
+ const [symbol_id, options_json] = args;
3433
+ const wiki = await load_wiki(get_db_path(...args));
3423
3434
  const options = parse_options(options_json, DependencySelectOptions, "dependencies used-by-symbol");
3424
3435
  const results = wiki.dependencies.used_by_symbol(Number(symbol_id), options);
3425
3436
  env.log(JSON.stringify(results, null, 2));
@@ -3468,6 +3479,7 @@ var commands = [update7, status, describe, files3, symbols3, directories3, depen
3468
3479
  async function run(argv) {
3469
3480
  const program = new import_commander30.Command();
3470
3481
  program.name("codewiki").description("Describe and explore TypeScript codebases").version("0.0.1");
3482
+ program.option("--db <path>", "Database location", "./wiki.db");
3471
3483
  for (const cmd of commands) program.addCommand(cmd);
3472
3484
  return program.parseAsync(argv, { from: "user" });
3473
3485
  }