@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,306 @@
1
+ import { Command, Flags } from '@oclif/core';
2
+ import { Logger } from '../../utils/logger.js';
3
+ import { existsSync } from 'node:fs';
4
+ import { readdir, readFile, writeFile, stat as fsStat } from 'node:fs/promises';
5
+ import { join } from 'node:path';
6
+
7
+ const ELEMENTS_REACT_DIR = 'packages/elements-react';
8
+
9
+ interface ElementDeps {
10
+ deps: Set<string>;
11
+ peerDeps: Set<string>;
12
+ }
13
+
14
+ export default class CreateReactElements extends Command {
15
+ static override description = 'Create package.json files for synced React elements';
16
+
17
+ static override examples = ['<%= config.bin %> <%= command.id %>'];
18
+
19
+ static override flags = {
20
+ verbose: Flags.boolean({
21
+ char: 'v',
22
+ description: 'Show detailed output',
23
+ default: false,
24
+ }),
25
+ };
26
+
27
+ private logger = new Logger();
28
+
29
+ public async run(): Promise<void> {
30
+ const { flags } = await this.parse(CreateReactElements);
31
+
32
+ this.logger = new Logger(flags.verbose);
33
+
34
+ this.logger.section('šŸ“¦ Creating package.json files for React elements');
35
+
36
+ const elements = await readdir(ELEMENTS_REACT_DIR);
37
+ let created = 0;
38
+ let skipped = 0;
39
+
40
+ for (const element of elements) {
41
+ const elementDir = join(ELEMENTS_REACT_DIR, element);
42
+ const packageJsonPath = join(elementDir, 'package.json');
43
+
44
+ // Skip if not a directory
45
+ const statResult = await fsStat(elementDir).catch(() => null);
46
+ if (!statResult?.isDirectory()) {
47
+ continue;
48
+ }
49
+
50
+ // Skip if package.json already exists
51
+ if (existsSync(packageJsonPath)) {
52
+ this.logger.info(` ā­ļø ${element}: package.json already exists`);
53
+ skipped++;
54
+ continue;
55
+ }
56
+
57
+ // Scan for dependencies
58
+ const { deps, peerDeps } = await this.scanElement(elementDir);
59
+
60
+ // Add controller package as a dependency
61
+ const controllerPkg = `@pie-element/${element}-controller`;
62
+ deps.add(controllerPkg);
63
+
64
+ // Generate package.json
65
+ const packageContent = this.generatePackageJson(
66
+ element,
67
+ Array.from(deps),
68
+ Array.from(peerDeps)
69
+ );
70
+
71
+ // Write package.json
72
+ await writeFile(packageJsonPath, packageContent, 'utf-8');
73
+
74
+ // Generate vite.config.ts
75
+ const viteConfigPath = join(elementDir, 'vite.config.ts');
76
+ if (!existsSync(viteConfigPath)) {
77
+ await writeFile(viteConfigPath, this.generateViteConfig(), 'utf-8');
78
+ }
79
+
80
+ // Generate tsconfig.json
81
+ const tsconfigPath = join(elementDir, 'tsconfig.json');
82
+ if (!existsSync(tsconfigPath)) {
83
+ await writeFile(tsconfigPath, this.generateTsConfig(), 'utf-8');
84
+ }
85
+
86
+ this.logger.success(
87
+ ` āœ… ${element}: Created package.json (${deps.size} deps, ${peerDeps.size} peer deps)`
88
+ );
89
+ created++;
90
+ }
91
+
92
+ this.logger.section(`\nšŸ“Š Summary: ${created} created, ${skipped} skipped`);
93
+ }
94
+
95
+ private async scanElement(elementDir: string): Promise<ElementDeps> {
96
+ const srcDir = join(elementDir, 'src');
97
+ const deps = new Set<string>();
98
+ const peerDeps = new Set<string>();
99
+
100
+ if (!existsSync(srcDir)) {
101
+ return { deps, peerDeps };
102
+ }
103
+
104
+ // Recursively scan all .ts and .tsx files
105
+ const scanDir = async (dir: string): Promise<void> => {
106
+ const items = await readdir(dir, { withFileTypes: true });
107
+
108
+ for (const item of items) {
109
+ const itemPath = join(dir, item.name);
110
+
111
+ if (item.isDirectory()) {
112
+ await scanDir(itemPath);
113
+ } else if (item.name.endsWith('.ts') || item.name.endsWith('.tsx')) {
114
+ const content = await readFile(itemPath, 'utf-8');
115
+ const fileDeps = this.extractDeps(content);
116
+
117
+ for (const dep of fileDeps.deps) deps.add(dep);
118
+ for (const dep of fileDeps.peerDeps) peerDeps.add(dep);
119
+ }
120
+ }
121
+ };
122
+
123
+ await scanDir(srcDir);
124
+
125
+ return { deps, peerDeps };
126
+ }
127
+
128
+ private extractDeps(content: string): { deps: string[]; peerDeps: string[] } {
129
+ const deps = new Set<string>();
130
+ const peerDeps = new Set<string>();
131
+
132
+ // Match import statements
133
+ const importRegex = /^import .* from ['"]([^'"]+)['"]/gm;
134
+ const matches = content.matchAll(importRegex);
135
+
136
+ for (const match of matches) {
137
+ const dep = match[1];
138
+
139
+ // Skip relative imports
140
+ if (dep.startsWith('.')) continue;
141
+
142
+ // React is a peer dependency
143
+ if (dep === 'react' || dep.startsWith('react/')) {
144
+ peerDeps.add('react');
145
+ continue;
146
+ }
147
+ if (dep === 'react-dom' || dep.startsWith('react-dom/')) {
148
+ peerDeps.add('react-dom');
149
+ continue;
150
+ }
151
+
152
+ // Add @pie-lib packages
153
+ if (dep.startsWith('@pie-lib/')) {
154
+ deps.add(dep.split('/').slice(0, 2).join('/'));
155
+ }
156
+ // Add @pie-element packages (controller packages)
157
+ else if (dep.startsWith('@pie-element/')) {
158
+ deps.add(dep.split('/').slice(0, 2).join('/'));
159
+ }
160
+ // Add other scoped packages
161
+ else if (dep.startsWith('@')) {
162
+ deps.add(dep.split('/').slice(0, 2).join('/'));
163
+ }
164
+ // Add non-scoped packages
165
+ else if (!dep.includes('/')) {
166
+ deps.add(dep);
167
+ } else {
168
+ // Package with sub-path (e.g., lodash/get)
169
+ deps.add(dep.split('/')[0]);
170
+ }
171
+ }
172
+
173
+ return {
174
+ deps: Array.from(deps).sort(),
175
+ peerDeps: Array.from(peerDeps).sort(),
176
+ };
177
+ }
178
+
179
+ private generatePackageJson(name: string, deps: string[], peerDeps: string[]): string {
180
+ const dependencies: Record<string, string> = {};
181
+ const peerDependencies: Record<string, string> = {};
182
+
183
+ // Add dependencies (use * for external deps, they're in root package.json)
184
+ for (const dep of deps) {
185
+ // Use workspace protocol for internal packages
186
+ if (dep.startsWith('@pie-element/')) {
187
+ dependencies[dep] = 'workspace:*';
188
+ } else {
189
+ dependencies[dep] = '*';
190
+ }
191
+ }
192
+
193
+ // Add peer dependencies
194
+ for (const dep of peerDeps) {
195
+ peerDependencies[dep] = '^18.0.0';
196
+ }
197
+
198
+ const pkg = {
199
+ name: `@pie-element/${name}`,
200
+ version: '0.1.0',
201
+ description: `React implementation of ${name} element synced from pie-elements`,
202
+ type: 'module',
203
+ main: './dist/index.js',
204
+ types: './dist/index.d.ts',
205
+ exports: {
206
+ '.': {
207
+ types: './dist/index.d.ts',
208
+ default: './dist/index.js',
209
+ },
210
+ './delivery': {
211
+ types: './dist/delivery/index.d.ts',
212
+ default: './dist/delivery/index.js',
213
+ },
214
+ './configure': {
215
+ types: './dist/configure/index.d.ts',
216
+ default: './dist/configure/index.js',
217
+ },
218
+ './controller': {
219
+ types: './dist/controller/index.d.ts',
220
+ default: './dist/controller/index.js',
221
+ },
222
+ },
223
+ files: ['dist', 'src'],
224
+ scripts: {
225
+ dev: 'vite',
226
+ build: 'vite build && tsc --emitDeclarationOnly',
227
+ test: 'vitest run',
228
+ lint: 'biome check .',
229
+ 'lint:fix': 'biome check --write .',
230
+ },
231
+ dependencies: Object.keys(dependencies).length > 0 ? dependencies : undefined,
232
+ peerDependencies: Object.keys(peerDependencies).length > 0 ? peerDependencies : undefined,
233
+ devDependencies: {
234
+ '@types/react': '^18.2.0',
235
+ '@types/react-dom': '^18.2.0',
236
+ '@vitejs/plugin-react': '^4.2.0',
237
+ typescript: '^5.9.3',
238
+ vite: '^6.0.0',
239
+ vitest: '^2.1.0',
240
+ },
241
+ keywords: ['pie', 'pie-element', 'react', name, 'assessment'],
242
+ license: 'ISC',
243
+ repository: {
244
+ type: 'git',
245
+ url: 'https://github.com/pie-framework/pie-elements-ng.git',
246
+ directory: `packages/elements-react/${name}`,
247
+ },
248
+ };
249
+
250
+ // Remove undefined fields
251
+ const cleaned = JSON.parse(JSON.stringify(pkg));
252
+
253
+ return `${JSON.stringify(cleaned, null, 2)}\n`;
254
+ }
255
+
256
+ private generateViteConfig(): string {
257
+ return `import react from '@vitejs/plugin-react';
258
+ import { defineConfig } from 'vite';
259
+ import { resolve } from 'node:path';
260
+
261
+ export default defineConfig({
262
+ plugins: [react()],
263
+ build: {
264
+ lib: {
265
+ entry: {
266
+ index: resolve(__dirname, 'src/index.ts'),
267
+ 'delivery/index': resolve(__dirname, 'src/index.ts'),
268
+ 'configure/index': resolve(__dirname, 'src/configure/index.ts'),
269
+ },
270
+ formats: ['es'],
271
+ },
272
+ rollupOptions: {
273
+ external: [
274
+ /^react($|\\/)/,
275
+ /^react-dom($|\\/)/,
276
+ /^@pie-lib/,
277
+ /^@pie-element/,
278
+ /^@pie-framework/,
279
+ /^@mui/,
280
+ ],
281
+ output: {
282
+ preserveModules: true,
283
+ preserveModulesRoot: 'src',
284
+ },
285
+ },
286
+ },
287
+ });
288
+ `;
289
+ }
290
+
291
+ private generateTsConfig(): string {
292
+ return `{
293
+ "extends": "../../../tsconfig.json",
294
+ "compilerOptions": {
295
+ "outDir": "./dist",
296
+ "rootDir": "./src",
297
+ "jsx": "react-jsx",
298
+ "declaration": true,
299
+ "emitDeclarationOnly": false
300
+ },
301
+ "include": ["src/**/*"],
302
+ "exclude": ["node_modules", "dist", "**/*.test.ts", "**/*.test.tsx"]
303
+ }
304
+ `;
305
+ }
306
+ }
@@ -0,0 +1,161 @@
1
+ import { Command, Flags } from '@oclif/core';
2
+ import { Logger } from '../../utils/logger.js';
3
+ import { loadPackageJson, writePackageJson } from '../../utils/package-json.js';
4
+ import { glob } from 'glob';
5
+ import { readFile } from 'node:fs/promises';
6
+
7
+ interface ChangesetConfig {
8
+ $schema?: string;
9
+ changelog: string;
10
+ commit: boolean;
11
+ fixed: string[];
12
+ linked: string[];
13
+ access: string;
14
+ baseBranch: string;
15
+ updateInternalDependencies: string;
16
+ ignore: string[];
17
+ }
18
+
19
+ const REACT_PACKAGE_PATTERNS = [
20
+ 'packages/elements-react/*/package.json',
21
+ 'packages/lib-react/*/package.json',
22
+ ];
23
+
24
+ const CHANGESET_CONFIG_PATH = '.changeset/config.json';
25
+
26
+ export default class EnablePublishing extends Command {
27
+ static override description = 'Enable React package publishing by removing private flags';
28
+
29
+ static override examples = [
30
+ '<%= config.bin %> <%= command.id %> --dry-run',
31
+ '<%= config.bin %> <%= command.id %>',
32
+ ];
33
+
34
+ static override flags = {
35
+ 'dry-run': Flags.boolean({
36
+ description: 'Show what would be changed without making any changes',
37
+ default: false,
38
+ }),
39
+ };
40
+
41
+ private logger = new Logger();
42
+
43
+ public async run(): Promise<void> {
44
+ const { flags } = await this.parse(EnablePublishing);
45
+
46
+ this.logger.section('šŸ”„ React Package Publishing Migration');
47
+
48
+ if (flags['dry-run']) {
49
+ this.logger.info('šŸ” DRY RUN MODE - No changes will be made\n');
50
+ }
51
+
52
+ const changes: string[] = [];
53
+ let totalPackages = 0;
54
+
55
+ // Step 1: Find all React packages
56
+ this.logger.info('šŸ“¦ Finding React packages...');
57
+ const packagePaths: string[] = [];
58
+ for (const pattern of REACT_PACKAGE_PATTERNS) {
59
+ const matches = await glob(pattern);
60
+ packagePaths.push(...matches);
61
+ }
62
+
63
+ this.logger.info(` Found ${packagePaths.length} React packages\n`);
64
+
65
+ // Step 2: Remove "private": true from package.json files
66
+ this.logger.info('šŸ”“ Removing private flag from React packages...');
67
+ const packageNames: string[] = [];
68
+
69
+ for (const pkgPath of packagePaths) {
70
+ const pkg = await loadPackageJson(pkgPath);
71
+
72
+ packageNames.push(pkg.name);
73
+
74
+ if (pkg.private === true) {
75
+ totalPackages++;
76
+ this.logger.info(` āœ“ ${pkg.name}`);
77
+ changes.push(`Remove private flag from ${pkg.name}`);
78
+
79
+ if (!flags['dry-run']) {
80
+ // Remove the private field
81
+ delete pkg.private;
82
+
83
+ // Write back with proper formatting
84
+ await writePackageJson(pkgPath, pkg);
85
+ }
86
+ }
87
+ }
88
+
89
+ this.logger.info(` Modified ${totalPackages} package.json files\n`);
90
+
91
+ // Step 3: Update .changeset/config.json
92
+ this.logger.info('āš™ļø Updating changeset configuration...');
93
+ const changesetContent = await readFile(CHANGESET_CONFIG_PATH, 'utf-8');
94
+ const changesetConfig = JSON.parse(changesetContent) as ChangesetConfig;
95
+
96
+ // Filter out React packages from ignore list
97
+ const reactPackageSet = new Set(packageNames);
98
+ const originalIgnoreCount = changesetConfig.ignore.length;
99
+ const newIgnore = changesetConfig.ignore.filter((name) => !reactPackageSet.has(name));
100
+
101
+ const removedCount = originalIgnoreCount - newIgnore.length;
102
+ this.logger.info(` Removing ${removedCount} packages from ignore list`);
103
+ changes.push(`Remove ${removedCount} React packages from changeset ignore list`);
104
+
105
+ if (!flags['dry-run']) {
106
+ changesetConfig.ignore = newIgnore;
107
+ await writePackageJson(CHANGESET_CONFIG_PATH, changesetConfig as any);
108
+ }
109
+
110
+ this.logger.info(` Updated ${CHANGESET_CONFIG_PATH}\n`);
111
+
112
+ // Summary
113
+ this.logger.section('šŸ“‹ Summary of Changes');
114
+
115
+ for (const change of changes) {
116
+ this.logger.info(` • ${change}`);
117
+ }
118
+
119
+ this.logger.info(`\n Total packages enabled for publishing: ${totalPackages}`);
120
+
121
+ if (flags['dry-run']) {
122
+ this.logger.warn('\nāš ļø This was a dry run. No files were modified.');
123
+ this.logger.info(
124
+ ' Run without --dry-run to apply these changes:\n bun run cli packages:enable-publishing\n'
125
+ );
126
+ } else {
127
+ this.logger.success('\nāœ… Migration complete!');
128
+ this.logger.info('\nNext steps:');
129
+ this.logger.info('1. Review the changes with: git diff');
130
+ this.logger.info('2. Create changesets for the React packages you want to publish:');
131
+ this.logger.info(' bun run changeset');
132
+ this.logger.info('3. Commit and push the changes:');
133
+ this.logger.info(' git add .');
134
+ this.logger.info(' git commit -m "chore: enable React package publishing"');
135
+ this.logger.info(' git push');
136
+ this.logger.info('4. Wait for the automated Version Packages PR and merge it to publish\n');
137
+ }
138
+
139
+ // Provide package list
140
+ this.logger.section('\nšŸ“¦ Packages that will now be published');
141
+
142
+ const elementPackages = packageNames.filter((name) => name.startsWith('@pie-element/'));
143
+ const libPackages = packageNames.filter((name) => name.startsWith('@pie-lib/'));
144
+
145
+ if (elementPackages.length > 0) {
146
+ this.logger.info('React Elements:');
147
+ for (const name of elementPackages.sort()) {
148
+ this.logger.info(` • ${name}`);
149
+ }
150
+ this.log();
151
+ }
152
+
153
+ if (libPackages.length > 0) {
154
+ this.logger.info('React Libraries:');
155
+ for (const name of libPackages.sort()) {
156
+ this.logger.info(` • ${name}`);
157
+ }
158
+ this.log();
159
+ }
160
+ }
161
+ }