@makano/rew 1.2.4 → 1.2.6
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/civet/main.js +17239 -0
- package/lib/rew/cli/cli.js +57 -5
- package/lib/rew/cli/log.js +5 -1
- package/lib/rew/cli/run.js +2 -2
- package/lib/rew/cli/utils.js +147 -60
- package/lib/rew/const/default.js +5 -1
- package/lib/rew/const/ext.js +5 -0
- package/lib/rew/const/opt.js +7 -2
- package/lib/rew/const/usage.js +15 -0
- package/lib/rew/functions/exec.js +2 -2
- package/lib/rew/functions/export.js +1 -1
- package/lib/rew/functions/fs.js +6 -1
- package/lib/rew/functions/id.js +2 -2
- package/lib/rew/functions/import.js +34 -13
- package/lib/rew/functions/require.js +17 -1
- package/lib/rew/functions/stdout.js +4 -0
- package/lib/rew/main.js +1 -13
- package/lib/rew/modules/compiler.js +122 -26
- package/lib/rew/modules/context.js +13 -1
- package/lib/rew/modules/runtime.js +37 -20
- package/lib/rew/pkgs/conf.js +1 -1
- package/lib/rew/pkgs/rune.js +8 -1
- package/lib/rew/pkgs/serve.js +373 -0
- package/lib/rew/pkgs/stream.js +10 -0
- package/lib/rew/pkgs/web.js +504 -0
- package/package.json +10 -5
- package/runtime.d.ts +943 -0
- package/lib/coffeescript/browser.js +0 -156
- package/lib/coffeescript/cake.js +0 -134
- package/lib/coffeescript/coffeescript.js +0 -465
- package/lib/coffeescript/command.js +0 -832
- package/lib/coffeescript/grammar.js +0 -1930
- package/lib/coffeescript/helpers.js +0 -513
- package/lib/coffeescript/index.js +0 -230
- package/lib/coffeescript/lexer.js +0 -2316
- package/lib/coffeescript/nodes.js +0 -9784
- package/lib/coffeescript/optparse.js +0 -258
- package/lib/coffeescript/parser.js +0 -20384
- package/lib/coffeescript/register.js +0 -120
- package/lib/coffeescript/repl.js +0 -328
- package/lib/coffeescript/rewriter.js +0 -1448
- package/lib/coffeescript/scope.js +0 -191
- package/lib/coffeescript/sourcemap.js +0 -244
package/lib/rew/cli/cli.js
CHANGED
@@ -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, statSync } = require('fs');
|
8
|
+
const { existsSync, readFileSync, writeFileSync, mkdirSync, statSync, unlinkSync } = require('fs');
|
9
9
|
const { log } = require('./log');
|
10
10
|
const os = require('os');
|
11
11
|
const crypto = require('crypto');
|
@@ -17,6 +17,8 @@ const { print, input } = require('../functions/stdout');
|
|
17
17
|
const colors = require('colors');
|
18
18
|
const { req } = require('../misc/req');
|
19
19
|
const { gen_key } = require('../misc/bin');
|
20
|
+
const { REW_FILE_TYPE } = require('../const/ext');
|
21
|
+
const { generateRandomID } = require('../functions/id');
|
20
22
|
|
21
23
|
if (!existsSync(CONFIG_PATH) || !existsSync(CONFIG_PATH + '/repos.yaml')) {
|
22
24
|
mkdirSync(CONFIG_PATH, { recursive: true });
|
@@ -48,6 +50,11 @@ yargs(hideBin(process.argv))
|
|
48
50
|
alias: 'w',
|
49
51
|
describe: 'Watch the file for changes',
|
50
52
|
type: 'boolean',
|
53
|
+
})
|
54
|
+
.option('compile', {
|
55
|
+
alias: 'c',
|
56
|
+
describe: 'Compile and output the javascript',
|
57
|
+
type: 'boolean',
|
51
58
|
});
|
52
59
|
},
|
53
60
|
(argv) => {
|
@@ -56,8 +63,35 @@ yargs(hideBin(process.argv))
|
|
56
63
|
log('File not found:'.red.bold, argv.file, ':end');
|
57
64
|
return;
|
58
65
|
}
|
59
|
-
utils.runFileWithArgv(filePath, { watch: argv.watch });
|
66
|
+
utils.runFileWithArgv(filePath, { async: !process.stdin.isTTY, onlyCompile: argv.compile, watch: argv.watch });
|
67
|
+
},
|
68
|
+
)
|
69
|
+
.command(
|
70
|
+
'exec [code]',
|
71
|
+
'Executes in REPL',
|
72
|
+
(yargs) => {
|
73
|
+
yargs
|
74
|
+
.option('compile', {
|
75
|
+
alias: 'c',
|
76
|
+
describe: 'Compile and output the javascript',
|
77
|
+
type: 'boolean',
|
78
|
+
});
|
60
79
|
},
|
80
|
+
async (argv) => {
|
81
|
+
const replFile = '/tmp/rew-'+generateRandomID()+'-'+Date.now()+'.coffee';
|
82
|
+
let code = argv.code;
|
83
|
+
if(!process.stdin.isTTY) {
|
84
|
+
code = await utils.getAllPipeInput();
|
85
|
+
}
|
86
|
+
writeFileSync(replFile, code);
|
87
|
+
try{
|
88
|
+
utils.runFileWithArgv(replFile, { async: !process.stdin.isTTY, onlyCompile: argv.compile });
|
89
|
+
} catch(e){
|
90
|
+
console.error(e);
|
91
|
+
} finally {
|
92
|
+
unlinkSync(replFile);
|
93
|
+
}
|
94
|
+
}
|
61
95
|
)
|
62
96
|
.command(
|
63
97
|
'conf <command> [path] [key] [value]',
|
@@ -122,7 +156,7 @@ yargs(hideBin(process.argv))
|
|
122
156
|
type: 'string',
|
123
157
|
})
|
124
158
|
.option('dev', {
|
125
|
-
describe:
|
159
|
+
describe: `If your entry file is a .qrew, then just use .coffe or ${REW_FILE_TYPE.EXTENSION} instead`,
|
126
160
|
type: 'boolean',
|
127
161
|
})
|
128
162
|
.option('entry', {
|
@@ -223,6 +257,10 @@ yargs(hideBin(process.argv))
|
|
223
257
|
alias: 'r',
|
224
258
|
describe: 'Install requirements of the app',
|
225
259
|
type: 'boolean',
|
260
|
+
}).option('verbose', {
|
261
|
+
alias: 'v',
|
262
|
+
describe: 'Verbose',
|
263
|
+
type: 'boolean',
|
226
264
|
}).option('update', {
|
227
265
|
alias: 'u',
|
228
266
|
describe: 'Update the app',
|
@@ -280,6 +318,20 @@ yargs(hideBin(process.argv))
|
|
280
318
|
}
|
281
319
|
},
|
282
320
|
)
|
321
|
+
|
322
|
+
.command(
|
323
|
+
'cache <command>',
|
324
|
+
'Manage cache',
|
325
|
+
(yargs) => {
|
326
|
+
yargs.positional('command', {
|
327
|
+
describe: 'Command to clear/list',
|
328
|
+
type: 'string',
|
329
|
+
});
|
330
|
+
},
|
331
|
+
async (argv) => {
|
332
|
+
utils.cache(argv.command)
|
333
|
+
},
|
334
|
+
)
|
283
335
|
.command(
|
284
336
|
'repo <command> [name] [url]',
|
285
337
|
'Manage install repositories',
|
@@ -331,7 +383,7 @@ yargs(hideBin(process.argv))
|
|
331
383
|
})
|
332
384
|
.option('remove', {
|
333
385
|
alias: 'r',
|
334
|
-
describe: 'Remove all coffee',
|
386
|
+
describe: 'Remove all .coffee and '+REW_FILE_TYPE.EXTENSION,
|
335
387
|
type: 'boolean',
|
336
388
|
});
|
337
389
|
},
|
@@ -339,4 +391,4 @@ yargs(hideBin(process.argv))
|
|
339
391
|
utils.build(argv);
|
340
392
|
},
|
341
393
|
)
|
342
|
-
.help(!isFileGiven).argv;
|
394
|
+
.help(!isFileGiven).argv;
|
package/lib/rew/cli/log.js
CHANGED
@@ -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
|
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
|
});
|
package/lib/rew/cli/run.js
CHANGED
@@ -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 };
|
package/lib/rew/cli/utils.js
CHANGED
@@ -14,9 +14,15 @@ 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');
|
21
|
+
const { REW_FILE_TYPE } = require('../const/ext');
|
17
22
|
|
18
23
|
const binpath = path.join(conf({}).create('').root, '.bin');
|
19
24
|
const logspath = path.join(conf({}).create('').root, '.logs');
|
25
|
+
const cachepath = path.join(conf({}).create('').root, '.cache');
|
20
26
|
const localBinPath = path.join(binpath, '../../../', 'bin');
|
21
27
|
|
22
28
|
module.exports = {
|
@@ -30,7 +36,7 @@ module.exports = {
|
|
30
36
|
|
31
37
|
const runIt = () => {
|
32
38
|
if (options.watch) console.clear();
|
33
|
-
const imports = execRewFile(filePath, [filePath, ...(argv || [])]);
|
39
|
+
const imports = execRewFile(filePath, [filePath, ...(argv || [])], { onlyCompile: options?.onlyCompile, async: options?.async });
|
34
40
|
if (options.watch) {
|
35
41
|
imports.forEach((file) => {
|
36
42
|
watchIt(file);
|
@@ -42,15 +48,21 @@ module.exports = {
|
|
42
48
|
runIt();
|
43
49
|
},
|
44
50
|
runFileWithArgv(filePath, options = {}, cargv) {
|
45
|
-
|
51
|
+
let argv = cargv || process.argv;
|
46
52
|
argv.shift();
|
47
|
-
if (argv[0].endsWith('
|
53
|
+
if (argv[0].endsWith(REW_FILE_TYPE.EXTENSION) || argv[0].endsWith('.coffee')) {
|
48
54
|
if (argv[1] == 'run') {
|
49
55
|
argv.splice(0, 3);
|
50
56
|
} else if(argv[1] == '-w' || argv[1] == '--watch'){
|
51
57
|
argv.splice(0, 3);
|
52
58
|
} else argv.splice(0, 2);
|
53
59
|
}
|
60
|
+
if (argv[1] == 'exec') {
|
61
|
+
argv.splice(0, 2);
|
62
|
+
}
|
63
|
+
if (argv.includes('--')) {
|
64
|
+
argv = argv.slice(argv.indexOf('--') + 1, argv.length);
|
65
|
+
}
|
54
66
|
this.runFile(filePath, options, argv)
|
55
67
|
},
|
56
68
|
conf(command, fullPath, key, value) {
|
@@ -59,15 +71,19 @@ module.exports = {
|
|
59
71
|
if (!fullPath || fullPath == 'list') {
|
60
72
|
return fs.readdirSync(con.CONFIG_PATH).join('\n');
|
61
73
|
} else {
|
62
|
-
|
63
|
-
|
74
|
+
let name = fullPath.indexOf('/') ? fullPath.split('/')[0] : fullPath;
|
75
|
+
let dpath = fullPath.indexOf('/') ? fullPath.split('/').slice(1).join('/') : '';
|
76
|
+
if(fullPath.startsWith('/')){
|
77
|
+
dpath = name;
|
78
|
+
name = '';
|
79
|
+
}
|
64
80
|
const root = con.create(name);
|
65
81
|
if (dpath) {
|
66
82
|
const fp = path.join(root.root, dpath);
|
67
|
-
if (fs.existsSync(fp) && fs.statSync(fp).isDirectory()) {
|
83
|
+
if (!fullPath.startsWith('/') && fs.existsSync(fp) && fs.statSync(fp).isDirectory()) {
|
68
84
|
return fs.readdirSync(fp).join('\n');
|
69
85
|
} else {
|
70
|
-
const o =
|
86
|
+
const o = dpath && dpath !== '/' ? root.optionCenter(dpath) : root.optionCenter('_default');
|
71
87
|
return key ? o.get(key) : o.getAll(true);
|
72
88
|
}
|
73
89
|
} else {
|
@@ -75,14 +91,18 @@ module.exports = {
|
|
75
91
|
}
|
76
92
|
}
|
77
93
|
} else {
|
78
|
-
|
79
|
-
|
80
|
-
if
|
94
|
+
let name = fullPath.indexOf('/') ? fullPath.split('/')[0] : fullPath;
|
95
|
+
let dpath = fullPath.indexOf('/') ? fullPath.split('/')[1] : '';
|
96
|
+
if(fullPath.startsWith('/')){
|
97
|
+
dpath = name == '/' ? '_default' : name;
|
98
|
+
name = '';
|
99
|
+
}
|
100
|
+
if (key) {
|
81
101
|
const root = con.create(name);
|
82
102
|
const o = dpath ? root.optionCenter(dpath) : root;
|
83
103
|
if (command == 'set') {
|
84
104
|
if (value) {
|
85
|
-
o.set(key, value);
|
105
|
+
o.set(key, value == 'false' || value == 'true' ? (value == 'true' ? true : false) : !isNaN(parseFloat(value)) ? parseFloat(value) : value);
|
86
106
|
} else {
|
87
107
|
log('Value not specified', ':end');
|
88
108
|
}
|
@@ -90,7 +110,7 @@ module.exports = {
|
|
90
110
|
o.remove(key);
|
91
111
|
}
|
92
112
|
} else {
|
93
|
-
log(
|
113
|
+
log('Key not specified', ':end');
|
94
114
|
}
|
95
115
|
}
|
96
116
|
},
|
@@ -105,15 +125,23 @@ module.exports = {
|
|
105
125
|
const create = () => {
|
106
126
|
fs.mkdirSync(projectPath, { recursive: true });
|
107
127
|
const confPath = path.join(projectPath, 'app.yaml');
|
108
|
-
const entryFile = path.join(projectPath, 'main.coffee');
|
109
|
-
fs.writeFileSync(confPath, jsYaml.dump({ manifest: { package: project.package, private: false }, exec: { entry: 'main.coffee' }, assets: { icon: 'assets/icon.png', folder: './assets' }, install: { requirements: [] } }));
|
128
|
+
const entryFile = path.join(projectPath, 'main'+(project.civet ? REW_FILE_TYPE.EXTENSION : '.coffee'));
|
129
|
+
fs.writeFileSync(confPath, jsYaml.dump({ manifest: { package: project.package, private: false }, exec: { entry: 'main'+(project.civet ? REW_FILE_TYPE.EXTENSION : '.coffee') }, assets: { icon: 'assets/icon.png', folder: './assets' }, install: { requirements: [] } }));
|
110
130
|
fs.writeFileSync(entryFile, `print("Hello World!")`);
|
111
131
|
fs.mkdirSync(path.join(projectPath, 'assets'), { recursive: true });
|
112
132
|
if (project.git) {
|
113
133
|
fs.writeFileSync(path.join(projectPath, '.gitignore'), `node_modules/\npackage-lock.json`);
|
114
134
|
execSync('cd ' + projectPath + ' && git init . && git branch -m main', { stdio: 'ignore' });
|
115
135
|
}
|
136
|
+
if(project.intellisense){
|
137
|
+
fs.copyFileSync(path.join(__dirname, '../../../tsconfig.json'), path.join(projectPath, 'tsconfig.json'));
|
138
|
+
fs.copyFileSync(path.join(__dirname, '../../../runtime.d.ts'), path.join(projectPath, 'runtime.d.ts'));
|
139
|
+
}
|
116
140
|
execSync('cd ' + projectPath + ' && npm init -y', { stdio: 'ignore' });
|
141
|
+
if(project.civet){
|
142
|
+
log('Installing NPM Packages');
|
143
|
+
execSync('cd '+projectPath+' && npm i @types/node --no-save', { stdio: 'ignore' });
|
144
|
+
}
|
117
145
|
// log('Installing '+npm_package_name);
|
118
146
|
// exec('cd '+projectPath+' && npm i '+npm_package_name, (err) => {
|
119
147
|
// if(err){
|
@@ -130,9 +158,15 @@ module.exports = {
|
|
130
158
|
rl.question(logget(' Package Name: '.blue), (pkg) => {
|
131
159
|
if (pkg.trim()) {
|
132
160
|
project.package = pkg.trim();
|
133
|
-
rl.question(logget('
|
134
|
-
project.
|
135
|
-
|
161
|
+
rl.question(logget(' Use intellisense declarations ? (y/N): '.magenta.bold), (inteli) => {
|
162
|
+
project.intellisense = inteli.toLowerCase() == 'y' || inteli.toLowerCase() == 'yes';
|
163
|
+
rl.question(logget(' Use Civet For main ? (y/N): '.blue.bold), (civet) => {
|
164
|
+
project.civet = civet.toLowerCase() == 'y' || civet.toLowerCase() == 'yes';
|
165
|
+
rl.question(logget(' Use git ? (y/N): '.yellow.bold), (use_git) => {
|
166
|
+
project.git = use_git.toLowerCase() == 'y' || use_git.toLowerCase() == 'yes';
|
167
|
+
create();
|
168
|
+
});
|
169
|
+
});
|
136
170
|
});
|
137
171
|
} else {
|
138
172
|
rl.close();
|
@@ -153,8 +187,8 @@ module.exports = {
|
|
153
187
|
c.exec.entry = c.exec[options.entry] || c.exec.entry;
|
154
188
|
}
|
155
189
|
if (c.exec.entry) {
|
156
|
-
if (byPath && options.dev) c.exec.entry = c.entry.endsWith('.qrew') ? c.exec.entry.replace(/\.qrew$/, '.coffee') : c.exec.entry;
|
157
190
|
let r = path.resolve(root, c.exec.entry);
|
191
|
+
if (byPath && options.dev) r = r.endsWith('.qrew') ? r.replace(/\.qrew$/, (a, b) => fs.existsSync(r.replace(a, '.coffee')) ? '.coffee' : REW_FILE_TYPE.EXTENSION) : r;
|
158
192
|
if (options.build) {
|
159
193
|
this.build({
|
160
194
|
file: r,
|
@@ -162,7 +196,7 @@ module.exports = {
|
|
162
196
|
});
|
163
197
|
r = path.resolve(root, c.exec.entry.replace(new RegExp(path.extname(c.exec.entry).replace('.', '\\.') + '$'), options.translate ? '.js' : '.qrew'));
|
164
198
|
}
|
165
|
-
this.runFileWithArgv(r);
|
199
|
+
this.runFileWithArgv(r, { async: !process.stdin.isTTY });
|
166
200
|
}
|
167
201
|
};
|
168
202
|
|
@@ -195,28 +229,29 @@ module.exports = {
|
|
195
229
|
});
|
196
230
|
log(' Installing '.blue + pname.green.bold);
|
197
231
|
log(' Package'.blue + ': ' + p.name.green + '@' + p.version.yellow);
|
198
|
-
if (p.
|
199
|
-
log(' Description'.blue + '
|
232
|
+
if (p.description) {
|
233
|
+
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');
|
234
|
+
}
|
235
|
+
if (p.keywords && p.keywords.length) {
|
236
|
+
log(' Tags'.blue + '\n ' + log.endPrefix + p.keywords.map(i => '#'+i).join(' '), ':end')
|
200
237
|
}
|
201
238
|
const done = (f) => {
|
202
239
|
if (f.toLowerCase() == 'y' || f.toLowerCase() == 'yes') {
|
203
240
|
if (fs.existsSync(installPath)) {
|
204
241
|
execSync(`rm -r ${installPath}`);
|
205
242
|
}
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
execSync(`rm -r ${apppath}`);
|
210
|
-
}
|
211
|
-
log(' Installed '.green + pname.cyan.bold, c.install ? '' : ':end');
|
212
|
-
if (c.install) {
|
213
|
-
if (c.install.build) {
|
214
|
-
log(' Building'.blue);
|
243
|
+
if (c.install?.build) {
|
244
|
+
log(' Building'.blue);
|
245
|
+
try{
|
215
246
|
this.build({
|
216
247
|
...c.install.build,
|
217
|
-
file: path.join(
|
248
|
+
file: path.join(apppath, c.exec[c.install.build.file] || c.install.build.file)
|
218
249
|
});
|
219
|
-
}
|
250
|
+
} catch(e){}
|
251
|
+
}
|
252
|
+
execSync(`cp -r ${apppath} ${installPath}`);
|
253
|
+
execSync(`chmod 444 ${installPath}/app.yaml`);
|
254
|
+
if (c.install) {
|
220
255
|
if (c.install.commands) {
|
221
256
|
for (let command of c.install.commands) {
|
222
257
|
try{
|
@@ -224,7 +259,7 @@ module.exports = {
|
|
224
259
|
} catch(e){
|
225
260
|
const logFile = path.join(logspath, 'logs-'+Date.now()+'.log');
|
226
261
|
fs.writeFileSync(logFile, e.toString() +'\n'+ e.stack);
|
227
|
-
log(` Command Failed: ${command}, check logs at ${logFile}
|
262
|
+
log(` Command Failed: ${command}, check logs at ${logFile}`);
|
228
263
|
}
|
229
264
|
}
|
230
265
|
}
|
@@ -232,28 +267,32 @@ module.exports = {
|
|
232
267
|
this.runFileWithArgv(path.join(installPath, c.exec[c.install.file] || c.install.file), {}, []);
|
233
268
|
}
|
234
269
|
if (c.install.requirements) {
|
235
|
-
this.installReq(c);
|
270
|
+
this.installReq(c, opts);
|
236
271
|
}
|
237
272
|
if (c.install.exec) {
|
238
273
|
// this.installReq(c);
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
274
|
+
if(conf({}).create('').get('executables') == false){
|
275
|
+
log(' Ignoring executables'.blue);
|
276
|
+
} else {
|
277
|
+
for (let i in c.install.exec) {
|
278
|
+
let iff = c.install.exec[i];
|
279
|
+
if (iff in c.exec) iff = c.exec[iff];
|
280
|
+
const file = path.join(installPath, iff);
|
281
|
+
const filepath = path.join(binpath, i);
|
282
|
+
const binfp = path.join(localBinPath, i);
|
283
|
+
if (!fs.existsSync(localBinPath)) fs.mkdirSync(localBinPath, { recursive: true });
|
284
|
+
fs.writeFileSync(filepath, `#!/usr/bin/env bash\n#@app.${pname}\nrew ${file} $*`);
|
285
|
+
fs.chmodSync(filepath, '755');
|
286
|
+
if(fs.existsSync(binfp)) fs.unlinkSync(binfp);
|
287
|
+
fs.linkSync(filepath, binfp);
|
288
|
+
}
|
249
289
|
}
|
250
290
|
}
|
291
|
+
|
292
|
+
log(' Installed '.green + pname.cyan.bold, ':end');
|
251
293
|
}
|
252
294
|
rl.close();
|
253
295
|
} else {
|
254
|
-
if (rmidiri) {
|
255
|
-
execSync(`rm -rf ${apppath}`);
|
256
|
-
}
|
257
296
|
log(' Canceled install'.red.bold, ':end');
|
258
297
|
rl.close();
|
259
298
|
}
|
@@ -332,6 +371,9 @@ module.exports = {
|
|
332
371
|
if (fs.existsSync(importedFilePath)) {
|
333
372
|
importsArray.push(importStatement);
|
334
373
|
processFile(importedFilePath, importsArray);
|
374
|
+
} else if (fs.existsSync(importedFilePath + REW_FILE_TYPE.EXTENSION)) {
|
375
|
+
importsArray.push(importStatement);
|
376
|
+
processFile(importedFilePath + REW_FILE_TYPE.EXTENSION, importsArray);
|
335
377
|
} else if (fs.existsSync(importedFilePath + '.coffee')) {
|
336
378
|
importsArray.push(importStatement);
|
337
379
|
processFile(importedFilePath + '.coffee', importsArray);
|
@@ -344,7 +386,7 @@ module.exports = {
|
|
344
386
|
|
345
387
|
const appPath = findAppInfo(filePath);
|
346
388
|
|
347
|
-
const compiled = argv.translate ? compile({ content }, {}) : to_qrew(content
|
389
|
+
const compiled = argv.translate ? compile({ content }, {}) : to_qrew(`"initFile ${filePath}"\n${path.basename(content)}`, appPath?.config?.manifest?.package || path.basename(filePath).split('.').slice(0, -1).join('.'));
|
348
390
|
writeCompiledFile(filePath, compiled);
|
349
391
|
}
|
350
392
|
|
@@ -355,21 +397,51 @@ module.exports = {
|
|
355
397
|
processFile(filePath, importsArray);
|
356
398
|
log(' Compiled'.yellow, (importsArray.length + 1 + '').blue, `file${importsArray.length ? 's' : ''}.`.yellow, ':end');
|
357
399
|
},
|
358
|
-
|
400
|
+
cache(command){
|
401
|
+
if(command == 'list'){
|
402
|
+
console.log(fs.readdirSync(cachepath).join('\n').trim());
|
403
|
+
} else {
|
404
|
+
fs.readdirSync(cachepath).forEach(file => fs.rmSync(path.join(cachepath, file), { recursive: true }));
|
405
|
+
}
|
406
|
+
},
|
407
|
+
async cloneGit(gitpath, opts) {
|
359
408
|
const p = gitpath.split('github:')[1];
|
409
|
+
const clonePath = path.join(cachepath, 'rew-git-clone-'+gen_key(gitpath).substring(0, 12));
|
360
410
|
const url = `https://github.com/${p}`;
|
361
|
-
const apiurl = `https://api.github.com/repos/${p}`;
|
411
|
+
const apiurl = `https://api.github.com/repos/${p}/commits`;
|
412
|
+
const load = loading("Finding Repo...".yellow).start();
|
362
413
|
try {
|
363
414
|
const response = await req(apiurl);
|
364
|
-
if (response.status !== 200)
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
415
|
+
if (response.status !== 200) {
|
416
|
+
load.stop();
|
417
|
+
return log(' Package not found in github'.red.bold, ':end');
|
418
|
+
}
|
419
|
+
let pull = false;
|
420
|
+
if(fs.existsSync(clonePath)){
|
421
|
+
if(fs.existsSync(path.join(clonePath, response.data[0].sha))){
|
422
|
+
load.stop();
|
423
|
+
log('Found Cache'.yellow);
|
424
|
+
return clonePath+'/clone';
|
425
|
+
} else {
|
426
|
+
pull = true;
|
427
|
+
}
|
428
|
+
}
|
429
|
+
fs.mkdirSync(clonePath, { recursive: true });
|
430
|
+
fs.writeFileSync(path.join(clonePath, response.data[0].sha), '');
|
431
|
+
load.text = 'Cloning from github'.blue.bold;
|
432
|
+
await sleep(100)
|
433
|
+
if(pull) execSync(`cd ${clonePath}/clone && git pull`, { stdio: opts.verbose ? 'inherit' : 'ignore' });
|
434
|
+
else execSync(`git clone ${url} ${clonePath}/clone`, { stdio: opts.verbose ? 'pipe' : 'ignore' });
|
435
|
+
load.text = 'Installing npm packages'.green.bold;
|
436
|
+
await sleep(100)
|
437
|
+
execSync(`cd ${clonePath}/clone && npm i`, { stdio: opts.verbose ? 'inherit' : 'ignore' });
|
438
|
+
load.stop();
|
439
|
+
return clonePath+'/clone';
|
371
440
|
} catch (e) {
|
372
|
-
|
441
|
+
const logFile = path.join(logspath, 'logs-'+Date.now()+'.log');
|
442
|
+
fs.writeFileSync(logFile, e.toString() +'\n'+ e.stack);
|
443
|
+
load.stop();
|
444
|
+
log(' Something went wrong, check logs at'.red.bold, logFile.green, ':end');
|
373
445
|
}
|
374
446
|
},
|
375
447
|
findRepo(repo) {
|
@@ -377,7 +449,7 @@ module.exports = {
|
|
377
449
|
return repos.get(repo);
|
378
450
|
},
|
379
451
|
async installAppFrom(path, opts) {
|
380
|
-
if (path.startsWith('github:')) this.installApp(await this.cloneGit(path
|
452
|
+
if (path.startsWith('github:')) this.installApp(await this.cloneGit(path, opts), opts, true);
|
381
453
|
else if (path.startsWith('@')) this.fromRepo(path, opts);
|
382
454
|
else this.installApp(path, opts, null, null);
|
383
455
|
},
|
@@ -465,7 +537,7 @@ module.exports = {
|
|
465
537
|
console.log(Object.keys(confInstance.getAll()).join('\n'));
|
466
538
|
}
|
467
539
|
} else if (command === 'delete') {
|
468
|
-
confInstance.remove(
|
540
|
+
confInstance.remove(key);
|
469
541
|
} else {
|
470
542
|
log(' Invalid command'.red.bold, ':end');
|
471
543
|
}
|
@@ -474,6 +546,21 @@ module.exports = {
|
|
474
546
|
log('First time init')
|
475
547
|
conf({}).create('').optionCenter('repos').set('rewpkgs', '//raw.githubusercontent.com/kevinJ045/rewpkgs/main/main.yaml');
|
476
548
|
fs.mkdirSync(binpath, { recursive: true });
|
549
|
+
fs.mkdirSync(cachepath, { recursive: true });
|
477
550
|
fs.mkdirSync(logspath, { recursive: true });
|
551
|
+
},
|
552
|
+
getAllPipeInput(){
|
553
|
+
return new Promise((resolve) => {
|
554
|
+
let data = '';
|
555
|
+
process.stdin.setEncoding('utf8');
|
556
|
+
|
557
|
+
process.stdin.on('data', (chunk) => {
|
558
|
+
data += chunk;
|
559
|
+
});
|
560
|
+
|
561
|
+
process.stdin.on('end', () => {
|
562
|
+
resolve(data);
|
563
|
+
});
|
564
|
+
});
|
478
565
|
}
|
479
566
|
};
|
package/lib/rew/const/default.js
CHANGED
@@ -7,11 +7,12 @@ const { match } = require('../functions/match');
|
|
7
7
|
const { map } = require('../functions/map');
|
8
8
|
const { typex, typeis, typedef, typei, int, float, num, str, bool } = require('../functions/types');
|
9
9
|
const { isEmpty, clone, deepClone, merge, uniqueId, compose, curry } = require('../functions/core');
|
10
|
-
const { print, input, clear } = require('../functions/stdout');
|
10
|
+
const { print, input, clear, printf } = 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
14
|
const { jsons, yaml, json, yamls } = require('../functions/json');
|
15
|
+
const { generateRandomID } = require('../functions/id');
|
15
16
|
|
16
17
|
module.exports = {
|
17
18
|
cenum,
|
@@ -49,8 +50,11 @@ module.exports = {
|
|
49
50
|
yaml,
|
50
51
|
yamls,
|
51
52
|
|
53
|
+
genID: generateRandomID,
|
54
|
+
|
52
55
|
curl,
|
53
56
|
|
54
57
|
print,
|
58
|
+
printf,
|
55
59
|
input,
|
56
60
|
};
|
package/lib/rew/const/opt.js
CHANGED
@@ -1,10 +1,15 @@
|
|
1
|
+
const { REW_FILE_TYPE } = require("./ext");
|
2
|
+
|
1
3
|
const execOptions = {
|
2
4
|
sharedContext: true,
|
3
|
-
resolveExtensions: [{ ext: '.js', options: { type: 'js' } }, { ext: '.qrew', options: { qrew: true } }
|
5
|
+
resolveExtensions: [REW_FILE_TYPE.EXTENSION, ".coffee", { ext: '.js', options: { type: 'js' } }, { ext: '.qrew', options: { qrew: true } }],
|
4
6
|
nativeRequire: false,
|
7
|
+
useImport: false,
|
5
8
|
cwdAlias: '$',
|
6
|
-
jsxPragma: 'createElement',
|
9
|
+
jsxPragma: '__using__.JSX.createElement',
|
7
10
|
jsx: false,
|
11
|
+
typescript: false,
|
12
|
+
decorators: false
|
8
13
|
};
|
9
14
|
|
10
15
|
module.exports.execOptions = execOptions;
|
@@ -0,0 +1,15 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
|
4
|
+
module.exports.USING_DEFAULT = {
|
5
|
+
JSX: {
|
6
|
+
param: (param) => ({ createElement: param }),
|
7
|
+
use: (options) => options.jsx = true
|
8
|
+
},
|
9
|
+
TYPES: {
|
10
|
+
use: (options) => options.typescript = true
|
11
|
+
},
|
12
|
+
DECORATORS: {
|
13
|
+
use: (options) => options.decorators = true
|
14
|
+
}
|
15
|
+
}
|
package/lib/rew/functions/fs.js
CHANGED
@@ -31,7 +31,11 @@ module.exports = (currentFile) => {
|
|
31
31
|
}
|
32
32
|
|
33
33
|
function rm(filepath, options) {
|
34
|
-
return fs.
|
34
|
+
return fs.rmSync(gp(filepath), { recursive: true,...options });
|
35
|
+
}
|
36
|
+
|
37
|
+
function unlink(filepath, options) {
|
38
|
+
return fs.unlinkSync(gp(filepath));
|
35
39
|
}
|
36
40
|
|
37
41
|
function chmod(filepath, mode, options) {
|
@@ -51,6 +55,7 @@ module.exports = (currentFile) => {
|
|
51
55
|
mkdir,
|
52
56
|
chmod,
|
53
57
|
rm,
|
58
|
+
unlink,
|
54
59
|
fstat,
|
55
60
|
exists,
|
56
61
|
write,
|
package/lib/rew/functions/id.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
module.exports.generateRandomID = function generateRandomID(length = 12) {
|
2
|
-
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
1
|
+
module.exports.generateRandomID = function generateRandomID(length = 12, _characters) {
|
2
|
+
const characters = _characters || 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
3
3
|
const charactersLength = characters.length;
|
4
4
|
let randomID = '';
|
5
5
|
|