Compare commits

...

7 commits

Author SHA1 Message Date
Manuel Thalmann 9444dddd49 Refactor sourcemap path fix
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2022-12-04 19:08:33 +01:00
Manuel Thalmann 40b069b632
Fix webpack source maps
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2022-12-03 15:20:07 +01:00
Manuel Thalmann a409ebb160 Compile mocha test files
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2022-12-02 01:11:30 +01:00
Manuel Thalmann 16453d44a7 Replace unsupported module 2022-12-02 01:11:06 +01:00
Manuel Thalmann e2f8bba503 Add CI configuration
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2022-12-02 01:05:07 +01:00
Manuel Thalmann 4d45e8e576 Migrate to webpack 2022-12-02 00:58:56 +01:00
Manuel Thalmann 07a33c8ee4 Initialize a new project 2022-12-02 00:10:48 +01:00
22 changed files with 5746 additions and 4 deletions

19
.eslintrc.cjs Normal file
View file

@ -0,0 +1,19 @@
const { join } = require("node:path");
const { PluginName, PresetName } = require("@manuth/eslint-plugin-typescript");
module.exports = {
extends: [
`plugin:${PluginName}/${PresetName.RecommendedWithTypeChecking}`
],
env: {
node: true,
es6: true
},
parserOptions: {
project: [
join(__dirname, "tsconfig.app.json"),
join(__dirname, "misc.tsconfig.json"),
join(__dirname, "src", "tests", "tsconfig.json")
]
}
};

11
.gitignore vendored
View file

@ -1,4 +1,6 @@
# ---> Node
# Build results
[Ll]ib/
# Logs
logs
*.log
@ -94,7 +96,7 @@ dist
# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# Comment in the public line in if your project uses Gatsby and *not* Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public
@ -130,3 +132,8 @@ dist
.yarn/install-state.gz
.pnp.*
# Temporary release-assets
.tagName.txt
.tagHeading.txt
.releaseNotes.md
.releaseTitle.md

7
.mocharc.jsonc Normal file
View file

@ -0,0 +1,7 @@
{
"spec": [
"./lib/tests/main.test.js"
],
"ui": "tdd",
"colors": true
}

167
.npmignore Normal file
View file

@ -0,0 +1,167 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
*.lcov
# nyc test coverage
.nyc_output
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# Snowpack dependency directory (https://snowpack.dev/)
web_modules/
# TypeScript cache
*.tsbuildinfo
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Optional stylelint cache
.stylelintcache
# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local
# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache
# Next.js build output
.next
out
# Nuxt.js build / generate output
.nuxt
dist
# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and *not* Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public
# vuepress build output
.vuepress/dist
# vuepress v2.x temp and cache directory
.temp
.cache
# Docusaurus cache and generated files
.docusaurus
# Serverless directories
.serverless/
# FuseBox cache
.fusebox/
# DynamoDB Local files
.dynamodb/
# TernJS port file
.tern-port
# Stores VSCode versions used for testing VSCode extensions
.vscode-test
# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
# Source-files
[Ss]rc/
# TypeScript config-files
tsconfig.json
tsconfig.*.json
# Lint config-files
.eslintrc
.eslintrc.*
# Source-maps
[Ll]ib/**/*.map
# Unit-Tests
.mocharc.*
[Ll]ib/tests/
# Visual Studio Code-Environment
.vscode/
# GitHub configuration
.github/
# CI configuration
.drone.yml
.woodpecker.yml
# Build System
webpack.config.ts
# Temporary release-assets
.tagName.txt
.tagHeading.txt
.releaseNotes.md
.releaseTitle.md

8
.vscode/extensions.json vendored Normal file
View file

@ -0,0 +1,8 @@
{
"recommendations": [
"dbaeumer.vscode-eslint",
"hbenl.test-adapter-converter",
"hbenl.vscode-mocha-test-adapter",
"hbenl.vscode-test-explorer"
]
}

25
.vscode/launch.json vendored Normal file
View file

@ -0,0 +1,25 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Tests",
"program": "${workspaceFolder}/node_modules/mocha/bin/mocha",
"args": [
"--timeout",
"0"
],
"internalConsoleOptions": "openOnSessionStart",
"preLaunchTask": "Build",
"sourceMaps": true,
"outFiles": [
"${workspaceFolder}/**/*.js",
"!**/node_modules/**"
]
}
]
}

10
.vscode/settings.json vendored Normal file
View file

@ -0,0 +1,10 @@
{
"javascript.format.insertSpaceAfterFunctionKeywordForAnonymousFunctions": false,
"javascript.format.placeOpenBraceOnNewLineForControlBlocks": true,
"javascript.format.placeOpenBraceOnNewLineForFunctions": true,
"typescript.format.insertSpaceAfterFunctionKeywordForAnonymousFunctions": false,
"typescript.format.placeOpenBraceOnNewLineForControlBlocks": true,
"typescript.format.placeOpenBraceOnNewLineForFunctions": true,
"mochaExplorer.require": "source-map-support/register",
"mochaExplorer.timeout": 0
}

39
.vscode/tasks.json vendored Normal file
View file

@ -0,0 +1,39 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "Build",
"type": "npm",
"script": "watch",
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": "$ts-webpack-watch",
"isBackground": true,
"presentation": {
"reveal": "never"
}
},
{
"label": "Rebuild",
"type": "npm",
"script": "rebuild",
"problemMatcher": "$ts-webpack",
"presentation": {
"reveal": "never"
}
},
{
"label": "Lint",
"type": "npm",
"script": "lint-ide",
"problemMatcher": "$eslint-stylish",
"presentation": {
"reveal": "never"
}
}
]
}

17
.woodpecker.yml Normal file
View file

@ -0,0 +1,17 @@
pipeline:
install:
image: node
commands:
- npm install
build:
image: node
commands:
- npm run build
lint:
image: node
commands:
- npm run lint
test:
image: node
commands:
- npm run test

8
CHANGELOG.md Normal file
View file

@ -0,0 +1,8 @@
# Changelog
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## ConnectForce [Unreleased]
- Initial release

View file

@ -1,3 +1,2 @@
# ConnectForce
A selfmade Connect Four game.

11
misc.tsconfig.json Normal file
View file

@ -0,0 +1,11 @@
{
"extends": "./tsconfig.base.json",
"compilerOptions": {
"noEmit": true,
"checkJs": true
},
"include": [
"./.eslintrc.cjs",
"./webpack.config.ts"
]
}

5141
package-lock.json generated Normal file

File diff suppressed because it is too large Load diff

57
package.json Normal file
View file

@ -0,0 +1,57 @@
{
"name": "connect-force",
"version": "0.0.0",
"type": "module",
"description": "A selfmade Connect Four game.",
"author": "Manuel Thalmann <m@nuth.ch>",
"exports": {
".": {
"import": {
"types": "./lib/index.d.ts",
"default": "./lib/index.js"
}
},
"./package.json": "./package.json"
},
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
"publishConfig": {
"access": "public"
},
"scripts": {
"webpack": "cross-env NODE_OPTIONS=\"--loader ts-node/esm\" webpack",
"build": "npm run webpack --",
"compile": "tsc -b tsconfig.build.json",
"rebuild": "npm run clean && npm run build",
"watch": "npm run build -- --watch",
"clean": "npm run compile -- --clean && rimraf ./lib",
"lint": "eslint --max-warnings 0 ./src .eslintrc.cjs",
"lint-ide": "npm run lint || exit 0",
"test": "mocha",
"prepare": "npm run rebuild"
},
"dependencies": {
"ts-keyof": "^1.3.0",
"ts-nameof-proxy": "^0.0.3"
},
"devDependencies": {
"@manuth/eslint-plugin-typescript": "^4.0.0",
"@manuth/tsconfig": "^3.0.2",
"@types/chai": "^4.3.4",
"@types/mocha": "^9.1.1",
"@types/node": "^18.7.18",
"@types/webpack": "^5.28.0",
"chai": "^4.3.7",
"cross-env": "^7.0.3",
"eslint": "^8.23.1",
"mocha": "^10.0.0",
"rimraf": "^3.0.2",
"source-map-support": "^0.5.21",
"ts-loader": "^9.4.2",
"ts-node": "^10.9.1",
"ts-patch": "^2.0.2",
"typescript": "^4.8.3",
"webpack": "^5.75.0",
"webpack-cli": "^5.0.0"
}
}

5
src/index.ts Normal file
View file

@ -0,0 +1,5 @@
// eslint-disable-next-line import/no-default-export
export default async (): Promise<void> =>
{
console.log("Hello World");
};

13
src/tests/main.test.ts Normal file
View file

@ -0,0 +1,13 @@
import { assert } from "chai";
suite(
"ConnectForce",
() =>
{
test(
"Example…",
() =>
{
assert.equal(1, 1);
});
});

12
src/tests/tsconfig.json Normal file
View file

@ -0,0 +1,12 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"rootDir": "..",
"outDir": "../../lib",
"composite": true
},
"include": [
"./**/*"
],
"references": []
}

14
tsconfig.app.json Normal file
View file

@ -0,0 +1,14 @@
{
"extends": "./tsconfig.base.json",
"compilerOptions": {
"composite": true,
"rootDir": "./src",
"outDir": "./lib"
},
"include": [
"./src/**/*"
],
"exclude": [
"./src/tests/**/*"
]
}

11
tsconfig.base.json Normal file
View file

@ -0,0 +1,11 @@
{
"extends": "@manuth/tsconfig/recommended",
"compilerOptions": {
"declaration": true,
"module": "Node16",
"lib": [
"ES2020"
],
"target": "ES6"
}
}

12
tsconfig.build.json Normal file
View file

@ -0,0 +1,12 @@
{
"extends": "./tsconfig.base.json",
"files": [],
"references": [
{
"path": "./tsconfig.app.json"
},
{
"path": "./src/tests"
}
]
}

12
tsconfig.json Normal file
View file

@ -0,0 +1,12 @@
{
"extends": "./tsconfig.base.json",
"files": [],
"references": [
{
"path": "./tsconfig.build.json"
},
{
"path": "./misc.tsconfig.json"
}
]
}

148
webpack.config.ts Normal file
View file

@ -0,0 +1,148 @@
import { writeFile } from "fs/promises";
import { dirname, isAbsolute, relative, resolve } from "path";
import { fileURLToPath } from "url";
import exports, { Configuration } from "webpack";
const { WatchIgnorePlugin } = exports;
let dirName = fileURLToPath(new URL(".", import.meta.url));
let generator = (env: any, argv: any): Configuration[] =>
{
return [
{
target: "web",
mode: env.production ? "production" : "development",
entry: {
main: "./src/index.ts",
...(
env.production ?
{} :
{
"tests/main.test": "./src/tests/main.test.ts"
})
},
output: {
filename: "[name].js",
path: resolve(dirName, "lib"),
devtoolModuleFilenameTemplate: (context: any) =>
{
let path = context.absoluteResourcePath;
// For regular files, this statement is true.
if (isAbsolute(path))
{
return path;
}
else
{
return `webpack://${context.namespace}/${context.resourcePath}${context.loaders === "" ? "" : `?${context.loaders}`}`;
}
},
libraryTarget: "module",
chunkFormat: "module",
environment: {
dynamicImport: true
}
},
devtool: "source-map",
resolve: {
extensions: [
".ts",
".js"
],
extensionAlias: {
".js": [
".js",
".ts"
],
".mjs": [
".mjs",
".mts"
],
".cjs": [
".cjs",
".cts"
]
}
},
plugins: [
new WatchIgnorePlugin(
{
paths: [
/\.d\.ts$/
]
}),
{
apply(compiler)
{
compiler.hooks.assetEmitted.tap(
{
name: "AdjustSourceMap"
},
async (file, { content, source, outputPath, compilation, targetPath }) =>
{
if (file.endsWith(".map"))
{
try
{
let sourceMap = JSON.parse(content.toString());
if (Array.isArray(sourceMap.sources))
{
sourceMap.sources = sourceMap.sources.map(
(source: string) =>
{
console.log(source);
// Prevent `webpack://` sources from being changed
if (isAbsolute(source))
{
// Change regular file paths to relative ones
return relative(dirname(targetPath), source);
}
else
{
return source;
}
});
// Overwrite old source map
await writeFile(targetPath, JSON.stringify(sourceMap));
}
}
catch {}
}
});
}
}
],
module: {
rules: [
{
test: /\.([cm]?ts|tsx)$/,
exclude: /node_modules/,
use: [
{
loader: "ts-loader",
options: {
configFile: resolve(dirName, "tsconfig.build.json"),
projectReferences: true,
compilerOptions: {
outDir: resolve(dirName, "lib", "temp")
}
}
}
]
}
]
},
experiments: {
outputModule: true
}
}
];
};
// eslint-disable-next-line import/no-default-export
export default generator;