Skip to content

Commit 3c2a9f8

Browse files
committed
refactor(convert-to-osts): use double quotes
1 parent f664397 commit 3c2a9f8

1 file changed

Lines changed: 36 additions & 36 deletions

File tree

convert-to-osts.ts

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { readdirSync, readFileSync, statSync, writeFileSync } from 'node:fs';
2-
import { join, resolve } from 'node:path';
1+
import { readdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
2+
import { join, resolve } from "node:path";
33

4-
const SCRIPTS_DIR = resolve(import.meta.dirname, 'scripts');
4+
const SCRIPTS_DIR = resolve(import.meta.dirname, "scripts");
55

66
interface Param {
77
name: string;
@@ -25,34 +25,34 @@ interface OstsFile {
2525
function tsTypeToJsonSchema(tsType: string): JsonSchemaType {
2626
const type = tsType.trim();
2727

28-
if (type.endsWith('[]')) {
29-
return { type: 'array', items: tsTypeToJsonSchema(type.slice(0, -2)) };
28+
if (type.endsWith("[]")) {
29+
return { type: "array", items: tsTypeToJsonSchema(type.slice(0, -2)) };
3030
}
3131

3232
switch (type) {
33-
case 'string': return { type: 'string' };
34-
case 'number': return { type: 'number' };
35-
case 'boolean': return { type: 'boolean' };
36-
default: return { type: 'string' };
33+
case "string": return { type: "string" };
34+
case "number": return { type: "number" };
35+
case "boolean": return { type: "boolean" };
36+
default: return { type: "string" };
3737
}
3838
}
3939

4040
function parseMainParams(code: string): Param[] {
4141
const match = code.match(/function\s+main\s*\(([\s\S]*?)\)\s*[:{]/);
42-
if (!match) throw new Error('No `main` function found.');
42+
if (!match) throw new Error("No `main` function found.");
4343

4444
const paramsStr = match[1];
4545
const rawParams: string[] = [];
4646
let depth = 0;
47-
let current = '';
47+
let current = "";
4848

4949
for (const ch of paramsStr) {
50-
if ('<(['.includes(ch)) depth++;
51-
else if ('>)]'.includes(ch)) depth--;
52-
else if (ch === ',' && depth === 0) {
50+
if ("<([".includes(ch)) depth++;
51+
else if (">)]".includes(ch)) depth--;
52+
else if (ch === "," && depth === 0) {
5353
const trimmed = current.trim();
5454
if (trimmed) rawParams.push(trimmed);
55-
current = '';
55+
current = "";
5656
continue;
5757
}
5858
current += ch;
@@ -61,9 +61,9 @@ function parseMainParams(code: string): Param[] {
6161
if (last) rawParams.push(last);
6262

6363
return rawParams.map(param => {
64-
const normalised = param.replace(/\s+/g, ' ').trim();
65-
const colonIdx = normalised.indexOf(':');
66-
if (colonIdx === -1) return { name: normalised, type: 'string' };
64+
const normalised = param.replace(/\s+/g, " ").trim();
65+
const colonIdx = normalised.indexOf(":");
66+
if (colonIdx === -1) return { name: normalised, type: "string" };
6767
return {
6868
name: normalised.slice(0, colonIdx).trim(),
6969
type: normalised.slice(colonIdx + 1).trim(),
@@ -73,25 +73,25 @@ function parseMainParams(code: string): Param[] {
7373

7474
function parseDescription(code: string): string {
7575
const jsdocMatch = code.match(/\/\*\*([\s\S]*?)\*\/\s*function\s+main/);
76-
if (!jsdocMatch) return '';
76+
if (!jsdocMatch) return "";
7777

7878
const descLines: string[] = [];
79-
for (const line of jsdocMatch[1].split('\n')) {
80-
const cleaned = line.replace(/^\s*\*\s?/, '').trim();
81-
if (cleaned.startsWith('@')) break;
79+
for (const line of jsdocMatch[1].split("\n")) {
80+
const cleaned = line.replace(/^\s*\*\s?/, "").trim();
81+
if (cleaned.startsWith("@")) break;
8282
if (cleaned) descLines.push(cleaned);
8383
}
8484

85-
return descLines.join(' ');
85+
return descLines.join(" ");
8686
}
8787

8888
function convertToOsts(inputPath: string): void {
89-
const code = readFileSync(inputPath, 'utf8');
90-
const body = code.replace(/\r\n/g, '\n').replace(/\n/g, '\r\n');
89+
const code = readFileSync(inputPath, "utf8");
90+
const body = code.replace(/\r\n/g, "\n").replace(/\n/g, "\r\n");
9191

9292
const description = parseDescription(code);
9393
const allParams = parseMainParams(code);
94-
const userParams = allParams.filter(p => p.name !== 'workbook');
94+
const userParams = allParams.filter(p => p.name !== "workbook");
9595

9696
const properties: Record<string, JsonSchemaType> = {};
9797
for (const p of userParams) {
@@ -103,25 +103,25 @@ function convertToOsts(inputPath: string): void {
103103
originalParameterOrder: userParams.map((p, i) => ({ name: p.name, index: i })),
104104
parameterSchema:
105105
userParams.length > 0
106-
? { type: 'object', required: userParams.map(p => p.name), properties }
107-
: { type: 'object', properties: {} },
108-
returnSchema: { type: 'object', properties: {} },
106+
? { type: "object", required: userParams.map(p => p.name), properties }
107+
: { type: "object", properties: {} },
108+
returnSchema: { type: "object", properties: {} },
109109
signature: {
110-
comment: '',
111-
parameters: allParams.map(p => ({ name: p.name, comment: '' })),
110+
comment: "",
111+
parameters: allParams.map(p => ({ name: p.name, comment: "" })),
112112
},
113113
};
114114

115115
const osts: OstsFile = {
116-
version: '0.3.0',
116+
version: "0.3.0",
117117
body,
118118
description,
119-
noCodeMetadata: '',
119+
noCodeMetadata: "",
120120
parameterInfo: JSON.stringify(parameterInfo),
121-
apiInfo: JSON.stringify({ variant: 'synchronous', variantVersion: 2 }),
121+
apiInfo: JSON.stringify({ variant: "synchronous", variantVersion: 2 }),
122122
};
123123

124-
const outputPath = inputPath.replace(/\.ts$/, '.osts');
124+
const outputPath = inputPath.replace(/\.ts$/, ".osts");
125125
writeFileSync(outputPath, JSON.stringify(osts));
126126
console.log(`Converted: ${outputPath}`);
127127
}
@@ -131,7 +131,7 @@ function walkAndConvert(dir: string): void {
131131
const fullPath = join(dir, entry);
132132
if (statSync(fullPath).isDirectory()) {
133133
walkAndConvert(fullPath);
134-
} else if (entry.endsWith('.ts')) {
134+
} else if (entry.endsWith(".ts")) {
135135
try {
136136
convertToOsts(fullPath);
137137
} catch (err) {

0 commit comments

Comments
 (0)