@makano/rew 1.2.44 → 1.2.47

Sign up to get free protection for your applications and to get access to all the features.
@@ -48,6 +48,11 @@ yargs(hideBin(process.argv))
48
48
  alias: 'w',
49
49
  describe: 'Watch the file for changes',
50
50
  type: 'boolean',
51
+ })
52
+ .option('compile', {
53
+ alias: 'c',
54
+ describe: 'Compile and output the javascript',
55
+ type: 'boolean',
51
56
  });
52
57
  },
53
58
  (argv) => {
@@ -56,7 +61,7 @@ yargs(hideBin(process.argv))
56
61
  log('File not found:'.red.bold, argv.file, ':end');
57
62
  return;
58
63
  }
59
- utils.runFileWithArgv(filePath, { watch: argv.watch });
64
+ utils.runFileWithArgv(filePath, { onlyCompile: argv.compile, watch: argv.watch });
60
65
  },
61
66
  )
62
67
  .command(
@@ -1,8 +1,8 @@
1
1
  // run.js
2
2
  const { run } = require('../main');
3
3
 
4
- function exec(filePath, argv) {
5
- return run(filePath, { argv })?.context?.module?.imports || [];
4
+ function exec(filePath, argv, options = {}) {
5
+ return run(filePath, { argv, ...options })?.context?.module?.imports || [];
6
6
  }
7
7
 
8
8
  module.exports = { execRewFile: exec };
@@ -35,7 +35,7 @@ module.exports = {
35
35
 
36
36
  const runIt = () => {
37
37
  if (options.watch) console.clear();
38
- const imports = execRewFile(filePath, [filePath, ...(argv || [])]);
38
+ const imports = execRewFile(filePath, [filePath, ...(argv || [])], { onlyCompile: options?.onlyCompile });
39
39
  if (options.watch) {
40
40
  imports.forEach((file) => {
41
41
  watchIt(file);
@@ -64,15 +64,19 @@ module.exports = {
64
64
  if (!fullPath || fullPath == 'list') {
65
65
  return fs.readdirSync(con.CONFIG_PATH).join('\n');
66
66
  } else {
67
- const name = fullPath.indexOf('/') ? fullPath.split('/')[0] : fullPath;
68
- const dpath = fullPath.indexOf('/') ? fullPath.split('/').slice(1).join('/') : '';
67
+ let name = fullPath.indexOf('/') ? fullPath.split('/')[0] : fullPath;
68
+ let dpath = fullPath.indexOf('/') ? fullPath.split('/').slice(1).join('/') : '';
69
+ if(fullPath.startsWith('/')){
70
+ dpath = name;
71
+ name = '';
72
+ }
69
73
  const root = con.create(name);
70
74
  if (dpath) {
71
75
  const fp = path.join(root.root, dpath);
72
- if (fs.existsSync(fp) && fs.statSync(fp).isDirectory()) {
76
+ if (!fullPath.startsWith('/') && fs.existsSync(fp) && fs.statSync(fp).isDirectory()) {
73
77
  return fs.readdirSync(fp).join('\n');
74
78
  } else {
75
- const o = con.create(name).optionCenter(dpath);
79
+ const o = dpath && dpath !== '/' ? root.optionCenter(dpath) : root.optionCenter('_default');
76
80
  return key ? o.get(key) : o.getAll(true);
77
81
  }
78
82
  } else {
@@ -80,14 +84,18 @@ module.exports = {
80
84
  }
81
85
  }
82
86
  } else {
83
- const name = fullPath.indexOf('/') ? fullPath.split('/')[0] : fullPath;
84
- const dpath = fullPath.indexOf('/') ? fullPath.split('/')[1] : '';
85
- if (name && key) {
87
+ let name = fullPath.indexOf('/') ? fullPath.split('/')[0] : fullPath;
88
+ let dpath = fullPath.indexOf('/') ? fullPath.split('/')[1] : '';
89
+ if(fullPath.startsWith('/')){
90
+ dpath = name == '/' ? '_default' : name;
91
+ name = '';
92
+ }
93
+ if (key) {
86
94
  const root = con.create(name);
87
95
  const o = dpath ? root.optionCenter(dpath) : root;
88
96
  if (command == 'set') {
89
97
  if (value) {
90
- o.set(key, value);
98
+ o.set(key, value == 'false' || value == 'true' ? (value == 'true' ? true : false) : !isNaN(parseFloat(value)) ? parseFloat(value) : value);
91
99
  } else {
92
100
  log('Value not specified', ':end');
93
101
  }
@@ -95,7 +103,7 @@ module.exports = {
95
103
  o.remove(key);
96
104
  }
97
105
  } else {
98
- log(!name ? 'Path not specified' : 'Key not specified', ':end');
106
+ log('Key not specified', ':end');
99
107
  }
100
108
  }
101
109
  },
@@ -222,7 +230,6 @@ module.exports = {
222
230
  }
223
231
  execSync(`cp -r ${apppath} ${installPath}`);
224
232
  execSync(`chmod 444 ${installPath}/app.yaml`);
225
- log(' Installed '.green + pname.cyan.bold, ':end');
226
233
  if (c.install) {
227
234
  if (c.install.commands) {
228
235
  for (let command of c.install.commands) {
@@ -231,7 +238,7 @@ module.exports = {
231
238
  } catch(e){
232
239
  const logFile = path.join(logspath, 'logs-'+Date.now()+'.log');
233
240
  fs.writeFileSync(logFile, e.toString() +'\n'+ e.stack);
234
- log(` Command Failed: ${command}, check logs at ${logFile}`, ':end');
241
+ log(` Command Failed: ${command}, check logs at ${logFile}`);
235
242
  }
236
243
  }
237
244
  }
@@ -243,18 +250,25 @@ module.exports = {
243
250
  }
244
251
  if (c.install.exec) {
245
252
  // this.installReq(c);
246
- for (let i in c.install.exec) {
247
- let iff = c.install.exec[i];
248
- if (iff in c.exec) iff = c.exec[iff];
249
- const file = path.join(installPath, iff);
250
- const filepath = path.join(binpath, i);
251
- const binfp = path.join(localBinPath, i);
252
- if (!fs.existsSync(localBinPath)) fs.mkdirSync(localBinPath, { recursive: true });
253
- fs.writeFileSync(filepath, `#!/usr/bin/env bash\n#@app.${pname}\nrew ${file} $*`);
254
- fs.chmodSync(filepath, '755');
255
- fs.linkSync(filepath, binfp);
253
+ if(conf({}).create('').get('executables') == false){
254
+ log(' Ignoring executables'.blue);
255
+ } else {
256
+ for (let i in c.install.exec) {
257
+ let iff = c.install.exec[i];
258
+ if (iff in c.exec) iff = c.exec[iff];
259
+ const file = path.join(installPath, iff);
260
+ const filepath = path.join(binpath, i);
261
+ const binfp = path.join(localBinPath, i);
262
+ if (!fs.existsSync(localBinPath)) fs.mkdirSync(localBinPath, { recursive: true });
263
+ fs.writeFileSync(filepath, `#!/usr/bin/env bash\n#@app.${pname}\nrew ${file} $*`);
264
+ fs.chmodSync(filepath, '755');
265
+ if(fs.existsSync(binfp)) fs.unlinkSync(binfp);
266
+ fs.linkSync(filepath, binfp);
267
+ }
256
268
  }
257
269
  }
270
+
271
+ log(' Installed '.green + pname.cyan.bold, ':end');
258
272
  }
259
273
  rl.close();
260
274
  } else {
@@ -145,6 +145,15 @@ function compileRewStuff(content, options) {
145
145
  continue;
146
146
  }
147
147
 
148
+
149
+ if (token.type === 'IDENTIFIER' && token.value === 'let') {
150
+ result += '`'
151
+ hooks.push({
152
+ index: fnextToken(i, tokens, 'OTHER', ';').ti,
153
+ value: `\``,
154
+ });
155
+ }
156
+
148
157
  if (token.type === 'IDENTIFIER' && token.value === 'import') {
149
158
  // console.log(nextToken.type);
150
159
  let ind = i + n + 2;
@@ -254,13 +263,20 @@ const cpl = (module.exports.compile = function (file, options = {}) {
254
263
 
255
264
  module.exports.compileFile = function (filepath, options = {}) {
256
265
  const f = getFile(filepath);
266
+ let qrew = false;
257
267
 
258
268
  if(options.qrew || path.extname(filepath) == '.qrew') {
269
+ qrew = true
259
270
  f.content = from_qrew(readFileSync(f.path), options.package || findAppInfo(filepath)?.config.manifest.package || path.basename(filepath).split('.').slice(0, -1).join('.')).toString();
260
- }
271
+ }
261
272
 
262
273
  let compiled_code = cpl(f, { ...options });
263
274
 
275
+ if(options.onlyCompile && !qrew){
276
+ console.log(compiled_code);
277
+ process.exit();
278
+ }
279
+
264
280
  return {
265
281
  compiled_code,
266
282
  file: f,
@@ -82,7 +82,7 @@ module.exports = (context) => ({
82
82
  };
83
83
 
84
84
  return {
85
- get: (key, defaultValue) => getData(optionCenter, key) || defaultValue,
85
+ get: (key, defaultValue) => getData(optionCenter, key) ?? defaultValue,
86
86
  set: (key, value) => setData(optionCenter, key, value),
87
87
  remove: (key) => removeData(optionCenter, key),
88
88
  reset: () => fs.writeFileSync(optionCenter.root, dumpYaml(defaults)) && (conf[name] = defaults),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@makano/rew",
3
- "version": "1.2.44",
3
+ "version": "1.2.47",
4
4
  "description": "A simple coffescript runtime and app manager",
5
5
  "main": "main.js",
6
6
  "directories": {