112 lines
2.8 KiB
JavaScript
112 lines
2.8 KiB
JavaScript
const Unit = require('libflitter/Unit')
|
|
|
|
/*
|
|
* The Miscellaneous Unit
|
|
* -------------------------------------------------------------
|
|
* This is a Unit file where you should make any modifications that
|
|
* your application may need such as custom Express add-ons. Changes
|
|
* here are loaded after the core Flitter units, but before the other
|
|
* units (secondary, custom, error, and App), so they are available to
|
|
* other units in the stack.
|
|
*/
|
|
class MiscUnit extends Unit {
|
|
|
|
/*
|
|
* Initializes the unit class.
|
|
* This is called OUTSIDE of a Flitter context,
|
|
* so no other contexts are available. Modifications here
|
|
* take place before any part of Flitter is loaded or available.
|
|
*/
|
|
constructor(){
|
|
super()
|
|
|
|
|
|
}
|
|
|
|
/*
|
|
* Initialize the actual Unit.
|
|
* This is where most of the changes will go.
|
|
* This is provided an instance of the Express app
|
|
* so any custom changes can be made. The core Flitter
|
|
* contexts are available here, so things like config(),
|
|
* model(), etc. work.
|
|
*/
|
|
async go(app, context){
|
|
|
|
// do stuff here
|
|
global.devbug = {
|
|
version: '0.2.0',
|
|
code: {
|
|
node: `require("devbugjs")
|
|
dbsetup({
|
|
\tserver: "https://CHANGEME:8000/", // DevBug Server URL
|
|
\tproject: "CHANGEME", // Project API Key
|
|
})`,
|
|
php: `<?php
|
|
// ===========================================================
|
|
// DEVBUG INLINE DEBUGGING HELPER - FOR USE WITH DEVBUG SERVER
|
|
// TODO: REMOVE BEFORE COMMITTING
|
|
$dev_outs = [];
|
|
function out($key, $what, $group = null){
|
|
\tglobal $dev_outs;
|
|
\tif ( $group ){
|
|
\t\tif ( !array_key_exists($group, $dev_outs) ){
|
|
\t\t\t$dev_outs[$group] = [ $key => $what ];
|
|
\t\t}
|
|
\t\telse {
|
|
\t\t\t$dev_outs[$group][$key] = $what;
|
|
\t\t}
|
|
\t}
|
|
\telse {
|
|
\t\t$dev_outs[$key] = $what;
|
|
\t}
|
|
}
|
|
function breakpoint($html = false, $name = null){
|
|
\tglobal $dev_outs;
|
|
\t$devbug = "http://CHANGEME:8000/";
|
|
\t$project_api_key = "CHANGEME";
|
|
\t$bt = debug_backtrace();
|
|
\t$caller = array_shift($bt);
|
|
|
|
\tif ( !$html ){
|
|
\t\tvar_dump([($item ? $item : $caller), 'outs' => $dev_outs]);
|
|
\t}
|
|
\telse {
|
|
\t\techo "<pre><code>";
|
|
\t\tvar_dump([($item ? $item : $caller), 'outs' => $dev_outs]);
|
|
\t\techo "</code></pre>";
|
|
\t}
|
|
|
|
\t// Send to devbug server
|
|
\t$ch = curl_init();
|
|
\t$url = $devbug.'api/v1/out/'.$project_api_key;
|
|
\tvar_dump($url);
|
|
\tcurl_setopt($ch, CURLOPT_URL, $url);
|
|
\tcurl_setopt($ch, CURLOPT_POST, 1);
|
|
\tcurl_setopt($ch, CURLOPT_POSTFIELDS, [
|
|
\t 'data' => json_encode([
|
|
\t 'brief' => ($name ? $name : 'Breakpoint').': '.$caller['file'].': '.$caller['line'],
|
|
\t 'data' => $dev_outs,
|
|
\t ])
|
|
\t]);
|
|
|
|
\tcurl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
\t
|
|
\t$odata = curl_exec($ch);
|
|
|
|
\texit();
|
|
}
|
|
// ===========================================================`
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
name(){
|
|
return "misc"
|
|
}
|
|
|
|
}
|
|
|
|
module.exports = exports = MiscUnit
|