bilderhic
Advanced tools
Comparing version 1.1.1 to 1.1.2
@@ -10,2 +10,3 @@ #!/usr/bin/env node | ||
const moment = require("moment"); | ||
const Environment = require("./src/environment"); | ||
@@ -24,3 +25,7 @@ const Pipe = require("./src/commands/pipe/index"); | ||
const initialVariables = {}; | ||
const initialVariables = { | ||
timestamp: () => moment().format("YYYYMMDDHHmmss"), | ||
date: format => moment().format(format ? format[0] : "YYYY-MM-DD"), | ||
time: format => moment().format(format ? format[0] : "HHmmss"), | ||
}; | ||
@@ -27,0 +32,0 @@ for (let i = 0; i < args.length; i++) { |
{ | ||
"name": "bilderhic", | ||
"version": "1.1.1", | ||
"version": " 1.1.2", | ||
"description": "Bilderhic (bhic) is a smart and simple command tool for automatization.", | ||
@@ -59,8 +59,8 @@ "preferGlobal": true, | ||
"devDependencies": { | ||
"chai": "^4.2.0", | ||
"eslint": "^7.11.0", | ||
"chai": "^4.3.4", | ||
"eslint": "^7.25.0", | ||
"eslint-config-airbnb-base": "^14.2.0", | ||
"eslint-plugin-chai-friendly": "^0.6.0", | ||
"eslint-plugin-import": "^2.22.1", | ||
"mocha": "^8.2.0", | ||
"mocha": "^8.3.2", | ||
"nyc": "^15.1.0" | ||
@@ -74,7 +74,8 @@ }, | ||
"glob": "^7.1.6", | ||
"inquirer": "^7.3.3", | ||
"inquirer": "^8.0.0", | ||
"md5-file": "^5.0.0", | ||
"moment": "^2.29.1", | ||
"safe-eval": "git+https://github.com/hacksparrow/safe-eval.git", | ||
"yaml": "^1.7.2" | ||
} | ||
} | ||
} |
@@ -392,1 +392,26 @@ <img src="https://lucianorasente.com/public_img/bhic.png" style="max-width:100px;width:100%;"> | ||
``` | ||
Timestamp | ||
```bash | ||
bhic -c echo My timestamp is [timestamp] | ||
``` | ||
Date | ||
```bash | ||
bhic -c echo Today is [date] | ||
``` | ||
Date (custom format) | ||
```bash | ||
bhic -c echo Today is [date:YYYY-MM-DD] | ||
``` | ||
Time | ||
```bash | ||
bhic -c echo The current time is [hour] | ||
``` | ||
Time (custom format) | ||
```bash | ||
bhic -c echo The current time is [hour:HH.MM] | ||
``` |
@@ -0,3 +1,6 @@ | ||
/* eslint-disable class-methods-use-this */ | ||
/** @typedef {import("../../environment")} Environment */ | ||
const os = require('os'); | ||
const os = require("os"); | ||
const path = require("path"); | ||
@@ -4,0 +7,0 @@ const inquirer = require("inquirer"); |
@@ -102,3 +102,3 @@ const path = require("path"); | ||
if (typeof existing === "undefined") { | ||
this.variables[id] = value; | ||
this.setVariable(id, value); | ||
} | ||
@@ -115,4 +115,6 @@ } | ||
Object.keys(this.variables).forEach(k => { | ||
if (typeof this.variables[k] === "object") { | ||
extractVariables(this.variables[k], k).forEach(kv => { | ||
const variable = this.variables[k]; | ||
if (typeof variable === "object") { | ||
extractVariables(variable, k).forEach(kv => { | ||
variables[kv.key] = kv.value; | ||
@@ -158,5 +160,27 @@ }); | ||
Object.keys(variables).forEach(key => { | ||
while (finalStr.indexOf(`[${key}]`) !== -1) { | ||
const val = variables[key]; | ||
finalStr = finalStr.replace(`[${key}]`, `${val}`); | ||
while (finalStr.includes(`[${key}]`) || finalStr.includes(`[${key}:`)) { | ||
let args = null; | ||
let keyWithArgs; | ||
if (finalStr.includes(`[${key}:`)) { | ||
args = finalStr.substr(finalStr.indexOf(`[${key}:`)); | ||
args = args.substring(args.indexOf(":") + 1, args.indexOf("]")); | ||
keyWithArgs = `${key}:${args}`; | ||
} | ||
else { | ||
keyWithArgs = key; | ||
} | ||
let val = variables[key]; | ||
if (typeof variables[key] === "function") { | ||
if (args) { | ||
val = val(args); | ||
} | ||
else { | ||
val = val(); | ||
} | ||
} | ||
finalStr = finalStr.replace(`[${keyWithArgs}]`, `${val}`); | ||
} | ||
@@ -163,0 +187,0 @@ }); |
@@ -107,3 +107,10 @@ const { expect } = require("chai"); | ||
}); | ||
it("should work fine - env set example", () => { | ||
const line = "env set hola \"hola mundo\""; | ||
const expected = ["env", "set","hola", "hola mundo"]; | ||
const result = CommandsExtractor.extract(line); | ||
expect(result).deep.equals(expected); | ||
}); | ||
}); | ||
}); |
@@ -152,3 +152,19 @@ const { expect } = require("chai"); | ||
}); | ||
it("apply a function variable", () => { | ||
env.setVariable("test", () => "testVar"); | ||
const path = "[test].ok"; | ||
const result = env.applyVariables(path); | ||
const expected = "testVar.ok"; | ||
expect(result).to.equals(expected); | ||
}); | ||
it("apply a function variable with parameters", () => { | ||
env.setVariable("test", x => `testVar${x}`); | ||
const path = "[test:iable].ok"; | ||
const result = env.applyVariables(path); | ||
const expected = "testVariable.ok"; | ||
expect(result).to.equals(expected); | ||
}); | ||
}); | ||
}); |
135172
3482
417
10
+ Addedmoment@^2.29.1
+ Addedbase64-js@1.5.1(transitive)
+ Addedbl@4.1.0(transitive)
+ Addedbuffer@5.7.1(transitive)
+ Addedcli-spinners@2.9.2(transitive)
+ Addedclone@1.0.4(transitive)
+ Addeddefaults@1.0.4(transitive)
+ Addedieee754@1.2.1(transitive)
+ Addedinquirer@8.2.6(transitive)
+ Addedis-interactive@1.0.0(transitive)
+ Addedis-unicode-supported@0.1.0(transitive)
+ Addedlog-symbols@4.1.0(transitive)
+ Addedmoment@2.30.1(transitive)
+ Addedora@5.4.1(transitive)
+ Addedreadable-stream@3.6.2(transitive)
+ Addedrxjs@7.8.1(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
+ Addedstring_decoder@1.3.0(transitive)
+ Addedtslib@2.6.2(transitive)
+ Addedutil-deprecate@1.0.2(transitive)
+ Addedwcwidth@1.0.1(transitive)
+ Addedwrap-ansi@6.2.0(transitive)
- Removedinquirer@7.3.3(transitive)
- Removedrxjs@6.6.7(transitive)
- Removedtslib@1.14.1(transitive)
Updatedinquirer@^8.0.0