@makano/rew 1.1.7 → 1.1.9

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 (74) hide show
  1. package/README.md +1 -1
  2. package/bin/ui +0 -0
  3. package/build.sh +3 -1
  4. package/lib/coffeescript/browser.js +144 -139
  5. package/lib/coffeescript/cake.js +132 -133
  6. package/lib/coffeescript/coffeescript.js +437 -381
  7. package/lib/coffeescript/command.js +806 -724
  8. package/lib/coffeescript/grammar.js +1908 -2474
  9. package/lib/coffeescript/helpers.js +509 -473
  10. package/lib/coffeescript/index.js +228 -215
  11. package/lib/coffeescript/lexer.js +2282 -1909
  12. package/lib/coffeescript/nodes.js +9782 -9202
  13. package/lib/coffeescript/optparse.js +255 -227
  14. package/lib/coffeescript/parser.js +20305 -1265
  15. package/lib/coffeescript/register.js +107 -87
  16. package/lib/coffeescript/repl.js +307 -284
  17. package/lib/coffeescript/rewriter.js +1389 -1079
  18. package/lib/coffeescript/scope.js +176 -172
  19. package/lib/coffeescript/sourcemap.js +242 -227
  20. package/lib/rew/cli/cli.js +245 -186
  21. package/lib/rew/cli/log.js +31 -32
  22. package/lib/rew/cli/run.js +10 -12
  23. package/lib/rew/cli/utils.js +248 -175
  24. package/lib/rew/const/config_path.js +4 -0
  25. package/lib/rew/const/default.js +38 -35
  26. package/lib/rew/const/files.js +9 -9
  27. package/lib/rew/const/opt.js +8 -8
  28. package/lib/rew/css/theme.css +2 -2
  29. package/lib/rew/functions/core.js +55 -57
  30. package/lib/rew/functions/curl.js +23 -0
  31. package/lib/rew/functions/emitter.js +52 -55
  32. package/lib/rew/functions/exec.js +25 -21
  33. package/lib/rew/functions/export.js +18 -20
  34. package/lib/rew/functions/fs.js +55 -54
  35. package/lib/rew/functions/future.js +29 -21
  36. package/lib/rew/functions/id.js +8 -9
  37. package/lib/rew/functions/import.js +104 -93
  38. package/lib/rew/functions/map.js +13 -16
  39. package/lib/rew/functions/match.js +35 -26
  40. package/lib/rew/functions/path.js +8 -8
  41. package/lib/rew/functions/require.js +32 -33
  42. package/lib/rew/functions/sleep.js +2 -2
  43. package/lib/rew/functions/stdout.js +20 -20
  44. package/lib/rew/functions/types.js +96 -95
  45. package/lib/rew/html/ui.html +12 -13
  46. package/lib/rew/html/ui.js +205 -168
  47. package/lib/rew/main.js +14 -14
  48. package/lib/rew/misc/findAppInfo.js +16 -0
  49. package/lib/rew/misc/findAppPath.js +21 -0
  50. package/lib/rew/misc/seededid.js +13 -0
  51. package/lib/rew/models/enum.js +12 -12
  52. package/lib/rew/models/struct.js +30 -32
  53. package/lib/rew/modules/compiler.js +228 -177
  54. package/lib/rew/modules/context.js +35 -22
  55. package/lib/rew/modules/fs.js +10 -10
  56. package/lib/rew/modules/runtime.js +17 -21
  57. package/lib/rew/modules/yaml.js +27 -30
  58. package/lib/rew/pkgs/conf.js +82 -75
  59. package/lib/rew/pkgs/data.js +12 -7
  60. package/lib/rew/pkgs/date.js +27 -28
  61. package/lib/rew/pkgs/env.js +6 -8
  62. package/lib/rew/pkgs/modules/data/bintree.js +52 -52
  63. package/lib/rew/pkgs/modules/data/doublylinked.js +85 -85
  64. package/lib/rew/pkgs/modules/data/linkedList.js +73 -73
  65. package/lib/rew/pkgs/modules/data/queue.js +19 -20
  66. package/lib/rew/pkgs/modules/data/stack.js +19 -19
  67. package/lib/rew/pkgs/modules/threads/worker.js +36 -26
  68. package/lib/rew/pkgs/modules/ui/classes.js +182 -178
  69. package/lib/rew/pkgs/pkgs.js +9 -10
  70. package/lib/rew/pkgs/rune.js +422 -0
  71. package/lib/rew/pkgs/threads.js +57 -53
  72. package/lib/rew/pkgs/ui.js +148 -136
  73. package/meson.build +13 -0
  74. package/package.json +9 -2
@@ -1,112 +1,123 @@
1
- const path = require("path");
2
- const { getFile, file } = require("../modules/fs");
3
- const { importYaml } = require("../modules/yaml");
4
- const { findPackage, getPackage } = require("../pkgs/pkgs");
5
- const { existsSync, readFileSync } = require("fs");
6
- const conf = require("../pkgs/conf");
7
- const jsYaml = require("js-yaml");
8
- const { execOptions } = require("../const/opt");
1
+ const path = require('path');
2
+ const { getFile, file } = require('../modules/fs');
3
+ const { importYaml } = require('../modules/yaml');
4
+ const { findPackage, getPackage } = require('../pkgs/pkgs');
5
+ const { existsSync, readFileSync } = require('fs');
6
+ const conf = require('../pkgs/conf');
7
+ const jsYaml = require('js-yaml');
8
+ const { execOptions } = require('../const/opt');
9
9
 
10
10
  const cachedFiles = [];
11
11
 
12
12
  const lookUpInOtherApps = (fullPath) => {
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');
17
- if (!existsSync(ppath)) return null;
18
- if (!dpath) {
19
- dpath = jsYaml.load(readFileSync(path.join(ppath, 'app.yaml'), 'utf-8')).entry;
20
- }
21
- ppath = path.join(ppath, dpath);
22
- if (existsSync(ppath)) return ppath;
23
- else return null;
24
- }
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');
17
+ const config = jsYaml.load(readFileSync(path.join(ppath, 'app.yaml'), 'utf-8'));
18
+ if (!existsSync(ppath)) return null;
19
+ if (!dpath) {
20
+ dpath = config.entry;
21
+ }
22
+ if(config.private == true) return null;
23
+ const pepath = path.join(ppath, dpath);
24
+ if(Array.isArray(config.private)){
25
+ if(config.private.find(f => pepath == path.join(ppath, f))) return null;
26
+ }
27
+ if (existsSync(pepath)) return pepath;
28
+ else return null;
29
+ };
25
30
 
26
31
  module.exports.imp = function (runPath, context) {
27
- return function (filename, options = {}) {
28
- if (!options) options = {};
29
- let type = options.type || "coffee";
30
- let exports,
31
- ispkg = findPackage(filename);
32
+ return function (filename, options = {}) {
33
+ if (!options) options = {};
34
+ let type = options.type || 'coffee';
35
+ let exports,
36
+ ispkg = findPackage(filename);
32
37
 
33
- let filepath = path.resolve(path.dirname(context.module.filepath), filename);
38
+ if (filename.startsWith('@') && context.app) {
39
+ filename = filename.replace('@', context.app.path);
40
+ }
34
41
 
35
- // console.log(typeof runPath);
42
+ let filepath = path.resolve(path.dirname(context.module.filepath), filename);
36
43
 
37
- const lookUp = () => {
38
- const otherPath = lookUpInOtherApps(filename);
39
- if (!otherPath) throw new Error('Module "' + filename + '" not found');
40
- else filepath = otherPath;
41
- }
44
+ // console.log(typeof runPath);
42
45
 
43
- const foundCache = cachedFiles.find(f => f.filepath == filepath);
46
+ const lookUp = () => {
47
+ const otherPath = lookUpInOtherApps(filename);
48
+ if (!otherPath) throw new Error('Module "' + filename + '" not found');
49
+ else filepath = otherPath;
50
+ };
44
51
 
45
- if (!ispkg && foundCache) {
46
- exports = foundCache.exports;
47
- }
52
+ const foundCache = cachedFiles.find((f) => f.filepath == filepath);
48
53
 
49
- 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 || '')));
52
- if (resolve) {
53
- filepath += typeof resolve == "string" ? resolve : resolve.ext;
54
- if (typeof resolve == "object" && resolve.options) {
55
- if (resolve.options.type) type = resolve.options.type;
56
- for (let i in resolve.options) options[i] = resolve.options[i];
57
- }
58
- } else lookUp();
59
- } else lookUp();
60
- }
54
+ if (!ispkg && foundCache) {
55
+ exports = foundCache.exports;
56
+ }
61
57
 
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;
58
+ if (!ispkg && !existsSync(filepath)) {
59
+ if (Array.isArray(execOptions.resolveExtensions) && execOptions.resolveExtensions.length) {
60
+ const resolve = execOptions.resolveExtensions.find((ext) =>
61
+ typeof ext == 'string' ? existsSync(filepath + ext) : existsSync(filepath + (ext.ext || '')),
62
+ );
63
+ if (resolve) {
64
+ filepath += typeof resolve == 'string' ? resolve : resolve.ext;
65
+ if (typeof resolve == 'object' && resolve.options) {
66
+ if (resolve.options.type) type = resolve.options.type;
67
+ for (let i in resolve.options) options[i] = resolve.options[i];
68
+ }
69
+ } else lookUp();
70
+ } else lookUp();
71
+ }
75
72
 
76
- if (ispkg) {
77
- exports = getPackage(filename)(context);
78
- } else if (foundCache) {
73
+ const exec = (coptions = {}) =>
74
+ runPath(
75
+ filepath,
76
+ {
77
+ import: options,
78
+ main: false,
79
+ useContext: execOptions.sharedContext == false ? false : !(options.context && options.context == 'new'),
80
+ ...coptions,
81
+ as: options.as == 'main' ? (context.module.main ? 'main' : 'parent') : options.as == 'parent' ? 'parent' : 'child',
82
+ fromMain: context.module.main,
83
+ },
84
+ execOptions.sharedContext == false ? {} : options.context && options.context == 'new' ? {} : context,
85
+ ).context.module.exports;
79
86
 
80
- } else if (type == "coffee") {
81
- exports = exec({});
82
- } else if (type == "js") {
83
- exports = exec({ compile: false });
84
- } else if (type == "yaml" || type == "json" || type == "text") {
85
- const f = getFile(filepath);
86
- if (type == "yaml") {
87
- exports = importYaml(f.path, f);
88
- } else if (type == "json") {
89
- try {
90
- exports = JSON.parse(f.content);
91
- } catch (e) {
92
- exports = {};
93
- }
94
- } else {
95
- exports = f.content;
96
- }
97
- }
87
+ if (ispkg) {
88
+ const pkg = getPackage(filename)(context);
89
+ exports = pkg._onImport ? pkg._onImport() : pkg;
90
+ } else if (foundCache) {
91
+ } else if (type == 'coffee') {
92
+ exports = exec({});
93
+ } else if (type == 'js') {
94
+ exports = exec({ compile: false });
95
+ } else if (type == 'yaml' || type == 'json' || type == 'text') {
96
+ const f = getFile(filepath);
97
+ if (type == 'yaml') {
98
+ exports = importYaml(f.path, f);
99
+ } else if (type == 'json') {
100
+ try {
101
+ exports = JSON.parse(f.content);
102
+ } catch (e) {
103
+ exports = {};
104
+ }
105
+ } else {
106
+ exports = f.content;
107
+ }
108
+ }
98
109
 
99
- if (options.save && (type == "js" || type == "coffee")) {
100
- if (typeof options.save == "string") context[options.save] = exports[i];
101
- else
102
- for (let i in exports) {
103
- context[i] = exports[i];
104
- }
105
- }
110
+ if (options.save && (type == 'js' || type == 'coffee')) {
111
+ if (typeof options.save == 'string') context[options.save] = exports[i];
112
+ else
113
+ for (let i in exports) {
114
+ context[i] = exports[i];
115
+ }
116
+ }
106
117
 
107
- if (!ispkg) context.module.imports.push(filepath);
108
- if (!ispkg) cachedFiles.push({ filepath, exports });
118
+ if (!ispkg) context.module.imports.push(filepath);
119
+ if (!ispkg) cachedFiles.push({ filepath, exports });
109
120
 
110
- return exports;
111
- };
121
+ return exports;
122
+ };
112
123
  };
@@ -1,17 +1,14 @@
1
-
2
-
3
-
4
1
  module.exports.map = function map(...args) {
5
- if (args.length % 2 !== 0) {
6
- throw new Error('Arguments must be in key-value pairs');
7
- }
8
-
9
- const result = new Map();
10
- for (let i = 0; i < args.length; i += 2) {
11
- const key = args[i];
12
- const value = args[i + 1];
13
- result.set(key, value);
14
- }
15
-
16
- return result;
17
- };
2
+ if (args.length % 2 !== 0) {
3
+ throw new Error('Arguments must be in key-value pairs');
4
+ }
5
+
6
+ const result = new Map();
7
+ for (let i = 0; i < args.length; i += 2) {
8
+ const key = args[i];
9
+ const value = args[i + 1];
10
+ result.set(key, value);
11
+ }
12
+
13
+ return result;
14
+ };
@@ -1,34 +1,43 @@
1
-
2
- const SerializableData = ["string", "number", "boolean"];
1
+ const SerializableData = ['string', 'number', 'boolean'];
3
2
 
4
3
  const isRegExp = (obj) => Object.prototype.toString.call(obj) === '[object RegExp]';
5
4
 
6
5
  module.exports.match = function match(value, templates, props) {
7
- const matchProps = (pattern, value) => {
8
- if (!props) return false;
9
- if (typeof props === "object") {
10
- let t = true;
11
- for (let i in props) {
12
- t = t && pattern[i] == value[i];
13
- if (!t) break;
14
- }
15
- return t;
16
- } else if (typeof props === "function") {
17
- return props(pattern, value);
18
- } else {
19
- return false;
20
- }
21
- };
6
+ const matchProps = (pattern, value) => {
7
+ if (!props) return false;
8
+ if (typeof props === 'object') {
9
+ let t = true;
10
+ for (let i in props) {
11
+ t = t && pattern[i] == value[i];
12
+ if (!t) break;
13
+ }
14
+ return t;
15
+ } else if (typeof props === 'function') {
16
+ return props(pattern, value);
17
+ } else {
18
+ return false;
19
+ }
20
+ };
22
21
 
23
- const matchRegex = (pattern, value) => pattern.test(value);
22
+ const matchRegex = (pattern, value) => pattern.test(value);
24
23
 
25
- const entries = templates instanceof Map ? templates.entries() : Array.isArray(templates) ? templates : Object.entries(templates);
24
+ const entries = templates instanceof Map ? templates.entries() : Array.isArray(templates) ? templates : Object.entries(templates);
26
25
 
27
- 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)))) {
29
- return callback(...(isRegExp(pattern) ? pattern.exec(value) : [value]));
30
- }
31
- }
26
+ for (const [pattern, callback] of entries) {
27
+ if (
28
+ isRegExp(pattern)
29
+ ? matchRegex(pattern, value)
30
+ : SerializableData.includes(typeof value)
31
+ ? pattern == value
32
+ : isRegExp(pattern)
33
+ ? matchRegex(pattern, value)
34
+ : typeof pattern === 'function'
35
+ ? value instanceof pattern || value?.__proto__?.['@instance'] === pattern
36
+ : matchProps(pattern, value)
37
+ ) {
38
+ return callback(...(isRegExp(pattern) ? pattern.exec(value) : [value]));
39
+ }
40
+ }
32
41
 
33
- return null;
34
- };
42
+ return null;
43
+ };
@@ -1,13 +1,13 @@
1
1
  const path = require('path');
2
2
 
3
3
  module.exports = (currentFile) => {
4
- const e = {};
5
- e.basename = (pathname, suffix) => path.basename(pathname, suffix);
6
- e.dirname = (pathname) => path.dirname(pathname);
7
- e.extname = (pathname) => path.extname(pathname);
4
+ const e = {};
5
+ e.basename = (pathname, suffix) => path.basename(pathname, suffix);
6
+ e.dirname = (pathname) => path.dirname(pathname);
7
+ e.extname = (pathname) => path.extname(pathname);
8
8
 
9
- e.pjoin = (...paths) => path.join(...paths);
10
- e.presolve = (...paths) => path.resolve(...paths);
9
+ e.pjoin = (...paths) => path.join(...paths);
10
+ e.presolve = (...paths) => path.resolve(...paths);
11
11
 
12
- return e;
13
- }
12
+ return e;
13
+ };
@@ -1,41 +1,40 @@
1
1
  const fs = require('fs');
2
2
  const path = require('path');
3
3
 
4
-
5
4
  module.exports.customRequire = function customRequire(modulePath, filePath) {
6
- const resolvedPath = resolveModulePath(modulePath, filePath);
7
- return require(resolvedPath);
8
- }
5
+ const resolvedPath = resolveModulePath(modulePath, filePath);
6
+ return require(resolvedPath);
7
+ };
9
8
 
10
9
  function resolveModulePath(modulePath, filePath) {
11
- if (modulePath.startsWith('./') || modulePath.startsWith('../') || path.isAbsolute(modulePath)) {
12
- return path.resolve(modulePath);
13
- }
10
+ if (modulePath.startsWith('./') || modulePath.startsWith('../') || path.isAbsolute(modulePath)) {
11
+ return path.resolve(modulePath);
12
+ }
14
13
 
15
- const paths = module.constructor._nodeModulePaths(path.dirname(filePath));
16
- for (const basePath of paths) {
17
- const fullPath = path.join(basePath, modulePath);
18
- if (fs.existsSync(fullPath + '.js')) {
19
- return fullPath + '.js';
20
- }
21
- if (fs.existsSync(fullPath + '.json')) {
22
- return fullPath + '.json';
23
- }
24
- if (fs.existsSync(fullPath) && fs.statSync(fullPath).isDirectory()) {
25
- const packageJsonPath = path.join(fullPath, 'package.json');
26
- if (fs.existsSync(packageJsonPath)) {
27
- const main = require(packageJsonPath).main || 'index.js';
28
- const mainPath = path.join(fullPath, main);
29
- if (fs.existsSync(mainPath)) {
30
- return mainPath;
31
- }
32
- }
33
- const indexPath = path.join(fullPath, 'index.js');
34
- if (fs.existsSync(indexPath)) {
35
- return indexPath;
36
- }
37
- }
38
- }
14
+ const paths = module.constructor._nodeModulePaths(path.dirname(filePath));
15
+ for (const basePath of paths) {
16
+ const fullPath = path.join(basePath, modulePath);
17
+ if (fs.existsSync(fullPath + '.js')) {
18
+ return fullPath + '.js';
19
+ }
20
+ if (fs.existsSync(fullPath + '.json')) {
21
+ return fullPath + '.json';
22
+ }
23
+ if (fs.existsSync(fullPath) && fs.statSync(fullPath).isDirectory()) {
24
+ const packageJsonPath = path.join(fullPath, 'package.json');
25
+ if (fs.existsSync(packageJsonPath)) {
26
+ const main = require(packageJsonPath).main || 'index.js';
27
+ const mainPath = path.join(fullPath, main);
28
+ if (fs.existsSync(mainPath)) {
29
+ return mainPath;
30
+ }
31
+ }
32
+ const indexPath = path.join(fullPath, 'index.js');
33
+ if (fs.existsSync(indexPath)) {
34
+ return indexPath;
35
+ }
36
+ }
37
+ }
39
38
 
40
- throw new Error(`Cannot find module '${modulePath}'`);
41
- }
39
+ throw new Error(`Cannot find module '${modulePath}'`);
40
+ }
@@ -1,5 +1,5 @@
1
- const future = require("./future");
1
+ const future = require('./future');
2
2
 
3
3
  module.exports = async function sleep(time) {
4
- return new Promise((r) => setTimeout(r, time));
4
+ return new Promise((r) => setTimeout(r, time));
5
5
  };
@@ -1,30 +1,30 @@
1
1
  const { execSync, spawnSync } = require('child_process');
2
2
  const fs = require('fs');
3
3
 
4
- const print = module.exports.print = function print(...arguments) {
5
- return console.log(...arguments);
6
- };
4
+ const print = (module.exports.print = function print(...arguments) {
5
+ return console.log(...arguments);
6
+ });
7
7
 
8
8
  print.stdout = process.stdout;
9
9
  print.stdin = process.stdin;
10
10
 
11
11
  module.exports.input = function input(prompt) {
12
- process.stdout.write(prompt);
12
+ process.stdout.write(prompt);
13
+
14
+ let cmd;
15
+ let args;
16
+ if ('null' == 'win32') {
17
+ cmd = 'cmd';
18
+ args = ['/V:ON', '/C', 'set /p response= && echo !response!'];
19
+ } else {
20
+ cmd = 'bash';
21
+ args = ['-c', 'read response; echo "$response"'];
22
+ }
13
23
 
14
- let cmd;
15
- let args;
16
- if ("null" == "win32") {
17
- cmd = 'cmd';
18
- args = ['/V:ON', '/C', 'set /p response= && echo !response!'];
19
- } else {
20
- cmd = 'bash';
21
- args = ['-c', 'read response; echo "$response"'];
22
- }
24
+ let opts = {
25
+ stdio: ['inherit', 'pipe'],
26
+ shell: false,
27
+ };
23
28
 
24
- let opts = {
25
- stdio: ['inherit', 'pipe'],
26
- shell: false,
27
- };
28
-
29
- return spawnSync(cmd, args, opts).stdout.toString().trim();
30
- }
29
+ return spawnSync(cmd, args, opts).stdout.toString().trim();
30
+ };