@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.js CHANGED
@@ -1178,12 +1178,6 @@ async function create_context(sqlite, db6, config) {
1178
1178
  );
1179
1179
  return ctx;
1180
1180
  }
1181
- async function context_from_config(config) {
1182
- const sqlite = new Database(config.db_path);
1183
- sqlite.pragma("foreign_keys = ON");
1184
- const db6 = drizzle(sqlite, { schema: schema_exports });
1185
- return create_context(sqlite, db6, config);
1186
- }
1187
1181
  async function context_from_db(db_path) {
1188
1182
  const sqlite = new Database(db_path);
1189
1183
  sqlite.pragma("foreign_keys = ON");
@@ -1240,6 +1234,7 @@ async function get_github_repo(node_modules_paths, package_name) {
1240
1234
  // src/cli/env.ts
1241
1235
  var env = {
1242
1236
  read_file,
1237
+ cwd: () => process.cwd(),
1243
1238
  file_exists: (path7) => existsSync(path7),
1244
1239
  argv: () => process.argv,
1245
1240
  log: (...args) => console.log(...args),
@@ -1256,119 +1251,6 @@ import { Command } from "commander";
1256
1251
  // src/cli/commands/_common.ts
1257
1252
  import "zod";
1258
1253
 
1259
- // src/cli/schema.ts
1260
- import { z } from "zod";
1261
- var Config = z.object({
1262
- db_path: z.string().describe("Path to SQLite database"),
1263
- project_path: z.string().describe("Path to TypeScript project"),
1264
- description: z.string().optional(),
1265
- package_json_path: z.string().optional(),
1266
- node_modules_paths: z.array(z.string()).optional()
1267
- });
1268
- var StringFilter = z.union([
1269
- z.string(),
1270
- z.object({ contains: z.string() }),
1271
- z.object({ starts_with: z.string() }),
1272
- z.object({ ends_with: z.string() })
1273
- ]);
1274
- var OrderDirection = z.enum(["asc", "desc"]);
1275
- var FileField = z.enum(["id", "directory_id", "path", "description", "state", "error"]);
1276
- var FileState = z.enum(["to_scan", "to_describe", "ready"]);
1277
- var FileSearchOptions = z.object({
1278
- select: z.array(FileField).optional(),
1279
- limit: z.number().int().positive().optional(),
1280
- offset: z.number().int().nonnegative().optional(),
1281
- where: z.object({
1282
- id: z.number().optional(),
1283
- directory_id: z.number().optional(),
1284
- path: StringFilter.optional(),
1285
- description: StringFilter.optional(),
1286
- state: z.union([FileState, z.object({ contains: z.string() })]).optional(),
1287
- error: StringFilter.optional()
1288
- }).optional(),
1289
- order_by: z.tuple([FileField, OrderDirection]).optional()
1290
- });
1291
- var FileRelationOptions = z.object({
1292
- select: z.array(FileField).optional(),
1293
- limit: z.number().int().positive().optional(),
1294
- offset: z.number().int().nonnegative().optional(),
1295
- deep: z.boolean().optional()
1296
- });
1297
- var SymbolField = z.enum(["id", "file_id", "type", "name", "text", "meta", "description", "is_exported", "state", "error"]);
1298
- var SymbolType = z.enum(["function", "class", "class_method", "class_property", "variable", "type"]);
1299
- var SymbolState = z.enum(["to_link", "to_describe", "ready"]);
1300
- var SymbolSearchOptions = z.object({
1301
- select: z.array(SymbolField).optional(),
1302
- limit: z.number().int().positive().optional(),
1303
- offset: z.number().int().nonnegative().optional(),
1304
- where: z.object({
1305
- id: z.number().optional(),
1306
- file_id: z.number().optional(),
1307
- type: z.union([SymbolType, z.object({ contains: z.string() })]).optional(),
1308
- name: StringFilter.optional(),
1309
- text: StringFilter.optional(),
1310
- meta: StringFilter.optional(),
1311
- description: StringFilter.optional(),
1312
- is_exported: z.boolean().optional(),
1313
- state: z.union([SymbolState, z.object({ contains: z.string() })]).optional(),
1314
- error: StringFilter.optional()
1315
- }).optional(),
1316
- order_by: z.tuple([SymbolField, OrderDirection]).optional()
1317
- });
1318
- var SymbolRelationOptions = z.object({
1319
- select: z.array(SymbolField).optional(),
1320
- limit: z.number().int().positive().optional(),
1321
- offset: z.number().int().nonnegative().optional(),
1322
- deep: z.boolean().optional()
1323
- });
1324
- var DirectoryField = z.enum(["id", "parent_id", "path", "description", "state", "error"]);
1325
- var DirectoryState = z.enum(["to_describe", "ready"]);
1326
- var DirectorySearchOptions = z.object({
1327
- select: z.array(DirectoryField).optional(),
1328
- limit: z.number().int().positive().optional(),
1329
- offset: z.number().int().nonnegative().optional(),
1330
- where: z.object({
1331
- id: z.number().optional(),
1332
- parent_id: z.number().optional(),
1333
- path: StringFilter.optional(),
1334
- description: StringFilter.optional(),
1335
- state: z.union([DirectoryState, z.object({ contains: z.string() })]).optional(),
1336
- error: StringFilter.optional()
1337
- }).optional(),
1338
- order_by: z.tuple([DirectoryField, OrderDirection]).optional()
1339
- });
1340
- var DirectoryRelationOptions = z.object({
1341
- select: z.array(DirectoryField).optional(),
1342
- limit: z.number().int().positive().optional(),
1343
- offset: z.number().int().nonnegative().optional(),
1344
- deep: z.boolean().optional()
1345
- });
1346
- var DependencyField = z.enum(["id", "package", "subpath", "name", "version", "github_repo", "is_builtin", "description", "state", "error"]);
1347
- var DependencyState = z.enum(["to_describe", "ready"]);
1348
- var DependencySearchOptions = z.object({
1349
- select: z.array(DependencyField).optional(),
1350
- limit: z.number().int().positive().optional(),
1351
- offset: z.number().int().nonnegative().optional(),
1352
- where: z.object({
1353
- id: z.number().optional(),
1354
- package: StringFilter.optional(),
1355
- subpath: StringFilter.optional(),
1356
- name: StringFilter.optional(),
1357
- version: StringFilter.optional(),
1358
- github_repo: StringFilter.optional(),
1359
- is_builtin: z.boolean().optional(),
1360
- description: StringFilter.optional(),
1361
- state: z.union([DependencyState, z.object({ contains: z.string() })]).optional(),
1362
- error: StringFilter.optional()
1363
- }).optional(),
1364
- order_by: z.tuple([DependencyField, OrderDirection]).optional()
1365
- });
1366
- var DependencySelectOptions = z.object({
1367
- select: z.array(DependencyField).optional(),
1368
- limit: z.number().int().positive().optional(),
1369
- offset: z.number().int().nonnegative().optional()
1370
- });
1371
-
1372
1254
  // src/update/track_changes.ts
1373
1255
  import path3 from "path";
1374
1256
  import "typescript";
@@ -1519,6 +1401,7 @@ import ts4 from "typescript";
1519
1401
  import path4 from "path";
1520
1402
  import ts3 from "typescript";
1521
1403
  function is_external_module(ctx, source_file, module_path) {
1404
+ if (module_path.startsWith("#")) return false;
1522
1405
  const resolved = ts3.resolveModuleName(module_path, source_file.fileName, ctx.program.getCompilerOptions(), ts3.sys);
1523
1406
  if (!resolved.resolvedModule) return true;
1524
1407
  const resolved_path = path4.resolve(resolved.resolvedModule.resolvedFileName);
@@ -2465,6 +2348,21 @@ async function update6(ctx) {
2465
2348
  await link_symbols(ctx);
2466
2349
  }
2467
2350
 
2351
+ // src/update_config.ts
2352
+ function update_config(ctx, config, updates) {
2353
+ if (Object.keys(updates).length === 0) return;
2354
+ const new_config = { ...config, ...updates };
2355
+ err.or_throw(
2356
+ configs_exports.upsert(ctx, {
2357
+ project_path: new_config.project_path,
2358
+ description: new_config.description ?? null,
2359
+ package_json_path: new_config.package_json_path ?? null,
2360
+ node_modules_paths: new_config.node_modules_paths ? JSON.stringify(new_config.node_modules_paths) : null
2361
+ })
2362
+ );
2363
+ Object.assign(config, updates);
2364
+ }
2365
+
2468
2366
  // src/counts.ts
2469
2367
  import { count as count10 } from "drizzle-orm";
2470
2368
  function counts(ctx) {
@@ -2780,19 +2678,6 @@ function directories_to_describe(ctx, limit) {
2780
2678
  }
2781
2679
 
2782
2680
  // src/index.ts
2783
- async function create(config) {
2784
- const ctx = await context_from_config(config);
2785
- return {
2786
- config,
2787
- update: () => update6(ctx),
2788
- counts: () => counts(ctx),
2789
- to_describe: (limit) => to_describe(ctx, limit),
2790
- files: files_wiki(ctx),
2791
- symbols: symbols_wiki(ctx),
2792
- directories: directories_wiki(ctx),
2793
- dependencies: dependencies_wiki(ctx)
2794
- };
2795
- }
2796
2681
  async function load(db_path) {
2797
2682
  const ctx = await context_from_db(db_path);
2798
2683
  const stored = ctx.db.select().from(schema_exports.configs).get();
@@ -2805,6 +2690,7 @@ async function load(db_path) {
2805
2690
  };
2806
2691
  return {
2807
2692
  config,
2693
+ update_config: (updates) => update_config(ctx, config, updates),
2808
2694
  update: () => update6(ctx),
2809
2695
  counts: () => counts(ctx),
2810
2696
  to_describe: (limit) => to_describe(ctx, limit),
@@ -2816,30 +2702,18 @@ async function load(db_path) {
2816
2702
  }
2817
2703
 
2818
2704
  // src/cli/commands/_common.ts
2819
- var config_path = "codewiki.json";
2820
- async function load_wiki() {
2821
- try {
2822
- const content = err.or_throw(env.read_file(config_path));
2823
- const raw_config = err.or_throw(parse_json(content));
2824
- const res = Config.safeParse(raw_config);
2825
- if (!res.success) throw err.new("invalid_config", { errors: res.error.issues });
2826
- const config = res.data;
2827
- if (env.file_exists(config.db_path)) return load(config.db_path);
2828
- return create(config);
2829
- } catch (error) {
2830
- if (error.type === "could_not_read_file") {
2831
- env.error(`Error: Configuration file ${config_path} not found`);
2832
- } else if (error.type === "invalid_json") {
2833
- env.error(`Error: Invalid JSON in ${config_path}`);
2834
- } else if (error.type === "invalid_config") {
2835
- env.error("Error: Invalid configuration");
2836
- } else if (error.message) {
2837
- env.error(`Error: ${error.message}`);
2838
- } else {
2839
- env.error(`Error: ${String(error)}`);
2840
- }
2841
- process.exit(1);
2705
+ function get_db_path(...args) {
2706
+ const cmd = args[args.length - 1];
2707
+ return cmd.optsWithGlobals().db;
2708
+ }
2709
+ async function load_wiki(db_path) {
2710
+ if (!env.file_exists(db_path)) {
2711
+ env.error(`Error: No wiki found at ${db_path}`);
2712
+ env.error(`Run \`codewiki init\` to create one.`);
2713
+ env.exit(1);
2714
+ return void 0;
2842
2715
  }
2716
+ return load(db_path);
2843
2717
  }
2844
2718
  function parse_options(options_json, schema, context) {
2845
2719
  let parsed_json;
@@ -2887,8 +2761,8 @@ function count_text({ total, ...states }) {
2887
2761
  // src/cli/commands/update.ts
2888
2762
  var update7 = new Command("update");
2889
2763
  update7.description("Reads current files and updates the wiki database");
2890
- update7.action(async () => {
2891
- const wiki = await load_wiki();
2764
+ update7.action(async (...args) => {
2765
+ const wiki = await load_wiki(get_db_path(...args));
2892
2766
  await wiki.update();
2893
2767
  env.log("Update complete.\n");
2894
2768
  const counts2 = wiki.counts();
@@ -2900,8 +2774,8 @@ update7.action(async () => {
2900
2774
  import { Command as Command2 } from "commander";
2901
2775
  var status = new Command2("status");
2902
2776
  status.description("Show the status of the wiki");
2903
- status.action(async () => {
2904
- const wiki = await load_wiki();
2777
+ status.action(async (...args) => {
2778
+ const wiki = await load_wiki(get_db_path(...args));
2905
2779
  const counts2 = wiki.counts();
2906
2780
  env.log(format_counts(counts2));
2907
2781
  });
@@ -2911,8 +2785,8 @@ import dedent2 from "dedent";
2911
2785
  import { Command as Command3 } from "commander";
2912
2786
  var describe = new Command3("describe");
2913
2787
  describe.description("Show the next item to describe");
2914
- describe.action(async () => {
2915
- const wiki = await load_wiki();
2788
+ describe.action(async (...args) => {
2789
+ const wiki = await load_wiki(get_db_path(...args));
2916
2790
  const result = wiki.to_describe(1);
2917
2791
  if (result.type === "none") {
2918
2792
  return env.log("All items are described!");
@@ -2992,19 +2866,136 @@ import { Command as Command4 } from "commander";
2992
2866
  var get6 = new Command4("get");
2993
2867
  get6.description("Get a file by ID");
2994
2868
  get6.argument("<id>", "File ID");
2995
- get6.action(async (id) => {
2996
- const wiki = await load_wiki();
2869
+ get6.action(async (...args) => {
2870
+ const [id] = args;
2871
+ const wiki = await load_wiki(get_db_path(...args));
2997
2872
  const file = wiki.files.get(Number(id));
2998
2873
  env.log(JSON.stringify(file, null, 2));
2999
2874
  });
3000
2875
 
3001
2876
  // src/cli/commands/files/search.ts
3002
2877
  import { Command as Command5 } from "commander";
2878
+
2879
+ // src/cli/schema.ts
2880
+ import { z as z2 } from "zod";
2881
+ var Config = z2.object({
2882
+ db_path: z2.string().describe("Path to SQLite database"),
2883
+ project_path: z2.string().describe("Path to TypeScript project"),
2884
+ description: z2.string().optional(),
2885
+ package_json_path: z2.string().optional(),
2886
+ node_modules_paths: z2.array(z2.string()).optional()
2887
+ });
2888
+ var StringFilter = z2.union([
2889
+ z2.string(),
2890
+ z2.object({ contains: z2.string() }),
2891
+ z2.object({ starts_with: z2.string() }),
2892
+ z2.object({ ends_with: z2.string() })
2893
+ ]);
2894
+ var OrderDirection = z2.enum(["asc", "desc"]);
2895
+ var FileField = z2.enum(["id", "directory_id", "path", "description", "state", "error"]);
2896
+ var FileState = z2.enum(["to_scan", "to_describe", "ready"]);
2897
+ var FileSearchOptions = z2.object({
2898
+ select: z2.array(FileField).optional(),
2899
+ limit: z2.number().int().positive().optional(),
2900
+ offset: z2.number().int().nonnegative().optional(),
2901
+ where: z2.object({
2902
+ id: z2.number().optional(),
2903
+ directory_id: z2.number().optional(),
2904
+ path: StringFilter.optional(),
2905
+ description: StringFilter.optional(),
2906
+ state: z2.union([FileState, z2.object({ contains: z2.string() })]).optional(),
2907
+ error: StringFilter.optional()
2908
+ }).optional(),
2909
+ order_by: z2.tuple([FileField, OrderDirection]).optional()
2910
+ });
2911
+ var FileRelationOptions = z2.object({
2912
+ select: z2.array(FileField).optional(),
2913
+ limit: z2.number().int().positive().optional(),
2914
+ offset: z2.number().int().nonnegative().optional(),
2915
+ deep: z2.boolean().optional()
2916
+ });
2917
+ var SymbolField = z2.enum(["id", "file_id", "type", "name", "text", "meta", "description", "is_exported", "state", "error"]);
2918
+ var SymbolType = z2.enum(["function", "class", "class_method", "class_property", "variable", "type"]);
2919
+ var SymbolState = z2.enum(["to_link", "to_describe", "ready"]);
2920
+ var SymbolSearchOptions = z2.object({
2921
+ select: z2.array(SymbolField).optional(),
2922
+ limit: z2.number().int().positive().optional(),
2923
+ offset: z2.number().int().nonnegative().optional(),
2924
+ where: z2.object({
2925
+ id: z2.number().optional(),
2926
+ file_id: z2.number().optional(),
2927
+ type: z2.union([SymbolType, z2.object({ contains: z2.string() })]).optional(),
2928
+ name: StringFilter.optional(),
2929
+ text: StringFilter.optional(),
2930
+ meta: StringFilter.optional(),
2931
+ description: StringFilter.optional(),
2932
+ is_exported: z2.boolean().optional(),
2933
+ state: z2.union([SymbolState, z2.object({ contains: z2.string() })]).optional(),
2934
+ error: StringFilter.optional()
2935
+ }).optional(),
2936
+ order_by: z2.tuple([SymbolField, OrderDirection]).optional()
2937
+ });
2938
+ var SymbolRelationOptions = z2.object({
2939
+ select: z2.array(SymbolField).optional(),
2940
+ limit: z2.number().int().positive().optional(),
2941
+ offset: z2.number().int().nonnegative().optional(),
2942
+ deep: z2.boolean().optional()
2943
+ });
2944
+ var DirectoryField = z2.enum(["id", "parent_id", "path", "description", "state", "error"]);
2945
+ var DirectoryState = z2.enum(["to_describe", "ready"]);
2946
+ var DirectorySearchOptions = z2.object({
2947
+ select: z2.array(DirectoryField).optional(),
2948
+ limit: z2.number().int().positive().optional(),
2949
+ offset: z2.number().int().nonnegative().optional(),
2950
+ where: z2.object({
2951
+ id: z2.number().optional(),
2952
+ parent_id: z2.number().optional(),
2953
+ path: StringFilter.optional(),
2954
+ description: StringFilter.optional(),
2955
+ state: z2.union([DirectoryState, z2.object({ contains: z2.string() })]).optional(),
2956
+ error: StringFilter.optional()
2957
+ }).optional(),
2958
+ order_by: z2.tuple([DirectoryField, OrderDirection]).optional()
2959
+ });
2960
+ var DirectoryRelationOptions = z2.object({
2961
+ select: z2.array(DirectoryField).optional(),
2962
+ limit: z2.number().int().positive().optional(),
2963
+ offset: z2.number().int().nonnegative().optional(),
2964
+ deep: z2.boolean().optional()
2965
+ });
2966
+ var DependencyField = z2.enum(["id", "package", "subpath", "name", "version", "github_repo", "is_builtin", "description", "state", "error"]);
2967
+ var DependencyState = z2.enum(["to_describe", "ready"]);
2968
+ var DependencySearchOptions = z2.object({
2969
+ select: z2.array(DependencyField).optional(),
2970
+ limit: z2.number().int().positive().optional(),
2971
+ offset: z2.number().int().nonnegative().optional(),
2972
+ where: z2.object({
2973
+ id: z2.number().optional(),
2974
+ package: StringFilter.optional(),
2975
+ subpath: StringFilter.optional(),
2976
+ name: StringFilter.optional(),
2977
+ version: StringFilter.optional(),
2978
+ github_repo: StringFilter.optional(),
2979
+ is_builtin: z2.boolean().optional(),
2980
+ description: StringFilter.optional(),
2981
+ state: z2.union([DependencyState, z2.object({ contains: z2.string() })]).optional(),
2982
+ error: StringFilter.optional()
2983
+ }).optional(),
2984
+ order_by: z2.tuple([DependencyField, OrderDirection]).optional()
2985
+ });
2986
+ var DependencySelectOptions = z2.object({
2987
+ select: z2.array(DependencyField).optional(),
2988
+ limit: z2.number().int().positive().optional(),
2989
+ offset: z2.number().int().nonnegative().optional()
2990
+ });
2991
+
2992
+ // src/cli/commands/files/search.ts
3003
2993
  var search13 = new Command5("search");
3004
2994
  search13.description("Search files with JSON options");
3005
2995
  search13.argument("<options>", "JSON options for search");
3006
- search13.action(async (options_json) => {
3007
- const wiki = await load_wiki();
2996
+ search13.action(async (...args) => {
2997
+ const [options_json] = args;
2998
+ const wiki = await load_wiki(get_db_path(...args));
3008
2999
  const options = parse_options(options_json, FileSearchOptions, "files search");
3009
3000
  const results = wiki.files.search(options);
3010
3001
  env.log(JSON.stringify(results, null, 2));
@@ -3017,8 +3008,9 @@ var set_description5 = new Command6("set-description");
3017
3008
  set_description5.description("Set description for a file");
3018
3009
  set_description5.argument("<file-id>", "File ID");
3019
3010
  set_description5.argument("<markdown-file>", "Path to markdown file");
3020
- set_description5.action(async (id, file) => {
3021
- const wiki = await load_wiki();
3011
+ set_description5.action(async (...args) => {
3012
+ const [id, file] = args;
3013
+ const wiki = await load_wiki(get_db_path(...args));
3022
3014
  try {
3023
3015
  const content = readFileSync2(file, "utf-8");
3024
3016
  wiki.files.set_description(Number(id), content);
@@ -3035,8 +3027,9 @@ var imported_by_file2 = new Command7("imported-by-file");
3035
3027
  imported_by_file2.description("Files imported by the given file");
3036
3028
  imported_by_file2.argument("<file-id>", "File ID");
3037
3029
  imported_by_file2.argument("<options>", "JSON options");
3038
- imported_by_file2.action(async (file_id, options_json) => {
3039
- const wiki = await load_wiki();
3030
+ imported_by_file2.action(async (...args) => {
3031
+ const [file_id, options_json] = args;
3032
+ const wiki = await load_wiki(get_db_path(...args));
3040
3033
  const options = parse_options(options_json, FileRelationOptions, "files imported-by-file");
3041
3034
  const results = wiki.files.imported_by_file(Number(file_id), options);
3042
3035
  env.log(JSON.stringify(results, null, 2));
@@ -3048,8 +3041,9 @@ var importing_file2 = new Command8("importing-file");
3048
3041
  importing_file2.description("Files importing the given file");
3049
3042
  importing_file2.argument("<file-id>", "File ID");
3050
3043
  importing_file2.argument("<options>", "JSON options");
3051
- importing_file2.action(async (file_id, options_json) => {
3052
- const wiki = await load_wiki();
3044
+ importing_file2.action(async (...args) => {
3045
+ const [file_id, options_json] = args;
3046
+ const wiki = await load_wiki(get_db_path(...args));
3053
3047
  const options = parse_options(options_json, FileRelationOptions, "files importing-file");
3054
3048
  const results = wiki.files.importing_file(Number(file_id), options);
3055
3049
  env.log(JSON.stringify(results, null, 2));
@@ -3061,8 +3055,9 @@ var importing_dependency2 = new Command9("importing-dependency");
3061
3055
  importing_dependency2.description("Files importing the given dependency");
3062
3056
  importing_dependency2.argument("<dep-id>", "Dependency ID");
3063
3057
  importing_dependency2.argument("<options>", "JSON options");
3064
- importing_dependency2.action(async (dep_id, options_json) => {
3065
- const wiki = await load_wiki();
3058
+ importing_dependency2.action(async (...args) => {
3059
+ const [dep_id, options_json] = args;
3060
+ const wiki = await load_wiki(get_db_path(...args));
3066
3061
  const options = parse_options(options_json, FileRelationOptions, "files importing-dependency");
3067
3062
  const results = wiki.files.importing_dependency(Number(dep_id), options);
3068
3063
  env.log(JSON.stringify(results, null, 2));
@@ -3115,8 +3110,9 @@ import { Command as Command11 } from "commander";
3115
3110
  var get7 = new Command11("get");
3116
3111
  get7.description("Get a symbol by ID");
3117
3112
  get7.argument("<id>", "Symbol ID");
3118
- get7.action(async (id) => {
3119
- const wiki = await load_wiki();
3113
+ get7.action(async (...args) => {
3114
+ const [id] = args;
3115
+ const wiki = await load_wiki(get_db_path(...args));
3120
3116
  const symbol = wiki.symbols.get(Number(id));
3121
3117
  env.log(JSON.stringify(symbol, null, 2));
3122
3118
  });
@@ -3126,8 +3122,9 @@ import { Command as Command12 } from "commander";
3126
3122
  var search14 = new Command12("search");
3127
3123
  search14.description("Search symbols with JSON options");
3128
3124
  search14.argument("<options>", "JSON options");
3129
- search14.action(async (options_json) => {
3130
- const wiki = await load_wiki();
3125
+ search14.action(async (...args) => {
3126
+ const [options_json] = args;
3127
+ const wiki = await load_wiki(get_db_path(...args));
3131
3128
  const options = parse_options(options_json, SymbolSearchOptions, "symbols search");
3132
3129
  const results = wiki.symbols.search(options);
3133
3130
  env.log(JSON.stringify(results, null, 2));
@@ -3140,8 +3137,9 @@ var set_description6 = new Command13("set-description");
3140
3137
  set_description6.description("Set description for a symbol");
3141
3138
  set_description6.argument("<symbol-id>", "Symbol ID");
3142
3139
  set_description6.argument("<markdown-file>", "Path to markdown file");
3143
- set_description6.action(async (id, file) => {
3144
- const wiki = await load_wiki();
3140
+ set_description6.action(async (...args) => {
3141
+ const [id, file] = args;
3142
+ const wiki = await load_wiki(get_db_path(...args));
3145
3143
  try {
3146
3144
  const content = readFileSync3(file, "utf-8");
3147
3145
  wiki.symbols.set_description(Number(id), content);
@@ -3158,8 +3156,9 @@ var referencing_symbol2 = new Command14("referencing-symbol");
3158
3156
  referencing_symbol2.description("Symbols referencing the given symbol");
3159
3157
  referencing_symbol2.argument("<symbol-id>", "Symbol ID");
3160
3158
  referencing_symbol2.argument("<options>", "JSON options");
3161
- referencing_symbol2.action(async (symbol_id, options_json) => {
3162
- const wiki = await load_wiki();
3159
+ referencing_symbol2.action(async (...args) => {
3160
+ const [symbol_id, options_json] = args;
3161
+ const wiki = await load_wiki(get_db_path(...args));
3163
3162
  const options = parse_options(options_json, SymbolRelationOptions, "symbols referencing-symbol");
3164
3163
  const results = wiki.symbols.referencing_symbol(Number(symbol_id), options);
3165
3164
  env.log(JSON.stringify(results, null, 2));
@@ -3171,8 +3170,9 @@ var referenced_by_symbol2 = new Command15("referenced-by-symbol");
3171
3170
  referenced_by_symbol2.description("Symbols referenced by the given symbol");
3172
3171
  referenced_by_symbol2.argument("<symbol-id>", "Symbol ID");
3173
3172
  referenced_by_symbol2.argument("<options>", "JSON options");
3174
- referenced_by_symbol2.action(async (symbol_id, options_json) => {
3175
- const wiki = await load_wiki();
3173
+ referenced_by_symbol2.action(async (...args) => {
3174
+ const [symbol_id, options_json] = args;
3175
+ const wiki = await load_wiki(get_db_path(...args));
3176
3176
  const options = parse_options(options_json, SymbolRelationOptions, "symbols referenced-by-symbol");
3177
3177
  const results = wiki.symbols.referenced_by_symbol(Number(symbol_id), options);
3178
3178
  env.log(JSON.stringify(results, null, 2));
@@ -3184,8 +3184,9 @@ var using_dependency4 = new Command16("using-dependency");
3184
3184
  using_dependency4.description("Symbols using the given dependency");
3185
3185
  using_dependency4.argument("<dep-id>", "Dependency ID");
3186
3186
  using_dependency4.argument("<options>", "JSON options");
3187
- using_dependency4.action(async (dep_id, options_json) => {
3188
- const wiki = await load_wiki();
3187
+ using_dependency4.action(async (...args) => {
3188
+ const [dep_id, options_json] = args;
3189
+ const wiki = await load_wiki(get_db_path(...args));
3189
3190
  const options = parse_options(options_json, SymbolRelationOptions, "symbols using-dependency");
3190
3191
  const results = wiki.symbols.using_dependency(Number(dep_id), options);
3191
3192
  env.log(JSON.stringify(results, null, 2));
@@ -3238,8 +3239,9 @@ import { Command as Command18 } from "commander";
3238
3239
  var get8 = new Command18("get");
3239
3240
  get8.description("Get a directory by ID");
3240
3241
  get8.argument("<id>", "Directory ID");
3241
- get8.action(async (id) => {
3242
- const wiki = await load_wiki();
3242
+ get8.action(async (...args) => {
3243
+ const [id] = args;
3244
+ const wiki = await load_wiki(get_db_path(...args));
3243
3245
  const directory = wiki.directories.get(Number(id));
3244
3246
  env.log(JSON.stringify(directory, null, 2));
3245
3247
  });
@@ -3249,8 +3251,9 @@ import { Command as Command19 } from "commander";
3249
3251
  var search15 = new Command19("search");
3250
3252
  search15.description("Search directories with JSON options");
3251
3253
  search15.argument("<options>", "JSON options");
3252
- search15.action(async (options_json) => {
3253
- const wiki = await load_wiki();
3254
+ search15.action(async (...args) => {
3255
+ const [options_json] = args;
3256
+ const wiki = await load_wiki(get_db_path(...args));
3254
3257
  const options = parse_options(options_json, DirectorySearchOptions, "directories search");
3255
3258
  const results = wiki.directories.search(options);
3256
3259
  env.log(JSON.stringify(results, null, 2));
@@ -3263,8 +3266,9 @@ var set_description7 = new Command20("set-description");
3263
3266
  set_description7.description("Set description for a directory");
3264
3267
  set_description7.argument("<directory-id>", "Directory ID");
3265
3268
  set_description7.argument("<markdown-file>", "Path to markdown file");
3266
- set_description7.action(async (id, file) => {
3267
- const wiki = await load_wiki();
3269
+ set_description7.action(async (...args) => {
3270
+ const [id, file] = args;
3271
+ const wiki = await load_wiki(get_db_path(...args));
3268
3272
  try {
3269
3273
  const content = readFileSync4(file, "utf-8");
3270
3274
  wiki.directories.set_description(Number(id), content);
@@ -3281,8 +3285,9 @@ var children2 = new Command21("children");
3281
3285
  children2.description("Child directories of the given directory");
3282
3286
  children2.argument("<parent-id>", "Parent directory ID");
3283
3287
  children2.argument("<options>", "JSON options");
3284
- children2.action(async (parent_id, options_json) => {
3285
- const wiki = await load_wiki();
3288
+ children2.action(async (...args) => {
3289
+ const [parent_id, options_json] = args;
3290
+ const wiki = await load_wiki(get_db_path(...args));
3286
3291
  const options = parse_options(options_json, DirectoryRelationOptions, "directories children");
3287
3292
  const results = wiki.directories.children(Number(parent_id), options);
3288
3293
  env.log(JSON.stringify(results, null, 2));
@@ -3294,8 +3299,9 @@ var files4 = new Command22("files");
3294
3299
  files4.description("Files in the given directory");
3295
3300
  files4.argument("<directory-id>", "Directory ID");
3296
3301
  files4.argument("<options>", "JSON options");
3297
- files4.action(async (directory_id, options_json) => {
3298
- const wiki = await load_wiki();
3302
+ files4.action(async (...args) => {
3303
+ const [directory_id, options_json] = args;
3304
+ const wiki = await load_wiki(get_db_path(...args));
3299
3305
  const options = parse_options(options_json, FileRelationOptions, "directories files");
3300
3306
  const results = wiki.directories.files(Number(directory_id), options);
3301
3307
  env.log(JSON.stringify(results, null, 2));
@@ -3347,8 +3353,9 @@ import { Command as Command24 } from "commander";
3347
3353
  var get9 = new Command24("get");
3348
3354
  get9.description("Get a dependency by ID");
3349
3355
  get9.argument("<id>", "Dependency ID");
3350
- get9.action(async (id) => {
3351
- const wiki = await load_wiki();
3356
+ get9.action(async (...args) => {
3357
+ const [id] = args;
3358
+ const wiki = await load_wiki(get_db_path(...args));
3352
3359
  const dependency = wiki.dependencies.get(Number(id));
3353
3360
  env.log(JSON.stringify(dependency, null, 2));
3354
3361
  });
@@ -3358,8 +3365,9 @@ import { Command as Command25 } from "commander";
3358
3365
  var search16 = new Command25("search");
3359
3366
  search16.description("Search dependencies with JSON options");
3360
3367
  search16.argument("<options>", "JSON options");
3361
- search16.action(async (options_json) => {
3362
- const wiki = await load_wiki();
3368
+ search16.action(async (...args) => {
3369
+ const [options_json] = args;
3370
+ const wiki = await load_wiki(get_db_path(...args));
3363
3371
  const options = parse_options(options_json, DependencySearchOptions, "dependencies search");
3364
3372
  const results = wiki.dependencies.search(options);
3365
3373
  env.log(JSON.stringify(results, null, 2));
@@ -3372,8 +3380,9 @@ var set_description8 = new Command26("set-description");
3372
3380
  set_description8.description("Set description for a dependency");
3373
3381
  set_description8.argument("<dependency-id>", "Dependency ID");
3374
3382
  set_description8.argument("<markdown-file>", "Path to markdown file");
3375
- set_description8.action(async (id, file) => {
3376
- const wiki = await load_wiki();
3383
+ set_description8.action(async (...args) => {
3384
+ const [id, file] = args;
3385
+ const wiki = await load_wiki(get_db_path(...args));
3377
3386
  try {
3378
3387
  const content = readFileSync5(file, "utf-8");
3379
3388
  wiki.dependencies.set_description(Number(id), content);
@@ -3390,8 +3399,9 @@ var used_by_file3 = new Command27("used-by-file");
3390
3399
  used_by_file3.description("Dependencies used by the given file");
3391
3400
  used_by_file3.argument("<file-id>", "File ID");
3392
3401
  used_by_file3.argument("<options>", "JSON options");
3393
- used_by_file3.action(async (file_id, options_json) => {
3394
- const wiki = await load_wiki();
3402
+ used_by_file3.action(async (...args) => {
3403
+ const [file_id, options_json] = args;
3404
+ const wiki = await load_wiki(get_db_path(...args));
3395
3405
  const options = parse_options(options_json, DependencySelectOptions, "dependencies used-by-file");
3396
3406
  const results = wiki.dependencies.used_by_file(Number(file_id), options);
3397
3407
  env.log(JSON.stringify(results, null, 2));
@@ -3403,8 +3413,9 @@ var used_by_symbol3 = new Command28("used-by-symbol");
3403
3413
  used_by_symbol3.description("Dependencies used by the given symbol");
3404
3414
  used_by_symbol3.argument("<symbol-id>", "Symbol ID");
3405
3415
  used_by_symbol3.argument("<options>", "JSON options");
3406
- used_by_symbol3.action(async (symbol_id, options_json) => {
3407
- const wiki = await load_wiki();
3416
+ used_by_symbol3.action(async (...args) => {
3417
+ const [symbol_id, options_json] = args;
3418
+ const wiki = await load_wiki(get_db_path(...args));
3408
3419
  const options = parse_options(options_json, DependencySelectOptions, "dependencies used-by-symbol");
3409
3420
  const results = wiki.dependencies.used_by_symbol(Number(symbol_id), options);
3410
3421
  env.log(JSON.stringify(results, null, 2));
@@ -3453,6 +3464,7 @@ var commands = [update7, status, describe, files3, symbols3, directories3, depen
3453
3464
  async function run(argv) {
3454
3465
  const program = new Command30();
3455
3466
  program.name("codewiki").description("Describe and explore TypeScript codebases").version("0.0.1");
3467
+ program.option("--db <path>", "Database location", "./wiki.db");
3456
3468
  for (const cmd of commands) program.addCommand(cmd);
3457
3469
  return program.parseAsync(argv, { from: "user" });
3458
3470
  }