Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
AidasPa committed Mar 10, 2021
0 parents commit e8eb22a
Show file tree
Hide file tree
Showing 10 changed files with 1,939 additions and 0 deletions.
19 changes: 19 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module.exports = {
env: {
commonjs: true,
es6: true,
node: true,
},
extends: [
'airbnb-base',
],
globals: {
Atomics: 'readonly',
SharedArrayBuffer: 'readonly',
},
parserOptions: {
ecmaVersion: 11,
},
rules: {
},
};
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
Empty file added babel/index.js
Empty file.
34 changes: 34 additions & 0 deletions examples/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// @ts-nocheck
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var MyActor = /** @class */ (function (_super) {
__extends(MyActor, _super);
function MyActor() {
return _super !== null && _super.apply(this, arguments) || this;
}
MyActor.prototype.properties = function () {
this.hello /*Replicated+EditAnywhere+string*/;
};
MyActor.prototype.ctor = function () {
this.hello = "Hello? Random: " + Math.round(Math.random() * 100);
};
MyActor.prototype.receiveBeginPlay = function () {
_super.prototype.receiveBeginPlay.call(this);
console.log(this.hello);
};
return MyActor;
}(Actor));
require('bootstrap')('index');
16 changes: 16 additions & 0 deletions examples/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// @ts-nocheck

@UCLASS()
class MyActor extends Actor {
@UPROPERTY(Replicated, EditAnywhere)
hello: string;

constructor() {
this.hello = `Hello? Random: ${Math.round(Math.random() * 100)}`;
}

receiveBeginPlay() {
super.receiveBeginPlay();
console.log(this.hello);
}
}
66 changes: 66 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/* eslint-disable no-console */
const yargs = require('yargs/yargs');
const { hideBin } = require('yargs/helpers');
const ts = require('typescript');

const utils = require('./utils');
const parser = require('./parser');

const { argv } = yargs(hideBin(process.argv));

const processCode = (code) => {
const lines = code.split('\n');

const propertyBag = [];
let constructorLine = null;

// eslint-disable-next-line array-callback-return
const transformedCodeArray = lines.map((line, i) => {
if (parser.isConstructor(line)) {
constructorLine = i;
return parser.replaceConstructorName(line, lines, i);
}
if (parser.isDecorator(line)) {
const [decorator, decoratorArguments] = parser.parseDecorator(line);
if (decorator === 'UCLASS') {
return '';
}
if (decorator === 'UPROPERTY') {
// basically now we need to check the next line to see what are we trying to decorate
// and get the type accordingly
const nextLine = lines[i + 1];
const [propertyName, propertyType] = parser.parseTypescriptClassField(
nextLine,
);
propertyBag.push({
type: propertyType,
name: propertyName,
line: i + 1,
decoratorArguments,
});
return '';
}
}

return line;
});

const processedCode = parser.injectBootstrap(parser.injectProperties(
transformedCodeArray,
propertyBag,
constructorLine,
), argv.file);

const compiledJavascript = ts.transpileModule(processedCode.join('\n'), {
compilerOptions: { removeComments: false },
}).outputText;

utils.writeCode(argv.file, compiledJavascript);
};

if (argv.file) {
(async () => {
const code = await utils.readCode(argv.file);
processCode(code);
})();
}
Loading

0 comments on commit e8eb22a

Please sign in to comment.