From 32ef037b9eafaa1dce7d66921df6e5d21ba256f1 Mon Sep 17 00:00:00 2001 From: Himani1519 Date: Fri, 13 Oct 2023 00:37:13 +0530 Subject: [PATCH 1/5] fixed linter error Signed-off-by: Himani1519 --- .github/workflows/test-linter.yml | 21 +++++++++++ src/actions/HomeActions.ts | 5 +-- src/actions/InstallationHandler.ts | 3 +- src/main/index.ts | 2 +- src/renderer/components/stages/Planning.tsx | 8 ++--- src/renderer/jsonFormsTheme.ts | 10 ++++++ src/renderer/preload.ts | 2 +- src/services/FileTransfer.ts | 4 +-- src/services/SubmitJcl.ts | 39 +++++++++++---------- src/services/configService.ts | 10 ++++++ src/services/utils.ts | 2 +- src/storage/ConfigurationStore.ts | 2 +- src/storage/ConnectionStore.ts | 2 +- src/types/zos-node-accessor.d.ts | 11 ++++++ 14 files changed, 88 insertions(+), 33 deletions(-) create mode 100644 .github/workflows/test-linter.yml create mode 100644 src/types/zos-node-accessor.d.ts diff --git a/.github/workflows/test-linter.yml b/.github/workflows/test-linter.yml new file mode 100644 index 00000000..b8324398 --- /dev/null +++ b/.github/workflows/test-linter.yml @@ -0,0 +1,21 @@ +name: Lint TypeScript + +on: [push, pull_request] + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Set up Node.js + uses: actions/setup-node@v2 + with: + node-version: '18' + + - name: Install Dependencies + run: npm ci + + - name: Lint TypeScript + run: npm run lint \ No newline at end of file diff --git a/src/actions/HomeActions.ts b/src/actions/HomeActions.ts index 7d98672d..5d85d9b3 100644 --- a/src/actions/HomeActions.ts +++ b/src/actions/HomeActions.ts @@ -10,14 +10,15 @@ import { ConnectionStore } from "../storage/ConnectionStore"; import { IResponse } from '../types/interfaces'; +import * as util from 'node:util'; +import { execFile as execFileCallback } from 'node:child_process'; export class HomeActions { public static async checkZoweCLI(): Promise { const version = await ConnectionStore.get('zowe-cli-version'); if (!version) { - const util = require('node:util'); - const execFile = util.promisify(require('node:child_process').execFile); + const execFile = util.promisify(execFileCallback); // TODO: Verify not just Zowe CLI version, but get list of profiles available with host names // and check ssh commands are operational to verify it set up correctly. try { diff --git a/src/actions/InstallationHandler.ts b/src/actions/InstallationHandler.ts index 18f8e0c6..0b9ed00e 100644 --- a/src/actions/InstallationHandler.ts +++ b/src/actions/InstallationHandler.ts @@ -16,6 +16,7 @@ import { stringify } from 'yaml'; import { IIpcConnectionArgs, IResponse } from '../types/interfaces'; import { ConfigurationStore } from "../storage/ConfigurationStore"; import { ProgressStore } from "../storage/ProgressStore"; +import * as fs from 'fs'; class Installation { @@ -73,7 +74,6 @@ class Installation { async generateYamlFile() { const zoweYaml: any = ConfigurationStore.getConfig(); - const fs = require('fs'); const filePath = path.join(app.getPath('temp'), 'zowe.yaml') await fs.writeFile(filePath, stringify(zoweYaml), (err: any) => { if (err) { @@ -135,7 +135,6 @@ export class FTPInstallation extends Installation { const filePath = path.join(installDir, "zowe.pax"); console.log(`Uploading ${tempPath} to ${filePath}`) const result = await new FileTransfer().upload(connectionArgs, tempPath, filePath, DataType.BINARY); - const fs = require('fs'); try { fs.unlink(tempPath, () => { console.log("Deleted zowe.pax successfully."); diff --git a/src/main/index.ts b/src/main/index.ts index c971391b..90db5c72 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -147,5 +147,5 @@ app.on('window-all-closed', async () => { }); app.on('activate', () => { - + // Intentionally left empty }); diff --git a/src/renderer/components/stages/Planning.tsx b/src/renderer/components/stages/Planning.tsx index 80337983..09c9c41b 100644 --- a/src/renderer/components/stages/Planning.tsx +++ b/src/renderer/components/stages/Planning.tsx @@ -55,7 +55,7 @@ const serverSchema = { "$anchor": "zoweDatasetMember", "type": "string", "description": "A 1-8-char all caps dataset member name", - "pattern": "^([A-Z\$\#\@]){1}([A-Z0-9\$\#\@]){0,7}$", + "pattern": "^([A-Z$#@]){1}([A-Z0-9$#@]){0,7}$", "minLength": 1, "maxLength": 8 }, @@ -153,15 +153,15 @@ const Planning = () => { schema.properties.zowe.properties.setup.properties.dataset.properties.parmlibMembers.properties.zis = serverSchema.$defs.datasetMember; schema.properties.zowe.properties.setup.properties.certificate.properties.pkcs12.properties.directory = serverSchema.$defs.path; dispatch(setSchema(schema)); - let installationDir = '', javaHome, nodeHome; + let installationDir = ''; if (res.details.config?.zowe?.runtimeDirectory && res.details.config?.zowe?.workspaceDirectory) { const getParentDir = (path: string): string => path.split('/').filter((i: string, ind: number) => i || !ind).slice(0, -1).join('/'); const runtimeParent = getParentDir(res.details.config.zowe.runtimeDirectory); const workspaceParent = getParentDir(res.details.config.zowe.workspaceDirectory); if (runtimeParent === workspaceParent) installationDir = runtimeParent; } - javaHome = (res.details.config?.java?.home) ? res.details.config.java.home : ''; - nodeHome = (res.details.config?.node?.home) ? res.details.config.node.home : ''; + const javaHome = (res.details.config?.java?.home) ? res.details.config.java.home : ''; + const nodeHome = (res.details.config?.node?.home) ? res.details.config.node.home : ''; dispatch(setInstallationArgs({...installationArgs, installationDir, javaHome, nodeHome})); } else { window.electron.ipcRenderer.getExampleZowe().then((res: IResponse) => { diff --git a/src/renderer/jsonFormsTheme.ts b/src/renderer/jsonFormsTheme.ts index 67c8998d..5886f40d 100644 --- a/src/renderer/jsonFormsTheme.ts +++ b/src/renderer/jsonFormsTheme.ts @@ -1,3 +1,13 @@ +/* + * This program and the accompanying materials are made available under the terms of the + * Eclipse Public License v2.0 which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-v20.html + * + * SPDX-License-Identifier: EPL-2.0 + * + * Copyright Contributors to the Zowe Project. + */ + import { createTheme } from '@mui/material/styles'; const jsonFormTheme = createTheme({ diff --git a/src/renderer/preload.ts b/src/renderer/preload.ts index ef08db7c..4531880b 100644 --- a/src/renderer/preload.ts +++ b/src/renderer/preload.ts @@ -8,7 +8,7 @@ * Copyright Contributors to the Zowe Project. */ -const { contextBridge, ipcRenderer } = require('electron'); +import { contextBridge, ipcRenderer } from 'electron'; import { IIpcConnectionArgs } from '../types/interfaces'; contextBridge.exposeInMainWorld('electron', { diff --git a/src/services/FileTransfer.ts b/src/services/FileTransfer.ts index 567a3bb4..8cf3cefc 100644 --- a/src/services/FileTransfer.ts +++ b/src/services/FileTransfer.ts @@ -12,8 +12,8 @@ import {IncomingMessage} from "http"; import {connectFTPServer} from "./utils"; import {IIpcConnectionArgs} from "../types/interfaces"; -const fs = require('fs'); -const https = require('https'); +import * as fs from 'fs'; +import * as https from 'https'; export enum DataType { ASCII = 'ascii', diff --git a/src/services/SubmitJcl.ts b/src/services/SubmitJcl.ts index 4721f4d9..ab44bd14 100644 --- a/src/services/SubmitJcl.ts +++ b/src/services/SubmitJcl.ts @@ -11,28 +11,31 @@ import {connectFTPServer} from "./utils"; import {IIpcConnectionArgs, IJobResults, JobOutput} from "../types/interfaces"; -export async function submitJcl(config: IIpcConnectionArgs, jcl: string, returnDDs: string[]): Promise { +export function submitJcl(config: IIpcConnectionArgs, jcl: string, returnDDs: string[]): Promise { - return new Promise(async (resolve, reject) => { + return new Promise((resolve, reject) => { let jobOutput: IJobResults; - let client - try { - client = await connectFTPServer(config); - console.log('About to submit jcl=',jcl); - const jobId = await client.submitJCL(jcl); - console.log(`jobId: ${jobId}`); - jobOutput = await waitForjobToFinish(client, jobId, returnDDs) - - client.close(); - console.log(`job result=`,jobOutput); - resolve(jobOutput); + let client: any; - } catch (err) { - console.error(err) - client.close() - reject(err) + async function submitAndResolve() { + try { + client = await connectFTPServer(config); + console.log('About to submit jcl=', jcl); + const jobId = await client.submitJCL(jcl); + console.log(`jobId: ${jobId}`); + jobOutput = await waitForjobToFinish(client, jobId, returnDDs); + client.close(); + console.log(`job result=`, jobOutput); + resolve(jobOutput); + } catch (err) { + console.error(err); + client.close(); + reject(err); + } } - }) + + submitAndResolve(); + }); } async function waitForjobToFinish(client: any, jobId: string, returnDDs: string[]): Promise { diff --git a/src/services/configService.ts b/src/services/configService.ts index 9d89ee25..b46aaeb8 100644 --- a/src/services/configService.ts +++ b/src/services/configService.ts @@ -1,3 +1,13 @@ +/* + * This program and the accompanying materials are made available under the terms of the + * Eclipse Public License v2.0 which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-v20.html + * + * SPDX-License-Identifier: EPL-2.0 + * + * Copyright Contributors to the Zowe Project. + */ + import { flatten, unflatten } from 'flat'; export const setConfiguration = (section: string, data: any) => { diff --git a/src/services/utils.ts b/src/services/utils.ts index 2cb2039a..50b80fdf 100644 --- a/src/services/utils.ts +++ b/src/services/utils.ts @@ -11,7 +11,7 @@ import {IIpcConnectionArgs} from "../types/interfaces"; import Header from "../renderer/components/Header" import { AlertColor } from "@mui/material/Alert"; -const zos = require('zos-node-accessor'); +import zos from 'zos-node-accessor'; export async function connectFTPServer(config: IIpcConnectionArgs): Promise { diff --git a/src/storage/ConfigurationStore.ts b/src/storage/ConfigurationStore.ts index 59a84ac5..374dee86 100644 --- a/src/storage/ConfigurationStore.ts +++ b/src/storage/ConfigurationStore.ts @@ -20,7 +20,7 @@ export class ConfigurationStore { const schema = store.get('schema') as any; let schemaPart: any = schema.properties; for (const key of keys) { - if (!schemaPart.hasOwnProperty(key)) { + if (!Object.prototype.hasOwnProperty.call(schemaPart, key)) { return false; } schemaPart = schemaPart[key].properties; diff --git a/src/storage/ConnectionStore.ts b/src/storage/ConnectionStore.ts index a83c31b2..cd7632c5 100644 --- a/src/storage/ConnectionStore.ts +++ b/src/storage/ConnectionStore.ts @@ -92,7 +92,7 @@ const validateWithSchema = (key: string): boolean => { const keys = key.split('.'); let schemaPart: any = storeSchema; for (const key of keys) { - if (!schemaPart.hasOwnProperty(key)) { + if (!Object.prototype.hasOwnProperty.call(schemaPart, key)) { return false; } schemaPart = schemaPart[key].properties; diff --git a/src/types/zos-node-accessor.d.ts b/src/types/zos-node-accessor.d.ts new file mode 100644 index 00000000..dcd94ade --- /dev/null +++ b/src/types/zos-node-accessor.d.ts @@ -0,0 +1,11 @@ +/* + * This program and the accompanying materials are made available under the terms of the + * Eclipse Public License v2.0 which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-v20.html + * + * SPDX-License-Identifier: EPL-2.0 + * + * Copyright Contributors to the Zowe Project. + */ + +declare module 'zos-node-accessor'; From 7723fccbe1493944a56b10bdd0bdfc314b92ed1f Mon Sep 17 00:00:00 2001 From: Himani1519 Date: Tue, 17 Oct 2023 21:02:27 +0530 Subject: [PATCH 2/5] resolved conflicts Signed-off-by: Himani1519 --- src/services/configService.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/services/configService.ts b/src/services/configService.ts index 6fe38db7..23e73e2f 100644 --- a/src/services/configService.ts +++ b/src/services/configService.ts @@ -9,7 +9,6 @@ */ import { flatten, unflatten } from 'flat'; - // To set the subsection of the configuration export const setConfiguration = (section: string, data: any, setZconfig?: boolean) => { if(!data) { From ae4be904642cb8490927fba08eb823112c68bdf5 Mon Sep 17 00:00:00 2001 From: Himani1519 <44604176+Himani1519@users.noreply.github.com> Date: Tue, 17 Oct 2023 21:10:21 +0530 Subject: [PATCH 3/5] resolved conflicts Signed-off-by: Himani1519 <44604176+Himani1519@users.noreply.github.com> --- src/services/ConfigService.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/services/ConfigService.ts b/src/services/ConfigService.ts index a71e8274..6fe38db7 100644 --- a/src/services/ConfigService.ts +++ b/src/services/ConfigService.ts @@ -1,3 +1,13 @@ +/* + * This program and the accompanying materials are made available under the terms of the + * Eclipse Public License v2.0 which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-v20.html + * + * SPDX-License-Identifier: EPL-2.0 + * + * Copyright Contributors to the Zowe Project. + */ + import { flatten, unflatten } from 'flat'; // To set the subsection of the configuration From 5b8e29fd6359563aa1f4c1d5ebe24fa709e228f9 Mon Sep 17 00:00:00 2001 From: Himani1519 Date: Tue, 17 Oct 2023 21:30:58 +0530 Subject: [PATCH 4/5] update lint github action Signed-off-by: Himani1519 --- .github/workflows/test-linter.yml | 3 +- src/services/ConfigService.ts | 1 - src/services/configService.ts | 75 ------------------------------- 3 files changed, 2 insertions(+), 77 deletions(-) delete mode 100644 src/services/configService.ts diff --git a/.github/workflows/test-linter.yml b/.github/workflows/test-linter.yml index b8324398..ac6166f2 100644 --- a/.github/workflows/test-linter.yml +++ b/.github/workflows/test-linter.yml @@ -1,6 +1,7 @@ name: Lint TypeScript -on: [push, pull_request] + pull_request: + types: [opened, reopened, synchronize] jobs: lint: diff --git a/src/services/ConfigService.ts b/src/services/ConfigService.ts index 6fe38db7..23e73e2f 100644 --- a/src/services/ConfigService.ts +++ b/src/services/ConfigService.ts @@ -9,7 +9,6 @@ */ import { flatten, unflatten } from 'flat'; - // To set the subsection of the configuration export const setConfiguration = (section: string, data: any, setZconfig?: boolean) => { if(!data) { diff --git a/src/services/configService.ts b/src/services/configService.ts deleted file mode 100644 index 23e73e2f..00000000 --- a/src/services/configService.ts +++ /dev/null @@ -1,75 +0,0 @@ -/* - * This program and the accompanying materials are made available under the terms of the - * Eclipse Public License v2.0 which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-v20.html - * - * SPDX-License-Identifier: EPL-2.0 - * - * Copyright Contributors to the Zowe Project. - */ - -import { flatten, unflatten } from 'flat'; -// To set the subsection of the configuration -export const setConfiguration = (section: string, data: any, setZconfig?: boolean) => { - if(!data) { - return; - } - const flattenedConfig = flatten(data); - localStorage.setItem(section+ 'Config', JSON.stringify(flattenedConfig)); - - // Updating zowe.yaml - if(setZconfig) { - const zoweSection = 'zowe'; - let storedZoweConfig = localStorage.getItem(zoweSection + 'Config'); - if (!storedZoweConfig) { - return; - } - - // Parse the stored configuration from JSON - storedZoweConfig = JSON.parse(storedZoweConfig); - const zoweConfig: any = unflatten(storedZoweConfig) - - if (zoweConfig && zoweConfig.zowe && zoweConfig.zowe.setup) { - zoweConfig.zowe.setup[section] = data; - const flattenedZoweConfig = flatten(zoweConfig); - localStorage.setItem('zoweConfig', JSON.stringify(flattenedZoweConfig)); - } - } -} - -// To get the subsection of the configuration -export const getConfiguration = (section: string) => { - let flattenedStoredConfig; - let config; - const storedConfig = localStorage.getItem(section+ 'Config'); - if(storedConfig) { - flattenedStoredConfig = storedConfig ? JSON.parse(storedConfig) : {}; - config = unflatten(flattenedStoredConfig); - } else { - config = {}; - } - return config; -} - -// To set the entire zowe configuration -export const setZoweConfig = (data: any) => { - const section = 'zowe'; - if(!data && data !== "") { - return; - } - const flattenedConfig = flatten(data); - localStorage.setItem(section+ 'Config', JSON.stringify(flattenedConfig)); -} - -// To get the entire zowe configuration -export const getZoweConfig = () => { - const section = 'zowe'; - let flattenedStoredConfig; - let config; - const storedConfig = localStorage.getItem(section+ 'Config'); - if(storedConfig) { - flattenedStoredConfig = storedConfig ? JSON.parse(storedConfig) : {}; - config = unflatten(flattenedStoredConfig); - } - return config; -} From 17553905014febf2f0e239289043368a6e01acd0 Mon Sep 17 00:00:00 2001 From: Himani1519 Date: Tue, 17 Oct 2023 21:39:42 +0530 Subject: [PATCH 5/5] update lint github action Signed-off-by: Himani1519 --- .github/workflows/test-linter.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/test-linter.yml b/.github/workflows/test-linter.yml index ac6166f2..f54b8ee7 100644 --- a/.github/workflows/test-linter.yml +++ b/.github/workflows/test-linter.yml @@ -1,5 +1,9 @@ name: Lint TypeScript +on: + push: + branches: + - v2.x/staging pull_request: types: [opened, reopened, synchronize]