-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: extract default properties from jsdoc annotations
- Loading branch information
Showing
6 changed files
with
182 additions
and
47 deletions.
There are no files selected for viewing
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,45 @@ | ||
import { createGenerator } from "ts-json-schema-generator"; | ||
import { writeFileSync } from "fs"; | ||
|
||
/** @type {import('ts-json-schema-generator/dist/src/Config').Config} */ | ||
const config = { | ||
tsconfig: "./tsconfig.json", | ||
type: "InSchema", | ||
sortProps: false, | ||
}; | ||
|
||
const schema = createGenerator(config).createSchema(config.type); | ||
|
||
function generateDefaults(schema) { | ||
function generateProps(properties) { | ||
const lines = []; | ||
for (const [key, value] of Object.entries(properties)) { | ||
if (value.default !== undefined) { | ||
lines.push(` ${key}: ${JSON.stringify(value.default)}`); | ||
} else { | ||
console.warn(`Warning: No default defined for '${key}'`); | ||
} | ||
} | ||
return lines; | ||
} | ||
|
||
const jsCode = ` | ||
// Automatically generated by extract-default-properties.mjs | ||
import { | ||
type LayoutProperties, | ||
type CostWeights | ||
} from "./layout.js"; | ||
export const DEFAULT_PROPERTIES = { | ||
${generateProps(schema.definitions["LayoutProperties"].properties).join(",\n")} | ||
} as LayoutProperties; | ||
export const DEFAULT_COST_WEIGHTS = { | ||
${generateProps(schema.definitions["CostWeights"].properties).join(",\n")} | ||
} as CostWeights; | ||
`; | ||
return jsCode; | ||
} | ||
|
||
writeFileSync("src/defaultProperties.ts", generateDefaults(schema)); |
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,37 @@ | ||
|
||
// Automatically generated by extract-default-properties.mjs | ||
|
||
import { | ||
type LayoutProperties, | ||
type CostWeights | ||
} from "./layout.js"; | ||
|
||
export const DEFAULT_PROPERTIES = { | ||
bellTipShape: 0.1, | ||
bellTipSpread: 0.5, | ||
bellStrokeWidth: 1, | ||
bellPlateauPos: 0.75, | ||
sampleHeight: 110, | ||
sampleWidth: 90, | ||
inferredSampleHeight: 120, | ||
gapHeight: 60, | ||
sampleSpacing: 60, | ||
columnSpacing: 90, | ||
tentacleWidth: 2, | ||
tentacleSpacing: 5, | ||
inOutCPDistance: 0.3, | ||
bundleCPDistance: 0.6, | ||
sampleFontSize: 12, | ||
showLegend: true, | ||
phylogenyColorScheme: true, | ||
phylogenyHueOffset: 0, | ||
sampleTakenGuide: "text" | ||
} as LayoutProperties; | ||
|
||
export const DEFAULT_COST_WEIGHTS = { | ||
crossing: 10, | ||
pathLength: 2, | ||
orderMismatch: 2, | ||
bundleMismatch: 3, | ||
divergence: 4 | ||
} as CostWeights; |
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
Oops, something went wrong.