mirror of https://github.com/jdx/mise
chore: simplify render:settings task (#3142)
* chore: simplify render:settings task * [autofix.ci] apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
parent
32d788954f
commit
2a7887149b
|
@ -8,6 +8,7 @@ repos:
|
|||
- id: end-of-file-fixer
|
||||
- id: check-yaml
|
||||
- id: check-toml
|
||||
- id: check-json
|
||||
- repo: https://github.com/shellcheck-py/shellcheck-py
|
||||
rev: v0.10.0.1
|
||||
hooks:
|
||||
|
|
|
@ -7,6 +7,5 @@ docs/registry.md
|
|||
docs/.vitepress/cache
|
||||
docs/.vitepress/dist
|
||||
docs/public/site.webmanifest
|
||||
schema/mise.json.hbs
|
||||
tasks.md
|
||||
tasks/fig/src/mise.ts
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
"@tsconfig/node18": "^18.2.4",
|
||||
"@withfig/autocomplete-tools": "^2.10.0",
|
||||
"@withfig/autocomplete-types": "^1.31.0",
|
||||
"handlebars": "^4.7.8",
|
||||
"toml": "^3.0.0",
|
||||
"ts-pattern": "^5.4.0",
|
||||
"tsx": "^4.19.1",
|
||||
|
|
|
@ -267,7 +267,7 @@
|
|||
},
|
||||
"ignored_config_paths": {
|
||||
"default": [],
|
||||
"description": "This is a list of config paths that mise will ignore. This only works as an env var.",
|
||||
"description": "This is a list of config paths that mise will ignore.",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
|
@ -541,7 +541,7 @@
|
|||
},
|
||||
"trusted_config_paths": {
|
||||
"default": [],
|
||||
"description": "This is a list of config paths that mise will automatically mark as trusted. This only works as an env var.",
|
||||
"description": "This is a list of config paths that mise will automatically mark as trusted.",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
|
|
|
@ -1,392 +0,0 @@
|
|||
{
|
||||
"$id": "https://mise.jdx.dev/schema/mise.json",
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"title": "mise",
|
||||
"type": "object",
|
||||
"$defs": {
|
||||
"env": {
|
||||
"additionalProperties": {
|
||||
"oneOf": [
|
||||
{
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"type": "number"
|
||||
},
|
||||
{
|
||||
"enum": [
|
||||
false
|
||||
],
|
||||
"type": "boolean"
|
||||
}
|
||||
]
|
||||
},
|
||||
"description": "environment variables",
|
||||
"properties": {
|
||||
"_": {
|
||||
"description": "environment modules",
|
||||
"additionalProperties": true,
|
||||
"properties": {
|
||||
"file": {
|
||||
"oneOf": [
|
||||
{
|
||||
"description": "dotenv file to load",
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"description": "dotenv files to load",
|
||||
"items": {
|
||||
"description": "dotenv file to load",
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
}
|
||||
]
|
||||
},
|
||||
"path": {
|
||||
"oneOf": [
|
||||
{
|
||||
"description": "PATH entry to add",
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"description": "PATH entries to add",
|
||||
"items": {
|
||||
"description": "PATH entry to add",
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
}
|
||||
]
|
||||
},
|
||||
"python": {
|
||||
"description": "python environment",
|
||||
"properties": {
|
||||
"venv": {
|
||||
"oneOf": [
|
||||
{
|
||||
"description": "path to python virtual environment to use",
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"description": "virtualenv options",
|
||||
"properties": {
|
||||
"create": {
|
||||
"default": false,
|
||||
"description": "create a new virtual environment if one does not exist",
|
||||
"type": "boolean"
|
||||
},
|
||||
"path": {
|
||||
"description": "path to python virtual environment to use",
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"path"
|
||||
],
|
||||
"type": "object"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
},
|
||||
"source": {
|
||||
"oneOf": [
|
||||
{
|
||||
"description": "bash script to load",
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"description": "bash scripts to load",
|
||||
"items": {
|
||||
"description": "bash script to load",
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
},
|
||||
"settings": {
|
||||
"properties": {{settings_json}}
|
||||
},
|
||||
"task": {
|
||||
"oneOf": [
|
||||
{
|
||||
"description": "script to run",
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"description": "script to run",
|
||||
"items": {
|
||||
"description": "script to run",
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"alias": {
|
||||
"oneOf": [
|
||||
{
|
||||
"description": "alias for this task",
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"description": "alias for this task",
|
||||
"items": {
|
||||
"description": "alias for this task",
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
}
|
||||
]
|
||||
},
|
||||
"depends": {
|
||||
"description": "other tasks to run before this task",
|
||||
"items": {
|
||||
"description": "task to run before this task",
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
"wait_for": {
|
||||
"description": "if these tasks run, wait for them to complete first",
|
||||
"items": {
|
||||
"description": "task to run before this task",
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
"description": {
|
||||
"description": "description of task",
|
||||
"type": "string"
|
||||
},
|
||||
"dir": {
|
||||
"description": "directory to run script in, default is current working directory",
|
||||
"type": "string"
|
||||
},
|
||||
"env": {
|
||||
"additionalProperties": {
|
||||
"oneOf": [
|
||||
{
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"type": "number"
|
||||
},
|
||||
{
|
||||
"enum": [
|
||||
false
|
||||
],
|
||||
"type": "boolean"
|
||||
}
|
||||
]
|
||||
},
|
||||
"description": "environment variables",
|
||||
"type": "object"
|
||||
},
|
||||
"hide": {
|
||||
"description": "do not display this task",
|
||||
"type": "boolean"
|
||||
},
|
||||
"outputs": {
|
||||
"description": "files created by this task",
|
||||
"items": {
|
||||
"description": "glob pattern or path to files created by this task",
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
"quiet": {
|
||||
"description": "do not display mise information for this task",
|
||||
"type": "boolean"
|
||||
},
|
||||
"raw": {
|
||||
"description": "directly connect task to stdin/stdout/stderr",
|
||||
"type": "boolean"
|
||||
},
|
||||
"run": {
|
||||
"oneOf": [
|
||||
{
|
||||
"description": "script to run",
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"description": "script to run",
|
||||
"items": {
|
||||
"description": "script to run",
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
}
|
||||
]
|
||||
},
|
||||
"file": {
|
||||
"description": "Execute an external script",
|
||||
"type": "string"
|
||||
},
|
||||
"sources": {
|
||||
"description": "files that this task depends on",
|
||||
"items": {
|
||||
"description": "glob pattern or path to files that this task depends on",
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
"shell": {
|
||||
"description": "specify a shell command to run the script with",
|
||||
"type": "string",
|
||||
"default": "sh -c"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
}
|
||||
]
|
||||
},
|
||||
"vars": {
|
||||
"description": "variables to set",
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
"description": "value of variable",
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"task_config": {
|
||||
"description": "configration for task execution/management",
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"includes": {
|
||||
"description": "files/directories to include searching for tasks",
|
||||
"items": {
|
||||
"description": "file/directory root to include in task execution",
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
}
|
||||
}
|
||||
},
|
||||
"tool": {
|
||||
"oneOf": [
|
||||
{
|
||||
"description": "version of the tool to install",
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"properties": {
|
||||
"version": {
|
||||
"description": "version of the tool to install",
|
||||
"type": "string"
|
||||
},
|
||||
"os": {
|
||||
"oneOf": [
|
||||
{
|
||||
"description": "operating system to install on",
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"description": "option to pass to tool",
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"version"
|
||||
],
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
"oneOf": [
|
||||
{
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"additionalProperties": false,
|
||||
"description": "config file for mise version manager (mise.toml)",
|
||||
"properties": {
|
||||
"alias": {
|
||||
"additionalProperties": {
|
||||
"additionalProperties": {
|
||||
"description": "version alias points to",
|
||||
"type": "string"
|
||||
},
|
||||
"description": "plugin to set aliases for",
|
||||
"type": "object"
|
||||
},
|
||||
"description": "custom shorthands for versions",
|
||||
"type": "object"
|
||||
},
|
||||
"env": {
|
||||
"oneOf": [
|
||||
{
|
||||
"$ref": "#/$defs/env"
|
||||
},
|
||||
{
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/$defs/env"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"min_version": {
|
||||
"description": "minimum version of mise required to use this config",
|
||||
"pattern": "^\\d+\\.\\d+\\.\\d+$",
|
||||
"type": "string"
|
||||
},
|
||||
"plugins": {
|
||||
"additionalProperties": {
|
||||
"description": "url to plugin repository",
|
||||
"type": "string"
|
||||
},
|
||||
"description": "plugins to use",
|
||||
"type": "object"
|
||||
},
|
||||
"settings": {
|
||||
"$ref": "#/$defs/settings",
|
||||
"additionalProperties": false,
|
||||
"description": "mise settings",
|
||||
"type": "object"
|
||||
},
|
||||
"task_config": {
|
||||
"$ref": "#/$defs/task_config"
|
||||
},
|
||||
"tasks": {
|
||||
"additionalProperties": {
|
||||
"$ref": "#/$defs/task"
|
||||
},
|
||||
"description": "task runner tasks",
|
||||
"type": "object"
|
||||
},
|
||||
"tools": {
|
||||
"additionalProperties": {
|
||||
"oneOf": [
|
||||
{
|
||||
"items": {
|
||||
"$ref": "#/$defs/tool"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"$ref": "#/$defs/tool"
|
||||
}
|
||||
]
|
||||
},
|
||||
"description": "dev tools to use",
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -303,7 +303,7 @@ type = "ListPath"
|
|||
rust_type = "BTreeSet<PathBuf>"
|
||||
default = []
|
||||
parse_env = "list_by_colon"
|
||||
description = "This is a list of config paths that mise will ignore. This only works as an env var."
|
||||
description = "This is a list of config paths that mise will ignore."
|
||||
|
||||
[jobs]
|
||||
env = "MISE_JOBS"
|
||||
|
@ -381,13 +381,7 @@ type = "String"
|
|||
default = "info"
|
||||
hide = true
|
||||
description = "Show more/less output."
|
||||
enum = [
|
||||
["trace"],
|
||||
["debug"],
|
||||
["info"],
|
||||
["warn"],
|
||||
["error"]
|
||||
]
|
||||
enum = [["trace"], ["debug"], ["info"], ["warn"], ["error"]]
|
||||
|
||||
[node.compile]
|
||||
env = "MISE_NODE_COMPILE"
|
||||
|
@ -727,8 +721,14 @@ type = "String"
|
|||
optional = true
|
||||
description = "Change output style when executing tasks."
|
||||
enum = [
|
||||
["prefix", "(default if jobs > 1) print by line with the prefix of the task name"],
|
||||
["interleave", "(default if jobs > 1) print by line with the prefix of the task name"]
|
||||
[
|
||||
"prefix",
|
||||
"(default if jobs > 1) print by line with the prefix of the task name"
|
||||
],
|
||||
[
|
||||
"interleave",
|
||||
"(default if jobs > 1) print by line with the prefix of the task name"
|
||||
]
|
||||
]
|
||||
docs = """
|
||||
Change output style when executing tasks. This controls the output of `mise run`.
|
||||
|
@ -752,7 +752,7 @@ type = "ListPath"
|
|||
rust_type = "BTreeSet<PathBuf>"
|
||||
default = []
|
||||
parse_env = "list_by_colon"
|
||||
description = "This is a list of config paths that mise will automatically mark as trusted. This only works as an env var."
|
||||
description = "This is a list of config paths that mise will automatically mark as trusted."
|
||||
|
||||
[unix_default_file_shell_args]
|
||||
env = "MISE_UNIX_DEFAULT_FILE_SHELL_ARGS"
|
||||
|
|
|
@ -1,14 +1,10 @@
|
|||
import * as fs from "node:fs";
|
||||
import * as child_process from "node:child_process";
|
||||
import * as toml from "toml";
|
||||
import * as Handlebars from "handlebars";
|
||||
import { match, P } from "ts-pattern";
|
||||
|
||||
const doc = toml.parse(fs.readFileSync("settings.toml", "utf-8"));
|
||||
const settings = {};
|
||||
import { match } from "ts-pattern";
|
||||
|
||||
type Element = {
|
||||
default: string;
|
||||
default: string | number | boolean;
|
||||
description: string;
|
||||
deprecated: boolean;
|
||||
type: string;
|
||||
|
@ -18,12 +14,26 @@ type Element = {
|
|||
};
|
||||
};
|
||||
|
||||
function buildElement(key, props): Element {
|
||||
let type = props.type;
|
||||
type Props = {
|
||||
type: string;
|
||||
default: string | number | boolean;
|
||||
description: string;
|
||||
deprecated: boolean;
|
||||
enum?: [string][];
|
||||
};
|
||||
|
||||
function buildElement(key: string, props: Props): Element {
|
||||
let { type } = props;
|
||||
if (!type) {
|
||||
throw new Error("Type property must be a string");
|
||||
}
|
||||
|
||||
if (type.startsWith("Option<")) {
|
||||
type = type.slice(7, -1);
|
||||
}
|
||||
type = type.replaceAll("PathBuf", "String");
|
||||
|
||||
type = type.replace(/PathBuf/g, "Path").replaceAll("PathBuf", "String");
|
||||
|
||||
type = match(type)
|
||||
.with("String", () => "string")
|
||||
.with("Path", () => "string")
|
||||
|
@ -36,28 +46,36 @@ function buildElement(key, props): Element {
|
|||
.otherwise(() => {
|
||||
throw new Error(`Unknown type: ${type}`);
|
||||
});
|
||||
|
||||
if (!props.description) {
|
||||
console.error(`Missing description for ${key}`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const ele: Element = {
|
||||
default: props.default,
|
||||
description: props.description,
|
||||
deprecated: props.deprecated,
|
||||
type,
|
||||
};
|
||||
|
||||
if (props.enum) {
|
||||
ele.enum = props.enum.map((e) => e[0]);
|
||||
}
|
||||
|
||||
if (type === "string[]") {
|
||||
ele.type = "array";
|
||||
ele.items = {
|
||||
type: "string",
|
||||
};
|
||||
}
|
||||
|
||||
return ele;
|
||||
}
|
||||
|
||||
const doc = toml.parse(fs.readFileSync("settings.toml", "utf-8"));
|
||||
const settings: any = {};
|
||||
|
||||
for (const key in doc) {
|
||||
const props = doc[key];
|
||||
if (props.type) {
|
||||
|
@ -77,15 +95,9 @@ for (const key in doc) {
|
|||
}
|
||||
}
|
||||
|
||||
const schema_tmpl = Handlebars.compile(
|
||||
fs.readFileSync("schema/mise.json.hbs", "utf-8"),
|
||||
);
|
||||
fs.writeFileSync(
|
||||
"schema/mise.json.tmp",
|
||||
schema_tmpl({
|
||||
settings_json: new Handlebars.SafeString(JSON.stringify(settings, null, 2)),
|
||||
}),
|
||||
);
|
||||
const schema = JSON.parse(fs.readFileSync("schema/mise.json", "utf-8"));
|
||||
schema["$defs"].settings.properties = settings;
|
||||
fs.writeFileSync("schema/mise.json.tmp", JSON.stringify(schema, null, 2));
|
||||
|
||||
child_process.execSync("jq . < schema/mise.json.tmp > schema/mise.json");
|
||||
child_process.execSync("prettier --write schema/mise.json");
|
||||
|
|
Loading…
Reference in New Issue