@makano/rew 1.2.58 → 1.2.61

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,7 +5,7 @@ const path = require('path');
5
5
  const { hideBin } = require('yargs/helpers');
6
6
  const { execSync } = require('child_process');
7
7
  const utils = require('./utils');
8
- const { existsSync, readFileSync, writeFileSync, mkdirSync, statSync } = require('fs');
8
+ const { existsSync, readFileSync, writeFileSync, mkdirSync, statSync, unlinkSync } = require('fs');
9
9
  const { log } = require('./log');
10
10
  const os = require('os');
11
11
  const crypto = require('crypto');
@@ -18,6 +18,7 @@ const colors = require('colors');
18
18
  const { req } = require('../misc/req');
19
19
  const { gen_key } = require('../misc/bin');
20
20
  const { REW_FILE_TYPE } = require('../const/ext');
21
+ const { generateRandomID } = require('../functions/id');
21
22
 
22
23
  if (!existsSync(CONFIG_PATH) || !existsSync(CONFIG_PATH + '/repos.yaml')) {
23
24
  mkdirSync(CONFIG_PATH, { recursive: true });
@@ -62,9 +63,36 @@ yargs(hideBin(process.argv))
62
63
  log('File not found:'.red.bold, argv.file, ':end');
63
64
  return;
64
65
  }
65
- utils.runFileWithArgv(filePath, { onlyCompile: argv.compile, watch: argv.watch });
66
+ utils.runFileWithArgv(filePath, { async: !process.stdin.isTTY, onlyCompile: argv.compile, watch: argv.watch });
66
67
  },
67
68
  )
69
+ .command(
70
+ 'exec [code]',
71
+ 'Executes in REPL',
72
+ (yargs) => {
73
+ yargs
74
+ .option('compile', {
75
+ alias: 'c',
76
+ describe: 'Compile and output the javascript',
77
+ type: 'boolean',
78
+ });
79
+ },
80
+ async (argv) => {
81
+ const replFile = '/tmp/rew-'+generateRandomID()+'-'+Date.now()+'.coffee';
82
+ let code = argv.code;
83
+ if(!process.stdin.isTTY) {
84
+ code = await utils.getAllPipeInput();
85
+ }
86
+ writeFileSync(replFile, code);
87
+ try{
88
+ utils.runFileWithArgv(replFile, { async: !process.stdin.isTTY, onlyCompile: argv.compile });
89
+ } catch(e){
90
+ console.error(e);
91
+ } finally {
92
+ unlinkSync(replFile);
93
+ }
94
+ }
95
+ )
68
96
  .command(
69
97
  'conf <command> [path] [key] [value]',
70
98
  'Configuration management',
@@ -363,4 +391,4 @@ yargs(hideBin(process.argv))
363
391
  utils.build(argv);
364
392
  },
365
393
  )
366
- .help(!isFileGiven).argv;
394
+ .help(!isFileGiven).argv;
@@ -36,7 +36,7 @@ module.exports = {
36
36
 
37
37
  const runIt = () => {
38
38
  if (options.watch) console.clear();
39
- const imports = execRewFile(filePath, [filePath, ...(argv || [])], { onlyCompile: options?.onlyCompile });
39
+ const imports = execRewFile(filePath, [filePath, ...(argv || [])], { onlyCompile: options?.onlyCompile, async: options?.async });
40
40
  if (options.watch) {
41
41
  imports.forEach((file) => {
42
42
  watchIt(file);
@@ -48,7 +48,7 @@ module.exports = {
48
48
  runIt();
49
49
  },
50
50
  runFileWithArgv(filePath, options = {}, cargv) {
51
- const argv = cargv || process.argv;
51
+ let argv = cargv || process.argv;
52
52
  argv.shift();
53
53
  if (argv[0].endsWith(REW_FILE_TYPE.EXTENSION) || argv[0].endsWith('.coffee')) {
54
54
  if (argv[1] == 'run') {
@@ -57,6 +57,12 @@ module.exports = {
57
57
  argv.splice(0, 3);
58
58
  } else argv.splice(0, 2);
59
59
  }
60
+ if (argv[1] == 'exec') {
61
+ argv.splice(0, 2);
62
+ }
63
+ if (argv.includes('--')) {
64
+ argv = argv.slice(argv.indexOf('--') + 1, argv.length);
65
+ }
60
66
  this.runFile(filePath, options, argv)
61
67
  },
62
68
  conf(command, fullPath, key, value) {
@@ -190,7 +196,7 @@ module.exports = {
190
196
  });
191
197
  r = path.resolve(root, c.exec.entry.replace(new RegExp(path.extname(c.exec.entry).replace('.', '\\.') + '$'), options.translate ? '.js' : '.qrew'));
192
198
  }
193
- this.runFileWithArgv(r);
199
+ this.runFileWithArgv(r, { async: !process.stdin.isTTY });
194
200
  }
195
201
  };
196
202
 
@@ -542,5 +548,19 @@ module.exports = {
542
548
  fs.mkdirSync(binpath, { recursive: true });
543
549
  fs.mkdirSync(cachepath, { recursive: true });
544
550
  fs.mkdirSync(logspath, { recursive: true });
551
+ },
552
+ getAllPipeInput(){
553
+ return new Promise((resolve) => {
554
+ let data = '';
555
+ process.stdin.setEncoding('utf8');
556
+
557
+ process.stdin.on('data', (chunk) => {
558
+ data += chunk;
559
+ });
560
+
561
+ process.stdin.on('end', () => {
562
+ resolve(data);
563
+ });
564
+ });
545
565
  }
546
566
  };
@@ -304,6 +304,14 @@ class Page extends Node {
304
304
  el.style.setProperty(i, value[i]);
305
305
  }
306
306
  return;
307
+ } else if(key.startsWith('on')){
308
+ if(!el.listeners) el.listeners = [];
309
+ if(el.listeners.includes(value)) return;
310
+ el.listeners.push(value);
311
+ el.addEventListener(key.replace('on', '').toLowerCase(), (event) => {
312
+ new Function('event', value).call(event.target, event);
313
+ });
314
+ return;
307
315
  }
308
316
  el.setAttribute(key, defVal);
309
317
  }
@@ -443,9 +451,9 @@ module.exports = (context, importOptions) => {
443
451
  state(value) {
444
452
  return new State(value);
445
453
  }
446
- useState(states, callback){
447
- const statesMapped = states.map(i => `getState('${i.id}')`);
448
- return `((${callback})(...[${statesMapped}]))`;
454
+ invokeState(states, callback){
455
+ const statesMapped = states.map(i => i instanceof State ? `getState('${i.id}')` : JSON.stringify(i));
456
+ return `((${callback})(event, ...[${statesMapped}]))`;
449
457
  }
450
458
  async bundle(filepath, options = {}) {
451
459
  const virtualModuleId = `virtual:${filepath}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@makano/rew",
3
- "version": "1.2.58",
3
+ "version": "1.2.61",
4
4
  "description": "A simple coffescript runtime and app manager",
5
5
  "main": "main.js",
6
6
  "directories": {
package/runtime.d.ts CHANGED
@@ -492,7 +492,7 @@ declare class ModuleWeb {
492
492
 
493
493
  state(value): ModuleWebState | any;
494
494
  // @ts-ignore
495
- useState(states: State[], callback: CallableFunction): any;
495
+ invokeState(states: State[], callback: CallableFunction): any;
496
496
 
497
497
  bundle(filePath: string, options?: Record<string, any>): string;
498
498
  }