@pie-element/cli 0.1.1 → 0.1.2-next.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (281) hide show
  1. package/README.md +48 -10
  2. package/dist/commands/dev/demo/index.d.ts +1 -1
  3. package/dist/commands/dev/demo/index.js +21 -0
  4. package/dist/commands/dev/demo/index.js.map +1 -1
  5. package/dist/commands/dev/test-bundler.d.ts +0 -1
  6. package/dist/commands/dev/test-bundler.js +2 -10
  7. package/dist/commands/dev/test-bundler.js.map +1 -1
  8. package/dist/commands/docs/generate.d.ts +16 -0
  9. package/dist/commands/docs/generate.js +150 -0
  10. package/dist/commands/docs/generate.js.map +1 -0
  11. package/dist/commands/docs/verify.d.ts +12 -0
  12. package/dist/commands/docs/verify.js +40 -0
  13. package/dist/commands/docs/verify.js.map +1 -0
  14. package/dist/commands/packages/create-controllers.d.ts +0 -1
  15. package/dist/commands/packages/create-controllers.js.map +1 -1
  16. package/dist/commands/packages/create-lib-react.d.ts +0 -1
  17. package/dist/commands/packages/create-lib-react.js +1 -3
  18. package/dist/commands/packages/create-lib-react.js.map +1 -1
  19. package/dist/commands/packages/create-react-elements.d.ts +0 -1
  20. package/dist/commands/packages/create-react-elements.js +2 -3
  21. package/dist/commands/packages/create-react-elements.js.map +1 -1
  22. package/dist/commands/packages/enable-publishing.d.ts +0 -1
  23. package/dist/commands/packages/enable-publishing.js +26 -23
  24. package/dist/commands/packages/enable-publishing.js.map +1 -1
  25. package/dist/commands/packages/init-synced-elements.d.ts +0 -1
  26. package/dist/commands/packages/init-synced-elements.js +1 -1
  27. package/dist/commands/packages/init-synced-elements.js.map +1 -1
  28. package/dist/commands/upstream/analyze-esm.d.ts +0 -1
  29. package/dist/commands/upstream/analyze-esm.js +5 -1
  30. package/dist/commands/upstream/analyze-esm.js.map +1 -1
  31. package/dist/commands/upstream/check.d.ts +0 -1
  32. package/dist/commands/upstream/check.js.map +1 -1
  33. package/dist/commands/upstream/deps.d.ts +0 -1
  34. package/dist/commands/upstream/deps.js.map +1 -1
  35. package/dist/commands/upstream/sync.d.ts +11 -2
  36. package/dist/commands/upstream/sync.js +364 -25
  37. package/dist/commands/upstream/sync.js.map +1 -1
  38. package/dist/commands/upstream/track.d.ts +0 -1
  39. package/dist/commands/upstream/track.js.map +1 -1
  40. package/dist/commands/upstream/update.d.ts +0 -1
  41. package/dist/commands/upstream/update.js +37 -7
  42. package/dist/commands/upstream/update.js.map +1 -1
  43. package/dist/commands/verify/controllers.d.ts +0 -1
  44. package/dist/commands/verify/controllers.js +213 -59
  45. package/dist/commands/verify/controllers.js.map +1 -1
  46. package/dist/commands/verify/dependency-integrity.d.ts +18 -0
  47. package/dist/commands/verify/dependency-integrity.js +147 -0
  48. package/dist/commands/verify/dependency-integrity.js.map +1 -0
  49. package/dist/commands/verify/react-build.d.ts +0 -1
  50. package/dist/commands/verify/react-build.js.map +1 -1
  51. package/dist/index.d.ts +0 -1
  52. package/dist/index.js.map +1 -1
  53. package/dist/lib/docs/contract-validator.d.ts +12 -0
  54. package/dist/lib/docs/contract-validator.js +38 -0
  55. package/dist/lib/docs/contract-validator.js.map +1 -0
  56. package/dist/lib/docs/contracts.d.ts +11 -0
  57. package/dist/lib/docs/contracts.js +241 -0
  58. package/dist/lib/docs/contracts.js.map +1 -0
  59. package/dist/lib/docs/discovery.d.ts +10 -0
  60. package/dist/lib/docs/discovery.js +91 -0
  61. package/dist/lib/docs/discovery.js.map +1 -0
  62. package/dist/lib/docs/generator.d.ts +14 -0
  63. package/dist/lib/docs/generator.js +450 -0
  64. package/dist/lib/docs/generator.js.map +1 -0
  65. package/dist/lib/docs/source-extractor.d.ts +2 -0
  66. package/dist/lib/docs/source-extractor.js +209 -0
  67. package/dist/lib/docs/source-extractor.js.map +1 -0
  68. package/dist/lib/docs/types.d.ts +77 -0
  69. package/dist/lib/docs/types.js +2 -0
  70. package/dist/lib/docs/types.js.map +1 -0
  71. package/dist/lib/upstream/repo-utils.d.ts +0 -1
  72. package/dist/lib/upstream/repo-utils.js.map +1 -1
  73. package/dist/lib/upstream/sync-compatibility.d.ts +0 -1
  74. package/dist/lib/upstream/sync-compatibility.js.map +1 -1
  75. package/dist/lib/upstream/sync-constants.d.ts +35 -7
  76. package/dist/lib/upstream/sync-constants.js +40 -11
  77. package/dist/lib/upstream/sync-constants.js.map +1 -1
  78. package/dist/lib/upstream/sync-controllers-strategy.d.ts +0 -1
  79. package/dist/lib/upstream/sync-controllers-strategy.js +14 -4
  80. package/dist/lib/upstream/sync-controllers-strategy.js.map +1 -1
  81. package/dist/lib/upstream/sync-demo-metadata.d.ts +0 -1
  82. package/dist/lib/upstream/sync-demo-metadata.js +1 -1
  83. package/dist/lib/upstream/sync-demo-metadata.js.map +1 -1
  84. package/dist/lib/upstream/sync-entry-discovery.d.ts +3 -0
  85. package/dist/lib/upstream/sync-entry-discovery.js +23 -0
  86. package/dist/lib/upstream/sync-entry-discovery.js.map +1 -0
  87. package/dist/lib/upstream/sync-externals.d.ts +7 -7
  88. package/dist/lib/upstream/sync-externals.js +51 -35
  89. package/dist/lib/upstream/sync-externals.js.map +1 -1
  90. package/dist/lib/upstream/sync-filesystem.d.ts +0 -1
  91. package/dist/lib/upstream/sync-filesystem.js.map +1 -1
  92. package/dist/lib/upstream/sync-imports.d.ts +82 -62
  93. package/dist/lib/upstream/sync-imports.js +658 -185
  94. package/dist/lib/upstream/sync-imports.js.map +1 -1
  95. package/dist/lib/upstream/sync-package-json.d.ts +0 -1
  96. package/dist/lib/upstream/sync-package-json.js +7 -0
  97. package/dist/lib/upstream/sync-package-json.js.map +1 -1
  98. package/dist/lib/upstream/sync-package-manager.d.ts +14 -4
  99. package/dist/lib/upstream/sync-package-manager.js +405 -72
  100. package/dist/lib/upstream/sync-package-manager.js.map +1 -1
  101. package/dist/lib/upstream/sync-pielib-strategy.d.ts +2 -1
  102. package/dist/lib/upstream/sync-pielib-strategy.js +228 -110
  103. package/dist/lib/upstream/sync-pielib-strategy.js.map +1 -1
  104. package/dist/lib/upstream/sync-presets.d.ts +52 -0
  105. package/dist/lib/upstream/sync-presets.js +175 -0
  106. package/dist/lib/upstream/sync-presets.js.map +1 -0
  107. package/dist/lib/upstream/sync-react-strategy.d.ts +6 -1
  108. package/dist/lib/upstream/sync-react-strategy.js +342 -134
  109. package/dist/lib/upstream/sync-react-strategy.js.map +1 -1
  110. package/dist/lib/upstream/sync-source-edit.d.ts +14 -0
  111. package/dist/lib/upstream/sync-source-edit.js +89 -0
  112. package/dist/lib/upstream/sync-source-edit.js.map +1 -0
  113. package/dist/lib/upstream/sync-source-tree.d.ts +22 -0
  114. package/dist/lib/upstream/sync-source-tree.js +99 -0
  115. package/dist/lib/upstream/sync-source-tree.js.map +1 -0
  116. package/dist/lib/upstream/sync-strategy.d.ts +1 -1
  117. package/dist/lib/upstream/sync-strategy.js.map +1 -1
  118. package/dist/lib/upstream/sync-summary.d.ts +0 -1
  119. package/dist/lib/upstream/sync-summary.js.map +1 -1
  120. package/dist/lib/upstream/sync-transforms.d.ts +13 -11
  121. package/dist/lib/upstream/sync-transforms.js +23 -17
  122. package/dist/lib/upstream/sync-transforms.js.map +1 -1
  123. package/dist/lib/upstream/sync-vite-config.d.ts +13 -1
  124. package/dist/lib/upstream/sync-vite-config.js +65 -46
  125. package/dist/lib/upstream/sync-vite-config.js.map +1 -1
  126. package/dist/utils/compatibility.d.ts +13 -1
  127. package/dist/utils/compatibility.js +143 -2
  128. package/dist/utils/compatibility.js.map +1 -1
  129. package/dist/utils/conversion.d.ts +0 -1
  130. package/dist/utils/conversion.js.map +1 -1
  131. package/dist/utils/dependency-integrity.d.ts +37 -0
  132. package/dist/utils/dependency-integrity.js +557 -0
  133. package/dist/utils/dependency-integrity.js.map +1 -0
  134. package/dist/utils/git.d.ts +0 -1
  135. package/dist/utils/git.js.map +1 -1
  136. package/dist/utils/logger.d.ts +0 -1
  137. package/dist/utils/logger.js.map +1 -1
  138. package/dist/utils/package-json.d.ts +0 -1
  139. package/dist/utils/package-json.js.map +1 -1
  140. package/package.json +25 -8
  141. package/.compatibility/report.json +0 -2491
  142. package/.turbo/turbo-build.log +0 -1
  143. package/CHANGELOG.md +0 -8
  144. package/REFACTORING.md +0 -131
  145. package/bin/dev.js +0 -5
  146. package/dist/commands/dev/demo/index.d.ts.map +0 -1
  147. package/dist/commands/dev/test-bundler.d.ts.map +0 -1
  148. package/dist/commands/mathquill/migrate.d.ts +0 -20
  149. package/dist/commands/mathquill/migrate.d.ts.map +0 -1
  150. package/dist/commands/mathquill/migrate.js +0 -240
  151. package/dist/commands/mathquill/migrate.js.map +0 -1
  152. package/dist/commands/mathquill/status.d.ts +0 -20
  153. package/dist/commands/mathquill/status.d.ts.map +0 -1
  154. package/dist/commands/mathquill/status.js +0 -231
  155. package/dist/commands/mathquill/status.js.map +0 -1
  156. package/dist/commands/packages/create-controllers.d.ts.map +0 -1
  157. package/dist/commands/packages/create-lib-react.d.ts.map +0 -1
  158. package/dist/commands/packages/create-react-elements.d.ts.map +0 -1
  159. package/dist/commands/packages/enable-publishing.d.ts.map +0 -1
  160. package/dist/commands/packages/init-synced-elements.d.ts.map +0 -1
  161. package/dist/commands/upstream/analyze-esm.d.ts.map +0 -1
  162. package/dist/commands/upstream/check.d.ts.map +0 -1
  163. package/dist/commands/upstream/deps.d.ts.map +0 -1
  164. package/dist/commands/upstream/sync-mathquill.d.ts +0 -12
  165. package/dist/commands/upstream/sync-mathquill.d.ts.map +0 -1
  166. package/dist/commands/upstream/sync-mathquill.js +0 -97
  167. package/dist/commands/upstream/sync-mathquill.js.map +0 -1
  168. package/dist/commands/upstream/sync.d.ts.map +0 -1
  169. package/dist/commands/upstream/track.d.ts.map +0 -1
  170. package/dist/commands/upstream/update.d.ts.map +0 -1
  171. package/dist/commands/verify/controllers.d.ts.map +0 -1
  172. package/dist/commands/verify/react-build.d.ts.map +0 -1
  173. package/dist/index.d.ts.map +0 -1
  174. package/dist/lib/mathquill/extension-generator.d.ts +0 -9
  175. package/dist/lib/mathquill/extension-generator.d.ts.map +0 -1
  176. package/dist/lib/mathquill/extension-generator.js +0 -107
  177. package/dist/lib/mathquill/extension-generator.js.map +0 -1
  178. package/dist/lib/mathquill/khan-extractor.d.ts +0 -16
  179. package/dist/lib/mathquill/khan-extractor.d.ts.map +0 -1
  180. package/dist/lib/mathquill/khan-extractor.js +0 -148
  181. package/dist/lib/mathquill/khan-extractor.js.map +0 -1
  182. package/dist/lib/mathquill/learnosity-extractor.d.ts +0 -15
  183. package/dist/lib/mathquill/learnosity-extractor.d.ts.map +0 -1
  184. package/dist/lib/mathquill/learnosity-extractor.js +0 -170
  185. package/dist/lib/mathquill/learnosity-extractor.js.map +0 -1
  186. package/dist/lib/mathquill/migration-orchestrator.d.ts +0 -77
  187. package/dist/lib/mathquill/migration-orchestrator.d.ts.map +0 -1
  188. package/dist/lib/mathquill/migration-orchestrator.js +0 -391
  189. package/dist/lib/mathquill/migration-orchestrator.js.map +0 -1
  190. package/dist/lib/mathquill/package-updater.d.ts +0 -9
  191. package/dist/lib/mathquill/package-updater.d.ts.map +0 -1
  192. package/dist/lib/mathquill/package-updater.js +0 -103
  193. package/dist/lib/mathquill/package-updater.js.map +0 -1
  194. package/dist/lib/mathquill/pie-extractor.d.ts +0 -14
  195. package/dist/lib/mathquill/pie-extractor.d.ts.map +0 -1
  196. package/dist/lib/mathquill/pie-extractor.js +0 -167
  197. package/dist/lib/mathquill/pie-extractor.js.map +0 -1
  198. package/dist/lib/upstream/repo-utils.d.ts.map +0 -1
  199. package/dist/lib/upstream/sync-compatibility.d.ts.map +0 -1
  200. package/dist/lib/upstream/sync-constants.d.ts.map +0 -1
  201. package/dist/lib/upstream/sync-controllers-strategy.d.ts.map +0 -1
  202. package/dist/lib/upstream/sync-demo-metadata.d.ts.map +0 -1
  203. package/dist/lib/upstream/sync-dev-exports.d.ts +0 -13
  204. package/dist/lib/upstream/sync-dev-exports.d.ts.map +0 -1
  205. package/dist/lib/upstream/sync-dev-exports.js +0 -115
  206. package/dist/lib/upstream/sync-dev-exports.js.map +0 -1
  207. package/dist/lib/upstream/sync-externals.d.ts.map +0 -1
  208. package/dist/lib/upstream/sync-filesystem.d.ts.map +0 -1
  209. package/dist/lib/upstream/sync-imports.d.ts.map +0 -1
  210. package/dist/lib/upstream/sync-mathquill.d.ts +0 -19
  211. package/dist/lib/upstream/sync-mathquill.d.ts.map +0 -1
  212. package/dist/lib/upstream/sync-mathquill.js +0 -160
  213. package/dist/lib/upstream/sync-mathquill.js.map +0 -1
  214. package/dist/lib/upstream/sync-package-json.d.ts.map +0 -1
  215. package/dist/lib/upstream/sync-package-manager.d.ts.map +0 -1
  216. package/dist/lib/upstream/sync-pielib-strategy.d.ts.map +0 -1
  217. package/dist/lib/upstream/sync-react-strategy.d.ts.map +0 -1
  218. package/dist/lib/upstream/sync-strategy.d.ts.map +0 -1
  219. package/dist/lib/upstream/sync-summary.d.ts.map +0 -1
  220. package/dist/lib/upstream/sync-transforms.d.ts.map +0 -1
  221. package/dist/lib/upstream/sync-vite-config.d.ts.map +0 -1
  222. package/dist/utils/compatibility.d.ts.map +0 -1
  223. package/dist/utils/conversion.d.ts.map +0 -1
  224. package/dist/utils/git.d.ts.map +0 -1
  225. package/dist/utils/logger.d.ts.map +0 -1
  226. package/dist/utils/package-json.d.ts.map +0 -1
  227. package/packages/cli/bin/dev.js +0 -5
  228. package/packages/cli/bin/run.js +0 -5
  229. package/src/commands/dev/demo/index.ts +0 -313
  230. package/src/commands/dev/test-bundler.ts +0 -345
  231. package/src/commands/mathquill/migrate.ts +0 -269
  232. package/src/commands/mathquill/status.ts +0 -267
  233. package/src/commands/packages/create-controllers.ts +0 -127
  234. package/src/commands/packages/create-lib-react.ts +0 -279
  235. package/src/commands/packages/create-react-elements.ts +0 -306
  236. package/src/commands/packages/enable-publishing.ts +0 -161
  237. package/src/commands/packages/init-synced-elements.ts +0 -259
  238. package/src/commands/upstream/README.md +0 -444
  239. package/src/commands/upstream/analyze-esm.ts +0 -1973
  240. package/src/commands/upstream/check.ts +0 -228
  241. package/src/commands/upstream/deps.ts +0 -222
  242. package/src/commands/upstream/sync-mathquill.ts +0 -108
  243. package/src/commands/upstream/sync.ts +0 -687
  244. package/src/commands/upstream/track.ts +0 -145
  245. package/src/commands/upstream/update.ts +0 -110
  246. package/src/commands/verify/controllers.ts +0 -166
  247. package/src/commands/verify/react-build.ts +0 -171
  248. package/src/index.ts +0 -1
  249. package/src/lib/mathquill/extension-generator.ts +0 -111
  250. package/src/lib/mathquill/khan-extractor.ts +0 -175
  251. package/src/lib/mathquill/learnosity-extractor.ts +0 -198
  252. package/src/lib/mathquill/migration-orchestrator.ts +0 -513
  253. package/src/lib/mathquill/package-updater.ts +0 -120
  254. package/src/lib/mathquill/pie-extractor.ts +0 -194
  255. package/src/lib/upstream/repo-utils.ts +0 -18
  256. package/src/lib/upstream/sync-compatibility.ts +0 -89
  257. package/src/lib/upstream/sync-constants.ts +0 -77
  258. package/src/lib/upstream/sync-controllers-strategy.ts +0 -291
  259. package/src/lib/upstream/sync-demo-metadata.ts +0 -199
  260. package/src/lib/upstream/sync-dev-exports.ts +0 -151
  261. package/src/lib/upstream/sync-externals.ts +0 -159
  262. package/src/lib/upstream/sync-filesystem.ts +0 -87
  263. package/src/lib/upstream/sync-imports.ts +0 -992
  264. package/src/lib/upstream/sync-mathquill.ts +0 -194
  265. package/src/lib/upstream/sync-package-json.ts +0 -86
  266. package/src/lib/upstream/sync-package-manager.ts +0 -694
  267. package/src/lib/upstream/sync-pielib-strategy.ts +0 -441
  268. package/src/lib/upstream/sync-react-strategy.ts +0 -945
  269. package/src/lib/upstream/sync-strategy.ts +0 -61
  270. package/src/lib/upstream/sync-summary.ts +0 -194
  271. package/src/lib/upstream/sync-transforms.ts +0 -154
  272. package/src/lib/upstream/sync-vite-config.ts +0 -243
  273. package/src/types/es-module-lexer.d.ts +0 -4
  274. package/src/utils/compatibility.ts +0 -182
  275. package/src/utils/conversion.ts +0 -153
  276. package/src/utils/git.ts +0 -63
  277. package/src/utils/logger.ts +0 -69
  278. package/src/utils/package-json.ts +0 -43
  279. package/tests/sync-package-manager.test.ts +0 -112
  280. package/tests/transform-assign-props.test.ts +0 -101
  281. package/tsconfig.json +0 -15
@@ -1,279 +0,0 @@
1
- import { Command, Flags } from '@oclif/core';
2
- import { Logger } from '../../utils/logger.js';
3
- import { loadPackageJson } from '../../utils/package-json.js';
4
- import { existsSync } from 'node:fs';
5
- import { mkdir, readdir, writeFile, stat as fsStat } from 'node:fs/promises';
6
- import { join } from 'node:path';
7
-
8
- interface PackageJson {
9
- name: string;
10
- version: string;
11
- description: string;
12
- type: string;
13
- main: string;
14
- types: string;
15
- exports: Record<string, unknown>;
16
- files: string[];
17
- scripts: Record<string, string>;
18
- dependencies?: Record<string, string>;
19
- peerDependencies?: Record<string, string>;
20
- devDependencies?: Record<string, string>;
21
- keywords: string[];
22
- license: string;
23
- repository: {
24
- type: string;
25
- url: string;
26
- directory: string;
27
- };
28
- }
29
-
30
- export default class CreateLibReact extends Command {
31
- static override description = 'Create package.json files for synced @pie-lib packages';
32
-
33
- static override examples = [
34
- '<%= config.bin %> <%= command.id %>',
35
- '<%= config.bin %> <%= command.id %> --dry-run',
36
- ];
37
-
38
- static override flags = {
39
- 'dry-run': Flags.boolean({
40
- description: 'Show what would be created without making changes',
41
- default: false,
42
- }),
43
- verbose: Flags.boolean({
44
- char: 'v',
45
- description: 'Show detailed output',
46
- default: false,
47
- }),
48
- };
49
-
50
- private logger = new Logger();
51
-
52
- public async run(): Promise<void> {
53
- const { flags } = await this.parse(CreateLibReact);
54
-
55
- this.logger = new Logger(flags.verbose);
56
-
57
- this.logger.section('📦 Creating package.json files for @pie-lib packages');
58
- this.logger.info(` Mode: ${flags['dry-run'] ? 'DRY RUN' : 'LIVE'}\n`);
59
-
60
- const libReactDir = 'packages/lib-react';
61
- const packages = await readdir(libReactDir);
62
-
63
- let created = 0;
64
- let skipped = 0;
65
-
66
- for (const pkg of packages) {
67
- const pkgPath = join(libReactDir, pkg);
68
- const statResult = await fsStat(pkgPath);
69
-
70
- if (!statResult.isDirectory() || pkg === 'node_modules') {
71
- continue;
72
- }
73
-
74
- // Check if src directory exists
75
- const srcPath = join(pkgPath, 'src');
76
- if (!existsSync(srcPath)) {
77
- continue;
78
- }
79
-
80
- try {
81
- const packageJsonPath = join(pkgPath, 'package.json');
82
- if (existsSync(packageJsonPath)) {
83
- skipped++;
84
- this.logger.info(` ⏭️ ${pkg}: Already configured`);
85
- continue;
86
- }
87
-
88
- await this.createPackageJson(pkg, flags['dry-run']);
89
- await this.createViteConfig(pkg, flags['dry-run']);
90
- await this.createTsConfig(pkg, flags['dry-run']);
91
- created++;
92
- } catch (error) {
93
- this.logger.error(` ❌ ${pkg}: Error - ${error}`);
94
- }
95
- }
96
-
97
- this.logger.success(`\n✅ Created ${created} package configurations`);
98
- this.logger.info(`⏭️ Skipped ${skipped} existing packages`);
99
-
100
- if (!flags['dry-run'] && created > 0) {
101
- this.logger.section('\n💡 Next steps');
102
- this.logger.info(' 1. Run: bun install (to link workspace packages)');
103
- this.logger.info(' 2. Run: bun run build --filter="@pie-lib/*" (to build all lib packages)');
104
- this.logger.info(' 3. Update React elements to use the new workspace dependencies\n');
105
- }
106
- }
107
-
108
- private async getUpstreamPackageJson(pkgName: string): Promise<PackageJson | null> {
109
- const upstreamPath = join('../pie-lib/packages', pkgName, 'package.json');
110
- if (existsSync(upstreamPath)) {
111
- return (await loadPackageJson(upstreamPath)) as unknown as PackageJson;
112
- }
113
- return null;
114
- }
115
-
116
- private convertDependencies(deps: Record<string, string> | undefined): Record<string, string> {
117
- if (!deps) return {};
118
-
119
- const converted: Record<string, string> = {};
120
- for (const [name, version] of Object.entries(deps)) {
121
- if (name.startsWith('@pie-lib/')) {
122
- // Convert to workspace dependency
123
- converted[name] = 'workspace:*';
124
- } else {
125
- // Keep external dependencies as-is
126
- converted[name] = version;
127
- }
128
- }
129
- return converted;
130
- }
131
-
132
- private async createPackageJson(pkgName: string, dryRun: boolean = false): Promise<void> {
133
- const targetDir = join('packages/lib-react', pkgName);
134
- const targetPath = join(targetDir, 'package.json');
135
-
136
- // Skip if package.json already exists
137
- if (existsSync(targetPath)) {
138
- this.logger.info(` ⏭️ ${pkgName}: package.json already exists`);
139
- return;
140
- }
141
-
142
- // Get upstream package.json for dependencies
143
- const upstream = await this.getUpstreamPackageJson(pkgName);
144
-
145
- const packageJson: PackageJson = {
146
- name: `@pie-lib/${pkgName}`,
147
- version: '0.1.0',
148
- description:
149
- upstream?.description || `React implementation of @pie-lib/${pkgName} synced from pie-lib`,
150
- type: 'module',
151
- main: './dist/index.js',
152
- types: './dist/index.d.ts',
153
- exports: {
154
- '.': {
155
- types: './dist/index.d.ts',
156
- default: './dist/index.js',
157
- },
158
- },
159
- files: ['dist', 'src'],
160
- scripts: {
161
- build: 'vite build && tsc --emitDeclarationOnly',
162
- lint: 'biome check .',
163
- 'lint:fix': 'biome check --write .',
164
- },
165
- keywords: ['pie', 'pie-lib', 'react', pkgName],
166
- license: 'ISC',
167
- repository: {
168
- type: 'git',
169
- url: 'https://github.com/pie-framework/pie-elements-ng.git',
170
- directory: `packages/lib-react/${pkgName}`,
171
- },
172
- };
173
-
174
- // Convert dependencies
175
- if (upstream?.dependencies) {
176
- packageJson.dependencies = this.convertDependencies(upstream.dependencies);
177
- }
178
-
179
- if (upstream?.peerDependencies) {
180
- packageJson.peerDependencies = this.convertDependencies(upstream.peerDependencies);
181
- }
182
-
183
- // Add common devDependencies
184
- packageJson.devDependencies = {
185
- '@types/react': '^18.2.0',
186
- '@types/react-dom': '^18.2.0',
187
- '@vitejs/plugin-react': '^4.2.0',
188
- typescript: '^5.9.3',
189
- vite: '^6.0.0',
190
- };
191
-
192
- if (dryRun) {
193
- this.logger.info(` 🔍 ${pkgName}: Would create package.json`);
194
- } else {
195
- await mkdir(targetDir, { recursive: true });
196
- await writeFile(targetPath, `${JSON.stringify(packageJson, null, 2)}\n`, 'utf-8');
197
- this.logger.success(` ✨ ${pkgName}: Created package.json`);
198
- }
199
- }
200
-
201
- private async createViteConfig(pkgName: string, dryRun: boolean = false): Promise<void> {
202
- const targetDir = join('packages/lib-react', pkgName);
203
- const targetPath = join(targetDir, 'vite.config.ts');
204
-
205
- // Skip if vite.config.ts already exists
206
- if (existsSync(targetPath)) {
207
- return;
208
- }
209
-
210
- const viteConfig = `import react from '@vitejs/plugin-react';
211
- import { defineConfig } from 'vite';
212
-
213
- export default defineConfig({
214
- plugins: [react()],
215
- build: {
216
- lib: {
217
- entry: './src/index.ts',
218
- formats: ['es'],
219
- fileName: () => 'index.js',
220
- },
221
- rollupOptions: {
222
- external: [
223
- 'react',
224
- 'react-dom',
225
- 'react/jsx-runtime',
226
- 'prop-types',
227
- 'lodash',
228
- 'debug',
229
- 'classnames',
230
- /^@pie-lib\\//,
231
- /^@pie-framework\\//,
232
- /^@pie-element\\//,
233
- /^@mui\\//,
234
- /^@emotion\\//,
235
- /^@dnd-kit\\//,
236
- /^react-transition-group/,
237
- ],
238
- },
239
- outDir: 'dist',
240
- emptyOutDir: true,
241
- },
242
- });
243
- `;
244
-
245
- if (dryRun) {
246
- this.logger.info(` 🔍 ${pkgName}: Would create vite.config.ts`);
247
- } else {
248
- await writeFile(targetPath, viteConfig, 'utf-8');
249
- }
250
- }
251
-
252
- private async createTsConfig(pkgName: string, dryRun: boolean = false): Promise<void> {
253
- const targetDir = join('packages/lib-react', pkgName);
254
- const targetPath = join(targetDir, 'tsconfig.json');
255
-
256
- // Skip if tsconfig.json already exists
257
- if (existsSync(targetPath)) {
258
- return;
259
- }
260
-
261
- const tsConfig = {
262
- extends: '../../../tsconfig.base.json',
263
- compilerOptions: {
264
- outDir: './dist',
265
- rootDir: './src',
266
- declaration: true,
267
- emitDeclarationOnly: false,
268
- },
269
- include: ['src/**/*'],
270
- exclude: ['node_modules', 'dist', '**/*.spec.ts', '**/*.spec.tsx'],
271
- };
272
-
273
- if (dryRun) {
274
- this.logger.info(` 🔍 ${pkgName}: Would create tsconfig.json`);
275
- } else {
276
- await writeFile(targetPath, `${JSON.stringify(tsConfig, null, 2)}\n`, 'utf-8');
277
- }
278
- }
279
- }
@@ -1,306 +0,0 @@
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
- }