Skip to content

Commit

Permalink
Further fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Idrinth committed May 12, 2024
1 parent 9f887cb commit 5da8433
Show file tree
Hide file tree
Showing 11 changed files with 266 additions and 53 deletions.
110 changes: 110 additions & 0 deletions .dictionary.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
2xx
APIs
Autowiring
Benchmarking
Björn
Büttner
CLI
Codacy
Destructuring
DockerHub
Dockerfiles
ENV
Fastify
vue
Gitea
Gitlab
HAR
Idrinth's
airtimeux.com
JSON
Javascript
Jira
LinkedIn
MSSQL
Matomo
Microservice
Middleware
Middlewares
Mindmap
NPMJS
Node.js
OpenApi
OpenSauced
PascalCase
Postgres
README
Reddit
Roadmap
SHA
Web-UI
XML
XRAY_CLIENT_ID
XRAY_CLIENT_SECRET
XRAY_ENDPOINT
XRAY_PASSWORD
XRAY_TEST_PLAN_KEY
XRAY_USER_NAME
XRay
aBc
api-bench
api-bench-cli
api-bench-gitea-action
api-bench-gitlab-runner
api-bench-history-microservice
api-bench-history-website
api-bench-runner
api-benchmark
autowire
autowired
benchmarking
bugfixes
bvanderlaan
camelCase
ci-images
coai
codecheck
csrf-header
data.yml
deprecations
dockerfiles
eslint
faq
gitea
gitlab
gitlab-runner
history-microservice
iab
idrinth
idrinth-api-bench
jeffbski
json
jungwild
macOS
markmap
matteofigus
microservice
microservices
middleware
middlewares
mindmap
mono-repo
npm
ns
package.json
pino
pre
programmatically
readme
rest-APIs
sexualised
src
subprojects
tracking.bjoern-buettner.me
ui
UI
webmaster@idrinth-api-ben.ch
winston
www.contributor-covenant.org
www.youtube-nocookie.com
xml
2 changes: 1 addition & 1 deletion .github/workflows/fta.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ jobs:
package-lock.json
- run: npm ci
- run: npm run language
- run: npm run ftas
- run: npm run fta
2 changes: 1 addition & 1 deletion .knip.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"$schema": "https://unpkg.com/knip@5/schema.json",
"entry": ["index.ts", "src/middlewares/*.ts", "src/locales/*.ts", "worker/*.js", "bin/*.js", "tools/*.js", "test/**/*.ts", "integration/**/*.ts", "property/**/*.ts"],
"project": ["index.ts", "src/**/*.ts", "test/**/*.ts", "integration/**/*.ts", "property/**/*.ts", "tools/*.js"],
"ignoreDependencies": ["@idrinth/api-bench-cli", "ts-node"]
"ignoreDependencies": ["ts-node"]
}
4 changes: 0 additions & 4 deletions bin/check-route-definitions.js

This file was deleted.

4 changes: 0 additions & 4 deletions bin/run-loadtest.js

This file was deleted.

16 changes: 11 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 4 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,10 @@
"winston": "^3.11.0",
"markdownlint-cli": "^0.40.0",
"spellchecker-cli": "^6.2.0",
"knip": "^5.13.0"
"knip": "^5.13.0",
"fta-cli": "^2.0.0"
},
"bin": {
"check-route-definitions": "bin/check-route-definitions.js",
"run-loadtest": "bin/run-loadtest.js",
"iabl": "bin/run-loadtest.js",
"iabcrd": "bin/check-route-definitions.js",
"iab": "bin/iab.js"
},
"scripts": {
Expand All @@ -103,7 +100,8 @@
"spellcheck": "itlfy dump && spellchecker",
"knip": "knip --exclude duplicates --exclude exports --exclude types",
"commitlint": "commitlint --edit",
"commitlint-ci": "commitlint --latest"
"commitlint-ci": "commitlint --from latest",
"fta": "node tools/fta.js"
},
"engines": {
"node": ">=20"
Expand Down
21 changes: 0 additions & 21 deletions test/cli/bench.ts

This file was deleted.

11 changes: 0 additions & 11 deletions test/cli/check-routes.ts

This file was deleted.

7 changes: 7 additions & 0 deletions tools/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const FIRST_ARGUMENT = 2;
export const EXIT_SUCCESS = 0;
export const EXIT_FAILURE = 1;
export const EMPTY = 0;
export const ERROR_FTA_SCORE = 60;
export const WARNING_FTA_SCORE = 60;
export const PADDING_DEFAULT = 1;
132 changes: 132 additions & 0 deletions tools/fta.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
import {
EXIT_FAILURE,
EXIT_SUCCESS,
FIRST_ARGUMENT,
ERROR_FTA_SCORE,
WARNING_FTA_SCORE,
PADDING_DEFAULT,
} from './constants.js';
import path from 'path';
import fs from 'fs';
import {
execSync,
} from 'child_process';

const platform = process.platform;
const architecture = process.arch;

// eslint-disable-next-line complexity
const getBinaryPath = () => {
const targetDirectory = path.join(
process.cwd(),
'node_modules',
'fta-cli',
'binaries',
);

switch (platform) {
case 'win32':
if (architecture === 'x64') {
return path.join(targetDirectory, 'x86_64-pc-windows-msvc', 'fta.exe',);
}
if (architecture === 'arm64') {
return path.join(
targetDirectory,
'aarch64-pc-windows-msvc',
'fta.exe',
);
}
break;
case 'darwin':
if (architecture === 'x64') {
return path.join(targetDirectory, 'x86_64-apple-darwin', 'fta',);
} else if (architecture === 'arm64') {
return path.join(targetDirectory, 'aarch64-apple-darwin', 'fta',);
}
break;
case 'linux':
if (architecture === 'x64') {
return path.join(targetDirectory, 'x86_64-unknown-linux-musl', 'fta',);
} else if (architecture === 'arm64') {
return path.join(targetDirectory, 'aarch64-unknown-linux-musl', 'fta',);
} else if (architecture === 'arm') {
return path.join(targetDirectory, 'arm-unknown-linux-musleabi', 'fta',);
}
break;
default:
throw new Error('Unsupported platform: ' + platform,);
}

throw new Error('Binary not found for the current platform',);
};

const setUnixPerms = (binaryPath,) => {
if (platform === 'darwin' || platform === 'linux') {
try {
fs.chmodSync(binaryPath, '755',);
} catch (e) {
console.warn('Could not chmod fta binary: ', e,);
}
}
};

const binary = getBinaryPath();
setUnixPerms(binary,);
const output = JSON.parse(execSync(
`${ binary } ${ process.cwd() } --json`,

Check warning

Code scanning / CodeQL

Shell command built from environment values Medium

This shell command depends on an uncontrolled
absolute path
.
This shell command depends on an uncontrolled
absolute path
.
{
encoding: 'utf8',
stdio: 'pipe',
},
).toString(),);

let hardToMaintain = false;
let maxLength = 0;
let maxScore = 0;
let maxAfter = 0;

for (const file of output) {
file.name = `${ process.argv[FIRST_ARGUMENT] }/${ file.file_name }`;
maxLength = maxLength > file.name.length ? maxLength : file.name.length;
maxScore = maxScore > `${ file.fta_score }`.split('.',).shift().length
? maxScore
: `${ file.fta_score }`.split('.',).shift().length;
maxAfter = maxAfter > `${ file.fta_score }`.split('.',).pop().length
? maxScore
: `${ file.fta_score }`.split('.',).pop().length;
}

for (const file of output) {
const padding = new Array(maxLength - file.name.length + PADDING_DEFAULT,)
.fill(' ',)
.join('',);
const before = new Array(
maxScore
- `${ file.fta_score }`.split('.',).shift().length
+ PADDING_DEFAULT,
)
.fill(' ',)
.join('',);
const after = new Array(
maxAfter
- `${ file.fta_score }`.split('.',).pop().length
+ PADDING_DEFAULT,
)
.fill('0',)
.join('',);
const message = [
`${ file.name }${ padding }`,
`${ before }${ file.fta_score }${ after.replace(/0$/u, ' ',) }`,
` ${ file.assessment }`,
].join('|',);
if (file.fta_score > ERROR_FTA_SCORE) {
hardToMaintain = true;
console.error(message,);
} else if (file.fta_score > WARNING_FTA_SCORE) {
console.warn(message,);
} else {
console.log(message,);
}
}

process.exit(hardToMaintain ? EXIT_FAILURE : EXIT_SUCCESS,);

0 comments on commit 5da8433

Please sign in to comment.