catchword 0.0.0-stage → 1.0.0
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/LICENSE +21 -0
- package/README.md +314 -2
- package/bin/catchword.js +8 -0
- package/bin/falcon.js +5 -0
- package/dist/cli/adb.d.ts +6 -0
- package/dist/cli/adb.js +52 -0
- package/dist/cli/audit.d.ts +4 -0
- package/dist/cli/audit.js +91 -0
- package/dist/cli/build.d.ts +13 -0
- package/dist/cli/build.js +139 -0
- package/dist/cli/clean.d.ts +1 -0
- package/dist/cli/clean.js +15 -0
- package/dist/cli/create.d.ts +4 -0
- package/dist/cli/create.js +60 -0
- package/dist/cli/dev.d.ts +10 -0
- package/dist/cli/dev.js +23 -0
- package/dist/cli/index.d.ts +3 -0
- package/dist/cli/index.js +243 -0
- package/dist/cli/native.d.ts +18 -0
- package/dist/cli/native.js +232 -0
- package/dist/cli/simulator.d.ts +8 -0
- package/dist/cli/simulator.js +77 -0
- package/dist/cli/upload.d.ts +9 -0
- package/dist/cli/upload.js +135 -0
- package/dist/cli/util.d.ts +8 -0
- package/dist/cli/util.js +43 -0
- package/dist/config.d.ts +17 -0
- package/dist/config.js +90 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +51 -0
- package/dist/native/api.d.ts +46 -0
- package/dist/native/api.js +185 -0
- package/dist/native/build.d.ts +47 -0
- package/dist/native/build.js +407 -0
- package/dist/native/elf.d.ts +15 -0
- package/dist/native/elf.js +200 -0
- package/dist/native/types.d.ts +9 -0
- package/dist/native/types.js +91 -0
- package/dist/native/wsl.d.ts +7 -0
- package/dist/native/wsl.js +29 -0
- package/dist/plugin/app-entry.d.ts +6 -0
- package/dist/plugin/app-entry.js +115 -0
- package/dist/plugin/assets.d.ts +4 -0
- package/dist/plugin/assets.js +84 -0
- package/dist/plugin/config.d.ts +14 -0
- package/dist/plugin/config.js +80 -0
- package/dist/plugin/context.d.ts +58 -0
- package/dist/plugin/context.js +255 -0
- package/dist/plugin/fallback.d.ts +4 -0
- package/dist/plugin/fallback.js +81 -0
- package/dist/plugin/image-service.d.ts +17 -0
- package/dist/plugin/image-service.js +138 -0
- package/dist/plugin/jsapi.d.ts +6 -0
- package/dist/plugin/jsapi.js +82 -0
- package/dist/plugin/output.d.ts +4 -0
- package/dist/plugin/output.js +75 -0
- package/dist/plugin/preview.d.ts +34 -0
- package/dist/plugin/preview.js +459 -0
- package/dist/plugin/sanitize.d.ts +5 -0
- package/dist/plugin/sanitize.js +48 -0
- package/dist/plugin/security.d.ts +4 -0
- package/dist/plugin/security.js +18 -0
- package/dist/plugin/sfc.d.ts +6 -0
- package/dist/plugin/sfc.js +181 -0
- package/dist/plugin/shim.d.ts +4 -0
- package/dist/plugin/shim.js +68 -0
- package/dist/plugin/state.d.ts +31 -0
- package/dist/plugin/state.js +61 -0
- package/dist/plugin/string-table.d.ts +7 -0
- package/dist/plugin/string-table.js +324 -0
- package/dist/plugin/style.d.ts +15 -0
- package/dist/plugin/style.js +114 -0
- package/dist/plugin/template.d.ts +7 -0
- package/dist/plugin/template.js +39 -0
- package/dist/steps/manifest.d.ts +9 -0
- package/dist/steps/manifest.js +60 -0
- package/dist/steps/pack.d.ts +3 -0
- package/dist/steps/pack.js +46 -0
- package/dist/steps/qjsc.d.ts +9 -0
- package/dist/steps/qjsc.js +186 -0
- package/dist/steps/report.d.ts +2 -0
- package/dist/steps/report.js +50 -0
- package/dist/steps/security.d.ts +17 -0
- package/dist/steps/security.js +310 -0
- package/dist/types.d.ts +158 -0
- package/dist/types.js +1 -0
- package/dist/util/class-tokenize.d.ts +2 -0
- package/dist/util/class-tokenize.js +56 -0
- package/dist/util/component-name.d.ts +6 -0
- package/dist/util/component-name.js +120 -0
- package/dist/util/fs.d.ts +14 -0
- package/dist/util/fs.js +70 -0
- package/dist/util/imports.d.ts +2 -0
- package/dist/util/imports.js +173 -0
- package/dist/util/log.d.ts +8 -0
- package/dist/util/log.js +24 -0
- package/package.json +61 -4
- package/template/README.md +38 -0
- package/template/catchword.config.ts +18 -0
- package/template/native/CMakeLists.txt +33 -0
- package/template/native/README.md +34 -0
- package/template/native/api.override.json +7 -0
- package/template/native/include/jsapi_demo.h +10 -0
- package/template/native/lib/README.md +10 -0
- package/template/native/sdk/README.md +6 -0
- package/template/native/src/bridge.cpp +9 -0
- package/template/native/src/jsapi_demo.cpp +11 -0
- package/template/package.json +38 -0
- package/template/src/app.js +45 -0
- package/template/src/app.json +11 -0
- package/template/src/base-page.js +150 -0
- package/template/src/components/HelloWorld.vue +20 -0
- package/template/src/mocks/$jsapi.test.js +5 -0
- package/template/src/mocks/test-module.js +5 -0
- package/template/src/pages/index/index.vue +41 -0
- package/template/src/pages/page/page.vue +63 -0
- package/template/src/shims.d.ts +21 -0
- package/template/src/styles/base.less +23 -0
- package/template/src/styles/mixin.less +32 -0
- package/template/src/styles/var.less +15 -0
- package/template/tsconfig.json +14 -0
- package/vendor/README.md +16 -0
- package/vendor/falcon-styler/.jscsrc +31 -0
- package/vendor/falcon-styler/LICENSE +21 -0
- package/vendor/falcon-styler/README.md +124 -0
- package/vendor/falcon-styler/index.js +273 -0
- package/vendor/falcon-styler/lib/shorthand-parser.js +78 -0
- package/vendor/falcon-styler/lib/util.js +30 -0
- package/vendor/falcon-styler/lib/validator.js +846 -0
- package/vendor/falcon-styler/package.json +32 -0
- package/vendor/licenses/falcon-styler.LICENSE +21 -0
- package/vendor/licenses/weex-template-compiler.README.md +3 -0
- package/vendor/package.json +5 -0
- package/vendor/qjsc/SHA256SUMS +11 -0
- package/vendor/qjsc/bin/darwin/arm64/qjsc20200705 +0 -0
- package/vendor/qjsc/bin/darwin/x64/qjsc20200412 +0 -0
- package/vendor/qjsc/bin/darwin/x64/qjsc20200705 +0 -0
- package/vendor/qjsc/bin/darwin/x64/qjsc20200906 +0 -0
- package/vendor/qjsc/bin/darwin/x64/qjscbn20200412 +0 -0
- package/vendor/qjsc/bin/darwin/x64/qjscbn20200705 +0 -0
- package/vendor/qjsc/bin/darwin/x64/qjscbn20200906 +0 -0
- package/vendor/qjsc/bin/linux/qjsc20200705 +0 -0
- package/vendor/qjsc/bin/win32/libgcc_s_dw2-1.dll +0 -0
- package/vendor/qjsc/bin/win32/pthreadGC-3.dll +0 -0
- package/vendor/qjsc/bin/win32/qjsc20200705.exe +0 -0
- package/vendor/web/falcon-js-web.js +863 -0
- package/vendor/web/falcon-jsapi-web.js +479 -0
- package/vendor/web/falcon-vue-render.js +11323 -0
- package/vendor/web/falcon-web-boot.js +4 -0
- package/vendor/web/falcon-web-hud.js +119 -0
- package/vendor/web/falcon-web-style.js +235 -0
- package/vendor/web/vue.runtime.common.dev.js +8467 -0
- package/vendor/web/vue.runtime.common.js +5 -0
- package/vendor/weex-template-compiler/README.md +3 -0
- package/vendor/weex-template-compiler/build.js +4824 -0
- package/vendor/weex-template-compiler/index.js +17 -0
- package/vendor/weex-template-compiler/package.json +25 -0
package/dist/util/fs.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import crypto from 'node:crypto';
|
|
4
|
+
export function ensureDir(dir) {
|
|
5
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
6
|
+
}
|
|
7
|
+
export function exists(p) {
|
|
8
|
+
return fs.existsSync(p);
|
|
9
|
+
}
|
|
10
|
+
export function walkSync(dir, opts = {}) {
|
|
11
|
+
const out = [];
|
|
12
|
+
if (!fs.existsSync(dir))
|
|
13
|
+
return out;
|
|
14
|
+
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
15
|
+
for (const entry of entries) {
|
|
16
|
+
if (opts.skipDotFiles && entry.name.startsWith('.'))
|
|
17
|
+
continue;
|
|
18
|
+
const full = path.join(dir, entry.name);
|
|
19
|
+
if (entry.isDirectory()) {
|
|
20
|
+
out.push(...walkSync(full, opts));
|
|
21
|
+
}
|
|
22
|
+
else if (entry.isFile()) {
|
|
23
|
+
if (!opts.filter || opts.filter(full))
|
|
24
|
+
out.push(full);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return out;
|
|
28
|
+
}
|
|
29
|
+
function hashFile(algorithm, file) {
|
|
30
|
+
const hash = crypto.createHash(algorithm);
|
|
31
|
+
const fd = fs.openSync(file, 'r');
|
|
32
|
+
const buf = Buffer.allocUnsafe(1024 * 1024);
|
|
33
|
+
try {
|
|
34
|
+
let read = 0;
|
|
35
|
+
while ((read = fs.readSync(fd, buf, 0, buf.length, null)) > 0) {
|
|
36
|
+
hash.update(buf.subarray(0, read));
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
finally {
|
|
40
|
+
fs.closeSync(fd);
|
|
41
|
+
}
|
|
42
|
+
return hash.digest('hex');
|
|
43
|
+
}
|
|
44
|
+
export function md5File(file) {
|
|
45
|
+
return hashFile('md5', file);
|
|
46
|
+
}
|
|
47
|
+
export function sha256File(file) {
|
|
48
|
+
return hashFile('sha256', file);
|
|
49
|
+
}
|
|
50
|
+
export function md5(data) {
|
|
51
|
+
return crypto.createHash('md5').update(data).digest('hex');
|
|
52
|
+
}
|
|
53
|
+
export function copyDirSync(src, dest) {
|
|
54
|
+
fs.cpSync(src, dest, { recursive: true, force: true });
|
|
55
|
+
}
|
|
56
|
+
export function rmrf(target) {
|
|
57
|
+
fs.rmSync(target, { recursive: true, force: true });
|
|
58
|
+
}
|
|
59
|
+
export function readJson(file) {
|
|
60
|
+
if (!fs.existsSync(file))
|
|
61
|
+
return null;
|
|
62
|
+
return JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
63
|
+
}
|
|
64
|
+
export function writeFile(file, content) {
|
|
65
|
+
ensureDir(path.dirname(file));
|
|
66
|
+
fs.writeFileSync(file, content);
|
|
67
|
+
}
|
|
68
|
+
export function toUnix(p) {
|
|
69
|
+
return p.replace(/\\/g, '/');
|
|
70
|
+
}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
export function stripVueDefineComponentImport(code) {
|
|
2
|
+
const IMPORT_RE = /import\s+([^;]+?)\s+from\s+(['"])vue\2\s*;?/g;
|
|
3
|
+
return code.replace(IMPORT_RE, (statement, clause) => {
|
|
4
|
+
const braceStart = clause.indexOf('{');
|
|
5
|
+
if (braceStart === -1)
|
|
6
|
+
return statement;
|
|
7
|
+
const braceEnd = clause.indexOf('}', braceStart);
|
|
8
|
+
if (braceEnd === -1)
|
|
9
|
+
return statement;
|
|
10
|
+
const before = clause.slice(0, braceStart).trim();
|
|
11
|
+
const named = clause
|
|
12
|
+
.slice(braceStart + 1, braceEnd)
|
|
13
|
+
.split(',')
|
|
14
|
+
.map((s) => s.trim())
|
|
15
|
+
.filter(Boolean);
|
|
16
|
+
const kept = named.filter((s) => !/^defineComponent(\s+as\s+\w+)?$/.test(s));
|
|
17
|
+
if (kept.length === named.length)
|
|
18
|
+
return statement;
|
|
19
|
+
if (kept.length === 0 && !before)
|
|
20
|
+
return '';
|
|
21
|
+
const namedPart = kept.length ? `{ ${kept.join(', ')} }` : '';
|
|
22
|
+
const parts = [before, namedPart].filter(Boolean).join(', ');
|
|
23
|
+
return `import ${parts} from 'vue';`;
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
const BACKSLASH = String.fromCharCode(92);
|
|
27
|
+
const SPACE_RE = /\s/;
|
|
28
|
+
const NL = String.fromCharCode(10);
|
|
29
|
+
const ASSET_RE = /\.(png|jpe?g|gif|webp|bmp|svg|ttf|otf|woff2?|mp3|mp4|wav)$/i;
|
|
30
|
+
function identifierFor(specifier) {
|
|
31
|
+
let safe = '';
|
|
32
|
+
for (const ch of specifier) {
|
|
33
|
+
safe += /[a-z0-9]/i.test(ch) ? ch : '_';
|
|
34
|
+
}
|
|
35
|
+
return `__falcon_require_${safe}__`;
|
|
36
|
+
}
|
|
37
|
+
export function transformRequireToImport(code) {
|
|
38
|
+
let out = '';
|
|
39
|
+
let collected = '';
|
|
40
|
+
const seen = new Map();
|
|
41
|
+
let i = 0;
|
|
42
|
+
let quote = null;
|
|
43
|
+
let inLineComment = false;
|
|
44
|
+
let inBlockComment = false;
|
|
45
|
+
const insideString = () => quote !== null || inLineComment || inBlockComment;
|
|
46
|
+
while (i < code.length) {
|
|
47
|
+
const ch = code[i];
|
|
48
|
+
const next = code[i + 1];
|
|
49
|
+
if (inLineComment) {
|
|
50
|
+
out += ch;
|
|
51
|
+
if (ch === '\n')
|
|
52
|
+
inLineComment = false;
|
|
53
|
+
i++;
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
if (inBlockComment) {
|
|
57
|
+
out += ch;
|
|
58
|
+
if (ch === '*' && next === '/') {
|
|
59
|
+
out += '/';
|
|
60
|
+
i += 2;
|
|
61
|
+
inBlockComment = false;
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
i++;
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
if (quote) {
|
|
68
|
+
out += ch;
|
|
69
|
+
if (ch === BACKSLASH) {
|
|
70
|
+
out += next || '';
|
|
71
|
+
i += 2;
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
if (ch === quote)
|
|
75
|
+
quote = null;
|
|
76
|
+
i++;
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
if (ch === '/' && next === '/') {
|
|
80
|
+
inLineComment = true;
|
|
81
|
+
out += ch;
|
|
82
|
+
i++;
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
if (ch === '/' && next === '*') {
|
|
86
|
+
inBlockComment = true;
|
|
87
|
+
out += ch;
|
|
88
|
+
i++;
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
if (ch === '"' || ch === "'" || ch === '`') {
|
|
92
|
+
quote = ch;
|
|
93
|
+
out += ch;
|
|
94
|
+
i++;
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
const isRequire = code.startsWith('require', i) &&
|
|
98
|
+
!/[a-z0-9_$]/i.test(code[i - 1] || '') &&
|
|
99
|
+
code[i - 1] !== '.';
|
|
100
|
+
if (!isRequire) {
|
|
101
|
+
out += ch;
|
|
102
|
+
i++;
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
let cursor = i + 'require'.length;
|
|
106
|
+
while (cursor < code.length && /\s/.test(code[cursor]))
|
|
107
|
+
cursor++;
|
|
108
|
+
if (code[cursor] !== '(') {
|
|
109
|
+
out += ch;
|
|
110
|
+
i++;
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
cursor++;
|
|
114
|
+
while (cursor < code.length && /\s/.test(code[cursor]))
|
|
115
|
+
cursor++;
|
|
116
|
+
const literalQuote = code[cursor];
|
|
117
|
+
if (literalQuote !== '"' && literalQuote !== "'") {
|
|
118
|
+
out += ch;
|
|
119
|
+
i++;
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
let end = cursor + 1;
|
|
123
|
+
while (end < code.length && code[end] !== literalQuote) {
|
|
124
|
+
if (code[end] === BACKSLASH)
|
|
125
|
+
end++;
|
|
126
|
+
end++;
|
|
127
|
+
}
|
|
128
|
+
if (end >= code.length) {
|
|
129
|
+
out += ch;
|
|
130
|
+
i++;
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
const specifier = code.slice(cursor + 1, end);
|
|
134
|
+
let close = end + 1;
|
|
135
|
+
while (close < code.length && /\s/.test(code[close]))
|
|
136
|
+
close++;
|
|
137
|
+
if (code[close] !== ')') {
|
|
138
|
+
out += ch;
|
|
139
|
+
i++;
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
let before = i - 1;
|
|
143
|
+
while (before >= 0 && SPACE_RE.test(code[before]))
|
|
144
|
+
before--;
|
|
145
|
+
const beforeChar = before >= 0 ? code[before] : '';
|
|
146
|
+
let after = close + 1;
|
|
147
|
+
while (after < code.length && SPACE_RE.test(code[after]))
|
|
148
|
+
after++;
|
|
149
|
+
const afterChar = after < code.length ? code[after] : '';
|
|
150
|
+
const statementOnly = (beforeChar === ';' || beforeChar === '{' || beforeChar === '}' || beforeChar === '') &&
|
|
151
|
+
(afterChar === ';' || afterChar === '}' || afterChar === '');
|
|
152
|
+
if (statementOnly) {
|
|
153
|
+
collected += `import ${literalQuote}${specifier}${literalQuote}` + NL;
|
|
154
|
+
i = close + 1;
|
|
155
|
+
if (code[i] === ';')
|
|
156
|
+
i++;
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
let ident = seen.get(specifier);
|
|
160
|
+
if (!ident) {
|
|
161
|
+
ident = identifierFor(specifier);
|
|
162
|
+
seen.set(specifier, ident);
|
|
163
|
+
const asset = ASSET_RE.test(specifier);
|
|
164
|
+
collected += asset
|
|
165
|
+
? `import ${ident} from ${literalQuote}${specifier}${literalQuote}` + NL
|
|
166
|
+
: `import * as ${ident} from ${literalQuote}${specifier}${literalQuote}` + NL;
|
|
167
|
+
}
|
|
168
|
+
out += ident;
|
|
169
|
+
i = close + 1;
|
|
170
|
+
}
|
|
171
|
+
void insideString;
|
|
172
|
+
return collected + out;
|
|
173
|
+
}
|
package/dist/util/log.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
function fmt(args) {
|
|
3
|
+
return args.map((a) => (typeof a === 'string' ? a : JSON.stringify(a))).join(' ');
|
|
4
|
+
}
|
|
5
|
+
export const log = {
|
|
6
|
+
info(...args) {
|
|
7
|
+
console.log(...args);
|
|
8
|
+
},
|
|
9
|
+
raw(msg) {
|
|
10
|
+
console.log(msg);
|
|
11
|
+
},
|
|
12
|
+
success(...args) {
|
|
13
|
+
console.log(chalk.green(fmt(args)));
|
|
14
|
+
},
|
|
15
|
+
warn(...args) {
|
|
16
|
+
console.warn(chalk.yellow(fmt(args)));
|
|
17
|
+
},
|
|
18
|
+
error(...args) {
|
|
19
|
+
console.error(chalk.red(fmt(args)));
|
|
20
|
+
},
|
|
21
|
+
step(msg) {
|
|
22
|
+
console.log(chalk.cyan(`\n» ${msg}`));
|
|
23
|
+
}
|
|
24
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,63 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "catchword",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "一个 Falcon 小程序构建工具",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"bin": {
|
|
15
|
+
"catchword": "bin/catchword.js",
|
|
16
|
+
"falcon": "bin/falcon.js",
|
|
17
|
+
"aiot-cli": "bin/catchword.js"
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"bin",
|
|
21
|
+
"dist",
|
|
22
|
+
"vendor",
|
|
23
|
+
"template",
|
|
24
|
+
"README.md"
|
|
25
|
+
],
|
|
26
|
+
"engines": {
|
|
27
|
+
"node": "^20.19.0 || >=22.12.0"
|
|
28
|
+
},
|
|
29
|
+
"scripts": {
|
|
30
|
+
"build": "tsc -p tsconfig.json",
|
|
31
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
32
|
+
"test:build": "node bin/catchword.js build -d tests/fixtures/demo-app -q -p",
|
|
33
|
+
"test:inspect": "node bin/catchword.js build -d tests/fixtures/demo-app",
|
|
34
|
+
"test": "bun run build && bun test",
|
|
35
|
+
"test:smoke": "bun test",
|
|
36
|
+
"format": "biome format --write .",
|
|
37
|
+
"format:check": "biome format ."
|
|
38
|
+
},
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"@vue/compiler-sfc": "^3.5.46",
|
|
41
|
+
"acorn": "^5.2.1",
|
|
42
|
+
"chalk": "^5.6.2",
|
|
43
|
+
"commander": "^14.0.2",
|
|
44
|
+
"compressing": "^2.1.5",
|
|
45
|
+
"css": "2.2.1",
|
|
46
|
+
"esbuild": "^0.25.0",
|
|
47
|
+
"escodegen": "^1.9.0",
|
|
48
|
+
"hash-sum": "^2.0.0",
|
|
49
|
+
"he": "^1.2.0",
|
|
50
|
+
"js-beautify": "^1.15.4",
|
|
51
|
+
"less": "^4.4.2",
|
|
52
|
+
"oxc-parser": "^0.160.0",
|
|
53
|
+
"vite": "^8.4.0",
|
|
54
|
+
"vue-template-es2015-compiler": "^1.9.1"
|
|
55
|
+
},
|
|
56
|
+
"devDependencies": {
|
|
57
|
+
"@biomejs/biome": "^2.6.10",
|
|
58
|
+
"@types/node": "^24.0.0",
|
|
59
|
+
"typescript": "^7.0.2"
|
|
60
|
+
},
|
|
61
|
+
"license": "MIT",
|
|
62
|
+
"author": "catchword contributors"
|
|
63
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# Falcon 小程序模板
|
|
2
|
+
|
|
3
|
+
```bash
|
|
4
|
+
bun install
|
|
5
|
+
bun run dev # 浏览器预览
|
|
6
|
+
bun run build # 构建到 .falcon_
|
|
7
|
+
bun run build:prod # 压缩 + qjsc + .amr
|
|
8
|
+
bun run adb # 真机安装并启动
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## 目录
|
|
12
|
+
|
|
13
|
+
- `src/pages/**`:页面,在 `src/app.json` 的 `pages` 中登记。
|
|
14
|
+
- `src/components/`:组件。
|
|
15
|
+
- `src/services/`:原生能力适配层,页面不直接调用 `$jsapi`。
|
|
16
|
+
- `src/mocks/`:浏览器预览使用的 `$jsapi` 替身。
|
|
17
|
+
- `src/assets/`:会被构建处理的图片、样式等资源。
|
|
18
|
+
- `assets/`:运行期按路径引用的音视频和大图,原样进入产物。
|
|
19
|
+
- `native/`:可选的 C++ JSAPI 工程,用 `catchword native init` 添加。
|
|
20
|
+
- `libs/`:编译好的原生库,作为 `.amr` 的输入。
|
|
21
|
+
|
|
22
|
+
## 约定
|
|
23
|
+
|
|
24
|
+
- 页面可以直接是 `.vue`,也可以写 `.js` 继承 `$falcon.Page`。
|
|
25
|
+
- 运行时是设备固件提供的 Vue 2.6;不要使用 `<script setup>`。
|
|
26
|
+
- `defineComponent` 可以用于类型提示,构建期会退化为恒等函数。
|
|
27
|
+
- 资源引用:`import logo from '../../assets/logo.png'`,需要 base64 时加 `?base64`。
|
|
28
|
+
- 原生模块的解析和错误处理放在 `src/services/`,与 `src/mocks/` 保持同一入口。
|
|
29
|
+
|
|
30
|
+
## 原生能力
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
catchword native init # 向已有工程加入 native/
|
|
34
|
+
bun run native # 抽取契约、生成类型、编译并校验 .so
|
|
35
|
+
bun run native:check # CI 中检查契约和类型是否漂移
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
构建 `native/` 需要交叉工具链和 SDK 头文件,具体见 `native/README.md`。
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { CatchwordUserConfig } from 'catchword'
|
|
2
|
+
|
|
3
|
+
const config: CatchwordUserConfig = {
|
|
4
|
+
preview: {
|
|
5
|
+
mockDir: 'src/mocks'
|
|
6
|
+
},
|
|
7
|
+
native: {
|
|
8
|
+
dir: 'native',
|
|
9
|
+
targets: {
|
|
10
|
+
x7: {
|
|
11
|
+
buildDir: 'native/build/x7',
|
|
12
|
+
out: 'libs/libjsapi_bridge_x7.so'
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export default config
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
cmake_minimum_required(VERSION 3.20)
|
|
2
|
+
project(falcon_jsapi LANGUAGES C CXX)
|
|
3
|
+
|
|
4
|
+
set(CMAKE_CXX_STANDARD 17)
|
|
5
|
+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
6
|
+
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
|
7
|
+
|
|
8
|
+
if(NOT DEFINED LOLI_SDK_ROOT)
|
|
9
|
+
set(LOLI_SDK_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/sdk")
|
|
10
|
+
endif()
|
|
11
|
+
|
|
12
|
+
if(NOT EXISTS "${LOLI_SDK_ROOT}/include")
|
|
13
|
+
message(FATAL_ERROR "Native SDK headers not found: ${LOLI_SDK_ROOT}/include")
|
|
14
|
+
endif()
|
|
15
|
+
|
|
16
|
+
file(GLOB_RECURSE FALCON_JSAPI_SOURCES CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp")
|
|
17
|
+
|
|
18
|
+
add_library(jsapi_bridge SHARED ${FALCON_JSAPI_SOURCES})
|
|
19
|
+
target_include_directories(jsapi_bridge PRIVATE
|
|
20
|
+
"${LOLI_SDK_ROOT}/include"
|
|
21
|
+
"${CMAKE_CURRENT_SOURCE_DIR}/include"
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
if(DEFINED LOLI_DEPS_ROOT AND EXISTS "${LOLI_DEPS_ROOT}")
|
|
25
|
+
target_link_directories(jsapi_bridge PRIVATE "${LOLI_DEPS_ROOT}")
|
|
26
|
+
endif()
|
|
27
|
+
|
|
28
|
+
if(EXISTS "${LOLI_DEPS_ROOT}/libquickjs.so")
|
|
29
|
+
target_link_libraries(jsapi_bridge PRIVATE quickjs)
|
|
30
|
+
endif()
|
|
31
|
+
|
|
32
|
+
target_compile_options(jsapi_bridge PRIVATE -fvisibility=hidden -fno-exceptions -fno-rtti)
|
|
33
|
+
target_link_options(jsapi_bridge PRIVATE -Wl,-soname,libjsapi_bridge.so)
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# Native JSAPI
|
|
2
|
+
|
|
3
|
+
这个目录只在需要扩展原生能力时使用。纯 JS 工程可以删除它。
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
bun run native
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
上面的命令会依次执行契约抽取、类型生成、交叉编译和 ELF 校验。
|
|
10
|
+
|
|
11
|
+
## 目录
|
|
12
|
+
|
|
13
|
+
- `src/bridge.cpp`:模块注册表,`kModules` 是唯一入口。
|
|
14
|
+
- `src/jsapi_<name>.cpp`:模块实现。
|
|
15
|
+
- `include/`:模块头文件。
|
|
16
|
+
- `sdk/include/`:设备 SDK 头文件。
|
|
17
|
+
- `lib/`:设备上对应库的副本,交叉编译时作为链接输入。
|
|
18
|
+
- `api.json`:由源码生成的契约,提交到仓库。
|
|
19
|
+
- `api.d.ts`:由 `api.json` 生成的类型,提交到仓库。
|
|
20
|
+
- `api.override.json`:唯一允许手写的契约补充。
|
|
21
|
+
|
|
22
|
+
## 约定
|
|
23
|
+
|
|
24
|
+
- 模块名在三处保持一致:`kModules`、`import '$jsapi/<Name>'`、`src/mocks/$jsapi.<Name>.js`。
|
|
25
|
+
- 原生模块只返回 JSON 字符串,解析和错误归一放在 `src/services/`。
|
|
26
|
+
- 发布前执行 `catchword native verify -t <target>`;CI 中加 `--strict`。
|
|
27
|
+
- 额外运行库依赖在 `catchword.config.ts` 的 `allowedNeeded` 中声明。
|
|
28
|
+
- 不使用的模块从 `kModules` 移除,再重新生成契约。
|
|
29
|
+
|
|
30
|
+
## 构建前提
|
|
31
|
+
|
|
32
|
+
- 交叉工具链路径放在 `scripts/build.env`,该文件不提交。
|
|
33
|
+
- `sdk/include` 与 `lib` 需要按目标设备准备。
|
|
34
|
+
- 编译参数已经关闭异常和 RTTI,避免额外运行库依赖。
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <jsmodules/JSCModuleExtension.h>
|
|
4
|
+
#include <quickjs/quickjs.h>
|
|
5
|
+
|
|
6
|
+
class DemoBridge {
|
|
7
|
+
public:
|
|
8
|
+
static JSValue CreateClass(JQUTIL_NS::JQModuleEnv *env);
|
|
9
|
+
static JSValue Ping(JSContext *ctx, JSValueConst thisVal, int argc, JSValueConst *argv);
|
|
10
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
#include "jsapi_demo.h"
|
|
2
|
+
|
|
3
|
+
JSValue DemoBridge::CreateClass(JQUTIL_NS::JQModuleEnv *env) {
|
|
4
|
+
auto tpl = JQUTIL_NS::JQFunctionTemplate::New(env, "Demo");
|
|
5
|
+
tpl->SetProtoMethod("ping", &DemoBridge::Ping);
|
|
6
|
+
return tpl->CallConstructor();
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
JSValue DemoBridge::Ping(JSContext *ctx, JSValueConst, int, JSValueConst *) {
|
|
10
|
+
return JS_NewString(ctx, "pong");
|
|
11
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "hello_catchword",
|
|
3
|
+
"appid": "8000000000000000",
|
|
4
|
+
"version": "1.0.0",
|
|
5
|
+
"description": "hello catchword",
|
|
6
|
+
"quickjs": {
|
|
7
|
+
"version": "20200705",
|
|
8
|
+
"bigNum": false
|
|
9
|
+
},
|
|
10
|
+
"simulator": {
|
|
11
|
+
"path": "",
|
|
12
|
+
"page": ""
|
|
13
|
+
},
|
|
14
|
+
"single-js-bundle": false,
|
|
15
|
+
"scripts": {
|
|
16
|
+
"dev": "catchword dev",
|
|
17
|
+
"start": "catchword dev",
|
|
18
|
+
"build": "catchword build",
|
|
19
|
+
"build:bin": "catchword build -q",
|
|
20
|
+
"build:prod": "catchword build -c -q -p",
|
|
21
|
+
"adb": "catchword adb",
|
|
22
|
+
"upload": "catchword upload -n",
|
|
23
|
+
"typecheck": "tsc --noEmit",
|
|
24
|
+
"clean": "catchword clean"
|
|
25
|
+
},
|
|
26
|
+
"keywords": [
|
|
27
|
+
"iot",
|
|
28
|
+
"miniapp",
|
|
29
|
+
"falcon"
|
|
30
|
+
],
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"falcon-ui": "^2.0.2"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"catchword": "^2.0.0",
|
|
36
|
+
"typescript": "^7.0.0"
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { BasePage } from './base-page.js'
|
|
2
|
+
class App extends $falcon.App {
|
|
3
|
+
constructor() {
|
|
4
|
+
super()
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
onLaunch(options) {
|
|
8
|
+
super.onLaunch(options)
|
|
9
|
+
|
|
10
|
+
$falcon.useDefaultBasePageClass(BasePage)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
onShow() {
|
|
14
|
+
super.onShow()
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
onHide() {
|
|
18
|
+
super.onHide()
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
onDestroy() {
|
|
22
|
+
super.onDestroy()
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
try {
|
|
27
|
+
globalThis['window'] = {
|
|
28
|
+
requestAnimationFrame,
|
|
29
|
+
cancelAnimationFrame
|
|
30
|
+
}
|
|
31
|
+
} catch (err) {
|
|
32
|
+
console.log(err)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
try {
|
|
36
|
+
globalThis['process'] = {
|
|
37
|
+
env: {
|
|
38
|
+
NODE_ENV: 'production'
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
} catch (err) {
|
|
42
|
+
console.log(err)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export default App
|