Grammalecte  Check-in [c5b6c3d6cb]

Overview
Comment:[njs] Minor change
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | njs | nodejs
Files: files | file ages | folders
SHA3-256: c5b6c3d6cb1e0a9401018bb588d6ed53f897e8b1fca06e8bf82b4fbfc8bd8c85
User & Date: IllusionPerdu on 2018-10-15 21:00:57
Original Comment: [js] Minor change
Other Links: branch diff | manifest | tags
Context
2018-10-16
10:16
[njs] Add TF option Chg how to set option check-in: ee5d077740 user: IllusionPerdu tags: njs, nodejs
2018-10-15
21:00
[njs] Minor change check-in: c5b6c3d6cb user: IllusionPerdu tags: njs, nodejs
20:35
[njs] Fix some spell/typo check-in: 36bf480e0d user: IllusionPerdu tags: njs, nodejs
Changes

Modified gc_lang/fr/nodejs/cli/bin/gramma-cli.js from [c22a3b0bfa] to [c328932d14].

13
14
15
16
17
18
19






20
21
22
23
24

25
26
27
28
29
30
31
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment
https://stackoverflow.com/questions/41058569/what-is-the-difference-between-const-and-const-in-javascript
*/

const argCmd = require("../lib/minimist.js")(process.argv.slice(2));
const { performance } = require("perf_hooks");







var repJson = false;
var repPerf = false;

var sBufferConsole = "";
var sCmdToExec = "";


var cmdAction = {
    help: {
        short: "",
        description: "Affiche les informations que vous lisez ;)",
        execute: ""
    },







>
>
>
>
>
>





>







13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment
https://stackoverflow.com/questions/41058569/what-is-the-difference-between-const-and-const-in-javascript
*/

const argCmd = require("../lib/minimist.js")(process.argv.slice(2));
const { performance } = require("perf_hooks");

//Initialisation des messages
const msgStart = "\x1b[31mBienvenu sur Grammalecte pour NodeJS!!!\x1b[0m\n";
const msgPrompt = "\x1b[36mGrammaJS\x1b[33m>\x1b[0m ";
const msgSuite = "\x1b[33m…\x1b[0m ";
const msgEnd = "\x1b[31m\x1b[5m\x1b[5mBye bye!\x1b[0m";

var repJson = false;
var repPerf = false;

var sBufferConsole = "";
var sCmdToExec = "";
var sText = "";

var cmdAction = {
    help: {
        short: "",
        description: "Affiche les informations que vous lisez ;)",
        execute: ""
    },
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
                        repText += "\n " + ascii1a + "  " + ascii2 + ' "' + suggestion + '"';
                    }
                }
            }
        }
    }


    if ("help" in oRep) {
        let colorNum = 31;
        for (const action of oRep.help) {
            //Uniquement pour le fun on met de la couleur ;)
            if(action.indexOf('===')>-1){
                console.log("\x1b["+colorNum+"m"+action+"\x1b[0m");
                colorNum = colorNum + 2;
            } else {
                console.log(action);
            }
        }
    }

    if (oRep.time) {
        repText += "\nExécuté en: " + oRep.time + " ms";
    }
    return repText.trim("\n");
}

var sWord = "";
var actionToExec = function(aArg) {
    let repAction = {};
    let tStart, tEnd;

    if (!isBool(aArg.text)) {
        sWord = aArg.text;
    }

    repAction["text"] = sWord;

    if (getArg(aArg, ["json"])) {
        repJson = getArgVal(aArg, ["json"]);
        repAction["Json"] = repJson ? "ON" : "OFF";
    }

    if (getArg(aArg, ["perf"])) {
        repPerf = getArgVal(aArg, ["perf"]);
        repAction["Perf"] = repPerf ? "ON" : "OFF";
    }

    if (repPerf) {
        tStart = performance.now();
    }

    if (getArg(aArg, ["gceoption"])) {
        let sOpt = sWord.split(" ");
        if (sOpt[0] == "reset") {
            oGrammarChecker.resetGceOptions();
            repAction["GceOption"] = "reset";
        } else {
            let bOptVal = toBool(sOpt[1]);
            oGrammarChecker.setGceOption(sOpt[0], bOptVal);
            repAction["GceOption"] = sOpt[0] + " " + (bOptVal ? "ON" : "OFF");
        }
    }

    for (const action in aArg) {
        if (cmdAction[action] && cmdAction[action].execute !== "") {
            if (!isBool(aArg[action]) && aArg[action] !== "") {
                repAction.text = aArg[action];
                sWord = repAction.text;
            }
            if (!isBool(repAction.text)) {
                repAction[action] = oGrammarChecker[cmdAction[action].execute](repAction.text);
            } else {
                repAction[action] = "NoText";
            }
        }







<



















<
|




|


|
















|














|







285
286
287
288
289
290
291

292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310

311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
                        repText += "\n " + ascii1a + "  " + ascii2 + ' "' + suggestion + '"';
                    }
                }
            }
        }
    }


    if ("help" in oRep) {
        let colorNum = 31;
        for (const action of oRep.help) {
            //Uniquement pour le fun on met de la couleur ;)
            if(action.indexOf('===')>-1){
                console.log("\x1b["+colorNum+"m"+action+"\x1b[0m");
                colorNum = colorNum + 2;
            } else {
                console.log(action);
            }
        }
    }

    if (oRep.time) {
        repText += "\nExécuté en: " + oRep.time + " ms";
    }
    return repText.trim("\n");
}


function actionToExec(aArg) {
    let repAction = {};
    let tStart, tEnd;

    if (!isBool(aArg.text)) {
        sText = aArg.text;
    }

    repAction["text"] = sText;

    if (getArg(aArg, ["json"])) {
        repJson = getArgVal(aArg, ["json"]);
        repAction["Json"] = repJson ? "ON" : "OFF";
    }

    if (getArg(aArg, ["perf"])) {
        repPerf = getArgVal(aArg, ["perf"]);
        repAction["Perf"] = repPerf ? "ON" : "OFF";
    }

    if (repPerf) {
        tStart = performance.now();
    }

    if (getArg(aArg, ["gceoption"])) {
        let sOpt = sText.split(" ");
        if (sOpt[0] == "reset") {
            oGrammarChecker.resetGceOptions();
            repAction["GceOption"] = "reset";
        } else {
            let bOptVal = toBool(sOpt[1]);
            oGrammarChecker.setGceOption(sOpt[0], bOptVal);
            repAction["GceOption"] = sOpt[0] + " " + (bOptVal ? "ON" : "OFF");
        }
    }

    for (const action in aArg) {
        if (cmdAction[action] && cmdAction[action].execute !== "") {
            if (!isBool(aArg[action]) && aArg[action] !== "") {
                repAction.text = aArg[action];
                sText = repAction.text;
            }
            if (!isBool(repAction.text)) {
                repAction[action] = oGrammarChecker[cmdAction[action].execute](repAction.text);
            } else {
                repAction[action] = "NoText";
            }
        }
386
387
388
389
390
391
392
393

394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424

425
426
427
428
429
430
431
    }

    if (repJson) {
        return JSON.stringify(repAction);
    } else {
        return repToText(repAction);
    }
};


function argToExec(aCommand, aText, rl, resetCmd = true){
    let execAct = {};
    aCommand = aCommand.toLowerCase();

    if (!isBool(aText)) {
        execAct["text"] = aText;
        execAct[aCommand] = true;
    } else {
        execAct[aCommand] = toBool(aText);
    }

    console.log(actionToExec(execAct));
    //sBufferConsole = "";
    if (resetCmd){
        sCmdToExec = "";
    }

    if (typeof(rl) !== "undefined"){
        rl.setPrompt("\x1b[36mGrammaJS\x1b[33m>\x1b[0m ");
    }
}

function completer(line) {
    var hits = cmdAll.filter(function(c) {
        if (c.indexOf(line) == 0) {
            return c;
        }
    });
    return [hits && hits.length ? hits : cmdAll, line];
}


if (process.argv.length <= 2) {
    console.log(actionToExec({help:true}));
} else {
    //var GrammarChecker = require("./api.js");
    //console.log(module.paths);
    var GrammarChecker = require("grammalecte");







<
>



















|











>







391
392
393
394
395
396
397

398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
    }

    if (repJson) {
        return JSON.stringify(repAction);
    } else {
        return repToText(repAction);
    }

}

function argToExec(aCommand, aText, rl, resetCmd = true){
    let execAct = {};
    aCommand = aCommand.toLowerCase();

    if (!isBool(aText)) {
        execAct["text"] = aText;
        execAct[aCommand] = true;
    } else {
        execAct[aCommand] = toBool(aText);
    }

    console.log(actionToExec(execAct));
    //sBufferConsole = "";
    if (resetCmd){
        sCmdToExec = "";
    }

    if (typeof(rl) !== "undefined"){
        rl.setPrompt(msgPrompt);
    }
}

function completer(line) {
    var hits = cmdAll.filter(function(c) {
        if (c.indexOf(line) == 0) {
            return c;
        }
    });
    return [hits && hits.length ? hits : cmdAll, line];
}


if (process.argv.length <= 2) {
    console.log(actionToExec({help:true}));
} else {
    //var GrammarChecker = require("./api.js");
    //console.log(module.paths);
    var GrammarChecker = require("grammalecte");
474
475
476
477
478
479
480
481
482
483
484
485

486
487
488
489
490
491
492

493
494

495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
                    reponseRequest(oParams, aResponse);
                }
            }
        });
        server.listen(argCmd.port || 2212);
        console.log("Server started on http://127.0.0.1:" + (argCmd.port || 2212) + "/");
    } else if (getArg(argCmd, ["i", "interactive"])) {
        const readline = require("readline");
        const reg = /(.*?) (.*)/gm;

        process.stdin.setEncoding("utf8");


        const rl = readline.createInterface({
            crlfDelay: Infinity,
            input: process.stdin,
            output: process.stdout,
            completer: completer,
            prompt: "\x1b[36mGrammaJS\x1b[33m>\x1b[0m "
        });

        //console.log( process.stdin.isTTY );
        process.stdout.write("\x1b[31mBienvenu sur Grammalecte pour NodeJS!!!\x1b[0m\n");

        rl.prompt();
        rl.on("line", sBuffer => {
            //process.stdout.write
            if (sBuffer == "exit") {
                console.log("\x1b[31m\x1b[5m\x1b[5mBye bye!\x1b[0m");
                process.exit(0);
            }

            let lg = sBuffer.toLowerCase().trim();
            let bSpace = lg.indexOf(" ") > -1;
            //sBufferConsole
            //console.log("\""+sBuffer+"\"");
            if (!bSpace) {
                //console.log("=> ", lg.slice(0, lg.length-1), cmdAll.indexOf( lg.slice(-1) ));
                if (cmdOne.indexOf(lg) > -1){
                    argToExec(lg, sBuffer, rl, true);
                } else if (cmdAll.indexOf(lg) > -1) {
                    sBufferConsole = "";
                    sCmdToExec = lg;
                    //Prompt simple pour distinguer que c"est une suite d"une commande
                    rl.setPrompt("\x1b[33m>\x1b[0m ");
                } else if (lg.slice(1) == sCmdToExec) {
                    argToExec(sCmdToExec, sBufferConsole, rl, true);
                } else if (cmdAll.indexOf(lg.slice(0, lg.length - 1)) > -1) {
                    argToExec(lg.slice(0, lg.length - 1), sBufferConsole, rl, true);
                } else if (lg == "") {
                    sBufferConsole += "\n";
                }
            } else if (sCmdToExec == "") {
                let regRep = /(.*?) (.*)/gm.exec(sBuffer);
                //console.log(regRep.length,sBuffer);
                if (regRep && regRep.length == 3) {
                    argToExec(regRep[1], regRep[2]);
                }
            } else {
                sBufferConsole += sBuffer + "\n";
            }

            rl.prompt();
        }).on("close", () => {
            console.log("\n\x1b[31m\x1b[5mBye bye!\x1b[0m");
            process.exit(0);
        });
    } else {
        console.log(actionToExec(argCmd));
    }
}







<
<
<


>





|

>

<
>




|





<
<

<






|



















|






480
481
482
483
484
485
486



487
488
489
490
491
492
493
494
495
496
497
498

499
500
501
502
503
504
505
506
507
508
509


510

511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
                    reponseRequest(oParams, aResponse);
                }
            }
        });
        server.listen(argCmd.port || 2212);
        console.log("Server started on http://127.0.0.1:" + (argCmd.port || 2212) + "/");
    } else if (getArg(argCmd, ["i", "interactive"])) {



        process.stdin.setEncoding("utf8");

        const readline = require("readline");
        const rl = readline.createInterface({
            crlfDelay: Infinity,
            input: process.stdin,
            output: process.stdout,
            completer: completer,
            prompt: msgPrompt
        });

        //console.log( process.stdin.isTTY );

        console.log(msgStart);
        rl.prompt();
        rl.on("line", sBuffer => {
            //process.stdout.write
            if (sBuffer == "exit") {
                console.log(msgEnd);
                process.exit(0);
            }

            let lg = sBuffer.toLowerCase().trim();
            let bSpace = lg.indexOf(" ") > -1;


            if (!bSpace) {

                if (cmdOne.indexOf(lg) > -1){
                    argToExec(lg, sBuffer, rl, true);
                } else if (cmdAll.indexOf(lg) > -1) {
                    sBufferConsole = "";
                    sCmdToExec = lg;
                    //Prompt simple pour distinguer que c"est une suite d"une commande
                    rl.setPrompt(msgSuite);
                } else if (lg.slice(1) == sCmdToExec) {
                    argToExec(sCmdToExec, sBufferConsole, rl, true);
                } else if (cmdAll.indexOf(lg.slice(0, lg.length - 1)) > -1) {
                    argToExec(lg.slice(0, lg.length - 1), sBufferConsole, rl, true);
                } else if (lg == "") {
                    sBufferConsole += "\n";
                }
            } else if (sCmdToExec == "") {
                let regRep = /(.*?) (.*)/gm.exec(sBuffer);
                //console.log(regRep.length,sBuffer);
                if (regRep && regRep.length == 3) {
                    argToExec(regRep[1], regRep[2]);
                }
            } else {
                sBufferConsole += sBuffer + "\n";
            }

            rl.prompt();
        }).on("close", () => {
            console.log(msgEnd);
            process.exit(0);
        });
    } else {
        console.log(actionToExec(argCmd));
    }
}

Modified gc_lang/fr/nodejs/cli/package.json from [5d07f6ca63] to [e0a3054dc0].

14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
  "bin": {
    "gramma-cli": "bin/gramma-cli.js"
  },
  "engines": {
    "node": ">=9.0.0"
  },
  "scripts": {
    "gramma-cli": "node bin/gramma-cli.js"
  },
  "dependencies": {
    "grammalecte": "~1.0.0"
  },
  "files": [
    "bin",
    "lib",







|







14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
  "bin": {
    "gramma-cli": "bin/gramma-cli.js"
  },
  "engines": {
    "node": ">=9.0.0"
  },
  "scripts": {
    "test": "node bin/gramma-cli.js"
  },
  "dependencies": {
    "grammalecte": "~1.0.0"
  },
  "files": [
    "bin",
    "lib",

Modified gc_lang/fr/nodejs/core/package.json from [f9b31c7c8a] to [fbedcd1684].

11
12
13
14
15
16
17
18
19
20
  "license": "GPL-3.0-or-later",
  "homepage": "https://www.dicollecte.org/",
  "main": "api.js",
  "engines": {
    "node": ">=9.0.0"
  },
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  }
}







|


11
12
13
14
15
16
17
18
19
20
  "license": "GPL-3.0-or-later",
  "homepage": "https://www.dicollecte.org/",
  "main": "api.js",
  "engines": {
    "node": ">=9.0.0"
  },
  "scripts": {
    "test": "echo \"Error: no test specified\""
  }
}