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

Commit

Permalink
Added Path Resolver
Browse files Browse the repository at this point in the history
  • Loading branch information
Stuyk committed Oct 9, 2022
1 parent 25ffa60 commit c91ebb1
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 19 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ streamers/marker.ts -> Converted to const
streamers/item.ts -> Converted to const
streamers/textlabel.ts -> Converted to const
streamers/worldNotifications.ts -> Converted to const
Added Custom Path Resolver
@AthenaServer -> src/core/server
@AthenaClient -> src/core/client
@AthenaShared -> src/core/shared
@AthenaPlugins -> src/core/plugins
```

## 3.9.0
Expand Down
30 changes: 30 additions & 0 deletions scripts/compiler/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,41 @@ function getFilesToCopy(enabledPlugins) {
});
}

/**
* Resolves paths in files since SWC can't handle Athena's structure.
* @param {string} file
* @param {string} rawCode
* @return {string}
*/
function resolvePaths(file, rawCode) {
const cleanedPath = file.replace(sanitizePath(process.cwd()), '');
const pathSplit = cleanedPath.split('/');
pathSplit.pop(); // Remove current file
let depth = 0;

while (pathSplit[pathSplit.length - 1] !== 'core') {
pathSplit.pop();
depth += 1;
}

rawCode = rawCode.replaceAll(`@AthenaServer`, `../`.repeat(depth) + `server`);
rawCode = rawCode.replaceAll(`@AthenaClient`, `../`.repeat(depth) + `client`);
rawCode = rawCode.replaceAll(`@AthenaShared`, `../`.repeat(depth) + `shared`);
rawCode = rawCode.replaceAll(`@AthenaPlugins`, `../`.repeat(depth) + `plugins`);
return rawCode;
}

async function transpileFile(file) {
const targetPath = file.replace('src/', 'resources/').replace('.ts', '.js');

return new Promise(async (resolve) => {
const result = await swc.transformFile(file, SWC_CONFIG);

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

fs.outputFileSync(targetPath, result.code);
resolve();
});
Expand Down
2 changes: 1 addition & 1 deletion src/core/plugins/athena-debug/server/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as alt from 'alt-server';
import { PluginSystem } from '../../../server/systems/plugins';
import { PluginSystem } from '@AthenaServer/systems/plugins';
import { DebugKeys } from './system/keys';
import { RestService } from './system/rest';

Expand Down
17 changes: 0 additions & 17 deletions src/tsconfig.json

This file was deleted.

15 changes: 14 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
{
"compilerOptions": {
"baseUrl": "src",
"paths": {
"@AthenaServer/*": ["core/server/*"],
"@AthenaClient/*": ["core/client/*"],
"@AthenaShared/*": ["core/shared/*"],
"@AthenaPlugins/*": ["core/plugins/*"]
},
"typeRoots": ["./node_modules/@types", "./node_modules/@altv"],
"removeComments": true,
"noUnusedLocals": false,
Expand All @@ -10,8 +17,14 @@
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"moduleResolution": "node",
"jsx": "preserve"
"allowSyntheticDefaultImports": true,
"composite": false,
"forceConsistentCasingInFileNames": true,
"strict": false,
"module": "ES2022",
"target": "ES2022"
},
"include": ["src/**/*.ts", "src-webviews/**/*.ts"],
"exclude": [
"resources",
"scripts",
Expand Down

0 comments on commit c91ebb1

Please sign in to comment.