mirror of
https://github.com/revng/revng
synced 2026-06-21 14:07:57 +00:00
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:
@@ -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
|
||||
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
"dependencies": {
|
||||
"@types/node": ">=17",
|
||||
"fast-equals": "^5",
|
||||
"prettier": "^2.6",
|
||||
"typescript": "^4.6",
|
||||
"yaml": "^2"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user