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' - name: 'Use Node.js'
uses: 'actions/setup-node@v2.5.1' uses: 'actions/setup-node@v2.5.1'
with: with:
node-version: '16.x' node-version: 'lts/*'
cache: 'npm' cache: 'npm'
- name: 'Install' - name: 'Install'

View File

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

1
.gitignore vendored
View File

@ -7,6 +7,7 @@ npm-debug.log*
# production # production
build build
.swc
__pycache__ __pycache__
obj obj
bin 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) jest.setTimeout(Docker.MAXIMUM_TIMEOUT_MILLISECONDS)

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,11 +1,11 @@
#!/usr/bin/env node #!/usr/bin/env node
import { Cli } from 'clipanion' 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...') console.error('Error occurred...')
process.exit(1) process.exit(1)
}) })

View File

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

View File

@ -1,13 +1,13 @@
import execa from 'execa' import execa from 'execa'
import { Challenge } from './Challenge' import { Challenge } from './Challenge.js'
import { Solution } from './Solution' 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 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 { export interface GitAffectedOptions {
isContinuousIntegration: boolean isContinuousIntegration: boolean

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

7301
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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