tuple-tree-generate-typescript: drop --prettier

The `prettier` binary is now assumed to be installed as part of the
system. No need to manually install it and use the `--prettier`
command-line option.
This commit is contained in:
Giacomo Vercesi
2025-03-10 10:31:21 +01:00
parent 6c31138374
commit 140735a913
3 changed files with 7 additions and 10 deletions
@@ -5,6 +5,7 @@
import argparse
from pathlib import Path
from shutil import which
from subprocess import DEVNULL, run
from tempfile import NamedTemporaryFile
@@ -18,7 +19,6 @@ argparser.add_argument("--output", "-o", help="Output to this file")
argparser.add_argument("--namespace", required=True, help="Base namespace for generated types")
argparser.add_argument("--root-type", required=True, help="Schema root type")
argparser.add_argument("--global-name", required=True, help="Name of the top-level object")
argparser.add_argument("--prettier", help="Path to the prettier binary for formatting")
argparser.add_argument("--external-file", action="append", help="Additional ts file to include")
argparser.add_argument(
"--string-type", action="append", default=[], help="Treat this type as a string"
@@ -46,8 +46,8 @@ def main(args):
args.external_type,
)
if args.prettier is not None:
source = prettify_typescript(source, args.prettier)
if which("prettier") is not None:
source = prettify_typescript(source)
if args.output:
output_file = Path(args.output)
@@ -58,11 +58,11 @@ def main(args):
print(source)
def prettify_typescript(source: str, prettier: str) -> str:
def prettify_typescript(source: str) -> str:
with NamedTemporaryFile(suffix=".ts") as temp_file:
source_file = Path(temp_file.name)
source_file.write_text(source)
run([prettier, "--write", temp_file.name], check=True, stdout=DEVNULL)
run(["prettier", "--write", temp_file.name], check=True, stdout=DEVNULL)
new_source = source_file.read_text()
return new_source
+2 -4
View File
@@ -386,10 +386,8 @@ function(
COMMAND
"${SCRIPTS_ROOT_DIR}/tuple-tree-generate-typescript.py" --namespace
"${NAMESPACE}" --root-type "${ROOT_TYPE}" --output "${OUTPUT_PATH}"
--global-name "${GLOBAL_NAME}" --prettier
"${CMAKE_BINARY_DIR}/node_build/node_modules/.bin/prettier"
${INCLUDE_FILE_ARGS} ${STRING_TYPE_ARGS} ${EXTERNAL_TYPE_ARGS}
${SCALAR_TYPE_ARGS} "${YAML_DEFINITIONS}"
--global-name "${GLOBAL_NAME}" ${INCLUDE_FILE_ARGS} ${STRING_TYPE_ARGS}
${EXTERNAL_TYPE_ARGS} ${SCALAR_TYPE_ARGS} "${YAML_DEFINITIONS}"
OUTPUT "${OUTPUT_PATH}"
DEPENDS "${YAML_DEFINITIONS}" ${TYPESCRIPT_TEMPLATES}
"${CMAKE_SOURCE_DIR}/typescript/model.ts"
-1
View File
@@ -4,7 +4,6 @@
"dependencies": {
"@types/node": ">=17",
"fast-equals": "^5",
"prettier": "^2.6",
"typescript": "^4.6",
"yaml": "^2"
}