weird stuff happening
parent
31b2bc87e3
commit
9ec0a610bb
|
@ -3,3 +3,4 @@ r3 create R3Object extends Event
|
|||
r3 create Utils normal
|
||||
r3 create Component extends R3Object
|
||||
r3 create Project extends R3Object
|
||||
r3 create System static ./r3-system/
|
||||
|
|
|
@ -1,9 +1,34 @@
|
|||
const Event = require('.././r3-event');
|
||||
const Utils = require('.././r3-utils');
|
||||
|
||||
/**
|
||||
|
||||
STATIC_METHODS_START
|
||||
Start
|
||||
Stop
|
||||
STATIC_METHODS_END
|
||||
|
||||
**/
|
||||
|
||||
class System {
|
||||
|
||||
static start() {
|
||||
console.log('starting a system');
|
||||
}
|
||||
//STATIC_METHODS_DEFINITION_START
|
||||
static Start() {
|
||||
//CUSTOM_START_METHOD_START
|
||||
//CUSTOM_START_METHOD_END
|
||||
}
|
||||
static Stop() {
|
||||
//CUSTOM_STOP_METHOD_START
|
||||
//CUSTOM_STOP_METHOD_END
|
||||
}
|
||||
//STATIC_METHODS_DEFINITION_END
|
||||
|
||||
//CUSTOM_IMPLEMENTATION_START
|
||||
//CUSTOM_IMPLEMENTATION_END
|
||||
|
||||
}
|
||||
|
||||
module.exports = System;
|
||||
//CUSTOM_OUT_OF_CLASS_IMPLEMENTATION_START
|
||||
//CUSTOM_OUT_OF_CLASS_IMPLEMENTATION_END
|
||||
|
||||
module.exports = System;
|
|
@ -1,5 +1,5 @@
|
|||
const Event = require('r3-event');
|
||||
const Utils = require('r3-utils');
|
||||
const Event = require('INCLUDE_PATH/r3-event');
|
||||
const Utils = require('INCLUDE_PATH/r3-utils');
|
||||
|
||||
/**
|
||||
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
const Event = require('INCLUDE_PATH/r3-event');
|
||||
const Utils = require('INCLUDE_PATH/r3-utils');
|
||||
|
||||
/**
|
||||
|
||||
STATIC_METHODS_START
|
||||
STATIC_METHODS_END
|
||||
|
||||
**/
|
||||
|
||||
class CLASS_NAME {
|
||||
|
||||
//STATIC_METHODS_DEFINITION_START
|
||||
//STATIC_METHODS_DEFINITION_END
|
||||
|
||||
//CUSTOM_IMPLEMENTATION_START
|
||||
//CUSTOM_IMPLEMENTATION_END
|
||||
|
||||
}
|
||||
|
||||
//CUSTOM_OUT_OF_CLASS_IMPLEMENTATION_START
|
||||
//CUSTOM_OUT_OF_CLASS_IMPLEMENTATION_END
|
||||
|
||||
module.exports = CLASS_NAME;
|
|
@ -0,0 +1,4 @@
|
|||
static METHOD_NAME() {
|
||||
//CUSTOM_METHOD_NAME_UPPERCASE_METHOD_START
|
||||
//CUSTOM_METHOD_NAME_UPPERCASE_METHOD_END
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
const Event = require('r3-event');
|
||||
const Utils = require('r3-utils');
|
||||
|
||||
/**
|
||||
|
||||
OPTIONS_START
|
||||
OPTIONS_END
|
||||
|
||||
**/
|
||||
|
||||
class CLASS_NAME {
|
||||
|
||||
//CONSTRUCTOR_TEMPLATE_START
|
||||
//CONSTRUCTOR_TEMPLATE_END
|
||||
|
||||
//CUSTOM_IMPLEMENTATION_START
|
||||
//CUSTOM_IMPLEMENTATION_END
|
||||
|
||||
}
|
||||
|
||||
//CUSTOM_OUT_OF_CLASS_IMPLEMENTATION_START
|
||||
//CUSTOM_OUT_OF_CLASS_IMPLEMENTATION_END
|
||||
|
||||
module.exports = CLASS_NAME;
|
|
@ -0,0 +1,138 @@
|
|||
#!/usr/bin/php
|
||||
<?php
|
||||
|
||||
if (isset($argc)) {
|
||||
for ($i = 0; $i < $argc; $i++) {
|
||||
echo "Argument #" . $i . " - " . $argv[$i] . "\n";
|
||||
}
|
||||
}
|
||||
else {
|
||||
echo "argc and argv disabled\n";
|
||||
}
|
||||
|
||||
if ($argv[1] == 'all') {
|
||||
$files = scandir('src/r3/', SCANDIR_SORT_DESCENDING);
|
||||
$systemFiles = scandir('src/r3/r3-system', SCANDIR_SORT_DESCENDING);
|
||||
|
||||
$newFiles = [];
|
||||
|
||||
for ($i = 0; $i < sizeof($files); $i++) {
|
||||
if (preg_match('/\.js$/', $files[$i])) {
|
||||
array_push($newFiles, 'src/r3/' . $files[$i]);
|
||||
}
|
||||
}
|
||||
|
||||
for ($i = 0; $i < sizeof($systemFiles); $i++) {
|
||||
if (preg_match('/\.js$/', $systemFiles[$i])) {
|
||||
array_push($newFiles, 'src/r3/r3-system/' . $systemFiles[$i]);
|
||||
}
|
||||
}
|
||||
|
||||
$files = $newFiles;
|
||||
|
||||
} else {
|
||||
$files = [$argv[1]];
|
||||
}
|
||||
|
||||
foreach ($files as $file) {
|
||||
|
||||
echo $file . "\n";
|
||||
|
||||
echo "processing methods for file " . $file . "\n";
|
||||
|
||||
$fn = fopen($file, "r");
|
||||
|
||||
$saveLine = true;
|
||||
|
||||
$methods = [];
|
||||
|
||||
$saveMethod = false;
|
||||
|
||||
$lines = [];
|
||||
|
||||
while (!feof($fn)) {
|
||||
|
||||
$line = fgets($fn);
|
||||
|
||||
/**
|
||||
* if exiting an options definition block - stop saving that definition
|
||||
*/
|
||||
if (preg_match('/\bSTATIC_METHODS_END\b/', $line)) {
|
||||
$saveMethod = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* if exiting an method mplementation block - save the line for later
|
||||
*/
|
||||
if (preg_match('/\bSTATIC_METHODS_DEFINITION_END\b/', $line)) {
|
||||
$saveLine = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Now save the line
|
||||
*/
|
||||
if ($saveLine) {
|
||||
array_push($lines, $line);
|
||||
}
|
||||
|
||||
/**
|
||||
* if entering an options implementation block - do not save the line for later
|
||||
*/
|
||||
if (preg_match('/\bSTATIC_METHODS_DEFINITION_START\b/', $line)) {
|
||||
$saveLine = false;
|
||||
}
|
||||
|
||||
if ($saveMethod) {
|
||||
|
||||
$line = trim($line);
|
||||
|
||||
array_push($methods, $line);
|
||||
}
|
||||
|
||||
/**
|
||||
* If entering an options definition block - start saving that definition
|
||||
*/
|
||||
if (preg_match('/\bSTATIC_METHODS_START\b/', $line)) {
|
||||
$saveMethod = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fclose($fn);
|
||||
|
||||
file_put_contents($file, $lines);
|
||||
|
||||
/**
|
||||
* Process the methods
|
||||
*/
|
||||
|
||||
if (sizeof($methods) > 0) {
|
||||
|
||||
$template = file_get_contents('src/templates/static_method.template');
|
||||
|
||||
$newOptions = '';
|
||||
|
||||
foreach ($methods as $method) {
|
||||
$updated = str_replace('METHOD_NAME_UPPERCASE', strtoupper($method), $template);
|
||||
$updated = str_replace('METHOD_NAME', $method, $updated);
|
||||
$newOptions .= $updated;
|
||||
}
|
||||
|
||||
$contents = file_get_contents($file);
|
||||
|
||||
$contents = preg_replace(
|
||||
'/\/\/\bSTATIC_METHODS_DEFINITION_START\b.*?\/\/\bSTATIC_METHODS_DEFINITION_END\b/s',
|
||||
"//STATIC_METHODS_DEFINITION_START\n" . $newOptions . "\t\t//STATIC_METHODS_DEFINITION_END",
|
||||
$contents
|
||||
);
|
||||
|
||||
file_put_contents($file, $contents);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
exit(0);
|
||||
?>
|
||||
|
|
@ -14,6 +14,7 @@ $tokens = [
|
|||
'OPTIONS_START' => 'OPTIONS_END',
|
||||
'INSTANCE_OPTIONS_MAPPING_START' => 'INSTANCE_OPTIONS_MAPPING_END',
|
||||
'LINKED_OBJECTS_START' => 'LINKED_OBJECTS_END',
|
||||
'STATIC_METHODS_START' => 'STATIC_METHODS_END',
|
||||
'EXCLUDED_FROM_INSTANCE_OPTIONS_START' => 'EXCLUDED_FROM_INSTANCE_OPTIONS_END',
|
||||
'CUSTOM_OPTIONS_INIT_START' => 'CUSTOM_OPTIONS_INIT_END',
|
||||
'CUSTOM_BEFORE_INIT_START' => 'CUSTOM_BEFORE_INIT_END',
|
||||
|
@ -23,7 +24,8 @@ $tokens = [
|
|||
'CUSTOM_DISPOSE_START' => 'CUSTOM_DISPOSE_END',
|
||||
'CUSTOM_DISPOSE_INSTANCE_START' => 'CUSTOM_DISPOSE_INSTANCE_END',
|
||||
'CUSTOM_IMPLEMENTATION_START' => 'CUSTOM_IMPLEMENTATION_END',
|
||||
'CUSTOM_OUT_OF_CLASS_IMPLEMENTATION_START' => 'CUSTOM_OUT_OF_CLASS_IMPLEMENTATION_END'
|
||||
'CUSTOM_OUT_OF_CLASS_IMPLEMENTATION_START' => 'CUSTOM_OUT_OF_CLASS_IMPLEMENTATION_END',
|
||||
'CUSTOM_[A..Z_]+_METHOD_START' => 'CUSTOM_[A..Z_]+_METHOD_END'
|
||||
];
|
||||
|
||||
$files = [$argv[2]];
|
||||
|
@ -51,7 +53,14 @@ foreach ($files as $file) {
|
|||
$saved = [];
|
||||
$startSaving = false;
|
||||
|
||||
$fn = null;
|
||||
|
||||
// try {
|
||||
$fn = fopen($file, "r");
|
||||
// } catch (Exception $e) {
|
||||
// $file = "r3-system/" . $file;
|
||||
// $fn = fopen($file, "r");
|
||||
// }
|
||||
|
||||
while (!feof($fn)) {
|
||||
|
||||
|
@ -114,6 +123,8 @@ foreach ($files as $file) {
|
|||
|
||||
$startRestoring = false;
|
||||
|
||||
$saveLine = true;
|
||||
|
||||
while (!feof($fh)) {
|
||||
|
||||
$line = fgets($fh);
|
||||
|
@ -129,12 +140,14 @@ foreach ($files as $file) {
|
|||
foreach ($tokens as $startToken => $endToken) {
|
||||
if (preg_match('/\b' . $endToken . '\b/', $line)) {
|
||||
$startRestoring = false;
|
||||
$saveLine = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($startRestoring) {
|
||||
|
||||
|
||||
$startToken = $restoreTokenPair[0];
|
||||
$endToken = $restoreTokenPair[1];
|
||||
|
||||
|
@ -145,13 +158,18 @@ foreach ($files as $file) {
|
|||
echo "Could not find data to be restored : startIndex = " . $startIndex . ", endIndex = " . $endIndex;
|
||||
echo "Restore token pair = ";
|
||||
print_r($restoreTokenPair);
|
||||
array_push($merged, $line);
|
||||
$saveLine = true;
|
||||
} else {
|
||||
$restored = array_splice($saved, $startIndex, $endIndex - $startIndex);
|
||||
$restored = array_splice($saved, $startIndex, ($endIndex - $startIndex + 1));
|
||||
$merged = array_merge($merged, $restored);
|
||||
$saveLine = false;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
|
||||
if ($saveLine) {
|
||||
array_push($merged, $line);
|
||||
} else {
|
||||
$saveLine = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -161,7 +179,7 @@ foreach ($files as $file) {
|
|||
|
||||
echo "Restored file " . $file;
|
||||
|
||||
unlink($saveFile);
|
||||
// unlink($saveFile);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue