From 26257e878e704a595cd431efce9f14d7c84957da Mon Sep 17 00:00:00 2001 From: Ingvar Stepanyan Date: Tue, 10 Sep 2024 20:46:54 +0100 Subject: [PATCH] Regenerate mod.rs and mark as readonly --- src/api/autogen/index.ts | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/src/api/autogen/index.ts b/src/api/autogen/index.ts index 157b043..80c10be 100644 --- a/src/api/autogen/index.ts +++ b/src/api/autogen/index.ts @@ -1,5 +1,5 @@ import openapi from '@readme/openapi-parser'; -import { writeFile } from 'fs/promises'; +import { chmod, open, unlink, writeFile } from 'fs/promises'; import { spawnSync } from 'child_process'; import { toSnakeCase, @@ -632,15 +632,17 @@ function stringifyIter( function stringifyDoc(doc: string | undefined = '') { doc = doc.trim(); if (!doc) return ''; - return doc - // Change "`InterfaceV1 Only` ...actual description" to be "actual description\n\n_InterfaceV1 Only_" - .replace(/^`(.+?)\.?`\s*(.*)$/s, '$2\n\n_$1._') - // If there is no summary, split out first sentence as summary. - .replace(/^(.*?(? { case 'Response': { return ` ${stringifyDoc(type.doc)} - ${cfg}#[derive(Debug, Clone${type.name !== 'DeviceStateItem' ? ', Copy' : ''}, Serialize, Deserialize)] + ${cfg}#[derive(Debug, Clone${ + type.name !== 'DeviceStateItem' ? ', Copy' : '' + }, Serialize, Deserialize)] #[serde(rename_all = "PascalCase")] pub struct ${type.name} { ${stringifyIter( @@ -908,4 +908,8 @@ try { console.warn(err); } -await writeFile('../mod.rs', rendered); +await unlink('../mod.rs'); +await writeFile('../mod.rs', rendered, { + flag: 'wx', + mode: /* readonly */ 0o444 +});