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.
Files changed (157) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +314 -2
  3. package/bin/catchword.js +8 -0
  4. package/bin/falcon.js +5 -0
  5. package/dist/cli/adb.d.ts +6 -0
  6. package/dist/cli/adb.js +52 -0
  7. package/dist/cli/audit.d.ts +4 -0
  8. package/dist/cli/audit.js +91 -0
  9. package/dist/cli/build.d.ts +13 -0
  10. package/dist/cli/build.js +139 -0
  11. package/dist/cli/clean.d.ts +1 -0
  12. package/dist/cli/clean.js +15 -0
  13. package/dist/cli/create.d.ts +4 -0
  14. package/dist/cli/create.js +60 -0
  15. package/dist/cli/dev.d.ts +10 -0
  16. package/dist/cli/dev.js +23 -0
  17. package/dist/cli/index.d.ts +3 -0
  18. package/dist/cli/index.js +243 -0
  19. package/dist/cli/native.d.ts +18 -0
  20. package/dist/cli/native.js +232 -0
  21. package/dist/cli/simulator.d.ts +8 -0
  22. package/dist/cli/simulator.js +77 -0
  23. package/dist/cli/upload.d.ts +9 -0
  24. package/dist/cli/upload.js +135 -0
  25. package/dist/cli/util.d.ts +8 -0
  26. package/dist/cli/util.js +43 -0
  27. package/dist/config.d.ts +17 -0
  28. package/dist/config.js +90 -0
  29. package/dist/index.d.ts +16 -0
  30. package/dist/index.js +51 -0
  31. package/dist/native/api.d.ts +46 -0
  32. package/dist/native/api.js +185 -0
  33. package/dist/native/build.d.ts +47 -0
  34. package/dist/native/build.js +407 -0
  35. package/dist/native/elf.d.ts +15 -0
  36. package/dist/native/elf.js +200 -0
  37. package/dist/native/types.d.ts +9 -0
  38. package/dist/native/types.js +91 -0
  39. package/dist/native/wsl.d.ts +7 -0
  40. package/dist/native/wsl.js +29 -0
  41. package/dist/plugin/app-entry.d.ts +6 -0
  42. package/dist/plugin/app-entry.js +115 -0
  43. package/dist/plugin/assets.d.ts +4 -0
  44. package/dist/plugin/assets.js +84 -0
  45. package/dist/plugin/config.d.ts +14 -0
  46. package/dist/plugin/config.js +80 -0
  47. package/dist/plugin/context.d.ts +58 -0
  48. package/dist/plugin/context.js +255 -0
  49. package/dist/plugin/fallback.d.ts +4 -0
  50. package/dist/plugin/fallback.js +81 -0
  51. package/dist/plugin/image-service.d.ts +17 -0
  52. package/dist/plugin/image-service.js +138 -0
  53. package/dist/plugin/jsapi.d.ts +6 -0
  54. package/dist/plugin/jsapi.js +82 -0
  55. package/dist/plugin/output.d.ts +4 -0
  56. package/dist/plugin/output.js +75 -0
  57. package/dist/plugin/preview.d.ts +34 -0
  58. package/dist/plugin/preview.js +459 -0
  59. package/dist/plugin/sanitize.d.ts +5 -0
  60. package/dist/plugin/sanitize.js +48 -0
  61. package/dist/plugin/security.d.ts +4 -0
  62. package/dist/plugin/security.js +18 -0
  63. package/dist/plugin/sfc.d.ts +6 -0
  64. package/dist/plugin/sfc.js +181 -0
  65. package/dist/plugin/shim.d.ts +4 -0
  66. package/dist/plugin/shim.js +68 -0
  67. package/dist/plugin/state.d.ts +31 -0
  68. package/dist/plugin/state.js +61 -0
  69. package/dist/plugin/string-table.d.ts +7 -0
  70. package/dist/plugin/string-table.js +324 -0
  71. package/dist/plugin/style.d.ts +15 -0
  72. package/dist/plugin/style.js +114 -0
  73. package/dist/plugin/template.d.ts +7 -0
  74. package/dist/plugin/template.js +39 -0
  75. package/dist/steps/manifest.d.ts +9 -0
  76. package/dist/steps/manifest.js +60 -0
  77. package/dist/steps/pack.d.ts +3 -0
  78. package/dist/steps/pack.js +46 -0
  79. package/dist/steps/qjsc.d.ts +9 -0
  80. package/dist/steps/qjsc.js +186 -0
  81. package/dist/steps/report.d.ts +2 -0
  82. package/dist/steps/report.js +50 -0
  83. package/dist/steps/security.d.ts +17 -0
  84. package/dist/steps/security.js +310 -0
  85. package/dist/types.d.ts +158 -0
  86. package/dist/types.js +1 -0
  87. package/dist/util/class-tokenize.d.ts +2 -0
  88. package/dist/util/class-tokenize.js +56 -0
  89. package/dist/util/component-name.d.ts +6 -0
  90. package/dist/util/component-name.js +120 -0
  91. package/dist/util/fs.d.ts +14 -0
  92. package/dist/util/fs.js +70 -0
  93. package/dist/util/imports.d.ts +2 -0
  94. package/dist/util/imports.js +173 -0
  95. package/dist/util/log.d.ts +8 -0
  96. package/dist/util/log.js +24 -0
  97. package/package.json +61 -4
  98. package/template/README.md +38 -0
  99. package/template/catchword.config.ts +18 -0
  100. package/template/native/CMakeLists.txt +33 -0
  101. package/template/native/README.md +34 -0
  102. package/template/native/api.override.json +7 -0
  103. package/template/native/include/jsapi_demo.h +10 -0
  104. package/template/native/lib/README.md +10 -0
  105. package/template/native/sdk/README.md +6 -0
  106. package/template/native/src/bridge.cpp +9 -0
  107. package/template/native/src/jsapi_demo.cpp +11 -0
  108. package/template/package.json +38 -0
  109. package/template/src/app.js +45 -0
  110. package/template/src/app.json +11 -0
  111. package/template/src/base-page.js +150 -0
  112. package/template/src/components/HelloWorld.vue +20 -0
  113. package/template/src/mocks/$jsapi.test.js +5 -0
  114. package/template/src/mocks/test-module.js +5 -0
  115. package/template/src/pages/index/index.vue +41 -0
  116. package/template/src/pages/page/page.vue +63 -0
  117. package/template/src/shims.d.ts +21 -0
  118. package/template/src/styles/base.less +23 -0
  119. package/template/src/styles/mixin.less +32 -0
  120. package/template/src/styles/var.less +15 -0
  121. package/template/tsconfig.json +14 -0
  122. package/vendor/README.md +16 -0
  123. package/vendor/falcon-styler/.jscsrc +31 -0
  124. package/vendor/falcon-styler/LICENSE +21 -0
  125. package/vendor/falcon-styler/README.md +124 -0
  126. package/vendor/falcon-styler/index.js +273 -0
  127. package/vendor/falcon-styler/lib/shorthand-parser.js +78 -0
  128. package/vendor/falcon-styler/lib/util.js +30 -0
  129. package/vendor/falcon-styler/lib/validator.js +846 -0
  130. package/vendor/falcon-styler/package.json +32 -0
  131. package/vendor/licenses/falcon-styler.LICENSE +21 -0
  132. package/vendor/licenses/weex-template-compiler.README.md +3 -0
  133. package/vendor/package.json +5 -0
  134. package/vendor/qjsc/SHA256SUMS +11 -0
  135. package/vendor/qjsc/bin/darwin/arm64/qjsc20200705 +0 -0
  136. package/vendor/qjsc/bin/darwin/x64/qjsc20200412 +0 -0
  137. package/vendor/qjsc/bin/darwin/x64/qjsc20200705 +0 -0
  138. package/vendor/qjsc/bin/darwin/x64/qjsc20200906 +0 -0
  139. package/vendor/qjsc/bin/darwin/x64/qjscbn20200412 +0 -0
  140. package/vendor/qjsc/bin/darwin/x64/qjscbn20200705 +0 -0
  141. package/vendor/qjsc/bin/darwin/x64/qjscbn20200906 +0 -0
  142. package/vendor/qjsc/bin/linux/qjsc20200705 +0 -0
  143. package/vendor/qjsc/bin/win32/libgcc_s_dw2-1.dll +0 -0
  144. package/vendor/qjsc/bin/win32/pthreadGC-3.dll +0 -0
  145. package/vendor/qjsc/bin/win32/qjsc20200705.exe +0 -0
  146. package/vendor/web/falcon-js-web.js +863 -0
  147. package/vendor/web/falcon-jsapi-web.js +479 -0
  148. package/vendor/web/falcon-vue-render.js +11323 -0
  149. package/vendor/web/falcon-web-boot.js +4 -0
  150. package/vendor/web/falcon-web-hud.js +119 -0
  151. package/vendor/web/falcon-web-style.js +235 -0
  152. package/vendor/web/vue.runtime.common.dev.js +8467 -0
  153. package/vendor/web/vue.runtime.common.js +5 -0
  154. package/vendor/weex-template-compiler/README.md +3 -0
  155. package/vendor/weex-template-compiler/build.js +4824 -0
  156. package/vendor/weex-template-compiler/index.js +17 -0
  157. package/vendor/weex-template-compiler/package.json +25 -0
@@ -0,0 +1,91 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ export function readOverrides(file) {
4
+ if (!fs.existsSync(file))
5
+ return {};
6
+ try {
7
+ return JSON.parse(fs.readFileSync(file, 'utf8'));
8
+ }
9
+ catch (error) {
10
+ throw new Error(`[catchword] 无法解析 ${path.basename(file)}: ${error.message}`);
11
+ }
12
+ }
13
+ function methodSignature(module, methodName, overrides) {
14
+ const custom = overrides.methods?.[module.name]?.[methodName];
15
+ if (custom)
16
+ return custom;
17
+ const method = module.methods.find((m) => m.name === methodName);
18
+ const returns = method?.async ? 'Promise<unknown>' : 'unknown';
19
+ return `${methodName}(...args: unknown[]): ${returns}`;
20
+ }
21
+ function moduleInterface(module, overrides, registered) {
22
+ const lines = [];
23
+ const isRegistered = registered.has(module.name);
24
+ if (!isRegistered && registered.size > 0) {
25
+ lines.push(`/** 注意:未在 kModules 注册,运行时取不到 */`);
26
+ }
27
+ lines.push(`export interface ${module.name}Module extends NativeBridgeModule {`);
28
+ for (const method of module.methods) {
29
+ const notes = [];
30
+ if (method.arity !== undefined)
31
+ notes.push(`arity=${method.arity}`);
32
+ if (method.style === 'raw')
33
+ notes.push('raw');
34
+ if (notes.length)
35
+ lines.push(` /** ${notes.join(' ')} */`);
36
+ lines.push(` ${methodSignature(module, method.name, overrides)}`);
37
+ }
38
+ for (const extra of overrides.types?.[module.name] ?? []) {
39
+ lines.push(` ${extra}`);
40
+ }
41
+ lines.push('}');
42
+ return lines.join('\n');
43
+ }
44
+ export function generateTypes(api, overrides = {}) {
45
+ const registered = new Set(api.registry.map((entry) => entry.name));
46
+ const guardOf = new Map(api.registry.map((entry) => [entry.name, entry.guard]));
47
+ const total = api.modules.reduce((n, m) => n + m.methods.length, 0);
48
+ const out = [];
49
+ out.push('// 由 catchword 生成,请勿手改。');
50
+ out.push(`// 来源: ${api.sources.join(', ')}(${api.modules.length} 个模块 / ${total} 个方法)`);
51
+ out.push('// 修改返回类型请编辑 api.override.json,然后重新运行 catchword native types。');
52
+ out.push('');
53
+ out.push('interface NativeBridgeModule {');
54
+ out.push(' readonly available?: boolean');
55
+ out.push('}');
56
+ out.push('');
57
+ for (const module of api.modules) {
58
+ const guard = guardOf.get(module.name);
59
+ if (guard)
60
+ out.push(`/** 仅 ${guard} 时编译进产物 */`);
61
+ out.push(moduleInterface(module, overrides, registered));
62
+ out.push('');
63
+ }
64
+ out.push('export interface FalconBridge {');
65
+ for (const module of api.modules) {
66
+ out.push(` ${module.name}: ${module.name}Module`);
67
+ }
68
+ out.push(' [name: string]: NativeBridgeModule | undefined');
69
+ out.push('}');
70
+ out.push('');
71
+ out.push(`declare module 'bridge' {`);
72
+ out.push(' const bridge: FalconBridge');
73
+ out.push(' export default bridge');
74
+ out.push('}');
75
+ out.push('');
76
+ for (const module of api.modules) {
77
+ out.push(`declare module '$jsapi/${module.name}' {`);
78
+ out.push(` const api: ${module.name}Module`);
79
+ out.push(' export default api');
80
+ out.push('}');
81
+ out.push('');
82
+ }
83
+ for (const extra of overrides.globals ?? []) {
84
+ out.push(extra);
85
+ }
86
+ return out.join('\n').replace(/\n+$/, '\n');
87
+ }
88
+ export function writeTypesFile(file, content) {
89
+ fs.mkdirSync(path.dirname(file), { recursive: true });
90
+ fs.writeFileSync(file, content, 'utf8');
91
+ }
@@ -0,0 +1,7 @@
1
+ export interface WslLocation {
2
+ distro: string;
3
+ root: string;
4
+ }
5
+ export declare function detectWsl(toolchainRoot: string | null): WslLocation | null;
6
+ export declare function toWslPath(value: string, distro: string): string;
7
+ export declare function shellQuote(value: string): string;
@@ -0,0 +1,29 @@
1
+ const BS = String.fromCharCode(92);
2
+ export function detectWsl(toolchainRoot) {
3
+ if (!toolchainRoot)
4
+ return null;
5
+ const parts = toolchainRoot.split(BS).filter((part) => part.length > 0);
6
+ if (parts.length < 3)
7
+ return null;
8
+ if (parts[0] !== 'wsl.localhost' && parts[0] !== 'wsl$')
9
+ return null;
10
+ return { distro: parts[1], root: parts.slice(2).join('/') };
11
+ }
12
+ export function toWslPath(value, distro) {
13
+ const text = String(value ?? '');
14
+ if (!text)
15
+ return text;
16
+ void distro;
17
+ const wsl = detectWsl(text);
18
+ if (wsl)
19
+ return '/' + wsl.root;
20
+ if (text.length > 2 && text[1] === ':' && (text[2] === BS || text[2] === '/')) {
21
+ const drive = text.charAt(0).toLowerCase();
22
+ const rest = text.slice(3).split(BS).join('/');
23
+ return '/mnt/' + drive + '/' + rest;
24
+ }
25
+ return text.split(BS).join('/');
26
+ }
27
+ export function shellQuote(value) {
28
+ return "'" + String(value).split("'").join("'\\''") + "'";
29
+ }
@@ -0,0 +1,6 @@
1
+ import type { Plugin } from 'vite';
2
+ import type { AppContext } from './context.js';
3
+ export declare const APP_VIRTUAL_ID = "virtual:falcon-app";
4
+ declare function cleanUrl(id: string): string;
5
+ export declare function appEntryPlugin(ctx: AppContext): Plugin;
6
+ export { cleanUrl };
@@ -0,0 +1,115 @@
1
+ import fs from 'node:fs';
2
+ import { transform as esbuildTransform } from 'esbuild';
3
+ export const APP_VIRTUAL_ID = 'virtual:falcon-app';
4
+ const APP_RESOLVED_ID = '\0falcon-app';
5
+ const APP_ORIGIN_QUERY = 'falcon-app-origin';
6
+ function cleanUrl(id) {
7
+ const idx = id.indexOf('?');
8
+ return idx === -1 ? id : id.slice(0, idx);
9
+ }
10
+ function camelCaseIdentifier(name) {
11
+ const cleaned = name.replace(/[^a-zA-Z0-9_$]/g, '_');
12
+ return '_' + cleaned.replace(/^_+/, '');
13
+ }
14
+ function generatePagesImports(ctx) {
15
+ const eager = ctx.singleBundle || ctx.isDev;
16
+ if (!eager)
17
+ return '';
18
+ const lines = [];
19
+ const assigns = ['App.__pages = {};'];
20
+ for (const [page, rel] of Object.entries(ctx.appJson.pages)) {
21
+ const abs = ctx.resolveSource(rel);
22
+ const ident = camelCaseIdentifier(page);
23
+ lines.push(`import ${ident} from ${JSON.stringify(abs)};`);
24
+ assigns.push(`App.__pages[${JSON.stringify(page)}] = ${ident};`);
25
+ }
26
+ return lines.join('\n') + '\n' + assigns.join('\n');
27
+ }
28
+ function keyMap(record) {
29
+ if (!record)
30
+ return undefined;
31
+ return Object.fromEntries(Object.keys(record).map((key) => [key, key]));
32
+ }
33
+ function runtimeMeta(ctx) {
34
+ if (ctx.toolOptions.keepMetaPaths === true)
35
+ return ctx.appJson;
36
+ const meta = JSON.parse(JSON.stringify(ctx.appJson));
37
+ meta.pages = keyMap(meta.pages) ?? {};
38
+ if (meta.services)
39
+ meta.services = keyMap(meta.services);
40
+ if (meta.providers)
41
+ meta.providers = keyMap(meta.providers);
42
+ if (meta.options && typeof meta.options === 'object') {
43
+ const options = { ...meta.options };
44
+ delete options.alias;
45
+ delete options.style;
46
+ if (Object.keys(options).length === 0)
47
+ delete meta.options;
48
+ else
49
+ meta.options = options;
50
+ }
51
+ return meta;
52
+ }
53
+ function generateAppModule(ctx) {
54
+ const meta = runtimeMeta(ctx);
55
+ const pages = generatePagesImports(ctx);
56
+ return `
57
+ import "virtual:falcon-shim";
58
+ import App from ${JSON.stringify(`${ctx.appEntry}?${APP_ORIGIN_QUERY}`)};
59
+
60
+ App.meta = ${JSON.stringify(meta, null, 2)};
61
+ App.meta.name = ${JSON.stringify(ctx.pkg.name ?? ctx.appName)};
62
+ App.meta.version = ${JSON.stringify(ctx.pkg.version ?? '0.0.0')};
63
+ App.meta.isSingleJsBundle = ${ctx.singleBundle ? 'true' : 'false'};
64
+
65
+ $falcon.__AppClazz = App;
66
+ $falcon.__loadModuleDefault = async function (fileName) {
67
+ if (App.__pages && App.__pages[fileName]) {
68
+ return App.__pages[fileName];
69
+ } else {
70
+ try {
71
+ const pagePath = './' + fileName + '.js';
72
+ const mod = await import(pagePath);
73
+ return mod.default;
74
+ } catch (e) {
75
+ console.log(e.message, e.stack);
76
+ }
77
+ }
78
+ };
79
+ ${pages}
80
+ export default App;
81
+ `;
82
+ }
83
+ export function appEntryPlugin(ctx) {
84
+ return {
85
+ name: 'falcon:app-entry',
86
+ enforce: 'pre',
87
+ resolveId(id) {
88
+ if (id === APP_VIRTUAL_ID || id === APP_RESOLVED_ID)
89
+ return APP_RESOLVED_ID;
90
+ if (id.includes(`?${APP_ORIGIN_QUERY}`))
91
+ return { id };
92
+ return null;
93
+ },
94
+ async load(id) {
95
+ if (id === APP_RESOLVED_ID)
96
+ return generateAppModule(ctx);
97
+ if (id.includes(`?${APP_ORIGIN_QUERY}`)) {
98
+ const file = cleanUrl(id);
99
+ const code = fs.readFileSync(file, 'utf8');
100
+ if (/\.tsx?$/.test(file)) {
101
+ const result = await esbuildTransform(code, {
102
+ loader: 'ts',
103
+ target: 'es2020',
104
+ format: 'esm',
105
+ sourcefile: file
106
+ });
107
+ return result.code;
108
+ }
109
+ return code;
110
+ }
111
+ return null;
112
+ }
113
+ };
114
+ }
115
+ export { cleanUrl };
@@ -0,0 +1,4 @@
1
+ import type { Plugin } from 'vite';
2
+ import type { AppContext } from './context.js';
3
+ export declare function imagePlugin(ctx: AppContext): Plugin;
4
+ export declare function mediaPlugin(ctx: AppContext): Plugin;
@@ -0,0 +1,84 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { getImageInfo, imageExtension, processImage } from './image-service.js';
4
+ import { ensureDir, md5File } from '../util/fs.js';
5
+ const IMAGE_PREFIX = '\0falcon-image:';
6
+ const MEDIA_PREFIX = '\0falcon-media:';
7
+ const MEDIA_EXTENSIONS = new Set([
8
+ '.mp4',
9
+ '.mkv',
10
+ '.mov',
11
+ '.avi',
12
+ '.wmv',
13
+ '.flv',
14
+ '.f4v',
15
+ '.hlv',
16
+ '.webm'
17
+ ]);
18
+ function resolveAssetId(id, importer, ctx) {
19
+ if (id.startsWith('\0'))
20
+ return null;
21
+ if (id.includes('?falcon-'))
22
+ return null;
23
+ if (/^https?:\/\//.test(id))
24
+ return null;
25
+ const qIndex = id.indexOf('?');
26
+ const filePart = qIndex === -1 ? id : id.slice(0, qIndex);
27
+ const query = qIndex === -1 ? '' : id.slice(qIndex);
28
+ if (path.isAbsolute(filePart))
29
+ return filePart + query;
30
+ if (filePart.startsWith('.')) {
31
+ return path.resolve(path.dirname(importer ?? ctx.srcDir), filePart) + query;
32
+ }
33
+ return null;
34
+ }
35
+ export function imagePlugin(ctx) {
36
+ return {
37
+ name: 'falcon:image',
38
+ enforce: 'pre',
39
+ resolveId(id, importer) {
40
+ const abs = resolveAssetId(id, importer, ctx);
41
+ if (!abs)
42
+ return null;
43
+ if (!getImageInfo(ctx, abs))
44
+ return null;
45
+ return IMAGE_PREFIX + abs;
46
+ },
47
+ async load(id) {
48
+ if (!id.startsWith(IMAGE_PREFIX))
49
+ return null;
50
+ const raw = id.slice(IMAGE_PREFIX.length);
51
+ const url = await processImage(ctx, raw);
52
+ return `export default ${JSON.stringify(url ?? raw)};`;
53
+ }
54
+ };
55
+ }
56
+ export function mediaPlugin(ctx) {
57
+ return {
58
+ name: 'falcon:media',
59
+ enforce: 'pre',
60
+ resolveId(id, importer) {
61
+ const abs = resolveAssetId(id, importer, ctx);
62
+ if (!abs)
63
+ return null;
64
+ if (!MEDIA_EXTENSIONS.has(imageExtension(abs)))
65
+ return null;
66
+ return MEDIA_PREFIX + abs;
67
+ },
68
+ load(id) {
69
+ if (!id.startsWith(MEDIA_PREFIX))
70
+ return null;
71
+ const file = id.slice(MEDIA_PREFIX.length);
72
+ const assetsDir = path.join(ctx.buildDir, 'assets');
73
+ ensureDir(assetsDir);
74
+ const ext = path.extname(file);
75
+ const base = path.basename(file, ext).replace(/[^\w-]/g, '_');
76
+ const name = `${base}-${md5File(file).slice(0, 8)}${ext}`;
77
+ const target = path.join(assetsDir, name);
78
+ if (!fs.existsSync(target))
79
+ fs.copyFileSync(file, target);
80
+ ctx.pendingAssets.set(target, file);
81
+ return `export default ${JSON.stringify(`assets/${name}`)};`;
82
+ }
83
+ };
84
+ }
@@ -0,0 +1,14 @@
1
+ import type { Plugin } from 'vite';
2
+ import type { AppContext } from './context.js';
3
+ import type { FalconOptions } from '../types.js';
4
+ export declare const PACKAGE_ROOT: string;
5
+ export declare const VENDOR_DIR: string;
6
+ export declare function devRuntimePaths(ctx: AppContext): {
7
+ dir: string;
8
+ vue: string;
9
+ weex: string;
10
+ previewEntry: string;
11
+ previewAppEntry: string;
12
+ pageEntry: (page: string) => string;
13
+ };
14
+ export declare function configPlugin(ctx: AppContext, options: FalconOptions): Plugin;
@@ -0,0 +1,80 @@
1
+ import path from 'node:path';
2
+ import { fileURLToPath } from 'node:url';
3
+ const here = path.dirname(fileURLToPath(import.meta.url));
4
+ export const PACKAGE_ROOT = path.resolve(here, '../..');
5
+ export const VENDOR_DIR = path.join(PACKAGE_ROOT, 'vendor');
6
+ export function devRuntimePaths(ctx) {
7
+ const dir = path.join(ctx.tmpDir, 'web');
8
+ return {
9
+ dir,
10
+ vue: path.join(dir, 'vue.mjs'),
11
+ weex: path.join(dir, 'falcon-vue-render.mjs'),
12
+ previewEntry: path.join(dir, 'preview-entry.mjs'),
13
+ previewAppEntry: path.join(dir, 'preview-app.mjs'),
14
+ pageEntry: (page) => path.join(dir, `preview-page-${page.replace(/[^\w-]/g, '_')}.mjs`)
15
+ };
16
+ }
17
+ export function configPlugin(ctx, options) {
18
+ return {
19
+ name: 'falcon:config',
20
+ enforce: 'pre',
21
+ config(_userConfig, env) {
22
+ const isDev = env.command === 'serve';
23
+ ctx.isDev = isDev;
24
+ const alias = ctx.aliasEntries();
25
+ if (isDev) {
26
+ const paths = devRuntimePaths(ctx);
27
+ alias.unshift({ find: 'vue', replacement: paths.vue });
28
+ alias.unshift({ find: 'falcon-vue-render', replacement: paths.weex });
29
+ }
30
+ const config = {
31
+ root: ctx.root,
32
+ appType: 'custom',
33
+ publicDir: false,
34
+ base: '',
35
+ resolve: { alias },
36
+ define: ctx.getDefines(isDev),
37
+ clearScreen: false,
38
+ server: isDev
39
+ ? {
40
+ host: '127.0.0.1',
41
+ fs: {
42
+ allow: [ctx.root, ctx.tmpDir, VENDOR_DIR, ctx.buildDir]
43
+ },
44
+ watch: {
45
+ ignored: ['**/node_modules/**', '**/.falcon_**', '**/.falcon_tmp/**']
46
+ }
47
+ }
48
+ : undefined,
49
+ optimizeDeps: isDev ? { exclude: ['vue', 'falcon-vue-render'] } : undefined
50
+ };
51
+ if (!isDev) {
52
+ config.build = {
53
+ target: 'es2020',
54
+ outDir: ctx.buildDir,
55
+ emptyOutDir: true,
56
+ copyPublicDir: false,
57
+ minify: options.minify ? 'oxc' : false,
58
+ modulePreload: false,
59
+ cssCodeSplit: false,
60
+ sourcemap: false,
61
+ assetsInlineLimit: 0,
62
+ reportCompressedSize: false,
63
+ chunkSizeWarningLimit: 4096,
64
+ rolldownOptions: {
65
+ input: ctx.inputs,
66
+ external: ['vue', 'falcon-vue-render'],
67
+ preserveEntrySignatures: 'strict',
68
+ output: {
69
+ format: 'es',
70
+ entryFileNames: '[name].js',
71
+ chunkFileNames: 'chunk-[name]-[hash].js',
72
+ assetFileNames: 'assets/[name][extname]'
73
+ }
74
+ }
75
+ };
76
+ }
77
+ return config;
78
+ }
79
+ };
80
+ }
@@ -0,0 +1,58 @@
1
+ import type { AppMeta, AppPackageJson, AppToolOptions, FalconOptions, FalconUserConfig, QjscOptions, StyleOptions } from '../types.js';
2
+ export declare const BUILD_DIR = ".falcon_";
3
+ export declare const TMP_DIR = ".falcon_tmp";
4
+ export declare const SOURCE_DIR = "src";
5
+ export declare const APP_JSON = "app.json";
6
+ export declare const AMR_EXCLUDE_DOT_FILES = true;
7
+ export interface ThemeSource {
8
+ FALCON_THEME: string;
9
+ FALCON_THEME_CUSTOM: string;
10
+ themePath: string | null;
11
+ themeCustomPath: string | null;
12
+ }
13
+ export declare class AppContext {
14
+ readonly options: FalconOptions;
15
+ readonly config: FalconUserConfig;
16
+ readonly root: string;
17
+ readonly srcDir: string;
18
+ readonly pkg: AppPackageJson;
19
+ readonly appJson: AppMeta;
20
+ readonly buildDir: string;
21
+ readonly tmpDir: string;
22
+ readonly appEntry: string;
23
+ readonly singleBundle: boolean;
24
+ readonly pageFiles: Set<string>;
25
+ readonly hasDynamicClassBindings: boolean;
26
+ isDev: boolean;
27
+ cliBuild: boolean;
28
+ pendingAssets: Map<string, string>;
29
+ private _inputs;
30
+ private _scopeIdCache;
31
+ constructor(root: string, options: FalconOptions);
32
+ get styleOptions(): StyleOptions;
33
+ get runtime(): "vue2";
34
+ get appid(): string;
35
+ get toolOptions(): AppToolOptions;
36
+ get appName(): string;
37
+ get amrFileName(): string;
38
+ get amrPath(): string;
39
+ get quickjsOptions(): Required<Pick<QjscOptions, 'version' | 'bigNum'>> & QjscOptions;
40
+ get inputs(): Record<string, string>;
41
+ resolveSource(rel: string): string;
42
+ private detectDynamicClassBindings;
43
+ pathToRootUnix(file: string): string;
44
+ scopeIdFor(file: string): string;
45
+ aliasEntries(): Array<{
46
+ find: string;
47
+ replacement: string;
48
+ }>;
49
+ getLessPaths(): string[];
50
+ getLessModifyVars(): Record<string, string>;
51
+ getThemes(): string[];
52
+ getThemeSource(): ThemeSource;
53
+ get mockDir(): string;
54
+ get mockDirLabel(): string;
55
+ getMockApis(): Record<string, string>;
56
+ getDefines(isDev: boolean): Record<string, string>;
57
+ }
58
+ export declare function createContext(options: FalconOptions): AppContext;