1
1
mirror of https://github.com/theoludwig/programming-challenges.git synced 2024-11-09 22:08:58 +01:00

build(deps): update latest

This commit is contained in:
Divlo 2023-01-10 23:15:36 +01:00
parent 1a12e0db0c
commit bc6ad699fc
No known key found for this signature in database
GPG Key ID: 8F9478F220CE65E9
20 changed files with 536 additions and 9974 deletions

View File

@ -11,7 +11,7 @@ jobs:
runs-on: 'ubuntu-latest' runs-on: 'ubuntu-latest'
timeout-minutes: 30 timeout-minutes: 30
steps: steps:
- uses: 'actions/checkout@v3.0.0' - uses: 'actions/checkout@v3.3.0'
with: with:
fetch-depth: 0 fetch-depth: 0
@ -21,7 +21,7 @@ jobs:
SKIP_LOGIN: true SKIP_LOGIN: true
- name: 'Use Node.js' - name: 'Use Node.js'
uses: 'actions/setup-node@v3.0.0' uses: 'actions/setup-node@v3.6.0'
with: with:
node-version: 'lts/*' node-version: 'lts/*'
cache: 'npm' cache: 'npm'

View File

@ -10,10 +10,10 @@ jobs:
lint: lint:
runs-on: 'ubuntu-latest' runs-on: 'ubuntu-latest'
steps: steps:
- uses: 'actions/checkout@v3.0.0' - uses: 'actions/checkout@v3.3.0'
- name: 'Use Node.js' - name: 'Use Node.js'
uses: 'actions/setup-node@v3.0.0' uses: 'actions/setup-node@v3.6.0'
with: with:
node-version: 'lts/*' node-version: 'lts/*'
cache: 'npm' cache: 'npm'
@ -24,15 +24,15 @@ jobs:
- run: 'npm run lint:commit -- --to "${{ github.sha }}"' - run: 'npm run lint:commit -- --to "${{ github.sha }}"'
- run: 'npm run lint:editorconfig' - run: 'npm run lint:editorconfig'
- run: 'npm run lint:markdown' - run: 'npm run lint:markdown'
- run: 'npm run lint:typescript' - run: 'npm run lint:eslint'
build: build:
runs-on: 'ubuntu-latest' runs-on: 'ubuntu-latest'
steps: steps:
- uses: 'actions/checkout@v3.0.0' - uses: 'actions/checkout@v3.3.0'
- name: 'Use Node.js' - name: 'Use Node.js'
uses: 'actions/setup-node@v3.0.0' uses: 'actions/setup-node@v3.6.0'
with: with:
node-version: 'lts/*' node-version: 'lts/*'
cache: 'npm' cache: 'npm'
@ -43,10 +43,12 @@ jobs:
- name: 'Build' - name: 'Build'
run: 'npm run build' run: 'npm run build'
- run: 'npm run build:typescript'
test: test:
runs-on: 'ubuntu-latest' runs-on: 'ubuntu-latest'
steps: steps:
- uses: 'actions/checkout@v3.0.0' - uses: 'actions/checkout@v3.3.0'
- name: 'Use Docker' - name: 'Use Docker'
uses: 'actions-hub/docker/cli@master' uses: 'actions-hub/docker/cli@master'
@ -54,7 +56,7 @@ jobs:
SKIP_LOGIN: true SKIP_LOGIN: true
- name: 'Use Node.js' - name: 'Use Node.js'
uses: 'actions/setup-node@v3.0.0' uses: 'actions/setup-node@v3.6.0'
with: with:
node-version: 'lts/*' node-version: 'lts/*'
cache: 'npm' cache: 'npm'

View File

@ -1,11 +1,5 @@
{ {
"config": {
"default": true,
"MD013": false,
"MD024": false,
"MD033": false,
"MD041": false
},
"globs": ["**/*.{md,mdx}"], "globs": ["**/*.{md,mdx}"],
"ignores": ["**/node_modules"] "ignores": ["**/node_modules"],
"customRules": ["markdownlint-rule-relative-links"]
} }

8
.markdownlint.json Normal file
View File

@ -0,0 +1,8 @@
{
"default": true,
"relative-links": true,
"extends": "markdownlint/style/prettier",
"MD024": false,
"MD033": false,
"MD041": false
}

View File

@ -5,9 +5,9 @@ import chalk from 'chalk'
import { Challenge } from '../../services/Challenge.js' import { Challenge } from '../../services/Challenge.js'
export class GenerateChallengeCommand extends Command { export class GenerateChallengeCommand extends Command {
static paths = [['generate', 'challenge']] public static override paths = [['generate', 'challenge']]
static usage = { public static override usage = {
description: 'Create the basic files needed for a new challenge.' description: 'Create the basic files needed for a new challenge.'
} }
@ -23,7 +23,7 @@ export class GenerateChallengeCommand extends Command {
validator: typanion.isString() validator: typanion.isString()
}) })
async execute(): Promise<number> { public async execute(): Promise<number> {
try { try {
const challenge = await Challenge.generate({ const challenge = await Challenge.generate({
name: this.challenge, name: this.challenge,

View File

@ -5,9 +5,9 @@ import chalk from 'chalk'
import { Solution } from '../../services/Solution.js' import { Solution } from '../../services/Solution.js'
export class GenerateSolutionCommand extends Command { export class GenerateSolutionCommand extends Command {
static paths = [['generate', 'solution']] public static override paths = [['generate', 'solution']]
static usage = { public static override usage = {
description: 'Create the basic files needed for a new solution.' description: 'Create the basic files needed for a new solution.'
} }
@ -35,7 +35,7 @@ export class GenerateSolutionCommand extends Command {
validator: typanion.isString() validator: typanion.isString()
}) })
async execute(): Promise<number> { public async execute(): Promise<number> {
try { try {
const solution = await Solution.generate({ const solution = await Solution.generate({
name: this.solutionName, name: this.solutionName,

View File

@ -11,9 +11,9 @@ import { Solution } from '../../services/Solution.js'
import { TemporaryFolder } from '../../services/TemporaryFolder.js' import { TemporaryFolder } from '../../services/TemporaryFolder.js'
export class RunSolutionCommand extends Command { export class RunSolutionCommand extends Command {
static paths = [['run', 'solution']] public static override paths = [['run', 'solution']]
static usage = { public static override usage = {
description: 'Run the solution with the given `input.txt` file.' description: 'Run the solution with the given `input.txt` file.'
} }
@ -45,7 +45,7 @@ export class RunSolutionCommand extends Command {
description: 'Display the output of the solution.' description: 'Display the output of the solution.'
}) })
async execute(): Promise<number> { public async execute(): Promise<number> {
console.log() console.log()
try { try {
await TemporaryFolder.cleanAll() await TemporaryFolder.cleanAll()

View File

@ -10,9 +10,9 @@ import { SolutionTestsResult } from '../../services/SolutionTestsResult.js'
import { TemporaryFolder } from '../../services/TemporaryFolder.js' import { TemporaryFolder } from '../../services/TemporaryFolder.js'
export class RunTestCommand extends Command { export class RunTestCommand extends Command {
static paths = [['run', 'test']] public static override paths = [['run', 'test']]
static usage = { public static override usage = {
description: description:
'Test if the solution is correct and display where it succeeds and fails.' 'Test if the solution is correct and display where it succeeds and fails.'
} }
@ -44,7 +44,7 @@ export class RunTestCommand extends Command {
description: 'Base of the current branch (usually master).' description: 'Base of the current branch (usually master).'
}) })
async execute(): Promise<number> { public async execute(): Promise<number> {
console.log() console.log()
try { try {
await TemporaryFolder.cleanAll() await TemporaryFolder.cleanAll()

View File

@ -9,9 +9,9 @@ import { template } from '../../services/Template.js'
import { Challenge } from '../../services/Challenge.js' import { Challenge } from '../../services/Challenge.js'
export class SearchCommand extends Command { export class SearchCommand extends Command {
static paths = [['search']] public static override paths = [['search']]
static usage = { public static override usage = {
description: 'Search challenges in the programming language specified.' description: 'Search challenges in the programming language specified.'
} }
@ -26,7 +26,7 @@ export class SearchCommand extends Command {
validator: typanion.isString() validator: typanion.isString()
}) })
async execute(): Promise<number> { public async execute(): Promise<number> {
try { try {
await template.verifySupportedProgrammingLanguage( await template.verifySupportedProgrammingLanguage(
this.programmingLanguage this.programmingLanguage

View File

@ -22,19 +22,19 @@ export class Challenge implements ChallengeOptions {
constructor(options: ChallengeOptions) { constructor(options: ChallengeOptions) {
const { name } = options const { name } = options
this.name = name this.name = name
this.path = fileURLToPath( this.path = fileURLToPath(new URL(`./${name}`, Challenge.BASE_URL))
new URL(`./${name}`, Challenge.BASE_URL)
)
} }
public static async getChallenges(): Promise<Challenge[]> { public static async getChallenges(): Promise<Challenge[]> {
const challengeNames = await fs.promises.readdir( Challenge.BASE_URL) const challengeNames = await fs.promises.readdir(Challenge.BASE_URL)
return challengeNames.map((challengeName) => { return challengeNames.map((challengeName) => {
return new Challenge({ name: challengeName }) return new Challenge({ name: challengeName })
}) })
} }
public static async generate(options: GenerateChallengeOptions): Promise<Challenge> { public static async generate(
options: GenerateChallengeOptions
): Promise<Challenge> {
const { name, githubUser } = options const { name, githubUser } = options
const challenge = new Challenge({ name }) const challenge = new Challenge({ name })
if (await isExistingPath(challenge.path)) { if (await isExistingPath(challenge.path)) {

View File

@ -70,6 +70,9 @@ export class GitAffected implements GitAffectedOptions {
const [, , programmingLanguageName] = filePath const [, , programmingLanguageName] = filePath
.replaceAll('\\', '/') .replaceAll('\\', '/')
.split('/') .split('/')
if (programmingLanguageName == null) {
throw new Error('programmingLanguageName is null')
}
return programmingLanguageName return programmingLanguageName
}) })
const affectedInputOutput = files.filter((filePath) => { const affectedInputOutput = files.filter((filePath) => {
@ -78,6 +81,9 @@ export class GitAffected implements GitAffectedOptions {
const affectedChallengesFromInputOutput = affectedInputOutput.map( const affectedChallengesFromInputOutput = affectedInputOutput.map(
(filePath) => { (filePath) => {
const [, challengeName] = filePath.replaceAll('\\', '/').split('/') const [, challengeName] = filePath.replaceAll('\\', '/').split('/')
if (challengeName == null) {
throw new Error('challengeName is null')
}
return new Challenge({ name: challengeName }) return new Challenge({ name: challengeName })
} }
) )

View File

@ -63,9 +63,7 @@ export class Solution implements SolutionOptions {
try { try {
await docker.build(this.temporaryFolder.id) await docker.build(this.temporaryFolder.id)
} catch (error: any) { } catch (error: any) {
throw new Error( throw new Error(`solution: ${this.path}\n${error.message as string}\n`)
`solution: ${this.path}\n${error.message as string}\n`
)
} }
} }
@ -90,9 +88,7 @@ export class Solution implements SolutionOptions {
} }
} catch (error: any) { } catch (error: any) {
loader.fail() loader.fail()
throw new Error( throw new Error(`solution: ${this.path}\n${error.message as string}\n`)
`solution: ${this.path}\n${error.message as string}\n`
)
} }
} }
@ -199,6 +195,15 @@ export class Solution implements SolutionOptions {
return solutions.map((solution) => { return solutions.map((solution) => {
const [, challengeName, , programmingLanguageName, solutionName] = const [, challengeName, , programmingLanguageName, solutionName] =
solution.replaceAll('\\', '/').split('/') solution.replaceAll('\\', '/').split('/')
if (
challengeName == null ||
programmingLanguageName == null ||
solutionName == null
) {
throw new Error(`Invalid solution path: ${solution}`)
}
return new Solution({ return new Solution({
challenge: new Challenge({ challenge: new Challenge({
name: challengeName name: challengeName

View File

@ -37,7 +37,8 @@ export class SolutionTestsResult implements SolutionTestsResultOptions {
} }
public print(options: SolutionTestsResultPrintOptions = {}): void { public print(options: SolutionTestsResultPrintOptions = {}): void {
const { shouldPrintBenchmark = false, shouldPrintTableResult = false } = options const { shouldPrintBenchmark = false, shouldPrintTableResult = false } =
options
const name = `${this.solution.challenge.name}/${this.solution.programmingLanguageName}/${this.solution.name}` const name = `${this.solution.challenge.name}/${this.solution.programmingLanguageName}/${this.solution.name}`
console.log(`${chalk.bold('Name:')} ${name}\n`) console.log(`${chalk.bold('Name:')} ${name}\n`)
const tableResult = [ const tableResult = [

View File

@ -109,7 +109,9 @@ class Template {
public async getProgrammingLanguages(): Promise<string[]> { public async getProgrammingLanguages(): Promise<string[]> {
const languages = await fs.promises.readdir(TEMPLATE_SOLUTION_PATH) const languages = await fs.promises.readdir(TEMPLATE_SOLUTION_PATH)
return languages.filter((language) => {return language !== 'base'}) return languages.filter((language) => {
return language !== 'base'
})
} }
public async verifySupportedProgrammingLanguage( public async verifySupportedProgrammingLanguage(

View File

@ -23,7 +23,9 @@ export class TemporaryFolder {
public static async cleanAll(): Promise<void> { public static async cleanAll(): Promise<void> {
try { try {
const temporaryPath = fileURLToPath(new URL('../../temp', import.meta.url)) const temporaryPath = fileURLToPath(
new URL('../../temp', import.meta.url)
)
await fs.promises.rm(temporaryPath, { recursive: true, force: true }) await fs.promises.rm(temporaryPath, { recursive: true, force: true })
await docker.removeImages() await docker.removeImages()
} catch {} } catch {}

View File

@ -4,9 +4,7 @@ import { performance } from 'node:perf_hooks'
import type { Solution } from './Solution.js' import type { Solution } from './Solution.js'
import { docker } from './Docker.js' import { docker } from './Docker.js'
import { import { SolutionTestsResult } from './SolutionTestsResult.js'
SolutionTestsResult
} from './SolutionTestsResult.js'
import { TemporaryFolder } from './TemporaryFolder.js' import { TemporaryFolder } from './TemporaryFolder.js'
export interface InputOutput { export interface InputOutput {
@ -74,9 +72,7 @@ export class Test implements TestOptions {
return { input, output } return { input, output }
} }
static async runManyWithSolutions( static async runManyWithSolutions(solutions: Solution[]): Promise<number> {
solutions: Solution[]
): Promise<number> {
const solutionTestsResultsPromises: Array<Promise<SolutionTestsResult>> = [] const solutionTestsResultsPromises: Array<Promise<SolutionTestsResult>> = []
let isSolutionSuccess = true let isSolutionSuccess = true
for (const solution of solutions) { for (const solution of solutions) {

10355
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -17,12 +17,13 @@
"bin": "build/index.js", "bin": "build/index.js",
"scripts": { "scripts": {
"start": "node build/index.js", "start": "node build/index.js",
"build": "rimraf ./build && swc ./cli --out-dir ./build && tsc", "build": "rimraf ./build && swc ./cli --out-dir ./build",
"build:dev": "swc ./src --out-dir ./build --watch", "build:dev": "swc ./src --out-dir ./build --watch",
"build:typescript": "tsc",
"lint:commit": "commitlint", "lint:commit": "commitlint",
"lint:editorconfig": "editorconfig-checker", "lint:editorconfig": "editorconfig-checker",
"lint:markdown": "markdownlint-cli2", "lint:markdown": "markdownlint-cli2",
"lint:typescript": "eslint \"**/*.{js,jsx,ts,tsx}\"", "lint:eslint": "eslint \"**/*.{js,jsx,ts,tsx}\"",
"test": "tap" "test": "tap"
}, },
"dependencies": { "dependencies": {
@ -38,10 +39,11 @@
"validate-npm-package-name": "5.0.0" "validate-npm-package-name": "5.0.0"
}, },
"devDependencies": { "devDependencies": {
"@commitlint/cli": "17.3.0", "@commitlint/cli": "17.4.1",
"@commitlint/config-conventional": "17.3.0", "@commitlint/config-conventional": "17.4.0",
"@swc/cli": "0.1.59", "@swc/cli": "0.1.57",
"@swc/core": "1.3.24", "@swc/core": "1.3.25",
"@tsconfig/strictest": "1.0.2",
"@types/date-and-time": "0.13.0", "@types/date-and-time": "0.13.0",
"@types/mock-fs": "4.13.1", "@types/mock-fs": "4.13.1",
"@types/ms": "0.7.31", "@types/ms": "0.7.31",
@ -49,21 +51,22 @@
"@types/sinon": "10.0.13", "@types/sinon": "10.0.13",
"@types/tap": "15.0.7", "@types/tap": "15.0.7",
"@types/validate-npm-package-name": "4.0.0", "@types/validate-npm-package-name": "4.0.0",
"@typescript-eslint/eslint-plugin": "5.47.1", "@typescript-eslint/eslint-plugin": "5.48.1",
"@typescript-eslint/parser": "5.47.1", "@typescript-eslint/parser": "5.48.1",
"editorconfig-checker": "4.0.2", "editorconfig-checker": "4.0.2",
"eslint": "8.30.0", "eslint": "8.31.0",
"eslint-config-conventions": "6.0.0", "eslint-config-conventions": "6.0.0",
"eslint-plugin-import": "2.26.0", "eslint-plugin-import": "2.26.0",
"eslint-plugin-promise": "6.1.1", "eslint-plugin-promise": "6.1.1",
"eslint-plugin-unicorn": "45.0.2", "eslint-plugin-unicorn": "45.0.2",
"get-stream": "6.0.1", "get-stream": "6.0.1",
"markdownlint-cli2": "0.5.1", "markdownlint-cli2": "0.6.0",
"markdownlint-rule-relative-links": "1.1.1",
"mock-fs": "5.2.0", "mock-fs": "5.2.0",
"ms": "2.1.3", "ms": "2.1.3",
"rimraf": "3.0.2", "rimraf": "3.0.2",
"sinon": "15.0.1", "sinon": "15.0.1",
"tap": "16.3.2", "tap": "16.3.3",
"typescript": "4.9.4" "typescript": "4.9.4"
} }
} }

View File

@ -1,9 +1,9 @@
FROM node:18.12.1 AS builder-dependencies FROM node:18.13.0 AS builder-dependencies
WORKDIR /usr/src/application WORKDIR /usr/src/application
COPY ./package*.json ./ COPY ./package*.json ./
RUN npm install RUN npm install
FROM node:18.12.1 AS builder FROM node:18.13.0 AS builder
WORKDIR /usr/src/application WORKDIR /usr/src/application
COPY --from=builder-dependencies /usr/src/application/node_modules ./node_modules COPY --from=builder-dependencies /usr/src/application/node_modules ./node_modules
COPY ./ ./ COPY ./ ./

View File

@ -1,4 +1,5 @@
{ {
"extends": "@tsconfig/strictest/tsconfig.json",
"compilerOptions": { "compilerOptions": {
"target": "ESNext", "target": "ESNext",
"module": "ESNext", "module": "ESNext",
@ -7,9 +8,8 @@
"outDir": "./build", "outDir": "./build",
"rootDir": "./cli", "rootDir": "./cli",
"noEmit": true, "noEmit": true,
"strict": true, "checkJs": false,
"skipLibCheck": true, "exactOptionalPropertyTypes": false
"esModuleInterop": true
}, },
"exclude": ["node_modules", "challenges", "templates", "temp", "tmp"] "exclude": ["node_modules", "challenges", "templates", "temp", "tmp"]
} }