@pure-ds/core 0.4.37 → 0.5.2

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 (146) hide show
  1. package/dist/types/pds.d.ts +34 -11
  2. package/dist/types/public/assets/auto-definer-XWHRBQPU.d.ts +9 -0
  3. package/dist/types/public/assets/auto-definer-XWHRBQPU.d.ts.map +1 -0
  4. package/dist/types/public/assets/chunk-746HIXIK.d.ts +52 -0
  5. package/dist/types/public/assets/chunk-746HIXIK.d.ts.map +1 -0
  6. package/dist/types/public/assets/chunk-APJV5T3J.d.ts +106 -0
  7. package/dist/types/public/assets/chunk-APJV5T3J.d.ts.map +1 -0
  8. package/dist/types/public/assets/chunk-BEPKFFM7.d.ts +398 -0
  9. package/dist/types/public/assets/chunk-BEPKFFM7.d.ts.map +1 -0
  10. package/dist/types/public/assets/chunk-ISS7UH5H.d.ts +2424 -0
  11. package/dist/types/public/assets/chunk-ISS7UH5H.d.ts.map +1 -0
  12. package/dist/types/public/assets/chunk-RUPLQUDG.d.ts +582 -0
  13. package/dist/types/public/assets/chunk-RUPLQUDG.d.ts.map +1 -0
  14. package/dist/types/public/assets/chunk-USML4NYF.d.ts +18 -0
  15. package/dist/types/public/assets/chunk-USML4NYF.d.ts.map +1 -0
  16. package/dist/types/public/assets/chunk-Z47A3HLT.d.ts +3 -0
  17. package/dist/types/public/assets/chunk-Z47A3HLT.d.ts.map +1 -0
  18. package/dist/types/public/assets/js/auto-definer-HZLD2XF4.d.ts +9 -0
  19. package/dist/types/public/assets/js/auto-definer-HZLD2XF4.d.ts.map +1 -0
  20. package/dist/types/public/assets/js/chunk-6A6DFAIG.d.ts +88 -0
  21. package/dist/types/public/assets/js/chunk-6A6DFAIG.d.ts.map +1 -0
  22. package/dist/types/public/assets/js/chunk-746HIXIK.d.ts +52 -0
  23. package/dist/types/public/assets/js/chunk-746HIXIK.d.ts.map +1 -0
  24. package/dist/types/public/assets/js/chunk-A3TZGIYX.d.ts +4 -0
  25. package/dist/types/public/assets/js/chunk-A3TZGIYX.d.ts.map +1 -0
  26. package/dist/types/public/assets/js/chunk-BEPKFFM7.d.ts +398 -0
  27. package/dist/types/public/assets/js/chunk-BEPKFFM7.d.ts.map +1 -0
  28. package/dist/types/public/assets/js/chunk-OTTRJ5MB.d.ts +1695 -0
  29. package/dist/types/public/assets/js/chunk-OTTRJ5MB.d.ts.map +1 -0
  30. package/dist/types/public/assets/js/chunk-RBPKHG76.d.ts +747 -0
  31. package/dist/types/public/assets/js/chunk-RBPKHG76.d.ts.map +1 -0
  32. package/dist/types/public/assets/js/chunk-RUPLQUDG.d.ts +582 -0
  33. package/dist/types/public/assets/js/chunk-RUPLQUDG.d.ts.map +1 -0
  34. package/dist/types/public/assets/js/chunk-SMD2R3CX.d.ts +68 -0
  35. package/dist/types/public/assets/js/chunk-SMD2R3CX.d.ts.map +1 -0
  36. package/dist/types/public/assets/js/chunk-Y73DA2D5.d.ts +15 -0
  37. package/dist/types/public/assets/js/chunk-Y73DA2D5.d.ts.map +1 -0
  38. package/dist/types/public/assets/js/chunks/auto-definer-X7MSXKTU.d.ts +9 -0
  39. package/dist/types/public/assets/js/chunks/auto-definer-X7MSXKTU.d.ts.map +1 -0
  40. package/dist/types/public/assets/js/chunks/chunk-7BDQH5CT.d.ts +485 -0
  41. package/dist/types/public/assets/js/chunks/chunk-7BDQH5CT.d.ts.map +1 -0
  42. package/dist/types/public/assets/js/chunks/chunk-MWB3S7NG.d.ts +3 -0
  43. package/dist/types/public/assets/js/chunks/chunk-MWB3S7NG.d.ts.map +1 -0
  44. package/dist/types/public/assets/js/chunks/chunk-WIMLORAU.d.ts +5 -0
  45. package/dist/types/public/assets/js/chunks/chunk-WIMLORAU.d.ts.map +1 -0
  46. package/dist/types/public/assets/js/chunks/chunk-WN4Y2ELN.d.ts +833 -0
  47. package/dist/types/public/assets/js/chunks/chunk-WN4Y2ELN.d.ts.map +1 -0
  48. package/dist/types/public/assets/js/chunks/chunk-XQOUIBLO.d.ts +1687 -0
  49. package/dist/types/public/assets/js/chunks/chunk-XQOUIBLO.d.ts.map +1 -0
  50. package/dist/types/public/assets/js/chunks/font-loader-VN5SRNOD.d.ts +5 -0
  51. package/dist/types/public/assets/js/chunks/font-loader-VN5SRNOD.d.ts.map +1 -0
  52. package/dist/types/public/assets/js/chunks/pds-live-validation-BQPWN5JG.d.ts +38 -0
  53. package/dist/types/public/assets/js/chunks/pds-live-validation-BQPWN5JG.d.ts.map +1 -0
  54. package/dist/types/public/assets/js/common-WIAC4WAJ.d.ts +4 -0
  55. package/dist/types/public/assets/js/common-WIAC4WAJ.d.ts.map +1 -0
  56. package/dist/types/public/assets/js/pds-config-WEBAXXSM.d.ts +4 -0
  57. package/dist/types/public/assets/js/pds-config-WEBAXXSM.d.ts.map +1 -0
  58. package/dist/types/public/assets/js/pds-core/pds-generator.d.ts +700 -0
  59. package/dist/types/public/assets/js/pds-core/pds-generator.d.ts.map +1 -0
  60. package/dist/types/public/assets/js/pds-core/pds-utilities.d.ts +27 -0
  61. package/dist/types/public/assets/js/pds-core/pds-utilities.d.ts.map +1 -0
  62. package/dist/types/public/assets/js/pds-enums-DCBZHS64.d.ts +3 -0
  63. package/dist/types/public/assets/js/pds-enums-DCBZHS64.d.ts.map +1 -0
  64. package/dist/types/public/assets/js/pds-gen.d.ts +106 -0
  65. package/dist/types/public/assets/js/pds-gen.d.ts.map +1 -0
  66. package/dist/types/public/assets/js/pds-live.d.ts +11 -0
  67. package/dist/types/public/assets/js/pds-live.d.ts.map +1 -0
  68. package/dist/types/public/assets/js/pds-manager.d.ts +1047 -0
  69. package/dist/types/public/assets/js/pds-manager.d.ts.map +1 -0
  70. package/dist/types/public/assets/js/pds-ontology-2DICJXHO.d.ts +9 -0
  71. package/dist/types/public/assets/js/pds-ontology-2DICJXHO.d.ts.map +1 -0
  72. package/dist/types/public/assets/js/pds-query-B54LBKKR.d.ts +70 -0
  73. package/dist/types/public/assets/js/pds-query-B54LBKKR.d.ts.map +1 -0
  74. package/dist/types/public/assets/js/pds.d.ts +1 -18
  75. package/dist/types/public/assets/js/pds.d.ts.map +1 -1
  76. package/dist/types/public/assets/pds-ontology-ZO6TJHO3.d.ts +9 -0
  77. package/dist/types/public/assets/pds-ontology-ZO6TJHO3.d.ts.map +1 -0
  78. package/dist/types/src/js/common/pds-core/pds-config.d.ts +757 -0
  79. package/dist/types/src/js/common/pds-core/pds-config.d.ts.map +1 -0
  80. package/dist/types/src/js/common/pds-core/pds-enhancers.d.ts +28 -0
  81. package/dist/types/src/js/common/pds-core/pds-enhancers.d.ts.map +1 -0
  82. package/dist/types/src/js/common/pds-core/pds-enums.d.ts +87 -0
  83. package/dist/types/src/js/common/pds-core/pds-enums.d.ts.map +1 -0
  84. package/dist/types/src/js/common/pds-core/pds-generator.d.ts +700 -0
  85. package/dist/types/src/js/common/pds-core/pds-generator.d.ts.map +1 -0
  86. package/dist/types/src/js/common/pds-core/pds-ontology.d.ts +380 -0
  87. package/dist/types/src/js/common/pds-core/pds-ontology.d.ts.map +1 -0
  88. package/dist/types/src/js/common/pds-core/pds-paths.d.ts +37 -0
  89. package/dist/types/src/js/common/pds-core/pds-paths.d.ts.map +1 -0
  90. package/dist/types/src/js/common/pds-core/pds-query.d.ts +102 -0
  91. package/dist/types/src/js/common/pds-core/pds-query.d.ts.map +1 -0
  92. package/dist/types/src/js/common/pds-core/pds-registry.d.ts +35 -0
  93. package/dist/types/src/js/common/pds-core/pds-registry.d.ts.map +1 -0
  94. package/dist/types/src/js/common/pds-core/pds-utilities.d.ts +27 -0
  95. package/dist/types/src/js/common/pds-core/pds-utilities.d.ts.map +1 -0
  96. package/dist/types/src/js/pds-core/pds-generator.d.ts +38 -46
  97. package/dist/types/src/js/pds-core/pds-generator.d.ts.map +1 -1
  98. package/dist/types/src/js/pds-core/pds-live.d.ts +39 -0
  99. package/dist/types/src/js/pds-core/pds-live.d.ts.map +1 -0
  100. package/dist/types/src/js/pds-core/pds-runtime.d.ts +39 -0
  101. package/dist/types/src/js/pds-core/pds-runtime.d.ts.map +1 -0
  102. package/dist/types/src/js/pds-core/pds-start-helpers.d.ts +60 -0
  103. package/dist/types/src/js/pds-core/pds-start-helpers.d.ts.map +1 -0
  104. package/dist/types/src/js/pds-core/pds-utilities.d.ts +27 -0
  105. package/dist/types/src/js/pds-core/pds-utilities.d.ts.map +1 -0
  106. package/dist/types/src/js/pds-gen.d.ts +48 -0
  107. package/dist/types/src/js/pds-gen.d.ts.map +1 -0
  108. package/dist/types/src/js/pds-live-runtime.d.ts +7 -0
  109. package/dist/types/src/js/pds-live-runtime.d.ts.map +1 -0
  110. package/dist/types/src/js/pds-live-validation.d.ts +44 -0
  111. package/dist/types/src/js/pds-live-validation.d.ts.map +1 -0
  112. package/dist/types/src/js/pds-live.d.ts +11 -0
  113. package/dist/types/src/js/pds-live.d.ts.map +1 -0
  114. package/dist/types/src/js/pds-manager.d.ts +2 -0
  115. package/dist/types/src/js/pds-manager.d.ts.map +1 -0
  116. package/dist/types/src/js/pds.d.ts +6 -33
  117. package/dist/types/src/js/pds.d.ts.map +1 -1
  118. package/package.json +11 -12
  119. package/packages/pds-cli/bin/{generate-css-data.mjs → generate-css-data.js} +563 -563
  120. package/packages/pds-cli/bin/{generate-manifest.mjs → generate-manifest.js} +352 -352
  121. package/packages/pds-cli/bin/{pds-build-icons.mjs → pds-build-icons.js} +152 -152
  122. package/packages/pds-cli/bin/{pds-dx.mjs → pds-dx.js} +114 -114
  123. package/packages/pds-cli/bin/{pds-init-config.mjs → pds-init-config.js} +34 -34
  124. package/packages/pds-cli/bin/{pds-setup-copilot.mjs → pds-setup-copilot.js} +106 -106
  125. package/packages/pds-cli/bin/{pds-static.mjs → pds-static.js} +597 -581
  126. package/packages/pds-cli/bin/{pds.mjs → pds.js} +127 -127
  127. package/packages/pds-cli/bin/postinstall.mjs +522 -563
  128. package/packages/pds-cli/bin/{sync-assets.mjs → sync-assets.js} +251 -251
  129. package/packages/pds-cli/lib/{asset-roots.mjs → asset-roots.js} +47 -47
  130. package/packages/pds-cli/lib/{fs-writer.mjs → fs-writer.js} +75 -75
  131. package/public/assets/js/app.js +95 -118
  132. package/public/assets/js/pds-manager.js +3251 -0
  133. package/public/assets/js/pds.js +10 -3201
  134. package/readme.md +2014 -2016
  135. package/src/js/pds-core/pds-enhancers.js +518 -518
  136. package/src/js/pds-core/pds-enums.js +86 -86
  137. package/src/js/pds-core/pds-generator.js +255 -185
  138. package/src/js/pds-core/pds-live.js +434 -0
  139. package/src/js/pds-core/pds-paths.js +109 -109
  140. package/src/js/pds-core/pds-registry.js +79 -79
  141. package/src/js/pds-core/pds-runtime.js +184 -0
  142. package/src/js/pds-core/pds-start-helpers.js +405 -0
  143. package/src/js/pds.d.ts +34 -11
  144. package/src/js/pds.js +43 -1182
  145. package/getting-started.md +0 -626
  146. package/src/js/pds-core/pds.d.ts +0 -129
@@ -1,252 +1,252 @@
1
- #!/usr/bin/env node
2
-
3
- import { readFile, writeFile, mkdir, copyFile, readdir, stat } from 'fs/promises';
4
- import { createHash } from 'crypto';
5
- import path from 'path';
6
- import { fileURLToPath } from 'url';
7
-
8
- const __dirname = path.dirname(fileURLToPath(import.meta.url));
9
-
10
- // Find the PDS package root, whether we're running from the package itself or from node_modules
11
- async function findPdsRoot() {
12
- const currentDir = __dirname;
13
-
14
- // If running from the package itself (development)
15
- if (currentDir.includes('packages/pds-cli/bin')) {
16
- return path.resolve(currentDir, '../../../');
17
- }
18
-
19
- // If running from node_modules (consumer app)
20
- // The structure would be: node_modules/@pure-ds/core/packages/pds-cli/bin
21
- if (currentDir.includes('node_modules')) {
22
- let dir = currentDir;
23
- while (dir !== path.dirname(dir)) {
24
- // Support both legacy scoped name and new unscoped name
25
- // node_modules/@pure-ds/core/... OR node_modules/pure-ds/...
26
- const base = path.basename(dir);
27
- const parent = path.basename(path.dirname(dir));
28
- if ((base === 'core' && parent === '@pure-ds') || base === 'pure-ds') {
29
- return dir;
30
- }
31
- dir = path.dirname(dir);
32
- }
33
- }
34
-
35
- // Fallback - navigate up to find package.json with correct name
36
- let dir = currentDir;
37
- while (dir !== path.dirname(dir)) {
38
- try {
39
- const packagePath = path.join(dir, 'package.json');
40
- const pkg = JSON.parse(await readFile(packagePath, 'utf8'));
41
- if (pkg.name === '@pure-ds/core' || pkg.name === 'pure-ds') {
42
- return dir;
43
- }
44
- } catch (e) {
45
- // Continue searching
46
- }
47
- dir = path.dirname(dir);
48
- }
49
-
50
- throw new Error('Could not find PDS package root');
51
- }
52
-
53
- /**
54
- * Sync PDS assets to consuming app's public directory
55
- * Copies:
56
- * - public/pds/components/* (or legacy public/auto-define/*) -> <targetDir>/components/*
57
- * - (icons no longer synced; static export focuses on components and styles)
58
- *
59
- * Usage: node node_modules/pure-ds/packages/pds-cli/bin/sync-assets.js [options]
60
- * Options:
61
- * --target=<path> Target directory (default: ./public)
62
- * --force Overwrite user-modified files
63
- * --dry-run Show what would be synced without copying
64
- * --verbose, -v Show detailed sync information
65
- */
66
-
67
- async function syncAssets(options = {}) {
68
- const {
69
- targetDir = './public',
70
- force = false,
71
- dryRun = false,
72
- verbose = false
73
- } = options;
74
-
75
- console.log('🔄 Syncing PDS assets...');
76
-
77
- // Find PDS package root
78
- const pdsRoot = await findPdsRoot();
79
-
80
- // Prefer new packaged location; fall back to legacy paths
81
- let autoDefineSource = path.join(pdsRoot, 'public/assets/pds/components');
82
- try {
83
- await stat(autoDefineSource);
84
- } catch {
85
- try {
86
- autoDefineSource = path.join(pdsRoot, 'public/pds/components');
87
- await stat(autoDefineSource);
88
- } catch {
89
- autoDefineSource = path.join(pdsRoot, 'public/auto-define');
90
- }
91
- }
92
-
93
- // Target directories
94
- const autoDefineTarget = path.join(process.cwd(), targetDir, 'components');
95
-
96
- // Load or create asset tracking file
97
- const trackingFile = path.join(process.cwd(), '.pds-assets.json');
98
- let tracking = {};
99
-
100
- try {
101
- const trackingData = await readFile(trackingFile, 'utf-8');
102
- tracking = JSON.parse(trackingData);
103
- } catch (e) {
104
- // First run or corrupted file
105
- tracking = {
106
- version: '0.1.0',
107
- lastSync: null,
108
- checksums: {},
109
- userModified: {}
110
- };
111
- }
112
-
113
- const newChecksums = {};
114
- const conflicts = [];
115
- const synced = [];
116
-
117
- // Helper to calculate file hash
118
- const getFileHash = async (filePath) => {
119
- try {
120
- const content = await readFile(filePath);
121
- return createHash('sha256').update(content).digest('hex');
122
- } catch (e) {
123
- return null;
124
- }
125
- };
126
-
127
- // Helper to sync a single file
128
- const syncFile = async (sourcePath, targetPath, relativeKey) => {
129
- try {
130
- // Ensure target directory exists
131
- await mkdir(path.dirname(targetPath), { recursive: true });
132
-
133
- const sourceHash = await getFileHash(sourcePath);
134
- const targetHash = await getFileHash(targetPath);
135
- const knownHash = tracking.checksums[relativeKey];
136
-
137
- newChecksums[relativeKey] = sourceHash;
138
-
139
- // Conflict detection
140
- if (targetHash && targetHash !== sourceHash && targetHash !== knownHash) {
141
- conflicts.push({
142
- file: relativeKey,
143
- path: targetPath,
144
- reason: 'User modified file conflicts with PDS update'
145
- });
146
-
147
- if (!force) {
148
- if (verbose) {
149
- console.log(`⚠️ Skipping ${relativeKey} (user modified)`);
150
- }
151
- tracking.userModified[relativeKey] = targetHash;
152
- return;
153
- }
154
- }
155
-
156
- // Copy file if needed
157
- if (!targetHash || targetHash !== sourceHash || force) {
158
- if (!dryRun) {
159
- await copyFile(sourcePath, targetPath);
160
- }
161
- synced.push(relativeKey);
162
-
163
- if (verbose) {
164
- console.log(`📁 ${dryRun ? '[DRY RUN] ' : ''}Synced ${relativeKey}`);
165
- }
166
- }
167
- } catch (e) {
168
- console.warn(`⚠️ Could not sync ${relativeKey}:`, e.message);
169
- }
170
- };
171
-
172
- // Helper to sync a directory
173
- const syncDirectory = async (sourceDir, targetDir, prefix = '') => {
174
- try {
175
- await mkdir(targetDir, { recursive: true });
176
- const files = await readdir(sourceDir);
177
-
178
- for (const file of files) {
179
- const sourcePath = path.join(sourceDir, file);
180
- const targetPath = path.join(targetDir, file);
181
- const relativeKey = `${prefix}${file}`;
182
-
183
- const sourceStat = await stat(sourcePath);
184
- if (sourceStat.isDirectory()) {
185
- await syncDirectory(sourcePath, targetPath, `${relativeKey}/`);
186
- continue;
187
- }
188
-
189
- await syncFile(sourcePath, targetPath, relativeKey);
190
- }
191
- } catch (e) {
192
- console.warn(`⚠️ Could not sync ${sourceDir}:`, e.message);
193
- }
194
- };
195
-
196
- // Sync components directory
197
- if (verbose) {
198
- console.log('📁 Syncing components...');
199
- }
200
- await syncDirectory(autoDefineSource, autoDefineTarget, 'components/');
201
-
202
- // Note: icons are not synced in this flow; use pds:export if needed
203
-
204
- // Update tracking file
205
- if (!dryRun) {
206
- tracking.checksums = { ...tracking.checksums, ...newChecksums };
207
- tracking.lastSync = new Date().toISOString();
208
- await writeFile(trackingFile, JSON.stringify(tracking, null, 2));
209
- }
210
-
211
- // Report results
212
- console.log(`✅ Sync complete: ${synced.length} files updated`);
213
-
214
- if (conflicts.length > 0) {
215
- console.log(`⚠️ ${conflicts.length} conflicts detected:`);
216
- conflicts.forEach(c => {
217
- console.log(` - ${c.file}: ${c.reason}`);
218
- });
219
- console.log(' Use --force to overwrite user modifications');
220
- }
221
-
222
- if (verbose) {
223
- console.log(`📊 Tracking file: ${trackingFile}`);
224
- console.log(`📁 Components: ${autoDefineTarget}`);
225
- }
226
-
227
- return {
228
- synced: synced.length,
229
- conflicts: conflicts.length,
230
- tracking
231
- };
232
- }
233
-
234
- // CLI interface
235
- if (import.meta.url === `file://${process.argv[1]}`) {
236
- const args = process.argv.slice(2);
237
- const options = {
238
- force: args.includes('--force'),
239
- dryRun: args.includes('--dry-run'),
240
- verbose: args.includes('--verbose') || args.includes('-v'),
241
- targetDir: args.find(arg => arg.startsWith('--target='))?.split('=')[1] || './public'
242
- };
243
-
244
- try {
245
- await syncAssets(options);
246
- } catch (error) {
247
- console.error('❌ Sync failed:', error.message);
248
- process.exit(1);
249
- }
250
- }
251
-
1
+ #!/usr/bin/env node
2
+
3
+ import { readFile, writeFile, mkdir, copyFile, readdir, stat } from 'fs/promises';
4
+ import { createHash } from 'crypto';
5
+ import path from 'path';
6
+ import { fileURLToPath } from 'url';
7
+
8
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
9
+
10
+ // Find the PDS package root, whether we're running from the package itself or from node_modules
11
+ async function findPdsRoot() {
12
+ const currentDir = __dirname;
13
+
14
+ // If running from the package itself (development)
15
+ if (currentDir.includes('packages/pds-cli/bin')) {
16
+ return path.resolve(currentDir, '../../../');
17
+ }
18
+
19
+ // If running from node_modules (consumer app)
20
+ // The structure would be: node_modules/@pure-ds/core/packages/pds-cli/bin
21
+ if (currentDir.includes('node_modules')) {
22
+ let dir = currentDir;
23
+ while (dir !== path.dirname(dir)) {
24
+ // Support both legacy scoped name and new unscoped name
25
+ // node_modules/@pure-ds/core/... OR node_modules/pure-ds/...
26
+ const base = path.basename(dir);
27
+ const parent = path.basename(path.dirname(dir));
28
+ if ((base === 'core' && parent === '@pure-ds') || base === 'pure-ds') {
29
+ return dir;
30
+ }
31
+ dir = path.dirname(dir);
32
+ }
33
+ }
34
+
35
+ // Fallback - navigate up to find package.json with correct name
36
+ let dir = currentDir;
37
+ while (dir !== path.dirname(dir)) {
38
+ try {
39
+ const packagePath = path.join(dir, 'package.json');
40
+ const pkg = JSON.parse(await readFile(packagePath, 'utf8'));
41
+ if (pkg.name === '@pure-ds/core' || pkg.name === 'pure-ds') {
42
+ return dir;
43
+ }
44
+ } catch (e) {
45
+ // Continue searching
46
+ }
47
+ dir = path.dirname(dir);
48
+ }
49
+
50
+ throw new Error('Could not find PDS package root');
51
+ }
52
+
53
+ /**
54
+ * Sync PDS assets to consuming app's public directory
55
+ * Copies:
56
+ * - public/pds/components/* (or legacy public/auto-define/*) -> <targetDir>/components/*
57
+ * - (icons no longer synced; static export focuses on components and styles)
58
+ *
59
+ * Usage: node node_modules/pure-ds/packages/pds-cli/bin/sync-assets.js [options]
60
+ * Options:
61
+ * --target=<path> Target directory (default: ./public)
62
+ * --force Overwrite user-modified files
63
+ * --dry-run Show what would be synced without copying
64
+ * --verbose, -v Show detailed sync information
65
+ */
66
+
67
+ async function syncAssets(options = {}) {
68
+ const {
69
+ targetDir = './public',
70
+ force = false,
71
+ dryRun = false,
72
+ verbose = false
73
+ } = options;
74
+
75
+ console.log('🔄 Syncing PDS assets...');
76
+
77
+ // Find PDS package root
78
+ const pdsRoot = await findPdsRoot();
79
+
80
+ // Prefer new packaged location; fall back to legacy paths
81
+ let autoDefineSource = path.join(pdsRoot, 'public/assets/pds/components');
82
+ try {
83
+ await stat(autoDefineSource);
84
+ } catch {
85
+ try {
86
+ autoDefineSource = path.join(pdsRoot, 'public/pds/components');
87
+ await stat(autoDefineSource);
88
+ } catch {
89
+ autoDefineSource = path.join(pdsRoot, 'public/auto-define');
90
+ }
91
+ }
92
+
93
+ // Target directories
94
+ const autoDefineTarget = path.join(process.cwd(), targetDir, 'components');
95
+
96
+ // Load or create asset tracking file
97
+ const trackingFile = path.join(process.cwd(), '.pds-assets.json');
98
+ let tracking = {};
99
+
100
+ try {
101
+ const trackingData = await readFile(trackingFile, 'utf-8');
102
+ tracking = JSON.parse(trackingData);
103
+ } catch (e) {
104
+ // First run or corrupted file
105
+ tracking = {
106
+ version: '0.1.0',
107
+ lastSync: null,
108
+ checksums: {},
109
+ userModified: {}
110
+ };
111
+ }
112
+
113
+ const newChecksums = {};
114
+ const conflicts = [];
115
+ const synced = [];
116
+
117
+ // Helper to calculate file hash
118
+ const getFileHash = async (filePath) => {
119
+ try {
120
+ const content = await readFile(filePath);
121
+ return createHash('sha256').update(content).digest('hex');
122
+ } catch (e) {
123
+ return null;
124
+ }
125
+ };
126
+
127
+ // Helper to sync a single file
128
+ const syncFile = async (sourcePath, targetPath, relativeKey) => {
129
+ try {
130
+ // Ensure target directory exists
131
+ await mkdir(path.dirname(targetPath), { recursive: true });
132
+
133
+ const sourceHash = await getFileHash(sourcePath);
134
+ const targetHash = await getFileHash(targetPath);
135
+ const knownHash = tracking.checksums[relativeKey];
136
+
137
+ newChecksums[relativeKey] = sourceHash;
138
+
139
+ // Conflict detection
140
+ if (targetHash && targetHash !== sourceHash && targetHash !== knownHash) {
141
+ conflicts.push({
142
+ file: relativeKey,
143
+ path: targetPath,
144
+ reason: 'User modified file conflicts with PDS update'
145
+ });
146
+
147
+ if (!force) {
148
+ if (verbose) {
149
+ console.log(`⚠️ Skipping ${relativeKey} (user modified)`);
150
+ }
151
+ tracking.userModified[relativeKey] = targetHash;
152
+ return;
153
+ }
154
+ }
155
+
156
+ // Copy file if needed
157
+ if (!targetHash || targetHash !== sourceHash || force) {
158
+ if (!dryRun) {
159
+ await copyFile(sourcePath, targetPath);
160
+ }
161
+ synced.push(relativeKey);
162
+
163
+ if (verbose) {
164
+ console.log(`📁 ${dryRun ? '[DRY RUN] ' : ''}Synced ${relativeKey}`);
165
+ }
166
+ }
167
+ } catch (e) {
168
+ console.warn(`⚠️ Could not sync ${relativeKey}:`, e.message);
169
+ }
170
+ };
171
+
172
+ // Helper to sync a directory
173
+ const syncDirectory = async (sourceDir, targetDir, prefix = '') => {
174
+ try {
175
+ await mkdir(targetDir, { recursive: true });
176
+ const files = await readdir(sourceDir);
177
+
178
+ for (const file of files) {
179
+ const sourcePath = path.join(sourceDir, file);
180
+ const targetPath = path.join(targetDir, file);
181
+ const relativeKey = `${prefix}${file}`;
182
+
183
+ const sourceStat = await stat(sourcePath);
184
+ if (sourceStat.isDirectory()) {
185
+ await syncDirectory(sourcePath, targetPath, `${relativeKey}/`);
186
+ continue;
187
+ }
188
+
189
+ await syncFile(sourcePath, targetPath, relativeKey);
190
+ }
191
+ } catch (e) {
192
+ console.warn(`⚠️ Could not sync ${sourceDir}:`, e.message);
193
+ }
194
+ };
195
+
196
+ // Sync components directory
197
+ if (verbose) {
198
+ console.log('📁 Syncing components...');
199
+ }
200
+ await syncDirectory(autoDefineSource, autoDefineTarget, 'components/');
201
+
202
+ // Note: icons are not synced in this flow; use pds:export if needed
203
+
204
+ // Update tracking file
205
+ if (!dryRun) {
206
+ tracking.checksums = { ...tracking.checksums, ...newChecksums };
207
+ tracking.lastSync = new Date().toISOString();
208
+ await writeFile(trackingFile, JSON.stringify(tracking, null, 2));
209
+ }
210
+
211
+ // Report results
212
+ console.log(`✅ Sync complete: ${synced.length} files updated`);
213
+
214
+ if (conflicts.length > 0) {
215
+ console.log(`⚠️ ${conflicts.length} conflicts detected:`);
216
+ conflicts.forEach(c => {
217
+ console.log(` - ${c.file}: ${c.reason}`);
218
+ });
219
+ console.log(' Use --force to overwrite user modifications');
220
+ }
221
+
222
+ if (verbose) {
223
+ console.log(`📊 Tracking file: ${trackingFile}`);
224
+ console.log(`📁 Components: ${autoDefineTarget}`);
225
+ }
226
+
227
+ return {
228
+ synced: synced.length,
229
+ conflicts: conflicts.length,
230
+ tracking
231
+ };
232
+ }
233
+
234
+ // CLI interface
235
+ if (import.meta.url === `file://${process.argv[1]}`) {
236
+ const args = process.argv.slice(2);
237
+ const options = {
238
+ force: args.includes('--force'),
239
+ dryRun: args.includes('--dry-run'),
240
+ verbose: args.includes('--verbose') || args.includes('-v'),
241
+ targetDir: args.find(arg => arg.startsWith('--target='))?.split('=')[1] || './public'
242
+ };
243
+
244
+ try {
245
+ await syncAssets(options);
246
+ } catch (error) {
247
+ console.error('❌ Sync failed:', error.message);
248
+ process.exit(1);
249
+ }
250
+ }
251
+
252
252
  export { syncAssets };
@@ -1,47 +1,47 @@
1
- import path from 'path';
2
- import { resolvePublicAssetURL, getPublicRootCandidate, __internal } from '../../../src/js/pds-core/pds-paths.js';
3
-
4
- const URL_PATTERN = __internal.URL_PATTERN;
5
- const PDS_SEGMENT = __internal.DEFAULT_SEGMENT;
6
-
7
- function trimTrailingSeparators(value) {
8
- return value.replace(/[\\/]+$/, '');
9
- }
10
-
11
- export function ensurePdsPath(input) {
12
- if (!input || typeof input !== 'string') return input;
13
- let target = trimTrailingSeparators(input);
14
- if (/[\\/]pds$/i.test(target)) {
15
- return target;
16
- }
17
- return path.join(target, PDS_SEGMENT);
18
- }
19
-
20
- export function resolvePublicAssetDirectory(config, options = {}) {
21
- const webRootPath = options.webRootPath;
22
- const cwd = options.cwd || process.cwd();
23
- const overrideRoot = options.overrideRoot;
24
- const candidate = (overrideRoot ?? getPublicRootCandidate(config)) || '';
25
-
26
- if (candidate && typeof candidate === 'string' && !URL_PATTERN.test(candidate.trim())) {
27
- let target = candidate.trim();
28
- if (target) {
29
- if (!path.isAbsolute(target)) {
30
- target = path.resolve(cwd, target);
31
- }
32
- return ensurePdsPath(target);
33
- }
34
- }
35
-
36
- if (webRootPath) {
37
- return ensurePdsPath(path.join(webRootPath, 'assets'));
38
- }
39
-
40
- return ensurePdsPath(path.resolve(cwd, 'public', 'assets'));
41
- }
42
-
43
- export function isUrlLike(value) {
44
- return typeof value === 'string' && URL_PATTERN.test(value.trim());
45
- }
46
-
47
- export { resolvePublicAssetURL, getPublicRootCandidate };
1
+ import path from 'path';
2
+ import { resolvePublicAssetURL, getPublicRootCandidate, __internal } from '../../../src/js/pds-core/pds-paths.js';
3
+
4
+ const URL_PATTERN = __internal.URL_PATTERN;
5
+ const PDS_SEGMENT = __internal.DEFAULT_SEGMENT;
6
+
7
+ function trimTrailingSeparators(value) {
8
+ return value.replace(/[\\/]+$/, '');
9
+ }
10
+
11
+ export function ensurePdsPath(input) {
12
+ if (!input || typeof input !== 'string') return input;
13
+ let target = trimTrailingSeparators(input);
14
+ if (/[\\/]pds$/i.test(target)) {
15
+ return target;
16
+ }
17
+ return path.join(target, PDS_SEGMENT);
18
+ }
19
+
20
+ export function resolvePublicAssetDirectory(config, options = {}) {
21
+ const webRootPath = options.webRootPath;
22
+ const cwd = options.cwd || process.cwd();
23
+ const overrideRoot = options.overrideRoot;
24
+ const candidate = (overrideRoot ?? getPublicRootCandidate(config)) || '';
25
+
26
+ if (candidate && typeof candidate === 'string' && !URL_PATTERN.test(candidate.trim())) {
27
+ let target = candidate.trim();
28
+ if (target) {
29
+ if (!path.isAbsolute(target)) {
30
+ target = path.resolve(cwd, target);
31
+ }
32
+ return ensurePdsPath(target);
33
+ }
34
+ }
35
+
36
+ if (webRootPath) {
37
+ return ensurePdsPath(path.join(webRootPath, 'assets'));
38
+ }
39
+
40
+ return ensurePdsPath(path.resolve(cwd, 'public', 'assets'));
41
+ }
42
+
43
+ export function isUrlLike(value) {
44
+ return typeof value === 'string' && URL_PATTERN.test(value.trim());
45
+ }
46
+
47
+ export { resolvePublicAssetURL, getPublicRootCandidate };