@makano/rew 1.1.81 → 1.2.0
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/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 +296 -239
- package/lib/rew/cli/log.js +27 -27
- package/lib/rew/cli/run.js +8 -8
- package/lib/rew/cli/utils.js +353 -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,360 @@
|
|
|
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');
|
|
10
14
|
|
|
11
|
-
const npm_package_name =
|
|
15
|
+
const npm_package_name = '@makano/rew';
|
|
12
16
|
|
|
13
17
|
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");
|
|
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');
|
|
114
110
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
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
|
+
};
|
|
127
131
|
|
|
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
|
-
|
|
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
|
+
}
|
|
205
327
|
},
|
|
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
|
+
}
|
|
206
360
|
};
|