Skip to content

Commit

Permalink
refactor: v7 codebase well some changes to tools (#674)
Browse files Browse the repository at this point in the history
  • Loading branch information
USERSATOSHI authored Oct 21, 2024
1 parent 783e1dc commit 9d1637b
Show file tree
Hide file tree
Showing 219 changed files with 6,656 additions and 15,501 deletions.
4 changes: 2 additions & 2 deletions bin/add.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ test('log', () => {
name: 'package.json',
type: 'file',
content: `{
"name": "@akarui/${lib}",
"name": "@aoijs/${lib}",
"version": "0.0.1",
"description": "@akarui/${lib} - A Extension for Aoi.js",
"description": "@aoijs/${lib} - A Extension for Aoi.js",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
"types": "dist/types/index.d.ts",
Expand Down
13 changes: 10 additions & 3 deletions bin/index.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#!/usr/bin/env node

process.removeAllListeners('warning');
#!/usr/bin/env -S node --no-warnings=ExperimentalWarning

import { program } from 'commander';
import test from './test.mjs';
Expand All @@ -12,11 +10,13 @@ import pkg from './package.json' assert { type: 'json' };
import chalk from 'chalk';
import add from './add.mjs';
import addLicense from './addLicense.mjs';
import run from './run.mjs';

program
.command('test')
.description('run all tests for the given library')
.requiredOption('-l, --library <library>', 'the library to test')
.option('-f, --folder <folder>', 'the folder to test in the library')
.action(test);

program
Expand Down Expand Up @@ -56,6 +56,13 @@ program
.requiredOption('-l, --library <library>', 'the library to license')
.action(addLicense);

program
.command('run')
.description('run a file for the given library')
.requiredOption('-l, --library <library>', 'the library to run')
.requiredOption('-f, --file <file>', 'the file to run')
.action(run);

program
.name(pkg.name)
.version(pkg.version)
Expand Down
45 changes: 45 additions & 0 deletions bin/run.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import path from 'node:path';
import { spawn } from 'node:child_process';

/**
* Run given path for the given library
* @param {object} options - The options object
* @param {string} options.library - The library to test
* @param {string} options.path - The path to the file that needs to be run
* @returns {Promise<void>}
*/
const run = async ({ library, file: filePath }) => {
console.log(`Running ${filePath} from ${library}`);

// Resolve paths in a cross-platform way
const mainFolder = path.join(process.cwd(), 'lib', library);

const spwn = spawn(
`node ${filePath}`,
[],
{
stdio: 'inherit',
// Set cwd to the project root
cwd: mainFolder,
shell: true,
},
);

spwn.on('exit', (code) => {
if (code !== 0) {
console.error(`Failed to run ${filePath} from ${library}`);
process.exit(1);
}
});

spwn.on('error', (error) => {
console.error(error);
process.exit(1);
});

spwn.on('close', () => {
console.log(`finished running ${filePath} from ${library}`);
});
};

export default run;
55 changes: 31 additions & 24 deletions bin/test.mjs
Original file line number Diff line number Diff line change
@@ -1,33 +1,39 @@
import path from 'node:path';
import { spawn } from 'node:child_process';

import { pathToFileURL } from 'node:url';
import chalk from 'chalk';
/**
* run all tests for the given library
* @param {object} options - the options object
* @param {string} options.library - the library to test
* Run all tests for the given library
* @param {object} options - The options object
* @param {string} options.library - The library to test
* @returns {Promise<void>}
*/
const test = async ({ library }) => {
const test = async ({ library, folder, reporter }) => {
const start = performance.now();
console.log(`Running tests for ${library}`);

// find all test files in the library
// recursively check all folders for test files
const mainFolder = path.resolve(process.cwd(), `lib/${library}`);

// Resolve paths in a cross-platform way
const mainFolder = path.join(process.cwd(), 'lib', library);
const reporterPath = pathToFileURL(
path.join(process.cwd(), 'tools', 'testing', 'testReporter.mjs'),
);
const flags = folder ? `--folder=${folder}` : '';
const runnerPath = path.join(
process.cwd(),
'tools',
'testing',
'testRunner.mjs',
);
// "glob -c \"tsx --test\" \"./src/**/*.test.ts\""
const spwn = spawn(
'npx',
[
'jest',
'--verbose',
'--color',
'--coverage',
'--coverageProvider=v8',
`--config=${process.cwd()}/jest.config.js`,
`${mainFolder}`,
],
// `npx glob -c "tsx --test-reporter="${reporterPath.toString()}" --test" "./src/**/*.test.ts"`,
`node --import tsx "${runnerPath.toString()}" -- ${flags}`,
[],
{
stdio: 'inherit',
cwd: mainFolder,
// Set cwd to the project root
cwd: `${mainFolder}`,
shell: true,
},
);

Expand All @@ -45,10 +51,11 @@ const test = async ({ library }) => {

spwn.on('close', () => {
console.log(`Tested ${library}`);
});

spwn.on('disconnect', () => {
console.log('Disconnected');
console.log(
chalk.gray(
`Duration: ${((performance.now() - start) / 1000).toFixed(2)}s`,
),
);
});
};

Expand Down
16 changes: 12 additions & 4 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable @typescript-eslint/naming-convention */
import globals from 'globals';
import tseslint from 'typescript-eslint';
// import tseslint from 'typescript-eslint';
import jsdoc from 'eslint-plugin-jsdoc';
import tsdoc from 'eslint-plugin-tsdoc';

Expand All @@ -23,7 +24,7 @@ export default [

...compat.extends('xo-typescript'),
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
...tseslint.configs.stylisticTypeChecked,
// ...tseslint.configs.stylisticTypeChecked,
{
// enable object curly spacing
rules: {
Expand All @@ -32,22 +33,29 @@ export default [
'error',
'interface',
],
'@typescript-eslint/parameter-properties': 'off',
'@typescript-eslint/naming-convention': [
'error',
{
selector: 'variable',
format: ['camelCase'],
format: ['camelCase', 'UPPER_CASE'],
leadingUnderscore: 'allow',
},
{
selector: 'classProperty',
format: [''],
format: ['camelCase'],
leadingUnderscore: 'allow',
trailingUnderscore: 'allow',
},
{ selector: 'parameter', format: ['camelCase'] },
{ selector: 'typeLike', format: ['PascalCase'] },
],
'@typescript-eslint/prefer-literal-enum-member': [
'error',
{
allowBitwiseExpressions: true,
},
],
},
},
{
Expand Down
5 changes: 0 additions & 5 deletions jest.config.js

This file was deleted.

7 changes: 0 additions & 7 deletions jsconfig.json

This file was deleted.

6 changes: 3 additions & 3 deletions lib/aoi.db/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@akarui/aoi.db",
"name": "@aoijs/aoi.db",
"version": "0.0.1",
"description": "@akarui/aoi.db - A Extension for Aoi.js",
"description": "@aoijs/aoi.db - A Extension for Aoi.js",
"main": "./dist/cjs/index.js",
"module": "./dist/esm/index.js",
"types": "./dist/types/index.d.ts",
Expand Down Expand Up @@ -44,6 +44,6 @@
},
"readme": "https://github.com/Aoijs/aoi.js/blob/main/README.md",
"dependencies": {
"@akarui/structures": "workspace:^"
"@aoijs/structures": "workspace:^"
}
}
2 changes: 2 additions & 0 deletions lib/aoi.js/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
node_modules
dist
coverage
index.mjs
index.js
4 changes: 2 additions & 2 deletions lib/aoi.js/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# @aoijs/aoi.js
# @akarui/aoi.js

dev version for Aoi.js
A Extension for Aoi.js
71 changes: 0 additions & 71 deletions lib/aoi.js/generators/readme.js

This file was deleted.

Loading

0 comments on commit 9d1637b

Please sign in to comment.