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