UNPKG

arky-js

Version:

**Arky.js** is a powerful, annotation-based framework for building serverless applications on **AWS Lambda and API Gateway**. Inspired by Angular and NestJS, Arky.js simplifies serverless development by providing decorators for defining modules, controlle

119 lines (118 loc) 5.05 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.FileHandler = void 0; const path = __importStar(require("path")); const fs_1 = __importDefault(require("fs")); const ts_morph_1 = require("ts-morph"); /** * FileHandler class to handle file operations such as copying directories, * removing decorators, and cleaning directories. */ class FileHandler { createTempProjectWithoutDecorators(tempFolder) { if (tempFolder) { const projectDir = path.resolve("."); // Root directory of the project const tempDir = path.join(projectDir, tempFolder); // Temporary directory console.log("✅ Copying project to temporary location...\n"); this.copyDirectory("src", tempDir); console.log("✅ Removing decorators...\n"); const project = new ts_morph_1.Project(); project.addSourceFilesAtPaths(path.join(tempDir, "**/*.ts")); this.removeDecorators(project); } } // Method to copy a directory recursively copyDirectory(src, dest) { if (!fs_1.default.existsSync(dest)) { fs_1.default.mkdirSync(dest, { recursive: true }); } const entries = fs_1.default.readdirSync(src, { withFileTypes: true }); for (const entry of entries) { const srcPath = path.join(src, entry.name); const destPath = path.join(dest, entry.name); if (entry.isDirectory()) { this.copyDirectory(srcPath, destPath); } else { fs_1.default.copyFileSync(srcPath, destPath); } } } // Method to remove decorators using ts-morph removeDecorators(project) { project.getSourceFiles().forEach((sourceFile) => { // Remove all decorators from the source file sourceFile.getClasses().forEach((classDeclaration) => { // Remove decorators from the class itself classDeclaration.getDecorators().forEach((decorator) => { decorator.remove(); }); // Remove decorators from methods classDeclaration.getMethods().forEach((methodDeclaration) => { methodDeclaration.getDecorators().forEach((decorator) => { decorator.remove(); }); }); // Remove decorators from properties classDeclaration.getProperties().forEach((propertyDeclaration) => { propertyDeclaration.getDecorators().forEach((decorator) => { decorator.remove(); }); }); // Remove decorators from constructor parameters classDeclaration.getConstructors().forEach((constructorDeclaration) => { constructorDeclaration .getParameters() .forEach((parameterDeclaration) => { parameterDeclaration.getDecorators().forEach((decorator) => { decorator.remove(); }); }); }); }); // Save the modified file sourceFile.saveSync(); }); } cleaningDirectory(diarectoryPath) { console.log(`✅ Cleaning up ${diarectoryPath}...\n`); fs_1.default.rmSync(diarectoryPath, { recursive: true, force: true }); } } exports.FileHandler = FileHandler;