@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,194 @@
1
+ /**
2
+ * MathQuill synchronization utilities
3
+ *
4
+ * Handles syncing the PIE MathQuill fork from ../mathquill to packages/shared/mathquill
5
+ * and regenerating the concatenated bundle.
6
+ */
7
+ import { existsSync } from 'node:fs';
8
+ import { readFile, writeFile, mkdir, cp } from 'node:fs/promises';
9
+ import { join } from 'node:path';
10
+ import type { Logger } from '../../utils/logger.js';
11
+
12
+ export interface MathQuillSyncConfig {
13
+ upstreamMathQuillPath: string;
14
+ sharedMathQuillPath: string;
15
+ logger: Logger;
16
+ }
17
+
18
+ /**
19
+ * Sync MathQuill source files from upstream
20
+ */
21
+ export async function syncMathQuillSources(config: MathQuillSyncConfig): Promise<boolean> {
22
+ const { upstreamMathQuillPath, sharedMathQuillPath, logger } = config;
23
+
24
+ if (!existsSync(upstreamMathQuillPath)) {
25
+ logger.warn(
26
+ `⚠️ Upstream MathQuill not found at ${upstreamMathQuillPath} - skipping MathQuill sync`
27
+ );
28
+ return false;
29
+ }
30
+
31
+ logger.info('📦 Syncing MathQuill sources from upstream...');
32
+
33
+ try {
34
+ // Ensure destination directories exist
35
+ await mkdir(join(sharedMathQuillPath, 'src'), { recursive: true });
36
+
37
+ // Copy core JavaScript files
38
+ const coreFiles = [
39
+ 'intro.js',
40
+ 'outro.js',
41
+ 'tree.js',
42
+ 'cursor.js',
43
+ 'controller.js',
44
+ 'publicapi.js',
45
+ ];
46
+ for (const file of coreFiles) {
47
+ const src = join(upstreamMathQuillPath, 'src', file);
48
+ const dest = join(sharedMathQuillPath, 'src', file);
49
+ if (existsSync(src)) {
50
+ await cp(src, dest);
51
+ logger.debug(` Copied ${file}`);
52
+ }
53
+ }
54
+
55
+ // Copy directories
56
+ const directories = ['services', 'commands', 'css', 'fonts'];
57
+ for (const dir of directories) {
58
+ const src = join(upstreamMathQuillPath, 'src', dir);
59
+ const dest = join(sharedMathQuillPath, 'src', dir);
60
+ if (existsSync(src)) {
61
+ await cp(src, dest, { recursive: true });
62
+ logger.debug(` Copied ${dir}/`);
63
+ }
64
+ }
65
+
66
+ // Copy documentation
67
+ const docs = ['README.md', 'CHANGELOG.md'];
68
+ for (const doc of docs) {
69
+ const src = join(upstreamMathQuillPath, doc);
70
+ const dest = join(sharedMathQuillPath, doc);
71
+ if (existsSync(src)) {
72
+ await cp(src, dest);
73
+ logger.debug(` Copied ${doc}`);
74
+ }
75
+ }
76
+
77
+ logger.success('✅ MathQuill sources synced');
78
+ return true;
79
+ } catch (error) {
80
+ logger.error(`❌ Failed to sync MathQuill sources: ${error}`);
81
+ return false;
82
+ }
83
+ }
84
+
85
+ /**
86
+ * Regenerate the MathQuill bundle from source files
87
+ */
88
+ export async function regenerateMathQuillBundle(config: MathQuillSyncConfig): Promise<boolean> {
89
+ const { upstreamMathQuillPath, sharedMathQuillPath, logger } = config;
90
+
91
+ logger.info('🔨 Regenerating MathQuill bundle...');
92
+
93
+ try {
94
+ // Check for pjs library in upstream
95
+ const pjsPath = join(upstreamMathQuillPath, 'node_modules/pjs/src/p.js');
96
+ if (!existsSync(pjsPath)) {
97
+ logger.warn(
98
+ `⚠️ pjs library not found in upstream. Install it first: cd ${upstreamMathQuillPath} && npm install pjs`
99
+ );
100
+ return false;
101
+ }
102
+
103
+ // Read pjs
104
+ const pjsContent = await readFile(pjsPath, 'utf-8');
105
+
106
+ // Read all source files in order
107
+ const srcDir = join(sharedMathQuillPath, 'src');
108
+ const fileOrder = [
109
+ 'intro.js',
110
+ // pjs is inserted here programmatically
111
+ 'tree.js',
112
+ 'cursor.js',
113
+ 'controller.js',
114
+ 'publicapi.js',
115
+ ];
116
+
117
+ // Concatenate main files
118
+ let bundle = '';
119
+ for (const file of fileOrder) {
120
+ if (file === 'intro.js') {
121
+ const content = await readFile(join(srcDir, file), 'utf-8');
122
+ bundle += content + '\n';
123
+ bundle += pjsContent + '\n'; // Insert pjs after intro
124
+ } else {
125
+ const content = await readFile(join(srcDir, file), 'utf-8');
126
+ bundle += content + '\n';
127
+ }
128
+ }
129
+
130
+ // Add service utilities (*.util.js files first)
131
+ const servicesDir = join(srcDir, 'services');
132
+ const serviceFiles = await readdir(servicesDir);
133
+ const utilFiles = serviceFiles.filter((f: string) => f.endsWith('.util.js'));
134
+ const otherServiceFiles = serviceFiles.filter(
135
+ (f: string) => f.endsWith('.js') && !f.endsWith('.util.js')
136
+ );
137
+
138
+ for (const file of [...utilFiles, ...otherServiceFiles]) {
139
+ const content = await readFile(join(servicesDir, file), 'utf-8');
140
+ bundle += content + '\n';
141
+ }
142
+
143
+ // Add commands
144
+ const commandsDir = join(srcDir, 'commands');
145
+ bundle += (await readFile(join(commandsDir, 'math.js'), 'utf-8')) + '\n';
146
+ bundle += (await readFile(join(commandsDir, 'text.js'), 'utf-8')) + '\n';
147
+
148
+ // Add math commands
149
+ const mathCommandsDir = join(commandsDir, 'math');
150
+ const mathFiles = await readdir(mathCommandsDir);
151
+ for (const file of mathFiles.filter((f: string) => f.endsWith('.js'))) {
152
+ const content = await readFile(join(mathCommandsDir, file), 'utf-8');
153
+ bundle += content + '\n';
154
+ }
155
+
156
+ // Add outro
157
+ bundle += (await readFile(join(srcDir, 'outro.js'), 'utf-8')) + '\n';
158
+
159
+ // Write bundle
160
+ const legacyDir = join(srcDir, 'legacy');
161
+ await mkdir(legacyDir, { recursive: true });
162
+ const bundlePath = join(legacyDir, 'mathquill-bundle.js');
163
+ await writeFile(bundlePath, bundle, 'utf-8');
164
+
165
+ const lineCount = bundle.split('\n').length;
166
+ logger.success(`✅ Bundle regenerated: ${lineCount} lines`);
167
+ logger.info(` Output: src/legacy/mathquill-bundle.js`);
168
+
169
+ return true;
170
+ } catch (error) {
171
+ logger.error(`❌ Failed to regenerate bundle: ${error}`);
172
+ return false;
173
+ }
174
+ }
175
+
176
+ /**
177
+ * Sync MathQuill: copy sources and regenerate bundle
178
+ */
179
+ export async function syncMathQuill(config: MathQuillSyncConfig): Promise<boolean> {
180
+ const sourcesSynced = await syncMathQuillSources(config);
181
+ if (!sourcesSynced) {
182
+ return false;
183
+ }
184
+
185
+ const bundleRegenerated = await regenerateMathQuillBundle(config);
186
+ return bundleRegenerated;
187
+ }
188
+
189
+ // Helper to read directory (wraps fs/promises)
190
+ async function readdir(path: string): Promise<string[]> {
191
+ const { readdir: fsReaddir } = await import('node:fs/promises');
192
+ const entries = await fsReaddir(path, { withFileTypes: true });
193
+ return entries.filter((e) => e.isFile()).map((e) => e.name);
194
+ }
@@ -0,0 +1,86 @@
1
+ /**
2
+ * Package.json utilities for sync operations
3
+ */
4
+ import type { PackageJson } from '../../utils/package-json.js';
5
+
6
+ /**
7
+ * Get all dependencies from a package.json (dependencies + optionalDependencies + devDependencies)
8
+ */
9
+ export function getAllDeps(
10
+ pkg: PackageJson | null,
11
+ includeDevDeps = false
12
+ ): Record<string, string> {
13
+ if (!pkg) {
14
+ return {};
15
+ }
16
+
17
+ const optionalDependencies =
18
+ (pkg.optionalDependencies as Record<string, string> | undefined) ?? {};
19
+
20
+ return {
21
+ ...(pkg.dependencies ?? {}),
22
+ ...optionalDependencies,
23
+ ...(includeDevDeps && pkg.devDependencies ? pkg.devDependencies : {}),
24
+ };
25
+ }
26
+
27
+ /**
28
+ * Extract @pie-lib/* dependencies from a dependencies object
29
+ */
30
+ export function extractPieLibDeps(deps: Record<string, string>): string[] {
31
+ return Object.keys(deps)
32
+ .filter((dep) => dep.startsWith('@pie-lib/'))
33
+ .map((dep) => dep.replace('@pie-lib/', ''));
34
+ }
35
+
36
+ /**
37
+ * Extract @pie-element/* dependencies from a dependencies object
38
+ */
39
+ export function extractPieElementDeps(deps: Record<string, string>): string[] {
40
+ return Object.keys(deps)
41
+ .filter((dep) => dep.startsWith('@pie-element/'))
42
+ .map((dep) => dep.replace('@pie-element/', ''));
43
+ }
44
+
45
+ /**
46
+ * Generate ESM-compatible package.json exports for an element package
47
+ */
48
+ export function generateElementExports(options: {
49
+ hasController: boolean;
50
+ hasConfigure: boolean;
51
+ }): Record<string, unknown> {
52
+ const exports: Record<string, unknown> = {
53
+ '.': {
54
+ types: './dist/index.d.ts',
55
+ default: './dist/index.js',
56
+ },
57
+ };
58
+
59
+ if (options.hasController) {
60
+ exports['./controller'] = {
61
+ types: './dist/controller/index.d.ts',
62
+ default: './dist/controller/index.js',
63
+ };
64
+ }
65
+
66
+ if (options.hasConfigure) {
67
+ exports['./configure'] = {
68
+ types: './dist/configure/index.d.ts',
69
+ default: './dist/configure/index.js',
70
+ };
71
+ }
72
+
73
+ return exports;
74
+ }
75
+
76
+ /**
77
+ * Generate ESM-compatible package.json exports for a pie-lib package
78
+ */
79
+ export function generatePieLibExports(): Record<string, unknown> {
80
+ return {
81
+ '.': {
82
+ types: './dist/index.d.ts',
83
+ default: './dist/index.js',
84
+ },
85
+ };
86
+ }