Skip to content

Commit

Permalink
Merge pull request zowe#1808 from zowe/add-imp-v1
Browse files Browse the repository at this point in the history
Migrate the `@zowe/imperative@zowe-v1-lts` project
  • Loading branch information
zFernand0 committed Oct 12, 2023
2 parents bb19946 + 1f93d14 commit a258124
Show file tree
Hide file tree
Showing 1,203 changed files with 123,900 additions and 40,270 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/audit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ jobs:
node-version: lts/*

- name: Check Vulnerabilities
run: npm audit --production --audit-level=moderate
run: |
npm install --package-lock-only --ignore-scripts --no-audit --save-prod ./packages/imperative/web-help
npm audit --production --audit-level=moderate
12 changes: 6 additions & 6 deletions .github/workflows/zowe-cli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ jobs:
strategy:
fail-fast: false
matrix:
node-version: [16.x, 18.x]
os: [windows-latest, ubuntu-latest, macos-latest]
node-version: [18.x, 20.x]
os: [windows-2019, ubuntu-latest, macos-latest]

env:
OS: ${{ matrix.os }}
Expand All @@ -58,10 +58,6 @@ jobs:
echo "::remove-matcher owner=eslint-compact::"
echo "::remove-matcher owner=eslint-stylish::"
- name: Use NPM v8
id: npm8
run: npm install -g npm@~8.3.2

- name: Install Dependencies
id: install
run: npm ci
Expand All @@ -80,6 +76,10 @@ jobs:
if: ${{ always() && steps.build.outcome == 'success' }}
run: npm run test:unit >> file.txt

- name: Unlock Keyring
if: ${{ always() && steps.build.outcome == 'success' && matrix.os == 'ubuntu-latest' }}
uses: t1m0thyj/unlock-keyring@v1

- name: Integration Tests
if: ${{ always() && steps.build.outcome == 'success' }}
run: npm run test:integration >> file.txt
Expand Down
11 changes: 7 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,14 @@ fabric.properties
!/.idea/artifacts/
/.idea/dictionaries/
/gui/BrightSide-win32-x64/
lib/
**/lib/
typings/
/gui/BrightSide-linux-x64/
/gui/BrightSide-darwin-x64/
/brightside.iml
/config/
**/docs/typedoc/
__tests__/__results__/
packages/zosunix/__tests__/__results__/
**/__tests__/__results__
/__tests__/tmpproj/
/__tests__/src/locales
/.nyc_output
Expand All @@ -85,6 +84,7 @@ packages/zosunix/__tests__/__results__/
node-report*
/docs/typedoc/
__tests__/__system__/util/Zosmf.info.ts
/.npm-global

audit.txt
imperative_debug.log
Expand All @@ -97,9 +97,12 @@ imperative_debug.log
*.bat

/packages/cli/lib
/packages/cli/__tests__/__results__
/packages/cli/npm-shrinkwrap.json

# Licenses in package folders (managed with build scripts)
packages/*/LICENSE
zowex/

# Browserified bundles and compiled JS for web help
packages/imperative/web-help/dist/css/bundle*
packages/imperative/web-help/dist/js/
8 changes: 4 additions & 4 deletions __mocks__/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ function lstatSync(filePath: string) {
}

fs.__setMockFiles = __setMockFiles;
fs.existsSync = existsSync;
fs.readFileSync = readFileSync;
fs.readdirSync = readdirSync;
fs.lstatSync = lstatSync;
fs.existsSync = jest.fn(existsSync);
fs.readFileSync = jest.fn(readFileSync);
fs.readdirSync = jest.fn(readdirSync);
fs.lstatSync = jest.fn(lstatSync);

module.exports = fs;
19 changes: 19 additions & 0 deletions __mocks__/opener.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* 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.
*
*/

const opener_ = jest.fn(() => ({
unref: jest.fn(),
stderr: {unref: jest.fn()},
stdin: {unref: jest.fn()},
stdout: {unref: jest.fn()},
}));

module.exports = opener_;
31 changes: 31 additions & 0 deletions __mocks__/yargs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* 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 {relative} from "path";

// Since yargs uses path.relative and somehow mocking fails because of this,
// we need to check if relative is a mocked function. If it is, reinstall the
// actual instance of the standard library so we can mock yargs.
const isMock = jest.isMockFunction(relative);

if (isMock) {
jest.dontMock("path");
}

const yargs = jest.genMockFromModule("yargs");

// Once we are done, we should install the mock back so that the test that needed
// to mock yargs continues as expected.
if (isMock) {
jest.doMock("path");
}

module.exports = yargs;
3 changes: 1 addition & 2 deletions __tests__/__resources__/application_instances/zowe
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
#!/bin/sh
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
node "$basedir/../../../packages/cli/lib/main.js" "$@"
MSYS_NO_PATHCONV=1 exec node "../../../../packages/cli/lib/main.js" "$@"
8 changes: 4 additions & 4 deletions __tests__/__src__/mocks/ZosmfProfileMock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export function getMockedResponse(): IHandlerResponseApi {
data: {
setMessage: jest.fn((setMsgArgs) => {
expect(setMsgArgs).toMatchSnapshot();
}),
}) as any,
setObj: jest.fn((setObjArgs) => {
expect(setObjArgs).toMatchSnapshot();
}),
Expand All @@ -72,11 +72,11 @@ export function getMockedResponse(): IHandlerResponseApi {
console: {
log: jest.fn((logs) => {
expect(logs.toString()).toMatchSnapshot();
}),
}) as any,
error: jest.fn((errors) => {
expect(errors.toString()).toMatchSnapshot();
}),
errorHeader: jest.fn(() => undefined)
}) as any,
errorHeader: jest.fn(() => undefined) as any
},
progress: {
startBar: jest.fn((parms) => undefined),
Expand Down
15 changes: 15 additions & 0 deletions __tests__/beforeTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,18 @@
*/

jest.setTimeout(200000);
const __mockedLogger = {debug: jest.fn(), info: jest.fn(), error: jest.fn(), trace: jest.fn(), fatal: jest.fn()};
const __imperativeLogger = {
Logger: {
getAppLogger: () => __mockedLogger,
getImperativeLogger: () => __mockedLogger,
getConsoleLogger: () => __mockedLogger,
initLogger: jest.fn()
},
LoggerConfigBuilder: {
getDefaultIConfigLogging: jest.fn(),
getDefaultFileName: jest.fn(),
addFileAppender: jest.fn()
}
};
jest.mock("@zowe/imperative/lib/logger", () => __imperativeLogger);
2 changes: 1 addition & 1 deletion __tests__/test-tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"module": "commonjs",
"declaration": true,
"moduleResolution": "node",
"noImplicitAny": true,
"noImplicitAny": false,
"outDir": "./lib",
"preserveConstEnums": true,
"removeComments": false,
Expand Down
119 changes: 115 additions & 4 deletions gulp/DevelopmentTasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@
*/

import { IGulpError, ITaskFunction } from "./GulpHelpers";
import { Constants } from "../packages/cli/src/Constants";
import { SpawnSyncReturns } from "child_process";
import * as util from "util";
import { DefaultHelpGenerator, Imperative, ImperativeConfig } from "@zowe/imperative";
import { DefaultHelpGenerator, Imperative, ImperativeConfig } from "../packages/imperative/src";

import { CliConstants } from "../packages/cli/src/CliConstants";

// "npx" command allows us to issue CLIs from node_modules dependencies
// without globally installing.
const npx = "npx" + (require("os").platform() === "win32" ? ".cmd" : ""); // platform dependent extension for npx command

const gulp = require('gulp');
const ansiColors = require("ansi-colors");
const childProcess = require("child_process");
const fancylog = require("fancy-log");
Expand Down Expand Up @@ -129,7 +131,7 @@ const doc: ITaskFunction = async () => {
clearRequire.all(); // in case the code has changed, reload any code

let totalCommands = 0;
let markdownContent = "# " + Constants.DISPLAY_NAME + " Help\n\n";
let markdownContent = "# " + CliConstants.DISPLAY_NAME + " Help\n\n";
markdownContent += "\n" + loadedDefinitions.description + "\n\n";

markdownContent += "{{tableOfContents}}\n\n";
Expand Down Expand Up @@ -186,7 +188,7 @@ const doc: ITaskFunction = async () => {

const helpGen = new DefaultHelpGenerator({
produceMarkdown: true,
rootCommandName: Constants.BINARY_NAME + oldCommandName
rootCommandName: CliConstants.BINARY_NAME + oldCommandName
} as any, {
commandDefinition: child,
fullCommandTree: definition
Expand Down Expand Up @@ -220,6 +222,115 @@ const doc: ITaskFunction = async () => {
};
doc.description = "Create documentation from the CLI help";

const tscExecutable = "node_modules/typescript/bin/tsc";
const buildImperative: ITaskFunction = (done) => {
license((licenseErr?: Error) => {
if (licenseErr) {
fancylog(ansiColors.red("Error encountered while adding copyright information"));
done(licenseErr);
}
if (fs.existsSync("tsconfig.tsbuildinfo")) {
fs.unlinkSync("tsconfig.tsbuildinfo");
}
if (fs.existsSync(compileDir)) {
rimraf(compileDir);
fancylog("Deleted old compiled source in '%s' folder", compileDir);
}
const compileProcess = childProcess.spawnSync("node", [tscExecutable]);
const typescriptOutput = compileProcess.output.join("");
if (typescriptOutput.trim().length > 0) {
fancylog("Typescript output:\n%s", typescriptOutput);
}
if (compileProcess.status !== 0) {
const buildFailedError: IGulpError = new Error(ansiColors.red("Build failed"));
buildFailedError.showStack = false;
done(buildFailedError);
}
else {
fancylog(ansiColors.blue("Compiled typescript successfully"));

lint((lintWarning: Error) => {
if (lintWarning) {
done(lintWarning);
return;
}
fancylog(ansiColors.blue("Build succeeded"));
done();
});
}
});
};
buildImperative.description = "Build the project and generate documentation";

const watchImperative: ITaskFunction = (done) => {
gulp.watch("packages/imperative/src/**", gulp.series("lint"));
const watchProcess = childProcess.spawn("node", [tscExecutable, "--watch"], {stdio: "inherit"});
watchProcess.on("error", (error: Error) => {
fancylog(error);
throw error;
});
watchProcess.on("close", () => {
fancylog("watch process closed");
done();
});
};
watchImperative.description = "Continuously build the project as you edit the source. To get full linting results and " +
"generate documentation, use the 'build' task before attempting to merge with the master branch";


const imperativeDirectory = __dirname + "/../packages/imperative/";
const buildAllClis: ITaskFunction = async () => {
const cliDirs: string[] = getDirectories(imperativeDirectory + "__tests__/__integration__/");
cliDirs.forEach((dir) => {
// Build them all
fancylog(`Build "${dir}" cli...`);
const buildResponse = childProcess.spawnSync((process.platform === "win32") ? "npm.cmd" : "npm", ["run", "build"],
{cwd: imperativeDirectory + `__tests__/__integration__/${dir}/`, stdio: "inherit"});
if (buildResponse.stdout && buildResponse.stdout.toString().length > 0) {
fancylog(`***BUILD "${dir}" stdout:\n${buildResponse.stdout.toString()}`);
}
if (buildResponse.stderr && buildResponse.stderr.toString().length > 0) {
fancylog(`***BUILD "${dir}" stderr:\n${buildResponse.stderr.toString()}`);
}
if (buildResponse.status !== 0) {
throw new Error(`Build failed for "${dir}" test CLI. Status code: "${buildResponse.status}". ` +
`Please review the stdout/stderr for more details.`);
}
fancylog(`Build for "${dir}" cli completed successfully.`);
});
};

function getDirectories(path: string) {
return fs.readdirSync(path).filter((file: string) => {
return fs.statSync(path + "/" + file).isDirectory();
});
}

const installAllCliDependencies: ITaskFunction = async () => {
const cliDirs: string[] = getDirectories(imperativeDirectory + "__tests__/__integration__/");
cliDirs.forEach((dir) => {
// Perform an NPM install
fancylog(`Executing "npm install" for "${dir}" cli to obtain dependencies...`);
const installResponse = childProcess.spawnSync((process.platform === "win32") ? "npm.cmd" : "npm", ["install"],
{cwd: imperativeDirectory + `__tests__/__integration__/${dir}/`, stdio: "inherit"});
if (installResponse.stdout && installResponse.stdout.toString().length > 0) {
fancylog(`***INSTALL "${dir}" stdout:\n${installResponse.stdout.toString()}`);
}
if (installResponse.stderr && installResponse.stderr.toString().length > 0) {
fancylog(`***INSTALL "${dir}" stderr:\n${installResponse.stderr.toString()}`);
}
if (installResponse.status !== 0) {
throw new Error(`Install dependencies failed for "${dir}" test CLI. Status code: "${installResponse.status}". ` +
`Please review the stdout/stderr for more details.`);
}
fancylog(`Install for "${dir}" cli dependencies complete.`);
});
};

exports.buildImperative = buildImperative;
exports.watchImperative = watchImperative;
exports.buildAllClis = buildAllClis;
exports.installAllCliDependencies = installAllCliDependencies;
exports.doc = doc;
exports.lint = lint;
exports.license = license;
Loading

0 comments on commit a258124

Please sign in to comment.