-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add validation .tool-versions file
- Loading branch information
Showing
8 changed files
with
114 additions
and
148 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 |
---|---|---|
@@ -1,8 +1,8 @@ | ||
const createConfig = require("@kcws/eslint-config") | ||
const createConfig = require('@kcws/eslint-config') | ||
module.exports = createConfig({ | ||
cwd: __dirname, | ||
profile: "node", | ||
profile: 'node', | ||
jest: true, | ||
prettier: true, | ||
ecma: "latest", | ||
ecma: 'latest', | ||
}) |
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 |
---|---|---|
@@ -1,55 +1,38 @@ | ||
import type { ToolVersion } from "./asdf.type" | ||
import type { ToolVersion } from './asdf.type' | ||
|
||
import { join } from "node:path" | ||
import { readFile } from "node:fs/promises" | ||
import { AppContext } from "@kcws/github-actions" | ||
import { readFile } from 'node:fs/promises' | ||
import { AppContext } from '@kcws/github-actions' | ||
|
||
import { getPluginUrl } from "./constants" | ||
import app from "../app" | ||
import { getPluginUrl } from './constants' | ||
import app from '../app' | ||
|
||
export const asdfPluginList = async (context: AppContext<typeof app>) => { | ||
const executors = context.use("exec") | ||
|
||
const { code, stdout, stderr } = await executors.captureRun( | ||
"asdf", | ||
"plugin", | ||
"list" | ||
) | ||
if (code > 0) throw new Error(stderr?.toString() ?? "unknown error occurred") | ||
return stdout?.toString().split("\n") ?? [] | ||
const executors = context.use('exec') | ||
|
||
const { code, stdout, stderr } = await executors.captureRun('asdf', 'plugin', 'list') | ||
if (code > 0) throw new Error(stderr?.toString() ?? 'unknown error occurred') | ||
return stdout?.toString().split('\n') ?? [] | ||
} | ||
|
||
export const asdfPluginAdd = async ( | ||
context: AppContext<typeof app>, | ||
plugin: string, | ||
pluginUrl?: string | ||
) => { | ||
const repo = context | ||
.use("log") | ||
.format(getPluginUrl(plugin, pluginUrl), plugin) | ||
await context.use("exec").run("asdf", "plugin", "add", plugin, repo) | ||
export const asdfPluginAdd = async (context: AppContext<typeof app>, plugin: string, pluginUrl?: string) => { | ||
const repo = context.use('log').format(getPluginUrl(plugin, pluginUrl), plugin) | ||
await context.use('exec').run('asdf', 'plugin', 'add', plugin, repo) | ||
} | ||
|
||
export const asdfToolList = async ( | ||
_context: AppContext<typeof app>, | ||
cwd: string | ||
): Promise<ToolVersion[]> => { | ||
const toolVersions = await readFile(join(cwd, ".tool-versions"), { | ||
encoding: "utf8", | ||
export const asdfToolList = async (_context: AppContext<typeof app>, toolFile: string): Promise<ToolVersion[]> => { | ||
const toolVersions = await readFile(toolFile, { | ||
encoding: 'utf8', | ||
}) | ||
|
||
return toolVersions | ||
.split("\n") | ||
.map(x => x.replace(/#.*/, "").trim()) | ||
.split('\n') | ||
.map(x => x.replace(/#.*/, '').trim()) | ||
.filter(x => x.length > 0) | ||
.map(x => x.split(" ")) | ||
.map(x => x.split(' ')) | ||
.map(([name, version]) => ({ name, version })) | ||
} | ||
|
||
export const asdfToolInstall = async ( | ||
context: AppContext<typeof app>, | ||
cwd: string | ||
): Promise<void> => { | ||
export const asdfToolInstall = async (context: AppContext<typeof app>, cwd: string): Promise<void> => { | ||
const options = { cwd } | ||
await context.use("exec").withOptions(options).run("asdf", "install") | ||
await context.use('exec').withOptions(options).run('asdf', 'install') | ||
} |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import app from "./app" | ||
import runner from "./runners/main" | ||
import app from './app' | ||
import runner from './runners/main' | ||
|
||
app.exec(runner) |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import app from "./app" | ||
import runner from "./runners/post" | ||
import app from './app' | ||
import runner from './runners/post' | ||
|
||
app.exec(runner) |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import app from "./app" | ||
import runner from "./runners/pre" | ||
import app from './app' | ||
import runner from './runners/pre' | ||
|
||
app.exec(runner) |
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