versioned-d.ts-tools 0.5.0 → 0.6.0

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 CHANGED
@@ -107,7 +107,7 @@ This generates a markdown file (e.g., `excel_whats_new.md`) containing a table s
107
107
 
108
108
  #### Link Configuration File
109
109
 
110
- You can provide an optional JSON configuration file to customize how URLs are generated for different API types. This is useful when different Office applications have different URL patterns.
110
+ You can provide an optional JSON configuration file to customize how URLs are generated for different API types using flexible templates with placeholders.
111
111
 
112
112
  **Configuration file format:**
113
113
 
@@ -117,21 +117,37 @@ You can provide an optional JSON configuration file to customize how URLs are ge
117
117
  {
118
118
  "name": "Office Scripts",
119
119
  "pathPattern": "office-scripts",
120
- "description": "Special URL pattern for Office Scripts"
120
+ "description": "Special URL pattern for Office Scripts",
121
+ "globalFunctionTemplate": "/{basePath}#officescript-officescript-{fieldName}-function(1)",
122
+ "classTemplate": "/{basePath}/officescript.{className}",
123
+ "classMemberTemplate": "/{basePath}/officescript.{className}#officescript-officescript-{className}-{fieldName}{suffix}"
121
124
  },
122
125
  {
123
126
  "name": "Standard Office Applications",
124
127
  "pathPattern": ".*",
125
- "description": "Standard URL pattern for Excel, Word, PowerPoint, Outlook"
128
+ "description": "Standard URL pattern for Excel, Word, PowerPoint, Outlook",
129
+ "globalFunctionTemplate": "/{basePath}#{hostName}-{fileName}-{fieldName}-function(1)",
130
+ "classTemplate": "/{basePath}.{className}",
131
+ "classMemberTemplate": "/{basePath}.{className}#{hostName}-{fileName}-{className}-{fieldName}{suffix}"
126
132
  }
127
133
  ]
128
134
  }
129
135
  ```
130
136
 
131
- When a configuration file is provided, the tool will use the appropriate URL pattern based on the relative path. For example:
137
+ **Available Template Placeholders:**
138
+ - `{basePath}` - relativePath without the trailing dot (e.g., 'javascript/api/excel/excel')
139
+ - `{hostName}` - extracted host name (e.g., 'excel', 'office-scripts')
140
+ - `{fileName}` - extracted file name (e.g., 'excel', 'officescript')
141
+ - `{className}` - class name in lowercase
142
+ - `{fieldName}` - field/method name in lowercase
143
+ - `{suffix}` - '-member(1)' for methods/functions, '-member' for properties
132
144
 
133
- - Office Scripts APIs will use the Office Scripts-specific URL format
134
- - Other Office applications will use the standard URL format
145
+ **Template Types:**
146
+ - `globalFunctionTemplate` - For namespace-level functions (global functions)
147
+ - `classTemplate` - For class/interface URLs in the first column
148
+ - `classMemberTemplate` - For class members (methods, properties, events)
149
+
150
+ When a configuration file is provided, the tool will use the appropriate URL template based on the pattern matching. The first matching `pathPattern` (regex) wins.
135
151
 
136
152
  See `example-link-config.json` for a complete example.
137
153
 
@@ -1,6 +1,8 @@
1
1
  export interface LinkConfig {
2
2
  pathPattern: string;
3
- buildLink: (relativePath: string, className: string, field: FieldStruct) => string;
3
+ globalFunctionTemplate: string;
4
+ classTemplate: string;
5
+ classMemberTemplate: string;
4
6
  }
5
7
  export declare const DEFAULT_LINK_CONFIGS: LinkConfig[];
6
8
  declare enum ClassType {
@@ -36,47 +36,48 @@ Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.APISet = exports.DEFAULT_LINK_CONFIGS = void 0;
37
37
  exports.parseDTS = parseDTS;
38
38
  const ts = __importStar(require("typescript"));
39
- // Default link builder for Office Scripts
40
- function buildOfficeScriptsLink(relativePath, className, field) {
41
- if (className === "<global>") {
42
- const basePath = relativePath.substring(0, relativePath.lastIndexOf("."));
43
- return "/" + basePath + "#officescript-officescript-" + field.name.toLowerCase() + "-function(1)";
39
+ // Available placeholders:
40
+ // {basePath} - relativePath without the trailing dot
41
+ // {hostName} - extracted host name (e.g., "excel", "office-scripts")
42
+ // {fileName} - extracted file name (e.g., "excel", "officescript")
43
+ // {className} - class name in lowercase
44
+ // {fieldName} - field/method name in lowercase
45
+ // {suffix} - "-member(1)" for methods/functions, "-member" for properties
46
+ // Default link builder using templates
47
+ function buildLinkFromTemplate(template, relativePath, className, field) {
48
+ const basePath = relativePath.substring(0, relativePath.lastIndexOf("."));
49
+ const hostName = relativePath.includes("/api/")
50
+ ? relativePath.substring(relativePath.indexOf("/api/") + 5, relativePath.lastIndexOf("/"))
51
+ : "";
52
+ const fileName = relativePath.substring(relativePath.lastIndexOf("/") + 1, relativePath.lastIndexOf("."));
53
+ let result = template
54
+ .replace(/{basePath}/g, basePath)
55
+ .replace(/{hostName}/g, hostName)
56
+ .replace(/{fileName}/g, fileName);
57
+ if (className && className !== "<global>") {
58
+ result = result.replace(/{className}/g, className.toLowerCase());
44
59
  }
45
- else {
46
- const suffix = (field.type === FieldType.Method || field.type === FieldType.Function) ? "-member(1)" : "-member";
47
- const url = "/" + relativePath + className.toLowerCase();
48
- const anchor = "officescript-officescript-" + className.toLowerCase() + "-" + field.name.toLowerCase() + suffix;
49
- return url + "#" + anchor;
50
- }
51
- }
52
- // Default link builder for standard Office applications
53
- function buildStandardLink(relativePath, className, field) {
54
- if (className === "<global>") {
55
- const hostName = relativePath.substring(relativePath.indexOf("/api/") + 5, relativePath.lastIndexOf("/"));
56
- const fileName = relativePath.substring(relativePath.lastIndexOf("/") + 1, relativePath.lastIndexOf("."));
57
- const basePath = relativePath.substring(0, relativePath.lastIndexOf("."));
58
- const anchorPrefix = hostName + "-" + fileName + "-";
59
- return "/" + basePath + "#" + anchorPrefix + field.name.toLowerCase() + "-function(1)";
60
- }
61
- else {
62
- const hostName = relativePath.substring(relativePath.indexOf("/api/") + 5, relativePath.lastIndexOf("/"));
63
- const fileName = relativePath.substring(relativePath.lastIndexOf("/") + 1, relativePath.lastIndexOf("."));
60
+ if (field) {
64
61
  const suffix = (field.type === FieldType.Method || field.type === FieldType.Function) ? "-member(1)" : "-member";
65
- const url = "/" + relativePath + className.toLowerCase();
66
- const anchorPrefix = hostName + "-" + fileName + "-";
67
- const anchor = anchorPrefix + className.toLowerCase() + "-" + field.name.toLowerCase() + suffix;
68
- return url + "#" + anchor;
62
+ result = result
63
+ .replace(/{fieldName}/g, field.name.toLowerCase())
64
+ .replace(/{suffix}/g, suffix);
69
65
  }
66
+ return result;
70
67
  }
71
68
  // Default configurations for known Office applications
72
69
  exports.DEFAULT_LINK_CONFIGS = [
73
70
  {
74
71
  pathPattern: "office-scripts",
75
- buildLink: buildOfficeScriptsLink
72
+ globalFunctionTemplate: "/{basePath}#officescript-officescript-{fieldName}-function(1)",
73
+ classTemplate: "/{basePath}/officescript.{className}",
74
+ classMemberTemplate: "/{basePath}/officescript.{className}#officescript-officescript-{className}-{fieldName}{suffix}"
76
75
  },
77
76
  {
78
77
  pathPattern: ".*", // matches any path as fallback
79
- buildLink: buildStandardLink
78
+ globalFunctionTemplate: "/{basePath}#{hostName}-{fileName}-{fieldName}-function(1)",
79
+ classTemplate: "/{basePath}.{className}",
80
+ classMemberTemplate: "/{basePath}.{className}#{hostName}-{fileName}-{className}-{fieldName}{suffix}"
80
81
  }
81
82
  ];
82
83
  // capturing these because of eccentricities with the compiler ordering
@@ -217,8 +218,8 @@ class APISet {
217
218
  output += "|*global*|";
218
219
  }
219
220
  else {
220
- output += "|[" + className + "](/"
221
- + relativePath + className.toLowerCase() + ")|";
221
+ output += "|[" + className + "]("
222
+ + buildClassLink(relativePath, className, linkConfigs) + ")|";
222
223
  }
223
224
  // Ignore the following:
224
225
  // - String literal overloads.
@@ -320,11 +321,21 @@ function removeAtLink(commentText) {
320
321
  commentText = commentText.replace(/{@link ([^}]*?) \| (http.*?)}/gm, "[$1]($2)");
321
322
  return commentText;
322
323
  }
324
+ function buildClassLink(relativePath, className, linkConfigs = exports.DEFAULT_LINK_CONFIGS) {
325
+ // Find the first matching configuration
326
+ const config = linkConfigs.find(config => new RegExp(config.pathPattern).test(relativePath)) || exports.DEFAULT_LINK_CONFIGS[exports.DEFAULT_LINK_CONFIGS.length - 1]; // fallback to last config
327
+ return buildLinkFromTemplate(config.classTemplate, relativePath, className);
328
+ }
323
329
  function buildFieldLink(relativePath, className, field, linkConfigs = exports.DEFAULT_LINK_CONFIGS) {
324
330
  // Find the first matching configuration
325
331
  const config = linkConfigs.find(config => new RegExp(config.pathPattern).test(relativePath)) || exports.DEFAULT_LINK_CONFIGS[exports.DEFAULT_LINK_CONFIGS.length - 1]; // fallback to last config
326
- // Use the configuration's link builder
327
- return config.buildLink(relativePath, className, field);
332
+ // Use appropriate template based on whether it's a global function or class member
333
+ if (className.trim() === "<global>") {
334
+ return buildLinkFromTemplate(config.globalFunctionTemplate, relativePath, className, field);
335
+ }
336
+ else {
337
+ return buildLinkFromTemplate(config.classMemberTemplate, relativePath, className, field);
338
+ }
328
339
  }
329
340
  function parseDTS(fileName, fileContents) {
330
341
  // Reset global state for new parse
package/dist/whats-new.js CHANGED
@@ -46,17 +46,18 @@ function loadLinkConfig(configFilePath) {
46
46
  try {
47
47
  const configContent = fsx.readFileSync(configFilePath, 'utf8');
48
48
  const config = JSON.parse(configContent);
49
- // Convert the config to LinkConfig objects with actual functions
50
- return config.linkConfigs.map((item) => ({
51
- pathPattern: new RegExp(item.pathPattern),
52
- buildLink: item.pathPattern === "office-scripts"
53
- ? (namespace, className) => className === "*global*"
54
- ? `/javascript/api/office-scripts/officescript/officescript#officescript-officescript-${namespace.toLowerCase()}-function(1)`
55
- : `/javascript/api/office-scripts/officescript/officescript.${className.toLowerCase()}#officescript-officescript-${className.toLowerCase()}-${namespace.toLowerCase()}-member(1)`
56
- : (namespace, className) => className === "*global*"
57
- ? `/javascript/api/${namespace}/${namespace}#${namespace}-${namespace}-${namespace.toLowerCase()}-function(1)`
58
- : `/javascript/api/${namespace}/${namespace}.${className.toLowerCase()}#${namespace}-${namespace}-${className.toLowerCase()}-${namespace.toLowerCase()}-member(1)`
59
- }));
49
+ // Validate that the config has the required template properties
50
+ return config.linkConfigs.map((item) => {
51
+ if (!item.globalFunctionTemplate || !item.classTemplate || !item.classMemberTemplate) {
52
+ throw new Error(`Configuration item missing required template properties: ${JSON.stringify(item)}`);
53
+ }
54
+ return {
55
+ pathPattern: item.pathPattern,
56
+ globalFunctionTemplate: item.globalFunctionTemplate,
57
+ classTemplate: item.classTemplate,
58
+ classMemberTemplate: item.classMemberTemplate
59
+ };
60
+ });
60
61
  }
61
62
  catch (error) {
62
63
  console.warn(`Could not load config file ${configFilePath}: ${error}. Using default configuration.`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "versioned-d.ts-tools",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "description": "Tools for managing versioned TypeScript definition files",
5
5
  "main": "dist/index.js",
6
6
  "bin": {