@makano/rew 1.1.81 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/coffeescript/browser.js +144 -139
- package/lib/coffeescript/cake.js +132 -133
- package/lib/coffeescript/coffeescript.js +437 -381
- package/lib/coffeescript/command.js +806 -724
- package/lib/coffeescript/grammar.js +1908 -2474
- package/lib/coffeescript/helpers.js +509 -473
- package/lib/coffeescript/index.js +228 -215
- package/lib/coffeescript/lexer.js +2282 -1909
- package/lib/coffeescript/nodes.js +9782 -9202
- package/lib/coffeescript/optparse.js +255 -227
- package/lib/coffeescript/parser.js +20305 -1265
- package/lib/coffeescript/register.js +107 -87
- package/lib/coffeescript/repl.js +307 -284
- package/lib/coffeescript/rewriter.js +1389 -1079
- package/lib/coffeescript/scope.js +176 -172
- package/lib/coffeescript/sourcemap.js +242 -227
- package/lib/rew/cli/cli.js +312 -239
- package/lib/rew/cli/log.js +27 -27
- package/lib/rew/cli/run.js +8 -8
- package/lib/rew/cli/utils.js +368 -199
- package/lib/rew/const/config_path.js +2 -2
- package/lib/rew/const/default.js +38 -53
- package/lib/rew/const/files.js +11 -14
- package/lib/rew/const/opt.js +6 -6
- package/lib/rew/css/theme.css +1 -1
- package/lib/rew/functions/core.js +55 -55
- package/lib/rew/functions/curl.js +23 -0
- package/lib/rew/functions/emitter.js +52 -55
- package/lib/rew/functions/exec.js +25 -25
- package/lib/rew/functions/export.js +17 -17
- package/lib/rew/functions/fs.js +57 -59
- package/lib/rew/functions/future.js +29 -21
- package/lib/rew/functions/id.js +8 -9
- package/lib/rew/functions/import.js +106 -122
- package/lib/rew/functions/map.js +10 -10
- package/lib/rew/functions/match.js +35 -42
- package/lib/rew/functions/path.js +8 -8
- package/lib/rew/functions/require.js +32 -36
- package/lib/rew/functions/sleep.js +2 -2
- package/lib/rew/functions/stdout.js +18 -18
- package/lib/rew/functions/types.js +82 -106
- package/lib/rew/html/ui.html +12 -12
- package/lib/rew/html/ui.js +196 -201
- package/lib/rew/main.js +14 -14
- package/lib/rew/misc/bin.js +37 -0
- package/lib/rew/misc/findAppInfo.js +13 -13
- package/lib/rew/misc/findAppPath.js +15 -15
- package/lib/rew/misc/req.js +7 -0
- package/lib/rew/misc/seededid.js +8 -8
- package/lib/rew/models/enum.js +12 -12
- package/lib/rew/models/struct.js +30 -32
- package/lib/rew/modules/compiler.js +237 -209
- package/lib/rew/modules/fs.js +10 -10
- package/lib/rew/modules/runtime.js +17 -21
- package/lib/rew/modules/yaml.js +27 -30
- package/lib/rew/pkgs/conf.js +82 -92
- package/lib/rew/pkgs/data.js +10 -10
- package/lib/rew/pkgs/date.js +27 -27
- package/lib/rew/pkgs/env.js +5 -5
- package/lib/rew/pkgs/modules/data/bintree.js +51 -51
- package/lib/rew/pkgs/modules/data/doublylinked.js +84 -84
- package/lib/rew/pkgs/modules/data/linkedList.js +72 -72
- package/lib/rew/pkgs/modules/data/queue.js +18 -18
- package/lib/rew/pkgs/modules/data/stack.js +18 -18
- package/lib/rew/pkgs/modules/threads/worker.js +36 -36
- package/lib/rew/pkgs/modules/ui/classes.js +181 -184
- package/lib/rew/pkgs/pkgs.js +9 -9
- package/lib/rew/pkgs/rune.js +373 -410
- package/lib/rew/pkgs/threads.js +62 -66
- package/lib/rew/pkgs/ui.js +148 -160
- package/lib/rew/qrew/compile.js +12 -0
- package/package.json +4 -3
package/lib/rew/modules/yaml.js
CHANGED
@@ -1,36 +1,33 @@
|
|
1
|
-
const yaml = require(
|
2
|
-
const path = require(
|
3
|
-
const { getFile } = require(
|
1
|
+
const yaml = require('js-yaml');
|
2
|
+
const path = require('path');
|
3
|
+
const { getFile } = require('./fs');
|
4
4
|
|
5
5
|
function yamlFile(file) {
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
6
|
+
const schema = new yaml.Schema([
|
7
|
+
new yaml.Type('!import', {
|
8
|
+
kind: 'scalar',
|
9
|
+
construct: (p) => importYaml(path.resolve(path.dirname(file.path), p)),
|
10
|
+
}),
|
11
|
+
new yaml.Type('!int', {
|
12
|
+
kind: 'scalar',
|
13
|
+
construct: (data) => parseInt(data),
|
14
|
+
}),
|
15
|
+
new yaml.Type('!float', {
|
16
|
+
kind: 'scalar',
|
17
|
+
construct: (data) => parseFloat(data),
|
18
|
+
}),
|
19
|
+
new yaml.Type('!bool', {
|
20
|
+
kind: 'scalar',
|
21
|
+
construct: (data) => (data == 'true' ? true : false),
|
22
|
+
}),
|
23
|
+
]);
|
24
24
|
|
25
|
-
|
25
|
+
return yaml.load(file.content, { schema });
|
26
26
|
}
|
27
27
|
|
28
|
-
const importYaml = (module.exports.importYaml = function importYaml(
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
file = getFile(filepath);
|
34
|
-
}
|
35
|
-
return yamlFile(file);
|
28
|
+
const importYaml = (module.exports.importYaml = function importYaml(filepath, file) {
|
29
|
+
if (!file) {
|
30
|
+
file = getFile(filepath);
|
31
|
+
}
|
32
|
+
return yamlFile(file);
|
36
33
|
});
|
package/lib/rew/pkgs/conf.js
CHANGED
@@ -1,109 +1,99 @@
|
|
1
|
-
const fs = require(
|
2
|
-
const jsYaml = require(
|
3
|
-
const path = require(
|
4
|
-
const { CONFIG_PATH } = require(
|
5
|
-
const { seededID } = require(
|
1
|
+
const fs = require('fs');
|
2
|
+
const jsYaml = require('js-yaml');
|
3
|
+
const path = require('path');
|
4
|
+
const { CONFIG_PATH } = require('../const/config_path');
|
5
|
+
const { seededID } = require('../misc/seededid');
|
6
6
|
|
7
7
|
const createPackageRoot = (packageName) => {
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
const rootPath = path.join(CONFIG_PATH, packageName);
|
9
|
+
fs.mkdirSync(rootPath, { recursive: true });
|
10
|
+
return rootPath;
|
11
11
|
};
|
12
12
|
|
13
13
|
module.exports = (context) => ({
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
}
|
25
|
-
},
|
26
|
-
create: (packageName) => {
|
27
|
-
const rootPath = createPackageRoot(packageName);
|
14
|
+
CONFIG_PATH,
|
15
|
+
_onImport() {
|
16
|
+
if (context.app) {
|
17
|
+
return this.create(context.app.config.package);
|
18
|
+
} else {
|
19
|
+
return this.create(seededID(path.basename(context.module.filepath).replace(/[-_/\.]/g, '')));
|
20
|
+
}
|
21
|
+
},
|
22
|
+
create: (packageName) => {
|
23
|
+
const rootPath = createPackageRoot(packageName);
|
28
24
|
|
29
|
-
|
25
|
+
const conf = {};
|
30
26
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
27
|
+
const dumpYaml = (val) => {
|
28
|
+
if (JSON.stringify(val) == '{}') return '';
|
29
|
+
else return jsYaml.dump(val);
|
30
|
+
};
|
35
31
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
32
|
+
const setData = (optionCenter, key, value) => {
|
33
|
+
conf[optionCenter.name][key] = value;
|
34
|
+
fs.writeFileSync(optionCenter.root, dumpYaml(conf[optionCenter.name]));
|
35
|
+
return true;
|
36
|
+
};
|
41
37
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
38
|
+
const removeData = (optionCenter, key) => {
|
39
|
+
delete conf[optionCenter.name][key];
|
40
|
+
fs.writeFileSync(optionCenter.root, dumpYaml(conf[optionCenter.name]));
|
41
|
+
return true;
|
42
|
+
};
|
47
43
|
|
48
|
-
|
49
|
-
|
50
|
-
|
44
|
+
const getData = (optionCenter, key) => {
|
45
|
+
return conf[optionCenter.name][key];
|
46
|
+
};
|
51
47
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
};
|
48
|
+
const staticFile = (name, defaultValue = '') => {
|
49
|
+
const fileRoot = path.join(rootPath, name);
|
50
|
+
const exists = fs.existsSync(fileRoot);
|
51
|
+
return {
|
52
|
+
create(value) {
|
53
|
+
if (!fs.existsSync(path.dirname(fileRoot))) fs.mkdirSync(path.dirname(fileRoot), { recursive: true });
|
54
|
+
fs.writeFileSync(fileRoot, value || defaultValue);
|
55
|
+
},
|
56
|
+
fileRoot,
|
57
|
+
exists,
|
58
|
+
};
|
59
|
+
};
|
65
60
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
fs.readFileSync(optionRoot, { encoding: "utf-8" }),
|
76
|
-
);
|
77
|
-
}
|
61
|
+
const createOptionCenter = (name, defaults = {}) => {
|
62
|
+
const optionRoot = path.join(rootPath, name + '.yaml');
|
63
|
+
if (!fs.existsSync(path.dirname(optionRoot))) fs.mkdirSync(path.dirname(optionRoot), { recursive: true });
|
64
|
+
if (!fs.existsSync(optionRoot)) {
|
65
|
+
conf[name] = defaults;
|
66
|
+
fs.writeFileSync(optionRoot, dumpYaml(defaults));
|
67
|
+
} else {
|
68
|
+
conf[name] = jsYaml.load(fs.readFileSync(optionRoot, { encoding: 'utf-8' }));
|
69
|
+
}
|
78
70
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
71
|
+
const optionCenter = {
|
72
|
+
root: optionRoot,
|
73
|
+
name,
|
74
|
+
package: packageName,
|
75
|
+
};
|
84
76
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
};
|
95
|
-
};
|
77
|
+
return {
|
78
|
+
get: (key, defaultValue) => getData(optionCenter, key) || defaultValue,
|
79
|
+
set: (key, value) => setData(optionCenter, key, value),
|
80
|
+
remove: (key) => removeData(optionCenter, key),
|
81
|
+
reset: () => fs.writeFileSync(optionCenter.root, dumpYaml(defaults)) && (conf[name] = defaults),
|
82
|
+
getAll: (str = false) => (str ? dumpYaml(conf[name]) : conf[name]),
|
83
|
+
...optionCenter,
|
84
|
+
};
|
85
|
+
};
|
96
86
|
|
97
|
-
|
87
|
+
const defaultCenter = createOptionCenter('_default', { default: true });
|
98
88
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
89
|
+
return {
|
90
|
+
optionCenter: createOptionCenter,
|
91
|
+
staticFile: staticFile,
|
92
|
+
set: (key, value) => defaultCenter.set(key, value),
|
93
|
+
get: (key, defaultValue) => defaultCenter.get(key, defaultValue),
|
94
|
+
remove: (key) => defaultCenter.remove(key),
|
95
|
+
root: rootPath,
|
96
|
+
package: packageName,
|
97
|
+
};
|
98
|
+
},
|
109
99
|
});
|
package/lib/rew/pkgs/data.js
CHANGED
@@ -1,13 +1,13 @@
|
|
1
|
-
const { BinaryTree } = require(
|
2
|
-
const { DoublyLinkedList } = require(
|
3
|
-
const { LinkedList } = require(
|
4
|
-
const { Queue } = require(
|
5
|
-
const { Stack } = require(
|
1
|
+
const { BinaryTree } = require('./modules/data/bintree');
|
2
|
+
const { DoublyLinkedList } = require('./modules/data/doublylinked');
|
3
|
+
const { LinkedList } = require('./modules/data/linkedList');
|
4
|
+
const { Queue } = require('./modules/data/queue');
|
5
|
+
const { Stack } = require('./modules/data/stack');
|
6
6
|
|
7
7
|
module.exports = (context) => ({
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
8
|
+
Stack,
|
9
|
+
Queue,
|
10
|
+
BinaryTree,
|
11
|
+
DoublyLinkedList,
|
12
|
+
LinkedList,
|
13
13
|
});
|
package/lib/rew/pkgs/date.js
CHANGED
@@ -8,10 +8,10 @@
|
|
8
8
|
* @return {string} - The formatted date string.
|
9
9
|
*/
|
10
10
|
function formatDate(date) {
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
11
|
+
const year = date.getFullYear();
|
12
|
+
const month = String(date.getMonth() + 1).padStart(2, '0');
|
13
|
+
const day = String(date.getDate()).padStart(2, '0');
|
14
|
+
return `${year}-${month}-${day}`;
|
15
15
|
}
|
16
16
|
|
17
17
|
/**
|
@@ -20,10 +20,10 @@ function formatDate(date) {
|
|
20
20
|
* @return {string} - The formatted time string.
|
21
21
|
*/
|
22
22
|
function formatTime(date) {
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
23
|
+
const hours = String(date.getHours()).padStart(2, '0');
|
24
|
+
const minutes = String(date.getMinutes()).padStart(2, '0');
|
25
|
+
const seconds = String(date.getSeconds()).padStart(2, '0');
|
26
|
+
return `${hours}:${minutes}:${seconds}`;
|
27
27
|
}
|
28
28
|
|
29
29
|
// Parsing Functions
|
@@ -34,8 +34,8 @@ function formatTime(date) {
|
|
34
34
|
* @return {Date} - The parsed date object.
|
35
35
|
*/
|
36
36
|
function parseDate(dateString) {
|
37
|
-
|
38
|
-
|
37
|
+
const [year, month, day] = dateString.split('-').map(Number);
|
38
|
+
return new Date(year, month - 1, day);
|
39
39
|
}
|
40
40
|
|
41
41
|
/**
|
@@ -44,10 +44,10 @@ function parseDate(dateString) {
|
|
44
44
|
* @return {Date} - The parsed date object.
|
45
45
|
*/
|
46
46
|
function parseTime(timeString) {
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
47
|
+
const [hours, minutes, seconds] = timeString.split(':').map(Number);
|
48
|
+
const date = new Date();
|
49
|
+
date.setHours(hours, minutes, seconds, 0);
|
50
|
+
return date;
|
51
51
|
}
|
52
52
|
|
53
53
|
// Arithmetic Functions
|
@@ -59,9 +59,9 @@ function parseTime(timeString) {
|
|
59
59
|
* @return {Date} - The new date object.
|
60
60
|
*/
|
61
61
|
function addDays(date, days) {
|
62
|
-
|
63
|
-
|
64
|
-
|
62
|
+
const result = new Date(date);
|
63
|
+
result.setDate(result.getDate() + days);
|
64
|
+
return result;
|
65
65
|
}
|
66
66
|
|
67
67
|
/**
|
@@ -71,7 +71,7 @@ function addDays(date, days) {
|
|
71
71
|
* @return {Date} - The new date object.
|
72
72
|
*/
|
73
73
|
function subtractDays(date, days) {
|
74
|
-
|
74
|
+
return addDays(date, -days);
|
75
75
|
}
|
76
76
|
|
77
77
|
/**
|
@@ -81,17 +81,17 @@ function subtractDays(date, days) {
|
|
81
81
|
* @return {number} - The difference in days.
|
82
82
|
*/
|
83
83
|
function differenceInDays(date1, date2) {
|
84
|
-
|
85
|
-
|
84
|
+
const diffTime = date2 - date1;
|
85
|
+
return Math.ceil(diffTime / (1000 * 60 * 60 * 24));
|
86
86
|
}
|
87
87
|
|
88
88
|
// Exporting the functions as a CommonJS module
|
89
89
|
module.exports = () => ({
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
90
|
+
formatDate,
|
91
|
+
formatTime,
|
92
|
+
parseDate,
|
93
|
+
parseTime,
|
94
|
+
addDays,
|
95
|
+
subtractDays,
|
96
|
+
differenceInDays,
|
97
97
|
});
|
package/lib/rew/pkgs/env.js
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module.exports = (context) => ({
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
2
|
+
has: (key) => key in process.env,
|
3
|
+
get: (key) => process.env[key],
|
4
|
+
set: (key, value) => (process.env[key] = value),
|
5
|
+
rm: (key) => delete process.env[key],
|
6
|
+
is: (key, value) => process.env[key] == value,
|
7
7
|
});
|
@@ -1,64 +1,64 @@
|
|
1
1
|
class TreeNode {
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
2
|
+
constructor(value) {
|
3
|
+
this.value = value;
|
4
|
+
this.left = null;
|
5
|
+
this.right = null;
|
6
|
+
}
|
7
7
|
}
|
8
8
|
|
9
9
|
class BinaryTree {
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
constructor() {
|
11
|
+
this.root = null;
|
12
|
+
}
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
14
|
+
insert(value) {
|
15
|
+
const newNode = new TreeNode(value);
|
16
|
+
if (!this.root) {
|
17
|
+
this.root = newNode;
|
18
|
+
return;
|
19
|
+
}
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
21
|
+
const insertNode = (node) => {
|
22
|
+
if (value < node.value) {
|
23
|
+
if (!node.left) {
|
24
|
+
node.left = newNode;
|
25
|
+
} else {
|
26
|
+
insertNode(node.left);
|
27
|
+
}
|
28
|
+
} else {
|
29
|
+
if (!node.right) {
|
30
|
+
node.right = newNode;
|
31
|
+
} else {
|
32
|
+
insertNode(node.right);
|
33
|
+
}
|
34
|
+
}
|
35
|
+
};
|
36
36
|
|
37
|
-
|
38
|
-
|
37
|
+
insertNode(this.root);
|
38
|
+
}
|
39
39
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
40
|
+
find(value) {
|
41
|
+
const findNode = (node) => {
|
42
|
+
if (!node) return null;
|
43
|
+
if (node.value === value) return node;
|
44
|
+
if (value < node.value) return findNode(node.left);
|
45
|
+
return findNode(node.right);
|
46
|
+
};
|
47
47
|
|
48
|
-
|
49
|
-
|
48
|
+
return findNode(this.root);
|
49
|
+
}
|
50
50
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
51
|
+
toArray() {
|
52
|
+
const elements = [];
|
53
|
+
const traverse = (node) => {
|
54
|
+
if (!node) return;
|
55
|
+
traverse(node.left);
|
56
|
+
elements.push(node.value);
|
57
|
+
traverse(node.right);
|
58
|
+
};
|
59
|
+
traverse(this.root);
|
60
|
+
return elements;
|
61
|
+
}
|
62
62
|
}
|
63
63
|
|
64
64
|
BinaryTree.Node = TreeNode;
|