jingrow-ui/vite/generateTypes.js
jingrow c7bac1a7a0
Some checks failed
Publish on NPM / publish (push) Has been cancelled
Build and Deploy Storybook / build (push) Has been cancelled
Tests / test (push) Has been cancelled
initial commit
2025-10-24 00:40:30 +08:00

62 lines
1.6 KiB
JavaScript

import path from 'path'
import { fileURLToPath } from 'url'
import { findAppsFolder } from './utils.js'
import { DocTypeInterfaceGenerator } from './doctypeInterfaceGenerator.js'
// Handle termination signals to exit cleanly
process.on('SIGINT', () => process.exit(0))
process.on('SIGTERM', () => process.exit(0))
async function main() {
try {
// Parse options passed from the plugin
let options = {}
if (process.argv[2]) {
try {
options = JSON.parse(process.argv[2])
} catch (err) {
console.error('Error parsing plugin options:', err)
}
}
// Use only the plugin options for configuration
if (!(options && options.input)) {
console.log('No type generation input specified in options')
return
}
const frontendFolder = process.cwd()
let outputPath = options.output || 'src/types/doctypes.ts'
if (!path.isAbsolute(outputPath)) {
outputPath = path.join(frontendFolder, outputPath)
}
const appsFolder = findAppsFolder()
if (!appsFolder) {
console.error('Could not find jingrow-bench/apps folder')
return
}
const generator = new DocTypeInterfaceGenerator(
appsFolder,
options.input,
outputPath,
)
await generator.generate()
} catch (error) {
console.error('Error generating PageType interfaces:', error)
process.exit(1)
}
}
// Execute if run directly
const currentFilePath = fileURLToPath(import.meta.url)
if (process.argv[1] === currentFilePath) {
main()
.then(() => process.exit(0))
.catch((err) => {
console.error(err)
process.exit(1)
})
}