@makano/rew 1.1.73 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. package/lib/coffeescript/browser.js +144 -139
  2. package/lib/coffeescript/cake.js +132 -133
  3. package/lib/coffeescript/coffeescript.js +437 -381
  4. package/lib/coffeescript/command.js +806 -724
  5. package/lib/coffeescript/grammar.js +1908 -2474
  6. package/lib/coffeescript/helpers.js +509 -473
  7. package/lib/coffeescript/index.js +228 -215
  8. package/lib/coffeescript/lexer.js +2282 -1909
  9. package/lib/coffeescript/nodes.js +9782 -9202
  10. package/lib/coffeescript/optparse.js +255 -227
  11. package/lib/coffeescript/parser.js +20305 -1265
  12. package/lib/coffeescript/register.js +107 -87
  13. package/lib/coffeescript/repl.js +307 -284
  14. package/lib/coffeescript/rewriter.js +1389 -1079
  15. package/lib/coffeescript/scope.js +176 -172
  16. package/lib/coffeescript/sourcemap.js +242 -227
  17. package/lib/rew/cli/cli.js +288 -186
  18. package/lib/rew/cli/log.js +31 -32
  19. package/lib/rew/cli/run.js +10 -12
  20. package/lib/rew/cli/utils.js +344 -176
  21. package/lib/rew/const/config_path.js +4 -0
  22. package/lib/rew/const/default.js +38 -35
  23. package/lib/rew/const/files.js +9 -9
  24. package/lib/rew/const/opt.js +8 -8
  25. package/lib/rew/css/theme.css +2 -2
  26. package/lib/rew/functions/core.js +55 -57
  27. package/lib/rew/functions/curl.js +23 -0
  28. package/lib/rew/functions/emitter.js +52 -55
  29. package/lib/rew/functions/exec.js +25 -21
  30. package/lib/rew/functions/export.js +18 -20
  31. package/lib/rew/functions/fs.js +55 -54
  32. package/lib/rew/functions/future.js +29 -21
  33. package/lib/rew/functions/id.js +8 -9
  34. package/lib/rew/functions/import.js +107 -93
  35. package/lib/rew/functions/map.js +13 -16
  36. package/lib/rew/functions/match.js +35 -26
  37. package/lib/rew/functions/path.js +8 -8
  38. package/lib/rew/functions/require.js +32 -33
  39. package/lib/rew/functions/sleep.js +2 -2
  40. package/lib/rew/functions/stdout.js +20 -20
  41. package/lib/rew/functions/types.js +96 -95
  42. package/lib/rew/html/ui.html +12 -13
  43. package/lib/rew/html/ui.js +205 -168
  44. package/lib/rew/main.js +14 -14
  45. package/lib/rew/misc/bin.js +37 -0
  46. package/lib/rew/misc/findAppInfo.js +16 -0
  47. package/lib/rew/misc/findAppPath.js +21 -0
  48. package/lib/rew/misc/req.js +7 -0
  49. package/lib/rew/misc/seededid.js +13 -0
  50. package/lib/rew/models/enum.js +12 -12
  51. package/lib/rew/models/struct.js +30 -32
  52. package/lib/rew/modules/compiler.js +237 -177
  53. package/lib/rew/modules/context.js +35 -22
  54. package/lib/rew/modules/fs.js +10 -10
  55. package/lib/rew/modules/runtime.js +17 -21
  56. package/lib/rew/modules/yaml.js +27 -30
  57. package/lib/rew/pkgs/conf.js +82 -75
  58. package/lib/rew/pkgs/data.js +12 -7
  59. package/lib/rew/pkgs/date.js +27 -28
  60. package/lib/rew/pkgs/env.js +6 -8
  61. package/lib/rew/pkgs/modules/data/bintree.js +52 -52
  62. package/lib/rew/pkgs/modules/data/doublylinked.js +85 -85
  63. package/lib/rew/pkgs/modules/data/linkedList.js +73 -73
  64. package/lib/rew/pkgs/modules/data/queue.js +19 -20
  65. package/lib/rew/pkgs/modules/data/stack.js +19 -19
  66. package/lib/rew/pkgs/modules/threads/worker.js +36 -26
  67. package/lib/rew/pkgs/modules/ui/classes.js +182 -178
  68. package/lib/rew/pkgs/pkgs.js +9 -10
  69. package/lib/rew/pkgs/rune.js +400 -0
  70. package/lib/rew/pkgs/threads.js +57 -53
  71. package/lib/rew/pkgs/ui.js +148 -136
  72. package/lib/rew/qrew/compile.js +12 -0
  73. package/package.json +11 -4
@@ -7,186 +7,354 @@ const { log, logget } = require('./log');
7
7
  const { execSync, exec } = require('child_process');
8
8
  const { run } = require('../main');
9
9
  const { generateRandomID } = require('../functions/id');
10
+ const { compile } = require('../modules/compiler');
11
+ const { to_qrew } = require('../qrew/compile');
12
+ const { findAppInfo } = require('../misc/findAppInfo');
13
+ const { req } = require('../misc/req');
10
14
 
11
15
  const npm_package_name = '@makano/rew';
12
16
 
13
17
  module.exports = {
14
- conf(command, fullPath, key, value){
15
- const con = conf({});
16
- if(command == 'get'){
17
- if(!fullPath || fullPath == 'list'){
18
- return fs.readdirSync(con.CONFIG_PATH).join('\n');
19
- } else {
20
- const name = fullPath.indexOf('/') ? fullPath.split('/')[0] : fullPath;
21
- const dpath = fullPath.indexOf('/') ? fullPath.split('/')[1] : '';
22
- const root = con.create(name);
23
- if(dpath){
24
- const fp = path.join(root.root, dpath);
25
- if(fs.existsSync(fp) && fs.statSync(fp).isDirectory()){
26
- return fs.readdirSync(fp).join('\n');
27
- } else {
28
- const o = con.create(name).optionCenter(dpath);
29
- return key ? o.get(key) : o.getAll(true);
30
- }
31
- } else {
32
- return fs.readdirSync(root.root).join('\n');
33
- }
34
- }
35
- } else {
36
- const name = fullPath.indexOf('/') ? fullPath.split('/')[0] : fullPath;
37
- const dpath = fullPath.indexOf('/') ? fullPath.split('/')[1] : '';
38
- if(name && key){
39
- const root = con.create(name);
40
- const o = dpath ? root.optionCenter(dpath) : root;
41
- if(command == 'set') {
42
- if(value){
43
- o.set(key, value);
44
- } else {
45
- log('Value not specified', ':end');
46
- }
47
- } else {
48
- o.remove(key);
49
- }
50
- } else {
51
- log(
52
- !name ? 'Path not specified' : 'Key not specified', ':end'
53
- );
54
- }
55
- }
56
- },
57
- createProject: (ppath) => {
58
- const projectPath = path.join(process.cwd(), ppath);
59
- log('Crating at', ppath);
60
- const rl = readline.createInterface({
61
- input: process.stdin,
62
- output: process.stdout
63
- });
64
- const project = {};
65
- const create = () => {
66
- fs.mkdirSync(projectPath, { recursive: true });
67
- const confPath = path.join(projectPath, 'app.yaml');
68
- const entryFile = path.join(projectPath, 'main.coffee');
69
- fs.writeFileSync(confPath, jsYaml.dump({ package: project.package, entry: 'main.coffee' }));
70
- fs.writeFileSync(entryFile, `print("Hello World!")`);
71
- if(project.git) {
72
- fs.writeFileSync(path.join(projectPath, '.gitignore'), `node_modules/\npackage-lock.json`);
73
- execSync('cd '+projectPath+' && git init .');
74
- }
75
- // log('Installing '+npm_package_name);
76
- // exec('cd '+projectPath+' && npm i '+npm_package_name, (err) => {
77
- // if(err){
78
- // console.error(err);
79
- // process.exit(0);
80
- // } else {
81
- // rl.close();
82
- // }
83
- // });
84
- log('Done.', ':end');
85
- rl.close();
86
- }
87
- if (!fs.existsSync(projectPath)) {
88
- rl.question(logget('Package Name: '), (pkg) => {
89
- if(pkg.trim()) {
90
- project.package = pkg.trim();
91
- rl.question(logget('Use git(y/N): '), (use_git) => {
92
- project.git = use_git.toLowerCase() == 'y' || use_git.toLowerCase() == 'yes';
93
- create();
94
- });
95
- } else {
96
- rl.close();
97
- }
98
- });
99
- } else {
100
- log(`Project ${ppath} already exists at ${projectPath}`, ':end');
101
- rl.close();
102
- }
103
- },
104
- runApp(pathOrPackage){
105
- const apppath = path.resolve(process.cwd(), pathOrPackage);
106
- const appConfpath = path.join(apppath, 'app.yaml');
18
+ conf(command, fullPath, key, value) {
19
+ const con = conf({});
20
+ if (command == 'get') {
21
+ if (!fullPath || fullPath == 'list') {
22
+ return fs.readdirSync(con.CONFIG_PATH).join('\n');
23
+ } else {
24
+ const name = fullPath.indexOf('/') ? fullPath.split('/')[0] : fullPath;
25
+ const dpath = fullPath.indexOf('/') ? fullPath.split('/').slice(1).join('/') : '';
26
+ const root = con.create(name);
27
+ if (dpath) {
28
+ const fp = path.join(root.root, dpath);
29
+ if (fs.existsSync(fp) && fs.statSync(fp).isDirectory()) {
30
+ return fs.readdirSync(fp).join('\n');
31
+ } else {
32
+ const o = con.create(name).optionCenter(dpath);
33
+ return key ? o.get(key) : o.getAll(true);
34
+ }
35
+ } else {
36
+ return fs.readdirSync(root.root).join('\n');
37
+ }
38
+ }
39
+ } else {
40
+ const name = fullPath.indexOf('/') ? fullPath.split('/')[0] : fullPath;
41
+ const dpath = fullPath.indexOf('/') ? fullPath.split('/')[1] : '';
42
+ if (name && key) {
43
+ const root = con.create(name);
44
+ const o = dpath ? root.optionCenter(dpath) : root;
45
+ if (command == 'set') {
46
+ if (value) {
47
+ o.set(key, value);
48
+ } else {
49
+ log('Value not specified', ':end');
50
+ }
51
+ } else {
52
+ o.remove(key);
53
+ }
54
+ } else {
55
+ log(!name ? 'Path not specified' : 'Key not specified', ':end');
56
+ }
57
+ }
58
+ },
59
+ createProject: (ppath) => {
60
+ const projectPath = path.join(process.cwd(), ppath);
61
+ log(''.cyan, 'Creating at'.blue, ppath.yellow);
62
+ const rl = readline.createInterface({
63
+ input: process.stdin,
64
+ output: process.stdout,
65
+ });
66
+ const project = {};
67
+ const create = () => {
68
+ fs.mkdirSync(projectPath, { recursive: true });
69
+ const confPath = path.join(projectPath, 'app.yaml');
70
+ const entryFile = path.join(projectPath, 'main.coffee');
71
+ fs.writeFileSync(confPath, jsYaml.dump({ package: project.package, entry: 'main.coffee' }));
72
+ fs.writeFileSync(entryFile, `print("Hello World!")`);
73
+ if (project.git) {
74
+ fs.writeFileSync(path.join(projectPath, '.gitignore'), `node_modules/\npackage-lock.json`);
75
+ execSync('cd ' + projectPath + ' && git init . && git branch -m main', { stdio: 'ignore' });
76
+ }
77
+ execSync('cd ' + projectPath + ' && npm init -y', { stdio: 'ignore' });
78
+ // log('Installing '+npm_package_name);
79
+ // exec('cd '+projectPath+' && npm i '+npm_package_name, (err) => {
80
+ // if(err){
81
+ // console.error(err);
82
+ // process.exit(0);
83
+ // } else {
84
+ // rl.close();
85
+ // }
86
+ // });
87
+ log('Done.'.blue.bold, ':end');
88
+ rl.close();
89
+ };
90
+ if (!fs.existsSync(projectPath)) {
91
+ rl.question(logget(' Package Name: '.blue), (pkg) => {
92
+ if (pkg.trim()) {
93
+ project.package = pkg.trim();
94
+ rl.question(logget('󰊢 Use git(y/N): '.yellow.bold), (use_git) => {
95
+ project.git = use_git.toLowerCase() == 'y' || use_git.toLowerCase() == 'yes';
96
+ create();
97
+ });
98
+ } else {
99
+ rl.close();
100
+ }
101
+ });
102
+ } else {
103
+ log(` Project ${ppath} already exists at ${projectPath}`.red.bold, ':end');
104
+ rl.close();
105
+ }
106
+ },
107
+ runApp(pathOrPackage, options) {
108
+ const apppath = path.resolve(process.cwd(), pathOrPackage);
109
+ const appConfpath = path.join(apppath, 'app.yaml');
107
110
 
108
- const runAppRoot = (root, confPath) => {
109
- const c = jsYaml.load(fs.readFileSync(confPath, { encoding: 'utf-8' }));
110
- if(c.entry){
111
- const r = path.resolve(root, c.entry);
112
- const mod_path = path.resolve(root, 'snode_moduless/@makano/rew');
113
- const mod_path_lib = path.join(mod_path, 'lib/rew/cli');
114
- if(fs.existsSync(mod_path) && __dirname !== mod_path_lib){
115
- const mod_path_utilsjs = path.join(mod_path_lib, '../main.js');
116
- require(mod_path_utilsjs)
117
- .run(r);
118
- } else run(r);
119
- }
120
- }
111
+ const runAppRoot = (root, confPath, byPath) => {
112
+ const c = jsYaml.load(fs.readFileSync(confPath, { encoding: 'utf-8' }));
113
+ if (c.entry) {
114
+ if(byPath && options.dev) c.entry = c.entry.endsWith('.qrew') ? c.entry.replace(/\.qrew$/, '.coffee') : c.entry;
115
+ let r = path.resolve(root, c.entry);
116
+ if(options.build) {
117
+ this.build({
118
+ file: r,
119
+ translate: options.translate || false
120
+ });
121
+ r = path.resolve(root, c.entry.replace(new RegExp(path.extname(c.entry).replace('.', '\\.') + '$'), options.translate ? '.js' : '.qrew'));
122
+ }
123
+ const mod_path = path.resolve(root, 'snode_moduless/@makano/rew');
124
+ const mod_path_lib = path.join(mod_path, 'lib/rew/cli');
125
+ if (fs.existsSync(mod_path) && __dirname !== mod_path_lib) {
126
+ const mod_path_utilsjs = path.join(mod_path_lib, '../main.js');
127
+ require(mod_path_utilsjs).run(r);
128
+ } else run(r);
129
+ }
130
+ };
121
131
 
122
- if(fs.existsSync(apppath) && fs.existsSync(appConfpath)){
123
- runAppRoot(apppath, appConfpath);
124
- } else {
125
- const con = conf({});
126
- const apppath = path.resolve(con.CONFIG_PATH, pathOrPackage, 'app');
127
- const appConfpath = path.join(apppath, 'app.yaml');
128
- if(fs.existsSync(apppath) && fs.existsSync(appConfpath)){
129
- runAppRoot(apppath, appConfpath);
130
- }
131
- }
132
- },
133
- installApp(pathname, rmidir, rmidiri){
134
- if(!pathname){
135
- return;
136
- }
137
- const apppath = path.resolve(process.cwd(), pathname);
138
- const appConfpath = path.join(apppath, 'app.yaml');
139
- const appPackagepath = path.join(apppath, 'package.json');
140
- if(fs.existsSync(apppath) && fs.existsSync(appConfpath)){
141
- const c = jsYaml.load(fs.readFileSync(appConfpath, { encoding: 'utf-8' }));
142
- const p = JSON.parse(fs.readFileSync(appPackagepath, { encoding: 'utf-8' }));
143
- const pname = c.package;
144
- const installPath = path.join(conf({}).create(pname).root, 'app');
145
- const rl = readline.createInterface({
146
- input: process.stdin,
147
- output: process.stdout
148
- });
149
- log('Installing '+pname);
150
- log("Package: "+p.name+'@'+p.version);
151
- if(p.description){
152
- log("Description: "+p.description);
153
- }
154
- rl.question(logget('Install '+pname+'? (y/N)'), (f) => {
155
- if(f.toLowerCase() == 'y'){
156
- if(fs.existsSync(installPath)){
157
- execSync(`rm -r ${installPath}`);
158
- }
159
- execSync(`cp -r ${apppath} ${installPath}`);
160
- if(rmidir){
161
- execSync(`rm -r ${apppath}`);
162
- }
163
- log('Installed '+pname, ':end');
164
- rl.close();
165
- } else {
166
- if(rmidiri){
167
- execSync(`rm -r ${apppath}`);
168
- }
169
- log('Canceled install', ':end');
170
- rl.close();
171
- }
172
- });
173
- } else {
174
- log('Path is not a rew app', ':end');
175
- }
132
+ if (fs.existsSync(apppath) && fs.existsSync(appConfpath)) {
133
+ runAppRoot(apppath, appConfpath, true);
134
+ } else {
135
+ const con = conf({});
136
+ const apppath = path.resolve(con.CONFIG_PATH, pathOrPackage, 'app');
137
+ const appConfpath = path.join(apppath, 'app.yaml');
138
+ if (fs.existsSync(apppath) && fs.existsSync(appConfpath)) {
139
+ runAppRoot(apppath, appConfpath);
140
+ }
141
+ }
142
+ },
143
+ installApp(pathname, rmidir, rmidiri) {
144
+ if (!pathname) {
145
+ return;
146
+ }
147
+ const apppath = path.resolve(process.cwd(), pathname);
148
+ const appConfpath = path.join(apppath, 'app.yaml');
149
+ const appPackagepath = path.join(apppath, 'package.json');
150
+ if (fs.existsSync(apppath) && fs.existsSync(appConfpath)) {
151
+ const c = jsYaml.load(fs.readFileSync(appConfpath, { encoding: 'utf-8' }));
152
+ const p = JSON.parse(fs.readFileSync(appPackagepath, { encoding: 'utf-8' }));
153
+ const pname = c.package;
154
+ const installPath = path.join(conf({}).create(pname).root, 'app');
155
+ const rl = readline.createInterface({
156
+ input: process.stdin,
157
+ output: process.stdout,
158
+ });
159
+ log('Installing '.blue + pname.green.bold);
160
+ log(' Package'.blue + ': ' + p.name.green + '@' + p.version.yellow);
161
+ if (p.description) {
162
+ log(' Description'.blue + ': ' + p.description);
163
+ }
164
+ rl.question(logget('Install '.blue + pname.green.bold + '? (y/N) '), (f) => {
165
+ if (f.toLowerCase() == 'y') {
166
+ if (fs.existsSync(installPath)) {
167
+ execSync(`rm -r ${installPath}`);
168
+ }
169
+ execSync(`cp -r ${apppath} ${installPath}`);
170
+ execSync(`chmod 444 ${installPath}/app.yaml`);
171
+ if (rmidir) {
172
+ execSync(`rm -r ${apppath}`);
173
+ }
174
+ log(' Installed '.green + pname.cyan.bold, c.install ? '' : ':end');
175
+ if(c.install){
176
+ if(c.install.build){
177
+ log(' Building'.blue);
178
+ this.build({
179
+ ...c.install.build,
180
+ file: path.join(installPath, c.install.build.file)
181
+ });
182
+ }
183
+ }
184
+ rl.close();
185
+ } else {
186
+ if (rmidiri) {
187
+ execSync(`rm -r ${apppath}`);
188
+ }
189
+ log(' Canceled install'.red.bold, ':end');
190
+ rl.close();
191
+ }
192
+ });
193
+ } else {
194
+ log(' Path is not a rew app'.red.bold, ':end');
195
+ }
196
+ },
197
+ build(argv){
198
+ function readFile(filePath) {
199
+ return fs.readFileSync(filePath, { encoding: 'utf-8' });
200
+ }
201
+
202
+ function extractImports(content) {
203
+ const customImportRegex = /(\w+)\s*=\s*(imp|inc)\s*['"](.+?)['"]/g;
204
+ const jsImportRegex = /import\s+((?:\w+\s*,?\s*)?{?[^{]*}?)\s*from\s*['"](.+?)['"]/g;
205
+ const imports = [];
206
+ let match;
207
+
208
+ while ((match = customImportRegex.exec(content)) !== null) {
209
+ imports.push({ variable: match[1], url: match[3] });
210
+ }
211
+
212
+ while ((match = jsImportRegex.exec(content)) !== null) {
213
+ const variables = match[1].trim().replace(/[{}]/g, '').split(',').map(v => v.trim()).filter(v => v);
214
+ const url = match[2];
215
+ variables.forEach(variable => {
216
+ imports.push({ variable, url });
217
+ });
218
+ }
219
+
220
+ return imports;
221
+ }
222
+
223
+ function writeCompiledFile(filePath, compiledCode) {
224
+ const dirName = outputDir ? outputDir : path.dirname(filePath);
225
+ if (!fs.existsSync(dirName)) fs.mkdirSync(dirName, { recursive: true });
226
+ const baseName = path.basename(filePath, path.extname(filePath));
227
+ const newFilePath = path.join(dirName, `${baseName}.${argv.translate ? 'js' : 'qrew'}`);
228
+ fs.writeFileSync(newFilePath, compiledCode);
229
+ log(`${'Compiled'.green.bold}: ${newFilePath.yellow}`);
230
+ if(argv.remove){
231
+ fs.unlinkSync(filePath);
232
+ log(`${'Removed'.red.bold}: ${filePath.yellow}`);
233
+ }
234
+ }
235
+
236
+ function processFile(filePath, importsArray) {
237
+ const content = readFile(filePath);
238
+ const imports = extractImports(content);
239
+
240
+ imports.forEach((importStatement) => {
241
+ const importedFilePath = path.resolve(path.dirname(filePath), importStatement.url);
242
+ if (!importsArray.some((importObj) => importObj.url === importStatement.url)) {
243
+ if (fs.existsSync(importedFilePath)) {
244
+ importsArray.push(importStatement);
245
+ processFile(importedFilePath, importsArray);
246
+ } else if (fs.existsSync(importedFilePath + '.coffee')) {
247
+ importsArray.push(importStatement);
248
+ processFile(importedFilePath + '.coffee', importsArray);
249
+ } else if (fs.existsSync(importedFilePath + '.js')) {
250
+ importsArray.push(importStatement);
251
+ processFile(importedFilePath + '.js', importsArray);
252
+ }
253
+ }
254
+ });
255
+
256
+ const appPath = findAppInfo(filePath);
257
+
258
+ const compiled = argv.translate ? compile({ content }, {}) : to_qrew(content, appPath?.config?.package || path.basename(filePath).split('.').slice(0, -1).join('.'));
259
+ writeCompiledFile(filePath, compiled);
260
+ }
261
+
262
+ const filePath = path.resolve(process.cwd(), argv.file);
263
+ const importsArray = [];
264
+ const outputDir = argv.output ? path.resolve(process.cwd(), argv.output) : null;
265
+ log(' Start compile at'.yellow, (outputDir || 'default path').green);
266
+ processFile(filePath, importsArray);
267
+ log('󰈔 Compiled'.yellow, (importsArray.length + 1 + '').blue, `file${importsArray.length ? 's' : ''}.`.yellow, ':end');
268
+ },
269
+ async cloneGit(gitpath) {
270
+ const p = gitpath.split('github:')[1];
271
+ const url = `https://github.com/${p}`;
272
+ const apiurl = `https://api.github.com/repos/${p}`;
273
+ try{
274
+ const response = await req(apiurl);
275
+ if (response.status !== 200) return log(' Repo not found'.red.bold, ':end');
276
+ log(''.blue, 'Cloning from github'.yellow);
277
+ const tempPath = '/tmp/rew-git-clone-' + p.replace(/\//g, '_') + '-' + generateRandomID();
278
+ execSync(`git clone ${url} ${tempPath}`, { stdio: 'ignore' });
279
+ log(''.blue, 'Installing deps...'.yellow);
280
+ execSync(`cd ${tempPath} && npm i`);
281
+ return tempPath;
282
+ } catch(e){
283
+ log(' Repo not found'.red.bold, ':end');
284
+ }
285
+ },
286
+ findRepo(repo){
287
+ const repos = conf({}).create('').optionCenter('repos');
288
+ return repos.get(repo);
289
+ },
290
+ async installAppFrom(path){
291
+ if (path.startsWith('github:')) this.installApp(await this.cloneGit(path), true, true);
292
+ else if(path.startsWith('@')) this.fromRepo(path);
293
+ else this.installApp(path);
294
+ },
295
+ async getRepoJson(repoUrl){
296
+ try{
297
+ const text = (await req(repoUrl.startsWith('//.') ? 'http://'+repoUrl.slice(3) : repoUrl.startsWith('//') ? 'https://'+repoUrl : repoUrl)).data;
298
+ const json = text.startsWith('---') || text.startsWith('%YAML') ? jsYaml.loadAll(text)[0] : JSON.parse(text);
299
+ if(Array.isArray(json.include)){
300
+ for(let i of json.include){
301
+ json.packages = {
302
+ ...json.packages,
303
+ ...((await this.getRepoJson(i.startsWith('.') ? path.join(path.dirname(repoUrl), i) : i)).packages || {})
304
+ };
305
+ }
306
+ }
307
+ return json;
308
+ } catch(e){
309
+ log(` Fetch Error. Check your connection.`.red.bold);
310
+ return {};
311
+ }
312
+ },
313
+ async fromRepo(repoAndPkg){
314
+ const [repo, pkg] = repoAndPkg.slice(1).split('/');
315
+ const repoUrl = this.findRepo(repo);
316
+ if(!repoUrl){
317
+ log(` Repository "${repo.green}"`.red.bold, `not found.`.red.bold);
318
+ return log(`Add with:`.yellow, '\n\t$'.green, `rew repo add ${repo} URL`.cyan.bold, ':end');
319
+ } else {
320
+ const repoJson = await this.getRepoJson(repoUrl);
321
+ if(repoJson?.packages?.[pkg]){
322
+ await this.installAppFrom(repoJson.packages[pkg]);
323
+ } else {
324
+ log(` Package "${pkg}" is not in repo "${repo.green}"`.red.bold, ":end");
325
+ }
326
+ }
176
327
  },
177
- async cloneGit(gitpath){
178
- const p = gitpath.split('github:')[1];
179
- const url = `https://github.com/${p}`;
180
- const apiurl = `https://api.github.com/repos/${p}`;
181
- return await fetch(apiurl)
182
- .then((r) => {
183
- if(r.status !== 200) return log('Repo not found', ':end');
184
- const tempPath = '/tmp/rew-git-clone-'+p.replace(/\//g, '_')+'-'+generateRandomID();
185
- execSync(`git clone ${url} ${tempPath}`);
186
- console.log('Installing deps...');
187
- execSync(`cd ${tempPath} && npm i`);
188
- return tempPath;
189
- })
190
- .catch(r => null);
191
- }
192
- }
328
+ async repo(command, key, value) {
329
+ const confInstance = conf({}).create('').optionCenter('repos') || {};
330
+
331
+ if (command === 'add' || command === 'set') {
332
+ confInstance.set(key, value.replace('https://', '//').replace('http://', '//.'));
333
+ } else if (command === 'get') {
334
+ if (key) {
335
+ console.log(confInstance.get(key) || 'Not found');
336
+ } else {
337
+ console.log(Object.keys(confInstance.getAll()).join('\n'));
338
+ }
339
+ } else if (command === 'view') {
340
+ if (key) {
341
+ const url = confInstance.get(key);
342
+ if(!url) return log(' Repo not found'.red.bold, ':end');
343
+ const json = await this.getRepoJson(url);
344
+ if(json.name) log(json.name);
345
+ log('Packages:'.yellow)
346
+ if(json.packages) Object.keys(json.packages).forEach(name => log(name)) || log(`${Object.keys(json.packages).length} Packages in ${key}`, ':end');
347
+ else log('None'.blue, ':end')
348
+ } else {
349
+ console.log(Object.keys(repos).join('\n'));
350
+ }
351
+ } else if (command === 'delete') {
352
+ confInstance.remove('repos');
353
+ } else {
354
+ log(' Invalid command'.red.bold, ':end');
355
+ }
356
+ },
357
+ initFirst(){
358
+ conf({}).create('').optionCenter('repos').set('rewpkgs', '//raw.githubusercontent.com/kevinJ045/rewpkgs/main/main.yaml');
359
+ }
360
+ };
@@ -0,0 +1,4 @@
1
+ const path = require('path');
2
+
3
+ const CONFIG_PATH = path.resolve(process.env.HOME, '.local/share/rew');
4
+ module.exports.CONFIG_PATH = CONFIG_PATH;
@@ -1,42 +1,45 @@
1
- const { cenum } = require("../models/enum");
2
- const { struct } = require("../models/struct");
3
- const emitter = require("../functions/emitter");
4
- const future = require("../functions/future");
5
- const sleep = require("../functions/sleep");
6
- const { match } = require("../functions/match");
7
- const { map } = require("../functions/map");
8
- const { typex, typeis, typedef, typei, int, float, num, str, bool } = require("../functions/types");
9
- const { isEmpty, clone, deepClone, merge, uniqueId, compose, curry } = require("../functions/core");
10
- const { print, input } = require("../functions/stdout");
1
+ const { cenum } = require('../models/enum');
2
+ const { struct } = require('../models/struct');
3
+ const emitter = require('../functions/emitter');
4
+ const future = require('../functions/future');
5
+ const sleep = require('../functions/sleep');
6
+ const { match } = require('../functions/match');
7
+ const { map } = require('../functions/map');
8
+ const { typex, typeis, typedef, typei, int, float, num, str, bool } = require('../functions/types');
9
+ const { isEmpty, clone, deepClone, merge, uniqueId, compose, curry } = require('../functions/core');
10
+ const { print, input } = require('../functions/stdout');
11
+ const { curl } = require('../functions/curl');
11
12
 
12
13
  module.exports = {
13
- cenum,
14
- struct,
15
- future,
16
- emitter,
17
- sleep,
18
- match,
19
- map,
14
+ cenum,
15
+ struct,
16
+ future,
17
+ emitter,
18
+ sleep,
19
+ match,
20
+ map,
20
21
 
21
- typex,
22
- typei,
23
- typeis,
24
- typedef,
22
+ typex,
23
+ typei,
24
+ typeis,
25
+ typedef,
25
26
 
26
- int,
27
- float,
28
- num,
29
- str,
30
- bool,
27
+ int,
28
+ float,
29
+ num,
30
+ str,
31
+ bool,
31
32
 
32
- isEmpty,
33
- clone,
34
- deepClone,
35
- merge,
36
- uniqueId,
37
- compose,
38
- curry,
33
+ isEmpty,
34
+ clone,
35
+ deepClone,
36
+ merge,
37
+ uniqueId,
38
+ compose,
39
+ curry,
39
40
 
40
- print,
41
- input
41
+ curl,
42
+
43
+ print,
44
+ input,
42
45
  };
@@ -2,14 +2,14 @@ const fs = require('fs');
2
2
  const path = require('path');
3
3
 
4
4
  const HOME_PATH = path.resolve(process.env.HOME, '.config/rew/default');
5
- const THEME_PATH = module.exports.THEME_PATH = path.resolve(HOME_PATH, 'theme.css');
5
+ const THEME_PATH = (module.exports.THEME_PATH = path.resolve(HOME_PATH, 'theme.css'));
6
6
 
7
7
  module.exports.FILES = [
8
- {
9
- path: HOME_PATH
10
- },
11
- {
12
- path: THEME_PATH,
13
- content: fs.readFileSync(path.resolve(__dirname, '../css/theme.css'))
14
- }
15
- ]
8
+ {
9
+ path: HOME_PATH,
10
+ },
11
+ {
12
+ path: THEME_PATH,
13
+ content: fs.readFileSync(path.resolve(__dirname, '../css/theme.css')),
14
+ },
15
+ ];