Skip to content

Commit

Permalink
Colors for default display, removed console.logs, new dependency json…
Browse files Browse the repository at this point in the history
… colorizer and more..
  • Loading branch information
mapoart committed Sep 17, 2020
1 parent 5699c76 commit 841b8c6
Show file tree
Hide file tree
Showing 15 changed files with 842 additions and 106 deletions.
15 changes: 0 additions & 15 deletions nexss-start/commands/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,6 @@ if (
}
}

// console.log(require("util").inspect(nexssConfig, true, 10));
// process.exit(1);

if (!Array.isArray(files)) {
files = [files];
}
Expand Down Expand Up @@ -407,17 +404,8 @@ if (cliArgs.server) {
process.chdir(PROCESS_CWD); //TODO: Later to recheck folder changing on getFiles + mess cleanup
// Recheck the Serialize (later remove??)
nexssResult = json.parse(json.stringify(nexssResult));
// const util = require("util");
// console.log("r", util.inspect(nexssResult, false, null, true));
// process.exit(1);
// console.log(nexssBuild);
// process.exit(1);
dg(`Executing..`);

// TODO: We revert back the current dir if there are any changes (should not be)
// To review
// process.chdir(process.nexssGlobalCWD);

if (cliArgs.nxsBuild) {
let buildFilename = "./build.nexss.json";
if (typeof cliArgs.nxsBuild !== "boolean") {
Expand All @@ -435,8 +423,5 @@ if (cliArgs.server) {
process.exit(0);
}

// console.log(nexssResult);
// process.exit(1);

run(nexssResult, { quiet: !cliArgs.verbose }).catch((e) => console.error(e));
}
2 changes: 1 addition & 1 deletion nexss-start/lib/pipe.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ async function run(operations, options = {}) {
})
)
.then((e) => {
// console.timeEnd(blue("Nexss Programmer"));
console.log("\n");
})
.catch((err) => {
// This is handled by nexss transform as all errors are parsed
Expand Down
10 changes: 10 additions & 0 deletions nexss-start/lib/start/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,16 @@ const getFiles = (folder, args, env, ccc) => {
}

let folderAbsolute = getPath(getName(folder.name));
// Each package can have platform dependent code. For example
// IF in the Id package is folder Linux, it will be run instead of main
// You can use symlinks to make it more DRY
if (folderAbsolute) {
const platformDependedPath = path.join(folderAbsolute, process.platform);
if (fs.existsSync(platformDependedPath)) {
folderAbsolute = platformDependedPath;
}
}

if (!folderAbsolute && folder.name !== NEXSS_SPECIAL_CHAR) {
if (!folder.filename) {
// TODO: Maybe later to add here extra/special functions like:
Expand Down
3 changes: 2 additions & 1 deletion nexss-start/lib/start/nxsStop.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ module.exports = (data) => {
console.log(
`Nexss Programmer execution stopped by command ${bold(
"nxsStop"
)}. \n Reason: ${bold(red(data.nxsStopReason))}`
)}. \n Reason: ${bold(red(JSON.stringify(data.nxsStopReason)))}`
);

r = 1;
}

Expand Down
2 changes: 1 addition & 1 deletion nexss-start/lib/transformFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const { bold } = require("../../lib/ansi");
module.exports.transformFile = (file, x, y) => {
return new Transform({
// writableObjectMode: true,
async transform(chunk, encoding, callback) {
transform(chunk, encoding, callback) {
process.chdir(y.cwd);
process.nexssCWD = y.cwd;
if (!existsSync(file)) {
Expand Down
47 changes: 8 additions & 39 deletions nexss-start/lib/transformNexss.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,8 @@ module.exports.transformNexss = (
env,
} = defaultExecuteOptions
) => {
// console.error("TRANSFORM NEXSSS!!!!!", fileName);

return new Transform({
async transform(chunk, encoding, callback) {
transform(chunk, encoding, callback) {
let startStreamTime;
if (process.argv.includes("--nxsTime")) {
startStreamTime = process.hrtime();
Expand All @@ -51,11 +49,6 @@ module.exports.transformNexss = (
chunk = chunk.toString();
}

if (chunk === "\u0003") {
// process.exit();
throw "User exited CTRL+C.";
}

let options = Object.assign({});

if (process.argv.includes("--nxsOnly")) {
Expand All @@ -72,7 +65,6 @@ module.exports.transformNexss = (
options.shell = "/bin/bash";
}

options.maxBuffer = 10485760; // 10 * 1024 * 1024;
options.cwd = cwd;
options.env = "SEE: process.env";

Expand All @@ -92,16 +84,12 @@ module.exports.transformNexss = (
options.env = env;
// args = args.filter(e => e !== "--test");

// console.log(args);
process.nexssCWD = cwd;

args2 = args.remove("--nocache");
args2 = args2.remove("--nxsPipeErrors");
args2 = args2.remove("--nxsTest");
// const argsStrings = args.map((a) =>
// a.indexOf(" ") > -1 ? `${a.replace("=", '="')}"` : a
// );
// Later batter code below

let argsStrings;
if (process.platform === "win32") {
argsStrings = args2.map((a) =>
Expand All @@ -122,26 +110,8 @@ module.exports.transformNexss = (
startCompilerTime = process.hrtime();
}

this.worker = await spawn(cmd, argsStrings, options);
this.worker = spawn(cmd, argsStrings, options);
this.worker.cmd = nexssCommand;
// let proc = new Proc(this.worker.pid, {
// filePath: path.resolve(fileName) /*required*/,
// exePath: process.nexssGlobalCWD /* command executed from here */,
// command: process.argv.slice(2).join(" "),
// });
// try {
// proc.write();
// } catch (error) {
// console.error(
// "Command " +
// bold(yellow(this.worker.cmd.trim())) +
// red(
// " failed.\n(process information saving error. Check if the systax is correct.)"
// )
// );
// process.exit(1);
// }

this.worker.on("error", (err) => {
// throw Error(err);
switch (err.code) {
Expand All @@ -154,9 +124,6 @@ module.exports.transformNexss = (

this.worker.stderr.on("data", function (err) {
const errorString = err.toString();

// console.error("ERRSTRING: " + err.toString());

if (errorString.includes("NEXSS/")) {
const exploded = errorString.split("NEXSS");
exploded.forEach((element) => {
Expand Down Expand Up @@ -201,8 +168,10 @@ module.exports.transformNexss = (
this.worker.stdout.on("data", function (data) {
// TODO: Check if trim is ok here
timeElapsed(startCompilerTime, `Response from ${bold(nexssCommand)}`);

if (cmd === "bash") {
self.push(data.toString().trim().replace(/\n/g, "\n\r"));
// self.push(data.toString().trim().replace(/\n/g, "\n\r"));
self.push(data);
return;
}

Expand Down Expand Up @@ -246,11 +215,12 @@ module.exports.transformNexss = (
!process.argv.includes("--nxsPipeErrors")
) {
// console.log("There was an error during run..", this.worker.cmd);
process.exitCode = 1;
return;
} else {
callback();
}
});

try {
// console.error(chunk);
j = JSON.parse(chunk.toString());
Expand All @@ -267,7 +237,6 @@ module.exports.transformNexss = (

nxsDebugTitle("Executed: " + this.worker.cmd, j, "yellow");

//Below maybe is in wrong placa but AutoIt doesn't work if is not here!
if (this.worker.stdin) this.worker.stdin.end();

dbg("waiting for ", this.worker.cmd);
Expand Down
2 changes: 1 addition & 1 deletion nexss-start/lib/transformOutput.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ module.exports.transformOutput = (x, y, z) =>
if (typeof data === "object") {
data = JSON.stringify(data);
}

data += ""; //Incase it is a string
callback(null, data);
}
// } else {
Expand Down
41 changes: 29 additions & 12 deletions nexss-start/lib/writeableStdout.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@ module.exports.writeableStdout = () =>
try {
chunk = JSON.parse(chunk);

// We hide variables started with _
// like username, password etc. replaced by ****
// Object.keys(chunk).forEach((e) => {
// if (e.length > 1 && e.startsWith("_")) chunk[e] = "*****";
// });

delete chunk["nexssScript"];
if (!chunk.nxsPretty) {
if (chunk["nxsDataDisplay"]) {
Expand All @@ -28,23 +22,46 @@ module.exports.writeableStdout = () =>
);
console.error(JSON.stringify(Object.keys(chunk)));
} else {
console.log(
typeof chunk === "object" ? JSON.stringify(chunk) : chunk
chunk =
typeof chunk === "object" || typeof chunk === "number"
? JSON.stringify(chunk)
: chunk;

process.stdout.write(
require("json-colorizer")(chunk, {
colors: {
STRING_KEY: "green.bold",
STRING_LITERAL: "yellow.bold",
NUMBER_LITERAL: "blue.bold",
},
})
);
}
} else {
delete chunk["nxsPretty"];
console.log(JSON.stringify(chunk, null, 2));
console.log(
require("json-colorizer")(chunk, {
pretty: true,
colors: {
STRING_KEY: "green.bold",
STRING_LITERAL: "yellow.bold",
NUMBER_LITERAL: "blue.bold",
},
})
);
}

timeElapsed(chunk.nxsTime);
} catch (error) {
if (process.argv.indexOf("--nxsModule") >= 0) {
process.stdout.write(JSON.stringify({ nxsOut: chunk }));
} else {
process.stdout.write(
typeof chunk === "object" ? JSON.stringify(chunk) : chunk
);
chunk =
typeof chunk === "object" || typeof chunk === "number"
? JSON.stringify(chunk)
: chunk;

process.stdout.write(require("json-colorizer")(chunk));
}
}

Expand Down
Loading

0 comments on commit 841b8c6

Please sign in to comment.