@makano/rew 1.2.95 → 1.2.97
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/README.md +7 -1
- package/lib/rew/cli/cli.js +31 -4
- package/lib/rew/cli/helpers.js +26 -1
- package/lib/rew/cli/miscUtils.js +41 -0
- package/lib/rew/cli/utils.js +52 -10
- package/lib/rew/const/stdns.js +1 -0
- package/lib/rew/const/usage.js +41 -2
- package/lib/rew/functions/import.js +19 -9
- package/lib/rew/functions/types.js +2 -2
- package/lib/rew/modules/compiler.js +14 -7
- package/lib/rew/modules/context.js +41 -32
- package/lib/rew/modules/runtime.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
@@ -12,9 +12,15 @@ Rew
|
|
12
12
|
<a href="https://www.npmjs.com/package/rayous"> <img src="https://img.shields.io/npm/v/@makano/rew?style=for-the-badge&logo=npm&color=b4befe&logoColor=9399b2&labelColor=181825" alt="npm version" /></a>
|
13
13
|
</p>
|
14
14
|
|
15
|
-
Rew is a simple lightweight coffeescript runtime, made to
|
15
|
+
Rew is a simple lightweight coffeescript runtime, made to simplify using coffescript and revive it
|
16
16
|
in the process.
|
17
17
|
|
18
|
+
```coffee
|
19
|
+
using namespace std::ns ->
|
20
|
+
define Main ->
|
21
|
+
print 'hello world' |> str
|
22
|
+
```
|
23
|
+
|
18
24
|
## Getting Started
|
19
25
|
1. Install `rew` globally
|
20
26
|
```bash
|
package/lib/rew/cli/cli.js
CHANGED
@@ -338,18 +338,45 @@ yargs(hideBin(process.argv))
|
|
338
338
|
}
|
339
339
|
},
|
340
340
|
)
|
341
|
-
|
342
341
|
.command(
|
343
342
|
'cache <command>',
|
344
343
|
'Manage cache',
|
344
|
+
(yargs) => {
|
345
|
+
yargs
|
346
|
+
.positional('command', {
|
347
|
+
describe: 'Command to clear/list/show',
|
348
|
+
type: 'string',
|
349
|
+
})
|
350
|
+
.example('rew cache list', 'Lists all caches')
|
351
|
+
.example('rew cache clear', 'Clears all caches')
|
352
|
+
.example('rew cache clear all', 'Clears all caches')
|
353
|
+
.example('rew cache clear [id]', 'Clears all caches for id [id]')
|
354
|
+
.example('rew cache show [id]', 'Shows commits downloaded for [id]')
|
355
|
+
.example('rew cache show [id]', 'Shows commits downloaded for [id]')
|
356
|
+
.example('rew cache show [id]/clone', 'Shows the contents for [id]')
|
357
|
+
.example('rew cache show [id]#tag', 'Shows the tag for [id]')
|
358
|
+
.example('rew cache show [id]#commit', 'Shows the current commit for [id]')
|
359
|
+
.example('rew cache show [id]#name', 'Shows the name for [id]')
|
360
|
+
.example('rew cache show [id]/clone/app.yaml', 'Shows the app config for [id]')
|
361
|
+
.example('rew cache show [id]/clone/path/to/file', 'Gives you the path to the file inside [id]')
|
362
|
+
.example('rew cache show [id]/clone/path/to/file', 'Gives you the path to the file inside [id]')
|
363
|
+
.example('rew cache install [id]', 'Installs cache')
|
364
|
+
},
|
365
|
+
async (argv) => {
|
366
|
+
require('./utils').cache(argv.command, ...argv._.slice(1));
|
367
|
+
},
|
368
|
+
)
|
369
|
+
.command(
|
370
|
+
'misc <command>',
|
371
|
+
'Misc functions',
|
345
372
|
(yargs) => {
|
346
373
|
yargs.positional('command', {
|
347
|
-
describe: '
|
374
|
+
describe: 'Misc command name',
|
348
375
|
type: 'string',
|
349
376
|
});
|
350
377
|
},
|
351
|
-
|
352
|
-
require('./
|
378
|
+
(argv) => {
|
379
|
+
require('./miscUtils')[argv.command](...argv._.slice(1));
|
353
380
|
},
|
354
381
|
)
|
355
382
|
.command(
|
package/lib/rew/cli/helpers.js
CHANGED
@@ -35,11 +35,36 @@ function getAllPipeInput(){
|
|
35
35
|
});
|
36
36
|
}
|
37
37
|
|
38
|
+
/**
|
39
|
+
*
|
40
|
+
* @param {string} string
|
41
|
+
* @param {Record<string,(replacedString: string, originalString: string) => any>} order
|
42
|
+
* @returns { { string: string, [key: string]: any } }
|
43
|
+
*/
|
44
|
+
function hashTags(string, order){
|
45
|
+
const hashes = Object.keys(order);
|
46
|
+
const h = {};
|
47
|
+
let s = string;
|
48
|
+
for(let i of hashes){
|
49
|
+
if(string.includes(`#${i}`)){
|
50
|
+
const str = s.replace(`#${i}`, '');
|
51
|
+
h[i] = order[i](str, string);
|
52
|
+
if(h[i]?.$set) {s = h[i].$set; string = s }
|
53
|
+
else s = str;
|
54
|
+
}
|
55
|
+
}
|
56
|
+
return {
|
57
|
+
string: s,
|
58
|
+
...h
|
59
|
+
};
|
60
|
+
}
|
61
|
+
|
38
62
|
module.exports = {
|
39
63
|
binpath,
|
40
64
|
logspath,
|
41
65
|
cachepath,
|
42
66
|
localBinPath,
|
43
67
|
npm_package_name,
|
44
|
-
getAllPipeInput
|
68
|
+
getAllPipeInput,
|
69
|
+
hashTags
|
45
70
|
}
|
@@ -0,0 +1,41 @@
|
|
1
|
+
const { findAppInfo } = require("../misc/findAppInfo");
|
2
|
+
const { log } = require("./log");
|
3
|
+
const colors = require('colors');
|
4
|
+
const path = require('path');
|
5
|
+
const fs = require('fs');
|
6
|
+
const { CONFIG_PATH } = require("../const/config_path");
|
7
|
+
|
8
|
+
module.exports = {
|
9
|
+
types(projectPath){
|
10
|
+
if(!projectPath) projectPath = process.cwd();
|
11
|
+
else projectPath = path.resolve(process.cwd(), projectPath);
|
12
|
+
const projectinfo = findAppInfo(projectPath+'/app.yaml');
|
13
|
+
if(!projectinfo){
|
14
|
+
log('Path not a rew app'.red.bold, ':end')
|
15
|
+
return;
|
16
|
+
}
|
17
|
+
let typesToLoad = ['rew'];
|
18
|
+
if(projectinfo.config?.types){
|
19
|
+
typesToLoad = projectinfo.config?.types;
|
20
|
+
}
|
21
|
+
fs.mkdirSync(path.join(projectPath, 'node_modules/@types/rew'), { recursive: true });
|
22
|
+
|
23
|
+
|
24
|
+
typesToLoad.forEach(name => {
|
25
|
+
let filename = name+'.d.ts';
|
26
|
+
if(name == 'rew'){
|
27
|
+
fs.copyFileSync(path.join(__dirname, '../../../runtime.d.ts'), path.join(projectPath, 'node_modules/@types/rew/index.d.ts'));
|
28
|
+
return;
|
29
|
+
}
|
30
|
+
let p = path.resolve(CONFIG_PATH, name, 'app', 'types.d.ts');
|
31
|
+
|
32
|
+
if(name.indexOf('/') > -1) {
|
33
|
+
const fn = name.split('/').slice(1).join('/')+'.d.ts';
|
34
|
+
p = path.resolve(CONFIG_PATH, name.split('/')[0], 'app', fn);
|
35
|
+
filename = name.split('/')[0]+'-'+path.basename(fn);
|
36
|
+
}
|
37
|
+
if(fs.existsSync(p)) fs.copyFileSync(p, path.join(projectPath, 'node_modules/@types/rew/'+filename));
|
38
|
+
});
|
39
|
+
},
|
40
|
+
|
41
|
+
}
|
package/lib/rew/cli/utils.js
CHANGED
@@ -12,9 +12,7 @@ const { to_qrew } = require('../qrew/compile');
|
|
12
12
|
const { findAppInfo } = require('../misc/findAppInfo');
|
13
13
|
const { req } = require('../misc/req');
|
14
14
|
const { CONFIG_PATH } = require('../const/config_path');
|
15
|
-
const {
|
16
|
-
const { execRewFile, runFileWithArgv } = require('./run');
|
17
|
-
const { seededID } = require('../misc/seededid');
|
15
|
+
const { runFileWithArgv } = require('./run');
|
18
16
|
const loading = require('loading-cli');
|
19
17
|
const sleep = require('../functions/sleep');
|
20
18
|
const { gen_key } = require('../misc/bin');
|
@@ -24,7 +22,8 @@ const {
|
|
24
22
|
binpath,
|
25
23
|
logspath,
|
26
24
|
cachepath,
|
27
|
-
localBinPath
|
25
|
+
localBinPath,
|
26
|
+
hashTags
|
28
27
|
} = require('./helpers');
|
29
28
|
const { input } = require('../functions/stdout');
|
30
29
|
|
@@ -94,9 +93,13 @@ module.exports = {
|
|
94
93
|
const project = {};
|
95
94
|
const create = () => {
|
96
95
|
fs.mkdirSync(projectPath, { recursive: true });
|
96
|
+
const confObj = { 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: [] } };
|
97
97
|
const confPath = path.join(projectPath, 'app.yaml');
|
98
98
|
const entryFile = path.join(projectPath, 'main'+(project.civet ? REW_FILE_TYPE.EXTENSION : '.coffee'));
|
99
|
-
|
99
|
+
if(project.intellisense) {
|
100
|
+
confObj.types = ['rew'];
|
101
|
+
}
|
102
|
+
fs.writeFileSync(confPath, jsYaml.dump(confObj));
|
100
103
|
fs.writeFileSync(entryFile, `print("Hello World!")`);
|
101
104
|
fs.mkdirSync(path.join(projectPath, 'assets'), { recursive: true });
|
102
105
|
if (project.git) {
|
@@ -104,8 +107,8 @@ module.exports = {
|
|
104
107
|
execSync('cd ' + projectPath + ' && git init . && git branch -m main', { stdio: 'ignore' });
|
105
108
|
}
|
106
109
|
if(project.intellisense){
|
107
|
-
|
108
|
-
|
110
|
+
require('./miscUtils')
|
111
|
+
.types(projectPath);
|
109
112
|
}
|
110
113
|
execSync('cd ' + projectPath + ' && npm init -y', { stdio: 'ignore' });
|
111
114
|
if(project.civet){
|
@@ -382,11 +385,50 @@ module.exports = {
|
|
382
385
|
processFile(filePath, importsArray);
|
383
386
|
log(' Compiled'.yellow, (importsArray.length + 1 + '').blue, `file${importsArray.length ? 's' : ''}.`.yellow, ':end');
|
384
387
|
},
|
385
|
-
cache(command){
|
388
|
+
cache(command, file){
|
389
|
+
|
390
|
+
const findGitCommitPath = (p) => {
|
391
|
+
const heads = path.join(p, '.git/refs/heads');
|
392
|
+
if(!fs.existsSync(heads)) return '';
|
393
|
+
const refs = fs.readdirSync(heads);
|
394
|
+
if(!refs.length) return '';
|
395
|
+
return fs.readFileSync(path.join(heads, refs[0]), { encoding: 'utf-8' }).trim();
|
396
|
+
}
|
397
|
+
|
386
398
|
if(command == 'list'){
|
387
399
|
console.log(fs.readdirSync(cachepath).join('\n').trim());
|
388
|
-
} else {
|
389
|
-
|
400
|
+
} else if(command == 'clear'){
|
401
|
+
if(file) fs.rmSync(path.join(cachepath, file), { recursive: true });
|
402
|
+
else if(file == 'all') fs.readdirSync(cachepath).forEach(file => fs.rmSync(path.join(cachepath, file), { recursive: true }));
|
403
|
+
} else if(command == 'install'){
|
404
|
+
if(!file) return process.exit(1);
|
405
|
+
this.installApp(path.join(cachepath, file, 'clone'), {
|
406
|
+
update: true
|
407
|
+
});
|
408
|
+
} else if(command == 'show'){
|
409
|
+
if(!file) return console.log(fs.readdirSync(cachepath).join('\n').trim());
|
410
|
+
|
411
|
+
const hashed = hashTags(file, {
|
412
|
+
tag: (str) => ({ $set: str + '#name#commit' }),
|
413
|
+
commit: (file) => findGitCommitPath(path.join(cachepath, file.replace(/#name/, ''), 'clone')),
|
414
|
+
name: (file) => jsYaml.load(fs.readFileSync(path.join(cachepath, file, 'clone/app.yaml'), { encoding: 'utf-8' }).trim()).manifest.package
|
415
|
+
});
|
416
|
+
file = hashed.string;
|
417
|
+
|
418
|
+
if(hashed.tag){
|
419
|
+
return console.log(hashed.name +':'+ hashed.commit);
|
420
|
+
}
|
421
|
+
if(hashed.commit) return console.log(hashed.commit);
|
422
|
+
if(hashed.name) return console.log(hashed.name);
|
423
|
+
|
424
|
+
const f = path.join(cachepath, file);
|
425
|
+
if(!fs.existsSync(f)) return;
|
426
|
+
if(fs.statSync(f).isDirectory()) console.log(
|
427
|
+
fs.readdirSync(f).join('\n')
|
428
|
+
);
|
429
|
+
else if(file.endsWith('app.yaml')){
|
430
|
+
console.log(fs.readFileSync(f, { encoding: 'utf-8' }).trim());
|
431
|
+
} else console.log(f);
|
390
432
|
}
|
391
433
|
},
|
392
434
|
async cloneGit(gitpath, opts) {
|
@@ -0,0 +1 @@
|
|
1
|
+
module.exports = class STDNS {}
|
package/lib/rew/const/usage.js
CHANGED
@@ -1,8 +1,9 @@
|
|
1
|
+
const STDNS = require("./stdns");
|
1
2
|
|
2
3
|
|
3
4
|
|
4
5
|
const JSX_FRAGMENT_SYMBOL = Symbol('fragment');
|
5
|
-
module.exports.USING_DEFAULT = {
|
6
|
+
const USING_DEFAULT = module.exports.USING_DEFAULT = {
|
6
7
|
JSX: {
|
7
8
|
param: (param, fragment) => param ? ({ createElement: param, Fragment: fragment || param(JSX_FRAGMENT_SYMBOL, { isFragment: true }), fragmentSymbol: JSX_FRAGMENT_SYMBOL }) : {},
|
8
9
|
use: (options) => options.jsx = true
|
@@ -15,7 +16,7 @@ module.exports.USING_DEFAULT = {
|
|
15
16
|
}
|
16
17
|
}
|
17
18
|
|
18
|
-
|
19
|
+
class Usage {
|
19
20
|
name = "null";
|
20
21
|
trigger = () => {};
|
21
22
|
save = true;
|
@@ -61,6 +62,7 @@ module.exports.Usage = class Usage {
|
|
61
62
|
}
|
62
63
|
}
|
63
64
|
}
|
65
|
+
module.exports.Usage = Usage;
|
64
66
|
|
65
67
|
class Namespace extends module.exports.Usage {
|
66
68
|
namespace = {};
|
@@ -84,7 +86,44 @@ class Namespace extends module.exports.Usage {
|
|
84
86
|
module.exports.Namespace = Namespace;
|
85
87
|
|
86
88
|
module.exports.namespace = (namespace, cb, parent) => {
|
89
|
+
if(namespace instanceof STDNS) {
|
90
|
+
if(namespace['@cb'] && !cb) {
|
91
|
+
cb = namespace['@cb'];
|
92
|
+
delete namespace['@cb'];
|
93
|
+
}
|
94
|
+
}
|
87
95
|
return new Namespace(namespace, cb, parent);
|
88
96
|
}
|
89
97
|
|
98
|
+
module.exports.usingFunction = (context, runtime) => {
|
99
|
+
return function using(name, ...params) {
|
100
|
+
if(name instanceof Usage.Group){
|
101
|
+
params.unshift(...name.g.slice(1));
|
102
|
+
name = name.g[0];
|
103
|
+
}
|
104
|
+
if(USING_DEFAULT[name]){
|
105
|
+
if(USING_DEFAULT[name].param) {
|
106
|
+
context.__using__[name] = USING_DEFAULT[name].param(...params);
|
107
|
+
}
|
108
|
+
} else if(name instanceof Namespace) {
|
109
|
+
const trigger = name.trigger;
|
110
|
+
const parentContext = name.parent || context;
|
111
|
+
const childContext = {...parentContext, ...name.namespace, trigger};
|
112
|
+
childContext.$self = name.namespace;
|
113
|
+
childContext.$parent = parentContext;
|
114
|
+
const code = `(${trigger.toString()})()`;
|
115
|
+
if(name.onUse) name.onUse();
|
116
|
+
const r = runtime.exec(code, childContext, code, context.module.filepath);
|
117
|
+
if(name.onAfterUse) name.onAfterUse();
|
118
|
+
return r;
|
119
|
+
} else if(name instanceof Usage) {
|
120
|
+
const v = name.trigger(...params) || true;
|
121
|
+
if(name.save !== false) context.__using__[name.name] = v;
|
122
|
+
return v;
|
123
|
+
} else {
|
124
|
+
context.__using__[name] = params.length ? params.length > 1 ? [...params] : params : true;
|
125
|
+
}
|
126
|
+
}
|
127
|
+
}
|
128
|
+
|
90
129
|
module.exports.namespace.group = (group, props) => new Namespace.Group(group, props);
|
@@ -9,6 +9,12 @@ const { execOptions } = require('../const/opt');
|
|
9
9
|
const { REW_FILE_TYPE } = require('../const/ext');
|
10
10
|
const { straceLog } = require('../misc/strace');
|
11
11
|
|
12
|
+
const _returns = (options, content) => {
|
13
|
+
if(options.useDefaultForPackages){
|
14
|
+
return content?.default ? content : { default: content };
|
15
|
+
} else return content;
|
16
|
+
}
|
17
|
+
|
12
18
|
const cachedFiles = [];
|
13
19
|
module.exports.cleanCache = () => {
|
14
20
|
while(cachedFiles.length) cachedFiles.pop();
|
@@ -37,7 +43,11 @@ const lookUpInOtherApps = (fullPath) => {
|
|
37
43
|
module.exports.imp = function (runPath, context) {
|
38
44
|
return function (filename, options = {}) {
|
39
45
|
if (!options) options = {};
|
40
|
-
|
46
|
+
if(filename == 'std' || filename == '#std') return {};
|
47
|
+
let type = options.type ? options.type : filename.endsWith('.coffee') ? 'coffee' : (
|
48
|
+
filename.endsWith(REW_FILE_TYPE.EXTENSION) ? REW_FILE_TYPE.TYPE :
|
49
|
+
path.extname(filename).slice(1)
|
50
|
+
);
|
41
51
|
let exports,
|
42
52
|
ispkg = findPackage(filename);
|
43
53
|
|
@@ -58,10 +68,10 @@ module.exports.imp = function (runPath, context) {
|
|
58
68
|
else filepath = otherPath;
|
59
69
|
};
|
60
70
|
|
61
|
-
const foundCache = cachedFiles.find((f) => f.filepath == filepath);
|
71
|
+
const foundCache = cachedFiles.find((f) => f.filepath == type+':'+filepath);
|
62
72
|
|
63
73
|
if (!ispkg && foundCache) {
|
64
|
-
exports = foundCache.exports;
|
74
|
+
exports = options.useDefaultForPackages === false ? foundCache.exports.default || foundCache.exports : _returns(options, foundCache.exports);
|
65
75
|
}
|
66
76
|
|
67
77
|
if (!ispkg && !existsSync(filepath) && !foundCache) {
|
@@ -117,17 +127,17 @@ module.exports.imp = function (runPath, context) {
|
|
117
127
|
const f = getFile(filepath);
|
118
128
|
if (type == 'yaml') {
|
119
129
|
straceLog('===> FROM_YAML()');
|
120
|
-
exports = importYaml(f.path, f);
|
130
|
+
exports = _returns(options, importYaml(f.path, f));
|
121
131
|
} else if (type == 'json') {
|
122
132
|
straceLog('===>');
|
123
133
|
try {
|
124
|
-
exports = JSON.parse(f.content);
|
134
|
+
exports = _returns(options, JSON.parse(f.content));
|
125
135
|
} catch (e) {
|
126
|
-
exports = {};
|
136
|
+
exports = _returns(options, {});
|
127
137
|
}
|
128
138
|
} else {
|
129
139
|
straceLog('===> FROM_TEXT');
|
130
|
-
exports = f.content;
|
140
|
+
exports = _returns(options, f.content);
|
131
141
|
}
|
132
142
|
}
|
133
143
|
|
@@ -143,13 +153,13 @@ module.exports.imp = function (runPath, context) {
|
|
143
153
|
// descriptive code
|
144
154
|
// you put them in comment blocks
|
145
155
|
// and name it something
|
146
|
-
// then you can
|
156
|
+
// then you can simply see
|
147
157
|
// which part of a code contains a certain
|
148
158
|
// task. cool right?
|
149
159
|
|
150
160
|
//** If is not package, post exec section
|
151
161
|
/**/ if (!ispkg) context.module.imports.push(filepath);
|
152
|
-
/**/ if (!ispkg) cachedFiles.push({ filepath, exports });
|
162
|
+
/**/ if (!ispkg) cachedFiles.push({ filepath: type+':'+filepath, exports });
|
153
163
|
//**
|
154
164
|
|
155
165
|
//** Mock imports section
|
@@ -36,7 +36,7 @@ function typedef(value, strict = false) {
|
|
36
36
|
? value.constructor
|
37
37
|
: _defaultConstructors[getType(value)],
|
38
38
|
type: getType(value),
|
39
|
-
|
39
|
+
isConstructed: typeof value === 'object' && value !== null && !Array.isArray(value),
|
40
40
|
isEmpty: typeof value == 'object' ? !Object.keys(value).length : typeof value == 'string' ? value == '' : typeof value !== 'function',
|
41
41
|
});
|
42
42
|
}
|
@@ -70,7 +70,7 @@ function typeis(obj, typeDef, missingObjects = false) {
|
|
70
70
|
// Resolve Type
|
71
71
|
if (typeof typeDef == 'function' && typeDef.type instanceof Type) typeDef = typeDef.type;
|
72
72
|
|
73
|
-
if (typeDef.
|
73
|
+
if (typeDef.isConstructed && typeDef.class && !(obj instanceof typeDef.class)) {
|
74
74
|
return missingObjects ? [false] : false;
|
75
75
|
}
|
76
76
|
|
@@ -285,7 +285,7 @@ function useImp(token, options){
|
|
285
285
|
let packageName = value.slice(1);
|
286
286
|
token.value = dem+packageName+dem;
|
287
287
|
straceLog('IMP() with HEADER for', packageName);
|
288
|
-
return includeFile(packageName, options);
|
288
|
+
return includeFile(packageName !== 'std' ? packageName : '*'+packageName, options);
|
289
289
|
}
|
290
290
|
return '';
|
291
291
|
}
|
@@ -378,7 +378,7 @@ function compileRewStuff(content, options) {
|
|
378
378
|
|
379
379
|
if (token.type === 'COMMENT' && token.value.slice(1).trim() === '@cls') {
|
380
380
|
options.cls = true;
|
381
|
-
straceLog('
|
381
|
+
straceLog('CLI_SYNTAX() ENABLE');
|
382
382
|
straceLog('===> HIGHLY EXPERIMENTAL FEATURE DETECTED');
|
383
383
|
}
|
384
384
|
|
@@ -401,6 +401,11 @@ function compileRewStuff(content, options) {
|
|
401
401
|
token.value = 'pub';
|
402
402
|
straceLog('EXPORT() => TRANSLATING TO pub');
|
403
403
|
}
|
404
|
+
|
405
|
+
if (token.type === 'IDENTIFIER' && token.value === 'package' && nextToken.type == 'STRING') {
|
406
|
+
token.value = 'appPackage';
|
407
|
+
straceLog('APP_PACKAGE_CHANGE()');
|
408
|
+
}
|
404
409
|
|
405
410
|
if (token.type === 'IDENTIFIER' && token.value === 'using' && !options.disableUse) {
|
406
411
|
straceLog('USING()');
|
@@ -432,14 +437,15 @@ function compileRewStuff(content, options) {
|
|
432
437
|
if (token.type === 'IDENTIFIER' && token.value === 'import' && !options.keepImports) {
|
433
438
|
// console.log(nextToken.type);
|
434
439
|
straceLog('IMPORT()');
|
435
|
-
straceLog('==> WARN: SLOWS DOWN
|
440
|
+
straceLog('==> WARN: SLOWS DOWN COMPILATION');
|
436
441
|
let ind = i + n + 2;
|
442
|
+
let isAs = false;
|
437
443
|
|
438
444
|
let defaultName;
|
439
445
|
if (nextToken.type === 'STRING') {
|
440
446
|
straceLog('==> SIMPLE');
|
447
|
+
if(useImp(nextToken, options)) updateAliases(aliases);
|
441
448
|
result += `inc ${nextToken.value}`;
|
442
|
-
if(useImp(nameToken, options)) updateAliases(aliases);
|
443
449
|
i += n;
|
444
450
|
} else if (nextToken.value === '{') {
|
445
451
|
const closingBraceToken = fnextToken(ind, tokens, 'OTHER', '}');
|
@@ -469,6 +475,7 @@ function compileRewStuff(content, options) {
|
|
469
475
|
if(useImp(nameToken, options)) updateAliases(aliases);
|
470
476
|
result += `${defaultName} ${options.type == 'coffee' ? '=' : ':='} inc ${nameToken.value}`;
|
471
477
|
i = ind + 6;
|
478
|
+
isAs = true;
|
472
479
|
}
|
473
480
|
} else if (nextToken) {
|
474
481
|
const nameToken = fnextToken(ind, tokens, 'STRING');
|
@@ -505,14 +512,14 @@ function compileRewStuff(content, options) {
|
|
505
512
|
if(assertionToken.token.type == 'OTHER' && assertionToken.token.value == '{'){
|
506
513
|
hooks.push({
|
507
514
|
index: assertionToken.token.ti,
|
508
|
-
value: ' useDefaultForPackages: true, '
|
515
|
+
value: ' useDefaultForPackages: '+(isAs?'false':'true')+', '
|
509
516
|
})
|
510
517
|
} else {
|
511
|
-
result += 'useDefaultForPackages: true, '
|
518
|
+
result += 'useDefaultForPackages: '+(isAs?'false':'true')+', '
|
512
519
|
}
|
513
520
|
i += 3;
|
514
521
|
} else {
|
515
|
-
result += ", { useDefaultForPackages: true }"
|
522
|
+
result += ", { useDefaultForPackages: "+(isAs?'false':'true')+" }"
|
516
523
|
}
|
517
524
|
|
518
525
|
continue;
|
@@ -8,11 +8,11 @@ const pathLib = require("../functions/path");
|
|
8
8
|
const path = require("path");
|
9
9
|
const execLib = require("../functions/exec");
|
10
10
|
const { findAppInfo } = require("../misc/findAppInfo");
|
11
|
-
const {
|
11
|
+
const { Usage, usingFunction } = require("../const/usage");
|
12
12
|
const runtime = require("./runtime");
|
13
|
-
const { permission } = require("process");
|
14
13
|
const { straceLog } = require("../misc/strace");
|
15
14
|
const reval = require("../functions/reval");
|
15
|
+
const STDNS = require("../const/stdns");
|
16
16
|
|
17
17
|
let mainFile = "";
|
18
18
|
const isMainFile = (filepath) => filepath == mainFile;
|
@@ -47,14 +47,41 @@ module.exports.prepareContext = function (
|
|
47
47
|
...context,
|
48
48
|
};
|
49
49
|
} else {
|
50
|
+
const std = {...defaultContext};
|
50
51
|
context = {
|
51
52
|
...context,
|
52
|
-
...
|
53
|
+
...std,
|
53
54
|
...pathLib(filepath),
|
54
55
|
...execLib(filepath),
|
55
56
|
...custom_context,
|
56
57
|
Usage
|
57
58
|
};
|
59
|
+
std.prototype = { ns: (cb) => {
|
60
|
+
return new (class extends STDNS {
|
61
|
+
constructor(){
|
62
|
+
super();
|
63
|
+
for(let i in std){
|
64
|
+
this[i] = std[i];
|
65
|
+
}
|
66
|
+
this.define = std.prototype.define;
|
67
|
+
this.Main = std.prototype.Main;
|
68
|
+
this['@cb'] = cb;
|
69
|
+
}
|
70
|
+
});
|
71
|
+
}, define: (name, object) => {
|
72
|
+
if(Array.isArray(name) && name.length == 2 && typeof name[0] == 'string'){
|
73
|
+
object = name[1];
|
74
|
+
name = name[0];
|
75
|
+
}
|
76
|
+
if(!context.module.exports) context.module.exports = {};
|
77
|
+
context.module.exports[name] = object;
|
78
|
+
context[name] = object;
|
79
|
+
}, Main: (cb) => (['main', cb?.main ?? cb]), attach: (object) => {
|
80
|
+
for(let i in object){
|
81
|
+
if(!context[i]) context[i] = object[i];
|
82
|
+
}
|
83
|
+
} }
|
84
|
+
context.std = std;
|
58
85
|
}
|
59
86
|
if (!context.process)
|
60
87
|
context.process = {
|
@@ -70,10 +97,19 @@ module.exports.prepareContext = function (
|
|
70
97
|
abort: () => process.abort(),
|
71
98
|
kill: () => process.kill(),
|
72
99
|
exit: (code) => process.exit(code),
|
100
|
+
chdir: (dir) => process.chdir(dir),
|
101
|
+
disconnect: () => process.disconnect(),
|
73
102
|
arch: process.arch,
|
74
103
|
pid: process.pid,
|
75
104
|
platform: process.platform,
|
76
|
-
|
105
|
+
channel: process.channel,
|
106
|
+
uptime: () => process.uptime(),
|
107
|
+
nextTick: (callback, ...args) => process.nextTick(callback, ...args),
|
108
|
+
permission: process.permission,
|
109
|
+
transmit: {
|
110
|
+
send: (...data) => process.send(...data),
|
111
|
+
recieve: (cb) => process.on('message', cb)
|
112
|
+
}
|
77
113
|
};
|
78
114
|
|
79
115
|
context.global = context;
|
@@ -120,34 +156,7 @@ module.exports.prepareContext = function (
|
|
120
156
|
context.pub = pubFunction(context);
|
121
157
|
context.exports = exportsFunction(context);
|
122
158
|
|
123
|
-
context.using = (
|
124
|
-
if(name instanceof Usage.Group){
|
125
|
-
params.unshift(...name.g.slice(1));
|
126
|
-
name = name.g[0];
|
127
|
-
}
|
128
|
-
if(USING_DEFAULT[name]){
|
129
|
-
if(USING_DEFAULT[name].param) {
|
130
|
-
context.__using__[name] = USING_DEFAULT[name].param(...params);
|
131
|
-
}
|
132
|
-
} else if(name instanceof Namespace) {
|
133
|
-
const trigger = name.trigger;
|
134
|
-
const parentContext = name.parent || context;
|
135
|
-
const childContext = {...parentContext, ...name.namespace, trigger};
|
136
|
-
childContext.currentNamespace = name.namespace;
|
137
|
-
childContext.parentNamespace = parentContext;
|
138
|
-
const code = `(${trigger.toString()})()`;
|
139
|
-
if(name.onUse) name.onUse();
|
140
|
-
const r = runtime.exec(code, childContext, code, context.module.filepath);
|
141
|
-
if(name.onAfterUse) name.onAfterUse();
|
142
|
-
return r;
|
143
|
-
} else if(name instanceof Usage) {
|
144
|
-
const v = name.trigger(...params) || true;
|
145
|
-
if(name.save !== false) context.__using__[name.name] = v;
|
146
|
-
return v;
|
147
|
-
} else {
|
148
|
-
context.__using__[name] = params.length ? params.length > 1 ? [...params] : params : true;
|
149
|
-
}
|
150
|
-
};
|
159
|
+
context.using = usingFunction(context, runtime);
|
151
160
|
|
152
161
|
if(context.app?.config?.exec?.['auto import']){
|
153
162
|
const autoipath = path.join(context.app.path, context.app.config?.exec?.['auto import']);
|
@@ -54,7 +54,7 @@ module.exports.runPath = function runPath(filepath, options = {}, custom_context
|
|
54
54
|
const mainFn = context.module.exports.main ?? context.module.exports;
|
55
55
|
return {
|
56
56
|
context,
|
57
|
-
returns: mainFn(context.process.argv)
|
57
|
+
returns: mainFn.call(context, context.process.argv)
|
58
58
|
}
|
59
59
|
} else {
|
60
60
|
return {
|