|
| 1 | +# TinyEngine vue-generator — Package Instructions |
| 2 | + |
| 3 | +## Scope |
| 4 | + |
| 5 | +This file applies to `packages/vue-generator/**`. |
| 6 | + |
| 7 | +- These rules extend the repo-wide rules in the root `AGENTS.md`. |
| 8 | +- Keep package-specific generator details here instead of growing the root file. |
| 9 | + |
| 10 | +## Package Goal |
| 11 | + |
| 12 | +`@opentiny/tiny-engine-dsl-vue` converts TinyEngine DSL schema JSON plus components map JSON into Vue single-file components. |
| 13 | + |
| 14 | +This package is responsible for code generation output. Runtime behavior, designer-side execution, and app-level integration fixes should stay in their owning packages unless the generated SFC output is wrong. |
| 15 | + |
| 16 | +## Key Paths |
| 17 | + |
| 18 | +- `src/generator/vue/sfc/genSetupSFC.js` |
| 19 | +- `src/generator/vue/sfc/generateAttribute.js` |
| 20 | +- `src/generator/vue/sfc/generateTemplate.js` |
| 21 | +- `src/generator/vue/sfc/generateScript.js` |
| 22 | +- `src/generator/vue/sfc/generateStyle.js` |
| 23 | +- `src/utils/formatCode.js` |
| 24 | +- `test/testcases/sfc/` |
| 25 | +- `test/testcases/element-plus-case/` |
| 26 | +- `test/testcases/generator/` |
| 27 | + |
| 28 | +## Architecture Rules |
| 29 | + |
| 30 | +### Core pipeline |
| 31 | + |
| 32 | +1. Input: schema JSON plus components map JSON |
| 33 | +2. `CodeGenerator` hook pipeline: `transformStart` -> `transform` -> `transformEnd` |
| 34 | +3. `genSetupSFC` orchestrates template, attribute, script, and style generation |
| 35 | +4. Output: a complete `.vue` SFC |
| 36 | + |
| 37 | +### Default attribute hook order |
| 38 | + |
| 39 | +The default hook chain registered in `genSetupSFC.js` executes in this order: |
| 40 | + |
| 41 | +1. `handleSlotParams` |
| 42 | +2. `handleJsxModelValueUpdate` |
| 43 | +3. `handleConditionAttrHook` |
| 44 | +4. `handleLoopAttrHook` |
| 45 | +5. `handleSlotBindAttrHook` |
| 46 | +6. `handleAttrKeyHook` |
| 47 | +7. `handlePrimitiveAttributeHook` |
| 48 | +8. `handleExpressionAttrHook` |
| 49 | +9. `handleJSFunctionAttrHook` |
| 50 | +10. `handleI18nAttrHook` |
| 51 | +11. `handleTinyIconPropsHook` |
| 52 | +12. `handleObjBindAttrHook` |
| 53 | +13. `handleEventAttrHook` |
| 54 | + |
| 55 | +`handleBindUtilsHooks` still exists in `generateAttribute.js`, but it is not part of the default hook chain. |
| 56 | + |
| 57 | +Do not reorder or change the default hook chain without approval. |
| 58 | + |
| 59 | +### Global hooks |
| 60 | + |
| 61 | +`genSetupSFC.js` exposes shared `globalHooks` helpers: |
| 62 | + |
| 63 | +- `addState(key, value)` |
| 64 | +- `addImport(fromPath, config)` |
| 65 | +- `addMethods(key, value)` |
| 66 | +- `addStatement(statement)` |
| 67 | +- `setScriptConfig(config)` |
| 68 | + |
| 69 | +These helpers mutate shared script-generation state. When debugging generated `<script>` output, imports, methods, or script config, inspect `genSetupSFC.js` and the downstream script generation path before adding new hooks. |
| 70 | + |
| 71 | +### Quote-handling rules |
| 72 | + |
| 73 | +- Primitive string attributes containing `"` may be emitted as `"` or as a `v-bind` string literal, depending on whether the content also contains `'`. |
| 74 | +- JSX slot mode is a separate path; do not assume primitive attribute escaping rules apply there unchanged. |
| 75 | +- Quote behavior is sensitive to Prettier reformatting. Validate final formatted output, not only intermediate strings. |
| 76 | +- When debugging quote output, inspect `generateAttribute.js` first and verify the formatted `.vue` result rather than raw intermediate strings. |
| 77 | + |
| 78 | +## Fixture and Snapshot Workflow |
| 79 | + |
| 80 | +- SFC cases live under `test/testcases/sfc/<caseName>/`. |
| 81 | +- Follow the nearest existing fixture style. Valid schema names include `schema.json`, `page.schema.json`, `block.schema.json`, and `blocks.schema.json`. |
| 82 | +- Components maps may be `components-map.json` or `componentsMap.json`. |
| 83 | +- Expected outputs live in `expected/*.vue` and are compared with `toMatchFileSnapshot()` after `formatCode(res, 'vue')`. |
| 84 | +- Test entry files typically follow `test/testcases/sfc/<caseName>/<caseName>.test.js`. |
| 85 | + |
| 86 | +When generator output intentionally changes: |
| 87 | + |
| 88 | +1. Update or add the smallest focused testcase that exposes the behavior. |
| 89 | +2. Keep new fixtures minimal and isolate a single behavior whenever possible. |
| 90 | +3. Regenerate or inspect the formatted output for that testcase. |
| 91 | +4. Update only the affected `expected/*.vue` files. |
| 92 | +5. Rerun the targeted testcase and then the full `test:unit` suite. |
| 93 | + |
| 94 | +Do not bulk-rename fixture files just to normalize naming. |
| 95 | + |
| 96 | +## Verification |
| 97 | + |
| 98 | +Use the narrowest command that proves the change, then broaden as needed. |
| 99 | + |
| 100 | +- Single testcase: |
| 101 | + `pnpm --filter @opentiny/tiny-engine-dsl-vue test:unit -- --run test/testcases/sfc/<case>/<case>.test.js` |
| 102 | +- Full unit suite: |
| 103 | + `pnpm --filter @opentiny/tiny-engine-dsl-vue test:unit` |
| 104 | +- Full coverage harness: |
| 105 | + `pnpm --filter @opentiny/tiny-engine-dsl-vue test` |
| 106 | +- Build plus integration-style check: |
| 107 | + `pnpm --filter @opentiny/tiny-engine-dsl-vue test:latest` |
| 108 | + |
| 109 | +Run the full `test:unit` suite before handoff if a change touches shared attribute generation, hook registration, script/style/template generation, or output formatting. |
| 110 | + |
| 111 | +Use `test` or `test:latest` when the change affects broad generator behavior, package build output, or integration between generation and package build steps. |
| 112 | + |
| 113 | +## Ask First |
| 114 | + |
| 115 | +- Changing the default hook chain in `genSetupSFC.js` |
| 116 | +- Editing `src/constant/index.js` |
| 117 | +- Changing package build tooling or package scripts |
| 118 | +- Changing shared quote-generation behavior across multiple attribute paths |
| 119 | +- Changing quote-generation behavior before adding a focused testcase that proves the intended output |
| 120 | + |
| 121 | +## Never |
| 122 | + |
| 123 | +- Update `expected/*.vue` without validating the formatted generator output first |
| 124 | +- Bypass `formatCode(res, 'vue')` when comparing expected SFC output |
| 125 | +- Assume one fixture naming convention is canonical across the whole package |
| 126 | +- Treat a snapshot diff by itself as proof that generated behavior is correct |
0 commit comments