@makano/rew 1.2.3 → 1.2.5

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/bin/rew CHANGED
@@ -1,2 +1,3 @@
1
1
  #!/usr/bin/env node
2
+ global.fileName = __filename;
2
3
  require("../lib/rew/cli/cli.js");
package/jsconfig.json ADDED
@@ -0,0 +1,13 @@
1
+ {
2
+ "compilerOptions": {
3
+ "checkJs": true,
4
+ "lib": ["ESNext"],
5
+ "module": "Node16"
6
+ },
7
+ "include": [
8
+ "./runtime.d.ts"
9
+ ],
10
+ "typeAcquisition": {
11
+ "include": ["./runtime.d.ts"]
12
+ }
13
+ }
@@ -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 } = require('fs');
8
+ const { existsSync, readFileSync, writeFileSync, mkdirSync, statSync } = require('fs');
9
9
  const { log } = require('./log');
10
10
  const os = require('os');
11
11
  const crypto = require('crypto');
@@ -18,13 +18,22 @@ const colors = require('colors');
18
18
  const { req } = require('../misc/req');
19
19
  const { gen_key } = require('../misc/bin');
20
20
 
21
- if (!existsSync(CONFIG_PATH)) {
21
+ if (!existsSync(CONFIG_PATH) || !existsSync(CONFIG_PATH + '/repos.yaml')) {
22
22
  mkdirSync(CONFIG_PATH, { recursive: true });
23
23
  utils.initFirst();
24
24
  }
25
25
 
26
26
  const npm_package_name = '@makano/rew';
27
27
 
28
+ function isFileArgument(file) {
29
+ try {
30
+ return existsSync(file) && statSync(file).isFile();
31
+ } catch {
32
+ return false;
33
+ }
34
+ }
35
+
36
+ const isFileGiven = isFileArgument(hideBin(process.argv)[0]) || hideBin(process.argv)[0] == 'run';
28
37
  yargs(hideBin(process.argv))
29
38
  .command(
30
39
  '$0 <file>',
@@ -39,6 +48,11 @@ yargs(hideBin(process.argv))
39
48
  alias: 'w',
40
49
  describe: 'Watch the file for changes',
41
50
  type: 'boolean',
51
+ })
52
+ .option('compile', {
53
+ alias: 'c',
54
+ describe: 'Compile and output the javascript',
55
+ type: 'boolean',
42
56
  });
43
57
  },
44
58
  (argv) => {
@@ -47,7 +61,7 @@ yargs(hideBin(process.argv))
47
61
  log('File not found:'.red.bold, argv.file, ':end');
48
62
  return;
49
63
  }
50
- utils.runFileWithArgv(filePath, { watch: argv.watch });
64
+ utils.runFileWithArgv(filePath, { onlyCompile: argv.compile, watch: argv.watch });
51
65
  },
52
66
  )
53
67
  .command(
@@ -112,25 +126,25 @@ yargs(hideBin(process.argv))
112
126
  describe: 'Path of the app to run',
113
127
  type: 'string',
114
128
  })
115
- .option('dev', {
116
- describe: 'If your entry file is a .qrew, then just use the .coffee instead',
117
- type: 'boolean',
118
- })
119
- .option('entry', {
120
- alias: 'e',
121
- describe: 'Choose entry file from app.config.exec',
122
- type: 'string',
123
- })
124
- .option('build', {
125
- alias: 'b',
126
- describe: 'Builds to a .qrew before running',
127
- type: 'boolean',
128
- })
129
- .option('translate', {
130
- alias: 't',
131
- describe: 'Builds to a .js before running, only used when --build is passed',
132
- type: 'boolean',
133
- });
129
+ .option('dev', {
130
+ describe: 'If your entry file is a .qrew, then just use the .coffee instead',
131
+ type: 'boolean',
132
+ })
133
+ .option('entry', {
134
+ alias: 'e',
135
+ describe: 'Choose entry file from app.config.exec',
136
+ type: 'string',
137
+ })
138
+ .option('build', {
139
+ alias: 'b',
140
+ describe: 'Builds to a .qrew before running',
141
+ type: 'boolean',
142
+ })
143
+ .option('translate', {
144
+ alias: 't',
145
+ describe: 'Builds to a .js before running, only used when --build is passed',
146
+ type: 'boolean',
147
+ });
134
148
  },
135
149
  (argv) => {
136
150
  utils.runApp(argv.path, argv);
@@ -141,16 +155,16 @@ yargs(hideBin(process.argv))
141
155
  'Add secrets to the current path',
142
156
  (yargs) => {
143
157
  yargs
144
- .positional('command', {
145
- describe: 'Path of the app to run',
146
- type: 'string',
147
- })
148
- .option('file', {
149
- alias: 'f',
150
- describe: 'Set file name',
151
- type: 'string',
152
- default: 'secrets.qrew'
153
- })
158
+ .positional('command', {
159
+ describe: 'Path of the app to run',
160
+ type: 'string',
161
+ })
162
+ .option('file', {
163
+ alias: 'f',
164
+ describe: 'Set file name',
165
+ type: 'string',
166
+ default: 'secrets.qrew'
167
+ })
154
168
  },
155
169
  (argv) => {
156
170
  const appPath = findAppInfo(path.join(process.cwd(), 'app.yaml'));
@@ -214,11 +228,23 @@ yargs(hideBin(process.argv))
214
228
  alias: 'r',
215
229
  describe: 'Install requirements of the app',
216
230
  type: 'boolean',
231
+ }).option('verbose', {
232
+ alias: 'v',
233
+ describe: 'Verbose',
234
+ type: 'boolean',
235
+ }).option('update', {
236
+ alias: 'u',
237
+ describe: 'Update the app',
238
+ type: 'boolean',
239
+ }).option('yes', {
240
+ alias: 'y',
241
+ describe: 'Auto yes',
242
+ type: 'boolean',
217
243
  });
218
244
  },
219
245
  async (argv) => {
220
- if(argv.requirements) utils.installReq(argv.path);
221
- else utils.installAppFrom(argv.path);
246
+ if (argv.requirements) utils.installReq(argv.path, argv);
247
+ else utils.installAppFrom(argv.path, argv);
222
248
  },
223
249
  )
224
250
  .command(
@@ -246,9 +272,9 @@ yargs(hideBin(process.argv))
246
272
  async (argv) => {
247
273
  const pkg = JSON.parse(readFileSync(path.resolve(__dirname, '../../../package.json'), { encoding: 'utf-8' }));
248
274
  const getLatest = async () => {
249
- try{
275
+ try {
250
276
  return (await req(`https://registry.npmjs.org/${pkg.name}`)).data['dist-tags'].latest
251
- } catch(e) {
277
+ } catch (e) {
252
278
  return `(${'!err'.blue.bgRed}, see ${`https://npmjs.com/package/${pkg.name}`.blue.underline})`;
253
279
  }
254
280
  }
@@ -257,12 +283,26 @@ yargs(hideBin(process.argv))
257
283
  const latest = await getLatest();
258
284
  const isLatest = latest === pkg.version;
259
285
  log(`Latest: ${pkg.name.cyan.bold}@${latest.yellow.bold}`.green.bold, isLatest ? ':end' : '');
260
- if(!isLatest){
286
+ if (!isLatest) {
261
287
  log(`There is an update available`.cyan.bold);
262
288
  log('Update With:'.yellow, `npm i -g ${npm_package_name}`.green.bold, ':end');
263
289
  }
264
290
  },
265
291
  )
292
+
293
+ .command(
294
+ 'cache <command>',
295
+ 'Manage cache',
296
+ (yargs) => {
297
+ yargs.positional('command', {
298
+ describe: 'Command to clear/list',
299
+ type: 'string',
300
+ });
301
+ },
302
+ async (argv) => {
303
+ utils.cache(argv.command)
304
+ },
305
+ )
266
306
  .command(
267
307
  'repo <command> [name] [url]',
268
308
  'Manage install repositories',
@@ -279,9 +319,13 @@ yargs(hideBin(process.argv))
279
319
  describe: 'url of the repo',
280
320
  type: 'string',
281
321
  });
322
+ yargs.option('json', {
323
+ describe: 'Return a json output',
324
+ type: 'boolean',
325
+ });
282
326
  },
283
327
  async (argv) => {
284
- utils.repo(argv.command, argv.name, argv.url);
328
+ utils.repo(argv.command, argv.name, argv.url, argv);
285
329
  },
286
330
  )
287
331
  .command(
@@ -318,4 +362,4 @@ yargs(hideBin(process.argv))
318
362
  utils.build(argv);
319
363
  },
320
364
  )
321
- .help().argv;
365
+ .help(!isFileGiven).argv;
@@ -4,6 +4,8 @@ const middlePrefix = '├';
4
4
  const separator = '│';
5
5
  const endPrefix = '╰';
6
6
 
7
+ let last = '';
8
+
7
9
  const log = (module.exports.log = function (...toPrint) {
8
10
  let prefix = start ? startPrefix : middlePrefix;
9
11
  let returns = false;
@@ -16,8 +18,10 @@ const log = (module.exports.log = function (...toPrint) {
16
18
  toPrint.pop();
17
19
  }
18
20
  if (prefix == endPrefix && start) prefix = separator;
19
- if (!start) console.log(separator);
21
+ // if(last == endPrefix && prefix == separator) prefix = startPrefix;
22
+ if (!start) console.log(last == endPrefix ? startPrefix : separator);
20
23
  if (start) start = false;
24
+ last = prefix;
21
25
  if (returns) return [prefix, ...toPrint].join(' ');
22
26
  else console.log(prefix, ...toPrint);
23
27
  });
@@ -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 };
@@ -14,8 +14,14 @@ const { req } = require('../misc/req');
14
14
  const { CONFIG_PATH } = require('../const/config_path');
15
15
  const { watch } = require('chokidar');
16
16
  const { execRewFile } = require('./run');
17
+ const { seededID } = require('../misc/seededid');
18
+ const loading = require('loading-cli');
19
+ const sleep = require('../functions/sleep');
20
+ const { gen_key } = require('../misc/bin');
17
21
 
18
22
  const binpath = path.join(conf({}).create('').root, '.bin');
23
+ const logspath = path.join(conf({}).create('').root, '.logs');
24
+ const cachepath = path.join(conf({}).create('').root, '.cache');
19
25
  const localBinPath = path.join(binpath, '../../../', 'bin');
20
26
 
21
27
  module.exports = {
@@ -29,7 +35,7 @@ module.exports = {
29
35
 
30
36
  const runIt = () => {
31
37
  if (options.watch) console.clear();
32
- const imports = execRewFile(filePath, [filePath, ...(argv || [])]);
38
+ const imports = execRewFile(filePath, [filePath, ...(argv || [])], { onlyCompile: options?.onlyCompile });
33
39
  if (options.watch) {
34
40
  imports.forEach((file) => {
35
41
  watchIt(file);
@@ -58,15 +64,19 @@ module.exports = {
58
64
  if (!fullPath || fullPath == 'list') {
59
65
  return fs.readdirSync(con.CONFIG_PATH).join('\n');
60
66
  } else {
61
- const name = fullPath.indexOf('/') ? fullPath.split('/')[0] : fullPath;
62
- 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
+ }
63
73
  const root = con.create(name);
64
74
  if (dpath) {
65
75
  const fp = path.join(root.root, dpath);
66
- if (fs.existsSync(fp) && fs.statSync(fp).isDirectory()) {
76
+ if (!fullPath.startsWith('/') && fs.existsSync(fp) && fs.statSync(fp).isDirectory()) {
67
77
  return fs.readdirSync(fp).join('\n');
68
78
  } else {
69
- const o = con.create(name).optionCenter(dpath);
79
+ const o = dpath && dpath !== '/' ? root.optionCenter(dpath) : root.optionCenter('_default');
70
80
  return key ? o.get(key) : o.getAll(true);
71
81
  }
72
82
  } else {
@@ -74,14 +84,18 @@ module.exports = {
74
84
  }
75
85
  }
76
86
  } else {
77
- const name = fullPath.indexOf('/') ? fullPath.split('/')[0] : fullPath;
78
- const dpath = fullPath.indexOf('/') ? fullPath.split('/')[1] : '';
79
- 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) {
80
94
  const root = con.create(name);
81
95
  const o = dpath ? root.optionCenter(dpath) : root;
82
96
  if (command == 'set') {
83
97
  if (value) {
84
- o.set(key, value);
98
+ o.set(key, value == 'false' || value == 'true' ? (value == 'true' ? true : false) : !isNaN(parseFloat(value)) ? parseFloat(value) : value);
85
99
  } else {
86
100
  log('Value not specified', ':end');
87
101
  }
@@ -89,7 +103,7 @@ module.exports = {
89
103
  o.remove(key);
90
104
  }
91
105
  } else {
92
- log(!name ? 'Path not specified' : 'Key not specified', ':end');
106
+ log('Key not specified', ':end');
93
107
  }
94
108
  }
95
109
  },
@@ -112,6 +126,10 @@ module.exports = {
112
126
  fs.writeFileSync(path.join(projectPath, '.gitignore'), `node_modules/\npackage-lock.json`);
113
127
  execSync('cd ' + projectPath + ' && git init . && git branch -m main', { stdio: 'ignore' });
114
128
  }
129
+ if(project.intellisense){
130
+ fs.copyFileSync(path.join(__dirname, '../../../jsconfig.json'), path.join(projectPath, 'jsconfig.json'));
131
+ fs.copyFileSync(path.join(__dirname, '../../../runtime.d.ts'), path.join(projectPath, 'runtime.d.ts'));
132
+ }
115
133
  execSync('cd ' + projectPath + ' && npm init -y', { stdio: 'ignore' });
116
134
  // log('Installing '+npm_package_name);
117
135
  // exec('cd '+projectPath+' && npm i '+npm_package_name, (err) => {
@@ -129,9 +147,12 @@ module.exports = {
129
147
  rl.question(logget(' Package Name: '.blue), (pkg) => {
130
148
  if (pkg.trim()) {
131
149
  project.package = pkg.trim();
132
- rl.question(logget('󰊢 Use git(y/N): '.yellow.bold), (use_git) => {
133
- project.git = use_git.toLowerCase() == 'y' || use_git.toLowerCase() == 'yes';
134
- create();
150
+ rl.question(logget(' Use intellisense declarations ? (y/N): '.magenta.bold), (inteli) => {
151
+ project.intellisense = inteli.toLowerCase() == 'y' || inteli.toLowerCase() == 'yes';
152
+ rl.question(logget('󰊢 Use git ? (y/N): '.yellow.bold), (use_git) => {
153
+ project.git = use_git.toLowerCase() == 'y' || use_git.toLowerCase() == 'yes';
154
+ create();
155
+ });
135
156
  });
136
157
  } else {
137
158
  rl.close();
@@ -176,7 +197,7 @@ module.exports = {
176
197
  }
177
198
  }
178
199
  },
179
- installApp(pathname, rmidir, rmidiri) {
200
+ installApp(pathname, opts, rmidir, rmidiri) {
180
201
  if (!pathname) {
181
202
  return;
182
203
  }
@@ -194,68 +215,86 @@ module.exports = {
194
215
  });
195
216
  log(' Installing '.blue + pname.green.bold);
196
217
  log(' Package'.blue + ': ' + p.name.green + '@' + p.version.yellow);
197
- if (p.descriptiondescription) {
198
- log(' Description'.blue + ': ' + p.description);
218
+ if (p.description) {
219
+ log(' Description'.blue + '\n' + p.description.split('\n').map((i, ind, a) => ' '+(ind == 0 && a.length > 1 ? log.startPrefix : (a.length-1 == ind ? log.endPrefix : log.middlePrefix))+' '+i).join('\n'), ':end');
199
220
  }
200
- rl.question(logget('Install '.blue + pname.green.bold + '? (y/N) '), (f) => {
201
- if (f.toLowerCase() == 'y') {
221
+ if (p.keywords && p.keywords.length) {
222
+ log(' Tags'.blue + '\n ' + log.endPrefix + p.keywords.map(i => '#'+i).join(' '), ':end')
223
+ }
224
+ const done = (f) => {
225
+ if (f.toLowerCase() == 'y' || f.toLowerCase() == 'yes') {
202
226
  if (fs.existsSync(installPath)) {
203
227
  execSync(`rm -r ${installPath}`);
204
228
  }
205
- execSync(`cp -r ${apppath} ${installPath}`);
206
- execSync(`chmod 444 ${installPath}/app.yaml`);
207
- if (rmidir) {
208
- execSync(`rm -r ${apppath}`);
209
- }
210
- log(' Installed '.green + pname.cyan.bold, c.install ? '' : ':end');
211
- if (c.install) {
212
- if (c.install.build) {
213
- log(' Building'.blue);
229
+ if (c.install?.build) {
230
+ log(' Building'.blue);
231
+ try{
214
232
  this.build({
215
233
  ...c.install.build,
216
- file: path.join(installPath, c.install.build.file)
234
+ file: path.join(apppath, c.exec[c.install.build.file] || c.install.build.file)
217
235
  });
218
- }
236
+ } catch(e){}
237
+ }
238
+ execSync(`cp -r ${apppath} ${installPath}`);
239
+ execSync(`chmod 444 ${installPath}/app.yaml`);
240
+ if (c.install) {
219
241
  if (c.install.commands) {
220
242
  for (let command of c.install.commands) {
221
- execSync(command.replace(/\$installPath/g, installPath));
243
+ try{
244
+ execSync(command.replace(/\$installPath/g, installPath), { stdio: 'inherit' });
245
+ } catch(e){
246
+ const logFile = path.join(logspath, 'logs-'+Date.now()+'.log');
247
+ fs.writeFileSync(logFile, e.toString() +'\n'+ e.stack);
248
+ log(` Command Failed: ${command}, check logs at ${logFile}`);
249
+ }
222
250
  }
223
251
  }
224
252
  if (c.install.file) {
225
253
  this.runFileWithArgv(path.join(installPath, c.exec[c.install.file] || c.install.file), {}, []);
226
254
  }
227
255
  if (c.install.requirements) {
228
- this.installReq(c);
256
+ this.installReq(c, opts);
229
257
  }
230
258
  if (c.install.exec) {
231
259
  // this.installReq(c);
232
- for (let i in c.install.exec) {
233
- let iff = c.install.exec[i];
234
- if (iff in c.exec) iff = c.exec[iff];
235
- const file = path.join(installPath, iff);
236
- const filepath = path.join(binpath, i);
237
- const binfp = path.join(localBinPath, i);
238
- if (!fs.existsSync(localBinPath)) fs.mkdirSync(localBinPath, { recursive: true });
239
- fs.writeFileSync(filepath, `#!/usr/bin/env bash\n#@app.${pname}\nrew ${file} $*`);
240
- fs.chmodSync(filepath, '755');
241
- fs.linkSync(filepath, binfp);
260
+ if(conf({}).create('').get('executables') == false){
261
+ log(' Ignoring executables'.blue);
262
+ } else {
263
+ for (let i in c.install.exec) {
264
+ let iff = c.install.exec[i];
265
+ if (iff in c.exec) iff = c.exec[iff];
266
+ const file = path.join(installPath, iff);
267
+ const filepath = path.join(binpath, i);
268
+ const binfp = path.join(localBinPath, i);
269
+ if (!fs.existsSync(localBinPath)) fs.mkdirSync(localBinPath, { recursive: true });
270
+ fs.writeFileSync(filepath, `#!/usr/bin/env bash\n#@app.${pname}\nrew ${file} $*`);
271
+ fs.chmodSync(filepath, '755');
272
+ if(fs.existsSync(binfp)) fs.unlinkSync(binfp);
273
+ fs.linkSync(filepath, binfp);
274
+ }
242
275
  }
243
276
  }
277
+
278
+ log(' Installed '.green + pname.cyan.bold, ':end');
244
279
  }
245
280
  rl.close();
246
281
  } else {
247
- if (rmidiri) {
248
- execSync(`rm -rf ${apppath}`);
249
- }
250
282
  log(' Canceled install'.red.bold, ':end');
251
283
  rl.close();
252
284
  }
253
- });
285
+ };
286
+ if (fs.existsSync(installPath) && !opts.update) {
287
+ rl.close();
288
+ log(` App Already Installed`.green.bold);
289
+ return log(` Run With --update or -u to update.`.green.bold, ':end');
290
+ }
291
+ if(opts.yes) done('y');
292
+ else rl.question(logget('Install '.blue + pname.green.bold + '? (y/N) '), done);
254
293
  } else {
255
294
  log(' Path is not a rew app'.red.bold, ':end');
256
295
  }
257
296
  },
258
- installReq(config) {
297
+ installReq(config, opts) {
259
298
  if (typeof config !== "object") {
260
299
  const confPath = path.join(config, './app.yaml');
261
300
  if (!fs.existsSync(confPath)) return log(' Path is not a rew app'.red.bold, ':end');
@@ -265,7 +304,7 @@ module.exports = {
265
304
  if (!Array.isArray(config.install.requirements)) return log(' Requirements must be an array'.red.bold, ':end');
266
305
  config.install.requirements.forEach(req => {
267
306
  log('Finding '.cyan + req.green);
268
- this.installAppFrom(req);
307
+ this.installAppFrom(req, opts);
269
308
  });
270
309
  }
271
310
  },
@@ -341,31 +380,61 @@ module.exports = {
341
380
  processFile(filePath, importsArray);
342
381
  log('󰈔 Compiled'.yellow, (importsArray.length + 1 + '').blue, `file${importsArray.length ? 's' : ''}.`.yellow, ':end');
343
382
  },
344
- async cloneGit(gitpath) {
383
+ cache(command){
384
+ if(command == 'list'){
385
+ console.log(fs.readdirSync(cachepath).join('\n').trim());
386
+ } else {
387
+ fs.readdirSync(cachepath).forEach(file => fs.rmSync(path.join(cachepath, file), { recursive: true }));
388
+ }
389
+ },
390
+ async cloneGit(gitpath, opts) {
345
391
  const p = gitpath.split('github:')[1];
392
+ const clonePath = path.join(cachepath, 'rew-git-clone-'+gen_key(gitpath).substring(0, 12));
346
393
  const url = `https://github.com/${p}`;
347
- const apiurl = `https://api.github.com/repos/${p}`;
394
+ const apiurl = `https://api.github.com/repos/${p}/commits`;
395
+ const load = loading("Finding Repo...".yellow).start();
348
396
  try {
349
397
  const response = await req(apiurl);
350
- if (response.status !== 200) return log(' Repo not found'.red.bold, ':end');
351
- log(''.blue, 'Cloning from github'.yellow);
352
- const tempPath = '/tmp/rew-git-clone-' + p.replace(/\//g, '_') + '-' + generateRandomID();
353
- execSync(`git clone ${url} ${tempPath}`, { stdio: 'ignore' });
354
- log(''.blue, 'Installing deps...'.yellow);
355
- execSync(`cd ${tempPath} && npm i`);
356
- return tempPath;
398
+ if (response.status !== 200) {
399
+ load.stop();
400
+ return log(' Package not found in github'.red.bold, ':end');
401
+ }
402
+ let pull = false;
403
+ if(fs.existsSync(clonePath)){
404
+ if(fs.existsSync(path.join(clonePath, response.data[0].sha))){
405
+ load.stop();
406
+ log('Found Cache'.yellow);
407
+ return clonePath+'/clone';
408
+ } else {
409
+ pull = true;
410
+ }
411
+ }
412
+ fs.mkdirSync(clonePath, { recursive: true });
413
+ fs.writeFileSync(path.join(clonePath, response.data[0].sha), '');
414
+ load.text = 'Cloning from github'.blue.bold;
415
+ await sleep(100)
416
+ if(pull) execSync(`cd ${clonePath}/clone && git pull`, { stdio: opts.verbose ? 'inherit' : 'ignore' });
417
+ else execSync(`git clone ${url} ${clonePath}/clone`, { stdio: opts.verbose ? 'pipe' : 'ignore' });
418
+ load.text = 'Installing npm packages'.green.bold;
419
+ await sleep(100)
420
+ execSync(`cd ${clonePath}/clone && npm i`, { stdio: opts.verbose ? 'inherit' : 'ignore' });
421
+ load.stop();
422
+ return clonePath+'/clone';
357
423
  } catch (e) {
358
- log(' Repo not found'.red.bold, ':end');
424
+ const logFile = path.join(logspath, 'logs-'+Date.now()+'.log');
425
+ fs.writeFileSync(logFile, e.toString() +'\n'+ e.stack);
426
+ load.stop();
427
+ log(' Something went wrong, check logs at'.red.bold, logFile.green, ':end');
359
428
  }
360
429
  },
361
430
  findRepo(repo) {
362
431
  const repos = conf({}).create('').optionCenter('repos');
363
432
  return repos.get(repo);
364
433
  },
365
- async installAppFrom(path) {
366
- if (path.startsWith('github:')) this.installApp(await this.cloneGit(path), true, true);
367
- else if (path.startsWith('@')) this.fromRepo(path);
368
- else this.installApp(path);
434
+ async installAppFrom(path, opts) {
435
+ if (path.startsWith('github:')) this.installApp(await this.cloneGit(path, opts), opts, true);
436
+ else if (path.startsWith('@')) this.fromRepo(path, opts);
437
+ else this.installApp(path, opts, null, null);
369
438
  },
370
439
  uninstall(packageName, all) {
371
440
  const confPath = path.join(CONFIG_PATH, packageName);
@@ -409,7 +478,7 @@ module.exports = {
409
478
  return {};
410
479
  }
411
480
  },
412
- async fromRepo(repoAndPkg) {
481
+ async fromRepo(repoAndPkg, opts) {
413
482
  const [repo, pkg] = repoAndPkg.slice(1).split('/');
414
483
  const repoUrl = this.findRepo(repo);
415
484
  if (!repoUrl) {
@@ -418,13 +487,13 @@ module.exports = {
418
487
  } else {
419
488
  const repoJson = await this.getRepoJson(repoUrl);
420
489
  if (repoJson?.packages?.[pkg]) {
421
- await this.installAppFrom(repoJson.packages[pkg]);
490
+ await this.installAppFrom(repoJson.packages[pkg], opts);
422
491
  } else {
423
492
  log(` Package "${pkg.cyan}" is not in repo "${repo.green}"`.red.bold, ":end");
424
493
  }
425
494
  }
426
495
  },
427
- async repo(command, key, value) {
496
+ async repo(command, key, value, options) {
428
497
  const confInstance = conf({}).create('').optionCenter('repos') || {};
429
498
 
430
499
  if (command === 'add' || command === 'set') {
@@ -433,6 +502,7 @@ module.exports = {
433
502
  if (key) {
434
503
  console.log(confInstance.get(key) || 'Not found');
435
504
  } else {
505
+ if(options.json) return console.log(JSON.stringify(confInstance.getAll()));
436
506
  console.log(Object.keys(confInstance.getAll()).join('\n'));
437
507
  }
438
508
  } else if (command === 'view') {
@@ -440,21 +510,26 @@ module.exports = {
440
510
  const url = confInstance.get(key);
441
511
  if (!url) return log(' Repo not found'.red.bold, ':end');
442
512
  const json = await this.getRepoJson(url);
513
+ if(options.json) return console.log(JSON.stringify(json));
443
514
  if (json.name) log(json.name);
444
515
  log('Packages:'.yellow)
445
516
  if (json.packages) Object.keys(json.packages).forEach(name => log(name)) || log(`${Object.keys(json.packages).length} Packages in ${key}`, ':end');
446
517
  else log('None'.blue, ':end')
447
518
  } else {
519
+ if(options.json) return JSON.stringify(confInstance.getAll());
448
520
  console.log(Object.keys(confInstance.getAll()).join('\n'));
449
521
  }
450
522
  } else if (command === 'delete') {
451
- confInstance.remove('repos');
523
+ confInstance.remove(key);
452
524
  } else {
453
525
  log(' Invalid command'.red.bold, ':end');
454
526
  }
455
527
  },
456
528
  initFirst() {
529
+ log('First time init')
457
530
  conf({}).create('').optionCenter('repos').set('rewpkgs', '//raw.githubusercontent.com/kevinJ045/rewpkgs/main/main.yaml');
458
531
  fs.mkdirSync(binpath, { recursive: true });
532
+ fs.mkdirSync(cachepath, { recursive: true });
533
+ fs.mkdirSync(logspath, { recursive: true });
459
534
  }
460
535
  };
@@ -11,6 +11,8 @@ const { print, input, clear } = require('../functions/stdout');
11
11
  const { curl } = require('../functions/curl');
12
12
  const { wait } = require('../functions/wait');
13
13
  const { scheduleFrame } = require('../functions/misc');
14
+ const { jsons, yaml, json, yamls } = require('../functions/json');
15
+ const { generateRandomID } = require('../functions/id');
14
16
 
15
17
  module.exports = {
16
18
  cenum,
@@ -43,6 +45,13 @@ module.exports = {
43
45
  compose,
44
46
  curry,
45
47
 
48
+ json,
49
+ jsons,
50
+ yaml,
51
+ yamls,
52
+
53
+ genID: generateRandomID,
54
+
46
55
  curl,
47
56
 
48
57
  print,
@@ -1,6 +1,6 @@
1
1
  const execOptions = {
2
2
  sharedContext: true,
3
- resolveExtensions: [{ ext: '.js', options: { type: 'js' } }, { ext: '.qrew', options: { qrew: true } }, '.coffee'],
3
+ resolveExtensions: ['.coffee', { ext: '.js', options: { type: 'js' } }, { ext: '.qrew', options: { qrew: true } }],
4
4
  nativeRequire: false,
5
5
  cwdAlias: '$',
6
6
  jsxPragma: 'createElement',