Skip to content
This repository has been archived by the owner on Jun 5, 2024. It is now read-only.

Commit

Permalink
5.2.0 (#444)
Browse files Browse the repository at this point in the history
* Dependency Updates, Script Updates

* remove fs-extra

* patch doctor script, and remove some other issues

* Add missing extension for fileHelpers

* Increase Build Performance

* remove extraneous file

* Build Timers

* Clean Logs

* small dependency fix

* One more fix

* giga-tired

* Update Changelog, and package version
  • Loading branch information
Stuyk authored Oct 13, 2023
1 parent 55b6185 commit 910490d
Show file tree
Hide file tree
Showing 26 changed files with 369 additions and 16,294 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## 5.2.0

```
- Startup time performance improvements
- Upgrade dependencies
- Patch upgraded dependencies
```

## 5.1.0

```
Expand Down
37 changes: 17 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "altv-athena",
"version": "5.1.0",
"version": "5.2.0",
"description": "a roleplay framework for alt:V",
"author": "stuyk",
"type": "module",
Expand All @@ -16,46 +16,43 @@
"check": "tsc -p ./tsconfig.json | node ./scripts/fileChecker/index.js",
"fix": "node ./scripts/doctor/index.js",
"[-] Vue WebView Deployment": "",
"vue-dev": "node ./scripts/plugins/webview && node ./scripts/plugins/files && npx vite ./src-webviews --clearScreen=false --host=localhost --port=3000",
"vue-dev": "node ./scripts/plugins/webview.js && node ./scripts/plugins/files.js && npx vite ./src-webviews --clearScreen=false --host=localhost --port=3000",
"[-] Utility": "",
"docs": "npx typedoc --options ./src/core/typedoc.json && node ./scripts/documentation/index.js",
"fix-natives": "node ./scripts/natives-upgrade/index.js",
"test": ""
},
"devDependencies": {
"@altv/types-client": "^2.6.3",
"@altv/types-natives": "^1.5.3",
"@altv/types-server": "^2.7.3",
"@altv/types-shared": "^1.4.8",
"@altv/types-webview": "^1.0.5",
"@altv/types-client": "^3.0.3",
"@altv/types-natives": "^1.5.4",
"@altv/types-server": "^3.1.1",
"@altv/types-shared": "^1.6.6",
"@altv/types-webview": "^1.0.7",
"@altv/types-worker": "1.0.7",
"@babel/types": "^7.17.0",
"@stuyk/altv-config": "^4.0.1",
"@swc/cli": "0.1.62",
"@swc/core": "1.3.40",
"@types/glob": "^7.2.0",
"@swc/core": "1.3.92",
"@types/minimatch": "^3.0.5",
"@types/node": "^14.6.1",
"@types/sockjs": "^0.3.33",
"@types/sockjs-client": "^1.5.1",
"altv-pkg": "^2.2.0",
"fkill": "^8.0.1",
"fs-extra": "^10.1.0",
"glob": "^8.0.3",
"altv-pkg": "^2.3.1",
"fkill": "^8.1.1",
"glob": "^10.3.1",
"prettier": "^2.6.2",
"stylus": "^0.58.1",
"typescript": "4.6.3",
"vite": "^4.2.0",
"vite-plugin-monaco-editor": "^1.1.0",
"vue": "^3.2.47"
"typescript": "^5.2.2",
"vite": "^4.4.11",
"vue": "^3.3.4"
},
"dependencies": {
"@stuyk/ezmongodb": "3.0.0",
"@stuyk/ezmongodb": "3.0.1",
"@vitejs/plugin-vue": "^4.1.0",
"axios": "0.26.1",
"axios": "1.5.1",
"bip39": "^3.1.0",
"elliptic": "6.5.4",
"njwt": "^1.2.0",
"njwt": "^2.0.0",
"sjcl": "1.0.8",
"sockjs": "0.3.21",
"sockjs-client": "1.5.2"
Expand Down
37 changes: 12 additions & 25 deletions scripts/buildresource/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import fs from 'fs-extra';
import glob from 'glob';
import path from 'path';
import { sanitizePath } from '../shared/path.js';
import { globSync, writeFile } from '../shared/fileHelpers.js';

const scriptPath = path.join(process.cwd(), '/scripts/buildresource/resource.json');
const scriptPath = sanitizePath(path.join(process.cwd(), '/scripts/buildresource/resource.json'));
const defaults = {
type: 'js',
main: 'server/startup.js',
Expand All @@ -13,33 +13,20 @@ const defaults = {
};

async function getClientPluginFolders() {
let folders = [];

const removalPath = path.join(process.cwd(), 'src/core/').replace(/\\/gm, '/');
const results = await new Promise((resolve) => {
glob(path.join(process.cwd(), `src/core/plugins/**/@(client|shared)`).replace(/\\/g, '/'), (err, files) => {
if (err) {
resolve([]);
return;
}

files = files.map((fileName) => {
return fileName.replace(removalPath, '') + `/*`;
});

resolve(files);
});
});

folders = folders.concat(results);
return folders;
const removalPath = sanitizePath(path.join(process.cwd(), 'src/core/'));
const results = globSync(sanitizePath(path.join(process.cwd(), `src/core/plugins/**/@(client|shared)`))).map(
(fileName) => {
return fileName.replace(removalPath, '') + `/*`;
},
);

return results;
}

async function start() {
const folders = await getClientPluginFolders();
defaults['client-files'] = [...defaults['client-files'], ...folders];

fs.outputFileSync(scriptPath, JSON.stringify(defaults, null, '\t'));
writeFile(scriptPath, JSON.stringify(defaults, null, '\t'));
}

start();
12 changes: 6 additions & 6 deletions scripts/clothes/getFileNames.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import glob from 'glob';
import fs from 'fs'
import { globSync, writeFile } from '../shared/fileHelpers.js';

async function start() {
const files = glob.sync(`./src-webviews/public/assets/images/clothing/**/*.png`)
let files = globSync(`./src-webviews/public/assets/images/clothing/**/*.png`);

for (let i = 0; i < files.length; i++) {
files[i] = files[i].split(`/`).pop();
}

const componentsList = files.filter(f => {
const componentsList = files.filter((f) => {
if (f.includes('prop')) {
return false;
}
Expand All @@ -19,7 +19,7 @@ async function start() {
return true;
});

fs.writeFileSync('clothes.json', JSON.stringify(componentsList, null, '\t'));
writeFile('clothes.json', JSON.stringify(componentsList, null, '\t'));
}

start();
start();
94 changes: 45 additions & 49 deletions scripts/compiler/core.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,20 @@
import swc from '@swc/core';
import fs from 'fs-extra';
import glob from 'glob';
import path from 'path';
import fs from 'node:fs';
import { copySync, getAllPluginFolders, getPluginFolder, globSync, writeFile } from '../shared/fileHelpers.js';
import { sanitizePath } from '../shared/path.js';

const viablePluginDisablers = ['disable.plugin', 'disabled.plugin', 'disable'];

/** @type {import('@swc/core').Config} */
const SWC_CONFIG = {
jsc: {
parser: {
syntax: 'typescript',
dynamicImport: true,
decorators: true,
},
transform: {
legacyDecorator: true,
decoratorMetadata: true,
},
target: 'es2020',
},
sourceMaps: false,
};

function sanitizePath(p) {
return p.replace(/\\/g, path.sep);
}

function getEnabledPlugins() {
const rootPath = sanitizePath(path.join(process.cwd(), 'src/core/plugins')).replace(/\\/g, '/');
const pluginFolders = fs.readdirSync(rootPath);
const pluginFolder = getPluginFolder();
const pluginFolders = getAllPluginFolders();

return pluginFolders.filter((pluginName) => {
const pluginPath = sanitizePath(path.join(rootPath, pluginName)).replace(/\\/g, '/');
const pluginPath = sanitizePath(path.join(pluginFolder, pluginName));

for (const fileName of viablePluginDisablers) {
const disabledPath = sanitizePath(path.join(pluginPath, fileName)).replace(/\\/g, '/');
const disabledPath = sanitizePath(path.join(pluginPath, fileName));

if (fs.existsSync(disabledPath)) {
return false;
Expand All @@ -47,7 +27,7 @@ function getEnabledPlugins() {

function getFilesForTranspilation(enabledPlugins) {
const rootPath = sanitizePath(path.join(process.cwd(), 'src/**/*.ts').replace(/\\/g, '/'));
const files = glob.sync(rootPath, {
const files = globSync(rootPath, {
nodir: true,
ignore: [
'**/node_modules/**',
Expand All @@ -57,7 +37,7 @@ function getFilesForTranspilation(enabledPlugins) {

for (const pluginName of enabledPlugins) {
const pluginPath = sanitizePath(path.join(process.cwd(), 'src/core/plugins', pluginName).replace(/\\/g, '/'));
const pluginFiles = glob.sync(path.join(pluginPath, '**/*.ts').replace(/\\/g, '/'), {
const pluginFiles = globSync(path.join(pluginPath, '**/*.ts').replace(/\\/g, '/'), {
nodir: true,
ignore: ['**/imports.ts', '**/webview/**'],
});
Expand All @@ -72,8 +52,7 @@ function getFilesForTranspilation(enabledPlugins) {

function getFilesToCopy(enabledPlugins) {
const filePath = sanitizePath(path.join(process.cwd(), 'src', '**/*.!(ts|vue)').replace(/\\/g, '/'));

return glob.sync(filePath, {
return globSync(filePath, {
nodir: true,
ignore: ['**/tsconfig.json', '**/dependencies.json', `**/core/plugins/!(${enabledPlugins.join('|')})/**`],
});
Expand Down Expand Up @@ -103,35 +82,50 @@ function resolvePaths(file, rawCode) {
return rawCode;
}

/**
* Transpile / compile a typescript file
*
* @param {Promise<void>} file
*/
async function transpileFile(file) {
const targetPath = file.replace('src/', 'resources/').replace('.ts', '.js');
const result = await swc.transformFile(file, {
jsc: {
parser: {
syntax: 'typescript',
dynamicImport: true,
decorators: true,
},
transform: {
legacyDecorator: true,
decoratorMetadata: true,
},
target: 'es2020',
},
sourceMaps: false,
});

return new Promise(async (resolve) => {
const result = await swc.transformFile(file, SWC_CONFIG);
if (!result) {
console.warn(`Failed to compile: ${targetPath}`);
}
if (!result) {
console.warn(`Failed to compile: ${targetPath}`);
}

// The path resolvers are really awful, so writing a custom one here.
if (result.code.includes('@Athena')) {
result.code = resolvePaths(file, result.code);
}
// The path resolvers are really awful, so writing a custom one here.
if (result.code.includes('@Athena')) {
result.code = resolvePaths(file, result.code);
}

const finalFile = `// YOU ARE EDITING COMPILED FILES. DO NOT EDIT THESE FILES \r\n` + result.code;
fs.outputFileSync(targetPath, finalFile);
resolve();
});
const finalFile = `// YOU ARE EDITING COMPILED FILES. DO NOT EDIT THESE FILES \r\n` + result.code;
writeFile(targetPath, finalFile);
}

async function run() {
const startTime = +new Date();
const enabledPlugins = getEnabledPlugins();

const filesToTranspile = getFilesForTranspilation(enabledPlugins);
const filesToCopy = getFilesToCopy(enabledPlugins);

const resourcesFolder = sanitizePath(path.join(process.cwd(), 'resources')).replace(/\\/g, '/');
const filesAndDirectories = await fs.readdir(resourcesFolder);
const filesAndDirectories = await fs.readdirSync(resourcesFolder);

for (const fileOrDirectory of filesAndDirectories) {
const fullPath = sanitizePath(path.join(resourcesFolder, fileOrDirectory)).replace(/\\/g, '/');
Expand All @@ -146,13 +140,15 @@ async function run() {

for (const file of filesToCopy) {
const targetPath = file.replace('src/', 'resources/');
fs.copy(file, targetPath, { overwrite: true });
if (file === targetPath) {
continue;
}

copySync(file, targetPath);
}

const promises = filesToTranspile.map((file) => transpileFile(file));
await Promise.all(promises);

console.log(`Compiled: ${filesToTranspile.length} || Copied: ${filesToCopy.length}`);
}

run();
Loading

0 comments on commit 910490d

Please sign in to comment.