@pie-element/cli 0.1.1

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 (255) hide show
  1. package/.compatibility/report.json +2491 -0
  2. package/.turbo/turbo-build.log +1 -0
  3. package/CHANGELOG.md +8 -0
  4. package/README.md +240 -0
  5. package/REFACTORING.md +131 -0
  6. package/bin/dev.js +5 -0
  7. package/bin/run.js +5 -0
  8. package/dist/commands/dev/demo/index.d.ts +33 -0
  9. package/dist/commands/dev/demo/index.d.ts.map +1 -0
  10. package/dist/commands/dev/demo/index.js +274 -0
  11. package/dist/commands/dev/demo/index.js.map +1 -0
  12. package/dist/commands/dev/test-bundler.d.ts +18 -0
  13. package/dist/commands/dev/test-bundler.d.ts.map +1 -0
  14. package/dist/commands/dev/test-bundler.js +284 -0
  15. package/dist/commands/dev/test-bundler.js.map +1 -0
  16. package/dist/commands/mathquill/migrate.d.ts +20 -0
  17. package/dist/commands/mathquill/migrate.d.ts.map +1 -0
  18. package/dist/commands/mathquill/migrate.js +240 -0
  19. package/dist/commands/mathquill/migrate.js.map +1 -0
  20. package/dist/commands/mathquill/status.d.ts +20 -0
  21. package/dist/commands/mathquill/status.d.ts.map +1 -0
  22. package/dist/commands/mathquill/status.js +231 -0
  23. package/dist/commands/mathquill/status.js.map +1 -0
  24. package/dist/commands/packages/create-controllers.d.ts +13 -0
  25. package/dist/commands/packages/create-controllers.d.ts.map +1 -0
  26. package/dist/commands/packages/create-controllers.js +103 -0
  27. package/dist/commands/packages/create-controllers.js.map +1 -0
  28. package/dist/commands/packages/create-lib-react.d.ts +17 -0
  29. package/dist/commands/packages/create-lib-react.d.ts.map +1 -0
  30. package/dist/commands/packages/create-lib-react.js +228 -0
  31. package/dist/commands/packages/create-lib-react.js.map +1 -0
  32. package/dist/commands/packages/create-react-elements.d.ts +16 -0
  33. package/dist/commands/packages/create-react-elements.d.ts.map +1 -0
  34. package/dist/commands/packages/create-react-elements.js +259 -0
  35. package/dist/commands/packages/create-react-elements.js.map +1 -0
  36. package/dist/commands/packages/enable-publishing.d.ts +11 -0
  37. package/dist/commands/packages/enable-publishing.d.ts.map +1 -0
  38. package/dist/commands/packages/enable-publishing.js +117 -0
  39. package/dist/commands/packages/enable-publishing.js.map +1 -0
  40. package/dist/commands/packages/init-synced-elements.d.ts +16 -0
  41. package/dist/commands/packages/init-synced-elements.d.ts.map +1 -0
  42. package/dist/commands/packages/init-synced-elements.js +204 -0
  43. package/dist/commands/packages/init-synced-elements.js.map +1 -0
  44. package/dist/commands/upstream/analyze-esm.d.ts +59 -0
  45. package/dist/commands/upstream/analyze-esm.d.ts.map +1 -0
  46. package/dist/commands/upstream/analyze-esm.js +1481 -0
  47. package/dist/commands/upstream/analyze-esm.js.map +1 -0
  48. package/dist/commands/upstream/check.d.ts +15 -0
  49. package/dist/commands/upstream/check.d.ts.map +1 -0
  50. package/dist/commands/upstream/check.js +165 -0
  51. package/dist/commands/upstream/check.js.map +1 -0
  52. package/dist/commands/upstream/deps.d.ts +15 -0
  53. package/dist/commands/upstream/deps.d.ts.map +1 -0
  54. package/dist/commands/upstream/deps.js +174 -0
  55. package/dist/commands/upstream/deps.js.map +1 -0
  56. package/dist/commands/upstream/sync-mathquill.d.ts +12 -0
  57. package/dist/commands/upstream/sync-mathquill.d.ts.map +1 -0
  58. package/dist/commands/upstream/sync-mathquill.js +97 -0
  59. package/dist/commands/upstream/sync-mathquill.js.map +1 -0
  60. package/dist/commands/upstream/sync.d.ts +25 -0
  61. package/dist/commands/upstream/sync.d.ts.map +1 -0
  62. package/dist/commands/upstream/sync.js +552 -0
  63. package/dist/commands/upstream/sync.js.map +1 -0
  64. package/dist/commands/upstream/track.d.ts +15 -0
  65. package/dist/commands/upstream/track.d.ts.map +1 -0
  66. package/dist/commands/upstream/track.js +115 -0
  67. package/dist/commands/upstream/track.js.map +1 -0
  68. package/dist/commands/upstream/update.d.ts +15 -0
  69. package/dist/commands/upstream/update.d.ts.map +1 -0
  70. package/dist/commands/upstream/update.js +98 -0
  71. package/dist/commands/upstream/update.js.map +1 -0
  72. package/dist/commands/verify/controllers.d.ts +12 -0
  73. package/dist/commands/verify/controllers.d.ts.map +1 -0
  74. package/dist/commands/verify/controllers.js +138 -0
  75. package/dist/commands/verify/controllers.js.map +1 -0
  76. package/dist/commands/verify/react-build.d.ts +13 -0
  77. package/dist/commands/verify/react-build.d.ts.map +1 -0
  78. package/dist/commands/verify/react-build.js +135 -0
  79. package/dist/commands/verify/react-build.js.map +1 -0
  80. package/dist/index.d.ts +2 -0
  81. package/dist/index.d.ts.map +1 -0
  82. package/dist/index.js +2 -0
  83. package/dist/index.js.map +1 -0
  84. package/dist/lib/mathquill/extension-generator.d.ts +9 -0
  85. package/dist/lib/mathquill/extension-generator.d.ts.map +1 -0
  86. package/dist/lib/mathquill/extension-generator.js +107 -0
  87. package/dist/lib/mathquill/extension-generator.js.map +1 -0
  88. package/dist/lib/mathquill/khan-extractor.d.ts +16 -0
  89. package/dist/lib/mathquill/khan-extractor.d.ts.map +1 -0
  90. package/dist/lib/mathquill/khan-extractor.js +148 -0
  91. package/dist/lib/mathquill/khan-extractor.js.map +1 -0
  92. package/dist/lib/mathquill/learnosity-extractor.d.ts +15 -0
  93. package/dist/lib/mathquill/learnosity-extractor.d.ts.map +1 -0
  94. package/dist/lib/mathquill/learnosity-extractor.js +170 -0
  95. package/dist/lib/mathquill/learnosity-extractor.js.map +1 -0
  96. package/dist/lib/mathquill/migration-orchestrator.d.ts +77 -0
  97. package/dist/lib/mathquill/migration-orchestrator.d.ts.map +1 -0
  98. package/dist/lib/mathquill/migration-orchestrator.js +391 -0
  99. package/dist/lib/mathquill/migration-orchestrator.js.map +1 -0
  100. package/dist/lib/mathquill/package-updater.d.ts +9 -0
  101. package/dist/lib/mathquill/package-updater.d.ts.map +1 -0
  102. package/dist/lib/mathquill/package-updater.js +103 -0
  103. package/dist/lib/mathquill/package-updater.js.map +1 -0
  104. package/dist/lib/mathquill/pie-extractor.d.ts +14 -0
  105. package/dist/lib/mathquill/pie-extractor.d.ts.map +1 -0
  106. package/dist/lib/mathquill/pie-extractor.js +167 -0
  107. package/dist/lib/mathquill/pie-extractor.js.map +1 -0
  108. package/dist/lib/upstream/repo-utils.d.ts +9 -0
  109. package/dist/lib/upstream/repo-utils.d.ts.map +1 -0
  110. package/dist/lib/upstream/repo-utils.js +10 -0
  111. package/dist/lib/upstream/repo-utils.js.map +1 -0
  112. package/dist/lib/upstream/sync-compatibility.d.ts +29 -0
  113. package/dist/lib/upstream/sync-compatibility.d.ts.map +1 -0
  114. package/dist/lib/upstream/sync-compatibility.js +70 -0
  115. package/dist/lib/upstream/sync-compatibility.js.map +1 -0
  116. package/dist/lib/upstream/sync-constants.d.ts +50 -0
  117. package/dist/lib/upstream/sync-constants.d.ts.map +1 -0
  118. package/dist/lib/upstream/sync-constants.js +66 -0
  119. package/dist/lib/upstream/sync-constants.js.map +1 -0
  120. package/dist/lib/upstream/sync-controllers-strategy.d.ts +18 -0
  121. package/dist/lib/upstream/sync-controllers-strategy.d.ts.map +1 -0
  122. package/dist/lib/upstream/sync-controllers-strategy.js +243 -0
  123. package/dist/lib/upstream/sync-controllers-strategy.js.map +1 -0
  124. package/dist/lib/upstream/sync-demo-metadata.d.ts +15 -0
  125. package/dist/lib/upstream/sync-demo-metadata.d.ts.map +1 -0
  126. package/dist/lib/upstream/sync-demo-metadata.js +165 -0
  127. package/dist/lib/upstream/sync-demo-metadata.js.map +1 -0
  128. package/dist/lib/upstream/sync-dev-exports.d.ts +13 -0
  129. package/dist/lib/upstream/sync-dev-exports.d.ts.map +1 -0
  130. package/dist/lib/upstream/sync-dev-exports.js +115 -0
  131. package/dist/lib/upstream/sync-dev-exports.js.map +1 -0
  132. package/dist/lib/upstream/sync-externals.d.ts +29 -0
  133. package/dist/lib/upstream/sync-externals.d.ts.map +1 -0
  134. package/dist/lib/upstream/sync-externals.js +164 -0
  135. package/dist/lib/upstream/sync-externals.js.map +1 -0
  136. package/dist/lib/upstream/sync-filesystem.d.ts +21 -0
  137. package/dist/lib/upstream/sync-filesystem.d.ts.map +1 -0
  138. package/dist/lib/upstream/sync-filesystem.js +64 -0
  139. package/dist/lib/upstream/sync-filesystem.js.map +1 -0
  140. package/dist/lib/upstream/sync-imports.d.ts +284 -0
  141. package/dist/lib/upstream/sync-imports.d.ts.map +1 -0
  142. package/dist/lib/upstream/sync-imports.js +816 -0
  143. package/dist/lib/upstream/sync-imports.js.map +1 -0
  144. package/dist/lib/upstream/sync-mathquill.d.ts +19 -0
  145. package/dist/lib/upstream/sync-mathquill.d.ts.map +1 -0
  146. package/dist/lib/upstream/sync-mathquill.js +160 -0
  147. package/dist/lib/upstream/sync-mathquill.js.map +1 -0
  148. package/dist/lib/upstream/sync-package-json.d.ts +28 -0
  149. package/dist/lib/upstream/sync-package-json.d.ts.map +1 -0
  150. package/dist/lib/upstream/sync-package-json.js +66 -0
  151. package/dist/lib/upstream/sync-package-json.js.map +1 -0
  152. package/dist/lib/upstream/sync-package-manager.d.ts +50 -0
  153. package/dist/lib/upstream/sync-package-manager.d.ts.map +1 -0
  154. package/dist/lib/upstream/sync-package-manager.js +570 -0
  155. package/dist/lib/upstream/sync-package-manager.js.map +1 -0
  156. package/dist/lib/upstream/sync-pielib-strategy.d.ts +26 -0
  157. package/dist/lib/upstream/sync-pielib-strategy.d.ts.map +1 -0
  158. package/dist/lib/upstream/sync-pielib-strategy.js +345 -0
  159. package/dist/lib/upstream/sync-pielib-strategy.js.map +1 -0
  160. package/dist/lib/upstream/sync-react-strategy.d.ts +54 -0
  161. package/dist/lib/upstream/sync-react-strategy.d.ts.map +1 -0
  162. package/dist/lib/upstream/sync-react-strategy.js +733 -0
  163. package/dist/lib/upstream/sync-react-strategy.js.map +1 -0
  164. package/dist/lib/upstream/sync-strategy.d.ts +49 -0
  165. package/dist/lib/upstream/sync-strategy.d.ts.map +1 -0
  166. package/dist/lib/upstream/sync-strategy.js +2 -0
  167. package/dist/lib/upstream/sync-strategy.js.map +1 -0
  168. package/dist/lib/upstream/sync-summary.d.ts +20 -0
  169. package/dist/lib/upstream/sync-summary.d.ts.map +1 -0
  170. package/dist/lib/upstream/sync-summary.js +157 -0
  171. package/dist/lib/upstream/sync-summary.js.map +1 -0
  172. package/dist/lib/upstream/sync-transforms.d.ts +60 -0
  173. package/dist/lib/upstream/sync-transforms.d.ts.map +1 -0
  174. package/dist/lib/upstream/sync-transforms.js +97 -0
  175. package/dist/lib/upstream/sync-transforms.js.map +1 -0
  176. package/dist/lib/upstream/sync-vite-config.d.ts +13 -0
  177. package/dist/lib/upstream/sync-vite-config.d.ts.map +1 -0
  178. package/dist/lib/upstream/sync-vite-config.js +231 -0
  179. package/dist/lib/upstream/sync-vite-config.js.map +1 -0
  180. package/dist/utils/compatibility.d.ts +129 -0
  181. package/dist/utils/compatibility.d.ts.map +1 -0
  182. package/dist/utils/compatibility.js +44 -0
  183. package/dist/utils/compatibility.js.map +1 -0
  184. package/dist/utils/conversion.d.ts +25 -0
  185. package/dist/utils/conversion.d.ts.map +1 -0
  186. package/dist/utils/conversion.js +123 -0
  187. package/dist/utils/conversion.js.map +1 -0
  188. package/dist/utils/git.d.ts +7 -0
  189. package/dist/utils/git.d.ts.map +1 -0
  190. package/dist/utils/git.js +63 -0
  191. package/dist/utils/git.js.map +1 -0
  192. package/dist/utils/logger.d.ts +29 -0
  193. package/dist/utils/logger.d.ts.map +1 -0
  194. package/dist/utils/logger.js +63 -0
  195. package/dist/utils/logger.js.map +1 -0
  196. package/dist/utils/package-json.d.ts +12 -0
  197. package/dist/utils/package-json.d.ts.map +1 -0
  198. package/dist/utils/package-json.js +29 -0
  199. package/dist/utils/package-json.js.map +1 -0
  200. package/package.json +59 -0
  201. package/packages/cli/bin/dev.js +5 -0
  202. package/packages/cli/bin/run.js +5 -0
  203. package/src/commands/dev/demo/index.ts +313 -0
  204. package/src/commands/dev/test-bundler.ts +345 -0
  205. package/src/commands/mathquill/migrate.ts +269 -0
  206. package/src/commands/mathquill/status.ts +267 -0
  207. package/src/commands/packages/create-controllers.ts +127 -0
  208. package/src/commands/packages/create-lib-react.ts +279 -0
  209. package/src/commands/packages/create-react-elements.ts +306 -0
  210. package/src/commands/packages/enable-publishing.ts +161 -0
  211. package/src/commands/packages/init-synced-elements.ts +259 -0
  212. package/src/commands/upstream/README.md +444 -0
  213. package/src/commands/upstream/analyze-esm.ts +1973 -0
  214. package/src/commands/upstream/check.ts +228 -0
  215. package/src/commands/upstream/deps.ts +222 -0
  216. package/src/commands/upstream/sync-mathquill.ts +108 -0
  217. package/src/commands/upstream/sync.ts +687 -0
  218. package/src/commands/upstream/track.ts +145 -0
  219. package/src/commands/upstream/update.ts +110 -0
  220. package/src/commands/verify/controllers.ts +166 -0
  221. package/src/commands/verify/react-build.ts +171 -0
  222. package/src/index.ts +1 -0
  223. package/src/lib/mathquill/extension-generator.ts +111 -0
  224. package/src/lib/mathquill/khan-extractor.ts +175 -0
  225. package/src/lib/mathquill/learnosity-extractor.ts +198 -0
  226. package/src/lib/mathquill/migration-orchestrator.ts +513 -0
  227. package/src/lib/mathquill/package-updater.ts +120 -0
  228. package/src/lib/mathquill/pie-extractor.ts +194 -0
  229. package/src/lib/upstream/repo-utils.ts +18 -0
  230. package/src/lib/upstream/sync-compatibility.ts +89 -0
  231. package/src/lib/upstream/sync-constants.ts +77 -0
  232. package/src/lib/upstream/sync-controllers-strategy.ts +291 -0
  233. package/src/lib/upstream/sync-demo-metadata.ts +199 -0
  234. package/src/lib/upstream/sync-dev-exports.ts +151 -0
  235. package/src/lib/upstream/sync-externals.ts +159 -0
  236. package/src/lib/upstream/sync-filesystem.ts +87 -0
  237. package/src/lib/upstream/sync-imports.ts +992 -0
  238. package/src/lib/upstream/sync-mathquill.ts +194 -0
  239. package/src/lib/upstream/sync-package-json.ts +86 -0
  240. package/src/lib/upstream/sync-package-manager.ts +694 -0
  241. package/src/lib/upstream/sync-pielib-strategy.ts +441 -0
  242. package/src/lib/upstream/sync-react-strategy.ts +945 -0
  243. package/src/lib/upstream/sync-strategy.ts +61 -0
  244. package/src/lib/upstream/sync-summary.ts +194 -0
  245. package/src/lib/upstream/sync-transforms.ts +154 -0
  246. package/src/lib/upstream/sync-vite-config.ts +243 -0
  247. package/src/types/es-module-lexer.d.ts +4 -0
  248. package/src/utils/compatibility.ts +182 -0
  249. package/src/utils/conversion.ts +153 -0
  250. package/src/utils/git.ts +63 -0
  251. package/src/utils/logger.ts +69 -0
  252. package/src/utils/package-json.ts +43 -0
  253. package/tests/sync-package-manager.test.ts +112 -0
  254. package/tests/transform-assign-props.test.ts +101 -0
  255. package/tsconfig.json +15 -0
@@ -0,0 +1,733 @@
1
+ /**
2
+ * React components sync strategy - syncs React components from upstream pie-elements
3
+ *
4
+ * Synced from: pie-elements/packages/{element}/src/
5
+ * Target: packages/elements-react/{element}/src/
6
+ */
7
+ import { existsSync } from 'node:fs';
8
+ import { mkdir, readFile, stat as fsStat, writeFile, rm as fsRm } from 'node:fs/promises';
9
+ import { dirname, join } from 'node:path';
10
+ import { convertJsToTs, convertJsxToTsx } from '../../utils/conversion.js';
11
+ import { getCurrentCommit } from '../../utils/git.js';
12
+ import { cleanDirectory, existsAny, readdir } from './sync-filesystem.js';
13
+ import { createExternalFunction, createKonvaExternalFunction } from './sync-externals.js';
14
+ import { fixImportsInFile, containsJsx } from './sync-imports.js';
15
+ import { createReactComponentTransformPipeline } from './sync-transforms.js';
16
+ import { ensureElementPackageJson } from './sync-package-manager.js';
17
+ import { isSubdirectoryCompatible } from './sync-compatibility.js';
18
+ import { EXCLUDED_UPSTREAM_ELEMENTS } from './sync-constants.js';
19
+ export class ReactComponentsStrategy {
20
+ touchedElementPackages = new Set();
21
+ result = {
22
+ filesChecked: 0,
23
+ filesCopied: 0,
24
+ filesSkipped: 0,
25
+ filesUpdated: 0,
26
+ };
27
+ getName() {
28
+ return 'react-components';
29
+ }
30
+ getDescription() {
31
+ return 'React components';
32
+ }
33
+ shouldRun(config) {
34
+ return config.syncReactComponents;
35
+ }
36
+ async execute(context) {
37
+ const { config, logger } = context;
38
+ this.touchedElementPackages.clear();
39
+ this.result = {
40
+ filesChecked: 0,
41
+ filesCopied: 0,
42
+ filesSkipped: 0,
43
+ filesUpdated: 0,
44
+ };
45
+ if (!logger.isVerbose()) {
46
+ logger.progressStart('Syncing React components...');
47
+ }
48
+ else {
49
+ logger.section('⚛️ Syncing React components');
50
+ }
51
+ const upstreamElementsDir = join(config.pieElements, 'packages');
52
+ const targetBaseDir = join(config.pieElementsNg, 'packages/elements-react');
53
+ const upstreamCommit = getCurrentCommit(config.pieElements);
54
+ const packages = await readdir(upstreamElementsDir);
55
+ for (const pkg of packages) {
56
+ if (EXCLUDED_UPSTREAM_ELEMENTS.includes(pkg)) {
57
+ continue;
58
+ }
59
+ if (context.packageFilter && pkg !== context.packageFilter) {
60
+ continue;
61
+ }
62
+ // Check if element is in compatibility report (ESM-compatible)
63
+ if (context.compatibilityReport) {
64
+ if (!context.compatibilityReport.elements.includes(pkg)) {
65
+ continue; // Skip non-compatible elements
66
+ }
67
+ // Check if student UI (src/) is ESM-compatible
68
+ if (!isSubdirectoryCompatible(pkg, 'src', context)) {
69
+ if (logger.isVerbose()) {
70
+ logger.info(` ⏭️ ${pkg}: skipping src/ (not ESM-compatible)`);
71
+ }
72
+ continue;
73
+ }
74
+ }
75
+ // Check if React component exists upstream (src/ directory)
76
+ const componentSrcDir = join(upstreamElementsDir, pkg, 'src');
77
+ if (!existsSync(componentSrcDir)) {
78
+ continue;
79
+ }
80
+ // Target: packages/elements-react/{element}/src/
81
+ const targetDir = join(targetBaseDir, pkg);
82
+ const targetSrcDir = join(targetDir, 'src');
83
+ // Clean target src subtree first so removed upstream files don't linger
84
+ // BUT: preserve controller/ subdirectory if it exists (synced separately)
85
+ await this.cleanTargetDirExcept(targetSrcDir, ['controller'], `elements-react/${pkg}/src`, logger);
86
+ // Recursively sync all files from src/ directory to delivery/ subdirectory
87
+ const beforeChanges = this.result.filesCopied + this.result.filesUpdated;
88
+ const targetDeliveryDir = join(targetDir, 'src/delivery');
89
+ let elementFilesProcessed = await this.syncDirectory(componentSrcDir, targetDeliveryDir, 'src', pkg, upstreamCommit);
90
+ // Also sync configure/ if it exists and is ESM-compatible
91
+ // Note: Renamed to author/ in the target directory
92
+ const configureDir = join(upstreamElementsDir, pkg, 'configure');
93
+ if (existsSync(configureDir)) {
94
+ // Check if configure subdirectory is ESM-compatible
95
+ const configureCompatible = isSubdirectoryCompatible(pkg, 'configure', context);
96
+ if (configureCompatible) {
97
+ // First, sync configure/src/ -> src/author/
98
+ const configureSrcDir = join(configureDir, 'src');
99
+ if (existsSync(configureSrcDir)) {
100
+ const targetAuthorDir = join(targetDir, 'src/author');
101
+ const configureFilesProcessed = await this.syncDirectory(configureSrcDir, targetAuthorDir, 'configure/src', pkg, upstreamCommit);
102
+ elementFilesProcessed += configureFilesProcessed;
103
+ }
104
+ // Then, sync configure/*.js files (not in subdirectories) -> src/author/
105
+ // These are utility files that live directly in configure/ like utils.js
106
+ const targetAuthorDir = join(targetDir, 'src/author');
107
+ const configureRootFilesProcessed = await this.syncConfigureRootFiles(configureDir, targetAuthorDir, pkg, upstreamCommit);
108
+ elementFilesProcessed += configureRootFilesProcessed;
109
+ }
110
+ else if (logger.isVerbose()) {
111
+ logger.info(` ⏭️ ${pkg}: skipping configure/ (not ESM-compatible)`);
112
+ }
113
+ }
114
+ // Sync print file if it exists (src/print.js -> src/print/index.ts)
115
+ const upstreamPrintFile = join(componentSrcDir, 'print.js');
116
+ if (existsSync(upstreamPrintFile)) {
117
+ const targetPrintDir = join(targetDir, 'src/print');
118
+ const printFilesProcessed = await this.syncPrintFile(upstreamPrintFile, targetPrintDir, pkg, upstreamCommit);
119
+ elementFilesProcessed += printFilesProcessed;
120
+ }
121
+ // Generate src/index.ts that re-exports from delivery/
122
+ const mainIndexPath = join(targetDir, 'src/index.ts');
123
+ const mainIndexContent = `export { default } from './delivery/index.js';\n`;
124
+ await writeFile(mainIndexPath, mainIndexContent, 'utf-8');
125
+ const afterChanges = this.result.filesCopied + this.result.filesUpdated;
126
+ const elementChanged = afterChanges > beforeChanges;
127
+ if (elementFilesProcessed > 0 && logger.isVerbose()) {
128
+ logger.success(` ✨ ${pkg}: ${elementFilesProcessed} file(s) synced`);
129
+ }
130
+ const elementDir = join(targetBaseDir, pkg);
131
+ // Ensure IIFE files exist before generating package.json scripts.
132
+ // package.json generation derives the build script from presence of iife files.
133
+ await this.ensureIifeEntryPoint(pkg, elementDir, config, logger);
134
+ await this.ensureIifeViteConfig(pkg, elementDir, config, logger);
135
+ // Ensure package.json has ESM module support and expected exports.
136
+ let wrotePkgJson = false;
137
+ wrotePkgJson = await ensureElementPackageJson(pkg, elementDir, config);
138
+ await this.ensureElementViteConfig(pkg, elementDir, logger);
139
+ const wroteTsConfig = await this.ensureTsConfig(pkg, elementDir, logger);
140
+ // Ensure demo structure
141
+ await this.ensureElementDemoStructure(pkg, elementDir, config, logger);
142
+ // Demo configs are maintained locally - we do NOT apply overrides from upstream
143
+ if (elementChanged || wrotePkgJson || wroteTsConfig) {
144
+ this.touchedElementPackages.add(pkg);
145
+ }
146
+ }
147
+ // Demo configs are maintained locally - we do NOT apply overrides to existing elements
148
+ if (!logger.isVerbose()) {
149
+ logger.progressCompleteWithCount(this.touchedElementPackages.size, 'packages');
150
+ }
151
+ else {
152
+ logger.info(`\nSynced ${this.touchedElementPackages.size} React component package(s)`);
153
+ }
154
+ return {
155
+ count: this.touchedElementPackages.size,
156
+ packageNames: Array.from(this.touchedElementPackages).sort(),
157
+ };
158
+ }
159
+ async cleanTargetDirExcept(targetDir, preserveDirs, label, logger) {
160
+ await cleanDirectory(targetDir, label, { dryRun: false, verbose: false, preserve: preserveDirs }, logger);
161
+ }
162
+ async syncDirectory(sourceDir, targetDir, relativePath, pkg, upstreamCommit) {
163
+ let filesProcessed = 0;
164
+ const defaultExportFiles = new Set(); // Track files with default exports
165
+ const items = await readdir(sourceDir);
166
+ for (const item of items) {
167
+ const srcPath = join(sourceDir, item);
168
+ const stat = await fsStat(srcPath);
169
+ if (stat.isDirectory()) {
170
+ // Skip __tests__, __mocks__, etc.
171
+ if (item.startsWith('__')) {
172
+ continue;
173
+ }
174
+ // Recursively sync subdirectories
175
+ const subFilesProcessed = await this.syncDirectory(srcPath, join(targetDir, item), join(relativePath, item), pkg, upstreamCommit);
176
+ filesProcessed += subFilesProcessed;
177
+ continue;
178
+ }
179
+ // Only process .js and .jsx files
180
+ if (!item.endsWith('.js') && !item.endsWith('.jsx')) {
181
+ continue;
182
+ }
183
+ // Skip print.js/print.jsx files - they're synced to src/print/ separately
184
+ if (item === 'print.js' || item === 'print.jsx') {
185
+ continue;
186
+ }
187
+ this.result.filesChecked++;
188
+ filesProcessed++;
189
+ // Read source
190
+ let sourceContent = await readFile(srcPath, 'utf-8');
191
+ // Apply all standard transformations
192
+ const packageName = `@pie-element/${pkg}`;
193
+ const transformPipeline = createReactComponentTransformPipeline(packageName);
194
+ sourceContent = transformPipeline(sourceContent, join(relativePath, item));
195
+ const hasJsx = item.endsWith('.jsx') || (item.endsWith('.js') && containsJsx(sourceContent));
196
+ // Convert .js → .ts/.tsx and .jsx → .tsx
197
+ const targetFile = item.replace(/\.jsx?$/, hasJsx ? '.tsx' : '.ts');
198
+ const targetPath = join(targetDir, targetFile);
199
+ // Convert based on file extension
200
+ const conversionResult = hasJsx
201
+ ? convertJsxToTsx(sourceContent, {
202
+ sourcePath: `pie-elements/packages/${pkg}/${relativePath}/${item}`,
203
+ commit: upstreamCommit,
204
+ })
205
+ : convertJsToTs(sourceContent, {
206
+ sourcePath: `pie-elements/packages/${pkg}/${relativePath}/${item}`,
207
+ commit: upstreamCommit,
208
+ });
209
+ const converted = conversionResult.code;
210
+ // Track files that export default objects (for import fixing later)
211
+ if (conversionResult.hasDefaultObjectExport) {
212
+ // Store the file name without extension for import matching
213
+ const fileNameWithoutExt = targetFile.replace(/\.(ts|tsx)$/, '');
214
+ defaultExportFiles.add(fileNameWithoutExt);
215
+ }
216
+ // Check if different
217
+ // NOTE: This comparison is exact (===) to ensure any changes in:
218
+ // - Upstream source code
219
+ // - Transformation logic (lodash-es, event packages, etc.)
220
+ // - Sync version (tracked in @sync-version header)
221
+ // will trigger a file update. This prioritizes correctness over speed.
222
+ const isNew = !existsSync(targetPath);
223
+ if (!isNew) {
224
+ const currentContent = await readFile(targetPath, 'utf-8');
225
+ if (currentContent === converted) {
226
+ this.result.filesSkipped++;
227
+ continue;
228
+ }
229
+ this.result.filesUpdated++;
230
+ }
231
+ else {
232
+ this.result.filesCopied++;
233
+ }
234
+ // Write
235
+ await mkdir(dirname(targetPath), { recursive: true });
236
+ await writeFile(targetPath, converted, 'utf-8');
237
+ }
238
+ // After all files are synced, fix import statements in consuming files
239
+ if (defaultExportFiles.size > 0) {
240
+ const targetDirItems = await readdir(targetDir);
241
+ for (const item of targetDirItems) {
242
+ const itemPath = join(targetDir, item);
243
+ const stat = await fsStat(itemPath);
244
+ if (stat.isFile() && (item.endsWith('.tsx') || item.endsWith('.ts'))) {
245
+ await fixImportsInFile(itemPath, defaultExportFiles);
246
+ }
247
+ }
248
+ }
249
+ return filesProcessed;
250
+ }
251
+ /**
252
+ * Sync root-level .js files from configure/ directory (not including subdirectories)
253
+ * These are typically utility files like utils.js that are imported by files in configure/src/
254
+ */
255
+ async syncConfigureRootFiles(sourceDir, targetDir, pkg, upstreamCommit) {
256
+ let filesProcessed = 0;
257
+ const items = await readdir(sourceDir);
258
+ for (const item of items) {
259
+ const srcPath = join(sourceDir, item);
260
+ const stat = await fsStat(srcPath);
261
+ // Skip directories - we only want root-level files
262
+ if (stat.isDirectory()) {
263
+ continue;
264
+ }
265
+ // Only process .js and .jsx files
266
+ if (!item.endsWith('.js') && !item.endsWith('.jsx')) {
267
+ continue;
268
+ }
269
+ this.result.filesChecked++;
270
+ filesProcessed++;
271
+ // Read source
272
+ let sourceContent = await readFile(srcPath, 'utf-8');
273
+ // Apply all standard transformations
274
+ const packageName = `@pie-element/${pkg}`;
275
+ const transformPipeline = createReactComponentTransformPipeline(packageName);
276
+ sourceContent = transformPipeline(sourceContent);
277
+ const hasJsx = item.endsWith('.jsx') || (item.endsWith('.js') && containsJsx(sourceContent));
278
+ // Convert .js → .ts/.tsx and .jsx → .tsx
279
+ const targetFile = item.replace(/\.jsx?$/, hasJsx ? '.tsx' : '.ts');
280
+ const targetPath = join(targetDir, targetFile);
281
+ // Convert based on file extension
282
+ const conversionResult = hasJsx
283
+ ? convertJsxToTsx(sourceContent, {
284
+ sourcePath: `pie-elements/packages/${pkg}/configure/${item}`,
285
+ commit: upstreamCommit,
286
+ })
287
+ : convertJsToTs(sourceContent, {
288
+ sourcePath: `pie-elements/packages/${pkg}/configure/${item}`,
289
+ commit: upstreamCommit,
290
+ });
291
+ const converted = conversionResult.code;
292
+ // Check if file already exists (synced from configure/src/)
293
+ const isNew = !existsSync(targetPath);
294
+ if (!isNew) {
295
+ // File exists - this means configure/src/utils.js was already synced
296
+ // We need to merge the exports instead of overwriting
297
+ const existingContent = await readFile(targetPath, 'utf-8');
298
+ // Extract exports from both files and merge them
299
+ const mergedContent = this.mergeUtilsFiles(existingContent, converted);
300
+ if (existingContent === mergedContent) {
301
+ this.result.filesSkipped++;
302
+ continue;
303
+ }
304
+ await writeFile(targetPath, mergedContent, 'utf-8');
305
+ this.result.filesUpdated++;
306
+ }
307
+ else {
308
+ // New file - just write it
309
+ await mkdir(dirname(targetPath), { recursive: true });
310
+ await writeFile(targetPath, converted, 'utf-8');
311
+ this.result.filesCopied++;
312
+ }
313
+ }
314
+ return filesProcessed;
315
+ }
316
+ /**
317
+ * Sync a single print file (src/print.js -> src/print/index.ts)
318
+ */
319
+ async syncPrintFile(sourceFile, targetDir, pkg, upstreamCommit) {
320
+ this.result.filesChecked++;
321
+ // Read source
322
+ let sourceContent = await readFile(sourceFile, 'utf-8');
323
+ // Apply all standard transformations
324
+ const packageName = `@pie-element/${pkg}`;
325
+ const transformPipeline = createReactComponentTransformPipeline(packageName);
326
+ sourceContent = transformPipeline(sourceContent);
327
+ // Transform imports from './' to '../delivery/' since print is now in print/
328
+ // This handles './main', './stimulus-tabs', './choice', etc.
329
+ sourceContent = sourceContent.replace(/from\s+['"]\.\/([^'"]+)['"]/g, "from '../delivery/$1'");
330
+ sourceContent = sourceContent.replace(/import\s*\(\s*['"]\.\/([^'"]+)['"]\s*\)/g, "import('../delivery/$1')");
331
+ const hasJsx = sourceContent.includes('React.createElement') || containsJsx(sourceContent);
332
+ // Convert to TypeScript
333
+ const conversionResult = hasJsx
334
+ ? convertJsxToTsx(sourceContent, {
335
+ sourcePath: `pie-elements/packages/${pkg}/src/print.js`,
336
+ commit: upstreamCommit,
337
+ })
338
+ : convertJsToTs(sourceContent, {
339
+ sourcePath: `pie-elements/packages/${pkg}/src/print.js`,
340
+ commit: upstreamCommit,
341
+ });
342
+ const converted = conversionResult.code;
343
+ const targetFile = hasJsx ? 'index.tsx' : 'index.ts';
344
+ const targetPath = join(targetDir, targetFile);
345
+ // Check if needs update
346
+ const isNew = !existsSync(targetPath);
347
+ if (!isNew) {
348
+ const existingContent = await readFile(targetPath, 'utf-8');
349
+ if (existingContent === converted) {
350
+ this.result.filesSkipped++;
351
+ return 1;
352
+ }
353
+ await writeFile(targetPath, converted, 'utf-8');
354
+ this.result.filesUpdated++;
355
+ }
356
+ else {
357
+ await mkdir(targetDir, { recursive: true });
358
+ await writeFile(targetPath, converted, 'utf-8');
359
+ this.result.filesCopied++;
360
+ }
361
+ return 1;
362
+ }
363
+ /**
364
+ * Merge two utils files by combining their exports
365
+ *
366
+ * When syncing configure/ files, we may have:
367
+ * - configure/src/utils.js (already synced to src/configure/utils.ts)
368
+ * - configure/utils.js (being synced now to src/configure/utils.ts)
369
+ *
370
+ * Both files export different functions, so we need to merge them.
371
+ */
372
+ mergeUtilsFiles(existingContent, newContent) {
373
+ // Extract the header comment from existing file (has sync metadata)
374
+ const headerMatch = existingContent.match(/^\/\/ @ts-nocheck\n\/\*\*[\s\S]*?\*\/\n\n/);
375
+ const existingHeader = headerMatch ? headerMatch[0] : '';
376
+ // Extract exports from existing file (remove header and blank lines)
377
+ const existingExports = existingContent
378
+ .replace(/^\/\/ @ts-nocheck\n\/\*\*[\s\S]*?\*\/\n\n/, '')
379
+ .trim();
380
+ // Extract exports from new file (remove header and blank lines)
381
+ const newExports = newContent.replace(/^\/\/ @ts-nocheck\n\/\*\*[\s\S]*?\*\/\n\n/, '').trim();
382
+ // Combine: use existing header + both sets of exports
383
+ return `${existingHeader}${existingExports}\n\n${newExports}\n`;
384
+ }
385
+ async ensureElementViteConfig(_elementName, elementDir, _logger) {
386
+ if (!existsSync(elementDir)) {
387
+ return;
388
+ }
389
+ const viteConfigPath = join(elementDir, 'vite.config.ts');
390
+ // Always regenerate to reflect current directory structure
391
+ // (e.g., if configure/ was skipped due to ESM incompatibility)
392
+ // Detect entry points
393
+ const entryPoints = {};
394
+ // Helper to find which file extension exists (.ts or .tsx)
395
+ const findEntry = (basePath) => {
396
+ if (existsSync(join(elementDir, `${basePath}.tsx`)))
397
+ return `${basePath}.tsx`;
398
+ if (existsSync(join(elementDir, `${basePath}.ts`)))
399
+ return `${basePath}.ts`;
400
+ return null;
401
+ };
402
+ const indexEntry = findEntry('src/index');
403
+ if (indexEntry) {
404
+ entryPoints.index = indexEntry;
405
+ }
406
+ const controllerEntry = findEntry('src/controller/index');
407
+ if (controllerEntry) {
408
+ entryPoints['controller/index'] = controllerEntry;
409
+ }
410
+ const configureEntry = findEntry('src/configure/index');
411
+ if (configureEntry) {
412
+ entryPoints['configure/index'] = configureEntry;
413
+ }
414
+ const deliveryEntry = findEntry('src/delivery/index');
415
+ if (deliveryEntry) {
416
+ entryPoints['delivery/index'] = deliveryEntry;
417
+ }
418
+ const authorEntry = findEntry('src/author/index');
419
+ if (authorEntry) {
420
+ entryPoints['author/index'] = authorEntry;
421
+ }
422
+ const printEntry = findEntry('src/print/index');
423
+ if (printEntry) {
424
+ entryPoints['print/index'] = printEntry;
425
+ }
426
+ const typesEntry = findEntry('src/types/index');
427
+ if (typesEntry) {
428
+ entryPoints['types/index'] = typesEntry;
429
+ }
430
+ if (Object.keys(entryPoints).length === 0) {
431
+ return; // No entry points, skip vite config
432
+ }
433
+ // Format entry points for vite config
434
+ const entryLines = Object.entries(entryPoints)
435
+ .map(([key, value]) => ` '${key}': resolve(__dirname, '${value}'),`)
436
+ .join('\n');
437
+ // Konva is now external like other dependencies - no special bundling needed
438
+ // This avoids workspace dependency resolution issues
439
+ const shouldBundleKonva = false;
440
+ // Check if demo directory exists
441
+ const hasDemoDir = existsSync(join(elementDir, 'docs/demo'));
442
+ // Generate appropriate config based on element characteristics
443
+ const viteConfig = shouldBundleKonva
444
+ ? this.generateViteConfigWithBundledKonva(entryLines, hasDemoDir)
445
+ : this.generateStandardViteConfig(entryLines, hasDemoDir);
446
+ await writeFile(viteConfigPath, viteConfig, 'utf-8');
447
+ }
448
+ generateStandardViteConfig(entryLines, hasDemoDir) {
449
+ const demoModeConfig = hasDemoDir
450
+ ? `({ mode, command }) => {
451
+ // Demo mode: serve the docs/demo directory
452
+ if (mode === 'demo' && command === 'serve') {
453
+ return {
454
+ plugins: [react()],
455
+ root: resolve(__dirname, 'docs/demo'),
456
+ };
457
+ }
458
+
459
+ // Build mode: build the library
460
+ return {`
461
+ : `{`;
462
+ return `import { resolve } from 'node:path';
463
+ import react from '@vitejs/plugin-react';
464
+ import { defineConfig } from 'vite';
465
+
466
+ export default defineConfig(${demoModeConfig}
467
+ plugins: [react()],
468
+ build: {
469
+ lib: {
470
+ entry: {
471
+ ${entryLines}
472
+ },
473
+ formats: ['es'],
474
+ },
475
+ rollupOptions: {
476
+ external: ${createExternalFunction('element')},
477
+ output: {
478
+ preserveModules: true,
479
+ preserveModulesRoot: 'src',
480
+ },
481
+ },
482
+ },${hasDemoDir ? '\n };' : ''}
483
+ });
484
+ `;
485
+ }
486
+ generateViteConfigWithBundledKonva(entryLines, hasDemoDir) {
487
+ const demoModeConfig = hasDemoDir
488
+ ? `({ mode, command }) => ({
489
+ plugins: [react()],
490
+ // Only change root for demo mode when serving (not building)
491
+ root: mode === 'demo' && command === 'serve' ? resolve(__dirname, 'docs/demo') : __dirname,`
492
+ : `{
493
+ plugins: [react()],`;
494
+ return `import { resolve } from 'node:path';
495
+ import react from '@vitejs/plugin-react';
496
+ import { defineConfig } from 'vite';
497
+
498
+ export default defineConfig(${demoModeConfig}
499
+ build: {
500
+ lib: {
501
+ entry: {
502
+ ${entryLines}
503
+ },
504
+ formats: ['es'],
505
+ },
506
+ rollupOptions: {
507
+ external: ${createKonvaExternalFunction()},
508
+ output: {
509
+ preserveModules: false,
510
+ // Paths helps resolve external lodash imports correctly in the bundled output
511
+ paths: (id) => {
512
+ if (id.startsWith('lodash/')) {
513
+ // Keep lodash subpath imports as-is so they resolve via import map
514
+ return id;
515
+ }
516
+ return id;
517
+ },
518
+ },
519
+ },
520
+ },
521
+ }${hasDemoDir ? '))' : ')'};
522
+ `;
523
+ }
524
+ /**
525
+ * Ensure IIFE entry point exists for element
526
+ */
527
+ async ensureIifeEntryPoint(elementName, elementDir, _config, _logger) {
528
+ const iifeEntryPath = join(elementDir, 'src/index.iife.ts');
529
+ // Check if main entry point exists
530
+ const mainEntryExists = existsAny([
531
+ join(elementDir, 'src/index.ts'),
532
+ join(elementDir, 'src/index.tsx'),
533
+ ]);
534
+ if (!mainEntryExists) {
535
+ return; // No main entry, skip IIFE
536
+ }
537
+ const iifeContent = `/**
538
+ * IIFE entry point for ${elementName} element
539
+ * This file is only used for IIFE builds and includes auto-registration
540
+ *
541
+ * @sync-generated - Auto-generated during sync from pie-elements
542
+ */
543
+
544
+ import Element from './index';
545
+
546
+ // Auto-register the custom element for IIFE mode
547
+ if (typeof window !== 'undefined' && !customElements.get('${elementName}-element')) {
548
+ customElements.define('${elementName}-element', Element);
549
+ }
550
+
551
+ // Export for IIFE global
552
+ export default Element;
553
+ `;
554
+ await writeFile(iifeEntryPath, iifeContent, 'utf-8');
555
+ }
556
+ /**
557
+ * Ensure IIFE Vite config exists for element
558
+ */
559
+ async ensureIifeViteConfig(elementName, elementDir, _config, _logger) {
560
+ const iifeViteConfigPath = join(elementDir, 'vite.config.iife.ts');
561
+ // Check if IIFE entry exists
562
+ if (!existsSync(join(elementDir, 'src/index.iife.ts'))) {
563
+ return;
564
+ }
565
+ // Compute global name (e.g., "hotspot" → "HotspotElement")
566
+ const globalName = elementName
567
+ .split('-')
568
+ .map((part) => part.charAt(0).toUpperCase() + part.slice(1))
569
+ .join('') + 'Element';
570
+ const config = `import { existsSync } from 'node:fs';
571
+ import { resolve } from 'node:path';
572
+ import react from '@vitejs/plugin-react';
573
+ import { defineConfig } from 'vite';
574
+
575
+ const resolveWorkspaceEntry = (baseDir: string): string | null => {
576
+ const candidates = ['index.ts', 'index.tsx', 'index.js', 'index.jsx'];
577
+ for (const candidate of candidates) {
578
+ const fullPath = resolve(baseDir, candidate);
579
+ if (existsSync(fullPath)) {
580
+ return fullPath;
581
+ }
582
+ }
583
+ return null;
584
+ };
585
+
586
+ export default defineConfig({
587
+ plugins: [
588
+ {
589
+ name: 'iife-workspace-and-shim-resolver',
590
+ enforce: 'pre',
591
+ resolveId(id) {
592
+ const sharedMatch = id.match(/^@pie-element\\/shared-(.+)$/);
593
+ if (sharedMatch) {
594
+ const entry = resolveWorkspaceEntry(resolve(__dirname, '../../shared', sharedMatch[1], 'src'));
595
+ if (entry) {
596
+ return entry;
597
+ }
598
+ }
599
+
600
+ const pieLibMatch = id.match(/^@pie-lib\\/([^/]+)$/);
601
+ if (pieLibMatch) {
602
+ const entry = resolveWorkspaceEntry(resolve(__dirname, '../../lib-react', pieLibMatch[1], 'src'));
603
+ if (entry) {
604
+ return entry;
605
+ }
606
+ }
607
+
608
+ if (id === 'debug') {
609
+ return '\\0iife-debug-shim';
610
+ }
611
+ if (id === 'prop-types') {
612
+ return '\\0iife-prop-types-shim';
613
+ }
614
+ },
615
+ load(id) {
616
+ if (id === '\\0iife-debug-shim') {
617
+ return 'export default function debug() { return () => {}; }';
618
+ }
619
+ if (id === '\\0iife-prop-types-shim') {
620
+ return "const fn = () => null; const types = new Proxy(fn, { get: () => fn }); export default types;";
621
+ }
622
+ },
623
+ },
624
+ react(),
625
+ ],
626
+ define: {
627
+ 'process.env.NODE_ENV': JSON.stringify('production'),
628
+ },
629
+ build: {
630
+ emptyOutDir: false, // Don't wipe existing ESM builds
631
+ lib: {
632
+ entry: resolve(__dirname, 'src/index.iife.ts'),
633
+ name: '${globalName}',
634
+ fileName: () => 'index.iife.js',
635
+ formats: ['iife'] as const,
636
+ },
637
+ rollupOptions: {
638
+ external: (id: string) => {
639
+ // Bundle everything including React and math-rendering
640
+ // This creates a fully self-contained IIFE bundle
641
+ return false;
642
+ },
643
+ output: {
644
+ // IIFE global name
645
+ name: '${globalName}',
646
+ extend: true,
647
+ },
648
+ },
649
+ },
650
+ });
651
+ `;
652
+ await writeFile(iifeViteConfigPath, config, 'utf-8');
653
+ }
654
+ /**
655
+ * Ensure element demo structure exists with new dev/production split
656
+ */
657
+ async ensureElementDemoStructure(elementName, elementDir, config, _logger) {
658
+ const upstreamDemoDir = join(config.pieElements, 'packages', elementName, 'docs/demo');
659
+ // Only generate if upstream has demo files
660
+ if (!existsSync(upstreamDemoDir)) {
661
+ return;
662
+ }
663
+ const targetDemoDir = join(elementDir, 'docs/demo');
664
+ await mkdir(targetDemoDir, { recursive: true });
665
+ // Demo configs are maintained locally for the unified demo app (apps/element-demo).
666
+ // We do NOT sync demo configs from upstream - each element should have its own
667
+ // locally-maintained multi-demo config.mjs in docs/demo/.
668
+ //
669
+ // If a new element is synced and doesn't have a local demo config yet,
670
+ // it should be created manually with multiple demo scenarios.
671
+ //
672
+ // The unified demo app showcases all elements with rich demo configurations,
673
+ // so we maintain these locally rather than using upstream's single-demo configs.
674
+ // Convert session.js (CommonJS) to session.mjs (ESM) if it exists upstream
675
+ const sessionJs = join(upstreamDemoDir, 'session.js');
676
+ const sessionMjs = join(upstreamDemoDir, 'session.mjs');
677
+ let sessionContent = null;
678
+ if (existsSync(sessionMjs)) {
679
+ // If session.mjs exists, just copy it
680
+ sessionContent = await readFile(sessionMjs, 'utf-8');
681
+ }
682
+ else if (existsSync(sessionJs)) {
683
+ // Convert CommonJS session.js to ESM session.mjs
684
+ const content = await readFile(sessionJs, 'utf-8');
685
+ // Simple conversion: replace module.exports with export default
686
+ sessionContent = content
687
+ .replace(/module\.exports\s*=/, 'export default')
688
+ .replace(/exports\.\w+\s*=/g, 'export const');
689
+ }
690
+ if (sessionContent) {
691
+ await writeFile(join(targetDemoDir, 'session.mjs'), sessionContent, 'utf-8');
692
+ }
693
+ // Demo configs are maintained locally - we do NOT apply overrides from upstream
694
+ // Remove unused generate.js if config.mjs exists (from demo dir only)
695
+ const configPath = join(targetDemoDir, 'config.mjs');
696
+ const generatePath = join(targetDemoDir, 'generate.js');
697
+ if (existsSync(configPath) && existsSync(generatePath)) {
698
+ await fsRm(generatePath, { force: true });
699
+ }
700
+ }
701
+ async ensureTsConfig(elementName, elementDir, logger) {
702
+ if (!existsSync(elementDir)) {
703
+ return false;
704
+ }
705
+ const tsConfigPath = join(elementDir, 'tsconfig.json');
706
+ const tsConfig = this.generateTsConfig();
707
+ // Check if tsconfig needs to be written
708
+ const currentContent = existsSync(tsConfigPath)
709
+ ? await readFile(tsConfigPath, 'utf-8').catch(() => null)
710
+ : null;
711
+ if (currentContent === tsConfig) {
712
+ return false;
713
+ }
714
+ await writeFile(tsConfigPath, tsConfig, 'utf-8');
715
+ if (logger.isVerbose()) {
716
+ logger.success(` 📝 ${elementName}: generated tsconfig.json`);
717
+ }
718
+ return true;
719
+ }
720
+ generateTsConfig() {
721
+ return `{
722
+ "extends": "../../../tsconfig.base.json",
723
+ "compilerOptions": {
724
+ "outDir": "dist",
725
+ "declarationDir": "dist",
726
+ "rootDir": "src"
727
+ },
728
+ "include": ["src/**/*"]
729
+ }
730
+ `;
731
+ }
732
+ }
733
+ //# sourceMappingURL=sync-react-strategy.js.map