1
1
mirror of https://github.com/theoludwig/programming-challenges.git synced 2024-12-08 00:45:29 +01:00

chore: maintenance

This commit is contained in:
Divlo 2022-02-19 18:30:29 +01:00
parent bc1d34f126
commit 696de1580d
No known key found for this signature in database
GPG Key ID: 8F9478F220CE65E9
35 changed files with 3421 additions and 4107 deletions

6
.eslintignore Normal file
View File

@ -0,0 +1,6 @@
node_modules
challenges
templates
temp
tmp
build

15
.eslintrc.json Normal file
View File

@ -0,0 +1,15 @@
{
"extends": ["conventions"],
"plugins": ["import", "unicorn"],
"parserOptions": {
"project": "./tsconfig.json"
},
"env": {
"node": true,
"jest": true
},
"rules": {
"import/extensions": ["error", "always"],
"unicorn/prevent-abbreviations": "error"
}
}

1
.gitattributes vendored Normal file
View File

@ -0,0 +1 @@
* text=auto eol=lf

View File

@ -1,6 +0,0 @@
version: 2
updates:
- package-ecosystem: 'github-actions'
directory: '/'
schedule:
interval: 'daily'

View File

@ -22,7 +22,7 @@ jobs:
- name: 'Use Node.js'
uses: 'actions/setup-node@v2.5.1'
with:
node-version: '16.x'
node-version: 'lts/*'
cache: 'npm'
- name: 'Install'

View File

@ -15,7 +15,7 @@ jobs:
- name: 'Use Node.js'
uses: 'actions/setup-node@v2.5.1'
with:
node-version: '16.x'
node-version: 'lts/*'
cache: 'npm'
- name: 'Install'
@ -34,7 +34,7 @@ jobs:
- name: 'Use Node.js'
uses: 'actions/setup-node@v2.5.1'
with:
node-version: '16.x'
node-version: 'lts/*'
cache: 'npm'
- name: 'Install'
@ -56,7 +56,7 @@ jobs:
- name: 'Use Node.js'
uses: 'actions/setup-node@v2.5.1'
with:
node-version: '16.x'
node-version: 'lts/*'
cache: 'npm'
- name: 'Install'

1
.gitignore vendored
View File

@ -7,6 +7,7 @@ npm-debug.log*
# production
build
.swc
__pycache__
obj
bin

22
.swcrc Normal file
View File

@ -0,0 +1,22 @@
{
"jsc": {
"parser": {
"syntax": "typescript",
"decorators": true,
"dynamicImport": true
},
"transform": {
"legacyDecorator": true,
"decoratorMetadata": true
},
"target": "es2022",
"loose": true
},
"module": {
"type": "commonjs",
"strict": false,
"strictMode": true,
"lazy": false,
"noInterop": false
}
}

View File

@ -1,3 +1,3 @@
import { Docker } from '../services/Docker'
import { Docker } from '../services/Docker.js'
jest.setTimeout(Docker.MAXIMUM_TIMEOUT_MILLISECONDS)

View File

@ -1,8 +1,8 @@
import { Builtins, Cli } from 'clipanion'
import { GenerateChallengeCommand } from './commands/generate/challenge'
import { GenerateSolutionCommand } from './commands/generate/solution'
import { RunTestCommand } from './commands/run/test'
import { GenerateChallengeCommand } from './commands/generate/challenge.js'
import { GenerateSolutionCommand } from './commands/generate/solution.js'
import { RunTestCommand } from './commands/run/test.js'
export const cli = new Cli({
binaryLabel: 'programming-challenges',

View File

@ -7,8 +7,8 @@ import getStream from 'get-stream'
import fsMock from 'mock-fs'
import date from 'date-and-time'
import { cli } from '../../../cli'
import { isExistingPath } from '../../../utils/isExistingPath'
import { cli } from '../../../cli.js'
import { isExistingPath } from '../../../utils/isExistingPath.js'
const input = ['generate', 'challenge']
const githubUser = 'Divlo'

View File

@ -7,8 +7,8 @@ import getStream from 'get-stream'
import fsMock from 'mock-fs'
import date from 'date-and-time'
import { cli } from '../../../cli'
import { isExistingPath } from '../../../utils/isExistingPath'
import { cli } from '../../../cli.js'
import { isExistingPath } from '../../../utils/isExistingPath.js'
const input = ['generate', 'solution']
const githubUser = 'Divlo'

View File

@ -2,7 +2,7 @@ import { Command, Option } from 'clipanion'
import * as typanion from 'typanion'
import chalk from 'chalk'
import { Challenge } from '../../services/Challenge'
import { Challenge } from '../../services/Challenge.js'
export class GenerateChallengeCommand extends Command {
static paths = [['generate', 'challenge']]

View File

@ -2,7 +2,7 @@ import { Command, Option } from 'clipanion'
import * as typanion from 'typanion'
import chalk from 'chalk'
import { Solution } from '../../services/Solution'
import { Solution } from '../../services/Solution.js'
export class GenerateSolutionCommand extends Command {
static paths = [['generate', 'solution']]

View File

@ -2,8 +2,8 @@ import { PassThrough } from 'node:stream'
import chalk from 'chalk'
import { cli } from '../../../cli'
import { Test } from '../../../services/Test'
import { cli } from '../../../cli.js'
import { Test } from '../../../services/Test.js'
const input = ['run', 'test']
const challenge = 'hello-world'

View File

@ -2,10 +2,10 @@ import { Command, Option } from 'clipanion'
import * as typanion from 'typanion'
import chalk from 'chalk'
import { Solution } from '../../services/Solution'
import { GitAffected } from '../../services/GitAffected'
import { template } from '../../services/Template'
import { Test } from '../../services/Test'
import { Solution } from '../../services/Solution.js'
import { GitAffected } from '../../services/GitAffected.js'
import { template } from '../../services/Template.js'
import { Test } from '../../services/Test.js'
export class RunTestCommand extends Command {
static paths = [['run', 'test']]

View File

@ -1,11 +1,11 @@
#!/usr/bin/env node
import { Cli } from 'clipanion'
import { cli } from './cli'
import { cli } from './cli.js'
const [, , ...args] = process.argv
const [, , ...arguments_] = process.argv
cli.runExit(args, Cli.defaultContext).catch(() => {
cli.runExit(arguments_, Cli.defaultContext).catch(() => {
console.error('Error occurred...')
process.exit(1)
})

View File

@ -3,8 +3,8 @@ import fs from 'node:fs'
import validateProjectName from 'validate-npm-package-name'
import { isExistingPath } from '../utils/isExistingPath'
import { template } from './Template'
import { isExistingPath } from '../utils/isExistingPath.js'
import { template } from './Template.js'
export interface ChallengeOptions {
name: string

View File

@ -1,13 +1,13 @@
import execa from 'execa'
import { Challenge } from './Challenge'
import { Solution } from './Solution'
import { Challenge } from './Challenge.js'
import { Solution } from './Solution.js'
const solutionsRegex = /challenges\/[\s\S]*\/solutions\/(c|cpp|cs|dart|java|javascript|python|rust|typescript)\/[\s\S]*\/(.*).(c|cpp|cs|dart|java|js|py|rs|ts)/
const solutionsRegex = /challenges\/[\S\s]*\/solutions\/(c|cpp|cs|dart|java|javascript|python|rust|typescript)\/[\S\s]*\/(.*).(c|cpp|cs|dart|java|js|py|rs|ts)/
const dockerRegex = /templates\/docker\/(c|cpp|cs|dart|java|javascript|python|rust|typescript)\/(.*)/
const inputOutputRegex = /challenges\/[\s\S]*\/test\/(.*)\/(input.txt|output.txt)/
const inputOutputRegex = /challenges\/[\S\s]*\/test\/(.*)\/(input.txt|output.txt)/
export interface GitAffectedOptions {
isContinuousIntegration: boolean

View File

@ -4,13 +4,13 @@ import fs from 'node:fs'
import {
createTemporaryEmptyFolder,
TEMPORARY_PATH
} from '../utils/createTemporaryEmptyFolder'
import { isExistingPath } from '../utils/isExistingPath'
import { Challenge } from './Challenge'
import { copyDirectory } from '../utils/copyDirectory'
import { template } from './Template'
import { docker } from './Docker'
import { Test } from './Test'
} from '../utils/createTemporaryEmptyFolder.js'
import { isExistingPath } from '../utils/isExistingPath.js'
import { Challenge } from './Challenge.js'
import { copyDirectory } from '../utils/copyDirectory.js'
import { template } from './Template.js'
import { docker } from './Docker.js'
import { Test } from './Test.js'
export interface GetSolutionOptions {
programmingLanguageName: string

View File

@ -4,7 +4,7 @@ import fs from 'node:fs'
import { replaceInFile } from 'replace-in-file'
import date from 'date-and-time'
import { copyDirectory } from '../utils/copyDirectory'
import { copyDirectory } from '../utils/copyDirectory.js'
const TEMPLATE_PATH = path.join(__dirname, '..', '..', 'templates')
const TEMPLATE_DOCKER_PATH = path.join(TEMPLATE_PATH, 'docker')
@ -87,7 +87,7 @@ class Template {
const { destination, githubUser, name } = options
await copyDirectory(TEMPLATE_CHALLENGE_PATH, destination)
await this.replaceInDestination({
name: name,
name,
description: this.getDescription(githubUser),
destination
})

View File

@ -6,8 +6,8 @@ import ora from 'ora'
import chalk from 'chalk'
import { table } from 'table'
import { Solution } from './Solution'
import { docker } from './Docker'
import { Solution } from './Solution.js'
import { docker } from './Docker.js'
export interface InputOutput {
input: string
@ -49,7 +49,7 @@ export class Test implements TestOptions {
this.elapsedTimeMilliseconds = options.elapsedTimeMilliseconds
}
static async printResult (tests: Test[]): Promise<void> {
static printResult (tests: Test[]): void {
const tableResult = [
[
chalk.bold('N°'),
@ -120,7 +120,7 @@ export class Test implements TestOptions {
throw error
}
}
await Test.printResult(tests)
Test.printResult(tests)
}
static async getInputOutput (testPath: string): Promise<InputOutput> {

View File

@ -1,6 +1,6 @@
import { Challenge } from '../Challenge'
import { GitAffected } from '../GitAffected'
import { Solution } from '../Solution'
import { Challenge } from '../Challenge.js'
import { GitAffected } from '../GitAffected.js'
import { Solution } from '../Solution.js'
const gitAffected = new GitAffected({ isContinuousIntegration: false })

View File

@ -2,10 +2,10 @@ import fs from 'node:fs'
import fsMock from 'mock-fs'
import { copyDirectory } from '../copyDirectory'
import { copyDirectory } from '../copyDirectory.js'
describe('utils/copyDirectory', () => {
afterEach(async () => {
afterEach(() => {
fsMock.restore()
})

View File

@ -5,11 +5,11 @@ import fsMock from 'mock-fs'
import {
TEMPORARY_PATH,
createTemporaryEmptyFolder
} from '../createTemporaryEmptyFolder'
import { isExistingPath } from '../isExistingPath'
} from '../createTemporaryEmptyFolder.js'
import { isExistingPath } from '../isExistingPath.js'
describe('utils/createTemporaryEmptyFolder', () => {
afterEach(async () => {
afterEach(() => {
fsMock.restore()
})

View File

@ -1,9 +1,9 @@
import fsMock from 'mock-fs'
import { isExistingPath } from '../isExistingPath'
import { isExistingPath } from '../isExistingPath.js'
describe('utils/isExistingFile', () => {
afterEach(async () => {
afterEach(() => {
fsMock.restore()
})

View File

@ -1,7 +1,7 @@
import path from 'node:path'
import fs from 'node:fs'
import { isExistingPath } from '../utils/isExistingPath'
import { isExistingPath } from '../utils/isExistingPath.js'
export const TEMPORARY_PATH = path.join(__dirname, '..', '..', 'temp')

View File

@ -1,13 +1,14 @@
{
"preset": "ts-jest",
"testEnvironment": "node",
"resolver": "jest-ts-webcompat-resolver",
"transform": {
"^.+\\.(t|j)sx?$": ["@swc/jest"]
},
"rootDir": "./cli",
"testPathIgnorePatterns": [
"<rootDir>/commands/run/test.ts",
"<rootDir>/services/Test.ts",
"<rootDir>/node_modules"
],
"setupFiles": [
"<rootDir>/__test__/setup.ts"
]
"setupFiles": ["<rootDir>/__test__/setup.ts"]
}

7287
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,7 @@
{
"name": "programming-challenges",
"version": "1.0.0",
"private": true,
"description": "programming-challenges brings together lots of programming exercises and challenges to improve your algorithmic logic.",
"license": "MIT",
"repository": {
@ -11,59 +12,54 @@
"node": ">=16.0.0",
"npm": ">=8.0.0"
},
"ts-standard": {
"ignore": [
"build",
"node_modules",
"templates",
"challenges"
],
"envs": [
"node",
"jest"
],
"report": "stylish"
},
"main": "build/index.js",
"bin": "build/index.js",
"scripts": {
"start": "node build/index.js",
"build": "rimraf ./build && tsc",
"test": "jest",
"build": "rimraf ./build && swc ./cli --out-dir ./build && tsc",
"lint:commit": "commitlint",
"lint:editorconfig": "editorconfig-checker",
"lint:markdown": "markdownlint '**/*.md' --dot --ignore node_modules",
"lint:typescript": "ts-standard"
"lint:markdown": "markdownlint \"**/*.md\" --dot --ignore-path \".gitignore\"",
"lint:typescript": "eslint \"**/*.{js,jsx,ts,tsx}\"",
"test": "jest"
},
"dependencies": {
"chalk": "4.1.2",
"clipanion": "3.0.1",
"date-and-time": "2.0.1",
"date-and-time": "2.1.2",
"execa": "5.1.1",
"ora": "5.4.1",
"replace-in-file": "6.3.2",
"table": "6.7.5",
"table": "6.8.0",
"typanion": "3.7.1",
"validate-npm-package-name": "3.0.0"
},
"devDependencies": {
"@commitlint/cli": "15.0.0",
"@commitlint/config-conventional": "15.0.0",
"@commitlint/cli": "16.2.1",
"@commitlint/config-conventional": "16.2.1",
"@swc/cli": "0.1.55",
"@swc/core": "1.2.143",
"@swc/jest": "0.2.17",
"@types/date-and-time": "0.13.0",
"@types/jest": "27.0.3",
"@types/jest": "27.4.0",
"@types/mock-fs": "4.13.1",
"@types/ms": "0.7.31",
"@types/node": "16.11.12",
"@types/node": "17.0.18",
"@types/validate-npm-package-name": "3.0.3",
"editorconfig-checker": "4.0.2",
"eslint": "8.9.0",
"eslint-config-conventions": "1.0.1",
"eslint-plugin-import": "2.25.4",
"eslint-plugin-promise": "6.0.0",
"eslint-plugin-unicorn": "41.0.0",
"get-stream": "6.0.1",
"jest": "27.4.3",
"markdownlint-cli": "0.30.0",
"jest": "27.5.1",
"jest-mock-extended": "2.0.4",
"jest-ts-webcompat-resolver": "1.0.0",
"markdownlint-cli": "0.31.1",
"mock-fs": "5.1.2",
"ms": "2.1.3",
"rimraf": "3.0.2",
"ts-jest": "27.1.0",
"ts-standard": "11.0.0",
"typescript": "4.5.2"
"typescript": "4.5.5"
}
}

View File

@ -1,3 +1,3 @@
FROM dart:2.14.4
FROM dart:2.16.1
COPY ./ ./
CMD ["dart", "run", "solution.dart"]

View File

@ -1,3 +1,3 @@
FROM node:16.13.1
FROM node:16.14.0
COPY ./ ./
CMD ["node", "solution.js"]

View File

@ -1,4 +1,4 @@
FROM rust:1.57.0
FROM rust:1.58.1
COPY ./ ./
RUN rustc solution.rs
CMD ["./solution"]

View File

@ -1,4 +1,4 @@
FROM node:16.13.1
FROM node:16.14.0
WORKDIR /usr/app
COPY ./ /usr/app

View File

@ -6,6 +6,7 @@
"moduleResolution": "node",
"outDir": "./build",
"rootDir": "./cli",
"noEmit": true,
"strict": true,
"skipLibCheck": true,
"esModuleInterop": true