Skip to content

Commit

Permalink
Merge pull request #52 from naveedkhan8067/hello-world-component-fixes
Browse files Browse the repository at this point in the history
Functionality updated
  • Loading branch information
testUser3067 authored May 20, 2024
2 parents 7022ab1 + 9fd9d07 commit 7609ff9
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 96 deletions.
16 changes: 8 additions & 8 deletions .github/workflows/Build-And-Test-Component-Reuse-Case.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ on:
- .github/workflows/Build-And-Test-Component-Reuse-Case.yml

jobs:
hello-world-linux:
name: "Hello-World Linux"
hello-world-linux-reuse:
name: "Hello-World Linux Reuse"
runs-on: ubuntu-latest
steps:
- name: 📚 Checkout
Expand All @@ -36,8 +36,8 @@ jobs:
VARIANT_TYPE: linux
WORKING-DIR: ./components/

hello-world-mac:
name: "Hello-World Mac"
hello-world-mac-reuse:
name: "Hello-World Mac Reuse"
runs-on: macos-latest
steps:
- name: 📚 Checkout
Expand All @@ -56,8 +56,8 @@ jobs:
VARIANT_TYPE: mac
WORKING-DIR: ./components/

hello-world-windows:
name: "Hello-World Windows"
hello-world-windows-reuse:
name: "Hello-World Windows Reuse"
runs-on: windows-latest
steps:
- name: 📚 Checkout
Expand All @@ -76,12 +76,12 @@ jobs:
VARIANT_TYPE: windows
WORKING-DIR: ./components/

security-scan:
security-scan-reuse:
needs:
- hello-world-linux
- hello-world-mac
- hello-world-windows
name: "Security Scan"
name: "Security Scan Reuse"
runs-on: ubuntu-latest
steps:
- name: 📚 Checkout
Expand Down
7 changes: 1 addition & 6 deletions components/hello-world/configs/Linux_Config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1 @@
#define MY_CONST true
#define variable1 1
#define variable2 4
//#define MY_CONST2 House
#define MY_CONST3 42
#define VARIANT LINUX
#define VARIANT LINUX
5 changes: 0 additions & 5 deletions components/hello-world/configs/Mac_Config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1 @@
#define MY_CONST true
#define variable1 1
#define variable2 4
//#define MY_CONST2 House
#define MY_CONST3 42
#define VARIANT MAC
5 changes: 0 additions & 5 deletions components/hello-world/configs/Windows_Config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1 @@
#define MY_CONST true
#define variable1 1
#define variable2 4
//#define MY_CONST2 House
#define MY_CONST3 42
#define VARIANT WINDOWS
4 changes: 2 additions & 2 deletions components/hello-world/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
#else
"name": "@naveed235812/hello-world-windows",
#endif
"version": "1.0.3",
"description": "This component display helloworld message on screen.",
"version": "1.0.4",
"description": "This component display variant type based hello-world message on screen.",
"main": "index.js",
"bin": {
"hello-world": "./lib/index.js"
Expand Down
52 changes: 35 additions & 17 deletions components/hello-world/src/Main.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,39 @@
import * as fs from "fs";
import * as path from "path";
import * as chalk from "chalk";
#include "../VariantConfig.js"
const chalk=require("chalk");

export function Main (subStr: string): string {
// command: c-preprocessor Main.ts Main.ts
let moduleType;
/*
It provides the variant type
*/
export function GetVariantType (): string {
let variantType;
#if "VARIANT" == "MAC"
variantType = "Mac"
#elif "VARIANT" == "LINUX"
variantType = "Linux"
#else
variantType = "Windows"
#endif
return variantType;
}

/*
Creates the message string
*/
export function CreateMsgString (): string {
const variant = GetVariantType();
const msgString = "*** " + variant + " platform --> Hello-World ***"
return msgString;
}

#if "VARIANT" == "MAC"
moduleType = "MAC"
console.log("*** Mac platform -->" + subStr + " ***");
#elif "VARIANT" == "LINUX"
moduleType = "LINUX"
console.log("*** Linux platform -->" + subStr + " ***");
#else
moduleType = "WINDOWS"
console.log("*** Windows platform --> " + subStr + " ***");
#endif
return moduleType;
/*
Display's the colored message string
*/
export function DisplayMsg (messageString: string): void {
#if "VARIANT" == "MAC"
console.log(chalk.yellow(messageString));
#elif "VARIANT" == "LINUX"
console.log(chalk.red(messageString));
#else
console.log(chalk.green(messageString));
#endif
}
52 changes: 10 additions & 42 deletions components/hello-world/src/index.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,13 @@
const fs = require("fs");
const path = require("path");
const chalk=require("chalk");
const rimraf = require("rimraf");
const commander = require("commander");
const main = require("./Main").Main;

const program = new commander.Command("Hello World NPM CLI");
program.option("--displayMsg");
program.option("-g, --green", "Display the message in Green.");
program.option("-r, --red", "Display the message in Red.");

program.parse(process.argv);

if (program.green) {
console.log(chalk.green("Message was configured to show in green color."));
const displayMsg = require("./Main").DisplayMsg;
const msgString = require("./Main").CreateMsgString;

/*
Main function
*/
function main() {
const msg = msgString();
displayMsg(msg);
}

if (program.red) {
console.log(chalk.red("Message was configured to show in red color."));
}

// ** c-preprocess **
// 1st globally install this package
//command: c-preprocessor index.js outputFile.js
//-------------------------------------------------
// #include "VariantConfig.js"

// #if variable1 + variable2 == 5 && defined(MY_CONST)
// console("Multi-condition test")
// #elif "MY_CONST2" == "House"
// console.log("Equality Check Pass")
// #else
// console.log("Default Statement!")
// #endif

// #ifndef MY_CONST3
// console.log("Var is not defined!")
// #else
// console.log("Var is defined!")
// #endif
//-------------------------------------------------
main();

var str = "Hello-World";
main(str);
24 changes: 13 additions & 11 deletions components/hello-world/src/test/Main.test.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
import * as fs from "fs";
import * as path from "path";
import { expect } from "chai";
import * as rimraf from "rimraf";
import { Main } from "../Main";
#include "../../VariantConfig.js"

import { expect } from "chai";
import { CreateMsgString, GetVariantType, DisplayMsg } from "../Main";

describe("Hello-World Component Tests", async () => {
it("Get required module type", async () => {
var msgStr = "Hello World";
const moduleType = Main(msgStr);
it("verify variant and message string", async () => {
const variantType = GetVariantType();
const msgString = CreateMsgString();

#if "VARIANT" == "MAC"
expect(moduleType).to.equal("MAC");
expect(variantType).to.equal("Mac");
expect(msgString).to.equal("*** Mac platform --> Hello-World ***");
#elif "VARIANT" == "LINUX"
expect(moduleType).to.equal("LINUX");
expect(variantType).to.equal("Linux");
expect(msgString).to.equal("*** Linux platform --> Hello-World ***");
#else
expect(moduleType).to.equal("WINDOWS");
expect(variantType).to.equal("Windows");
expect(msgString).to.equal("*** Windows platform --> Hello-World ***");
#endif
DisplayMsg(msgString);
});
});

0 comments on commit 7609ff9

Please sign in to comment.