Skip to content

Commit

Permalink
not sure what I changed but I changed a lot lol
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsSpyce committed Oct 3, 2018
1 parent 1a4196d commit 65fa13f
Show file tree
Hide file tree
Showing 32 changed files with 4,948 additions and 120 deletions.
3 changes: 3 additions & 0 deletions lib/async.js
@@ -1,3 +1,6 @@
// this is Spigot specific. I'd like to find a way to do it without Spigot so we can use it
// across any JVM application. So basically don't use this if not in Spigot.

var Thread = require('@java.lang.Thread');
var Runnable = require('@java.lang.Runnable');
var Bukkit = require('@org.bukkit.Bukkit');
Expand Down
42 changes: 37 additions & 5 deletions lib/child_process.js
@@ -1,11 +1,11 @@
var ProcessBuilder = require('@java.lang.ProcessBuilder');
var Redirect = ProcessBuilder.Redirect;
var async = require('async');
var EventEmitter = require('events');
var internalUtil = require('internal/util');
var path = require('path');
var async = require('async');

var workingDirectory = new java.io.File(path.normalize('./plugins/Thiq'));
var workingDirectory = './plugins/Thiq/';

function ChildProcess(processBuilder, stdio) {
EventEmitter.call(this);
Expand All @@ -16,6 +16,7 @@ function ChildProcess(processBuilder, stdio) {
this.stderr = this._process.getErrorStream();
this.stdin = this._process.getInputStream();
this.stdout = this._process.getOutputStream();
this.pid = -1;
}

ChildProcess.prototype.send = function(message, options, callback) {
Expand All @@ -30,7 +31,28 @@ ChildProcess.prototype.kill = function(signal) {
this.emit('exit');
}

function spawn(command, args, options) {
ChildProcess.prototype._waitSync = function() {
this._process.waitFor();
this.status = this._process.exitValue();
this.output = [internalUtil.getStringFromBuffer(this.stdin)];
return this;
}

ChildProcess.prototype._wait = function() {
var self = this;
async(function() {
self._process.waitFor();
self.status = self._process.exitValue();
self.output = [internalUtil.getStringFromBuffer(self.stdin)];
});
return this;
}

function pathFromString(p) {
return new java.io.File(path.normalize(p));
}

function createProcessBuilder(command, args, options) {
var pbArgs = [command];
for (var i = 0; i < args.length; ++i) {
pbArgs.push(args[i]);
Expand All @@ -56,11 +78,21 @@ function spawn(command, args, options) {
if (stderr) processBuilder.redirectError(stderr);

processBuilder.redirectErrorStream(true);
processBuilder.directory(workingDirectory);
processBuilder.directory(pathFromString(options.cwd || workingDirectory));

return new ChildProcess(processBuilder, options.stdio);
}

function spawnSync(command, args, options) {
var process = createProcessBuilder(command, args, options);
return process._waitSync();
}

function spawn(command, args, options) {
var process = createProcessBuilder(command, args, options);
return process._wait;
}

function getRedirectFromString(input) {
switch(input) {
case 'pipe': return Redirect.PIPE;
Expand All @@ -71,5 +103,5 @@ function getRedirectFromString(input) {
}

module.exports = {
spawn
spawnSync
}
5 changes: 3 additions & 2 deletions lib/internal/bootstrap/loader.js
Expand Up @@ -66,7 +66,7 @@ var Bukkit = org.bukkit.Bukkit;

var plugin = Bukkit.getPluginManager().getPlugin('Thiq');
var wrapper = [
'(function (exports, module, require, process, plugin) {',
'(function (exports, module, require, process, plugin, NativeModule) {',
'\n})'
];
global.process = configureProcess();
Expand Down Expand Up @@ -132,7 +132,8 @@ var Bukkit = org.bukkit.Bukkit;
self,
NativeModule.require,
process,
plugin
plugin,
NativeModule
];
var compiled = eval(wrapped);
compiled.apply(null, args);
Expand Down
14 changes: 14 additions & 0 deletions lib/internal/util.js
@@ -1,3 +1,6 @@
var BufferedReader = require('@java.io.BufferedReader');
var InputStreamReader = require('@java.io.InputStreamReader');

function createArrayFromString(input, length) {
var result = [];
for (var i = 0; i < length; ++i) {
Expand All @@ -6,6 +9,17 @@ function createArrayFromString(input, length) {
return result;
}

function getStringFromBuffer(buffer) {
var result = '';
var fIn = new BufferedReader(new InputStreamReader(buffer));
var line;
while ((line = fIn.readLine()) != null) {
result += line + '\r\n';
}
fIn.close();
return result;
}

module.exports = {
createArrayFromString
}
10 changes: 0 additions & 10 deletions lib/modules.js
Expand Up @@ -5,9 +5,6 @@ var jio = require('@java.io');
var BufferedReader = jio.BufferedReader;
var InputStreamReader = jio.InputStreamReader;
var FileInputStream = jio.FileInputStream;
var BufferedWriter = jio.BufferedWriter;
var OutputStreamWriter = jio.OutputStreamWriter;
var FileOutputStream = jio.FileOutputStream;
var File = require('@java.io.File');
var Path = require('@java.nio.file.Paths');
var $root = path_resolve(process.cwd(), process.config.modules_dir);
Expand Down Expand Up @@ -180,13 +177,6 @@ function resolveModule(request, caller) {
return m;
}

function runScripts(m, name) {
if (!m.config.scripts) return false;
var script = m.config.scripts[name];
if (!script) return false;

}

Module.prototype.compile = function() {
if (this.config && this.config._jvmversion) {
if (version.gte(this.config._jvmversion, '1.' + version.getJvmVersion())) {
Expand Down
1 change: 1 addition & 0 deletions lib/tpm.js
@@ -0,0 +1 @@
module.exports = require('tpm/index');
19 changes: 19 additions & 0 deletions lib/tpm/command.js
@@ -0,0 +1,19 @@
function TpmCommand(options, callback) {
this.name = options.name;
this.help = options.help;
this.usage = options.usage;
this.callback = callback;
TpmCommand.registeredCommands.push(this);
}

TpmCommand.registeredCommands = [];

TpmCommand.findCommand = function(name) {
for (var i = 0; i < TpmCommand.registeredCommands.length; ++i) {
var cmd = TpmCommand.registeredCommands[i];
if (cmd.name === name) return cmd;
}
return null;
}

module.exports = TpmCommand;
19 changes: 16 additions & 3 deletions lib/tpm/index.js
@@ -1,21 +1,34 @@
var Command = require('tpm/command');
var assert = require('assert');
var tpmUtils = require('tpm/utils');
var consts = require('constants');

exports.init = init = require('tpm/init');
exports.install = install = require('tpm/install');
exports.ls = ls = require('tpm/ls');
exports.uninstall = uninstall = require('tpm/uninstall');
exports.update = update = require('tpm/update');
exports.version = version = require('tpm/version');

var repoUrl = 'https://api.github.com/repos/thiq/node_modules/contents/';
var repoUrl = tpmUtils.repoUrl;
var registeredCommands = Command.registeredCommands;

var modulesDir = process.config.modules_dir;

registerCommand({
name: 'tpm',
description: 'Commands for Thiq Package Manager',
usage: '\xA7e<command>'
usage: '\xA7e/<command> ' + registeredCommands.map(function(c) { return c.name })
}, function (sender, label, args) {
assert(sender.isOp(), consts.defaultPermissionMessage);
if (!args || args.length == 0) {
if (!args || args.length === 0) {
return false;
}
var cmd = Command.findCommand(args[0]);
if (!cmd) return false;
if (!cmd.callback) {
sender.sendMessage('This command is currenly not implemented');
return;
}
return cmd.callback(sender, label, args);
});
9 changes: 9 additions & 0 deletions lib/tpm/init.js
@@ -0,0 +1,9 @@
var Command = require('tpm/command');

module.exports = new Command({
name: 'init',
help: 'Executes the initialization function to setup a module',
usage: '\xA7c/tpm init [module name]'
}, function(sender, label, args) {

});
15 changes: 14 additions & 1 deletion lib/tpm/install.js
Expand Up @@ -2,6 +2,11 @@ var http = require('http');
var fs = require('fs');
var path = require('path');
var semver = require('semver');
var Command = require('tpm/command');

function checkIfNativeModule(id) {
return NativeModule.getCached(id);
}

function checkIfModuleExists(id) {
return fs.exists(process.config.modules_dir + id);
Expand All @@ -16,4 +21,12 @@ function isInstalledVersionHigher(id, version) {
function getVersionToInstall(request) {
var version = request.split('@')[1];
return !version || version == 'latest' ? true : version;
}
}

module.exports = new Command({
name: 'install',
help: 'Installs a specified module',
usage: '\xA7c/tpm install [module name]'
}, function(sender, label, args) {

});
9 changes: 9 additions & 0 deletions lib/tpm/ls.js
@@ -0,0 +1,9 @@
var Command = require('tpm/command');

module.exports = new Command({
name: 'ls',
help: 'Lists all installed modules for the current server',
usage: '\xA7c/tpm ls'
}, function(sender, label, args) {

});
9 changes: 9 additions & 0 deletions lib/tpm/uninstall.js
@@ -0,0 +1,9 @@
var Command = require('tpm/command');

module.exports = new Command({
name: 'uninstall',
help: 'Uninstalls a module from this server',
usage: '\xA7c/tpm uninstall [module name]'
}, function(sender, label, args) {

});
9 changes: 9 additions & 0 deletions lib/tpm/update.js
@@ -0,0 +1,9 @@
var Command = require('tpm/command');

module.exports = new Command({
name: 'update',
help: 'Updates all modules unless a specific module is supplied',
usage: '\xA7c/tpm update <module name> <version>'
}, function(sender, label, args) {

});
5 changes: 5 additions & 0 deletions lib/tpm/utils.js
@@ -0,0 +1,5 @@
var repoUrl = 'https://api.github.com/repos/thiq/node_modules/contents/';

module.exports = {
repoUrl
}
9 changes: 9 additions & 0 deletions lib/tpm/version.js
@@ -0,0 +1,9 @@
var Command = require('tpm/command');

module.exports = new Command({
name: 'version',
help: 'Displays the version of the specified module',
usage: '\xA7c/tpm version [module name]'
}, function(sender, label, args) {

});
77 changes: 77 additions & 0 deletions node_modules/banp/ban.js

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

1 change: 1 addition & 0 deletions node_modules/banp/index.js

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

4 changes: 4 additions & 0 deletions node_modules/banp/package.json

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

0 comments on commit 65fa13f

Please sign in to comment.