fenrir-runtime 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. package/App/App.axaml +8 -0
  2. package/App/App.axaml.cs +23 -0
  3. package/App/FenrirLinux.csproj +27 -0
  4. package/App/LICENSE +674 -0
  5. package/App/MainWindow.axaml +10 -0
  6. package/App/MainWindow.axaml.cs +16 -0
  7. package/App/Program.cs +19 -0
  8. package/App/README.md +24 -0
  9. package/App/Views/InstallationView.axaml +48 -0
  10. package/App/Views/InstallationView.axaml.cs +204 -0
  11. package/App/Views/PasswordView.axaml +34 -0
  12. package/App/Views/PasswordView.axaml.cs +62 -0
  13. package/App/Views/WelcomeView.axaml +63 -0
  14. package/App/Views/WelcomeView.axaml.cs +22 -0
  15. package/App/app.manifest +18 -0
  16. package/App/images/screenshot1.png +0 -0
  17. package/App/images/screenshot2.png +0 -0
  18. package/App/obj/Debug/net9.0/Avalonia/Resources.Inputs.cache +1 -0
  19. package/App/obj/Debug/net9.0/Avalonia/original.dll +0 -0
  20. package/App/obj/Debug/net9.0/Avalonia/original.pdb +0 -0
  21. package/App/obj/Debug/net9.0/Avalonia/original.ref.dll +0 -0
  22. package/App/obj/Debug/net9.0/Avalonia/references +202 -0
  23. package/App/obj/Debug/net9.0/Avalonia/resources +0 -0
  24. package/App/obj/Debug/net9.0/FenrirLi.7B98506C.Up2Date +0 -0
  25. package/App/obj/Debug/net9.0/FenrirLinux.AssemblyInfo.cs +22 -0
  26. package/App/obj/Debug/net9.0/FenrirLinux.AssemblyInfoInputs.cache +1 -0
  27. package/App/obj/Debug/net9.0/FenrirLinux.GeneratedMSBuildEditorConfig.editorconfig +35 -0
  28. package/App/obj/Debug/net9.0/FenrirLinux.assets.cache +0 -0
  29. package/App/obj/Debug/net9.0/FenrirLinux.csproj.AssemblyReference.cache +0 -0
  30. package/App/obj/Debug/net9.0/FenrirLinux.csproj.CoreCompileInputs.cache +1 -0
  31. package/App/obj/Debug/net9.0/FenrirLinux.csproj.FileListAbsolute.txt +135 -0
  32. package/App/obj/Debug/net9.0/FenrirLinux.dll +0 -0
  33. package/App/obj/Debug/net9.0/FenrirLinux.genruntimeconfig.cache +1 -0
  34. package/App/obj/Debug/net9.0/FenrirLinux.pdb +0 -0
  35. package/App/obj/Debug/net9.0/apphost +0 -0
  36. package/App/obj/Debug/net9.0/ref/FenrirLinux.dll +0 -0
  37. package/App/obj/Debug/net9.0/refint/FenrirLinux.dll +0 -0
  38. package/App/obj/FenrirLinux.csproj.nuget.dgspec.json +115 -0
  39. package/App/obj/FenrirLinux.csproj.nuget.g.props +26 -0
  40. package/App/obj/FenrirLinux.csproj.nuget.g.targets +9 -0
  41. package/App/obj/Release/net9.0/linux-x64/Avalonia/Resources.Inputs.cache +1 -0
  42. package/App/obj/Release/net9.0/linux-x64/Avalonia/original.dll +0 -0
  43. package/App/obj/Release/net9.0/linux-x64/Avalonia/original.pdb +0 -0
  44. package/App/obj/Release/net9.0/linux-x64/Avalonia/original.ref.dll +0 -0
  45. package/App/obj/Release/net9.0/linux-x64/Avalonia/references +194 -0
  46. package/App/obj/Release/net9.0/linux-x64/Avalonia/resources +0 -0
  47. package/App/obj/Release/net9.0/linux-x64/FenrirLi.7B98506C.Up2Date +0 -0
  48. package/App/obj/Release/net9.0/linux-x64/FenrirLinux.AssemblyInfo.cs +22 -0
  49. package/App/obj/Release/net9.0/linux-x64/FenrirLinux.AssemblyInfoInputs.cache +1 -0
  50. package/App/obj/Release/net9.0/linux-x64/FenrirLinux.GeneratedMSBuildEditorConfig.editorconfig +39 -0
  51. package/App/obj/Release/net9.0/linux-x64/FenrirLinux.assets.cache +0 -0
  52. package/App/obj/Release/net9.0/linux-x64/FenrirLinux.csproj.AssemblyReference.cache +0 -0
  53. package/App/obj/Release/net9.0/linux-x64/FenrirLinux.csproj.CoreCompileInputs.cache +1 -0
  54. package/App/obj/Release/net9.0/linux-x64/FenrirLinux.csproj.FileListAbsolute.txt +238 -0
  55. package/App/obj/Release/net9.0/linux-x64/FenrirLinux.deps.json +1317 -0
  56. package/App/obj/Release/net9.0/linux-x64/FenrirLinux.dll +0 -0
  57. package/App/obj/Release/net9.0/linux-x64/FenrirLinux.genbundle.cache +1 -0
  58. package/App/obj/Release/net9.0/linux-x64/FenrirLinux.genpublishdeps.cache +1 -0
  59. package/App/obj/Release/net9.0/linux-x64/FenrirLinux.genruntimeconfig.cache +1 -0
  60. package/App/obj/Release/net9.0/linux-x64/FenrirLinux.pdb +0 -0
  61. package/App/obj/Release/net9.0/linux-x64/PublishOutputs.fac9e24064.txt +4 -0
  62. package/App/obj/Release/net9.0/linux-x64/apphost +0 -0
  63. package/App/obj/Release/net9.0/linux-x64/ref/FenrirLinux.dll +0 -0
  64. package/App/obj/Release/net9.0/linux-x64/refint/FenrirLinux.dll +0 -0
  65. package/App/obj/Release/net9.0/linux-x64/singlefilehost +0 -0
  66. package/App/obj/project.assets.json +2463 -0
  67. package/App/obj/project.nuget.cache +47 -0
  68. package/LICENSE +674 -0
  69. package/Makefile +16 -0
  70. package/README.md +89 -0
  71. package/dist/archiveSystem.js +219 -0
  72. package/dist/cli.js +188 -0
  73. package/dist/packageManager.js +98 -0
  74. package/dist/parser.js +24 -0
  75. package/dist/runtime.js +99 -0
  76. package/dist/transformer.js +120 -0
  77. package/example/fenrir+aperium/aperium.json +17 -0
  78. package/example/fenrir+aperium/aperium_modules/hello-world/index.js +4 -0
  79. package/example/fenrir+aperium/aperium_modules/hello-world/module.json +6 -0
  80. package/example/fenrir+aperium/app.fnr +19 -0
  81. package/example/fenrir+aperium/package-lock.json +890 -0
  82. package/example/fenrir+aperium/package.json +17 -0
  83. package/example/fenrir.json +10 -0
  84. package/example/main.fnr +18 -0
  85. package/example/package-lock.json +867 -0
  86. package/example/package.json +17 -0
  87. package/package.json +32 -0
  88. package/src/archiveSystem.ts +264 -0
  89. package/src/cli.ts +216 -0
  90. package/src/packageManager.ts +119 -0
  91. package/src/parser.ts +36 -0
  92. package/src/runtime.ts +111 -0
  93. package/src/transformer.ts +147 -0
  94. package/tsconfig.json +15 -0
@@ -0,0 +1,99 @@
1
+ import { execSync } from 'child_process';
2
+ import fs from 'fs-extra';
3
+ import path from 'path';
4
+ export class FenrirRuntime {
5
+ static instance;
6
+ packageCache = new Map();
7
+ runtimeCache = new Map();
8
+ static getInstance() {
9
+ if (!FenrirRuntime.instance) {
10
+ FenrirRuntime.instance = new FenrirRuntime();
11
+ }
12
+ return FenrirRuntime.instance;
13
+ }
14
+ log = (...args) => {
15
+ process.stdout.write(args.map(arg => typeof arg === 'object' ? JSON.stringify(arg, null, 2) : String(arg)).join(' ') + '\n');
16
+ };
17
+ readFile = (filePath) => {
18
+ try {
19
+ return fs.readFileSync(path.resolve(filePath), 'utf8');
20
+ }
21
+ catch (error) {
22
+ throw new Error(`File cannot be read: ${filePath}`);
23
+ }
24
+ };
25
+ writeFile = (filePath, content) => {
26
+ try {
27
+ fs.writeFileSync(path.resolve(filePath), content, 'utf8');
28
+ }
29
+ catch (error) {
30
+ throw new Error(`File could not be written: ${filePath}`);
31
+ }
32
+ };
33
+ fetch = async (url, options) => {
34
+ const https = require('https');
35
+ const http = require('http');
36
+ return new Promise((resolve, reject) => {
37
+ const client = url.startsWith('https') ? https : http;
38
+ const req = client.get(url, (res) => {
39
+ let data = '';
40
+ res.on('data', (chunk) => data += chunk);
41
+ res.on('end', () => {
42
+ try {
43
+ resolve(JSON.parse(data));
44
+ }
45
+ catch {
46
+ resolve(data);
47
+ }
48
+ });
49
+ });
50
+ req.on('error', reject);
51
+ });
52
+ };
53
+ require = (packageName) => {
54
+ if (this.packageCache.has(packageName)) {
55
+ return this.packageCache.get(packageName);
56
+ }
57
+ try {
58
+ const pkg = require(packageName);
59
+ this.packageCache.set(packageName, pkg);
60
+ return pkg;
61
+ }
62
+ catch (error) {
63
+ throw new Error(`Package not found: ${packageName}. Install it with the command 'fenrir install ${packageName}'.`);
64
+ }
65
+ };
66
+ exec = (command) => {
67
+ try {
68
+ return execSync(command, { encoding: 'utf8', stdio: 'inherit' });
69
+ }
70
+ catch (error) {
71
+ throw new Error(`Command could not be executed: ${command}`);
72
+ }
73
+ };
74
+ executeCommand = (command) => {
75
+ try {
76
+ return execSync(command, { encoding: 'utf8', stdio: 'inherit' });
77
+ }
78
+ catch (error) {
79
+ const errorMessage = error.message || 'Bilinmeyen bir hata oluştu.';
80
+ throw new Error(`Fenrir komutu çalıştırılamadı: ${command}. Hata: ${errorMessage}`);
81
+ }
82
+ };
83
+ now = () => Date.now();
84
+ time = () => new Date().toISOString();
85
+ sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));
86
+ }
87
+ const fenrirRuntime = FenrirRuntime.getInstance();
88
+ Object.assign(globalThis, {
89
+ fenrir: fenrirRuntime.executeCommand,
90
+ log: fenrirRuntime.log,
91
+ readFile: fenrirRuntime.readFile,
92
+ writeFile: fenrirRuntime.writeFile,
93
+ fetch: fenrirRuntime.fetch,
94
+ exec: fenrirRuntime.exec,
95
+ now: fenrirRuntime.now,
96
+ sleep: fenrirRuntime.sleep
97
+ });
98
+ export { fenrirRuntime as fenrir };
99
+ export default FenrirRuntime;
@@ -0,0 +1,120 @@
1
+ import path from 'path';
2
+ export const transformFenrirCode = async (fenrirCode, filePath, aperiumImports) => {
3
+ if (fenrirCode.includes('import ')) {
4
+ throw new Error("Fenrir Error: The keyword 'import' cannot be used. Use 'declare' to identify modules.");
5
+ }
6
+ const lines = fenrirCode.split('\n');
7
+ let jsOutput = '';
8
+ let i = 0;
9
+ while (i < lines.length) {
10
+ const line = lines[i];
11
+ const trimmedLine = line.trim();
12
+ if (!trimmedLine) {
13
+ jsOutput += line + '\n';
14
+ i++;
15
+ continue;
16
+ }
17
+ let transformedLine = trimmedLine;
18
+ let isMultiLineStatement = false;
19
+ if (trimmedLine.startsWith('fn ')) {
20
+ transformedLine = transformedLine.replace(/^fn\s+/, 'function ');
21
+ }
22
+ else if (trimmedLine.startsWith('declare ')) {
23
+ const importMatch = trimmedLine.match(/declare\s+(.*?)\s+from\s+['"](.*?)['"]/);
24
+ if (importMatch) {
25
+ const importName = importMatch[1];
26
+ const modulePath = importMatch[2];
27
+ if (isNpmModule(modulePath)) {
28
+ transformedLine = `import ${importName} from "${modulePath}";`;
29
+ }
30
+ else {
31
+ const resolvedPath = path.resolve(path.dirname(filePath), modulePath);
32
+ transformedLine = `import ${importName} from "file://${resolvedPath}";`;
33
+ }
34
+ }
35
+ }
36
+ transformedLine = transformedLine.replace(/\blog\(/g, 'console.log(');
37
+ if (transformedLine.includes('(') && !transformedLine.includes(')')) {
38
+ isMultiLineStatement = true;
39
+ let fullStatement = transformedLine;
40
+ let j = i + 1;
41
+ let openParens = (transformedLine.match(/\(/g) || []).length;
42
+ let closeParens = (transformedLine.match(/\)/g) || []).length;
43
+ while (j < lines.length && openParens > closeParens) {
44
+ const nextLine = lines[j];
45
+ fullStatement += '\n' + nextLine;
46
+ openParens += (nextLine.match(/\(/g) || []).length;
47
+ closeParens += (nextLine.match(/\)/g) || []).length;
48
+ j++;
49
+ }
50
+ const processedStatement = fullStatement.replace(/\blog\(/g, 'console.log(');
51
+ if (shouldAddSemicolon(processedStatement.trim())) {
52
+ jsOutput += processedStatement + ';\n';
53
+ }
54
+ else {
55
+ jsOutput += processedStatement + '\n';
56
+ }
57
+ i = j;
58
+ continue;
59
+ }
60
+ if (shouldAddSemicolon(transformedLine)) {
61
+ transformedLine += ';';
62
+ }
63
+ jsOutput += transformedLine + '\n';
64
+ i++;
65
+ }
66
+ return jsOutput;
67
+ };
68
+ function isNpmModule(modulePath) {
69
+ if (modulePath.startsWith('./') || modulePath.startsWith('../')) {
70
+ return false;
71
+ }
72
+ if (modulePath.startsWith('/')) {
73
+ return false;
74
+ }
75
+ if (modulePath.match(/\.(js|mjs|ts|json)$/)) {
76
+ return false;
77
+ }
78
+ return true;
79
+ }
80
+ function shouldAddSemicolon(line) {
81
+ const trimmed = line.trim();
82
+ if (trimmed.endsWith(';'))
83
+ return false;
84
+ if (trimmed.endsWith('{') ||
85
+ trimmed.endsWith('}') ||
86
+ (trimmed.endsWith(')') && !hasAssignmentOrCall(trimmed))) {
87
+ return false;
88
+ }
89
+ if (trimmed.startsWith('function ') ||
90
+ trimmed.startsWith('if ') ||
91
+ trimmed.startsWith('else') ||
92
+ trimmed.startsWith('for ') ||
93
+ trimmed.startsWith('while ') ||
94
+ trimmed.startsWith('switch ') ||
95
+ trimmed.startsWith('try') ||
96
+ trimmed.startsWith('catch') ||
97
+ trimmed.startsWith('finally') ||
98
+ trimmed.startsWith('import ') ||
99
+ trimmed.startsWith('export ') ||
100
+ trimmed.match(/^}\s*else/)) {
101
+ return false;
102
+ }
103
+ return (trimmed.includes('=') ||
104
+ trimmed.includes('console.log') ||
105
+ trimmed.includes('return ') ||
106
+ trimmed.startsWith('const ') ||
107
+ trimmed.startsWith('let ') ||
108
+ trimmed.startsWith('var ') ||
109
+ /^[a-zA-Z_$][a-zA-Z0-9_$.]*\s*\(/.test(trimmed) ||
110
+ Boolean(trimmed.match(/^\w+\s*\+\+/)) ||
111
+ Boolean(trimmed.match(/^\w+\s*--/)) ||
112
+ Boolean(trimmed.match(/^\w+\s*[+\-*/]=/)));
113
+ }
114
+ function hasAssignmentOrCall(line) {
115
+ const trimmedLine = line.trim();
116
+ return trimmedLine.includes('=') ||
117
+ trimmedLine.includes('console.log') ||
118
+ trimmedLine.includes('return ') ||
119
+ /^[a-zA-Z_$][a-zA-Z0-9_$.]*\s*\(/.test(trimmedLine);
120
+ }
@@ -0,0 +1,17 @@
1
+ {
2
+ "project": {
3
+ "name": "fenrir-test",
4
+ "version": "1.0.0",
5
+ "description": "",
6
+ "author": "",
7
+ "license": "GPL-3.0-or-later"
8
+ },
9
+ "main": "app.fnr",
10
+ "dependencies": {
11
+ "hello-world": "1.0.0"
12
+ },
13
+ "imports": {},
14
+ "scripts": {
15
+ "start": "fenrir app.fnr"
16
+ }
17
+ }
@@ -0,0 +1,4 @@
1
+ const greet = (name) => {
2
+ return `Hello, ${name}! Welcome to Aperium and Fenrir.`;
3
+ };
4
+ export default greet;
@@ -0,0 +1,6 @@
1
+ {
2
+ "name": "hello-world",
3
+ "version": "1.0.0",
4
+ "main": "index.js",
5
+ "description": "A simple 'hello world' module for Aperium projects."
6
+ }
@@ -0,0 +1,19 @@
1
+ declare express from 'express'
2
+ declare hw from 'hello-world'
3
+
4
+ const app = express()
5
+ const port = 3000
6
+
7
+ fn handle_home_request(req, res) {
8
+ res.send(hw('World'))
9
+ }
10
+
11
+ app.get('/', handle_home_request)
12
+
13
+ fn start_server() {
14
+ app.listen(port, () => {
15
+ log(`Server running at http://localhost:${port}`)
16
+ })
17
+ }
18
+
19
+ start_server()