Skip to content

Commit

Permalink
Merge pull request #4 from naveedkhan8067/io-c_preprocessor
Browse files Browse the repository at this point in the history
C-Preprocessor Example
  • Loading branch information
naveedkhan8067 authored Dec 3, 2023
2 parents 796b9ac + 4a3a3ba commit 098cf97
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 1 deletion.
1 change: 1 addition & 0 deletions components/hello-world/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"test": "echo \"Error: no test specified\" && exit 1"
},
"dependencies": {
"c-preprocessor": "^0.2.13",
"chalk": "^2.4.1",
"commander": "^2.19.0",
"readdirp": "^3.0.0"
Expand Down
15 changes: 15 additions & 0 deletions components/hello-world/src/Main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import * as fs from "fs";
import * as path from "path";
import * as chalk from "chalk";

export function Main (subStr: string) {
// command: c-preprocessor Main.ts MainoutputFile.ts
#include "config1.js"
#if "VARIENT" == "MAC"
console.log("Mac platform string value: " + subStr);
#elif "VARIENT" == "LINUX"
console.log("Linux platform string value: " + subStr);
#else
console.log("Windows platform string value: " + subStr);
#endif
}
Empty file.
6 changes: 6 additions & 0 deletions components/hello-world/src/config1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#define MY_CONST true
#define variable1 1
#define variable2 4
//#define MY_CONST2 House
#define MY_CONST3 42
#define VARIENT LINUX
27 changes: 26 additions & 1 deletion components/hello-world/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ 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");
Expand All @@ -17,4 +18,28 @@ if (program.green) {

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 "config1.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
//-------------------------------------------------

var str = "Hello World";
main(str);

0 comments on commit 098cf97

Please sign in to comment.