From 622c0f235a899e36508d8290152cad96e9b4f253 Mon Sep 17 00:00:00 2001 From: Aidas Patas Date: Thu, 11 Mar 2021 16:28:00 +0200 Subject: [PATCH] stubs --- .eslintrc.js | 1 + cli/actions.js | 8 ++++++++ cli/index.js | 6 ++++++ cli/log.js | 1 + cli/stubs/actor.stub | 15 +++++++++++++++ cli/stubs/make.js | 18 ++++++++++++++++++ index.js | 3 +++ package-lock.json | 45 ++++++++++++++++++++++++++++++++++++++++++++ package.json | 2 ++ 9 files changed, 99 insertions(+) create mode 100644 cli/actions.js create mode 100644 cli/index.js create mode 100644 cli/log.js create mode 100644 cli/stubs/actor.stub create mode 100644 cli/stubs/make.js diff --git a/.eslintrc.js b/.eslintrc.js index 596430e..153c46b 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -15,5 +15,6 @@ module.exports = { ecmaVersion: 11, }, rules: { + 'no-console': 'off', }, }; diff --git a/cli/actions.js b/cli/actions.js new file mode 100644 index 0000000..643c937 --- /dev/null +++ b/cli/actions.js @@ -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)}`); + }, +}; diff --git a/cli/index.js b/cli/index.js new file mode 100644 index 0000000..bec60f2 --- /dev/null +++ b/cli/index.js @@ -0,0 +1,6 @@ +const actions = require('./actions'); + +module.exports = (command) => { + const [action, ...args] = command; + actions[action](...args); +}; diff --git a/cli/log.js b/cli/log.js new file mode 100644 index 0000000..cc40a46 --- /dev/null +++ b/cli/log.js @@ -0,0 +1 @@ +module.exports = () => {}; diff --git a/cli/stubs/actor.stub b/cli/stubs/actor.stub new file mode 100644 index 0000000..ec153b6 --- /dev/null +++ b/cli/stubs/actor.stub @@ -0,0 +1,15 @@ +/// /> + +@UCLASS() +class __CLASSNAME__ extends Actor +{ + + /** + * __CLASSNAME__'s Constructor + */ + constructor(GWorld: World) { + super(GWorld); + } +} + +module.exports = __CLASSNAME__; diff --git a/cli/stubs/make.js b/cli/stubs/make.js new file mode 100644 index 0000000..d3504ec --- /dev/null +++ b/cli/stubs/make.js @@ -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')}?`)); + } +}; diff --git a/index.js b/index.js index fa8786c..3b47ddb 100644 --- a/index.js +++ b/index.js @@ -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)); @@ -12,4 +13,6 @@ if (argv.file) { const compiled = compiler(code); utils.writeCode(argv.file, compiled); })(); +} else { + cli(argv._); } diff --git a/package-lock.json b/package-lock.json index 3bf15f3..fd967f9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -186,6 +186,15 @@ "integrity": "sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ==", "dev": true }, + "camel-case": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/camel-case/-/camel-case-4.1.2.tgz", + "integrity": "sha512-gxGWBrTT1JuMx6R+o5PTXMmUnhnVzLQ9SNutD4YqKtI6ap897t3tKECYla6gCWEkplXnlNybEkZg9GEGxKFCgw==", + "requires": { + "pascal-case": "^3.1.2", + "tslib": "^2.0.3" + } + }, "chalk": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.0.tgz", @@ -262,6 +271,11 @@ "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=", "dev": true }, + "colors": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/colors/-/colors-1.4.0.tgz", + "integrity": "sha512-a+UqTh4kgZg/SlGvfbzDHpgRu7AAQOmmqRHJnxhRZICKFUT91brVhNNt58CMWU9PsBbv3PDCZUHbVxuDiH2mtA==" + }, "concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", @@ -1036,6 +1050,14 @@ "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==", "dev": true }, + "lower-case": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/lower-case/-/lower-case-2.0.2.tgz", + "integrity": "sha512-7fm3l3NAF9WfN6W3JOmf5drwpVqX78JtoGJ3A6W0a6ZnldM41w2fV5D490psKFTpMds8TJse/eHLFFsNHHjHgg==", + "requires": { + "tslib": "^2.0.3" + } + }, "lru-cache": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", @@ -1072,6 +1094,15 @@ "integrity": "sha1-Sr6/7tdUHywnrPspvbvRXI1bpPc=", "dev": true }, + "no-case": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/no-case/-/no-case-3.0.4.tgz", + "integrity": "sha512-fgAN3jGAh+RoxUGZHTSOLJIqUc2wmoBwGR4tbpNAKmmovFoWq0OdRkb0VkldReO2a2iBT/OEulG9XSUc10r3zg==", + "requires": { + "lower-case": "^2.0.2", + "tslib": "^2.0.3" + } + }, "normalize-package-data": { "version": "2.5.0", "resolved": "https://registry.npmjs.org/normalize-package-data/-/normalize-package-data-2.5.0.tgz", @@ -1205,6 +1236,15 @@ "error-ex": "^1.2.0" } }, + "pascal-case": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/pascal-case/-/pascal-case-3.1.2.tgz", + "integrity": "sha512-uWlGT3YSnK9x3BQJaOdcZwrnV6hPpd8jFH1/ucpiLRPh/2zCVJKS19E4GvYHvaCcACn3foXZ0cLB9Wrx1KGe5g==", + "requires": { + "no-case": "^3.0.4", + "tslib": "^2.0.3" + } + }, "path-exists": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-3.0.0.tgz", @@ -1550,6 +1590,11 @@ "strip-bom": "^3.0.0" } }, + "tslib": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.1.0.tgz", + "integrity": "sha512-hcVC3wYEziELGGmEEXue7D75zbwIIVUMWAVbHItGPx0ziyXxrOMQx4rQEVEV45Ut/1IotuEvwqPopzIOkDMf0A==" + }, "type-check": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz", diff --git a/package.json b/package.json index 34d9f9c..d158b28 100644 --- a/package.json +++ b/package.json @@ -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",