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

Commit

Permalink
Finish Client Migration / API Update (#395)
Browse files Browse the repository at this point in the history
* in progress

* More Migrations

* Upgrade Packages, Vite Server, etc.

* force localhost for vue-dev

* Fix File Cleaning Bug
  • Loading branch information
Stuyk committed Mar 16, 2023
1 parent dbc1e2f commit 31ae17b
Show file tree
Hide file tree
Showing 143 changed files with 3,989 additions and 4,875 deletions.
16 changes: 7 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"check": "tsc --noEmit -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",
"vue-dev": "node ./scripts/plugins/webview && node ./scripts/plugins/files && npx vite ./src-webviews --clearScreen=false --host=localhost --port=3000",
"[-] Utility": "",
"docs": "npx typedoc --options ./src/core/typedoc.json",
"fix-natives": "node ./scripts/natives-upgrade/index.js",
Expand All @@ -31,16 +31,14 @@
"@altv/types-worker": "1.0.7",
"@babel/types": "^7.17.0",
"@stuyk/altv-config": "^4.0.1",
"@swc/cli": "0.1.57",
"@swc/core": "1.2.171",
"@swc/cli": "0.1.62",
"@swc/core": "1.3.40",
"@types/glob": "^7.2.0",
"@types/minimatch": "^3.0.5",
"@types/node": "^14.6.1",
"@types/sockjs": "^0.3.33",
"@types/sockjs-client": "^1.5.1",
"@vitejs/plugin-vue": "^2.3.1",
"@vue/compiler-sfc": "^3.2.33",
"altv-pkg": "^2.0.4",
"altv-pkg": "^2.0.10",
"fkill": "^8.0.1",
"fs-extra": "^10.1.0",
"glob": "^8.0.3",
Expand All @@ -52,12 +50,12 @@
"typedoc-plugin-missing-exports": "^1.0.0",
"typedoc-theme-hierarchy": "^3.0.2",
"typescript": "4.6.3",
"vite": "^2.9.5",
"vue": "^3.2.33",
"vue-tsc": "^1.0.9"
"vite": "^4.2.0",
"vue": "^3.2.47"
},
"dependencies": {
"@stuyk/ezmongodb": "3.0.0",
"@vitejs/plugin-vue": "^4.1.0",
"axios": "0.26.1",
"elliptic": "6.5.4",
"njwt": "^1.2.0",
Expand Down
10 changes: 4 additions & 6 deletions scripts/compiler/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ async function transpileFile(file) {
result.code = resolvePaths(file, result.code);
}

fs.outputFileSync(targetPath, result.code);
const finalFile = `// YOU ARE EDITING COMPILED FILES. DO NOT EDIT THESE FILES \r\n` + result.code;
fs.outputFileSync(targetPath, finalFile);
resolve();
});
}
Expand All @@ -134,7 +135,7 @@ async function run() {

for (const fileOrDirectory of filesAndDirectories) {
const fullPath = sanitizePath(path.join(resourcesFolder, fileOrDirectory)).replace(/\\/g, '/');
if (!fullPath.includes('core') || !fullPath.includes('webviews')) {
if (!fullPath.includes('core') && !fullPath.includes('webviews')) {
continue;
}

Expand All @@ -151,10 +152,7 @@ async function run() {
const promises = filesToTranspile.map((file) => transpileFile(file));
await Promise.all(promises);

const elapsedTime = +new Date() - startTime;
console.log(`Transpiled ${filesToTranspile.length} files`);
console.log(`Copied ${filesToCopy.length} files to resources folder`);
console.log(`Build completed in: ${elapsedTime}ms`);
console.log(`Compiled: ${filesToTranspile.length} || Copied: ${filesToCopy.length}`);
}

run();
5 changes: 1 addition & 4 deletions scripts/plugins/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,7 @@ function run() {

writeServerImports(serverImports);
writeClientImports(clientImports);

console.log(
`Enabled plugins: ${enabledPlugins.length} (${clientImports.length} client, ${serverImports.length} server)`,
);
console.log(`Plugin(s): ${enabledPlugins.length}`);
}

run();
4 changes: 0 additions & 4 deletions scripts/plugins/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ export function moveAssetsToWebview(folderName, extensions) {
amountCopied += 1;
}
}

console.log(`${folderName} - ${amountCopied} Files Available at Path (/plugins) in Webview`);
}

export function movePluginFilesToWebview(folderName, extensions, isSrc = false) {
Expand Down Expand Up @@ -131,6 +129,4 @@ export function movePluginFilesToWebview(folderName, extensions, isSrc = false)
}
}
}

console.log(`${folderName} - ${amountCopied} Files Added to WebView Plugins - (${extensions.join('|')})`);
}
23 changes: 9 additions & 14 deletions scripts/runtime/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ async function handleConfiguration() {
configName = 'devtest';
}

console.log(`===> Starting Configuration Build`);
const start = Date.now();
let promises = [];

Expand All @@ -102,7 +101,6 @@ async function handleConfiguration() {
promises.push(
runFile(npx, 'altv-config', './scripts/buildresource/resource.json', './resources/core/resource.toml'),
);
console.log(`===> Finished Configuration Build (${Date.now() - start}ms)`);
return await Promise.all(promises);
}

Expand All @@ -111,17 +109,19 @@ async function handleViteDevServer() {
lastViteServer.kill();
}

console.log(`===> Starting Vite Server`);
await runFile(node, './scripts/plugins/webview.js');
lastViteServer = spawn(npx, ['vite', './src-webviews', '--clearScreen=false', '--debug=true'], {
stdio: 'inherit',
});
lastViteServer = spawn(
npx,
['vite', './src-webviews', '--clearScreen=false', '--debug=true', '--host=localhost', '--port=3000'],
{
stdio: 'inherit',
},
);

lastViteServer.once('close', (code) => {
console.log(`Vite process exited with code ${code}`);
});

console.log(`===> Started Vite Server`);
return await new Promise((resolve) => {
setTimeout(resolve, 2000);
});
Expand All @@ -132,9 +132,7 @@ function handleStreamerProcess(shouldAutoRestart = false) {
lastStreamerProcess.kill();
}

console.log(`===> Starting Streamer Process`);
lastStreamerProcess = spawn(node, ['./scripts/streamer/dist/index.js'], { stdio: 'inherit' });

lastStreamerProcess.once('close', (code) => {
console.log(`Streamer process exited with code ${code}`);
if (shouldAutoRestart) {
Expand All @@ -148,8 +146,6 @@ async function handleServerProcess(shouldAutoRestart = false) {
lastServerProcess.kill();
}

console.log(`===> Starting Server Process`);

if (process.platform !== 'win32') {
await runFile('chmod', '+x', `./altv-server`);
}
Expand Down Expand Up @@ -218,13 +214,13 @@ async function refreshFileWatching() {
}

async function coreBuildProcess() {
console.log('===> Starting Core Build');
const start = Date.now();
await runFile(node, './scripts/compiler/core');
await runFile(node, './scripts/plugins/core');
await runFile(node, './scripts/plugins/webview');
await runFile(node, './scripts/plugins/files');
console.log(`===> Finished Core Build (${Date.now() - start}ms)`);
await runFile(node, './scripts/transform/index');
console.log(`Build Time - ${Date.now() - start}ms`);
}

async function devMode(firstRun = false) {
Expand Down Expand Up @@ -253,7 +249,6 @@ async function runServer() {
const isDev = passedArguments.includes('dev');

//Update dependencies for all the things
console.log('===> Updating dependencies for plugins');
await runFile(node, './scripts/plugins/update-dependencies');

if (isDev) {
Expand Down
79 changes: 79 additions & 0 deletions scripts/transform/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import path from 'path';
import glob from 'glob';
import fs from 'fs';

const startTime = Date.now();
const resourcePath = path.join(process.cwd(), 'resources/core/**/*.js').replace(/\\/gm, '/');
const filePaths = glob.sync(resourcePath);

const funcsToIgnore = [
//
'export function',
'export const',
'export let',
'export async function',
'=>',
];

let count = 0;
for (let filePath of filePaths) {
const fileContents = fs.readFileSync(filePath, { encoding: 'utf-8' });
const splitContents = fileContents.split(/\r?\n/);

const filePathing = filePath.split('/');
filePathing.pop();
const directoryPath = filePathing.join('/');

let wasModified = false;
for (let i = 0; i < splitContents.length; i++) {
if (!splitContents[i].includes('import') && !splitContents[i].includes('export')) {
continue;
}

let shouldSkip = false;
for (let funcToIgnore of funcsToIgnore) {
if (splitContents[i].includes(funcToIgnore)) {
shouldSkip = true;
break;
}
}

if (shouldSkip) {
continue;
}

const filePathReg = new RegExp(/('|").*.('|")/g);
const extractions = splitContents[i].match(filePathReg);
if (extractions === null || !extractions) {
continue;
}

const relativeFilePath = extractions[0].replace(/'/gm, '').replace(/"/gm, '');
if (relativeFilePath.charAt(0) !== '.' && relativeFilePath.charAt(0) !== '/') {
continue;
}

const actualFilePath = path.join(directoryPath, relativeFilePath).replace(/\\/gm, '/');
if (fs.existsSync(actualFilePath)) {
const barrelFileTest = fs.statSync(actualFilePath);
if (barrelFileTest.isDirectory()) {
splitContents[i] = splitContents[i].replace(relativeFilePath, `${relativeFilePath}/index.js`);
wasModified = true;
continue;
}
}

if (!splitContents[i].includes('.js')) {
splitContents[i] = splitContents[i].replace(relativeFilePath, `${relativeFilePath}.js`);
wasModified = true;
}
}

if (!wasModified) {
continue;
}

const finalFile = splitContents.join('\r\n');
fs.writeFileSync(filePath, finalFile, { encoding: 'utf-8' });
count += 1;
}
64 changes: 31 additions & 33 deletions src-webviews/src/App.vue
Original file line number Diff line number Diff line change
@@ -1,37 +1,35 @@
<template>
<keep-alive>
<div class="page">
<!-- Developer Menu for Local Host -->
<VueDevMenu
:pages="getAllPageNames"
:previousPages="pages"
@DevUpdatePages="devUpdatePages"
v-if="isDevMenu()"
/>
<!-- Displays Individual Pages -->
<component
v-for="(page, index) in pages"
:key="index"
:is="page.component"
:id="'page-' + page.name"
:state="state"
></component>
<component
v-for="(page, index) in overlays"
:key="index"
:is="page.component"
:id="'page-' + page.name"
:state="state"
></component>
<component
v-for="(page, index) in persistent"
:key="index"
:is="page.component"
:id="'page-' + page.name"
:state="state"
></component>
</div>
</keep-alive>
<div class="page">
<!-- Developer Menu for Local Host -->
<VueDevMenu
:pages="getAllPageNames"
:previousPages="pages"
@DevUpdatePages="devUpdatePages"
v-if="isDevMenu()"
/>
<!-- Displays Individual Pages -->
<component
v-for="(page, index) in pages"
:key="index"
:is="page.component"
:id="'page-' + page.name"
:state="state"
/>
<component
v-for="(page, index) in overlays"
:key="index"
:is="page.component"
:id="'page-' + page.name"
:state="state"
/>
<component
v-for="(page, index) in persistent"
:key="index"
:is="page.component"
:id="'page-' + page.name"
:state="state"
/>
</div>
</template>

<script lang="ts">
Expand Down
2 changes: 1 addition & 1 deletion src-webviews/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import * as path from 'path';
import vue from '@vitejs/plugin-vue';

// https://vitejs.dev/config/
export default defineConfig({
Expand Down
33 changes: 0 additions & 33 deletions src/core/client/api/athena.ts

This file was deleted.

6 changes: 3 additions & 3 deletions src/core/client/api/consts/cameraConst.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { GameplayCamera } from '@AthenaClient/systems/gameplayCamera';
import PedEditCamera from '@AthenaClient/utility/camera';
import { CinematicCam } from '@AthenaClient/utility/cinematic';
import { GameplayCamera } from '@AthenaClient/camera/gameplay';
import PedEditCamera from '@AthenaClient/camera/pedEdit';
import { CinematicCam } from '@AthenaClient/camera/cinematic';

export const cameraConst = {
ped: PedEditCamera,
Expand Down
4 changes: 2 additions & 2 deletions src/core/client/api/consts/screenConst.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { drawMarker } from '@AthenaClient/utility/marker';
import { drawMarker } from '@AthenaClient/screen/marker';
import { drawRectangle, drawRectangle2D, drawText2D, drawText3D } from '@AthenaClient/utility/text';
import Minimap from '@AthenaClient/utility/minimap';
import Minimap from '@AthenaClient/screen/minimap';
import Spinner from '@AthenaClient/utility/spinner';
import Shard from '@AthenaClient/utility/shard';
import { Notification } from '@AthenaClient/utility/notification';
Expand Down
Loading

0 comments on commit 31ae17b

Please sign in to comment.