From aa382647be75433e375633a5d62d3a94d79ba427 Mon Sep 17 00:00:00 2001 From: Deyan Razsadov Date: Wed, 15 Jan 2025 17:59:07 +0200 Subject: [PATCH] indent align and review comments --- typescript/polyglotpkg/src/lib/file-system.ts | 18 +++++- typescript/polyglotpkg/src/lib/utils.ts | 64 +++++++++---------- typescript/polyglotpkg/src/strategies/base.ts | 6 +- .../polyglotpkg/src/strategies/nodejs.ts | 18 +++--- .../polyglotpkg/src/strategies/powershell.ts | 20 +++--- .../polyglotpkg/src/strategies/python.ts | 20 +++--- typescript/polyglotpkg/src/vro.ts | 2 +- typescript/vropkg/src/parse/util.ts | 6 +- typescript/vropkg/src/serialize/js.ts | 4 +- typescript/vropkg/src/serialize/tree.ts | 1 + typescript/vrotest/src/util.ts | 12 ---- 11 files changed, 86 insertions(+), 85 deletions(-) diff --git a/typescript/polyglotpkg/src/lib/file-system.ts b/typescript/polyglotpkg/src/lib/file-system.ts index d36ed92ba..faa8d68f0 100644 --- a/typescript/polyglotpkg/src/lib/file-system.ts +++ b/typescript/polyglotpkg/src/lib/file-system.ts @@ -12,7 +12,7 @@ * This product may include a number of subcomponents with separate copyright notices and license terms. Your use of these subcomponents is subject to the terms and conditions of the subcomponent's license, as noted in the LICENSE file. * #L% */ -import { copyFileSync, mkdirSync, readdirSync, realpathSync, statSync } from "fs"; +import { readdirSync, realpathSync, statSync } from "fs"; import { join } from "path"; interface FindFilesOptions { @@ -23,6 +23,20 @@ interface FindFilesOptions { subPath?: string; absolute?: boolean; } +/** + * Returns list of files under directory tree matching search criteria + * Patterns may be: + * - RegExp + * - path/filename patterns, * and ** supported + * Options supported: + * - exclude - patterns for filenames to be excluded from result (optional) + * - maxDepth - maximum depth to search directory tree (default 10) + * - path - directory to search in (default .) + * - absolute - true: return full absolute path to file, false: return filename only (default false) + * @param {RegExp[] | string[]} patterns Filename patterns + * @param {FindFilesOptions} options Search options + * @returns {string[]} List of files found + */ export function findFiles(patterns: RegExp[] | string[], options: FindFilesOptions = {}): string[] { let result: string[] = []; @@ -48,7 +62,7 @@ export function findFiles(patterns: RegExp[] | string[], options: FindFilesOptio : directories.push(_path); } - const someMatch = (fileName: string, pattern: string|RegExp) => { + const someMatch = (fileName: string, pattern: string | RegExp) => { let regex: RegExp; if (pattern instanceof RegExp) { regex = pattern; diff --git a/typescript/polyglotpkg/src/lib/utils.ts b/typescript/polyglotpkg/src/lib/utils.ts index bf2cef7dd..3893ad83f 100644 --- a/typescript/polyglotpkg/src/lib/utils.ts +++ b/typescript/polyglotpkg/src/lib/utils.ts @@ -106,20 +106,20 @@ export function determineActionType(pkg: PlatformDefinition, actionType?: Action export async function getProjectActions(options: PackagerOptions, actionType?: ActionType): Promise { // Search for all polyglot.json files located in subfolders of src - const plg = findFiles([ 'src/**/polyglot.json' ], { - exclude: [ '**/node_modules/**' ], + const plg = findFiles([ 'src/**/polyglot.json' ], { + exclude: [ '**/node_modules/**' ], path: options.workspace, absolute: true - }); + }); if (plg.length === 0) { // No polyglot.json found. Assuming legacy project. // Locate package.json from project root - const pkg = findFiles([ 'package.json' ], { - exclude: [ '**/node_modules/**' ], - path: options.workspace, - absolute: true - }); + const pkg = findFiles([ 'package.json' ], { + exclude: [ '**/node_modules/**' ], + path: options.workspace, + absolute: true + }); if (pkg.length === 0) { return []; @@ -195,11 +195,11 @@ export async function createPackageJsonForABX(options: ActionOptions, isMixed: b */ export async function getActionManifest(projectPath: string): Promise { - const pkg = findFiles([ "package.json" ], { - exclude: [ "**/node_modules/**" ], - path: projectPath, - absolute: true, - }) + const pkg = findFiles([ "package.json" ], { + exclude: [ "**/node_modules/**" ], + path: projectPath, + absolute: true, + }) if (pkg.length === 0) { return null; @@ -223,25 +223,25 @@ export function notUndefined(x: T | undefined): x is T { */ export function run(cmd: string, args: Array = [], cwd: string = process.cwd()): Promise { return new Promise(async (resolve, reject) => { - let err: any; - let commandPath: readonly string[] = []; - try { - commandPath = await which(cmd, { all: true, nothrow: false }); - } catch(thrown) { - err = thrown; - } - if (err || !(commandPath && commandPath.length)) { - return reject(new Error(`Cannot find "${cmd}"`)); - } - const proc = spawn(quoteString(commandPath[0]), args, { cwd, shell: true, stdio: 'inherit' }); - proc.on('close', exitCode => { - if (exitCode !== 0) { - const commandLine = `${quoteString(commandPath[0])} ${args.join(' ')}`; - logger.error(`Error running command: ${commandLine}`); - return reject(new Error(`Exit code for ${cmd}: ${exitCode}`)); - } - resolve(exitCode); - }); + let err: any; + let commandPath: readonly string[] = []; + try { + commandPath = await which(cmd, { all: true, nothrow: false }); + } catch(thrown) { + err = thrown; + } + if (err || !(commandPath && commandPath.length)) { + return reject(new Error(`Cannot find "${cmd}"`)); + } + const proc = spawn(quoteString(commandPath[0]), args, { cwd, shell: true, stdio: 'inherit' }); + proc.on('close', exitCode => { + if (exitCode !== 0) { + const commandLine = `${quoteString(commandPath[0])} ${args.join(' ')}`; + logger.error(`Error running command: ${commandLine}`); + return reject(new Error(`Exit code for ${cmd}: ${exitCode}`)); + } + resolve(exitCode); + }); }); } diff --git a/typescript/polyglotpkg/src/strategies/base.ts b/typescript/polyglotpkg/src/strategies/base.ts index 8ff7c2a47..f3bc99314 100644 --- a/typescript/polyglotpkg/src/strategies/base.ts +++ b/typescript/polyglotpkg/src/strategies/base.ts @@ -44,7 +44,7 @@ export abstract class BaseStrategy implements IStrategy { } }) - mkdirSync(path.dirname(this.options.bundle), { recursive: true }); + mkdirSync(path.dirname(this.options.bundle), { recursive: true }); zip.writeZip(this.options.bundle); this.logger.info(`Created ${this.options.bundle}`); } @@ -54,8 +54,8 @@ export abstract class BaseStrategy implements IStrategy { const { files: filesToCopy, baseDir } = fileset; for (const filePath of filesToCopy) { const destPath = path.join(path.resolve(dest), path.relative(baseDir, filePath)); - mkdirSync(path.dirname(destPath), { recursive: true }); - copyFileSync(filePath, destPath); + mkdirSync(path.dirname(destPath), { recursive: true }); + copyFileSync(filePath, destPath); this.logger.debug(`Copied: ${filePath}`); } } diff --git a/typescript/polyglotpkg/src/strategies/nodejs.ts b/typescript/polyglotpkg/src/strategies/nodejs.ts index 33c2d2c80..9ca359be3 100644 --- a/typescript/polyglotpkg/src/strategies/nodejs.ts +++ b/typescript/polyglotpkg/src/strategies/nodejs.ts @@ -79,15 +79,15 @@ export class NodejsStrategy extends BaseStrategy { } } - const filesToBundle = findFiles(patterns, { - path: workspaceFolderPath, - absolute: true - }); - - const depsToBundle = findFiles([ "**" ], { - path: this.DEPENDENCY_TEMP_DIR, - absolute: true - }); + const filesToBundle = findFiles(patterns, { + path: workspaceFolderPath, + absolute: true + }); + + const depsToBundle = findFiles([ "**" ], { + path: this.DEPENDENCY_TEMP_DIR, + absolute: true + }); this.logger.info(`Packaging ${filesToBundle.length + depsToBundle.length} files into bundle ${this.options.bundle}...`); const actionBase = polyglotJson.platform.base ? path.resolve(polyglotJson.platform.base) : this.options.outBase; diff --git a/typescript/polyglotpkg/src/strategies/powershell.ts b/typescript/polyglotpkg/src/strategies/powershell.ts index 76ca02cee..fedaa2b83 100644 --- a/typescript/polyglotpkg/src/strategies/powershell.ts +++ b/typescript/polyglotpkg/src/strategies/powershell.ts @@ -59,21 +59,21 @@ export class PowershellStrategy extends BaseStrategy { patterns.push(`${outDir}/**`); } - const filesToBundle = findFiles(patterns, { - path: workspaceFolderPath, - absolute: true - }); + const filesToBundle = findFiles(patterns, { + path: workspaceFolderPath, + absolute: true + }); - const modulesToBundle = findFiles([ 'Modules' ], { - path: this.options.outBase, // use action specific out subfolder - absolute: true - }); + const modulesToBundle = findFiles([ 'Modules' ], { + path: this.options.outBase, // use action specific out subfolder + absolute: true + }); this.logger.info(`Packaging ${filesToBundle.length} files into bundle ${this.options.bundle}...`); const actionBase = polyglotJson.platform.base ? path.resolve(polyglotJson.platform.base) : this.options.outBase; this.logger.info(`Action base: ${actionBase}`); - this.zipFiles([ + this.zipFiles([ { files: filesToBundle, baseDir: actionBase }, { files: modulesToBundle, baseDir: actionBase } ]); @@ -81,7 +81,7 @@ export class PowershellStrategy extends BaseStrategy { private async compile(source: string, destination: string) { this.logger.info(`Compiling project...`); - cpSync(source, destination, { recursive: true }); + cpSync(source, destination, { recursive: true }); this.logger.info(`Compilation complete`); } diff --git a/typescript/polyglotpkg/src/strategies/python.ts b/typescript/polyglotpkg/src/strategies/python.ts index fe705623d..d684678bf 100644 --- a/typescript/polyglotpkg/src/strategies/python.ts +++ b/typescript/polyglotpkg/src/strategies/python.ts @@ -74,7 +74,7 @@ export class PythonStrategy extends BaseStrategy { }); } - mkdirSync(path.dirname(this.options.bundle), { recursive: true }); + mkdirSync(path.dirname(this.options.bundle), { recursive: true }); zip.writeZip(this.options.bundle); this.logger.info(`Created ${this.options.bundle}`); } @@ -83,7 +83,7 @@ export class PythonStrategy extends BaseStrategy { * package project into bundle */ async packageProject() { - const polyglotJson = JSON.parse(readFileSync(this.options.polyglotJson).toString("utf8")) as PlatformDefinition; + const polyglotJson = JSON.parse(readFileSync(this.options.polyglotJson).toString("utf8")) as PlatformDefinition; this.phaseCb(Events.COMPILE_START); await this.compile(this.options.src, this.options.out); @@ -112,15 +112,15 @@ export class PythonStrategy extends BaseStrategy { patterns.push(`${outDir}/**`); } - const filesToBundle = findFiles(patterns, { - path: workspaceFolderPath, - absolute: true - }); + const filesToBundle = findFiles(patterns, { + path: workspaceFolderPath, + absolute: true + }); - const depsToBundle = findFiles([ "**" ], { - path: this.DEPENDENCY_TEMP_DIR, - absolute: true - }); + const depsToBundle = findFiles([ "**" ], { + path: this.DEPENDENCY_TEMP_DIR, + absolute: true + }); this.logger.info(`Packaging ${filesToBundle.length + depsToBundle.length} files into bundle ${this.options.bundle}...`); const actionBase = path.resolve(path.join(this.options.outBase, polyglotJson.platform.base ? polyglotJson.platform.base : 'out')); diff --git a/typescript/polyglotpkg/src/vro.ts b/typescript/polyglotpkg/src/vro.ts index c6bba486e..fdbb857b5 100644 --- a/typescript/polyglotpkg/src/vro.ts +++ b/typescript/polyglotpkg/src/vro.ts @@ -75,7 +75,7 @@ export class VroTree { const doc = createXML({ version: '1.0', encoding: 'UTF-8' }, content) const xml = doc.end({ prettyPrint: true }); - writeFileSync(path.join(this.treeDir, 'pom.xml'), xml); + writeFileSync(path.join(this.treeDir, 'pom.xml'), xml); } private generateAction(actionDefintion: VroActionDefinition) { diff --git a/typescript/vropkg/src/parse/util.ts b/typescript/vropkg/src/parse/util.ts index f63312c7d..44e5fbb1a 100644 --- a/typescript/vropkg/src/parse/util.ts +++ b/typescript/vropkg/src/parse/util.ts @@ -77,7 +77,7 @@ export const xmlToAction = (file: string, bundlePath: string, name: string, comm }; params.push(param); } else if (element.type == "element" && element.name == "script") { - inline = getScriptInline(file, element, comment, false); // @TODO: check if lazy parameter is still relevant + inline = getScriptInline(file, element, comment); } else if (element.type == "element" && element.name == "runtime") { runtime = element.val; } else if (element.type == "element" && element.name == "entry-point") { @@ -131,7 +131,7 @@ export function getScriptRuntime(runtime: string): t.VroScriptRuntime { return { lang: lang, version: langVersion != "" ? langVersion : defaultVersion }; } -function getScriptInline(file: string, element: xmldoc.XmlElement, comment: string, lazy: boolean): t.VroScriptInline { +function getScriptInline(file: string, element: xmldoc.XmlElement, comment: string): t.VroScriptInline { let scriptSource: string = element.val; let scriptStartLine: number = element.line; @@ -152,7 +152,7 @@ function getScriptInline(file: string, element: xmldoc.XmlElement, comment: stri scriptEndIndex = lastLine.length; } return { - actionSource: lazy ? null : scriptSource, + actionSource: scriptSource, sourceFile: file, sourceStartLine: scriptStartLine, sourceStartIndex: scriptStartIndex, diff --git a/typescript/vropkg/src/serialize/js.ts b/typescript/vropkg/src/serialize/js.ts index 4b1e90f03..b9dc24850 100644 --- a/typescript/vropkg/src/serialize/js.ts +++ b/typescript/vropkg/src/serialize/js.ts @@ -15,8 +15,6 @@ import * as Path from "path"; import * as FileSystem from "fs-extra"; import * as XmlBuilder from "xmlbuilder2"; -import * as unzipper from "unzipper"; -import * as winston from "winston"; import * as packaging from "../packaging"; import { VroPackageMetadata, VroNativeElement, VroActionData, VroActionParameter, Lang, VroScriptBundle } from "../types"; import { exist, isDirectory } from "../util"; @@ -163,7 +161,7 @@ export class VroJsProjRealizer { FileSystem.copy(bundle.contentPath, dest); } else { FileSystem.mkdirs(dest); - await packaging.extract(bundle.contentPath, dest); + await packaging.extract(bundle.contentPath, dest); } } diff --git a/typescript/vropkg/src/serialize/tree.ts b/typescript/vropkg/src/serialize/tree.ts index 08770b1b5..6a098f807 100644 --- a/typescript/vropkg/src/serialize/tree.ts +++ b/typescript/vropkg/src/serialize/tree.ts @@ -109,6 +109,7 @@ const serializeTreeElement = async (context: any, element: t.VroNativeElement): ? element?.categoryPath.pop().split('.') : element?.categoryPath; + // @NOTE: The below code will not support empty values for version, mimetype, and description attributes if (element.type == t.VroElementType.ResourceElement && element.attributes["version"]) { xInfo.ele("entry").att("key", "version").text(element.attributes["version"].toString()); } diff --git a/typescript/vrotest/src/util.ts b/typescript/vrotest/src/util.ts index e3b501d67..ba62244e2 100644 --- a/typescript/vrotest/src/util.ts +++ b/typescript/vrotest/src/util.ts @@ -92,15 +92,3 @@ export async function withWorkingDir(dir: string, action: () => Promise): } } } - -type CopyFilter = (fileName: string) => boolean; - -/** - * Copy file or directory. Enables filtering. - * @param {string} path Copy source. - * @param {string} path Copy source. - * @return {boolean} Whether or not to copy the file. - */ -export async function copy(source: string, destination: string, filter?: CopyFilter) { - -}