@makano/rew 1.2.69 → 1.2.71

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.
package/lib/civet/main.js CHANGED
@@ -438,11 +438,11 @@ ${input.slice(result.pos)}
438
438
  hint = JSON.stringify(hint);
439
439
  else
440
440
  hint = "EOF";
441
- const error = new ParseError2("Failed to parse", `Expected:
442
- ${expectations.join("\n ")}
443
- Found: ${hint}
444
- `, filename2, line, column, maxFailPos);
445
- throw error;
441
+ // const error = new ParseError2("Failed to parse", `Expected:
442
+ // ${expectations.join("\n ")}
443
+ // Found: ${hint}
444
+ // `, filename2, line, column, maxFailPos);
445
+ throw new SyntaxError(`Unexpected Token at ${filename2}:${line}:${column}.\nFound: ${hint}\nExpected: ${expectations.join("\n ")}`);
446
446
  }
447
447
  if (result) {
448
448
  throw new Error(`
@@ -1,31 +1,21 @@
1
1
  #!/usr/bin/env node
2
2
 
3
+ const colors = require('colors');
3
4
  const yargs = require('yargs/yargs');
4
5
  const path = require('path');
5
6
  const { hideBin } = require('yargs/helpers');
6
- const { execSync } = require('child_process');
7
- const utils = require('./utils');
8
- const { existsSync, readFileSync, writeFileSync, mkdirSync, statSync, unlinkSync } = require('fs');
7
+ const { existsSync, readFileSync, writeFileSync, statSync, unlinkSync } = require('fs');
9
8
  const { log } = require('./log');
10
- const os = require('os');
11
- const crypto = require('crypto');
12
- const { CONFIG_PATH } = require('../const/config_path');
13
9
  const rune = require('../pkgs/rune');
14
10
  const { to_qrew, from_qrew } = require('../qrew/compile');
15
11
  const { findAppInfo } = require('../misc/findAppInfo');
16
- const { print, input } = require('../functions/stdout');
17
- const colors = require('colors');
12
+ const { input } = require('../functions/stdout');
18
13
  const { req } = require('../misc/req');
19
14
  const { gen_key } = require('../misc/bin');
20
15
  const { REW_FILE_TYPE } = require('../const/ext');
21
16
  const { generateRandomID } = require('../functions/id');
22
-
23
- if (!existsSync(CONFIG_PATH) || !existsSync(CONFIG_PATH + '/repos.yaml')) {
24
- mkdirSync(CONFIG_PATH, { recursive: true });
25
- utils.initFirst();
26
- }
27
-
28
- const npm_package_name = '@makano/rew';
17
+ const { runFileWithArgv } = require('./run');
18
+ const { npm_package_name, getAllPipeInput } = require('./helpers');
29
19
 
30
20
  function isFileArgument(file) {
31
21
  try {
@@ -36,6 +26,7 @@ function isFileArgument(file) {
36
26
  }
37
27
 
38
28
  const isFileGiven = isFileArgument(hideBin(process.argv)[0]) || hideBin(process.argv)[0] == 'run';
29
+ try{
39
30
  yargs(hideBin(process.argv))
40
31
  .command(
41
32
  '$0 <file>',
@@ -63,7 +54,7 @@ yargs(hideBin(process.argv))
63
54
  log('File not found:'.red.bold, argv.file, ':end');
64
55
  return;
65
56
  }
66
- utils.runFileWithArgv(filePath, { async: !process.stdin.isTTY, onlyCompile: argv.compile, watch: argv.watch });
57
+ runFileWithArgv(filePath, { async: !process.stdin.isTTY, onlyCompile: argv.compile, watch: argv.watch });
67
58
  },
68
59
  )
69
60
  .command(
@@ -81,11 +72,11 @@ yargs(hideBin(process.argv))
81
72
  const replFile = '/tmp/rew-'+generateRandomID()+'-'+Date.now()+'.coffee';
82
73
  let code = argv.code;
83
74
  if(!process.stdin.isTTY) {
84
- code = await utils.getAllPipeInput();
75
+ code = await getAllPipeInput();
85
76
  }
86
77
  writeFileSync(replFile, code);
87
78
  try{
88
- utils.runFileWithArgv(replFile, { async: !process.stdin.isTTY, onlyCompile: argv.compile });
79
+ runFileWithArgv(replFile, { async: !process.stdin.isTTY, onlyCompile: argv.compile });
89
80
  } catch(e){
90
81
  console.error(e);
91
82
  } finally {
@@ -121,7 +112,7 @@ yargs(hideBin(process.argv))
121
112
  },
122
113
  (argv) => {
123
114
  const { command, path, key, value } = argv;
124
- const result = utils.conf(command, path, key, value);
115
+ const result = require('./utils').conf(command, path, key, value);
125
116
  if (result) console.log(result);
126
117
  },
127
118
  )
@@ -135,7 +126,7 @@ yargs(hideBin(process.argv))
135
126
  });
136
127
  },
137
128
  (argv) => {
138
- utils.createProject(argv.path);
129
+ require('./utils').createProject(argv.path);
139
130
  },
140
131
  )
141
132
  .command(
@@ -176,7 +167,7 @@ yargs(hideBin(process.argv))
176
167
  });
177
168
  },
178
169
  (argv) => {
179
- utils.runApp(argv.path, argv);
170
+ require('./utils').runApp(argv.path, argv);
180
171
  },
181
172
  )
182
173
  .command(
@@ -272,8 +263,8 @@ yargs(hideBin(process.argv))
272
263
  });
273
264
  },
274
265
  async (argv) => {
275
- if (argv.requirements) utils.installReq(argv.path, argv);
276
- else utils.installAppFrom(argv.path, argv);
266
+ if (argv.requirements) require('./utils').installReq(argv.path, argv);
267
+ else require('./utils').installAppFrom(argv.path, argv);
277
268
  },
278
269
  )
279
270
  .command(
@@ -290,7 +281,7 @@ yargs(hideBin(process.argv))
290
281
  });
291
282
  },
292
283
  async (argv) => {
293
- utils.uninstall(argv.package, argv.all);
284
+ require('./utils').uninstall(argv.package, argv.all);
294
285
  },
295
286
  )
296
287
  .command(
@@ -329,7 +320,7 @@ yargs(hideBin(process.argv))
329
320
  });
330
321
  },
331
322
  async (argv) => {
332
- utils.cache(argv.command)
323
+ require('./utils').cache(argv.command)
333
324
  },
334
325
  )
335
326
  .command(
@@ -354,7 +345,7 @@ yargs(hideBin(process.argv))
354
345
  });
355
346
  },
356
347
  async (argv) => {
357
- utils.repo(argv.command, argv.name, argv.url, argv);
348
+ require('./utils').repo(argv.command, argv.name, argv.url, argv);
358
349
  },
359
350
  )
360
351
  .command(
@@ -388,7 +379,11 @@ yargs(hideBin(process.argv))
388
379
  });
389
380
  },
390
381
  (argv) => {
391
- utils.build(argv);
382
+ require('./utils').build(argv);
392
383
  },
393
384
  )
394
- .help(!isFileGiven).argv;
385
+ .help(!isFileGiven).argv;
386
+ } catch(e) {
387
+ console.error(e);
388
+ process.exit(1);
389
+ }
@@ -0,0 +1,44 @@
1
+ const { CONFIG_PATH } = require("../const/config_path");
2
+ const path = require('path');
3
+ const fs = require('fs');
4
+ const conf = require("../pkgs/conf");
5
+
6
+ const binpath = path.join(conf({}).create('').root, '.bin');
7
+ const logspath = path.join(conf({}).create('').root, '.logs');
8
+ const cachepath = path.join(conf({}).create('').root, '.cache');
9
+ const localBinPath = path.join(binpath, '../../../', 'bin');
10
+
11
+ if (!fs.existsSync(CONFIG_PATH) || !fs.existsSync(CONFIG_PATH + '/repos.yaml')) {
12
+ fs.mkdirSync(CONFIG_PATH, { recursive: true });
13
+ log('First time init');
14
+ conf({}).create('').optionCenter('repos').set('rewpkgs', '//raw.githubusercontent.com/kevinJ045/rewpkgs/main/main.yaml');
15
+ fs.mkdirSync(binpath, { recursive: true });
16
+ fs.mkdirSync(cachepath, { recursive: true });
17
+ fs.mkdirSync(logspath, { recursive: true });
18
+ }
19
+
20
+ const npm_package_name = '@makano/rew';
21
+
22
+ function getAllPipeInput(){
23
+ return new Promise((resolve) => {
24
+ let data = '';
25
+ process.stdin.setEncoding('utf8');
26
+
27
+ process.stdin.on('data', (chunk) => {
28
+ data += chunk;
29
+ });
30
+
31
+ process.stdin.on('end', () => {
32
+ resolve(data);
33
+ });
34
+ });
35
+ }
36
+
37
+ module.exports = {
38
+ binpath,
39
+ logspath,
40
+ cachepath,
41
+ localBinPath,
42
+ npm_package_name,
43
+ getAllPipeInput
44
+ }
@@ -1,8 +1,51 @@
1
1
  // run.js
2
+ const { REW_FILE_TYPE } = require('../const/ext');
2
3
  const { run } = require('../main');
4
+ const { watch } = require('chokidar');
3
5
 
4
6
  function exec(filePath, argv, options = {}) {
5
7
  return run(filePath, { argv, ...options })?.context?.module?.imports || [];
6
8
  }
7
9
 
8
- module.exports = { execRewFile: exec };
10
+ function runFile(filePath, options = {}, argv){
11
+ const watching = [];
12
+ const watchIt = (file) => {
13
+ if (watching.includes(file)) return;
14
+ watch(file).on('change', () => runIt());
15
+ watching.push(file);
16
+ };
17
+
18
+ const runIt = () => {
19
+ if (options.watch) console.clear();
20
+ const imports = exec(filePath, [filePath, ...(argv || [])], { onlyCompile: options?.onlyCompile, async: options?.async });
21
+ if (options.watch) {
22
+ imports.forEach((file) => {
23
+ watchIt(file);
24
+ });
25
+ watchIt(filePath);
26
+ }
27
+ };
28
+
29
+ runIt();
30
+ }
31
+
32
+ function runFileWithArgv(filePath, options = {}, cargv) {
33
+ let argv = cargv || process.argv;
34
+ argv.shift();
35
+ if (argv[0].endsWith(REW_FILE_TYPE.EXTENSION) || argv[0].endsWith('.coffee')) {
36
+ if (argv[1] == 'run') {
37
+ argv.splice(0, 3);
38
+ } else if(argv[1] == '-w' || argv[1] == '--watch'){
39
+ argv.splice(0, 3);
40
+ } else argv.splice(0, 2);
41
+ }
42
+ if (argv[1] == 'exec') {
43
+ argv.splice(0, 2);
44
+ }
45
+ if (argv.includes('--')) {
46
+ argv = argv.slice(argv.indexOf('--') + 1, argv.length);
47
+ }
48
+ runFile(filePath, options, argv);
49
+ }
50
+
51
+ module.exports = { runFileWithArgv, runFile, execRewFile: exec };
@@ -13,58 +13,21 @@ const { findAppInfo } = require('../misc/findAppInfo');
13
13
  const { req } = require('../misc/req');
14
14
  const { CONFIG_PATH } = require('../const/config_path');
15
15
  const { watch } = require('chokidar');
16
- const { execRewFile } = require('./run');
16
+ const { execRewFile, runFileWithArgv } = require('./run');
17
17
  const { seededID } = require('../misc/seededid');
18
18
  const loading = require('loading-cli');
19
19
  const sleep = require('../functions/sleep');
20
20
  const { gen_key } = require('../misc/bin');
21
21
  const { REW_FILE_TYPE } = require('../const/ext');
22
22
 
23
- const binpath = path.join(conf({}).create('').root, '.bin');
24
- const logspath = path.join(conf({}).create('').root, '.logs');
25
- const cachepath = path.join(conf({}).create('').root, '.cache');
26
- const localBinPath = path.join(binpath, '../../../', 'bin');
23
+ const {
24
+ binpath,
25
+ logspath,
26
+ cachepath,
27
+ localBinPath
28
+ } = require('./helpers');
27
29
 
28
30
  module.exports = {
29
- runFile(filePath, options = {}, argv) {
30
- const watching = [];
31
- const watchIt = (file) => {
32
- if (watching.includes(file)) return;
33
- watch(file).on('change', () => runIt());
34
- watching.push(file);
35
- };
36
-
37
- const runIt = () => {
38
- if (options.watch) console.clear();
39
- const imports = execRewFile(filePath, [filePath, ...(argv || [])], { onlyCompile: options?.onlyCompile, async: options?.async });
40
- if (options.watch) {
41
- imports.forEach((file) => {
42
- watchIt(file);
43
- });
44
- watchIt(filePath);
45
- }
46
- };
47
-
48
- runIt();
49
- },
50
- runFileWithArgv(filePath, options = {}, cargv) {
51
- let argv = cargv || process.argv;
52
- argv.shift();
53
- if (argv[0].endsWith(REW_FILE_TYPE.EXTENSION) || argv[0].endsWith('.coffee')) {
54
- if (argv[1] == 'run') {
55
- argv.splice(0, 3);
56
- } else if(argv[1] == '-w' || argv[1] == '--watch'){
57
- argv.splice(0, 3);
58
- } else argv.splice(0, 2);
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
- }
66
- this.runFile(filePath, options, argv)
67
- },
68
31
  conf(command, fullPath, key, value) {
69
32
  const con = conf({});
70
33
  if (command == 'get') {
@@ -196,7 +159,7 @@ module.exports = {
196
159
  });
197
160
  r = path.resolve(root, c.exec.entry.replace(new RegExp(path.extname(c.exec.entry).replace('.', '\\.') + '$'), options.translate ? '.js' : '.qrew'));
198
161
  }
199
- this.runFileWithArgv(r, { async: !process.stdin.isTTY });
162
+ runFileWithArgv(r, { async: !process.stdin.isTTY });
200
163
  }
201
164
  };
202
165
 
@@ -208,6 +171,9 @@ module.exports = {
208
171
  const appConfpath = path.join(apppath, 'app.yaml');
209
172
  if (fs.existsSync(apppath) && fs.existsSync(appConfpath)) {
210
173
  runAppRoot(apppath, appConfpath);
174
+ } else {
175
+ log('App does not exist'.red.bold, ':end');
176
+ process.exit(1);
211
177
  }
212
178
  }
213
179
  },
@@ -267,7 +233,7 @@ module.exports = {
267
233
  this.installReq(c, opts);
268
234
  }
269
235
  if (c.install.file) {
270
- this.runFileWithArgv(path.join(installPath, c.exec[c.install.file] || c.install.file), {}, [installPath]);
236
+ runFileWithArgv(path.join(installPath, c.exec[c.install.file] || c.install.file), {}, [installPath]);
271
237
  }
272
238
  if (c.install.exec) {
273
239
  // this.installReq(c);
@@ -281,7 +247,7 @@ module.exports = {
281
247
  const filepath = path.join(binpath, i);
282
248
  const binfp = path.join(localBinPath, i);
283
249
  if (!fs.existsSync(localBinPath)) fs.mkdirSync(localBinPath, { recursive: true });
284
- fs.writeFileSync(filepath, `#!/usr/bin/env bash\n#@app.${pname}\nrew ${file} $*`);
250
+ fs.writeFileSync(filepath, `#!/usr/bin/env bash\n#@app.${pname}\nrew ${file} -- $*`);
285
251
  fs.chmodSync(filepath, '755');
286
252
  if(fs.existsSync(binfp)) fs.unlinkSync(binfp);
287
253
  fs.linkSync(filepath, binfp);
@@ -561,26 +527,5 @@ module.exports = {
561
527
  } else {
562
528
  log(' Invalid command'.red.bold, ':end');
563
529
  }
564
- },
565
- initFirst() {
566
- log('First time init')
567
- conf({}).create('').optionCenter('repos').set('rewpkgs', '//raw.githubusercontent.com/kevinJ045/rewpkgs/main/main.yaml');
568
- fs.mkdirSync(binpath, { recursive: true });
569
- fs.mkdirSync(cachepath, { recursive: true });
570
- fs.mkdirSync(logspath, { recursive: true });
571
- },
572
- getAllPipeInput(){
573
- return new Promise((resolve) => {
574
- let data = '';
575
- process.stdin.setEncoding('utf8');
576
-
577
- process.stdin.on('data', (chunk) => {
578
- data += chunk;
579
- });
580
-
581
- process.stdin.on('end', () => {
582
- resolve(data);
583
- });
584
- });
585
530
  }
586
531
  };
@@ -5,7 +5,9 @@ module.exports.wait = (...args) => {
5
5
  const fn = args.shift();
6
6
  if(typeof fn !== "function") throw new TypeError("The first argument must be a function to use wait.");
7
7
  const df = deasync(async (cb) => {
8
- cb(null, await fn(...args));
8
+ fn(...args)
9
+ .then(d => cb(null, d))
10
+ .catch(d => cb(d));
9
11
  });
10
12
  return df();
11
13
  }
@@ -293,14 +293,13 @@ const compileCivetStuff = (file, options) => {
293
293
  const compileOptions = {
294
294
  ...options,
295
295
  bare: true,
296
- filename: file.content,
296
+ filename: file.path,
297
297
  inlineMap: false,
298
298
  js: true
299
299
  };
300
300
 
301
301
  const prepared = compileRewStuff(file.content, options);
302
-
303
- const compiled = options.async ? compileCivet(prepared, compileOptions) : wait(compileCivet, prepared, compileOptions);
302
+ let compiled = options.async ? compileCivet(prepared, compileOptions) : wait(compileCivet, prepared, compileOptions);
304
303
 
305
304
  return {
306
305
  compiled,
@@ -9,6 +9,7 @@ const path = require("path");
9
9
  const execLib = require("../functions/exec");
10
10
  const { findAppInfo } = require("../misc/findAppInfo");
11
11
  const { USING_DEFAULT, Usage, Namespace } = require("../const/usage");
12
+ const runtime = require("./runtime");
12
13
 
13
14
  let mainFile = "";
14
15
  const isMainFile = (filepath) => filepath == mainFile;
@@ -114,9 +115,8 @@ module.exports.prepareContext = function (
114
115
  const childContext = {...context, ...name.namespace, trigger};
115
116
  childContext.currentNamespace = name.namespace;
116
117
  childContext.parentNamespace = context;
117
- with(childContext){
118
- eval(`(${trigger.toString()})()`);
119
- }
118
+ const code = `(${trigger.toString()})()`;
119
+ runtime.exec(code, childContext, code, context.module.filepath);
120
120
  } else if(name instanceof Usage) {
121
121
  const v = name.trigger(...params) || true;
122
122
  if(name.save !== false) context.__using__[name.name] = v;
@@ -7,9 +7,9 @@ const path = require('path');
7
7
 
8
8
  const preScript = readFileSync(path.join(__dirname, '../const/pre-exec.js'), { encoding: 'utf-8' });
9
9
 
10
- const exec = (module.exports.exec = function (code, context, original = '') {
10
+ const exec = (module.exports.exec = function (code, context, original = '', filepath) {
11
11
  return vm.runInNewContext(code, context.do ? null : vm.createContext(context), {
12
- filename: context.module.filepath,
12
+ filename: filepath || context.module.filepath,
13
13
  lineOffset: (original.split('\n').length + preScript.split('\n').length) - code.split('\n').length,
14
14
  displayErrors: true,
15
15
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@makano/rew",
3
- "version": "1.2.69",
3
+ "version": "1.2.71",
4
4
  "description": "A simple coffescript runtime and app manager",
5
5
  "main": "main.js",
6
6
  "directories": {