MCPcopy Create free account
hub / github.com/formkit/formkit / sendFile

Function sendFile

scripts/deploy.mjs:136–170  ·  view source on GitHub ↗

* Upload an individual file to s3. * @param {string} version - The version being uploaded. * @param {string} pkg - The name of the package. * @param {string} file - The specific file being uploaded.

(version, pkg, file)

Source from the content-addressed store, hash-verified

134 * @param {string} file - The specific file being uploaded.
135 */
136async function sendFile(version, pkg, file) {
137 try {
138 const Body = await prepForDistribution(
139 await readFile(file, { encoding: 'utf8' }),
140 version,
141 !file.endsWith('.css') // dont minify css
142 )
143 let mime = 'application/javascript'
144 let Key = `${pkg}@${version}`
145 if (file.endsWith('.ts')) {
146 mime = 'application/x-typescript'
147 } else if (file.endsWith('.css')) {
148 Key = `themes@${version}-${
149 file.substring(`packages/${pkg}/dist/`.length).split('/')[0]
150 }.css`
151 mime = 'text/css'
152 }
153 const params = {
154 Bucket: 'cdn.formk.it',
155 Key,
156 Body,
157 ContentType: mime,
158 }
159 try {
160 await s3.send(new PutObjectCommand(params))
161 return Key
162 } catch (err) {
163 console.error(err)
164 return false
165 }
166 } catch (err) {
167 console.error('Unable to read file', file)
168 throw new Error(err)
169 }
170}
171
172/**
173 * Prepare the file for ESM distribution.

Callers 1

deployESMFunction · 0.85

Calls 1

prepForDistributionFunction · 0.85

Tested by

no test coverage detected