Skip to content

Commit

Permalink
stubs
Browse files Browse the repository at this point in the history
  • Loading branch information
AidasPa committed Mar 11, 2021
1 parent acc20c6 commit 622c0f2
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 0 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ module.exports = {
ecmaVersion: 11,
},
rules: {
'no-console': 'off',
},
};
8 changes: 8 additions & 0 deletions cli/actions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const camelCase = require('camel-case');
const make = require('./stubs/make');

module.exports = {
'create:actor': async (className) => {
make('actor', [['CLASSNAME', className]], `actors/${camelCase.camelCase(className)}`);
},
};
6 changes: 6 additions & 0 deletions cli/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const actions = require('./actions');

module.exports = (command) => {
const [action, ...args] = command;
actions[action](...args);
};
1 change: 1 addition & 0 deletions cli/log.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = () => {};
15 changes: 15 additions & 0 deletions cli/stubs/actor.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/// <reference path="typings/ue.d.ts">/>

@UCLASS()
class __CLASSNAME__ extends Actor
{

/**
* __CLASSNAME__'s Constructor
*/
constructor(GWorld: World) {
super(GWorld);
}
}

module.exports = __CLASSNAME__;
18 changes: 18 additions & 0 deletions cli/stubs/make.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const fs = require('fs').promises;
const colors = require('colors');

module.exports = async (stubName, argArray, filePath) => {
const rawStub = await fs.readFile(`${__dirname}/${stubName}.stub`, 'utf-8');

let computedStub = rawStub;
argArray.forEach(([key, value]) => {
const regexp = new RegExp(`__${key}__`, 'g');
computedStub = computedStub.replace(regexp, value);
});

try {
await fs.writeFile(`./${filePath}.ts`, computedStub, 'utf-8');
} catch (error) {
console.log(colors.red(`Did you run ${colors.bold.white('uts init')}?`));
}
};
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const yargs = require('yargs/yargs');
const { hideBin } = require('yargs/helpers');
const utils = require('./utils');
const compiler = require('./compiler');
const cli = require('./cli');

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

Expand All @@ -12,4 +13,6 @@ if (argv.file) {
const compiled = compiler(code);
utils.writeCode(argv.file, compiled);
})();
} else {
cli(argv._);
}
45 changes: 45 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
"eslint-plugin-import": "^2.22.1"
},
"dependencies": {
"camel-case": "^4.1.2",
"colors": "^1.4.0",
"randomstring": "^1.1.5",
"typescript": "^4.2.3",
"typescript-compiler": "^1.4.1-2",
Expand Down

0 comments on commit 622c0f2

Please sign in to comment.