@kitchenshelf/serverless-rspack
Version:
[Serverless Framework](https://www.serverless.com) plugin for zero-config JavaScript and TypeScript code bundling using the high performance Rust-based JavaScript bundler [`rspack`](https://rspack.dev/guide/start/introduction)
57 lines • 3.24 kB
JavaScript
import { __awaiter } from "tslib";
import { execSync } from 'node:child_process';
export function scripts() {
return __awaiter(this, void 0, void 0, function* () {
runFunctionScripts.call(this);
runGlobalScripts.call(this);
});
}
function runFunctionScripts() {
const scriptEntries = Object.entries(this.functionScripts);
if (scriptEntries.length > 0) {
const startScripts = Date.now();
for (const [functionName, scripts] of scriptEntries) {
this.log.verbose(`[Scripts] Running ${scripts.length} scripts for function ${functionName}`);
const startFunctionScripts = Date.now();
for (const [index, script] of scripts.entries()) {
const startScript = Date.now();
try {
execSync(script, {
cwd: this.serviceDirPath +
`/${this.buildOutputFolder}/${functionName}`,
stdio: this.options.verbose ? 'inherit' : 'ignore',
env: Object.assign(Object.assign({}, process.env), { KS_SERVICE_DIR: this.serviceDirPath, KS_BUILD_OUTPUT_FOLDER: this.buildOutputFolder, KS_PACKAGE_OUTPUT_FOLDER: this.packageOutputFolder, KS_FUNCTION_NAME: functionName }),
});
this.log.verbose(`[Performance] Script ${index + 1} of ${scripts.length} [${Date.now() - startScript} ms]`);
}
catch (error) {
throw new this.serverless.classes.Error(`Failed to execute script: ${script}\nError: ${error.message}`);
}
}
this.log.verbose(`[Performance] Scripts total execution time for function ${functionName} [${Date.now() - startFunctionScripts} ms]`);
}
this.log.verbose(`[Performance] Scripts total execution time for all functions in service ${this.serverless.service.service} [${Date.now() - startScripts} ms]`);
}
}
function runGlobalScripts() {
if (this.pluginOptions.scripts && this.pluginOptions.scripts.length > 0) {
this.log.verbose(`[Scripts] Running ${this.pluginOptions.scripts.length} global scripts`);
const startScripts = Date.now();
for (const [index, script] of this.pluginOptions.scripts.entries()) {
const startScript = Date.now();
try {
execSync(script, {
cwd: this.serviceDirPath,
stdio: this.options.verbose ? 'inherit' : 'ignore',
env: Object.assign(Object.assign({}, 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() - startScript} ms]`);
}
catch (error) {
throw new this.serverless.classes.Error(`Failed to execute script: ${script}\nError: ${error.message}`);
}
}
this.log.verbose(`[Performance] Scripts total execution time for global scripts [${Date.now() - startScripts} ms]`);
}
}
//# sourceMappingURL=scripts.js.map