@makano/rew 1.2.56 → 1.2.58
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 +3 -2
- package/lib/rew/cli/utils.js +20 -9
- package/lib/rew/const/default.js +2 -1
- package/lib/rew/const/ext.js +5 -0
- package/lib/rew/const/opt.js +7 -3
- package/lib/rew/const/usage.js +15 -0
- package/lib/rew/functions/fs.js +6 -1
- package/lib/rew/functions/import.js +12 -7
- package/lib/rew/functions/require.js +1 -1
- package/lib/rew/functions/stdout.js +4 -0
- package/lib/rew/main.js +1 -13
- package/lib/rew/modules/compiler.js +92 -28
- package/lib/rew/modules/context.js +12 -0
- package/lib/rew/modules/runtime.js +31 -13
- package/lib/rew/pkgs/serve.js +7 -4
- package/lib/rew/pkgs/web.js +5 -4
- package/package.json +5 -3
- package/runtime.d.ts +103 -62
- package/jsconfig.json +0 -13
- 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
@@ -17,6 +17,7 @@ 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');
|
20
21
|
|
21
22
|
if (!existsSync(CONFIG_PATH) || !existsSync(CONFIG_PATH + '/repos.yaml')) {
|
22
23
|
mkdirSync(CONFIG_PATH, { recursive: true });
|
@@ -127,7 +128,7 @@ yargs(hideBin(process.argv))
|
|
127
128
|
type: 'string',
|
128
129
|
})
|
129
130
|
.option('dev', {
|
130
|
-
describe:
|
131
|
+
describe: `If your entry file is a .qrew, then just use .coffe or ${REW_FILE_TYPE.EXTENSION} instead`,
|
131
132
|
type: 'boolean',
|
132
133
|
})
|
133
134
|
.option('entry', {
|
@@ -354,7 +355,7 @@ yargs(hideBin(process.argv))
|
|
354
355
|
})
|
355
356
|
.option('remove', {
|
356
357
|
alias: 'r',
|
357
|
-
describe: 'Remove all coffee',
|
358
|
+
describe: 'Remove all .coffee and '+REW_FILE_TYPE.EXTENSION,
|
358
359
|
type: 'boolean',
|
359
360
|
});
|
360
361
|
},
|
package/lib/rew/cli/utils.js
CHANGED
@@ -18,6 +18,7 @@ const { seededID } = require('../misc/seededid');
|
|
18
18
|
const loading = require('loading-cli');
|
19
19
|
const sleep = require('../functions/sleep');
|
20
20
|
const { gen_key } = require('../misc/bin');
|
21
|
+
const { REW_FILE_TYPE } = require('../const/ext');
|
21
22
|
|
22
23
|
const binpath = path.join(conf({}).create('').root, '.bin');
|
23
24
|
const logspath = path.join(conf({}).create('').root, '.logs');
|
@@ -49,7 +50,7 @@ module.exports = {
|
|
49
50
|
runFileWithArgv(filePath, options = {}, cargv) {
|
50
51
|
const argv = cargv || process.argv;
|
51
52
|
argv.shift();
|
52
|
-
if (argv[0].endsWith('
|
53
|
+
if (argv[0].endsWith(REW_FILE_TYPE.EXTENSION) || argv[0].endsWith('.coffee')) {
|
53
54
|
if (argv[1] == 'run') {
|
54
55
|
argv.splice(0, 3);
|
55
56
|
} else if(argv[1] == '-w' || argv[1] == '--watch'){
|
@@ -118,8 +119,8 @@ module.exports = {
|
|
118
119
|
const create = () => {
|
119
120
|
fs.mkdirSync(projectPath, { recursive: true });
|
120
121
|
const confPath = path.join(projectPath, 'app.yaml');
|
121
|
-
const entryFile = path.join(projectPath, 'main.coffee');
|
122
|
-
fs.writeFileSync(confPath, jsYaml.dump({ manifest: { package: project.package, private: false }, exec: { entry: 'main.coffee' }, assets: { icon: 'assets/icon.png', folder: './assets' }, install: { requirements: [] } }));
|
122
|
+
const entryFile = path.join(projectPath, 'main'+(project.civet ? REW_FILE_TYPE.EXTENSION : '.coffee'));
|
123
|
+
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: [] } }));
|
123
124
|
fs.writeFileSync(entryFile, `print("Hello World!")`);
|
124
125
|
fs.mkdirSync(path.join(projectPath, 'assets'), { recursive: true });
|
125
126
|
if (project.git) {
|
@@ -127,10 +128,14 @@ module.exports = {
|
|
127
128
|
execSync('cd ' + projectPath + ' && git init . && git branch -m main', { stdio: 'ignore' });
|
128
129
|
}
|
129
130
|
if(project.intellisense){
|
130
|
-
fs.copyFileSync(path.join(__dirname, '../../../
|
131
|
+
fs.copyFileSync(path.join(__dirname, '../../../tsconfig.json'), path.join(projectPath, 'tsconfig.json'));
|
131
132
|
fs.copyFileSync(path.join(__dirname, '../../../runtime.d.ts'), path.join(projectPath, 'runtime.d.ts'));
|
132
133
|
}
|
133
134
|
execSync('cd ' + projectPath + ' && npm init -y', { stdio: 'ignore' });
|
135
|
+
if(project.civet){
|
136
|
+
log('Installing NPM Packages');
|
137
|
+
execSync('cd '+projectPath+' && npm i @types/node --no-save', { stdio: 'ignore' });
|
138
|
+
}
|
134
139
|
// log('Installing '+npm_package_name);
|
135
140
|
// exec('cd '+projectPath+' && npm i '+npm_package_name, (err) => {
|
136
141
|
// if(err){
|
@@ -149,9 +154,12 @@ module.exports = {
|
|
149
154
|
project.package = pkg.trim();
|
150
155
|
rl.question(logget(' Use intellisense declarations ? (y/N): '.magenta.bold), (inteli) => {
|
151
156
|
project.intellisense = inteli.toLowerCase() == 'y' || inteli.toLowerCase() == 'yes';
|
152
|
-
rl.question(logget('
|
153
|
-
project.
|
154
|
-
|
157
|
+
rl.question(logget(' Use Civet For main ? (y/N): '.blue.bold), (civet) => {
|
158
|
+
project.civet = civet.toLowerCase() == 'y' || civet.toLowerCase() == 'yes';
|
159
|
+
rl.question(logget(' Use git ? (y/N): '.yellow.bold), (use_git) => {
|
160
|
+
project.git = use_git.toLowerCase() == 'y' || use_git.toLowerCase() == 'yes';
|
161
|
+
create();
|
162
|
+
});
|
155
163
|
});
|
156
164
|
});
|
157
165
|
} else {
|
@@ -173,8 +181,8 @@ module.exports = {
|
|
173
181
|
c.exec.entry = c.exec[options.entry] || c.exec.entry;
|
174
182
|
}
|
175
183
|
if (c.exec.entry) {
|
176
|
-
if (byPath && options.dev) c.exec.entry = c.entry.endsWith('.qrew') ? c.exec.entry.replace(/\.qrew$/, '.coffee') : c.exec.entry;
|
177
184
|
let r = path.resolve(root, c.exec.entry);
|
185
|
+
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;
|
178
186
|
if (options.build) {
|
179
187
|
this.build({
|
180
188
|
file: r,
|
@@ -357,6 +365,9 @@ module.exports = {
|
|
357
365
|
if (fs.existsSync(importedFilePath)) {
|
358
366
|
importsArray.push(importStatement);
|
359
367
|
processFile(importedFilePath, importsArray);
|
368
|
+
} else if (fs.existsSync(importedFilePath + REW_FILE_TYPE.EXTENSION)) {
|
369
|
+
importsArray.push(importStatement);
|
370
|
+
processFile(importedFilePath + REW_FILE_TYPE.EXTENSION, importsArray);
|
360
371
|
} else if (fs.existsSync(importedFilePath + '.coffee')) {
|
361
372
|
importsArray.push(importStatement);
|
362
373
|
processFile(importedFilePath + '.coffee', importsArray);
|
@@ -369,7 +380,7 @@ module.exports = {
|
|
369
380
|
|
370
381
|
const appPath = findAppInfo(filePath);
|
371
382
|
|
372
|
-
const compiled = argv.translate ? compile({ content }, {}) : to_qrew(content
|
383
|
+
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('.'));
|
373
384
|
writeCompiledFile(filePath, compiled);
|
374
385
|
}
|
375
386
|
|
package/lib/rew/const/default.js
CHANGED
@@ -7,7 +7,7 @@ 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');
|
@@ -55,5 +55,6 @@ module.exports = {
|
|
55
55
|
curl,
|
56
56
|
|
57
57
|
print,
|
58
|
+
printf,
|
58
59
|
input,
|
59
60
|
};
|
package/lib/rew/const/opt.js
CHANGED
@@ -1,11 +1,15 @@
|
|
1
|
+
const { REW_FILE_TYPE } = require("./ext");
|
2
|
+
|
1
3
|
const execOptions = {
|
2
4
|
sharedContext: true,
|
3
|
-
resolveExtensions: [
|
5
|
+
resolveExtensions: [REW_FILE_TYPE.EXTENSION, ".coffee", { ext: '.js', options: { type: 'js' } }, { ext: '.qrew', options: { qrew: true } }],
|
4
6
|
nativeRequire: false,
|
5
7
|
useImport: false,
|
6
8
|
cwdAlias: '$',
|
7
|
-
jsxPragma: 'createElement',
|
8
|
-
jsx: false
|
9
|
+
jsxPragma: '__using__.JSX.createElement',
|
10
|
+
jsx: false,
|
11
|
+
typescript: false,
|
12
|
+
decorators: false
|
9
13
|
};
|
10
14
|
|
11
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,
|
@@ -6,6 +6,7 @@ const { existsSync, readFileSync } = require('fs');
|
|
6
6
|
const conf = require('../pkgs/conf');
|
7
7
|
const jsYaml = require('js-yaml');
|
8
8
|
const { execOptions } = require('../const/opt');
|
9
|
+
const { REW_FILE_TYPE } = require('../const/ext');
|
9
10
|
|
10
11
|
const cachedFiles = [];
|
11
12
|
module.exports.cleanCache = () => {
|
@@ -34,7 +35,7 @@ const lookUpInOtherApps = (fullPath) => {
|
|
34
35
|
module.exports.imp = function (runPath, context) {
|
35
36
|
return function (filename, options = {}) {
|
36
37
|
if (!options) options = {};
|
37
|
-
let type = options.type || 'coffee';
|
38
|
+
let type = options.type || filename.endsWith('.coffee') ? 'coffee' : REW_FILE_TYPE.TYPE;
|
38
39
|
let exports,
|
39
40
|
ispkg = findPackage(filename);
|
40
41
|
|
@@ -72,8 +73,8 @@ module.exports.imp = function (runPath, context) {
|
|
72
73
|
} else lookUp();
|
73
74
|
}
|
74
75
|
|
75
|
-
const exec = (coptions = {}) =>
|
76
|
-
runPath(
|
76
|
+
const exec = (coptions = {}) => {
|
77
|
+
const r = runPath(
|
77
78
|
filepath,
|
78
79
|
{
|
79
80
|
import: options,
|
@@ -86,13 +87,18 @@ module.exports.imp = function (runPath, context) {
|
|
86
87
|
package: context.app ? context.app.config.package : path.basename(filepath)
|
87
88
|
},
|
88
89
|
execOptions.sharedContext == false ? {} : options.context && options.context == 'new' ? {} : context,
|
89
|
-
)
|
90
|
+
);
|
91
|
+
if(r instanceof Promise){
|
92
|
+
return new Promise((resolve) => r.then(c => resolve(c.context.module.exports)));
|
93
|
+
}
|
94
|
+
return r.context.module.exports;
|
95
|
+
}
|
90
96
|
|
91
97
|
if (ispkg) {
|
92
98
|
const pkg = getPackage(filename)(context, options);
|
93
99
|
exports = pkg._onImport ? pkg._onImport() : pkg;
|
94
100
|
} else if (foundCache) {
|
95
|
-
} else if (type ==
|
101
|
+
} else if (type == REW_FILE_TYPE.TYPE || type == "coffee") {
|
96
102
|
exports = exec({});
|
97
103
|
} else if (type == 'js') {
|
98
104
|
exports = exec({ compile: false });
|
@@ -111,7 +117,7 @@ module.exports.imp = function (runPath, context) {
|
|
111
117
|
}
|
112
118
|
}
|
113
119
|
|
114
|
-
if (options.save && (type == 'js' || type ==
|
120
|
+
if (options.save && (type == 'js' || type == REW_FILE_TYPE.TYPE || type == "coffee")) {
|
115
121
|
if (typeof options.save == 'string') context[options.save] = exports[i];
|
116
122
|
else
|
117
123
|
for (let i in exports) {
|
@@ -135,7 +141,6 @@ module.exports.imp = function (runPath, context) {
|
|
135
141
|
//** Mock imports section
|
136
142
|
/**/ if(!exports) exports = options.mock;
|
137
143
|
/**/ if(options.mock === null) return null;
|
138
|
-
/**/ if(!exports) throw new Error('Import '+filename+' does not export anything. Use the "mock" option to mock a value.');
|
139
144
|
//**
|
140
145
|
|
141
146
|
return exports;
|
@@ -8,7 +8,7 @@ const cahcedRequires = {};
|
|
8
8
|
const doImp = (path) => wait(async () => await import(resolvedPath));
|
9
9
|
|
10
10
|
module.exports.customRequire = function customRequire(modulePath, filePath) {
|
11
|
-
|
11
|
+
let pathname = modulePath;
|
12
12
|
if (modulePath.startsWith('./') || modulePath.startsWith('../') || path.isAbsolute(modulePath)) {
|
13
13
|
pathname = path.resolve(modulePath);
|
14
14
|
}
|
@@ -4,6 +4,10 @@ const print = (module.exports.print = function print(...args) {
|
|
4
4
|
return console.log(...args);
|
5
5
|
});
|
6
6
|
|
7
|
+
module.exports.printf = function printf(buffer, cb) {
|
8
|
+
return process.stdout.write(buffer, cb);
|
9
|
+
};
|
10
|
+
|
7
11
|
print.stdout = process.stdout;
|
8
12
|
print.stdin = process.stdin;
|
9
13
|
|
package/lib/rew/main.js
CHANGED
@@ -1,17 +1,5 @@
|
|
1
|
-
const {
|
2
|
-
const { exec, runPath } = require('./modules/runtime');
|
3
|
-
const fs = require('fs');
|
4
|
-
const { imp } = require('./functions/import');
|
5
|
-
const { FILES } = require('./const/files');
|
1
|
+
const { runPath } = require('./modules/runtime');
|
6
2
|
|
7
3
|
module.exports.run = function (filepath, options = {}, custom_context = {}) {
|
8
|
-
FILES.forEach((file) => {
|
9
|
-
if (fs.existsSync(file.path)) return;
|
10
|
-
if (file.content) {
|
11
|
-
fs.writeFileSync(file.path, file.content);
|
12
|
-
} else {
|
13
|
-
fs.mkdirSync(file.path, { recursive: true });
|
14
|
-
}
|
15
|
-
});
|
16
4
|
return runPath(filepath, options, custom_context);
|
17
5
|
};
|
@@ -1,4 +1,4 @@
|
|
1
|
-
const { compile } = require('../../
|
1
|
+
const { compile: compileCivet } = require('../../civet/main');
|
2
2
|
const { execOptions } = require('../const/opt');
|
3
3
|
const { findAppInfo } = require('../misc/findAppInfo');
|
4
4
|
const { from_qrew } = require('../qrew/compile');
|
@@ -7,6 +7,9 @@ const babel = require('@babel/core');
|
|
7
7
|
const path = require('path');
|
8
8
|
const babelReact = require('@babel/preset-react');
|
9
9
|
const { readFileSync } = require('fs');
|
10
|
+
const { wait } = require('../functions/wait');
|
11
|
+
const { REW_FILE_TYPE } = require('../const/ext');
|
12
|
+
const { USING_DEFAULT } = require('../const/usage');
|
10
13
|
|
11
14
|
function tokenizeCoffeeScript(code) {
|
12
15
|
const tokens = [];
|
@@ -115,6 +118,9 @@ function compileRewStuff(content, options) {
|
|
115
118
|
const token = tokens[i];
|
116
119
|
let { token: nextToken, n } = gnextToken(i, 1, tokens) || {};
|
117
120
|
|
121
|
+
if(token.type == "COMMENT" && i < 2 && token.value.startsWith('#!')){
|
122
|
+
continue;
|
123
|
+
}
|
118
124
|
|
119
125
|
if (token.type === 'IDENTIFIER' && token.value === 'opt.set') {
|
120
126
|
const { token: nextNextToken } = gnextToken(i, 2, tokens) || {};
|
@@ -150,18 +156,19 @@ function compileRewStuff(content, options) {
|
|
150
156
|
}
|
151
157
|
|
152
158
|
|
153
|
-
if (token.type === 'IDENTIFIER' && token.value === 'let' && !options.keepImports) {
|
154
|
-
result += '`'
|
155
|
-
hooks.push({
|
156
|
-
index: fnextToken(i, tokens, 'OTHER', ';').ti,
|
157
|
-
value: `\``,
|
158
|
-
});
|
159
|
-
}
|
160
|
-
|
161
159
|
if (token.type === 'IDENTIFIER' && token.value === 'export' && !options.keepImports) {
|
162
160
|
token.value = 'pub';
|
163
161
|
}
|
164
162
|
|
163
|
+
if (token.type === 'IDENTIFIER' && token.value === 'using' && !options.disableUse) {
|
164
|
+
const next = nextToken.value;
|
165
|
+
if(next in USING_DEFAULT) {
|
166
|
+
const { use } = USING_DEFAULT[next];
|
167
|
+
use?.(options);
|
168
|
+
nextToken.value = `"${nextToken.value}"`
|
169
|
+
}
|
170
|
+
}
|
171
|
+
|
165
172
|
if (token.type === 'IDENTIFIER' && token.value === 'import' && !options.keepImports) {
|
166
173
|
// console.log(nextToken.type);
|
167
174
|
let ind = i + n + 2;
|
@@ -177,9 +184,12 @@ function compileRewStuff(content, options) {
|
|
177
184
|
const exportsTokens = tokens.slice(ind, closingBraceToken.ti);
|
178
185
|
const exports = exportsTokens
|
179
186
|
.filter((t) => t.type === 'IDENTIFIER')
|
180
|
-
.map((t) => t.value)
|
187
|
+
.map((t, i, arr) => t.value == 'as' ? [arr[i-1].value +': '+arr[i+1].value] : t.value)
|
188
|
+
.flat(1)
|
189
|
+
.filter((t, i, arr) => !arr[i+1]?.match(':') && !arr[i-1]?.match(':'))
|
181
190
|
.join(', ');
|
182
|
-
|
191
|
+
|
192
|
+
result += `{ ${exports} } ${options.type == 'coffee' ? '=' : ':='} inc ${nameToken.value}`;
|
183
193
|
i = nameToken.ti;
|
184
194
|
}
|
185
195
|
} else if (nextToken.value === '*') {
|
@@ -188,7 +198,7 @@ function compileRewStuff(content, options) {
|
|
188
198
|
if (asToken) {
|
189
199
|
const nextToken = fnextToken(asToken.ti + 1, tokens, 'IDENTIFIER');
|
190
200
|
defaultName = nextToken.value;
|
191
|
-
result += `${defaultName} = inc ${nameToken.value}`;
|
201
|
+
result += `${defaultName} ${options.type == 'coffee' ? '=' : ':='} inc ${nameToken.value}`;
|
192
202
|
i = ind + 6;
|
193
203
|
}
|
194
204
|
} else if (nextToken) {
|
@@ -201,13 +211,15 @@ function compileRewStuff(content, options) {
|
|
201
211
|
const exportsTokens = tokens.slice(ind, closingBraceToken.ti);
|
202
212
|
const exports = exportsTokens
|
203
213
|
.filter((t) => t.type === 'IDENTIFIER')
|
204
|
-
.map((t) => t.value)
|
214
|
+
.map((t, i, arr) => t.value == 'as' ? [arr[i-1].value +': '+arr[i+1].value] : t.value)
|
215
|
+
.flat(1)
|
216
|
+
.filter((t, i, arr) => !arr[i+1]?.match(':') && !arr[i-1]?.match(':'))
|
205
217
|
.join(', ');
|
206
|
-
result += `{ default: ${defaultName}, ${exports} } = inc ${nameToken?.value || ''}`;
|
218
|
+
result += `{ default: ${defaultName}, ${exports} } ${options.type == 'coffee' ? '=' : ':='} inc ${nameToken?.value || ''}`;
|
207
219
|
i = closingBraceToken.ti + 4;
|
208
220
|
}
|
209
221
|
} else {
|
210
|
-
result += `{ default: ${defaultName} } = inc ${nameToken?.value || ''}`;
|
222
|
+
result += `{ default: ${defaultName} } ${options.type == 'coffee' ? '=' : ':='} inc ${nameToken?.value || ''}`;
|
211
223
|
i = ind + 2;
|
212
224
|
}
|
213
225
|
}
|
@@ -259,21 +271,65 @@ function compileRewStuff(content, options) {
|
|
259
271
|
return result;
|
260
272
|
}
|
261
273
|
|
262
|
-
const
|
263
|
-
|
274
|
+
const compileCivetStuff = (file, options) => {
|
275
|
+
const compileOptions = {
|
264
276
|
...options,
|
265
|
-
|
266
|
-
|
277
|
+
bare: true,
|
278
|
+
filename: file.content,
|
267
279
|
inlineMap: false,
|
268
|
-
|
280
|
+
js: true
|
281
|
+
};
|
282
|
+
|
283
|
+
const prepared = compileRewStuff(file.content, options);
|
284
|
+
|
285
|
+
const compiled = options.async ? compileCivet(prepared, compileOptions) : wait(compileCivet, prepared, compileOptions);
|
286
|
+
|
287
|
+
return {
|
288
|
+
compiled,
|
289
|
+
options
|
290
|
+
};
|
291
|
+
}
|
292
|
+
|
293
|
+
const cpl = (module.exports.compile = function (file, options = {}) {
|
294
|
+
let compiledCode;
|
295
|
+
const result = compileCivetStuff(file, {
|
296
|
+
...options,
|
297
|
+
parseOptions: {
|
298
|
+
coffeeCompat: options.type == "coffee",
|
299
|
+
}
|
300
|
+
});
|
301
|
+
|
302
|
+
options = result.options;
|
303
|
+
compiledCode = result.compiled;
|
304
|
+
|
305
|
+
const babelify = (code, options) => babel.transformSync(code, {
|
306
|
+
presets: [
|
307
|
+
...(doJSX ? [[babelReact, { pragma: options.jsxPragma || execOptions.jsxPragma }]] : [])
|
308
|
+
],
|
309
|
+
plugins: [
|
310
|
+
...(doDecorators ? [[require('@babel/plugin-proposal-decorators'), { version: '2023-05' }], [require('@babel/plugin-proposal-class-properties'), { loose: true }], [require('@babel/plugin-transform-class-static-block'), {}]] : [])
|
311
|
+
],
|
312
|
+
}).code;
|
313
|
+
|
314
|
+
const doJSX = execOptions.jsx || options.jsx;
|
315
|
+
const doTypes = execOptions.typescript || options.typescript;
|
316
|
+
const doDecorators = execOptions.decorators || options.decorators;
|
317
|
+
const doBabel = doJSX || doTypes || doDecorators;
|
318
|
+
|
319
|
+
if(compiledCode instanceof Promise){
|
320
|
+
return compiledCode.then((compiledCode) => {
|
321
|
+
if (doBabel) {
|
322
|
+
compiledCode = babelify(compiledCode, options);
|
323
|
+
}
|
324
|
+
return compiledCode;
|
325
|
+
});
|
326
|
+
}
|
327
|
+
|
269
328
|
// console.log(c);
|
270
|
-
if (
|
271
|
-
|
272
|
-
presets: [[babelReact, { pragma: options.jsxPragma || execOptions.jsxPragma }]],
|
273
|
-
plugins: [],
|
274
|
-
}).code;
|
329
|
+
if (doBabel) {
|
330
|
+
compiledCode = babelify(compiledCode, options);
|
275
331
|
}
|
276
|
-
return
|
332
|
+
return compiledCode;
|
277
333
|
});
|
278
334
|
|
279
335
|
module.exports.compileFile = function (filepath, options = {}) {
|
@@ -284,13 +340,21 @@ module.exports.compileFile = function (filepath, options = {}) {
|
|
284
340
|
if(options.qrew || path.extname(filepath) == '.qrew') {
|
285
341
|
qrew = true
|
286
342
|
f.content = from_qrew(readFileSync(f.path), options.package || findAppInfo(filepath)?.config.manifest.package || path.basename(filepath).split('.').slice(0, -1).join('.')).toString();
|
343
|
+
options.type = f.content.split('\n')[0]?.match(/"initFile (.+)"/)?.[1]?.split('.').pop();
|
287
344
|
}
|
288
345
|
|
289
346
|
let compiled_code = cpl(f, { ...options });
|
290
347
|
|
291
348
|
if(options.onlyCompile && !qrew){
|
292
|
-
|
293
|
-
|
349
|
+
if(compiled_code instanceof Promise){
|
350
|
+
compiled_code.then((r) => {
|
351
|
+
console.log(r);
|
352
|
+
process.exit();
|
353
|
+
});
|
354
|
+
} else {
|
355
|
+
console.log(compiled_code);
|
356
|
+
process.exit();
|
357
|
+
}
|
294
358
|
}
|
295
359
|
|
296
360
|
return {
|
@@ -7,6 +7,7 @@ const fsLib = require("../functions/fs");
|
|
7
7
|
const pathLib = require("../functions/path");
|
8
8
|
const execLib = require("../functions/exec");
|
9
9
|
const { findAppInfo } = require("../misc/findAppInfo");
|
10
|
+
const { USING_DEFAULT } = require("../const/usage");
|
10
11
|
|
11
12
|
let mainFile = "";
|
12
13
|
const isMainFile = (filepath) => filepath == mainFile;
|
@@ -30,6 +31,7 @@ module.exports.prepareContext = function (
|
|
30
31
|
},
|
31
32
|
app: findAppInfo(filepath),
|
32
33
|
...fsLib(filepath),
|
34
|
+
__using__: {}
|
33
35
|
};
|
34
36
|
if (options.useContext) {
|
35
37
|
context = {
|
@@ -91,6 +93,16 @@ module.exports.prepareContext = function (
|
|
91
93
|
context.pub = pubFunction(context);
|
92
94
|
context.exports = exportsFunction(context);
|
93
95
|
|
96
|
+
context.using = (name, ...params) => {
|
97
|
+
if(USING_DEFAULT[name]){
|
98
|
+
if(USING_DEFAULT[name].param) {
|
99
|
+
context.__using__[name] = USING_DEFAULT[name].param(...params);
|
100
|
+
}
|
101
|
+
} else {
|
102
|
+
context.__using__[name] = params.length ? params.length > 1 ? [...params] : params : true;
|
103
|
+
}
|
104
|
+
};
|
105
|
+
|
94
106
|
if (
|
95
107
|
context.module.main ||
|
96
108
|
(options.fromMain == true && options.as == "main")
|
@@ -17,26 +17,44 @@ const exec = (module.exports.exec = function (code, context, original = '') {
|
|
17
17
|
|
18
18
|
module.exports.runPath = function runPath(filepath, options = {}, custom_context = {}) {
|
19
19
|
if(filepath.endsWith('.js')) options.type = 'js';
|
20
|
+
if(filepath.endsWith('.coffee')) options.type = 'coffee';
|
21
|
+
if(filepath.endsWith('.qrew')) options.type = 'qrew';
|
22
|
+
|
23
|
+
if(options.import?.async) options.async = true;
|
20
24
|
let { compiled_code, file } = compileFile(options.code ? { content: options.code, path: filepath } : filepath, options);
|
21
|
-
const context = options.import?.takeThisContext ? custom_context : prepareContext(custom_context, options, file.path, runPath);
|
22
25
|
// context.module.compiled = compiled_code;
|
23
26
|
// context.process.exit = (int) => process.exit(int);
|
24
27
|
|
25
|
-
|
26
|
-
const
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
28
|
+
const doCode = () => {
|
29
|
+
const context = options.import?.takeThisContext ? custom_context : prepareContext(custom_context, options, file.path, runPath);
|
30
|
+
|
31
|
+
if(context.app){
|
32
|
+
const p = path.join(CONFIG_PATH, context.app.config.manifest.package, 'app');
|
33
|
+
if(existsSync(p) && context.app.path !== p){
|
34
|
+
console.log("App with the same package name has been installed. Conflicts happened. \nTo fix this, change your app's package name or remove the app making the conflict.");
|
35
|
+
return {
|
36
|
+
context: { module: { exports: null } },
|
37
|
+
returns: null
|
38
|
+
}
|
32
39
|
}
|
33
40
|
}
|
41
|
+
|
42
|
+
compiled_code = preScript+'\n'+compiled_code;
|
43
|
+
|
44
|
+
return {
|
45
|
+
context,
|
46
|
+
returns: exec(compiled_code, context, file.content),
|
47
|
+
};
|
34
48
|
}
|
35
49
|
|
36
|
-
|
50
|
+
if(options.async){
|
51
|
+
return new Promise(async (r, re) => {
|
52
|
+
compiled_code.then((e) => {
|
53
|
+
compiled_code = e;
|
54
|
+
r(doCode());
|
55
|
+
});
|
56
|
+
});
|
57
|
+
}
|
37
58
|
|
38
|
-
return
|
39
|
-
context,
|
40
|
-
returns: exec(compiled_code, context, file.content),
|
41
|
-
};
|
59
|
+
return doCode();
|
42
60
|
};
|
package/lib/rew/pkgs/serve.js
CHANGED
@@ -5,6 +5,10 @@ const path = require('path');
|
|
5
5
|
const { run } = require('../main');
|
6
6
|
const { runPath } = require('../modules/runtime');
|
7
7
|
const { cleanCache } = require('../functions/import');
|
8
|
+
const { REW_FILE_TYPE } = require('../const/ext');
|
9
|
+
|
10
|
+
const lookUpFiles = ['route', 'page', 'page.s'];
|
11
|
+
|
8
12
|
module.exports = (context) => {
|
9
13
|
|
10
14
|
// http.createServer((req, res) => {
|
@@ -105,7 +109,7 @@ module.exports = (context) => {
|
|
105
109
|
}
|
106
110
|
}
|
107
111
|
|
108
|
-
function findLayoutFiles(filePath, root, isClientSide = true, resolveExtensions = ['.coffee', '.js', '.jsx']) {
|
112
|
+
function findLayoutFiles(filePath, root, isClientSide = true, resolveExtensions = [REW_FILE_TYPE.EXTENSION, '.coffee', '.js', '.jsx']) {
|
109
113
|
const layouts = [];
|
110
114
|
const rootDir = root;
|
111
115
|
let currentDir = path.dirname(filePath);
|
@@ -162,13 +166,11 @@ module.exports = (context) => {
|
|
162
166
|
onError = () => error(404, 'Path not found'),
|
163
167
|
root = '',
|
164
168
|
basePath = '',
|
165
|
-
resolveExtensions = ['.coffee', '.js', '.jsx'],
|
169
|
+
resolveExtensions = [REW_FILE_TYPE.EXTENSION, '.coffee', '.js', '.jsx'],
|
166
170
|
bundlerOptions = {},
|
167
171
|
bundlerEntry = defaultBundlerEntry,
|
168
172
|
ssrBundlerEntry = defaultSsrBundlerEntry,
|
169
173
|
}) {
|
170
|
-
|
171
|
-
const lookUpFiles = ['route', 'page', 'page.s'];
|
172
174
|
|
173
175
|
const params = {};
|
174
176
|
|
@@ -176,6 +178,7 @@ module.exports = (context) => {
|
|
176
178
|
const routeParts = pathname.split('/').filter(Boolean);
|
177
179
|
let routePath = root;
|
178
180
|
|
181
|
+
|
179
182
|
Object.keys(params).forEach(key => delete params[key]);
|
180
183
|
|
181
184
|
for (const part of routeParts) {
|
package/lib/rew/pkgs/web.js
CHANGED
@@ -3,6 +3,7 @@ const emitter = require("../functions/emitter");
|
|
3
3
|
const { compile } = require("../modules/compiler");
|
4
4
|
const { wait } = require("../functions/wait");
|
5
5
|
const { generateRandomID } = require("../functions/id");
|
6
|
+
const { REW_FILE_TYPE } = require("../const/ext");
|
6
7
|
|
7
8
|
|
8
9
|
const selfClosingElements = new Set([
|
@@ -476,11 +477,11 @@ module.exports = (context, importOptions) => {
|
|
476
477
|
}
|
477
478
|
return null;
|
478
479
|
},
|
479
|
-
transform(code, id) {
|
480
|
-
if (id.endsWith('.coffee')) {
|
481
|
-
const result = compile({ content: code, path: filepath }, { jsx: true, keepImports: true });
|
480
|
+
async transform(code, id) {
|
481
|
+
if (id.endsWith(REW_FILE_TYPE.EXTENSION) || id.endsWith('.coffee')) {
|
482
|
+
const result = compile({ content: code, path: filepath }, { jsx: true, async: true, keepImports: true });
|
482
483
|
return {
|
483
|
-
code: result,
|
484
|
+
code: await result,
|
484
485
|
map: null,
|
485
486
|
};
|
486
487
|
}
|