-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ref: First-party TypeScript definitions #3166
- Loading branch information
Showing
10 changed files
with
1,634 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
const ts = require('typescript'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
// Load and parse the TypeScript definition file from node_modules | ||
const fileName = path.resolve(__dirname, '..', 'node_modules', '@types', 'cytoscape', 'index.d.ts'); | ||
const sourceFile = ts.createSourceFile( | ||
fileName, | ||
fs.readFileSync(fileName, 'utf8'), | ||
ts.ScriptTarget.Latest, | ||
true | ||
); | ||
|
||
// Helper function to recursively extract function names | ||
function extractFunctions(node, parentName = '') { | ||
let functions = []; | ||
|
||
function getQualifiedName(name) { | ||
return parentName ? `${parentName}.${name}` : name; | ||
} | ||
|
||
if (ts.isInterfaceDeclaration(node) || ts.isModuleDeclaration(node)) { | ||
const name = node.name.text; | ||
ts.forEachChild(node, child => { | ||
functions = functions.concat(extractFunctions(child, getQualifiedName(name))); | ||
}); | ||
} else if (ts.isMethodSignature(node) || (ts.isPropertySignature(node) && ts.isFunctionTypeNode(node.type))) { | ||
const name = node.name.text; | ||
functions.push(getQualifiedName(name)); | ||
} else { | ||
ts.forEachChild(node, child => { | ||
functions = functions.concat(extractFunctions(child, parentName)); | ||
}); | ||
} | ||
|
||
return functions; | ||
} | ||
|
||
// Extract functions from the source file | ||
const functions = extractFunctions(sourceFile); | ||
|
||
// Filter out options and results entries | ||
const filteredFunctions = functions.filter(fn => { | ||
return !fn.includes('Options') && !fn.includes('Result'); | ||
}); | ||
|
||
// Format the function names according to the API documentation style | ||
const formattedFunctions = filteredFunctions.map(fn => { | ||
if (fn.startsWith('cytoscape.Core')) { | ||
return 'cy.' + fn.split('.').slice(2).join('.'); | ||
} else if (fn.startsWith('cytoscape.Collection')) { | ||
return 'eles.' + fn.split('.').slice(2).join('.'); | ||
} else if (fn.startsWith('cytoscape.Singular')) { | ||
return 'ele.' + fn.split('.').slice(2).join('.'); | ||
} else if (fn.startsWith('cytoscape.EdgeSingular')) { | ||
return 'edge.' + fn.split('.').slice(2).join('.'); | ||
} else if (fn.startsWith('cytoscape.EdgeCollection')) { | ||
return 'edges.' + fn.split('.').slice(2).join('.'); | ||
} else if (fn.startsWith('cytoscape.NodeSingular')) { | ||
return 'node.' + fn.split('.').slice(2).join('.'); | ||
} else if (fn.startsWith('cytoscape.NodeCollection')) { | ||
return 'nodes.' + fn.split('.').slice(2).join('.'); | ||
} else if (fn.startsWith('cytoscape.AbstractEventObject')) { | ||
return 'event.' + fn.split('.').slice(2).join('.'); | ||
} else if (fn.startsWith('cytoscape.LayoutManipulation') || fn.startsWith('cytoscape.LayoutEvents')) { | ||
return 'layout.' + fn.split('.').slice(2).join('.'); | ||
} else if (fn.startsWith('cytoscape.AnimationManipulation')) { | ||
return 'ani.' + fn.split('.').slice(2).join('.'); | ||
} else if (fn.startsWith('cytoscape.Style')) { | ||
return 'style.' + fn.split('.').slice(2).join('.'); | ||
} else if (fn.startsWith('cytoscape.ElementStylesheetStyle')) { | ||
return 'stylesheet.' + fn.split('.').slice(2).join('.'); | ||
} else if (fn.startsWith('cytoscape.ElementStylesheetCSS')) { | ||
return 'style.' + fn.split('.').slice(2).join('.'); | ||
} | ||
return fn; | ||
}); | ||
|
||
// Sort the formatted functions alphabetically | ||
const sortedFunctions = formattedFunctions.sort(); | ||
|
||
// Output the functions as JSON | ||
console.log(JSON.stringify(sortedFunctions, null, 2)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
const ts = require('typescript'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
// Load and parse the TypeScript definition file from node_modules | ||
const fileName = path.resolve(__dirname, '..', 'node_modules', '@types', 'cytoscape', 'index.d.ts'); | ||
const sourceFile = ts.createSourceFile( | ||
fileName, | ||
fs.readFileSync(fileName, 'utf8'), | ||
ts.ScriptTarget.Latest, | ||
true | ||
); | ||
|
||
// Helper function to recursively find the Css namespace | ||
function findCssNamespace(node) { | ||
let cssNode = null; | ||
|
||
function recurse(currentNode) { | ||
if (ts.isModuleDeclaration(currentNode) && currentNode.name.text === 'Css') { | ||
cssNode = currentNode; | ||
} else { | ||
ts.forEachChild(currentNode, child => recurse(child)); | ||
} | ||
} | ||
|
||
recurse(node); | ||
return cssNode; | ||
} | ||
|
||
// Helper function to recursively extract style properties from nested structures within Css namespace | ||
function extractCssProperties(node) { | ||
let styles = []; | ||
|
||
if (ts.isInterfaceDeclaration(node)) { | ||
node.members.forEach(member => { | ||
if (ts.isPropertySignature(member)) { | ||
const name = member.name.text; | ||
styles.push(name); | ||
} | ||
}); | ||
} else { | ||
ts.forEachChild(node, child => { | ||
styles = styles.concat(extractCssProperties(child)); | ||
}); | ||
} | ||
|
||
return styles; | ||
} | ||
|
||
// Find the Css namespace | ||
const cssNamespace = findCssNamespace(sourceFile); | ||
|
||
if (cssNamespace) { | ||
// Extract styles from the Css namespace | ||
const styles = extractCssProperties(cssNamespace); | ||
|
||
// Remove duplicates and sort the styles alphabetically | ||
const uniqueSortedStyles = Array.from(new Set(styles)).sort(); | ||
|
||
// Output the styles as JSON | ||
console.log(JSON.stringify(uniqueSortedStyles, null, 2)); | ||
} else { | ||
console.error('Css namespace not found in the provided TypeScript definition file.'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
// Load and parse the JSON file | ||
const jsonFilePath = path.resolve(__dirname, '..', 'documentation', 'docmaker.json'); | ||
const jsonData = JSON.parse(fs.readFileSync(jsonFilePath, 'utf8')); | ||
|
||
// Helper function to recursively extract functions | ||
function extractFunctions(section) { | ||
let functions = []; | ||
|
||
if (section.fns) { | ||
section.fns.forEach(fn => { | ||
// Add the main function and formats | ||
if (fn.formats) { | ||
fn.formats.forEach(format => { | ||
if (format.name) { | ||
functions.push(format.name); | ||
} else { | ||
functions.push(fn.name); | ||
} | ||
}); | ||
} else { | ||
functions.push(fn.name); | ||
} | ||
|
||
// Add pureAliases the same number of times as the main function | ||
if (fn.pureAliases) { | ||
fn.pureAliases.forEach(alias => { | ||
const count = functions.filter(f => f === fn.name).length; | ||
for (let i = 0; i < count; i++) { | ||
functions.push(alias); | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
|
||
if (section.sections) { | ||
section.sections.forEach(subSection => { | ||
functions = functions.concat(extractFunctions(subSection)); | ||
}); | ||
} | ||
|
||
return functions; | ||
} | ||
|
||
// Extract functions from the JSON data | ||
const functions = extractFunctions(jsonData); | ||
|
||
// Sort the functions alphabetically | ||
const sortedFunctions = functions.sort(); | ||
|
||
// Output the functions as JSON | ||
console.log(JSON.stringify(sortedFunctions, null, 2)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
// Load the Markdown file | ||
const markdownFilePath = path.resolve(__dirname, '..', 'documentation', 'md', 'style.md'); | ||
const markdownContent = fs.readFileSync(markdownFilePath, 'utf8'); | ||
|
||
// Define a regex to match the style properties | ||
const stylePropertyRegex = /\*\*`([^`]+)`\*\*/g; | ||
|
||
// Extract style properties | ||
let match; | ||
const styleProperties = []; | ||
|
||
while ((match = stylePropertyRegex.exec(markdownContent)) !== null) { | ||
const property = match[1]; | ||
// Omit entries that have parentheses | ||
if (!property.includes('(')) { | ||
// Handle entries like <pos> | ||
if (property.includes('<pos>')) { | ||
['source', 'mid-source', 'target', 'mid-target'].forEach(pos => { | ||
styleProperties.push(property.replace('<pos>', pos)); | ||
}); | ||
} else if (property.includes('pie-i')) { | ||
// Handle pie-i properties | ||
styleProperties.push(property); | ||
for (let i = 1; i <= 16; i++) { | ||
styleProperties.push(property.replace('pie-i', `pie-${i}`)); | ||
} | ||
} else { | ||
styleProperties.push(property); | ||
} | ||
} | ||
} | ||
|
||
// Remove duplicates and sort the style properties alphabetically | ||
const uniqueSortedStyleProperties = Array.from(new Set(styleProperties)).sort(); | ||
|
||
// Output the style properties as JSON | ||
console.log(JSON.stringify(uniqueSortedStyleProperties, null, 2)); |
Oops, something went wrong.