@makano/rew 1.3.7 → 1.3.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -22,9 +22,9 @@ class Usage {
22
22
  save = true;
23
23
 
24
24
  constructor(name, trigger, save){
25
- this.name = name;
25
+ this.name = name || '';
26
26
  this.trigger = trigger;
27
- this.save = name == '' ? false : save;
27
+ this.save = name == '' || name == null ? false : save;
28
28
  }
29
29
 
30
30
  create(name, trigger, save = true){
@@ -117,9 +117,9 @@ module.exports.usingFunction = (context, runtime) => {
117
117
  if(name.onAfterUse) name.onAfterUse();
118
118
  return r;
119
119
  } else if(name instanceof Usage) {
120
- const v = name.trigger(...params) || true;
121
- if(name.save !== false) context.__using__[name.name] = v;
122
- return v;
120
+ const v = name.trigger(...params);
121
+ if(name.save !== false) context.__using__[name.name] = v ?? true;
122
+ return v || (typeof name.result === "function" ? name.result(v) : name.result || true);
123
123
  } else {
124
124
  context.__using__[name] = params.length ? params.length > 1 ? [...params] : params : true;
125
125
  }
@@ -1,6 +1,6 @@
1
1
  const { spawnSync } = require('child_process');
2
2
 
3
- const print = (module.exports.print = function print(...args) {
3
+ (module.exports.print = function print(...args) {
4
4
  return console.log(...args);
5
5
  });
6
6
 
@@ -8,9 +8,6 @@ module.exports.printf = function printf(buffer, cb) {
8
8
  return process.stdout.write(buffer, cb);
9
9
  };
10
10
 
11
- print.stdout = process.stdout;
12
- print.stdin = process.stdin;
13
-
14
11
  module.exports.input = function input(prompt) {
15
12
  process.stdout.write(prompt);
16
13
 
@@ -154,11 +154,15 @@ function declareAlias(aliases, token) {
154
154
 
155
155
  if(name.startsWith('=')){
156
156
  name = name.slice(1);
157
- let isDecOnly = false;
157
+ let isDecOnly = false, isConstructor = false;
158
158
  if(name.endsWith('*')) {
159
159
  name = name.slice(0, -1);
160
160
  isDecOnly = true;
161
161
  }
162
+ if(name.endsWith('!')) {
163
+ name = name.slice(0, -1);
164
+ isConstructor = true;
165
+ }
162
166
  aliasValue = (token, tokens, code, hooks, index, setIndex) => {
163
167
  const nextToken = tokens[index+1]
164
168
  let nextToken2 = gnextToken(index, 3, tokens);
@@ -181,7 +185,7 @@ function declareAlias(aliases, token) {
181
185
  let nextToken = gnextToken(index, offset+1, tokens);
182
186
  const args = nextToken.token.value;
183
187
  setIndex(ti + offset);
184
- return `${nextToken2.value} = ${token.value} ${args && args !== '(' && args !== '{' && args !== '[' && args !== '-' && args !== '=' ? `${args},` : ''} ${params.trim() ? params.trim() + ', ' : ''}${args == '(' || args == '[' || args == '{' || args == '=' || args == '-' ? args : ''}`.replace(/,(| )$/, '');
188
+ return `${nextToken2.value} = ${isConstructor?'new ':''}${token.value} ${args && args !== '(' && args !== '{' && args !== '[' && args !== '-' && args !== '=' ? `${args},` : ''} ${params.trim() ? params.trim() + ', ' : ''}${args == '(' || args == '[' || args == '{' || args == '=' || args == '-' ? args : ''}`.replace(/,(| )$/, '');
185
189
  } else if(nextToken?.value == ' ' && (isDecOnly || nextToken2?.token.value == '=' || nextToken2?.token.value == ':')){
186
190
  nextToken.value = '';
187
191
  if(isDecOnly){
@@ -194,7 +198,7 @@ function declareAlias(aliases, token) {
194
198
  if(nextToken2.token.value == ':') nextToken2.token.value = '=';
195
199
  hooks.push({
196
200
  index: nextToken2.ti,
197
- value: ' ' + value
201
+ value: ' ' + (isConstructor?'new ':'') + value
198
202
  })
199
203
  return "";
200
204
  }
@@ -215,8 +219,8 @@ function declareAlias(aliases, token) {
215
219
 
216
220
  const stdTypes = (isPublic) => {
217
221
  let r = '';
218
- const dec = (name, fn) => {
219
- r += `#declare${isPublic?'*':''} key "=${name}" = ${fn || name};\n`
222
+ const dec = (name, fn, cons = 0) => {
223
+ r += `#declare${isPublic?'*':''} key "=${name}${cons ? '!' : ''}" = ${fn || name};\n`
220
224
  }
221
225
  dec('int');
222
226
  dec('str');
@@ -226,6 +230,7 @@ const stdTypes = (isPublic) => {
226
230
  dec('typedef');
227
231
  dec('typef');
228
232
  dec('struct');
233
+ dec('Usage', null, 1);
229
234
  return r;
230
235
  };
231
236
  const includeFile = (includeContent, options) => {
@@ -461,7 +466,7 @@ function compileRewStuff(content, options) {
461
466
 
462
467
  if (tokens[i-1]?.value !== '.' && token.type === 'IDENTIFIER' && token.value === 'using' && !options.disableUse) {
463
468
  straceLog('USING()');
464
- const next = nextToken.value;
469
+ const next = nextToken?.value;
465
470
  if(next in USING_DEFAULT) {
466
471
  const { use } = USING_DEFAULT[next];
467
472
  use?.(options);
@@ -683,8 +688,8 @@ function compileRewStuff(content, options) {
683
688
  options.aliases = aliases;
684
689
  }
685
690
  // console.log(aliases);
686
- console.log(result);
687
- return "";
691
+ // console.log(result);
692
+ // return "";
688
693
  return result;
689
694
  }
690
695
 
@@ -694,7 +699,15 @@ const compileCivetStuff = (file, options) => {
694
699
  filename: file.path,
695
700
  ...options
696
701
  };
697
- straceLog('OPTION_PREPARE() for CURRENTFILE as', preCompileOptions);
702
+ straceLog('OPTION_PREPARE() for CURRENTFILE as', JSON.stringify(preCompileOptions));
703
+
704
+ if(options?.type == 'js' || file?.path?.endsWith('.js')){
705
+ return {
706
+ compiled: file?.content || "",
707
+ options: preCompileOptions
708
+ }
709
+ }
710
+
698
711
  const prepared = compileRewStuff(file.content, preCompileOptions);
699
712
 
700
713
  // console.log(prepared);
@@ -65,10 +65,13 @@ module.exports.prepareContext = function (
65
65
  }
66
66
  this.define = std.prototype.define;
67
67
  this.Main = std.prototype.Main;
68
+ this.attach = std.prototype.attach;
69
+ this.out = std.prototype.out;
70
+ this.inp = std.prototype.in;
68
71
  this['@cb'] = cb;
69
72
  }
70
73
  });
71
- }, define: (name, object) => {
74
+ }, out: {...process.stdout, put: (...logs) => context.print(...logs), strace: (...logs) => straceLog('==> STRACE_OUT():', ...logs ), write: (logs) => context.printf(logs+'\n') }, in: {...process.stdin, read: (...args) => context.input(...args)}, define: (name, object) => {
72
75
  if(Array.isArray(name) && name.length == 2 && typeof name[0] == 'string'){
73
76
  object = name[1];
74
77
  name = name[0];
@@ -79,6 +82,13 @@ module.exports.prepareContext = function (
79
82
  }, Main: (cb) => {
80
83
  if(cb?.main){
81
84
  cb.main._class = cb;
85
+ if(cb.prepare){
86
+ cb.prepare((object) => {
87
+ for(let i in object){
88
+ cb[i] = object[i];
89
+ }
90
+ });
91
+ }
82
92
  }
83
93
  return (['main', cb?.main ?? cb]);
84
94
  }, attach: (object) => {
@@ -120,6 +130,26 @@ module.exports.prepareContext = function (
120
130
  }
121
131
  };
122
132
 
133
+ context.std.prototype.__ = {
134
+ get prototype(){
135
+ const globals = context.app?.config?.assets?.globals ?? '_';
136
+ const p = context.pjoin(context.app ? context.app.path : context.dirname(context.module.filename), globals);
137
+ if(!context.exists(p)) return {};
138
+ const files = context.ls(p);
139
+ const pr = {};
140
+ files.forEach(file => {
141
+ if(!file.endsWith('.coffee')) return;
142
+ const e = runPath(context.pjoin(p, file));
143
+ let name = e.context.module.modset || file.split('.').shift();
144
+ pr[name] = e.context.module.exports || {};
145
+ if(typeof pr[name] == "object" && pr[name].default && Object.keys(pr[name]).length == 1){
146
+ pr[name] = pr[name].default;
147
+ }
148
+ });
149
+ return pr;
150
+ }
151
+ }
152
+
123
153
  context.global = context;
124
154
  context.imports.assert = options.import ?? {};
125
155
  context.imp = imp(runPath, context);
@@ -178,6 +208,8 @@ module.exports.prepareContext = function (
178
208
  if(!context.app){
179
209
  straceLog('==> APP NOT FOUND');
180
210
  context.appPackage = (packageName) => context.app = { config: { manifest: { package: packageName } } }
211
+ } else {
212
+ context.appPackage = context.mod = (packageName) => context.module.modset = packageName;
181
213
  }
182
214
 
183
215
  Object.defineProperty(context, 'packageName', {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@makano/rew",
3
- "version": "1.3.7",
3
+ "version": "1.3.9",
4
4
  "description": "A simple coffescript runtime and app manager",
5
5
  "main": "main.js",
6
6
  "directories": {