PromucFlow_constructor/app/client/packages/rts/build.js
Shrikant Sharat Kandula d6fbaa5372
chore: Port ctl code to Typescript (#37606)
This PR converts the Javscript code of the `ctl` module, into
Typescript, and in the process already fixing two small bugs that went
undetected because... of lack of good type checking.

The linting exceptions are still there and will be removed in the next
PR. Didn't want to change anymore than necessary or Git will detect
these changes as "new files" instead of as "renames".


## Automation

/test sanity

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/11949059369>
> Commit: e156dacbc5cb513030052535c3d1f25ce1c7f222
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=11949059369&attempt=1"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.Sanity`
> Spec:
> <hr>Thu, 21 Nov 2024 08:45:48 UTC
<!-- end of auto-generated comment: Cypress test results  -->


## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [x] No


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

## Release Notes

- **New Features**
- Introduced TypeScript support by updating entry points and adding type
definitions for `nodemailer` and `readline-sync`.
- Enhanced logging and error handling functionalities across various
modules.

- **Improvements**
- Transitioned from CommonJS to ES module syntax for better
compatibility and maintainability.
  - Improved clarity and structure in command handling and test files.

- **Bug Fixes**
- Corrected regex patterns and variable declarations in tests to enhance
reliability.

- **Chores**
- Updated dependencies and refined module exports for better
organization.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2024-11-21 15:37:11 +05:30

92 lines
2.4 KiB
JavaScript

const { dependencies: packageDeps } = require("./package.json");
const esbuild = require("esbuild");
const fs = require("fs").promises;
// List of external workflow packages (EE only)
const externalWorkflowPackages = [];
async function ensureDirectoryExistence(dirname) {
try {
await fs.mkdir(dirname, { recursive: true });
} catch (err) {
if (err.code !== "EEXIST") {
throw err;
}
}
}
async function createFile(dir, filename, content) {
try {
await ensureDirectoryExistence(dir);
const filePath = `${dir}/${filename}`;
await fs.writeFile(filePath, content);
} catch (err) {
console.error("Error writing file:", err);
}
}
/**
* Get dependencies for workflow packages
* @returns {Object} workflow dependencies
*/
const getWorkflowDependencies = () => {
if (externalWorkflowPackages.length === 0) {
return {};
}
return Object.entries(packageDeps).reduce((acc, [key, value]) => {
if (externalWorkflowPackages.includes(key)) {
acc[key] = value;
}
return acc;
}, {});
};
const bundle = async () => {
return esbuild
.build({
entryPoints: ["src/server.ts", "src/ctl/index.ts"],
bundle: true,
sourcemap: true,
platform: "node",
external: [...externalWorkflowPackages, "dtrace-provider"],
loader: {
".ts": "ts",
},
tsconfig: "tsconfig.json",
outdir: "dist/bundle",
target: "node" + process.versions.node,
minify: true,
keepNames: true,
})
.catch(() => process.exit(1));
};
(async () => {
if (externalWorkflowPackages.length > 0) {
// Create package.json for bundle, this is needed to install workflow dependencies
// in the bundle directory. This is needed for EE only. This is done to support the
// packages for our workflow provider which requires dynamic imports. ESBuild does
// not support dynamic imports for external packages hence we need to bundle them
// together with the workflow provider.
const bundlePackagejson = {
name: "rts-bundle",
version: "1.0.0",
description: "",
main: "bundle/server.js",
dependencies: getWorkflowDependencies(),
};
createFile(
"dist",
"package.json",
JSON.stringify(bundlePackagejson, null, 2),
);
console.log("Bundle package.json created successfully");
}
await bundle();
console.log("Bundle created successfully");
})();