@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/models/struct.js
CHANGED
@@ -1,41 +1,39 @@
|
|
1
|
-
const { generateRandomID } = require(
|
1
|
+
const { generateRandomID } = require('../functions/id');
|
2
2
|
|
3
3
|
module.exports.struct = function struct(template) {
|
4
|
-
|
4
|
+
var key, types, value;
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
6
|
+
types = {};
|
7
|
+
for (key in template) {
|
8
|
+
value = template[key];
|
9
|
+
types[key] = typeof value;
|
10
|
+
}
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
return instance;
|
31
|
-
};
|
12
|
+
const fun = function (properties = {}) {
|
13
|
+
var defaultValue, instance;
|
14
|
+
instance = {};
|
15
|
+
for (key in template) {
|
16
|
+
defaultValue = template[key];
|
17
|
+
if (key in properties) {
|
18
|
+
value = properties[key];
|
19
|
+
if (defaultValue != '!any' && typeof value !== types[key]) {
|
20
|
+
throw new Error(`Type error: Expected ${types[key]} for ${key}, got ${typeof value}`);
|
21
|
+
}
|
22
|
+
instance[key] = value;
|
23
|
+
} else {
|
24
|
+
instance[key] = defaultValue == '!any' ? null : defaultValue;
|
25
|
+
}
|
26
|
+
}
|
27
|
+
instance.__proto__ = { '@instance': fun };
|
28
|
+
return instance;
|
29
|
+
};
|
32
30
|
|
33
|
-
|
31
|
+
return fun;
|
34
32
|
};
|
35
33
|
|
36
34
|
module.exports.struct.inherits = function (struct, template) {
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
35
|
+
return module.exports.struct({
|
36
|
+
...struct(),
|
37
|
+
...template,
|
38
|
+
});
|
41
39
|
};
|
@@ -1,238 +1,266 @@
|
|
1
|
-
const { compile } = require(
|
2
|
-
const { execOptions } = require(
|
3
|
-
const {
|
4
|
-
const
|
5
|
-
const
|
1
|
+
const { compile } = require('../../coffeescript/coffeescript');
|
2
|
+
const { execOptions } = require('../const/opt');
|
3
|
+
const { findAppInfo } = require('../misc/findAppInfo');
|
4
|
+
const { from_qrew } = require('../qrew/compile');
|
5
|
+
const { getFile, file } = require('./fs');
|
6
|
+
const babel = require('@babel/core');
|
7
|
+
const path = require('path');
|
8
|
+
const babelReact = require('@babel/preset-react');
|
9
|
+
const { readFileSync } = require('fs');
|
6
10
|
|
7
11
|
function tokenizeCoffeeScript(code) {
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
tokens.push({ type: "OTHER", value: char });
|
71
|
-
}
|
72
|
-
}
|
12
|
+
const tokens = [];
|
13
|
+
let currentToken = '';
|
14
|
+
|
15
|
+
for (let i = 0; i < code.length; i++) {
|
16
|
+
const char = code[i];
|
17
|
+
const nextChar = code[i + 1];
|
18
|
+
|
19
|
+
if (char === '#') {
|
20
|
+
// Comment
|
21
|
+
tokens.push({
|
22
|
+
type: 'COMMENT',
|
23
|
+
value: char + code.substring(i + 1).split('\n')[0] + '\n',
|
24
|
+
});
|
25
|
+
i = code.indexOf('\n', i);
|
26
|
+
} else if (char === '"' || char === "'") {
|
27
|
+
// String
|
28
|
+
let string = char;
|
29
|
+
let escaped = false;
|
30
|
+
i++;
|
31
|
+
while (i < code.length && (code[i] !== char || escaped)) {
|
32
|
+
string += code[i];
|
33
|
+
if (code[i] === '\\' && !escaped) {
|
34
|
+
escaped = true;
|
35
|
+
} else {
|
36
|
+
escaped = false;
|
37
|
+
}
|
38
|
+
i++;
|
39
|
+
}
|
40
|
+
string += char; // Include closing quote
|
41
|
+
tokens.push({ type: 'STRING', value: string });
|
42
|
+
} else if (char === '/' && (nextChar === '/' || nextChar === '*')) {
|
43
|
+
// Regular expression
|
44
|
+
let regex = char;
|
45
|
+
i++;
|
46
|
+
while (i < code.length && (code[i] !== '/' || regex.endsWith('\\'))) {
|
47
|
+
regex += code[i];
|
48
|
+
i++;
|
49
|
+
}
|
50
|
+
regex += '/';
|
51
|
+
tokens.push({ type: 'REGEX', value: regex });
|
52
|
+
} else if (/\s/.test(char)) {
|
53
|
+
// Whitespace
|
54
|
+
if (tokens[tokens.length - 1]?.type == 'WHITESPACE' && tokens[tokens.length - 1].value[0] == char) {
|
55
|
+
tokens[tokens.length - 1].value += char;
|
56
|
+
} else {
|
57
|
+
tokens.push({ type: 'WHITESPACE', value: char });
|
58
|
+
}
|
59
|
+
} else if (/[a-zA-Z_$]/.test(char)) {
|
60
|
+
// Identifier
|
61
|
+
let identifier = char;
|
62
|
+
i++;
|
63
|
+
while (i < code.length && /[a-zA-Z0-9_$]/.test(code[i])) {
|
64
|
+
identifier += code[i];
|
65
|
+
i++;
|
66
|
+
}
|
67
|
+
tokens.push({ type: 'IDENTIFIER', value: identifier });
|
68
|
+
i--; // Move back one character to recheck
|
69
|
+
} else {
|
70
|
+
// Other characters
|
71
|
+
tokens.push({ type: 'OTHER', value: char });
|
72
|
+
}
|
73
|
+
}
|
73
74
|
|
74
|
-
|
75
|
+
return tokens;
|
76
|
+
}
|
77
|
+
|
78
|
+
const ValueIfy = (val) => {
|
79
|
+
if(!isNaN(parseFloat(val)) || !isNaN(parseInt(val))){
|
80
|
+
return isNaN(parseInt(val)) ? parseFloat(val) : parseInt(val);
|
81
|
+
} if(val == 'true' || val == 'false') {
|
82
|
+
return val == 'true' ? true : false;
|
83
|
+
} else {
|
84
|
+
return JSON.stringify(val);
|
85
|
+
}
|
75
86
|
}
|
76
87
|
|
77
88
|
const gnextToken = (i, n, tokens) => {
|
78
|
-
|
79
|
-
? tokens[i + n].type == "WHITESPACE"
|
80
|
-
? gnextToken(i, n + 1, tokens)
|
81
|
-
: { nextToken: tokens[i + n], n }
|
82
|
-
: null;
|
89
|
+
return tokens[i + n] ? (tokens[i + n].type == 'WHITESPACE' ? gnextToken(i, n + 1, tokens) : { token: tokens[i + n], n }) : null;
|
83
90
|
};
|
84
91
|
|
85
92
|
const fnextToken = (i, tokens, type, value) => {
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
93
|
+
return tokens
|
94
|
+
.map((t, ind) => {
|
95
|
+
t.ti = ind;
|
96
|
+
return t;
|
97
|
+
})
|
98
|
+
.slice(i, tokens.length - 1)
|
99
|
+
.map((t, ind) => {
|
100
|
+
t.ri = ind;
|
101
|
+
t.index = ind - i;
|
102
|
+
return t;
|
103
|
+
})
|
104
|
+
.find((t) => t.type == type && (value ? t.value == value : true));
|
98
105
|
};
|
99
106
|
|
100
107
|
function compileRewStuff(content, options) {
|
101
|
-
|
102
|
-
|
108
|
+
const tokens = tokenizeCoffeeScript(content);
|
109
|
+
let result = '';
|
103
110
|
|
104
|
-
|
111
|
+
let hooks = [];
|
105
112
|
|
106
|
-
|
107
|
-
|
108
|
-
|
113
|
+
for (let i = 0; i < tokens.length; i++) {
|
114
|
+
const token = tokens[i];
|
115
|
+
let { token: nextToken, n } = gnextToken(i, 1, tokens) || {};
|
109
116
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
if (token.type === "IDENTIFIER" && token.value === "import") {
|
123
|
-
// console.log(nextToken.type);
|
124
|
-
let ind = i + n + 2;
|
125
|
-
|
126
|
-
let defaultName;
|
127
|
-
if (nextToken.type === "STRING") {
|
128
|
-
result += `inc ${nextToken.value}`;
|
129
|
-
i += n;
|
130
|
-
} else if (nextToken.value === "{") {
|
131
|
-
const closingBraceToken = fnextToken(ind, tokens, "OTHER", "}");
|
132
|
-
const nameToken = fnextToken(ind, tokens, "STRING");
|
133
|
-
if (closingBraceToken) {
|
134
|
-
const exportsTokens = tokens.slice(ind, closingBraceToken.ti);
|
135
|
-
const exports = exportsTokens
|
136
|
-
.filter((t) => t.type === "IDENTIFIER")
|
137
|
-
.map((t) => t.value)
|
138
|
-
.join(", ");
|
139
|
-
result += `{ ${exports} } = inc ${nameToken.value}`;
|
140
|
-
i = nameToken.ti;
|
141
|
-
}
|
142
|
-
} else if (nextToken.value === "*") {
|
143
|
-
const asToken = fnextToken(ind, tokens, "IDENTIFIER", "as");
|
144
|
-
const nameToken = fnextToken(asToken.ri, tokens, "STRING");
|
145
|
-
if (asToken) {
|
146
|
-
const nextToken = fnextToken(asToken.ti + 1, tokens, "IDENTIFIER");
|
147
|
-
defaultName = nextToken.value;
|
148
|
-
result += `${defaultName} = inc ${nameToken.value}`;
|
149
|
-
i = ind + 6;
|
150
|
-
}
|
151
|
-
} else if (nextToken) {
|
152
|
-
const nameToken = fnextToken(ind, tokens, "STRING");
|
153
|
-
defaultName = nextToken.value;
|
154
|
-
let { nextToken: nextNextToken, n: n2 } =
|
155
|
-
gnextToken(i + 2, 1, tokens) || {};
|
156
|
-
if (nextNextToken?.type == "OTHER" && nextNextToken?.value == ",") {
|
157
|
-
const closingBraceToken = fnextToken(ind, tokens, "OTHER", "}");
|
158
|
-
if (closingBraceToken) {
|
159
|
-
const exportsTokens = tokens.slice(ind, closingBraceToken.ti);
|
160
|
-
const exports = exportsTokens
|
161
|
-
.filter((t) => t.type === "IDENTIFIER")
|
162
|
-
.map((t) => t.value)
|
163
|
-
.join(", ");
|
164
|
-
result += `{ default: ${defaultName}, ${exports} } = inc ${nameToken?.value || ""}`;
|
165
|
-
i = closingBraceToken.ti + 4;
|
166
|
-
}
|
167
|
-
} else {
|
168
|
-
result += `{ default: ${defaultName} } = inc ${nameToken?.value || ""}`;
|
169
|
-
i = ind + 2;
|
170
|
-
}
|
171
|
-
}
|
117
|
+
if (token.type === 'IDENTIFIER' && token.value === 'opt') {
|
118
|
+
const { token: nextNextToken } = gnextToken(i, 2, tokens) || {};
|
119
|
+
if (nextNextToken && nextNextToken.value == 'jsxPragma') {
|
120
|
+
const { token: nextLastToken } = gnextToken(i, 5, tokens) || {};
|
121
|
+
execOptions.jsxPragma = nextLastToken.value.slice(1).slice(0, -1);
|
122
|
+
}
|
123
|
+
}
|
124
|
+
|
125
|
+
if (token.type === 'COMMENT' && token.value.slice(1).trim() === '@jsx') {
|
126
|
+
options.jsx = true;
|
127
|
+
}
|
172
128
|
|
173
|
-
|
129
|
+
if (token.type === 'COMMENT' && token.value.slice(1).trim() === '@cls') {
|
130
|
+
options.cls = true;
|
131
|
+
}
|
174
132
|
|
175
|
-
|
176
|
-
|
177
|
-
|
133
|
+
if (options.cls && token.type === 'OTHER' && token.value === '-' && nextToken.value == '-' && tokens[i-1]?.type == 'WHITESPACE') {
|
134
|
+
// Argument case
|
135
|
+
let offset = 0, writenext = false;
|
136
|
+
const n = gnextToken(i, 2, tokens);
|
137
|
+
let v = gnextToken(i, 3, tokens);
|
138
|
+
if(v.token.type == 'IDENTIFIER' && v.token.value == '$'){
|
139
|
+
writenext = true;
|
178
140
|
}
|
141
|
+
result += n.token.value + ': ' + (writenext ? '' : (v.token.value == ',' ? 'true, ' : v.token.type == "STRING" ? v.token.value : ValueIfy(v.token.value)));
|
179
142
|
|
143
|
+
i = offset + tokens.indexOf(v.token);
|
180
144
|
continue;
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
145
|
+
}
|
146
|
+
|
147
|
+
if (token.type === 'IDENTIFIER' && token.value === 'import') {
|
148
|
+
// console.log(nextToken.type);
|
149
|
+
let ind = i + n + 2;
|
150
|
+
|
151
|
+
let defaultName;
|
152
|
+
if (nextToken.type === 'STRING') {
|
153
|
+
result += `inc ${nextToken.value}`;
|
154
|
+
i += n;
|
155
|
+
} else if (nextToken.value === '{') {
|
156
|
+
const closingBraceToken = fnextToken(ind, tokens, 'OTHER', '}');
|
157
|
+
const nameToken = fnextToken(ind, tokens, 'STRING');
|
158
|
+
if (closingBraceToken) {
|
159
|
+
const exportsTokens = tokens.slice(ind, closingBraceToken.ti);
|
160
|
+
const exports = exportsTokens
|
161
|
+
.filter((t) => t.type === 'IDENTIFIER')
|
162
|
+
.map((t) => t.value)
|
163
|
+
.join(', ');
|
164
|
+
result += `{ ${exports} } = inc ${nameToken.value}`;
|
165
|
+
i = nameToken.ti;
|
166
|
+
}
|
167
|
+
} else if (nextToken.value === '*') {
|
168
|
+
const asToken = fnextToken(ind, tokens, 'IDENTIFIER', 'as');
|
169
|
+
const nameToken = fnextToken(asToken.ri, tokens, 'STRING');
|
170
|
+
if (asToken) {
|
171
|
+
const nextToken = fnextToken(asToken.ti + 1, tokens, 'IDENTIFIER');
|
172
|
+
defaultName = nextToken.value;
|
173
|
+
result += `${defaultName} = inc ${nameToken.value}`;
|
174
|
+
i = ind + 6;
|
175
|
+
}
|
176
|
+
} else if (nextToken) {
|
177
|
+
const nameToken = fnextToken(ind, tokens, 'STRING');
|
178
|
+
defaultName = nextToken.value;
|
179
|
+
let { nextToken: nextNextToken, n: n2 } = gnextToken(i + 2, 1, tokens) || {};
|
180
|
+
if (nextNextToken?.type == 'OTHER' && nextNextToken?.value == ',') {
|
181
|
+
const closingBraceToken = fnextToken(ind, tokens, 'OTHER', '}');
|
182
|
+
if (closingBraceToken) {
|
183
|
+
const exportsTokens = tokens.slice(ind, closingBraceToken.ti);
|
184
|
+
const exports = exportsTokens
|
185
|
+
.filter((t) => t.type === 'IDENTIFIER')
|
186
|
+
.map((t) => t.value)
|
187
|
+
.join(', ');
|
188
|
+
result += `{ default: ${defaultName}, ${exports} } = inc ${nameToken?.value || ''}`;
|
189
|
+
i = closingBraceToken.ti + 4;
|
190
|
+
}
|
191
|
+
} else {
|
192
|
+
result += `{ default: ${defaultName} } = inc ${nameToken?.value || ''}`;
|
193
|
+
i = ind + 2;
|
194
|
+
}
|
195
|
+
}
|
196
|
+
|
197
|
+
const nextLastToken = fnextToken(i, tokens, 'IDENTIFIER');
|
198
|
+
|
199
|
+
if (nextLastToken?.value == 'assert') {
|
200
|
+
result += ', ';
|
201
|
+
i += 3;
|
202
|
+
}
|
203
|
+
|
204
|
+
continue;
|
205
|
+
}
|
207
206
|
|
208
|
-
|
207
|
+
if (
|
208
|
+
token.type === 'IDENTIFIER' &&
|
209
|
+
token.value === 'pub' &&
|
210
|
+
nextToken &&
|
211
|
+
nextToken.type === 'IDENTIFIER' &&
|
212
|
+
nextToken.value &&
|
213
|
+
nextToken.value !== 'undefined'
|
214
|
+
) {
|
215
|
+
hooks.push({
|
216
|
+
index: i + 1,
|
217
|
+
value: `"${nextToken.value}", `,
|
218
|
+
});
|
219
|
+
}
|
209
220
|
|
210
|
-
|
221
|
+
result += token.value;
|
222
|
+
if (hooks.length) {
|
223
|
+
hooks.forEach((hook, ind) => {
|
224
|
+
if (i == hook.index) {
|
225
|
+
result += hook.value;
|
226
|
+
hooks.splice(ind, 1);
|
227
|
+
}
|
228
|
+
});
|
229
|
+
}
|
230
|
+
}
|
231
|
+
|
232
|
+
// console.log(result)
|
233
|
+
|
234
|
+
return result;
|
211
235
|
}
|
212
236
|
|
213
237
|
const cpl = (module.exports.compile = function (file, options = {}) {
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
238
|
+
let c = compile(compileRewStuff(file.content, options), {
|
239
|
+
...options,
|
240
|
+
filename: file.path,
|
241
|
+
bare: false,
|
242
|
+
inlineMap: false,
|
243
|
+
});
|
244
|
+
if (execOptions.jsx || options.jsx) {
|
245
|
+
c = babel.transformSync(c, {
|
246
|
+
presets: [[babelReact, { pragma: execOptions.jsxPragma }]],
|
247
|
+
plugins: [],
|
248
|
+
}).code;
|
249
|
+
}
|
250
|
+
return c;
|
227
251
|
});
|
228
252
|
|
229
253
|
module.exports.compileFile = function (filepath, options = {}) {
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
254
|
+
const f = getFile(filepath);
|
255
|
+
|
256
|
+
if(options.qrew || path.extname(filepath) == '.qrew') {
|
257
|
+
f.content = from_qrew(readFileSync(f.path), options.package || findAppInfo(filepath)?.config.package || path.basename(filepath).split('.').slice(0, -1).join('.')).toString();
|
258
|
+
}
|
259
|
+
|
260
|
+
let compiled_code = options.compile == false ? f.content : cpl(f, { ...options });
|
261
|
+
|
262
|
+
return {
|
263
|
+
compiled_code,
|
264
|
+
file: f,
|
265
|
+
};
|
238
266
|
};
|
package/lib/rew/modules/fs.js
CHANGED
@@ -1,19 +1,19 @@
|
|
1
|
-
const { struct } = require(
|
2
|
-
const fs = require(
|
1
|
+
const { struct } = require('../models/struct');
|
2
|
+
const fs = require('fs');
|
3
3
|
|
4
4
|
const file = (module.exports.file = struct({
|
5
|
-
|
6
|
-
|
5
|
+
path: '',
|
6
|
+
content: '',
|
7
7
|
}));
|
8
8
|
|
9
9
|
const readFile = (module.exports.readFile = function readFile(file) {
|
10
|
-
|
10
|
+
return (file.content = fs.readFileSync(file.path, { encoding: 'utf-8' }));
|
11
11
|
});
|
12
12
|
|
13
13
|
module.exports.getFile = function (filepath) {
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
14
|
+
const f = file({
|
15
|
+
path: filepath,
|
16
|
+
});
|
17
|
+
readFile(f);
|
18
|
+
return f;
|
19
19
|
};
|
@@ -1,28 +1,24 @@
|
|
1
|
-
const vm = require(
|
2
|
-
const { compileFile } = require(
|
3
|
-
const { prepareContext } = require(
|
1
|
+
const vm = require('vm');
|
2
|
+
const { compileFile } = require('./compiler');
|
3
|
+
const { prepareContext } = require('./context');
|
4
4
|
|
5
5
|
const exec = (module.exports.exec = function (code, context) {
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
6
|
+
return vm.runInNewContext(code, vm.createContext(context), {
|
7
|
+
filename: context.module.filepath,
|
8
|
+
lineOffset: 0,
|
9
|
+
displayErrors: true,
|
10
|
+
});
|
11
11
|
});
|
12
12
|
|
13
|
-
module.exports.runPath = function runPath(
|
14
|
-
|
15
|
-
|
16
|
-
custom_context = {},
|
17
|
-
) {
|
18
|
-
const { compiled_code, file } = compileFile(filepath, options);
|
19
|
-
const context = prepareContext(custom_context, options, file.path, runPath);
|
13
|
+
module.exports.runPath = function runPath(filepath, options = {}, custom_context = {}) {
|
14
|
+
const { compiled_code, file } = compileFile(filepath, options);
|
15
|
+
const context = prepareContext(custom_context, options, file.path, runPath);
|
20
16
|
|
21
|
-
|
22
|
-
|
17
|
+
context.module.compiled = compiled_code;
|
18
|
+
context.process.exit = (int) => process.exit(int);
|
23
19
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
20
|
+
return {
|
21
|
+
context,
|
22
|
+
returns: exec(compiled_code, context),
|
23
|
+
};
|
28
24
|
};
|