-
Notifications
You must be signed in to change notification settings - Fork 290
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Code for Fig completions and publishing * [autofix.ci] apply automated fixes * [autofix.ci] apply automated fixes (attempt 2/3) * Fix task * Make task depend on completions or it will run in parallel * Remove hardcoded input path, oops * Lint fix * [autofix.ci] apply automated fixes * Remove autogenerated file * [autofix.ci] apply automated fixes * Fix duplicated code * [autofix.ci] apply automated fixes * Prettier: Ignore generated mise.ts * [autofix.ci] apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
0277b74
commit 914f668
Showing
11 changed files
with
3,395 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
name: "Publish mise completions version" | ||
on: | ||
push: | ||
tags: | ||
- "v*" ## Only run the action on new versions, this prevents useless runs of the action | ||
|
||
jobs: | ||
push-to-fig-autocomplete: | ||
## if github.repository == 'jdx/mise' | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
token: ${{ secrets.MY_RELEASE_PLEASE_TOKEN }} | ||
- uses: actions-rust-lang/setup-rust-toolchain@v1 | ||
with: { toolchain: nightly, components: rustfmt } | ||
- uses: actions-rust-lang/setup-rust-toolchain@v1 | ||
- run: mkdir -p "$HOME/bin" && echo "$HOME/bin" >> "$GITHUB_PATH" | ||
- run: npm i | ||
- run: cargo build --all-features && cp target/debug/mise "$HOME"/bin | ||
- uses: actions/cache/restore@v4 | ||
with: | ||
path: | | ||
~/.local/share/mise/installs | ||
~/.local/share/mise/plugins | ||
key: mise-tools-ubuntu-latest-${{ hashFiles('.mise.lock') }} | ||
restore-keys: mise-tools-ubuntu-latest | ||
- run: mise install | ||
- run: mise run render:fig | ||
- name: Create Autocomplete PR ## Create the autocomplete PR using this action | ||
uses: withfig/push-to-fig-autocomplete-action@v2 | ||
with: | ||
token: ${{ secrets.MY_RELEASE_PLEASE_TOKEN }} | ||
autocomplete-spec-name: mise | ||
spec-path: tasks/fig/src/mise.ts | ||
pr-body: "Automated PR for latest mise release by https://github.com/jdx/mise" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,4 @@ docs/.vitepress/dist | |
docs/public/site.webmanifest | ||
schema/mise.json.hbs | ||
tasks.md | ||
tasks/fig/src/mise.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
build/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
import fsAsync = require("node:fs/promises"); | ||
import * as ts from "typescript"; | ||
import * as path from "path"; | ||
|
||
type GeneratorIdentifier = { | ||
identifier: string; | ||
generator_name: string; | ||
}; | ||
|
||
const customGenerators: GeneratorIdentifier[] = [ | ||
{ | ||
identifier: "alias", | ||
generator_name: "aliasGenerator", | ||
}, | ||
{ | ||
identifier: "plugin", | ||
generator_name: "pluginGenerator", | ||
}, | ||
{ | ||
identifier: "all_plugins", | ||
generator_name: "allPluginsGenerator", | ||
}, | ||
{ | ||
identifier: "task", | ||
generator_name: "simpleTaskGenerator", | ||
}, | ||
{ | ||
identifier: "tasks", | ||
generator_name: "simpleTaskGenerator", | ||
}, | ||
{ | ||
identifier: "setting", | ||
generator_name: "settingsGenerator", | ||
}, | ||
{ | ||
identifier: "tool@version", | ||
generator_name: "toolVersionGenerator", | ||
}, | ||
{ | ||
identifier: "installed_tool@version", | ||
generator_name: "installedToolVersionGenerator", | ||
}, | ||
{ | ||
identifier: "config_file", | ||
generator_name: "configPathGenerator", | ||
}, | ||
{ | ||
identifier: "env_vars", | ||
generator_name: "envVarGenerator", | ||
}, | ||
{ | ||
identifier: "tool@version", | ||
generator_name: "toolVersionGenerator", | ||
}, | ||
]; | ||
|
||
const get_identifier = (node: ts.Node): ts.Identifier | undefined => { | ||
let name = ""; | ||
|
||
const objectLiteralExpr = node as ts.ObjectLiteralExpression; | ||
const properties = objectLiteralExpr.properties; | ||
properties.forEach((p) => { | ||
if (ts.isPropertyAssignment(p) && p.name.getText() == '"name"') { | ||
const value = p.getChildAt(2); | ||
name = value.getText().replaceAll('"', ""); | ||
} | ||
}); | ||
|
||
const custom = customGenerators | ||
.filter((g) => { | ||
if (name === g.identifier) { | ||
return true; | ||
// | ||
} | ||
}) | ||
.map((g) => ts.factory.createIdentifier(g.generator_name)); | ||
|
||
if (custom.length > 0) return custom[0]; | ||
return; | ||
}; | ||
|
||
function transformer<T extends ts.Node>(context: ts.TransformationContext) { | ||
return (rootNode: T) => { | ||
function visit(node: ts.Node): ts.Node { | ||
if ( | ||
ts.isPropertyAssignment(node) && | ||
node.name.getText() === '"generators"' | ||
) { | ||
const id = get_identifier(node.parent); | ||
if (id) { | ||
return ts.factory.updatePropertyAssignment(node, node.name, id); | ||
} | ||
} | ||
return ts.visitEachChild(node, visit, context); | ||
} | ||
return ts.visitNode(rootNode, visit); | ||
}; | ||
} | ||
|
||
const main = async (fileName: string, outFile?: string) => { | ||
try { | ||
const generatorFileContents = ( | ||
await fsAsync.readFile(path.join(__dirname, "generators.ts")) | ||
).toString(); | ||
const contents = (await fsAsync.readFile(fileName)).toString(); | ||
const sourceFile = ts.createSourceFile( | ||
"example.ts", | ||
contents, | ||
ts.ScriptTarget.Latest, | ||
true, | ||
); | ||
const result = ts.transform(sourceFile, [transformer]); | ||
const transformedSourceFile = result.transformed[0]; | ||
|
||
const printer = ts.createPrinter({ newLine: ts.NewLineKind.LineFeed }); | ||
const output = printer.printNode( | ||
ts.EmitHint.Unspecified, | ||
transformedSourceFile, | ||
sourceFile, | ||
); | ||
|
||
fsAsync.writeFile( | ||
outFile ?? `${fileName.replace(".ts", "")}.out.ts`, | ||
generatorFileContents + "\n" + output, | ||
); | ||
} catch (e) { | ||
console.error(e); | ||
} | ||
}; | ||
|
||
main(process.argv[2], process.argv[3]); |
Oops, something went wrong.