-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sls-rspack): support user supplied scripts
- Loading branch information
1 parent
26f0149
commit 22eac3a
Showing
17 changed files
with
184 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,25 @@ | ||
import { lib1Export } from '@kitchenshelf/path-import-libs/lib1/lib1'; | ||
import validateIsin from 'isin-validator'; | ||
import { readFileSync } from 'node:fs'; | ||
import path from 'node:path'; | ||
import sharp from 'sharp'; | ||
|
||
export async function handler(event: string) { | ||
const isInvalid = validateIsin(event); | ||
const imagePath = path.join(__dirname, '../my-image.jpeg'); | ||
const imageBuffer = readFileSync(imagePath); | ||
|
||
const { info } = await sharp(imageBuffer) | ||
.raw() | ||
.toBuffer({ resolveWithObject: true }); | ||
|
||
return { | ||
statusCode: lib1Export(!!isInvalid), | ||
body: JSON.stringify({ | ||
handler: 'App3', | ||
message: isInvalid ? 'ISIN is invalid!' : 'ISIN is fine!', | ||
input: event, | ||
info, | ||
}), | ||
}; | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import type { RspackServerlessPlugin } from './serverless-rspack.js'; | ||
import { execSync } from 'node:child_process'; | ||
|
||
export async function scripts(this: RspackServerlessPlugin) { | ||
if (this.pluginOptions.scripts && this.pluginOptions.scripts.length > 0) { | ||
this.log.verbose( | ||
`[Scripts] Running ${this.pluginOptions.scripts.length} scripts` | ||
); | ||
const startScripts = Date.now(); | ||
for (const [index, script] of this.pluginOptions.scripts.entries()) { | ||
const startZip = Date.now(); | ||
try { | ||
execSync(script, { | ||
cwd: this.serviceDirPath, | ||
stdio: this.options.verbose ? 'inherit' : 'ignore', | ||
env: { | ||
...process.env, | ||
KS_SERVICE_DIR: this.serviceDirPath, | ||
KS_BUILD_OUTPUT_FOLDER: this.buildOutputFolder, | ||
KS_PACKAGE_OUTPUT_FOLDER: this.packageOutputFolder, | ||
}, | ||
}); | ||
this.log.verbose( | ||
`[Performance] Script ${index + 1} of ${ | ||
this.pluginOptions.scripts.length | ||
} [${Date.now() - startZip} ms]` | ||
); | ||
} catch (error) { | ||
throw new this.serverless.classes.Error( | ||
`Failed to execute script: ${script}` | ||
); | ||
} | ||
} | ||
this.log.verbose( | ||
`[Performance] Scripts total execution time for service ${ | ||
this.serverless.service.service | ||
} [${Date.now() - startScripts} ms]` | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.