* Deploy full packages to the FormKit Cloudfront CDN. * @param {string} version
(version)
| 63 | * @param {string} version |
| 64 | */ |
| 65 | async function deployESM(version) { |
| 66 | let uploaded = 0 |
| 67 | let failed = 0 |
| 68 | const uploads = [] |
| 69 | msg.loader.start('» uploading files') |
| 70 | getPackages().forEach((pkg) => { |
| 71 | const matches = globSync(`packages/${pkg}/dist/**/*`) |
| 72 | matches.forEach((file) => { |
| 73 | if ( |
| 74 | !lstatSync(file).isDirectory() && |
| 75 | (file.endsWith('index.mjs') || file.endsWith('.css')) |
| 76 | ) { |
| 77 | uploads.push(sendFile(version, pkg, file)) |
| 78 | } |
| 79 | }) |
| 80 | }) |
| 81 | const results = await Promise.all(uploads) |
| 82 | results.forEach((result) => (result ? uploaded++ : failed++)) |
| 83 | if (failed) { |
| 84 | msg.error('Not all files were deployed. ' + failed + ' did not upload.') |
| 85 | } else { |
| 86 | msg.loader.succeed( |
| 87 | 'Deployment successful. Uploaded ' + uploaded + ' files.' |
| 88 | ) |
| 89 | msg.loader.start('» Refreshing CDN assets') |
| 90 | const { |
| 91 | Invalidation: { Id }, |
| 92 | } = await cloudfront.send( |
| 93 | new CreateInvalidationCommand({ |
| 94 | DistributionId: distributionId, |
| 95 | InvalidationBatch: { |
| 96 | CallerReference: String(new Date().getTime()), |
| 97 | Paths: { |
| 98 | Quantity: results.length, |
| 99 | Items: results.map((file) => '/' + file), |
| 100 | }, |
| 101 | }, |
| 102 | }) |
| 103 | ) |
| 104 | await waitForInvalidations(Id) |
| 105 | msg.loader.succeed('CDN Updated Successfully') |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | async function waitForInvalidations(Id) { |
| 110 | await new Promise((r) => setTimeout(r, 3000)) |
no test coverage detected