@makano/rew 1.2.74 → 1.2.76
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/rew/cli/cli.js +22 -1
- package/lib/rew/cli/log.js +7 -3
- package/lib/rew/cli/utils.js +45 -26
- package/lib/rew/const/opt.js +3 -1
- package/lib/rew/modules/compiler.js +82 -4
- package/package.json +1 -2
- package/runtime.d.ts +943 -891
package/lib/rew/cli/cli.js
CHANGED
|
@@ -123,10 +123,31 @@ yargs(hideBin(process.argv))
|
|
|
123
123
|
yargs.positional('path', {
|
|
124
124
|
describe: 'Path of the project to create',
|
|
125
125
|
type: 'string',
|
|
126
|
+
}).option('git', {
|
|
127
|
+
alias: 'g',
|
|
128
|
+
describe: `Enable Git Option`,
|
|
129
|
+
type: 'boolean',
|
|
130
|
+
}).option('civet', {
|
|
131
|
+
alias: 'c',
|
|
132
|
+
describe: `Use civet for main`,
|
|
133
|
+
type: 'boolean',
|
|
134
|
+
}).option('types', {
|
|
135
|
+
alias: 't',
|
|
136
|
+
describe: `Create @types/rew in node modules`,
|
|
137
|
+
type: 'boolean',
|
|
138
|
+
}).option('name', {
|
|
139
|
+
alias: 'n',
|
|
140
|
+
describe: `The package name`,
|
|
141
|
+
type: 'string'
|
|
142
|
+
}).option('ignore', {
|
|
143
|
+
alias: 'i',
|
|
144
|
+
describe: `Use default options`,
|
|
145
|
+
type: 'boolean',
|
|
146
|
+
default: false
|
|
126
147
|
});
|
|
127
148
|
},
|
|
128
149
|
(argv) => {
|
|
129
|
-
require('./utils').createProject(argv.path);
|
|
150
|
+
require('./utils').createProject(argv.path, argv);
|
|
130
151
|
},
|
|
131
152
|
)
|
|
132
153
|
.command(
|
package/lib/rew/cli/log.js
CHANGED
|
@@ -8,7 +8,7 @@ let last = '';
|
|
|
8
8
|
|
|
9
9
|
const log = (module.exports.log = function (...toPrint) {
|
|
10
10
|
let prefix = start ? startPrefix : middlePrefix;
|
|
11
|
-
let returns = false;
|
|
11
|
+
let returns = false, nosep = false;
|
|
12
12
|
if (toPrint[toPrint.length - 1] == ':end') {
|
|
13
13
|
prefix = endPrefix;
|
|
14
14
|
toPrint.pop();
|
|
@@ -17,13 +17,17 @@ const log = (module.exports.log = function (...toPrint) {
|
|
|
17
17
|
returns = true;
|
|
18
18
|
toPrint.pop();
|
|
19
19
|
}
|
|
20
|
+
if (toPrint[toPrint.length - 1] == ':nosep') {
|
|
21
|
+
nosep = true;
|
|
22
|
+
toPrint.pop();
|
|
23
|
+
}
|
|
20
24
|
if (prefix == endPrefix && start) prefix = separator;
|
|
21
25
|
// if(last == endPrefix && prefix == separator) prefix = startPrefix;
|
|
22
|
-
if (!start) console.log(last == endPrefix ? startPrefix : separator);
|
|
26
|
+
if (!start && !returns && !nosep) console.log(last == endPrefix ? startPrefix : separator);
|
|
23
27
|
if (start) start = false;
|
|
24
28
|
last = prefix;
|
|
25
29
|
if (returns) return [prefix, ...toPrint].join(' ');
|
|
26
|
-
else console.log(prefix, ...toPrint);
|
|
30
|
+
else if (toPrint.length) console.log(prefix, ...toPrint);
|
|
27
31
|
});
|
|
28
32
|
|
|
29
33
|
module.exports.logget = function (...toPrint) {
|
package/lib/rew/cli/utils.js
CHANGED
|
@@ -26,6 +26,7 @@ const {
|
|
|
26
26
|
cachepath,
|
|
27
27
|
localBinPath
|
|
28
28
|
} = require('./helpers');
|
|
29
|
+
const { input } = require('../functions/stdout');
|
|
29
30
|
|
|
30
31
|
module.exports = {
|
|
31
32
|
conf(command, fullPath, key, value) {
|
|
@@ -77,13 +78,19 @@ module.exports = {
|
|
|
77
78
|
}
|
|
78
79
|
}
|
|
79
80
|
},
|
|
80
|
-
createProject: (ppath) => {
|
|
81
|
+
createProject: (ppath, argv) => {
|
|
81
82
|
const projectPath = path.join(process.cwd(), ppath);
|
|
82
83
|
log(''.cyan, 'Creating at'.blue, ppath.yellow);
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
84
|
+
|
|
85
|
+
const b = (value, type) => type == "boolean" ? (value.toString() == 'y' || value.toString() == "yes" ? true : false) : value;
|
|
86
|
+
|
|
87
|
+
const registerInput = (name, promptText, type, argvName, defaultValue) => {
|
|
88
|
+
if(type == 'boolean') defaultValue = false;
|
|
89
|
+
let prompted = false;
|
|
90
|
+
project[name] = argv[argvName] ?? (argv.ignore ? defaultValue ?? b(input(promptText, prompted = log() || true), type) : b(input(promptText, prompted = log() || true), type));
|
|
91
|
+
log(name.grey+'?'.grey, type == 'string' ? project[name].green : (project[name] == true ? 'yes'.cyan : 'no'.yellow), prompted ? ':nosep' : '');
|
|
92
|
+
}
|
|
93
|
+
|
|
87
94
|
const project = {};
|
|
88
95
|
const create = () => {
|
|
89
96
|
fs.mkdirSync(projectPath, { recursive: true });
|
|
@@ -97,8 +104,8 @@ module.exports = {
|
|
|
97
104
|
execSync('cd ' + projectPath + ' && git init . && git branch -m main', { stdio: 'ignore' });
|
|
98
105
|
}
|
|
99
106
|
if(project.intellisense){
|
|
100
|
-
fs.
|
|
101
|
-
fs.copyFileSync(path.join(__dirname, '../../../runtime.d.ts'), path.join(projectPath, '
|
|
107
|
+
fs.mkdirSync(path.join(projectPath, 'node_modules/@types/rew'), { recursive: true });
|
|
108
|
+
fs.copyFileSync(path.join(__dirname, '../../../runtime.d.ts'), path.join(projectPath, 'node_modules/@types/rew/index.d.ts'));
|
|
102
109
|
}
|
|
103
110
|
execSync('cd ' + projectPath + ' && npm init -y', { stdio: 'ignore' });
|
|
104
111
|
if(project.civet){
|
|
@@ -115,29 +122,41 @@ module.exports = {
|
|
|
115
122
|
// }
|
|
116
123
|
// });
|
|
117
124
|
log('Done.'.blue.bold, ':end');
|
|
118
|
-
rl.close();
|
|
119
125
|
};
|
|
120
126
|
if (!fs.existsSync(projectPath)) {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
127
|
+
|
|
128
|
+
registerInput(
|
|
129
|
+
'package',
|
|
130
|
+
logget(' Package Name: '.blue),
|
|
131
|
+
'string',
|
|
132
|
+
'name',
|
|
133
|
+
path.basename(projectPath)
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
registerInput(
|
|
137
|
+
'intellisense',
|
|
138
|
+
logget(' Use intellisense declarations ? (y/N): '.magenta),
|
|
139
|
+
'boolean',
|
|
140
|
+
'types'
|
|
141
|
+
)
|
|
142
|
+
|
|
143
|
+
registerInput(
|
|
144
|
+
'civet',
|
|
145
|
+
logget(' Use Civet For main ? (y/N): '.blue),
|
|
146
|
+
'boolean',
|
|
147
|
+
'civet'
|
|
148
|
+
)
|
|
149
|
+
|
|
150
|
+
registerInput(
|
|
151
|
+
'git',
|
|
152
|
+
logget(' Use git ? (y/N): '.yellow),
|
|
153
|
+
'boolean',
|
|
154
|
+
'git'
|
|
155
|
+
)
|
|
156
|
+
|
|
157
|
+
create();
|
|
138
158
|
} else {
|
|
139
159
|
log(` Project ${ppath} already exists at ${projectPath}`.red.bold, ':end');
|
|
140
|
-
rl.close();
|
|
141
160
|
}
|
|
142
161
|
},
|
|
143
162
|
runApp(pathOrPackage, options) {
|
package/lib/rew/const/opt.js
CHANGED
|
@@ -6,7 +6,7 @@ const { getFile, file } = require('./fs');
|
|
|
6
6
|
const babel = require('@babel/core');
|
|
7
7
|
const path = require('path');
|
|
8
8
|
const babelReact = require('@babel/preset-react');
|
|
9
|
-
const { readFileSync } = require('fs');
|
|
9
|
+
const { readFileSync, existsSync } = require('fs');
|
|
10
10
|
const { wait } = require('../functions/wait');
|
|
11
11
|
const { REW_FILE_TYPE } = require('../const/ext');
|
|
12
12
|
const { USING_DEFAULT } = require('../const/usage');
|
|
@@ -122,12 +122,43 @@ const fnextToken = (i, tokens, type, value) => {
|
|
|
122
122
|
.find((t) => t.type == type && (value ? t.value == value : true));
|
|
123
123
|
};
|
|
124
124
|
|
|
125
|
+
function declareAlias(aliases, token) {
|
|
126
|
+
const regex = /^#declare(\*)?\s+(\w+)\s+"([^"]+)"\s*=\s*([\s\S]*);$/;
|
|
127
|
+
const match = token.value.trim().match(regex);
|
|
128
|
+
|
|
129
|
+
if (match) {
|
|
130
|
+
const isPublic = !!match[1];
|
|
131
|
+
const type = match[2] == "key" ? 'IDENTIFIER' : match[2];
|
|
132
|
+
const name = match[3];
|
|
133
|
+
const value = match[4].trim();
|
|
134
|
+
|
|
135
|
+
const aliasValue = value.startsWith('${')
|
|
136
|
+
? new Function('token', 'tokens', 'code', value.slice(2, -1))
|
|
137
|
+
: value;
|
|
138
|
+
|
|
139
|
+
aliases[type] = aliases[type] || {};
|
|
140
|
+
aliases[type][name] = aliasValue;
|
|
141
|
+
|
|
142
|
+
if(isPublic){
|
|
143
|
+
execOptions._syntaxAliases[type] = execOptions._syntaxAliases[type] || {};
|
|
144
|
+
execOptions._syntaxAliases[type][name] = aliasValue;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
125
149
|
function compileRewStuff(content, options) {
|
|
126
150
|
const tokens = tokenizeCoffeeScript(content);
|
|
127
151
|
let result = '';
|
|
152
|
+
let multilineDeclareBuffer = [];
|
|
153
|
+
let multilineDeclare = false;
|
|
128
154
|
|
|
129
155
|
let hooks = [];
|
|
130
156
|
|
|
157
|
+
|
|
158
|
+
const aliases = {
|
|
159
|
+
...execOptions._syntaxAliases
|
|
160
|
+
}
|
|
161
|
+
|
|
131
162
|
for (let i = 0; i < tokens.length; i++) {
|
|
132
163
|
const token = tokens[i];
|
|
133
164
|
let { token: nextToken, n } = gnextToken(i, 1, tokens) || {};
|
|
@@ -136,6 +167,30 @@ function compileRewStuff(content, options) {
|
|
|
136
167
|
continue;
|
|
137
168
|
}
|
|
138
169
|
|
|
170
|
+
if ((token.type === "COMMENT" && multilineDeclare) || (token.type !== "COMMENT" && multilineDeclare)) {
|
|
171
|
+
if(token.type === "COMMENT"){
|
|
172
|
+
multilineDeclareBuffer.push(token.value.startsWith('###') ? token.value.slice(3) : token.value.slice(1));
|
|
173
|
+
if (token.value.includes(';')) {
|
|
174
|
+
multilineDeclare = false;
|
|
175
|
+
const combinedDeclaration = multilineDeclareBuffer.join('\n');
|
|
176
|
+
declareAlias(aliases, { ...token, value: combinedDeclaration });
|
|
177
|
+
multilineDeclareBuffer = [];
|
|
178
|
+
}
|
|
179
|
+
} else {
|
|
180
|
+
multilineDeclare = false;
|
|
181
|
+
multilineDeclareBuffer = [];
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
if (token.type === "COMMENT" && token.value.startsWith('#declare')) {
|
|
186
|
+
if (token.value.includes(';')) {
|
|
187
|
+
declareAlias(aliases, token);
|
|
188
|
+
} else {
|
|
189
|
+
multilineDeclare = true;
|
|
190
|
+
multilineDeclareBuffer.push(token.value);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
139
194
|
if (token.type === 'IDENTIFIER' && token.value === 'opt.set') {
|
|
140
195
|
const { token: nextNextToken } = gnextToken(i, 2, tokens) || {};
|
|
141
196
|
if (nextNextToken && nextNextToken.value.slice(1).slice(0, -1) == 'jsxPragma') {
|
|
@@ -269,6 +324,17 @@ function compileRewStuff(content, options) {
|
|
|
269
324
|
});
|
|
270
325
|
}
|
|
271
326
|
|
|
327
|
+
const aliasType = aliases[token.type];
|
|
328
|
+
if (aliasType && aliasType[token.value]) {
|
|
329
|
+
const aliasValue = aliasType[token.value];
|
|
330
|
+
if (typeof aliasValue === 'function') {
|
|
331
|
+
result += aliasValue(token, tokens, result) || "";
|
|
332
|
+
} else {
|
|
333
|
+
result += aliasValue;
|
|
334
|
+
}
|
|
335
|
+
continue;
|
|
336
|
+
}
|
|
337
|
+
|
|
272
338
|
// if(token.type === 'TRIPLE_STRING'){
|
|
273
339
|
// token.value = '```'+token.value.slice(3).slice(0, -3).replace(/\#\{/g, '${')+'```';
|
|
274
340
|
// }
|
|
@@ -282,10 +348,19 @@ function compileRewStuff(content, options) {
|
|
|
282
348
|
}
|
|
283
349
|
});
|
|
284
350
|
}
|
|
351
|
+
|
|
352
|
+
if (token.type === "COMMENT" && token.value.startsWith('#include')) {
|
|
353
|
+
const includeContent = token.value.split(' ')[1] || '';
|
|
354
|
+
const filename = options.filename ? path.resolve(path.dirname(options.filename), includeContent) : includeContent;
|
|
355
|
+
if (existsSync(filename)) {
|
|
356
|
+
result += '\n'+ compileRewStuff(readFileSync(filename).toString(), {
|
|
357
|
+
...options,
|
|
358
|
+
filename
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
}
|
|
285
362
|
}
|
|
286
363
|
|
|
287
|
-
// console.log(result)
|
|
288
|
-
|
|
289
364
|
return result;
|
|
290
365
|
}
|
|
291
366
|
|
|
@@ -298,7 +373,10 @@ const compileCivetStuff = (file, options) => {
|
|
|
298
373
|
js: true
|
|
299
374
|
};
|
|
300
375
|
|
|
301
|
-
const prepared = compileRewStuff(file.content,
|
|
376
|
+
const prepared = compileRewStuff(file.content, {
|
|
377
|
+
filename: file.path,
|
|
378
|
+
...options
|
|
379
|
+
});
|
|
302
380
|
let compiled = options.async ? compileCivet(prepared, compileOptions) : wait(compileCivet, prepared, compileOptions);
|
|
303
381
|
|
|
304
382
|
return {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@makano/rew",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.76",
|
|
4
4
|
"description": "A simple coffescript runtime and app manager",
|
|
5
5
|
"main": "main.js",
|
|
6
6
|
"directories": {
|
|
@@ -12,7 +12,6 @@
|
|
|
12
12
|
"files": [
|
|
13
13
|
"lib/",
|
|
14
14
|
"runtime.d.ts",
|
|
15
|
-
"jsconfig.json",
|
|
16
15
|
"main.js",
|
|
17
16
|
"README.md"
|
|
18
17
|
],
|