@makano/rew 1.1.73 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. package/lib/coffeescript/browser.js +144 -139
  2. package/lib/coffeescript/cake.js +132 -133
  3. package/lib/coffeescript/coffeescript.js +437 -381
  4. package/lib/coffeescript/command.js +806 -724
  5. package/lib/coffeescript/grammar.js +1908 -2474
  6. package/lib/coffeescript/helpers.js +509 -473
  7. package/lib/coffeescript/index.js +228 -215
  8. package/lib/coffeescript/lexer.js +2282 -1909
  9. package/lib/coffeescript/nodes.js +9782 -9202
  10. package/lib/coffeescript/optparse.js +255 -227
  11. package/lib/coffeescript/parser.js +20305 -1265
  12. package/lib/coffeescript/register.js +107 -87
  13. package/lib/coffeescript/repl.js +307 -284
  14. package/lib/coffeescript/rewriter.js +1389 -1079
  15. package/lib/coffeescript/scope.js +176 -172
  16. package/lib/coffeescript/sourcemap.js +242 -227
  17. package/lib/rew/cli/cli.js +288 -186
  18. package/lib/rew/cli/log.js +31 -32
  19. package/lib/rew/cli/run.js +10 -12
  20. package/lib/rew/cli/utils.js +344 -176
  21. package/lib/rew/const/config_path.js +4 -0
  22. package/lib/rew/const/default.js +38 -35
  23. package/lib/rew/const/files.js +9 -9
  24. package/lib/rew/const/opt.js +8 -8
  25. package/lib/rew/css/theme.css +2 -2
  26. package/lib/rew/functions/core.js +55 -57
  27. package/lib/rew/functions/curl.js +23 -0
  28. package/lib/rew/functions/emitter.js +52 -55
  29. package/lib/rew/functions/exec.js +25 -21
  30. package/lib/rew/functions/export.js +18 -20
  31. package/lib/rew/functions/fs.js +55 -54
  32. package/lib/rew/functions/future.js +29 -21
  33. package/lib/rew/functions/id.js +8 -9
  34. package/lib/rew/functions/import.js +107 -93
  35. package/lib/rew/functions/map.js +13 -16
  36. package/lib/rew/functions/match.js +35 -26
  37. package/lib/rew/functions/path.js +8 -8
  38. package/lib/rew/functions/require.js +32 -33
  39. package/lib/rew/functions/sleep.js +2 -2
  40. package/lib/rew/functions/stdout.js +20 -20
  41. package/lib/rew/functions/types.js +96 -95
  42. package/lib/rew/html/ui.html +12 -13
  43. package/lib/rew/html/ui.js +205 -168
  44. package/lib/rew/main.js +14 -14
  45. package/lib/rew/misc/bin.js +37 -0
  46. package/lib/rew/misc/findAppInfo.js +16 -0
  47. package/lib/rew/misc/findAppPath.js +21 -0
  48. package/lib/rew/misc/req.js +7 -0
  49. package/lib/rew/misc/seededid.js +13 -0
  50. package/lib/rew/models/enum.js +12 -12
  51. package/lib/rew/models/struct.js +30 -32
  52. package/lib/rew/modules/compiler.js +237 -177
  53. package/lib/rew/modules/context.js +35 -22
  54. package/lib/rew/modules/fs.js +10 -10
  55. package/lib/rew/modules/runtime.js +17 -21
  56. package/lib/rew/modules/yaml.js +27 -30
  57. package/lib/rew/pkgs/conf.js +82 -75
  58. package/lib/rew/pkgs/data.js +12 -7
  59. package/lib/rew/pkgs/date.js +27 -28
  60. package/lib/rew/pkgs/env.js +6 -8
  61. package/lib/rew/pkgs/modules/data/bintree.js +52 -52
  62. package/lib/rew/pkgs/modules/data/doublylinked.js +85 -85
  63. package/lib/rew/pkgs/modules/data/linkedList.js +73 -73
  64. package/lib/rew/pkgs/modules/data/queue.js +19 -20
  65. package/lib/rew/pkgs/modules/data/stack.js +19 -19
  66. package/lib/rew/pkgs/modules/threads/worker.js +36 -26
  67. package/lib/rew/pkgs/modules/ui/classes.js +182 -178
  68. package/lib/rew/pkgs/pkgs.js +9 -10
  69. package/lib/rew/pkgs/rune.js +400 -0
  70. package/lib/rew/pkgs/threads.js +57 -53
  71. package/lib/rew/pkgs/ui.js +148 -136
  72. package/lib/rew/qrew/compile.js +12 -0
  73. package/package.json +11 -4
@@ -1,10 +1,10 @@
1
1
  const execOptions = {
2
- sharedContext: true,
3
- resolveExtensions: [{ext: '.js', options: { type: 'js' }}, '.coffee'],
4
- nativeRequire: false,
5
- cwdAlias: '$',
6
- jsxPragma: 'createElement',
7
- jsx: false
8
- }
2
+ sharedContext: true,
3
+ resolveExtensions: [{ ext: '.js', options: { type: 'js' } }, { ext: '.qrew', options: { qrew: true } }, '.coffee'],
4
+ nativeRequire: false,
5
+ cwdAlias: '$',
6
+ jsxPragma: 'createElement',
7
+ jsx: false,
8
+ };
9
9
 
10
- module.exports.execOptions = execOptions;
10
+ module.exports.execOptions = execOptions;
@@ -1,3 +1,3 @@
1
1
  body {
2
- background-color: #1c2541;
3
- }
2
+ background-color: #1c2541;
3
+ }
@@ -1,86 +1,84 @@
1
-
2
-
3
1
  function isEmpty(value) {
4
- if (Array.isArray(value) || typeof value === 'string') {
5
- return value.length === 0;
6
- } else if (typeof value === 'object') {
7
- return Object.keys(value).length === 0;
8
- } else {
9
- return true;
10
- }
2
+ if (Array.isArray(value) || typeof value === 'string') {
3
+ return value.length === 0;
4
+ } else if (typeof value === 'object') {
5
+ return Object.keys(value).length === 0;
6
+ } else {
7
+ return true;
8
+ }
11
9
  }
12
10
 
13
11
  function clone(value) {
14
- if (Array.isArray(value)) {
15
- return value.slice();
16
- } else if (typeof value === 'object') {
17
- return Object.assign({}, value);
18
- } else {
19
- return value;
20
- }
12
+ if (Array.isArray(value)) {
13
+ return value.slice();
14
+ } else if (typeof value === 'object') {
15
+ return Object.assign({}, value);
16
+ } else {
17
+ return value;
18
+ }
21
19
  }
22
20
 
23
21
  function deepClone(value) {
24
- if (Array.isArray(value)) {
25
- return value.map(item => deepClone(item));
26
- } else if (typeof value === 'object') {
27
- const obj = {};
28
- for (const key in value) {
29
- if (value.hasOwnProperty(key)) {
30
- obj[key] = deepClone(value[key]);
31
- }
32
- }
33
- return obj;
34
- } else {
35
- return value;
36
- }
22
+ if (Array.isArray(value)) {
23
+ return value.map((item) => deepClone(item));
24
+ } else if (typeof value === 'object') {
25
+ const obj = {};
26
+ for (const key in value) {
27
+ if (value.hasOwnProperty(key)) {
28
+ obj[key] = deepClone(value[key]);
29
+ }
30
+ }
31
+ return obj;
32
+ } else {
33
+ return value;
34
+ }
37
35
  }
38
36
 
39
37
  function merge(obj1, obj2) {
40
- return Object.assign({}, obj1, obj2);
38
+ return Object.assign({}, obj1, obj2);
41
39
  }
42
40
 
43
41
  const uniqueId = (() => {
44
- let id = 0;
45
- return () => {
46
- id += 1;
47
- return `id-${id}`;
48
- };
42
+ let id = 0;
43
+ return () => {
44
+ id += 1;
45
+ return `id-${id}`;
46
+ };
49
47
  })();
50
48
 
51
49
  function filter(arr, fn) {
52
- return arr.filter(fn);
50
+ return arr.filter(fn);
53
51
  }
54
52
 
55
53
  function reduce(arr, fn, initial) {
56
- return arr.reduce(fn, initial);
54
+ return arr.reduce(fn, initial);
57
55
  }
58
56
 
59
57
  function compose(...fns) {
60
- return initialValue => {
61
- return fns.reduceRight((acc, fn) => fn(acc), initialValue);
62
- };
58
+ return (initialValue) => {
59
+ return fns.reduceRight((acc, fn) => fn(acc), initialValue);
60
+ };
63
61
  }
64
62
 
65
63
  function curry(fn) {
66
- const curried = (...args) => {
67
- if (args.length >= fn.length) {
68
- return fn.apply(null, args);
69
- } else {
70
- return (...moreArgs) => curried.apply(null, args.concat(moreArgs));
71
- }
72
- };
73
- return curried;
64
+ const curried = (...args) => {
65
+ if (args.length >= fn.length) {
66
+ return fn.apply(null, args);
67
+ } else {
68
+ return (...moreArgs) => curried.apply(null, args.concat(moreArgs));
69
+ }
70
+ };
71
+ return curried;
74
72
  }
75
73
 
76
74
  module.exports = {
77
- isEmpty,
78
- clone,
79
- deepClone,
80
- merge,
81
- uniqueId,
82
- filter,
83
- reduce,
84
- compose,
85
- curry
75
+ isEmpty,
76
+ clone,
77
+ deepClone,
78
+ merge,
79
+ uniqueId,
80
+ filter,
81
+ reduce,
82
+ compose,
83
+ curry,
86
84
  };
@@ -0,0 +1,23 @@
1
+ const future = require("./future");
2
+ const fs = require('fs');
3
+
4
+ module.exports.curl = function curl(options, url){
5
+ if(typeof options == 'string'){
6
+ let newurl = options;
7
+ options = typeof url == "object" ? url : {};
8
+ url = newurl;
9
+ }
10
+ if(options.url && !url){
11
+ url = options.url
12
+ }
13
+ const method = options.x || "GET";
14
+ const f = future.promise(fetch(url, {
15
+ ...options,
16
+ method
17
+ }).then(async r => {
18
+ if(options.o) fs.writeFileSync(options.o, Buffer.from(await r.clone().arrayBuffer()));
19
+ return r;
20
+ }).then(r => options.json ? r.clone().json() : r));
21
+ if(options.a) return f.wait();
22
+ else return f;
23
+ }
@@ -1,57 +1,54 @@
1
1
  module.exports = function emitter() {
2
- const events = [];
3
- const on = (event, callback, props = {}) => {
4
- const addEvent = (event) => events.push({ ...props, event, callback });
5
- if (Array.isArray(event)) {
6
- event.forEach(addEvent);
7
- } else {
8
- addEvent(event);
9
- }
10
- return listener;
11
- };
12
- const off = (event, callback, removable = null) => {
13
- const rm = (event) => {
14
- if(removable){
15
- removable(event);
16
- }
17
- events.splice(events.indexOf(event), 1);
18
- }
19
- const rmEvent = (event) => {
20
- if (callback) {
21
- const _events = events.filter(({ callback: c }) => c == callback);
22
- _events.forEach((e) => {
23
- if (Array.isArray(event)) {
24
- if (event.includes(e.event)) rm(e);
25
- } else {
26
- if (e.event == event) rm(e);
27
- }
28
- });
29
- } else {
30
- const _events = events.filter(({ event: e }) => e == event);
31
- _events.forEach((e) => {
32
- rm(e);
33
- });
34
- }
35
- };
36
- if (Array.isArray(event)) {
37
- event.forEach(rmEvent);
38
- } else {
39
- rmEvent(event);
40
- }
41
- return listener;
42
- };
43
- const emit = (event, ...data) => {
44
- const emitEvent = (event) =>
45
- events
46
- .filter(({ event: e }) => e == event)
47
- .forEach(({ callback }) => callback(...data));
48
- if (Array.isArray(event)) {
49
- event.forEach(emitEvent);
50
- } else {
51
- emitEvent(event);
52
- }
53
- return listener;
54
- };
55
- const listener = { on, off, emit };
56
- return listener;
2
+ const events = [];
3
+ const on = (event, callback, props = {}) => {
4
+ const addEvent = (event) => events.push({ ...props, event, callback });
5
+ if (Array.isArray(event)) {
6
+ event.forEach(addEvent);
7
+ } else {
8
+ addEvent(event);
9
+ }
10
+ return listener;
11
+ };
12
+ const off = (event, callback, removable = null) => {
13
+ const rm = (event) => {
14
+ if (removable) {
15
+ removable(event);
16
+ }
17
+ events.splice(events.indexOf(event), 1);
18
+ };
19
+ const rmEvent = (event) => {
20
+ if (callback) {
21
+ const _events = events.filter(({ callback: c }) => c == callback);
22
+ _events.forEach((e) => {
23
+ if (Array.isArray(event)) {
24
+ if (event.includes(e.event)) rm(e);
25
+ } else {
26
+ if (e.event == event) rm(e);
27
+ }
28
+ });
29
+ } else {
30
+ const _events = events.filter(({ event: e }) => e == event);
31
+ _events.forEach((e) => {
32
+ rm(e);
33
+ });
34
+ }
35
+ };
36
+ if (Array.isArray(event)) {
37
+ event.forEach(rmEvent);
38
+ } else {
39
+ rmEvent(event);
40
+ }
41
+ return listener;
42
+ };
43
+ const emit = (event, ...data) => {
44
+ const emitEvent = (event) => events.filter(({ event: e }) => e == event).forEach(({ callback }) => callback(...data));
45
+ if (Array.isArray(event)) {
46
+ event.forEach(emitEvent);
47
+ } else {
48
+ emitEvent(event);
49
+ }
50
+ return listener;
51
+ };
52
+ const listener = { on, off, emit };
53
+ return listener;
57
54
  };
@@ -1,27 +1,31 @@
1
1
  const shell = require('child_process');
2
2
 
3
-
4
3
  module.exports = (currentFile) => {
4
+ function exec(command, options) {
5
+ return shell.execSync(command, {
6
+ stdio: options?.output == false ? null : 'inherit',
7
+ });
8
+ }
5
9
 
6
- function exec(command, options){
7
- return shell.execSync(command, { stdio: options?.output == false ? null : 'inherit' });
8
- }
9
-
10
- exec.background = function execAsync(command, options, callback){
11
- if(typeof options == "function" && !callback){
12
- callback = options;
13
- options = {};
14
- }
15
- if(!options) options = {};
16
- if(!callback) callback = () => {};
17
- return shell.exec(command, {
18
- ...options,
19
- }, callback);
20
- }
10
+ exec.background = function execAsync(command, options, callback) {
11
+ if (typeof options == 'function' && !callback) {
12
+ callback = options;
13
+ options = {};
14
+ }
15
+ if (!options) options = {};
16
+ if (!callback) callback = () => {};
17
+ return shell.exec(
18
+ command,
19
+ {
20
+ ...options,
21
+ },
22
+ callback,
23
+ );
24
+ };
21
25
 
22
- function spawn(command, options){
23
- return shell.spawn(command, options);
24
- }
26
+ function spawn(command, options) {
27
+ return shell.spawn(command, options);
28
+ }
25
29
 
26
- return { exec, spawn };
27
- }
30
+ return { exec, spawn };
31
+ };
@@ -1,27 +1,25 @@
1
-
2
- function exportsThe(item, name, context){
3
- if (name) {
4
- if(!context.module.exports) context.module.exports = {};
5
- context.module.exports[name] = item;
6
- } else {
7
- if(context.module.exports) context.module.exports.default = item;
8
- else context.module.exports = item;
9
- }
1
+ function exportsThe(item, name, context) {
2
+ if (name) {
3
+ if (!context.module.exports) context.module.exports = {};
4
+ context.module.exports[name] = item;
5
+ } else {
6
+ if (context.module.exports) context.module.exports.default = item;
7
+ else context.module.exports = item;
8
+ }
10
9
  }
11
10
 
12
11
  module.exports.pubFunction = function (context) {
13
- return function (name, item) {
14
- if(name && !item){
15
- item = name;
16
- name = null;
17
- }
18
- exportsThe(item, name, context);
19
- };
12
+ return function (name, item) {
13
+ if (name && !item) {
14
+ item = name;
15
+ name = null;
16
+ }
17
+ exportsThe(item, name, context);
18
+ };
20
19
  };
21
20
 
22
21
  module.exports.exportsFunction = function (context) {
23
- return function (item, name) {
24
- exportsThe(item, name, context);
25
- };
22
+ return function (item, name) {
23
+ exportsThe(item, name, context);
24
+ };
26
25
  };
27
-
@@ -2,58 +2,59 @@ const fs = require('fs');
2
2
  const path = require('path');
3
3
  const { execOptions } = require('../const/opt');
4
4
 
5
-
6
5
  module.exports = (currentFile) => {
7
-
8
- function gp(filepath){
9
- return path.resolve(filepath.startsWith(execOptions.cwdAlias) ? process.cwd() : path.dirname(currentFile), filepath.replaceAll(execOptions.cwdAlias+'/', ''));
10
- }
11
-
12
- function read(filepath, options = { encoding: 'utf-8' }){
13
- return fs.readFileSync(gp(filepath), options);
14
- }
15
-
16
- function realpath(filepath, options = { encoding: 'utf-8' }){
17
- return gp(filepath);
18
- }
19
-
20
- function write(filepath, content, options){
21
- return fs.writeFileSync(gp(filepath), content, options);
22
- }
23
-
24
- function exists(filepath, options){
25
- return fs.existsSync(gp(filepath));
26
- }
27
-
28
- function fstat(filepath, options){
29
- return fs.statSync(gp(filepath), options);
30
- }
31
-
32
- function rm(filepath, options){
33
- return fs.unlinkSync(filepath);
34
- }
35
-
36
- function chmod(filepath, mode, options){
37
- return fs.chmodSync(gp(filepath), mode);
38
- }
39
-
40
- function mkdir(filepath, options){
41
- return fs.mkdirSync(gp(filepath), options);
42
- }
43
-
44
- function ls(filepath, options){
45
- return fs.readdirSync(gp(filepath), options);
46
- }
47
-
48
- return {
49
- ls,
50
- mkdir,
51
- chmod,
52
- rm,
53
- fstat,
54
- exists,
55
- write,
56
- read,
57
- realpath
58
- };
59
- }
6
+ function gp(filepath) {
7
+ return path.resolve(
8
+ filepath.startsWith(execOptions.cwdAlias) ? process.cwd() : path.dirname(currentFile),
9
+ filepath.replaceAll(execOptions.cwdAlias + '/', ''),
10
+ );
11
+ }
12
+
13
+ function read(filepath, options = { encoding: 'utf-8' }) {
14
+ return fs.readFileSync(gp(filepath), options);
15
+ }
16
+
17
+ function realpath(filepath, options = { encoding: 'utf-8' }) {
18
+ return gp(filepath);
19
+ }
20
+
21
+ function write(filepath, content, options) {
22
+ return fs.writeFileSync(gp(filepath), content, options);
23
+ }
24
+
25
+ function exists(filepath, options) {
26
+ return fs.existsSync(gp(filepath));
27
+ }
28
+
29
+ function fstat(filepath, options) {
30
+ return fs.statSync(gp(filepath), options);
31
+ }
32
+
33
+ function rm(filepath, options) {
34
+ return fs.unlinkSync(filepath);
35
+ }
36
+
37
+ function chmod(filepath, mode, options) {
38
+ return fs.chmodSync(gp(filepath), mode);
39
+ }
40
+
41
+ function mkdir(filepath, options) {
42
+ return fs.mkdirSync(gp(filepath), options);
43
+ }
44
+
45
+ function ls(filepath, options) {
46
+ return fs.readdirSync(gp(filepath), options);
47
+ }
48
+
49
+ return {
50
+ ls,
51
+ mkdir,
52
+ chmod,
53
+ rm,
54
+ fstat,
55
+ exists,
56
+ write,
57
+ read,
58
+ realpath,
59
+ };
60
+ };
@@ -1,23 +1,31 @@
1
- const emitter = require("./emitter");
1
+ const emitter = require('./emitter');
2
2
 
3
- module.exports = function future(callback, timeout = 0, defData = null) {
4
- const listener = emitter();
5
- const promise = new Promise((resolve, reject) => {
6
- listener.on("resolve", (data) => {
7
- resolve(data);
8
- });
9
- listener.on("reject", (data) => {
10
- reject(data);
11
- });
12
- callback(resolve, reject);
13
- if (timeout) setTimeout(() => resolve(defData), timeout);
14
- });
15
- return {
16
- pipe: (callback) => promise.then(callback),
17
- last: (callback) => promise.finally(callback),
18
- catch: (callback) => promise.catch(callback),
19
- resolve: (data) => listener.emit("resolve", data),
20
- reject: (data) => listener.emit("reject", data),
21
- wait: async () => await promise
22
- };
3
+ function future(callback, timeout = 0, defData = null) {
4
+ const listener = emitter();
5
+ const promise = new Promise((resolve, reject) => {
6
+ listener.on('resolve', (data) => {
7
+ resolve(data);
8
+ });
9
+ listener.on('reject', (data) => {
10
+ reject(data);
11
+ });
12
+ callback(resolve, reject);
13
+ if (timeout) setTimeout(() => resolve(defData), timeout);
14
+ });
15
+ return {
16
+ pipe: (callback) => promise.then(callback),
17
+ last: (callback) => promise.finally(callback),
18
+ catch: (callback) => promise.catch(callback),
19
+ resolve: (data) => listener.emit('resolve', data),
20
+ reject: (data) => listener.emit('reject', data),
21
+ wait: async () => await promise,
22
+ };
23
23
  };
24
+
25
+ future.promise = (promse, timeout = 0, defData = null) => {
26
+ return future((resolve, reject) => {
27
+ promse.then(resolve).catch(reject);
28
+ }, timeout, defData);
29
+ }
30
+
31
+ module.exports = future;
@@ -1,13 +1,12 @@
1
1
  module.exports.generateRandomID = function generateRandomID(length = 12) {
2
- const characters =
3
- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
4
- const charactersLength = characters.length;
5
- let randomID = "";
2
+ const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
3
+ const charactersLength = characters.length;
4
+ let randomID = '';
6
5
 
7
- for (let i = 0; i < length; i++) {
8
- const randomIndex = Math.floor(Math.random() * charactersLength);
9
- randomID += characters.charAt(randomIndex);
10
- }
6
+ for (let i = 0; i < length; i++) {
7
+ const randomIndex = Math.floor(Math.random() * charactersLength);
8
+ randomID += characters.charAt(randomIndex);
9
+ }
11
10
 
12
- return randomID;
11
+ return randomID;
13
12
  };