papagaio 0.7.1 → 0.7.5
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 +1 -1
- package/bin/cli.mjs +114 -130
- package/index.html +160 -282
- package/package.json +2 -2
- package/papagaio.js +202 -0
- package/tests/test.js +1 -1
- package/examples/simple.html +0 -15
- package/examples/wasm.papagaio +0 -70
- package/mobile.html +0 -209
- package/src/papagaio-bootstrap.mjs +0 -23
- package/src/papagaio.js +0 -249
package/README.md
CHANGED
package/bin/cli.mjs
CHANGED
|
@@ -7,147 +7,131 @@ const isNode = typeof process !== 'undefined' && process.versions && process.ver
|
|
|
7
7
|
// MAIN FUNCTION
|
|
8
8
|
// ============================================================================
|
|
9
9
|
async function main() {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
10
|
+
// ============================================================================
|
|
11
|
+
// IMPORTS - Branch por runtime
|
|
12
|
+
// ============================================================================
|
|
13
|
+
let Papagaio, std, os, fs, pkg;
|
|
14
|
+
|
|
15
|
+
if (isQuickJS) {
|
|
16
|
+
// QuickJS imports
|
|
17
|
+
const stdModule = await import("std");
|
|
18
|
+
const osModule = await import("os");
|
|
19
|
+
std = stdModule;
|
|
20
|
+
os = osModule;
|
|
21
|
+
const { Papagaio: P } = await import("../papagaio.js");
|
|
22
|
+
Papagaio = P;
|
|
23
|
+
} else {
|
|
24
|
+
// Node.js imports
|
|
25
|
+
const fsModule = await import("fs");
|
|
26
|
+
fs = fsModule.default;
|
|
27
|
+
|
|
28
|
+
// Load package.json usando fs ao invés de require
|
|
29
|
+
const pkgPath = new URL("../package.json", import.meta.url);
|
|
30
|
+
const pkgContent = fs.readFileSync(pkgPath, "utf8");
|
|
31
|
+
pkg = JSON.parse(pkgContent);
|
|
32
|
+
|
|
33
|
+
const { Papagaio: P } = await import("../papagaio.js");
|
|
34
|
+
Papagaio = P;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// ============================================================================
|
|
38
|
+
// ABSTRAÇÃO DE CONSOLE/STD
|
|
39
|
+
// ============================================================================
|
|
40
|
+
const output = {
|
|
41
|
+
log: isQuickJS ? (msg) => std.out.puts(msg + "\n") : console.log,
|
|
42
|
+
error: isQuickJS ? (msg) => std.err.puts(msg + "\n") : console.error,
|
|
43
|
+
exit: isQuickJS ? std.exit : process.exit
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
// ============================================================================
|
|
47
|
+
// PARSE ARGUMENTS
|
|
48
|
+
// ============================================================================
|
|
49
|
+
const args = isQuickJS ? scriptArgs.slice(1) : process.argv.slice(2);
|
|
50
|
+
const VERSION = isQuickJS ? "0.6.0" : pkg.version;
|
|
51
|
+
|
|
52
|
+
// Help & Version
|
|
53
|
+
if (args.includes("-v") || args.includes("--version")) {
|
|
54
|
+
output.log(VERSION);
|
|
55
|
+
output.exit(0);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (args.includes("-h") || args.includes("--help")) {
|
|
59
|
+
output.log(`Usage: papagaio [options] <file1> [file2] [...]
|
|
60
60
|
|
|
61
61
|
Options:
|
|
62
62
|
-h, --help Show this help message
|
|
63
63
|
-v, --version Show version number
|
|
64
|
-
--sigil <symbol> Set sigil symbol
|
|
65
|
-
--open <symbol> Set open symbol
|
|
66
|
-
--close <symbol> Set close symbol
|
|
67
64
|
|
|
68
65
|
Examples:
|
|
69
66
|
papagaio input.txt
|
|
70
67
|
papagaio file1.txt file2.txt file3.txt
|
|
71
|
-
papagaio *.txt
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
throw new Error(`cannot open file '${filepath}'`);
|
|
105
|
-
}
|
|
106
|
-
const content = f.readAsString();
|
|
107
|
-
f.close();
|
|
108
|
-
return content;
|
|
109
|
-
} else {
|
|
110
|
-
if (!fs.existsSync(filepath)) {
|
|
111
|
-
throw new Error(`file not found: ${filepath}`);
|
|
112
|
-
}
|
|
113
|
-
return fs.readFileSync(filepath, "utf8");
|
|
68
|
+
papagaio *.txt`);
|
|
69
|
+
output.exit(0);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Get input files
|
|
73
|
+
const files = args.filter((arg, i) => {
|
|
74
|
+
if (arg.startsWith("-")) return false;
|
|
75
|
+
return true;
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
if (files.length === 0) {
|
|
79
|
+
output.error("Error: no input file specified.\nUse --help for usage.");
|
|
80
|
+
output.exit(1);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// ============================================================================
|
|
84
|
+
// FILE READING ABSTRACTION
|
|
85
|
+
// ============================================================================
|
|
86
|
+
function readFile(filepath) {
|
|
87
|
+
if (isQuickJS) {
|
|
88
|
+
const f = std.open(filepath, "r");
|
|
89
|
+
if (!f) {
|
|
90
|
+
throw new Error(`cannot open file '${filepath}'`);
|
|
91
|
+
}
|
|
92
|
+
const content = f.readAsString();
|
|
93
|
+
f.close();
|
|
94
|
+
return content;
|
|
95
|
+
} else {
|
|
96
|
+
if (!fs.existsSync(filepath)) {
|
|
97
|
+
throw new Error(`file not found: ${filepath}`);
|
|
98
|
+
}
|
|
99
|
+
return fs.readFileSync(filepath, "utf8");
|
|
100
|
+
}
|
|
114
101
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
102
|
+
|
|
103
|
+
// ============================================================================
|
|
104
|
+
// READ AND CONCATENATE FILES
|
|
105
|
+
// ============================================================================
|
|
106
|
+
let concatenatedSrc = "";
|
|
107
|
+
let hasErrors = false;
|
|
108
|
+
|
|
109
|
+
for (const file of files) {
|
|
110
|
+
try {
|
|
111
|
+
const src = readFile(file);
|
|
112
|
+
concatenatedSrc += src;
|
|
113
|
+
} catch (error) {
|
|
114
|
+
output.error(`Error reading ${file}: ${error.message || error}`);
|
|
115
|
+
hasErrors = true;
|
|
116
|
+
}
|
|
130
117
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
const p = new Papagaio(sigil, open, close);
|
|
141
|
-
const out = p.process(concatenatedSrc);
|
|
142
|
-
output.log(out);
|
|
118
|
+
|
|
119
|
+
if (hasErrors) {
|
|
120
|
+
output.exit(1);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// PROCESS CONCATENATED INPUT
|
|
124
|
+
const p = new Papagaio();
|
|
125
|
+
const out = p.process(concatenatedSrc);
|
|
126
|
+
output.log(out);
|
|
143
127
|
}
|
|
144
128
|
|
|
145
|
-
//
|
|
129
|
+
// main
|
|
146
130
|
main().catch(err => {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
131
|
+
const output = isQuickJS
|
|
132
|
+
? (msg) => std.err.puts(msg + "\n")
|
|
133
|
+
: console.error;
|
|
134
|
+
output("Fatal error: " + (err.message || err));
|
|
135
|
+
const exit = isQuickJS ? std.exit : process.exit;
|
|
136
|
+
exit(1);
|
|
153
137
|
});
|