-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
18d8235
commit 7ce7824
Showing
3 changed files
with
281 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,186 @@ | ||
#!/usr/bin/env node | ||
import {nodefony , kernel} from '../dist/index.js'; | ||
import {nodefony , kernel} from '../dist/node/index.js'; | ||
console.log(nodefony) | ||
|
||
const simpleLogger = function (cli) { | ||
return new Promise((resolve, reject) => { | ||
cli.log(`START simpleLogger : ${cli.getEmoji("clapper")}`); | ||
cli.log(`Emoji : ${cli.getEmoji()}`); | ||
cli.blankLine(); | ||
cli.log(`Emoji : ${cli.getEmoji()}`, "DEBUG"); | ||
cli.blankLine(); | ||
cli.log(`Emoji : ${cli.getEmoji()}`, "ERROR"); | ||
cli.blankLine(); | ||
cli.log(`Emoji : ${cli.getEmoji()}`, "WARNING"); | ||
cli.log(`END simpleLogger : ${cli.getEmoji("checkered_flag")}`); | ||
resolve(cli); | ||
}); | ||
}; | ||
|
||
// CLI | ||
const cli = new nodefony.Cli("MY CLI", { | ||
resize: true, | ||
onResize: (cli) => { | ||
cli.log(`RESIZE : ${cli.getEmoji()}`); | ||
}, | ||
onStart: (cli) => { | ||
cli.log("ON START"); | ||
// PROMISE | ||
return simpleLogger(cli) | ||
// .then((cli) => | ||
// // SPINNER | ||
// spinner(cli, 5000)) | ||
.then((cli) => | ||
// TABLE | ||
tableExample(cli)) | ||
.then((cli) => | ||
// PROGRESS | ||
progress(cli, 20)) | ||
.then((cli) => | ||
// PROGRESS 2 | ||
progress2(cli, 20)) | ||
.then((cli) => | ||
// Sparkline | ||
Sparkline(cli)) | ||
.then((cli) => | ||
// Sparkline 2 | ||
Sparkline2(cli, 30)) | ||
.then((cli) => { | ||
cli.log(`TERMINATE MY CLI : ${cli.getEmoji("checkered_flag")}`); | ||
cli.terminate(); | ||
}) | ||
.catch((e) => { | ||
console.error(e); | ||
cli.terminate(1); | ||
}); | ||
} | ||
}); | ||
|
||
|
||
const random = function (nb) { | ||
return Math.floor(Math.random() * nb) + 1; | ||
}; | ||
const severity = [ | ||
"EMERGENCY", | ||
"ALERT", | ||
"CRITIC", | ||
"ERROR", | ||
"WARNING", | ||
"NOTICE", | ||
"INFO", | ||
"DEBUG" | ||
]; | ||
const spinner = function (cli, time) { | ||
return new Promise((resolve, reject) => { | ||
cli.log(`START SPINNER : ${cli.getEmoji("clapper")}`); | ||
cli.startSpinner("MY CLI", ["⣾", "⣽", "⣻", "⢿", "⡿", "⣟", "⣯", "⣷"]); | ||
cli.blankLine(); | ||
cli.log(`MESSAGE : ${cli.getEmoji()}`); | ||
const interval = setInterval(() => { | ||
cli.spinlog(`MESSAGE : ${cli.getEmoji()}`, severity[random(7)]); | ||
}, 0); | ||
setTimeout(() => { | ||
cli.stopSpinner(); | ||
cli.log(`END SPINNER : ${cli.getEmoji("checkered_flag")}`); | ||
clearInterval(interval); | ||
resolve(cli); | ||
}, time || 2000); | ||
}); | ||
}; | ||
|
||
const tableExample = function (cli) { | ||
return new Promise((resolve, reject) => { | ||
cli.log(`START TABLE : ${cli.getEmoji("clapper")}`); | ||
const options = { | ||
head: [ | ||
"COLUMN 1", | ||
"COLUMN 2", | ||
"COLUMN 3", | ||
"COLUMN 4" | ||
] | ||
}; | ||
const table = cli.displayTable(null, options); | ||
for (let i = 0; i < 10; i++) { | ||
table.push([severity[random(7)], random(100), random(200), random(300)]); | ||
} | ||
console.log(table.toString()); | ||
const tab = []; | ||
for (let i = 0; i < 10; i++) { | ||
tab.push([severity[random(7)], random(100), random(200), random(300)]); | ||
} | ||
const table2 = cli.displayTable(tab, options); | ||
cli.log(`END TABLE : ${cli.getEmoji("checkered_flag")}`); | ||
resolve(cli); | ||
}); | ||
}; | ||
|
||
const progress = function (cli, time) { | ||
return new Promise((resolve, reject) => { | ||
cli.log(`START PROGRESS : ${cli.getEmoji("clapper")}`); | ||
let i = 0; | ||
const pg = cli.createProgress(50); | ||
var interval = setInterval(() => { | ||
cli.log(pg.update(++i, 50), "SPINNER"); | ||
if (i === 50) { | ||
cli.blankLine(); | ||
clearInterval(interval); | ||
cli.log(`\u001b[13pEND PROGRESS : ${cli.getEmoji("checkered_flag")}`); | ||
resolve(cli); | ||
} | ||
}, time || 50); | ||
}); | ||
}; | ||
|
||
const progress2 = function (cli, time) { | ||
return new Promise((resolve, reject) => { | ||
cli.log(`START PROGRESS 2 : ${cli.getEmoji("clapper")}`); | ||
const pg = cli.createProgress(100); | ||
let i = 0; | ||
// cli.startSpinner("PROGRESS"); | ||
var interval = setInterval(() => { | ||
cli.log(pg.update(++i, 100), "SPINNER"); | ||
if (i === 100) { | ||
cli.blankLine(); | ||
clearInterval(interval); | ||
// cli.stopSpinner(); | ||
cli.log(`MY PROGRESS ${pg.update(i, 100)}`); | ||
cli.log(`END PROGRESS 2 : ${cli.getEmoji("checkered_flag")}`); | ||
resolve(cli); | ||
} | ||
}, time || 30); | ||
}); | ||
}; | ||
|
||
const Sparkline = function (cli, time) { | ||
return new Promise((resolve, reject) => { | ||
cli.log(`START Sparkline : ${cli.getEmoji("clapper")}`); | ||
const sl = cli.createSparkline([10, 12, 3, 7, 12, 9, 23, 10, 9, 19, 16, 18, 12, 12], " reqs/sec"); | ||
cli.log(sl); | ||
cli.log(`END Sparkline : ${cli.getEmoji("checkered_flag")}`); | ||
resolve(cli); | ||
}); | ||
}; | ||
|
||
const Sparkline2 = function (cli, time) { | ||
return new Promise((resolve, reject) => { | ||
cli.log(`START Sparkline : ${cli.getEmoji("clapper")}`); | ||
let i = 0; | ||
const tab = []; | ||
cli.startSpinner("Sparkline"); | ||
const sl = cli.createSparkline(tab, " reqs/sec"); | ||
var myInterval = setInterval(() => { | ||
++i; | ||
tab.push(random(200)); | ||
const sl = cli.createSparkline(tab, " reqs/sec"); | ||
cli.log(sl, "SPINNER"); | ||
if (i === 100) { | ||
cli.blankLine(); | ||
clearInterval(myInterval); | ||
cli.stopSpinner(); | ||
cli.log(`END Sparkline2 : ${cli.getEmoji("checkered_flag")}`); | ||
resolve(cli); | ||
} | ||
}, time || 30); | ||
}); | ||
}; | ||
|
||
console.log(nodefony, kernel) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
#!/usr/bin/env node | ||
const {nodefony, kernel} = require("../../dist/index.js") | ||
const {nodefony, kernel} = require("../../dist/node-cjs/index.cjs") | ||
|
||
console.log(nodefony , kernel) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
#!/usr/bin/env node | ||
// nodefony | ||
|
||
const lib = require('../../dist/node-cjs/index.cjs') | ||
const nodefony = lib.default | ||
|
||
// https://github.com/SBoudrias/Inquirer.js/tree/master/examples | ||
const questions = [{ | ||
type: "confirm", | ||
name: "toBeDelivered", | ||
message: "Is this for delivery?", | ||
default: false | ||
}, | ||
{ | ||
type: "input", | ||
name: "phone", | ||
message: "What's your phone number?", | ||
validate (value) { | ||
const pass = value.match(/^([01]{1})?[-.\s]?\(?(\d{3})\)?[-.\s]?(\d{3})[-.\s]?(\d{4})\s?((?:#|ext\.?\s?|x\.?\s?){1}(?:\d+)?)?$/i); | ||
if (pass) { | ||
return true; | ||
} | ||
|
||
return "Please enter a valid phone number"; | ||
} | ||
}, | ||
{ | ||
type: "list", | ||
name: "size", | ||
message: "What size do you need?", | ||
choices: ["Large", "Medium", "Small"], | ||
filter (val) { | ||
return val.toLowerCase(); | ||
} | ||
}, | ||
{ | ||
type: "input", | ||
name: "quantity", | ||
message: "How many do you need?", | ||
validate (value) { | ||
const valid = !isNaN(parseFloat(value)); | ||
return valid || "Please enter a number"; | ||
}, | ||
filter: Number | ||
}, | ||
{ | ||
type: "expand", | ||
name: "toppings", | ||
message: "What about the toppings?", | ||
choices: [{ | ||
key: "p", | ||
name: "Pepperoni and cheese", | ||
value: "PepperoniCheese" | ||
}, | ||
{ | ||
key: "a", | ||
name: "All dressed", | ||
value: "alldressed" | ||
}, | ||
{ | ||
key: "w", | ||
name: "Hawaiian", | ||
value: "hawaiian" | ||
}] | ||
}, | ||
{ | ||
type: "rawlist", | ||
name: "beverage", | ||
message: "You also get a free 2L beverage", | ||
choices: ["Pepsi", "7up", "Coke"] | ||
}, | ||
{ | ||
type: "input", | ||
name: "comments", | ||
message: "Any comments on your purchase experience?", | ||
default: "Nope, all good!" | ||
}, | ||
{ | ||
type: "list", | ||
name: "prize", | ||
message: "For leaving a comment, you get a freebie", | ||
choices: ["cake", "fries"], | ||
when (answers) { | ||
return answers.comments !== "Nope, all good!"; | ||
} | ||
}]; | ||
|
||
const cli = new nodefony.Cli("CLI", null, null, { | ||
onStart: (cli) => { | ||
cli.prompt(questions) | ||
.then((answers) => { | ||
console.log("\nOrder receipt:"); | ||
console.log(JSON.stringify(answers, null, " ")); | ||
}); | ||
} | ||
}); |