admin管理员组文章数量:1332361
Very basic question. I'm not sure if this is a node / typescript question, a vs code question, or an nx question.
In an nx monorepo, say you have a simple .js script located in an nx library project that is used to convert some files from one format to another. How do you set up nx to a) run the script, b) to allow you to debug the script.
If the source file is called monkey-schemas.ts and contains:
import * as openApiSchema from './open-api-schemas';
export class monkeySchemas {
static nameSchema : openApiSchema.SchemaObject = {
type: "string",
description: "Name field"
}
static testModel : interfaces.SchemaObject = {
type: "object",
properties: {
body: {
type: "object",
properties: {
firstName: MonkeyModels.nameSchema,
secondName: MonkeyModels.nameSchema
}
}
}
}
}
and the expectation is to output a file containing the simple ts interface:
export interface testModel { firstName?: string; secondName?: string; }
In my case the script is at \libs\monkey-defs\src\scripts\generate-ts-interfaces.js. What I've got for the generate script is this so far:
// Define input and output paths
const inputPath = path.resolve(__dirname, '../lib/models/monkey-schemas.ts');
const outputPath = path.resolve(__dirname, '../out/ts-interfaces/');
// Utility to convert a schema object to TypeScript interface
function schemaToInterface(schemaName, schemaObject) {
const properties = schemaObject.properties || {};
const fields = Object.entries(properties)
.map(([key, value]) => {
const type = value.type || 'any';
return ` ${key}: ${type};`;
})
.join('\n');
return `export interface ${schemaName} {\n${fields}\n}`;
}
// Load schemas
const schemas = require(inputPath);
// Process and write selected schemas to TypeScript interfaces
function generateInterfaces() {
if (!fs.existsSync(outputPath)) {
fs.mkdirSync(outputPath, { recursive: true });
}
Object.entries(schemas.monkeySchemas)
.forEach(([name, schema]) => {
if (schema.type === 'object') {
const tsInterface = schemaToInterface(name, schema);
const filePath = path.join(outputPath, `${name}.ts`);
fs.writeFileSync(filePath, tsInterface, 'utf8');
console.log(`Generated: ${filePath}`);
}
});
}
generateInterfaces();
I'm consious but barely that the .ts needs to be compiled into .js.
I'm at a loss how to join this together in the configurations and so on.
本文标签: nodejsHow to run a simple js debugger with typescript (in nx monorepo)Stack Overflow
版权声明:本文标题:node.js - How to run a simple js debugger with typescript (in nx mono-repo) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742319258a2452447.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论