First commit with my initial local environment, lot of manual items at the...

First commit with my initial local environment, lot of manual items at the moment but it will be changed over to something better
parents
# EditorConfig is awesome: http://EditorConfig.org
# top-most EditorConfig file
root = true
# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true
# 4 space indentation
[**.*]
indent_style = space
indent_size = 4
# Created by https://www.gitignore.io/api/node
### Node ###
# Logs
logs
*.log
npm-debug.log*
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
# nyc test coverage
.nyc_output
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# node-waf configuration
.lock-wscript
# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules
jspm_packages
# Optional npm cache directory
.npm
# Optional REPL history
.node_repl_history
### Typings ###
## Ignore downloaded typings
/typings
## Ignore distribution folder
dist/
MIT License
Copyright (c) 2017 graywolf336
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
# temporary-rocketlets-dev-environment
Please ignore this repository and package, it simply is a temporary package to aid in the development of Rocketlets for Rocket.Chat :heart:
"use strict";
exports.__esModule = true;
var base_1 = require("temporary-rocketlets-ts-definition/base");
var ts = require("typescript");
var vm = require("vm");
var RocketletCompiler = (function () {
function RocketletCompiler() {
this.compilerOptions = {
lib: ['ES6'],
target: ts.ScriptTarget.ES2016,
module: ts.ModuleKind.CommonJS,
moduleResolution: ts.ModuleResolutionKind.NodeJs,
declaration: false,
noImplicitAny: false,
removeComments: true,
noImplicitReturns: true,
experimentalDecorators: true,
emitDecoratorMetadata: true
};
}
RocketletCompiler.prototype.linttTs = function (source) {
throw new Error('Not implemented yet.');
};
RocketletCompiler.prototype.toJs = function (source) {
var result = ts.transpileModule(source, { compilerOptions: this.compilerOptions });
// TODO: try to determine why I'm not getting any `result.diagnostics`
return result.outputText;
};
RocketletCompiler.prototype.toSandBox = function (js) {
var script = new vm.Script(js);
var context = vm.createContext({ require: require, exports: exports });
var result = script.runInContext(context);
if (typeof result !== 'function') {
throw new Error('The provided script is not valid.');
}
var rl = new result();
if (!(rl instanceof base_1.BaseRocketlet)) {
throw new Error('The script must extend BaseRocketlet.');
}
if (typeof rl.getName !== 'function') {
throw new Error('The Rocketlet doesn\'t have a `getName` function, this is required.');
}
if (typeof rl.getVersion !== 'function') {
throw new Error('The Rocketlet doesn\'t have a `getVersion` function, this is required.');
}
if (typeof rl.getID !== 'function') {
throw new Error('The Rocketlet doesn\'t have a `getID` function, this is required.');
}
if (typeof rl.getDescription !== 'function') {
throw new Error('The Rocketlet doesn\'t have a `getDescription` function, this is required.');
}
console.log(rl.getDescription.prototype.constructor);
console.log(rl.pre_messageSent.prototype.constructor);
return rl;
};
return RocketletCompiler;
}());
exports.RocketletCompiler = RocketletCompiler;
import { BaseRocketlet } from 'temporary-rocketlets-ts-definition/base';
import * as ts from 'typescript';
import * as vm from 'vm';
export class RocketletCompiler {
private readonly compilerOptions: ts.CompilerOptions;
constructor() {
this.compilerOptions = {
lib: ['ES6'],
target: ts.ScriptTarget.ES2016,
module: ts.ModuleKind.CommonJS,
moduleResolution: ts.ModuleResolutionKind.NodeJs,
declaration: false,
noImplicitAny: false,
removeComments: true,
noImplicitReturns: true,
experimentalDecorators: true,
emitDecoratorMetadata: true,
};
}
public linttTs(source: string): void {
throw new Error('Not implemented yet.');
}
public toJs(source: string): string {
const result = ts.transpileModule(source, { compilerOptions: this.compilerOptions });
// TODO: try to determine why I'm not getting any `result.diagnostics`
return result.outputText;
}
public toSandBox(js: string): BaseRocketlet {
const script = new vm.Script(js);
const context = vm.createContext({ require, exports });
const result = script.runInContext(context);
if (typeof result !== 'function') {
throw new Error('The provided script is not valid.');
}
const rl = new result();
if (!(rl instanceof BaseRocketlet)) {
throw new Error('The script must extend BaseRocketlet.');
}
if (typeof rl.getName !== 'function') {
throw new Error ('The Rocketlet doesn\'t have a `getName` function, this is required.');
}
if (typeof rl.getVersion !== 'function') {
throw new Error ('The Rocketlet doesn\'t have a `getVersion` function, this is required.');
}
if (typeof rl.getID !== 'function') {
throw new Error ('The Rocketlet doesn\'t have a `getID` function, this is required.');
}
if (typeof rl.getDescription !== 'function') {
throw new Error ('The Rocketlet doesn\'t have a `getDescription` function, this is required.');
}
console.log(rl.getDescription.prototype.constructor);
console.log(rl.pre_messageSent.prototype.constructor);
return rl as BaseRocketlet;
}
}
import { IMessage, IRoom, ISetting, IUser } from 'temporary-rocketlets-ts-definition';
import { BaseRocketlet } from 'temporary-rocketlets-ts-definition/base';
export class PreMessageSentRocketlet extends BaseRocketlet {
constructor() {
super('Pre Message Sent', 1, '0.0.1', 'Adds this Rocketlet\'s name to the end of each message.');
}
public pre_messageSent(room: IRoom, user: IUser, message: IMessage): IMessage {
message.text = message.text + ' ' + this.getName();
return message;
}
}
const fs = require('fs');
const express = require('express');
const bodyParser = require('body-parser');
const m = require('./manager.js');
const compiler = require('./compiler.js');
const app = express();
const manager = new m.RocketletManager('./examples');
manager.load().then((items) => console.log(items)).catch((err) => console.warn(err));
app.use(bodyParser.json());
app.get('/', function (req, res) {
res.json({
'GET: /compile': {},
'POST: /event': {
msg: 'string'
}
});
});
app.get('/compile', (req, res) => {
const src = fs.readFileSync('./examples/preMessageSent.ts', 'utf8');
const result = compiler.compiler(src);
const Rocketlet = eval(result);
new Rocketlet();
res.json({ src, result });
});
app.post('/event', (req, res) => {
console.log(req.body, req.body.msg);
res.json({ success: true });
});
app.listen(3003, function _appListen() {
console.log('Example app listening on port 3003!');
console.log('http://localhost:3003/');
});
"use strict";
exports.__esModule = true;
export interface IGetRocketletsFilter {
ids?: Array<number>;
name?: string | RegExp;
count?: number;
enabled?: boolean;
disabled?: boolean;
}
"use strict";
exports.__esModule = true;
var compiler_1 = require("./compiler");
var fs = require("fs");
var path = require("path");
var RocketletManager = (function () {
function RocketletManager(folder) {
this.folder = folder;
this.activeRocketlets = new Map();
this.inactiveRocketlets = new Map();
this.compiler = new compiler_1.RocketletCompiler();
console.log('Constructed the RocketletLoader and the src folder is:', this.folder);
}
RocketletManager.prototype.getCompiler = function () {
return this.compiler;
};
RocketletManager.prototype.load = function () {
var _this = this;
return new Promise(function (resolve, reject) {
if (_this.folder === '') {
return reject(new Error('Invalid source folder for loading Rocketlets from.'));
}
try {
fs.readdirSync(_this.folder).forEach(function (file) {
var filePath = path.join(_this.folder, file);
// Verify it's a typescript file
if (!file.endsWith('.ts')) {
return;
}
// Verify it is actually a file
var stat = fs.statSync(filePath);
if (stat.isDirectory()) {
return;
}
var src = _this.getCompiler().toJs(fs.readFileSync(filePath, 'utf8'));
var rocketlet = _this.getCompiler().toSandBox(src);
console.log("Successfully loaded " + rocketlet.getName() + "!");
});
}
catch (e) {
return reject(e);
}
// TODO: Combine the two maps values
return new Array();
});
};
RocketletManager.prototype.get = function (filter) {
throw new Error('Not implemented yet.');
};
RocketletManager.prototype.enable = function (id) {
throw new Error('Not implemented yet.');
};
RocketletManager.prototype.disable = function (id) {
throw new Error('Not implemented yet.');
};
// TODO: Determine what to do with this - add or addRocketlet?
RocketletManager.prototype.addRocketlet = function (source) {
throw new Error('Not implemented nor architected.');
};
// TODO: Determine what to do with this - add or addRocketlet?
RocketletManager.prototype.removeRocketlet = function (id) {
throw new Error('Not implemented nor architected.');
};
return RocketletManager;
}());
exports.RocketletManager = RocketletManager;
import { RocketletCompiler } from './compiler';
import { IGetRocketletsFilter } from './interfaces/IGetRocketletsFilter';
import * as fs from 'fs';
import * as path from 'path';
import { BaseRocketlet } from 'temporary-rocketlets-ts-definition/base';
import * as ts from 'typescript';
import * as vm from 'vm';
export class RocketletManager {
private readonly activeRocketlets: Map<number, BaseRocketlet>;
private readonly inactiveRocketlets: Map<number, BaseRocketlet>;
private readonly compiler: RocketletCompiler;
constructor(public folder: string) {
this.activeRocketlets = new Map<number, BaseRocketlet>();
this.inactiveRocketlets = new Map<number, BaseRocketlet>();
this.compiler = new RocketletCompiler();
console.log('Constructed the RocketletLoader and the src folder is:', this.folder);
}
public getCompiler(): RocketletCompiler {
return this.compiler;
}
public load(): Promise<Array<BaseRocketlet>> {
return new Promise((resolve, reject) => {
if (this.folder === '') {
return reject(new Error('Invalid source folder for loading Rocketlets from.'));
}
try {
fs.readdirSync(this.folder).forEach((file) => {
const filePath = path.join(this.folder, file);
// Verify it's a typescript file
if (!file.endsWith('.ts')) {
return;
}
// Verify it is actually a file
const stat = fs.statSync(filePath);
if (stat.isDirectory()) {
return;
}
const src = this.getCompiler().toJs(fs.readFileSync(filePath, 'utf8'));
const rocketlet = this.getCompiler().toSandBox(src);
console.log(`Successfully loaded ${rocketlet.getName()}!`);
});
} catch (e) {
return reject(e);
}
// TODO: Combine the two maps values
return new Array<BaseRocketlet>();
});
}
public get(filter: IGetRocketletsFilter): Array<BaseRocketlet> {
throw new Error('Not implemented yet.');
}
public enable(id: number): boolean {
throw new Error('Not implemented yet.');
}
public disable(id: number): boolean {
throw new Error('Not implemented yet.');
}
// TODO: Determine what to do with this - add or addRocketlet?
public addRocketlet(source: string): BaseRocketlet {
throw new Error('Not implemented nor architected.');
}
// TODO: Determine what to do with this - add or addRocketlet?
public removeRocketlet(id: number): BaseRocketlet {
throw new Error('Not implemented nor architected.');
}
}
{
"name": "rocketlets",
"version": "1.0.0",
"description": "Testing for rocketlets",
"main": "index.js",
"scripts": {
"start": "npm install && node index"
},
"author": "Bradley Hilton",
"license": "MIT",
"dependencies": {
"body-parser": "^1.17.2",
"express": "^4.15.3",
"reflect-metadata": "^0.1.10",
"temporary-rocketlets-ts-definition": "0.1.2",
"tslint": "^5.4.3",
"typescript": "^2.3.4",
"vm2": "^3.4.6"
},
"devDependencies": {
"@types/node": "^7.0.31"
}
}
{
"compileOnSave": false,
"compilerOptions": {
"sourceMap": true,
"target": "es5",
"module": "commonjs",
"declaration": false,
"noImplicitAny": false,
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"moduleResolution": "node",
"lib": ["es2017", "dom"]
},
"exclude": [
"node_modules"
],
"filesGlob": [
"./rc_typings/**/*.ts"
],
"atom": {
"rewriteTsconfig": false
}
}
{
"extends": "tslint:recommended",
"rules": {
"array-type": [true, "generic"],
"no-console": [false],
"no-duplicate-variable": true,
"object-literal-sort-keys": false,
"quotemark": [true, "single"]
},
"jsRules": {
"quotemark": [true, "single"]
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment