@makano/rew 1.1.81 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) 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 +296 -239
  18. package/lib/rew/cli/log.js +27 -27
  19. package/lib/rew/cli/run.js +8 -8
  20. package/lib/rew/cli/utils.js +353 -199
  21. package/lib/rew/const/config_path.js +2 -2
  22. package/lib/rew/const/default.js +38 -53
  23. package/lib/rew/const/files.js +11 -14
  24. package/lib/rew/const/opt.js +6 -6
  25. package/lib/rew/css/theme.css +1 -1
  26. package/lib/rew/functions/core.js +55 -55
  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 -25
  30. package/lib/rew/functions/export.js +17 -17
  31. package/lib/rew/functions/fs.js +57 -59
  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 +106 -122
  35. package/lib/rew/functions/map.js +10 -10
  36. package/lib/rew/functions/match.js +35 -42
  37. package/lib/rew/functions/path.js +8 -8
  38. package/lib/rew/functions/require.js +32 -36
  39. package/lib/rew/functions/sleep.js +2 -2
  40. package/lib/rew/functions/stdout.js +18 -18
  41. package/lib/rew/functions/types.js +82 -106
  42. package/lib/rew/html/ui.html +12 -12
  43. package/lib/rew/html/ui.js +196 -201
  44. package/lib/rew/main.js +14 -14
  45. package/lib/rew/misc/bin.js +37 -0
  46. package/lib/rew/misc/findAppInfo.js +13 -13
  47. package/lib/rew/misc/findAppPath.js +15 -15
  48. package/lib/rew/misc/req.js +7 -0
  49. package/lib/rew/misc/seededid.js +8 -8
  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 -209
  53. package/lib/rew/modules/fs.js +10 -10
  54. package/lib/rew/modules/runtime.js +17 -21
  55. package/lib/rew/modules/yaml.js +27 -30
  56. package/lib/rew/pkgs/conf.js +82 -92
  57. package/lib/rew/pkgs/data.js +10 -10
  58. package/lib/rew/pkgs/date.js +27 -27
  59. package/lib/rew/pkgs/env.js +5 -5
  60. package/lib/rew/pkgs/modules/data/bintree.js +51 -51
  61. package/lib/rew/pkgs/modules/data/doublylinked.js +84 -84
  62. package/lib/rew/pkgs/modules/data/linkedList.js +72 -72
  63. package/lib/rew/pkgs/modules/data/queue.js +18 -18
  64. package/lib/rew/pkgs/modules/data/stack.js +18 -18
  65. package/lib/rew/pkgs/modules/threads/worker.js +36 -36
  66. package/lib/rew/pkgs/modules/ui/classes.js +181 -184
  67. package/lib/rew/pkgs/pkgs.js +9 -9
  68. package/lib/rew/pkgs/rune.js +373 -410
  69. package/lib/rew/pkgs/threads.js +62 -66
  70. package/lib/rew/pkgs/ui.js +148 -160
  71. package/lib/rew/qrew/compile.js +12 -0
  72. package/package.json +4 -3
@@ -1,41 +1,39 @@
1
- const { generateRandomID } = require("../functions/id");
1
+ const { generateRandomID } = require('../functions/id');
2
2
 
3
3
  module.exports.struct = function struct(template) {
4
- var key, types, value;
4
+ var key, types, value;
5
5
 
6
- types = {};
7
- for (key in template) {
8
- value = template[key];
9
- types[key] = typeof value;
10
- }
6
+ types = {};
7
+ for (key in template) {
8
+ value = template[key];
9
+ types[key] = typeof value;
10
+ }
11
11
 
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(
21
- `Type error: Expected ${types[key]} for ${key}, got ${typeof value}`,
22
- );
23
- }
24
- instance[key] = value;
25
- } else {
26
- instance[key] = defaultValue == "!any" ? null : defaultValue;
27
- }
28
- }
29
- instance.__proto__ = { "@instance": fun };
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
- return fun;
31
+ return fun;
34
32
  };
35
33
 
36
34
  module.exports.struct.inherits = function (struct, template) {
37
- return module.exports.struct({
38
- ...struct(),
39
- ...template,
40
- });
35
+ return module.exports.struct({
36
+ ...struct(),
37
+ ...template,
38
+ });
41
39
  };
@@ -1,238 +1,266 @@
1
- const { compile } = require("../../coffeescript/coffeescript");
2
- const { execOptions } = require("../const/opt");
3
- const { getFile } = require("./fs");
4
- const babel = require("@babel/core");
5
- const babelReact = require("@babel/preset-react");
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
- const tokens = [];
9
- let currentToken = "";
10
-
11
- for (let i = 0; i < code.length; i++) {
12
- const char = code[i];
13
- const nextChar = code[i + 1];
14
-
15
- if (char === "#") {
16
- // Comment
17
- tokens.push({
18
- type: "COMMENT",
19
- value: char + code.substring(i + 1).split("\n")[0] + "\n",
20
- });
21
- i = code.indexOf("\n", i);
22
- } else if (char === '"' || char === "'") {
23
- // String
24
- let string = char;
25
- let escaped = false;
26
- i++;
27
- while (i < code.length && (code[i] !== char || escaped)) {
28
- string += code[i];
29
- if (code[i] === "\\" && !escaped) {
30
- escaped = true;
31
- } else {
32
- escaped = false;
33
- }
34
- i++;
35
- }
36
- string += char; // Include closing quote
37
- tokens.push({ type: "STRING", value: string });
38
- } else if (char === "/" && (nextChar === "/" || nextChar === "*")) {
39
- // Regular expression
40
- let regex = char;
41
- i++;
42
- while (i < code.length && (code[i] !== "/" || regex.endsWith("\\"))) {
43
- regex += code[i];
44
- i++;
45
- }
46
- regex += "/";
47
- tokens.push({ type: "REGEX", value: regex });
48
- } else if (/\s/.test(char)) {
49
- // Whitespace
50
- if (
51
- tokens[tokens.length - 1]?.type == "WHITESPACE" &&
52
- tokens[tokens.length - 1].value[0] == char
53
- ) {
54
- tokens[tokens.length - 1].value += char;
55
- } else {
56
- tokens.push({ type: "WHITESPACE", value: char });
57
- }
58
- } else if (/[a-zA-Z_$]/.test(char)) {
59
- // Identifier
60
- let identifier = char;
61
- i++;
62
- while (i < code.length && /[a-zA-Z0-9_$]/.test(code[i])) {
63
- identifier += code[i];
64
- i++;
65
- }
66
- tokens.push({ type: "IDENTIFIER", value: identifier });
67
- i--; // Move back one character to recheck
68
- } else {
69
- // Other characters
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
- return tokens;
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
- return tokens[i + n]
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
- return tokens
87
- .map((t, ind) => {
88
- t.ti = ind;
89
- return t;
90
- })
91
- .slice(i, tokens.length - 1)
92
- .map((t, ind) => {
93
- t.ri = ind;
94
- t.index = ind - i;
95
- return t;
96
- })
97
- .find((t) => t.type == type && (value ? t.value == value : true));
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
- const tokens = tokenizeCoffeeScript(content);
102
- let result = "";
108
+ const tokens = tokenizeCoffeeScript(content);
109
+ let result = '';
103
110
 
104
- let hooks = [];
111
+ let hooks = [];
105
112
 
106
- for (let i = 0; i < tokens.length; i++) {
107
- const token = tokens[i];
108
- let { nextToken, n } = gnextToken(i, 1, tokens) || {};
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
- if (token.type === "IDENTIFIER" && token.value === "opt") {
111
- const { nextToken: nextNextToken } = gnextToken(i, 2, tokens) || {};
112
- if (nextNextToken && nextNextToken.value == "jsxPragma") {
113
- const { nextToken: nextLastToken } = gnextToken(i, 5, tokens) || {};
114
- execOptions.jsxPragma = nextLastToken.value.slice(1).slice(0, -1);
115
- }
116
- }
117
-
118
- if (token.type === "COMMENT" && token.value.slice(1).trim() === "@jsx") {
119
- options.jsx = true;
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
- const nextLastToken = fnextToken(i, tokens, "IDENTIFIER");
129
+ if (token.type === 'COMMENT' && token.value.slice(1).trim() === '@cls') {
130
+ options.cls = true;
131
+ }
174
132
 
175
- if (nextLastToken?.value == "assert") {
176
- result += ", ";
177
- i += 3;
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
- if (
184
- token.type === "IDENTIFIER" &&
185
- token.value === "pub" &&
186
- nextToken &&
187
- nextToken.type === "IDENTIFIER" &&
188
- nextToken.value &&
189
- nextToken.value !== "undefined"
190
- ) {
191
- hooks.push({
192
- index: i + 1,
193
- value: `"${nextToken.value}", `,
194
- });
195
- }
196
-
197
- result += token.value;
198
- if (hooks.length) {
199
- hooks.forEach((hook, ind) => {
200
- if (i == hook.index) {
201
- result += hook.value;
202
- hooks.splice(ind, 1);
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
- // console.log(result)
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
- return result;
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
- let c = compile(compileRewStuff(file.content, options), {
215
- ...options,
216
- filename: file.path,
217
- bare: false,
218
- inlineMap: false,
219
- });
220
- if (execOptions.jsx || options.jsx) {
221
- c = babel.transformSync(c, {
222
- presets: [[babelReact, { pragma: execOptions.jsxPragma }]],
223
- plugins: [],
224
- }).code;
225
- }
226
- return c;
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
- const f = getFile(filepath);
231
- const compiled_code =
232
- options.compile == false ? f.content : cpl(f, { ...options });
233
-
234
- return {
235
- compiled_code,
236
- file: f,
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
  };
@@ -1,19 +1,19 @@
1
- const { struct } = require("../models/struct");
2
- const fs = require("fs");
1
+ const { struct } = require('../models/struct');
2
+ const fs = require('fs');
3
3
 
4
4
  const file = (module.exports.file = struct({
5
- path: "",
6
- content: "",
5
+ path: '',
6
+ content: '',
7
7
  }));
8
8
 
9
9
  const readFile = (module.exports.readFile = function readFile(file) {
10
- return (file.content = fs.readFileSync(file.path, { encoding: "utf-8" }));
10
+ return (file.content = fs.readFileSync(file.path, { encoding: 'utf-8' }));
11
11
  });
12
12
 
13
13
  module.exports.getFile = function (filepath) {
14
- const f = file({
15
- path: filepath,
16
- });
17
- readFile(f);
18
- return f;
14
+ const f = file({
15
+ path: filepath,
16
+ });
17
+ readFile(f);
18
+ return f;
19
19
  };
@@ -1,28 +1,24 @@
1
- const vm = require("vm");
2
- const { compileFile } = require("./compiler");
3
- const { prepareContext } = require("./context");
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
- return vm.runInNewContext(code, vm.createContext(context), {
7
- filename: context.module.filepath,
8
- lineOffset: 0,
9
- displayErrors: true,
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
- filepath,
15
- options = {},
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
- context.module.compiled = compiled_code;
22
- context.process.exit = (int) => process.exit(int);
17
+ context.module.compiled = compiled_code;
18
+ context.process.exit = (int) => process.exit(int);
23
19
 
24
- return {
25
- context,
26
- returns: exec(compiled_code, context),
27
- };
20
+ return {
21
+ context,
22
+ returns: exec(compiled_code, context),
23
+ };
28
24
  };