@makano/rew 1.1.73 → 1.1.81

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/lib/rew/cli/cli.js +189 -144
  2. package/lib/rew/cli/log.js +18 -19
  3. package/lib/rew/cli/run.js +7 -9
  4. package/lib/rew/cli/utils.js +109 -95
  5. package/lib/rew/const/config_path.js +4 -0
  6. package/lib/rew/const/default.js +21 -3
  7. package/lib/rew/const/files.js +11 -8
  8. package/lib/rew/const/opt.js +6 -6
  9. package/lib/rew/css/theme.css +1 -1
  10. package/lib/rew/functions/core.js +7 -9
  11. package/lib/rew/functions/emitter.js +2 -2
  12. package/lib/rew/functions/exec.js +19 -15
  13. package/lib/rew/functions/export.js +4 -6
  14. package/lib/rew/functions/fs.js +21 -18
  15. package/lib/rew/functions/future.js +1 -1
  16. package/lib/rew/functions/import.js +55 -25
  17. package/lib/rew/functions/map.js +2 -5
  18. package/lib/rew/functions/match.js +21 -5
  19. package/lib/rew/functions/path.js +2 -2
  20. package/lib/rew/functions/require.js +16 -13
  21. package/lib/rew/functions/stdout.js +11 -11
  22. package/lib/rew/functions/types.js +67 -42
  23. package/lib/rew/html/ui.html +5 -6
  24. package/lib/rew/html/ui.js +100 -58
  25. package/lib/rew/main.js +3 -3
  26. package/lib/rew/misc/findAppInfo.js +16 -0
  27. package/lib/rew/misc/findAppPath.js +21 -0
  28. package/lib/rew/misc/seededid.js +13 -0
  29. package/lib/rew/models/struct.js +1 -1
  30. package/lib/rew/modules/compiler.js +90 -58
  31. package/lib/rew/modules/context.js +35 -22
  32. package/lib/rew/modules/runtime.js +1 -1
  33. package/lib/rew/pkgs/conf.js +50 -33
  34. package/lib/rew/pkgs/data.js +7 -2
  35. package/lib/rew/pkgs/date.js +8 -9
  36. package/lib/rew/pkgs/env.js +3 -5
  37. package/lib/rew/pkgs/modules/data/bintree.js +1 -1
  38. package/lib/rew/pkgs/modules/data/doublylinked.js +1 -1
  39. package/lib/rew/pkgs/modules/data/linkedList.js +1 -1
  40. package/lib/rew/pkgs/modules/data/queue.js +1 -2
  41. package/lib/rew/pkgs/modules/data/stack.js +1 -1
  42. package/lib/rew/pkgs/modules/threads/worker.js +31 -21
  43. package/lib/rew/pkgs/modules/ui/classes.js +68 -61
  44. package/lib/rew/pkgs/pkgs.js +5 -6
  45. package/lib/rew/pkgs/rune.js +437 -0
  46. package/lib/rew/pkgs/threads.js +30 -22
  47. package/lib/rew/pkgs/ui.js +68 -44
  48. package/package.json +8 -2
@@ -11,17 +11,19 @@ const cachedFiles = [];
11
11
 
12
12
  const lookUpInOtherApps = (fullPath) => {
13
13
  const con = conf({});
14
- const name = fullPath.indexOf('/') ? fullPath.split('/')[0] : fullPath;
15
- let dpath = fullPath.indexOf('/') ? fullPath.split('/')[1] : '';
16
- let ppath = path.join(con.CONFIG_PATH, name, 'app');
14
+ const name = fullPath.indexOf("/") ? fullPath.split("/")[0] : fullPath;
15
+ let dpath = fullPath.indexOf("/") ? fullPath.split("/")[1] : "";
16
+ let ppath = path.join(con.CONFIG_PATH, name, "app");
17
17
  if (!existsSync(ppath)) return null;
18
18
  if (!dpath) {
19
- dpath = jsYaml.load(readFileSync(path.join(ppath, 'app.yaml'), 'utf-8')).entry;
19
+ dpath = jsYaml.load(
20
+ readFileSync(path.join(ppath, "app.yaml"), "utf-8"),
21
+ ).entry;
20
22
  }
21
23
  ppath = path.join(ppath, dpath);
22
24
  if (existsSync(ppath)) return ppath;
23
25
  else return null;
24
- }
26
+ };
25
27
 
26
28
  module.exports.imp = function (runPath, context) {
27
29
  return function (filename, options = {}) {
@@ -30,7 +32,14 @@ module.exports.imp = function (runPath, context) {
30
32
  let exports,
31
33
  ispkg = findPackage(filename);
32
34
 
33
- let filepath = path.resolve(path.dirname(context.module.filepath), filename);
35
+ if (filename.startsWith("@") && context.app) {
36
+ filename = filename.replace("@", context.app.path);
37
+ }
38
+
39
+ let filepath = path.resolve(
40
+ path.dirname(context.module.filepath),
41
+ filename,
42
+ );
34
43
 
35
44
  // console.log(typeof runPath);
36
45
 
@@ -38,17 +47,24 @@ module.exports.imp = function (runPath, context) {
38
47
  const otherPath = lookUpInOtherApps(filename);
39
48
  if (!otherPath) throw new Error('Module "' + filename + '" not found');
40
49
  else filepath = otherPath;
41
- }
50
+ };
42
51
 
43
- const foundCache = cachedFiles.find(f => f.filepath == filepath);
52
+ const foundCache = cachedFiles.find((f) => f.filepath == filepath);
44
53
 
45
54
  if (!ispkg && foundCache) {
46
55
  exports = foundCache.exports;
47
56
  }
48
57
 
49
58
  if (!ispkg && !existsSync(filepath)) {
50
- if (Array.isArray(execOptions.resolveExtensions) && execOptions.resolveExtensions.length) {
51
- const resolve = execOptions.resolveExtensions.find(ext => typeof ext == "string" ? existsSync(filepath + ext) : existsSync(filepath + (ext.ext || '')));
59
+ if (
60
+ Array.isArray(execOptions.resolveExtensions) &&
61
+ execOptions.resolveExtensions.length
62
+ ) {
63
+ const resolve = execOptions.resolveExtensions.find((ext) =>
64
+ typeof ext == "string"
65
+ ? existsSync(filepath + ext)
66
+ : existsSync(filepath + (ext.ext || "")),
67
+ );
52
68
  if (resolve) {
53
69
  filepath += typeof resolve == "string" ? resolve : resolve.ext;
54
70
  if (typeof resolve == "object" && resolve.options) {
@@ -59,24 +75,38 @@ module.exports.imp = function (runPath, context) {
59
75
  } else lookUp();
60
76
  }
61
77
 
62
- const exec = (coptions = {}) => runPath(
63
- filepath,
64
- {
65
- import: options,
66
- main: false,
67
- useContext: execOptions.sharedContext == false ? false : !(options.context && options.context == 'new'),
68
- ...coptions,
69
- as: options.as == 'main' ? context.module.main ? 'main' : 'parent' : options.as == 'parent' ? 'parent' : 'child',
70
- fromMain: context.module.main
71
- },
72
- execOptions.sharedContext == false ? {} :
73
- options.context && options.context == 'new' ? {} : context,
74
- ).context.module.exports;
78
+ const exec = (coptions = {}) =>
79
+ runPath(
80
+ filepath,
81
+ {
82
+ import: options,
83
+ main: false,
84
+ useContext:
85
+ execOptions.sharedContext == false
86
+ ? false
87
+ : !(options.context && options.context == "new"),
88
+ ...coptions,
89
+ as:
90
+ options.as == "main"
91
+ ? context.module.main
92
+ ? "main"
93
+ : "parent"
94
+ : options.as == "parent"
95
+ ? "parent"
96
+ : "child",
97
+ fromMain: context.module.main,
98
+ },
99
+ execOptions.sharedContext == false
100
+ ? {}
101
+ : options.context && options.context == "new"
102
+ ? {}
103
+ : context,
104
+ ).context.module.exports;
75
105
 
76
106
  if (ispkg) {
77
- exports = getPackage(filename)(context);
107
+ const pkg = getPackage(filename)(context);
108
+ exports = pkg._onImport ? pkg._onImport() : pkg;
78
109
  } else if (foundCache) {
79
-
80
110
  } else if (type == "coffee") {
81
111
  exports = exec({});
82
112
  } else if (type == "js") {
@@ -1,9 +1,6 @@
1
-
2
-
3
-
4
1
  module.exports.map = function map(...args) {
5
2
  if (args.length % 2 !== 0) {
6
- throw new Error('Arguments must be in key-value pairs');
3
+ throw new Error("Arguments must be in key-value pairs");
7
4
  }
8
5
 
9
6
  const result = new Map();
@@ -14,4 +11,4 @@ module.exports.map = function map(...args) {
14
11
  }
15
12
 
16
13
  return result;
17
- };
14
+ };
@@ -1,7 +1,7 @@
1
-
2
1
  const SerializableData = ["string", "number", "boolean"];
3
2
 
4
- const isRegExp = (obj) => Object.prototype.toString.call(obj) === '[object RegExp]';
3
+ const isRegExp = (obj) =>
4
+ Object.prototype.toString.call(obj) === "[object RegExp]";
5
5
 
6
6
  module.exports.match = function match(value, templates, props) {
7
7
  const matchProps = (pattern, value) => {
@@ -22,13 +22,29 @@ module.exports.match = function match(value, templates, props) {
22
22
 
23
23
  const matchRegex = (pattern, value) => pattern.test(value);
24
24
 
25
- const entries = templates instanceof Map ? templates.entries() : Array.isArray(templates) ? templates : Object.entries(templates);
25
+ const entries =
26
+ templates instanceof Map
27
+ ? templates.entries()
28
+ : Array.isArray(templates)
29
+ ? templates
30
+ : Object.entries(templates);
26
31
 
27
32
  for (const [pattern, callback] of entries) {
28
- if (isRegExp(pattern) ? matchRegex(pattern, value) : SerializableData.includes(typeof value) ? pattern == value : (isRegExp(pattern) ? matchRegex(pattern, value) : (typeof pattern === "function" ? value instanceof pattern || value?.__proto__?.['@instance'] === pattern : matchProps(pattern, value)))) {
33
+ if (
34
+ isRegExp(pattern)
35
+ ? matchRegex(pattern, value)
36
+ : SerializableData.includes(typeof value)
37
+ ? pattern == value
38
+ : isRegExp(pattern)
39
+ ? matchRegex(pattern, value)
40
+ : typeof pattern === "function"
41
+ ? value instanceof pattern ||
42
+ value?.__proto__?.["@instance"] === pattern
43
+ : matchProps(pattern, value)
44
+ ) {
29
45
  return callback(...(isRegExp(pattern) ? pattern.exec(value) : [value]));
30
46
  }
31
47
  }
32
48
 
33
49
  return null;
34
- };
50
+ };
@@ -1,4 +1,4 @@
1
- const path = require('path');
1
+ const path = require("path");
2
2
 
3
3
  module.exports = (currentFile) => {
4
4
  const e = {};
@@ -10,4 +10,4 @@ module.exports = (currentFile) => {
10
10
  e.presolve = (...paths) => path.resolve(...paths);
11
11
 
12
12
  return e;
13
- }
13
+ };
@@ -1,36 +1,39 @@
1
- const fs = require('fs');
2
- const path = require('path');
3
-
1
+ const fs = require("fs");
2
+ const path = require("path");
4
3
 
5
4
  module.exports.customRequire = function customRequire(modulePath, filePath) {
6
5
  const resolvedPath = resolveModulePath(modulePath, filePath);
7
6
  return require(resolvedPath);
8
- }
7
+ };
9
8
 
10
9
  function resolveModulePath(modulePath, filePath) {
11
- if (modulePath.startsWith('./') || modulePath.startsWith('../') || path.isAbsolute(modulePath)) {
10
+ if (
11
+ modulePath.startsWith("./") ||
12
+ modulePath.startsWith("../") ||
13
+ path.isAbsolute(modulePath)
14
+ ) {
12
15
  return path.resolve(modulePath);
13
16
  }
14
17
 
15
18
  const paths = module.constructor._nodeModulePaths(path.dirname(filePath));
16
19
  for (const basePath of paths) {
17
20
  const fullPath = path.join(basePath, modulePath);
18
- if (fs.existsSync(fullPath + '.js')) {
19
- return fullPath + '.js';
21
+ if (fs.existsSync(fullPath + ".js")) {
22
+ return fullPath + ".js";
20
23
  }
21
- if (fs.existsSync(fullPath + '.json')) {
22
- return fullPath + '.json';
24
+ if (fs.existsSync(fullPath + ".json")) {
25
+ return fullPath + ".json";
23
26
  }
24
27
  if (fs.existsSync(fullPath) && fs.statSync(fullPath).isDirectory()) {
25
- const packageJsonPath = path.join(fullPath, 'package.json');
28
+ const packageJsonPath = path.join(fullPath, "package.json");
26
29
  if (fs.existsSync(packageJsonPath)) {
27
- const main = require(packageJsonPath).main || 'index.js';
30
+ const main = require(packageJsonPath).main || "index.js";
28
31
  const mainPath = path.join(fullPath, main);
29
32
  if (fs.existsSync(mainPath)) {
30
33
  return mainPath;
31
34
  }
32
35
  }
33
- const indexPath = path.join(fullPath, 'index.js');
36
+ const indexPath = path.join(fullPath, "index.js");
34
37
  if (fs.existsSync(indexPath)) {
35
38
  return indexPath;
36
39
  }
@@ -38,4 +41,4 @@ function resolveModulePath(modulePath, filePath) {
38
41
  }
39
42
 
40
43
  throw new Error(`Cannot find module '${modulePath}'`);
41
- }
44
+ }
@@ -1,9 +1,9 @@
1
- const { execSync, spawnSync } = require('child_process');
2
- const fs = require('fs');
1
+ const { execSync, spawnSync } = require("child_process");
2
+ const fs = require("fs");
3
3
 
4
- const print = module.exports.print = function print(...arguments) {
4
+ const print = (module.exports.print = function print(...arguments) {
5
5
  return console.log(...arguments);
6
- };
6
+ });
7
7
 
8
8
  print.stdout = process.stdout;
9
9
  print.stdin = process.stdin;
@@ -14,17 +14,17 @@ module.exports.input = function input(prompt) {
14
14
  let cmd;
15
15
  let args;
16
16
  if ("null" == "win32") {
17
- cmd = 'cmd';
18
- args = ['/V:ON', '/C', 'set /p response= && echo !response!'];
17
+ cmd = "cmd";
18
+ args = ["/V:ON", "/C", "set /p response= && echo !response!"];
19
19
  } else {
20
- cmd = 'bash';
21
- args = ['-c', 'read response; echo "$response"'];
20
+ cmd = "bash";
21
+ args = ["-c", 'read response; echo "$response"'];
22
22
  }
23
23
 
24
24
  let opts = {
25
- stdio: ['inherit', 'pipe'],
25
+ stdio: ["inherit", "pipe"],
26
26
  shell: false,
27
27
  };
28
-
28
+
29
29
  return spawnSync(cmd, args, opts).stdout.toString().trim();
30
- }
30
+ };
@@ -1,4 +1,3 @@
1
-
2
1
  const _defaultConstructors = {
3
2
  string: String,
4
3
  array: Array,
@@ -8,48 +7,68 @@ const _defaultConstructors = {
8
7
  symbol: Symbol,
9
8
  undefined: Object,
10
9
  object: Object,
11
- function: Function
12
- }
13
-
14
- function getType(value){
15
- return typeof value === 'object' ? Array.isArray(value) ? 'array' : typeof value : typeof value;
10
+ function: Function,
11
+ };
12
+
13
+ function getType(value) {
14
+ return typeof value === "object"
15
+ ? Array.isArray(value)
16
+ ? "array"
17
+ : typeof value
18
+ : typeof value;
16
19
  }
17
20
 
18
21
  function typedef(value, strict = false) {
19
22
  return {
20
23
  strict,
21
24
  defaultValue: value,
22
- class: typeof value == 'function' ? value : typeof value === 'object' && value !== null && !Array.isArray(value) ? value.constructor : _defaultConstructors[getType(value)],
25
+ class:
26
+ typeof value == "function"
27
+ ? value
28
+ : typeof value === "object" && value !== null && !Array.isArray(value)
29
+ ? value.constructor
30
+ : _defaultConstructors[getType(value)],
23
31
  type: getType(value),
24
- isConstucted: typeof value === 'object' && value !== null && !Array.isArray(value),
25
- isEmpty: typeof value == "object" ? !Object.keys(value).length : typeof value == "string" ? value == "" : typeof value !== "function"
32
+ isConstucted:
33
+ typeof value === "object" && value !== null && !Array.isArray(value),
34
+ isEmpty:
35
+ typeof value == "object"
36
+ ? !Object.keys(value).length
37
+ : typeof value == "string"
38
+ ? value == ""
39
+ : typeof value !== "function",
26
40
  };
27
41
  }
28
42
 
29
43
  function typeis(obj, typeDef) {
30
44
  // Resolve Type
31
- if(typeof typeDef == "function" && typeDef.type) typeDef = typeDef.type;
45
+ if (typeof typeDef == "function" && typeDef.type) typeDef = typeDef.type;
32
46
 
33
- if (typeDef.isConstucted && typeDef.class && !(obj instanceof typeDef.class)) {
47
+ if (
48
+ typeDef.isConstucted &&
49
+ typeDef.class &&
50
+ !(obj instanceof typeDef.class)
51
+ ) {
34
52
  return false;
35
53
  }
36
54
 
37
- if(getType(obj) == "object" && typeDef.type == 'function') {
38
- return (obj instanceof typeDef.class);
55
+ if (getType(obj) == "object" && typeDef.type == "function") {
56
+ return obj instanceof typeDef.class;
39
57
  }
40
58
 
41
- if(getType(obj) !== typeDef.type){
59
+ if (getType(obj) !== typeDef.type) {
42
60
  return false;
43
61
  }
44
62
 
45
- if(!typeDef.isEmpty) {
46
- if(typeDef.type == 'object'){
63
+ if (!typeDef.isEmpty) {
64
+ if (typeDef.type == "object") {
47
65
  for (const key in typeDef.defaultValue) {
48
66
  let propTypeDef = typeDef.defaultValue[key];
49
67
  // Resolve type
50
- if(typeof propTypeDef == "function" && propTypeDef.type) propTypeDef = propTypeDef.type;
51
-
52
- if (typeof propTypeDef === 'object') {
68
+ if (typeof propTypeDef == "function" && propTypeDef.type)
69
+ propTypeDef = propTypeDef.type;
70
+
71
+ if (typeof propTypeDef === "object") {
53
72
  if (!typeis(obj[key], propTypeDef)) {
54
73
  return false;
55
74
  }
@@ -57,12 +76,17 @@ function typeis(obj, typeDef) {
57
76
  return false;
58
77
  }
59
78
  }
60
- if(typeDef.strict) {
61
- if(Object.keys(obj).some(key => !Object.keys(typeDef.defaultValue).includes(key))) return false;
79
+ if (typeDef.strict) {
80
+ if (
81
+ Object.keys(obj).some(
82
+ (key) => !Object.keys(typeDef.defaultValue).includes(key),
83
+ )
84
+ )
85
+ return false;
62
86
  }
63
- } else if(typeDef.type == 'string'){
87
+ } else if (typeDef.type == "string") {
64
88
  return typeDef.defaultValue == obj;
65
- } else if(typeDef.type == 'function'){
89
+ } else if (typeDef.type == "function") {
66
90
  return typeDef.defaultValue == obj;
67
91
  }
68
92
  }
@@ -78,46 +102,47 @@ function typei(child, parent) {
78
102
  return child instanceof parent || child.constructor === parent;
79
103
  }
80
104
 
81
- function int(str){
105
+ function int(str) {
82
106
  return parseInt(str);
83
107
  }
84
- int.type = typedef(1)
108
+ int.type = typedef(1);
85
109
 
86
- function float(str){
110
+ function float(str) {
87
111
  return parseFloat(str);
88
112
  }
89
- float.type = typedef(1.0)
113
+ float.type = typedef(1.0);
90
114
 
91
- function num(str){
115
+ function num(str) {
92
116
  return Number(str);
93
117
  }
94
- num.type = typedef(1)
118
+ num.type = typedef(1);
95
119
 
96
- function str(str){
120
+ function str(str) {
97
121
  return str ? str.toString() : "";
98
122
  }
99
- str.type = typedef('')
100
-
101
- function bool(value){
102
- return typeof value == 'string' ? (
103
- value == 'true' ? true : false
104
- ) : value !== null && value !== undefined;
123
+ str.type = typedef("");
124
+
125
+ function bool(value) {
126
+ return typeof value == "string"
127
+ ? value == "true"
128
+ ? true
129
+ : false
130
+ : value !== null && value !== undefined;
105
131
  }
106
- bool.type = typedef(true)
132
+ bool.type = typedef(true);
107
133
 
108
134
  module.exports = {
109
135
  typex,
110
136
  typei,
111
137
  typeis,
112
138
  typedef,
113
-
139
+
114
140
  int,
115
141
  float,
116
142
  num,
117
143
  str,
118
- bool
119
- }
120
-
144
+ bool,
145
+ };
121
146
 
122
147
  // const f = typedef('');
123
148
  // const fg = typedef({ g: f });
@@ -137,4 +162,4 @@ module.exports = {
137
162
  // let tn = typedef(n)
138
163
 
139
164
  // // console.log(typeis(g, fg), typeis(1, f), typei('', String));
140
- // console.log(typeis(l, tn));
165
+ // console.log(typeis(l, tn));
@@ -5,15 +5,14 @@
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
6
  <title>$OPTIONS(title)</title>
7
7
 
8
- <style>/* $OPTIONS(style) */</style>
9
-
8
+ <style>
9
+ /* $OPTIONS(style) */
10
+ </style>
10
11
 
11
12
  <script>
12
- window.onerror = () => alert('ERror');
13
+ window.onerror = () => alert("ERror");
13
14
  </script>
14
15
  </head>
15
16
 
16
- <body>
17
-
18
- </body>
17
+ <body></body>
19
18
  </html>