@node-cli/secret 1.2.3 → 1.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/parse.js +3 -3
- package/dist/parse.js.map +1 -1
- package/dist/secret.js +2 -2
- package/dist/secret.js.map +1 -1
- package/dist/utilities.js +3 -3
- package/dist/utilities.js.map +1 -1
- package/package.json +11 -7
package/dist/parse.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { parser } from "@node-cli/parser";
|
|
1
|
+
/* v8 ignore start */ import { parser } from "@node-cli/parser";
|
|
2
2
|
import kleur from "kleur";
|
|
3
|
-
/*
|
|
3
|
+
/* v8 ignore next 67 */ export const config = parser({
|
|
4
4
|
meta: import.meta,
|
|
5
5
|
examples: [
|
|
6
6
|
{
|
|
@@ -55,6 +55,6 @@ import kleur from "kleur";
|
|
|
55
55
|
}
|
|
56
56
|
],
|
|
57
57
|
usage: "secret [options] [input] [output]"
|
|
58
|
-
});
|
|
58
|
+
}); /* v8 ignore stop */
|
|
59
59
|
|
|
60
60
|
//# sourceMappingURL=parse.js.map
|
package/dist/parse.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/parse.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["../src/parse.ts"],"sourcesContent":["/* v8 ignore start */\nimport { parser } from \"@node-cli/parser\";\nimport kleur from \"kleur\";\n\nexport type Flags = {\n\tdecrypt?: boolean;\n\tencrypt?: boolean;\n\thelp?: boolean;\n\tversion?: boolean;\n};\n\nexport type Parameters = {\n\tinput?: string;\n\toutput?: string;\n};\n\nexport type Configuration = {\n\tflags?: Flags;\n\tparameters?: Parameters;\n};\n\n/* v8 ignore next 67 */\nexport const config: Configuration = parser({\n\tmeta: import.meta,\n\texamples: [\n\t\t{\n\t\t\tcommand: 'secret -e \"my-file.txt\" \"my-file.txt.enc\"',\n\t\t\tcomment:\n\t\t\t\t'## Encrypt the file \"my-file.txt\" and save the result in\\n ## \"my-file.txt.enc\" - password will be prompted',\n\t\t},\n\t\t{\n\t\t\tcommand: 'secret -d \"my-file.txt.enc\" \"my-file.txt\"',\n\t\t\tcomment: `## Decrypt the file \"my-file.txt.enc\" and save the\\n ## result in \"my-file.txt\" - password will be prompted`,\n\t\t},\n\t],\n\tflags: {\n\t\tdecrypt: {\n\t\t\tshortFlag: \"d\",\n\t\t\tdescription: `Decrypt a password protected file`,\n\t\t\ttype: \"boolean\",\n\t\t},\n\t\tencrypt: {\n\t\t\tshortFlag: \"e\",\n\t\t\tdescription: `Encrypt a file with a password`,\n\t\t\ttype: \"boolean\",\n\t\t},\n\t\thelp: {\n\t\t\tshortFlag: \"h\",\n\t\t\tdescription: \"Display help instructions\",\n\t\t\ttype: \"boolean\",\n\t\t},\n\t\tversion: {\n\t\t\tshortFlag: \"v\",\n\t\t\tdescription: \"Output the current version\",\n\t\t\ttype: \"boolean\",\n\t\t},\n\t},\n\tparameters: {\n\t\tinput: {\n\t\t\tdescription: \"The file to encrypt or decrypt\",\n\t\t},\n\t\toutput: {\n\t\t\tdescription:\n\t\t\t\t\"The file to create in order to save the result of the encryption or decryption\",\n\t\t},\n\t},\n\trestrictions: [\n\t\t{\n\t\t\texit: 1,\n\t\t\tmessage: () =>\n\t\t\t\tkleur.red(\n\t\t\t\t\t`\\nError: one of --encrypt or --decrypt option must be provided.`,\n\t\t\t\t),\n\t\t\ttest: (x: { encrypt: boolean; decrypt: boolean }) =>\n\t\t\t\tx.encrypt === false && x.decrypt === false,\n\t\t},\n\t\t{\n\t\t\texit: 1,\n\t\t\tmessage: () =>\n\t\t\t\tkleur.red(\n\t\t\t\t\t`\\nError: either --encrypt or --decrypt option must be provided, but not both.`,\n\t\t\t\t),\n\t\t\ttest: (x: { encrypt: boolean; decrypt: boolean }) =>\n\t\t\t\tx.encrypt === true && x.decrypt === true,\n\t\t},\n\t],\n\n\tusage: \"secret [options] [input] [output]\",\n});\n/* v8 ignore stop */\n"],"names":["parser","kleur","config","meta","examples","command","comment","flags","decrypt","shortFlag","description","type","encrypt","help","version","parameters","input","output","restrictions","exit","message","red","test","x","usage"],"mappings":"AAAA,mBAAmB,GACnB,SAASA,MAAM,QAAQ,mBAAmB;AAC1C,OAAOC,WAAW,QAAQ;AAmB1B,qBAAqB,GACrB,OAAO,MAAMC,SAAwBF,OAAO;IAC3CG,MAAM;IACNC,UAAU;QACT;YACCC,SAAS;YACTC,SACC;QACF;QACA;YACCD,SAAS;YACTC,SAAS,CAAC,8GAA8G,CAAC;QAC1H;KACA;IACDC,OAAO;QACNC,SAAS;YACRC,WAAW;YACXC,aAAa,CAAC,iCAAiC,CAAC;YAChDC,MAAM;QACP;QACAC,SAAS;YACRH,WAAW;YACXC,aAAa,CAAC,8BAA8B,CAAC;YAC7CC,MAAM;QACP;QACAE,MAAM;YACLJ,WAAW;YACXC,aAAa;YACbC,MAAM;QACP;QACAG,SAAS;YACRL,WAAW;YACXC,aAAa;YACbC,MAAM;QACP;IACD;IACAI,YAAY;QACXC,OAAO;YACNN,aAAa;QACd;QACAO,QAAQ;YACPP,aACC;QACF;IACD;IACAQ,cAAc;QACb;YACCC,MAAM;YACNC,SAAS,IACRnB,MAAMoB,GAAG,CACR,CAAC,+DAA+D,CAAC;YAEnEC,MAAM,CAACC,IACNA,EAAEX,OAAO,KAAK,SAASW,EAAEf,OAAO,KAAK;QACvC;QACA;YACCW,MAAM;YACNC,SAAS,IACRnB,MAAMoB,GAAG,CACR,CAAC,6EAA6E,CAAC;YAEjFC,MAAM,CAACC,IACNA,EAAEX,OAAO,KAAK,QAAQW,EAAEf,OAAO,KAAK;QACtC;KACA;IAEDgB,OAAO;AACR,GAAG,CACH,kBAAkB"}
|
package/dist/secret.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
/*
|
|
2
|
+
/* v8 ignore start */ import { displayConfirmation, displayPromptWithPassword, logger, processFileWithPassword, shouldContinue } from "./utilities.js";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import fs from "fs-extra";
|
|
5
5
|
import { config } from "./parse.js";
|
|
@@ -42,6 +42,6 @@ try {
|
|
|
42
42
|
}
|
|
43
43
|
} catch (error) {
|
|
44
44
|
logger.error(error);
|
|
45
|
-
}
|
|
45
|
+
} /* v8 ignore stop */
|
|
46
46
|
|
|
47
47
|
//# sourceMappingURL=secret.js.map
|
package/dist/secret.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/secret.ts"],"sourcesContent":["#!/usr/bin/env node\n/*
|
|
1
|
+
{"version":3,"sources":["../src/secret.ts"],"sourcesContent":["#!/usr/bin/env node\n/* v8 ignore start */\n\nimport {\n\tdisplayConfirmation,\n\tdisplayPromptWithPassword,\n\tlogger,\n\tprocessFileWithPassword,\n\tshouldContinue,\n} from \"./utilities.js\";\n\nimport path from \"node:path\";\nimport fs from \"fs-extra\";\nimport { config } from \"./parse.js\";\n\nconst ENCRYPT = \"encrypt\";\nconst DECRYPT = \"decrypt\";\n\n/**\n * Caching the \"action\" for future usage (encrypt or decrypt).\n */\nconst actionName = config.flags.encrypt ? ENCRYPT : DECRYPT;\n\n/**\n * Extracting the input and output files.\n */\nlet inputFile: string,\n\toutputFile: string,\n\toutputFileExists: boolean = false;\nif (Object.entries(config.parameters).length > 0) {\n\tinputFile = config.parameters[\"0\"];\n\toutputFile = config.parameters[\"1\"];\n\tif (!fs.existsSync(inputFile)) {\n\t\tlogger.printErrorsAndExit([`File \"${inputFile}\" does not exist!`], 1);\n\t}\n\tif (fs.existsSync(outputFile)) {\n\t\toutputFileExists = true;\n\t}\n}\n\nif (outputFileExists) {\n\tconst goodToGo = await displayConfirmation(\n\t\t`The file ${outputFile} already exists, overwrite it?`,\n\t);\n\tshouldContinue(goodToGo);\n}\n\nconst password = await displayPromptWithPassword(\n\t`Enter password to ${actionName} the file`,\n);\n\ntry {\n\tawait processFileWithPassword({\n\t\tencode: config.flags.encrypt,\n\t\tinput: inputFile,\n\t\toutput: outputFile,\n\t\tpassword,\n\t});\n\tlogger.log();\n\tlogger.info(`File ${path.basename(inputFile)} was ${actionName}ed.`);\n\tif (outputFileExists) {\n\t\tlogger.info(`The result was saved in the file ${outputFile}`);\n\t}\n} catch (error) {\n\tlogger.error(error);\n}\n/* v8 ignore stop */\n"],"names":["displayConfirmation","displayPromptWithPassword","logger","processFileWithPassword","shouldContinue","path","fs","config","ENCRYPT","DECRYPT","actionName","flags","encrypt","inputFile","outputFile","outputFileExists","Object","entries","parameters","length","existsSync","printErrorsAndExit","goodToGo","password","encode","input","output","log","info","basename","error"],"mappings":";AACA,mBAAmB,GAEnB,SACCA,mBAAmB,EACnBC,yBAAyB,EACzBC,MAAM,EACNC,uBAAuB,EACvBC,cAAc,QACR,iBAAiB;AAExB,OAAOC,UAAU,YAAY;AAC7B,OAAOC,QAAQ,WAAW;AAC1B,SAASC,MAAM,QAAQ,aAAa;AAEpC,MAAMC,UAAU;AAChB,MAAMC,UAAU;AAEhB;;CAEC,GACD,MAAMC,aAAaH,OAAOI,KAAK,CAACC,OAAO,GAAGJ,UAAUC;AAEpD;;CAEC,GACD,IAAII,WACHC,YACAC,mBAA4B;AAC7B,IAAIC,OAAOC,OAAO,CAACV,OAAOW,UAAU,EAAEC,MAAM,GAAG,GAAG;IACjDN,YAAYN,OAAOW,UAAU,CAAC,IAAI;IAClCJ,aAAaP,OAAOW,UAAU,CAAC,IAAI;IACnC,IAAI,CAACZ,GAAGc,UAAU,CAACP,YAAY;QAC9BX,OAAOmB,kBAAkB,CAAC;YAAC,CAAC,MAAM,EAAER,UAAU,iBAAiB,CAAC;SAAC,EAAE;IACpE;IACA,IAAIP,GAAGc,UAAU,CAACN,aAAa;QAC9BC,mBAAmB;IACpB;AACD;AAEA,IAAIA,kBAAkB;IACrB,MAAMO,WAAW,MAAMtB,oBACtB,CAAC,SAAS,EAAEc,WAAW,8BAA8B,CAAC;IAEvDV,eAAekB;AAChB;AAEA,MAAMC,WAAW,MAAMtB,0BACtB,CAAC,kBAAkB,EAAES,WAAW,SAAS,CAAC;AAG3C,IAAI;IACH,MAAMP,wBAAwB;QAC7BqB,QAAQjB,OAAOI,KAAK,CAACC,OAAO;QAC5Ba,OAAOZ;QACPa,QAAQZ;QACRS;IACD;IACArB,OAAOyB,GAAG;IACVzB,OAAO0B,IAAI,CAAC,CAAC,KAAK,EAAEvB,KAAKwB,QAAQ,CAAChB,WAAW,KAAK,EAAEH,WAAW,GAAG,CAAC;IACnE,IAAIK,kBAAkB;QACrBb,OAAO0B,IAAI,CAAC,CAAC,iCAAiC,EAAEd,YAAY;IAC7D;AACD,EAAE,OAAOgB,OAAO;IACf5B,OAAO4B,KAAK,CAACA;AACd,EACA,kBAAkB"}
|
package/dist/utilities.js
CHANGED
|
@@ -19,7 +19,7 @@ export const processFileWithPassword = async (options)=>{
|
|
|
19
19
|
logger.log(fileProcessor(password, data));
|
|
20
20
|
}
|
|
21
21
|
};
|
|
22
|
-
/*
|
|
22
|
+
/* v8 ignore next 12 */ export const displayConfirmation = async (message)=>{
|
|
23
23
|
const questions = {
|
|
24
24
|
default: true,
|
|
25
25
|
message: message || "Do you want to continue?",
|
|
@@ -30,7 +30,7 @@ export const processFileWithPassword = async (options)=>{
|
|
|
30
30
|
const answers = await inquirer.prompt(questions);
|
|
31
31
|
return answers.goodToGo;
|
|
32
32
|
};
|
|
33
|
-
/*
|
|
33
|
+
/* v8 ignore next 16 */ export const displayPromptWithPassword = async (message)=>{
|
|
34
34
|
const questions = {
|
|
35
35
|
message: message,
|
|
36
36
|
name: "password",
|
|
@@ -45,7 +45,7 @@ export const processFileWithPassword = async (options)=>{
|
|
|
45
45
|
const answers = await inquirer.prompt(questions);
|
|
46
46
|
return answers.password;
|
|
47
47
|
};
|
|
48
|
-
/*
|
|
48
|
+
/* v8 ignore next 8 */ export const shouldContinue = (goodToGo)=>{
|
|
49
49
|
if (!goodToGo) {
|
|
50
50
|
logger.log("\nBye then!");
|
|
51
51
|
// eslint-disable-next-line unicorn/no-process-exit
|
package/dist/utilities.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utilities.ts"],"sourcesContent":["import { Logger } from \"@node-cli/logger\";\nimport fs from \"fs-extra\";\nimport inquirer from \"inquirer\";\n\nimport { decrypt, encrypt } from \"./lib.js\";\n\nexport const logger = new Logger({\n\tboring: process.env.NODE_ENV === \"test\",\n});\n\nconst UTF8 = \"utf8\";\nconst DEFAULT_FILE_ENCODING = UTF8;\n\n/**\n * Process a file with a given password. The file can be\n * encoded or decoded depending on the `encode` flag.\n * @param {Boolean} encode whether to encode or decode the file\n * @param {String} input the input file path\n * @param {String} [output] the output file path\n * @param {String} password the password to use\n * @return {Promise} a promise that resolves when\n * the file has been processed.\n */\nexport type ProcessFileOptions = {\n\tencode: boolean;\n\tinput: string;\n\toutput?: string;\n\tpassword: string;\n};\nexport const processFileWithPassword = async (\n\toptions: ProcessFileOptions,\n): Promise<void> => {\n\tconst { encode, input, output, password } = options;\n\tconst fileProcessor = encode ? encrypt : decrypt;\n\tconst data = await fs.readFile(input, DEFAULT_FILE_ENCODING);\n\n\tif (output) {\n\t\t// Save data to output file\n\t\tawait fs.outputFile(output, fileProcessor(password, data));\n\t} else {\n\t\t// Print to stdout directly\n\t\tlogger.log(fileProcessor(password, data));\n\t}\n};\n\n/*
|
|
1
|
+
{"version":3,"sources":["../src/utilities.ts"],"sourcesContent":["import { Logger } from \"@node-cli/logger\";\nimport fs from \"fs-extra\";\nimport inquirer from \"inquirer\";\n\nimport { decrypt, encrypt } from \"./lib.js\";\n\nexport const logger = new Logger({\n\tboring: process.env.NODE_ENV === \"test\",\n});\n\nconst UTF8 = \"utf8\";\nconst DEFAULT_FILE_ENCODING = UTF8;\n\n/**\n * Process a file with a given password. The file can be\n * encoded or decoded depending on the `encode` flag.\n * @param {Boolean} encode whether to encode or decode the file\n * @param {String} input the input file path\n * @param {String} [output] the output file path\n * @param {String} password the password to use\n * @return {Promise} a promise that resolves when\n * the file has been processed.\n */\nexport type ProcessFileOptions = {\n\tencode: boolean;\n\tinput: string;\n\toutput?: string;\n\tpassword: string;\n};\nexport const processFileWithPassword = async (\n\toptions: ProcessFileOptions,\n): Promise<void> => {\n\tconst { encode, input, output, password } = options;\n\tconst fileProcessor = encode ? encrypt : decrypt;\n\tconst data = await fs.readFile(input, DEFAULT_FILE_ENCODING);\n\n\tif (output) {\n\t\t// Save data to output file\n\t\tawait fs.outputFile(output, fileProcessor(password, data));\n\t} else {\n\t\t// Print to stdout directly\n\t\tlogger.log(fileProcessor(password, data));\n\t}\n};\n\n/* v8 ignore next 12 */\nexport const displayConfirmation = async (message: string) => {\n\tconst questions = {\n\t\tdefault: true,\n\t\tmessage: message || \"Do you want to continue?\",\n\t\tname: \"goodToGo\",\n\t\ttype: \"confirm\",\n\t};\n\tlogger.log();\n\tconst answers = await inquirer.prompt(questions);\n\treturn answers.goodToGo;\n};\n\n/* v8 ignore next 16 */\nexport const displayPromptWithPassword = async (message: string) => {\n\tconst questions = {\n\t\tmessage: message,\n\t\tname: \"password\",\n\t\ttype: \"password\",\n\t\tvalidate(value: string) {\n\t\t\tif (!value) {\n\t\t\t\treturn \"Password cannot be empty...\";\n\t\t\t}\n\t\t\treturn true;\n\t\t},\n\t};\n\tconst answers = await inquirer.prompt(questions);\n\treturn answers.password;\n};\n\n/* v8 ignore next 8 */\nexport const shouldContinue = (goodToGo: boolean) => {\n\tif (!goodToGo) {\n\t\tlogger.log(\"\\nBye then!\");\n\t\t// eslint-disable-next-line unicorn/no-process-exit\n\t\tprocess.exit(0);\n\t}\n\treturn true;\n};\n"],"names":["Logger","fs","inquirer","decrypt","encrypt","logger","boring","process","env","NODE_ENV","UTF8","DEFAULT_FILE_ENCODING","processFileWithPassword","options","encode","input","output","password","fileProcessor","data","readFile","outputFile","log","displayConfirmation","message","questions","default","name","type","answers","prompt","goodToGo","displayPromptWithPassword","validate","value","shouldContinue","exit"],"mappings":"AAAA,SAASA,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ACA,UAAU;QACd1B,OAAOiB,GAAG,CAAC;QACX,mDAAmD;QACnDf,QAAQ6B,IAAI,CAAC;IACd;IACA,OAAO;AACR,EAAE"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@node-cli/secret",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.4",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Arno Versini",
|
|
6
6
|
"description": "Secret is a CLI tool that can encode or decode a file with a password",
|
|
@@ -19,19 +19,23 @@
|
|
|
19
19
|
"build:types": "tsc",
|
|
20
20
|
"clean": "rimraf dist types coverage",
|
|
21
21
|
"lint": "biome lint src",
|
|
22
|
-
"test": "
|
|
23
|
-
"test:coverage": "
|
|
22
|
+
"test": "vitest run --globals",
|
|
23
|
+
"test:coverage": "vitest run --coverage --globals",
|
|
24
24
|
"test:watch": "npm run test -- --watch",
|
|
25
25
|
"watch": "swc --strip-leading-paths --watch --out-dir dist src"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@node-cli/logger": "1.
|
|
29
|
-
"@node-cli/parser": "2.
|
|
30
|
-
"fs-extra": "11.
|
|
28
|
+
"@node-cli/logger": "1.3.1",
|
|
29
|
+
"@node-cli/parser": "2.4.1",
|
|
30
|
+
"fs-extra": "11.3.0",
|
|
31
31
|
"inquirer": "9.3.7"
|
|
32
32
|
},
|
|
33
33
|
"publishConfig": {
|
|
34
34
|
"access": "public"
|
|
35
35
|
},
|
|
36
|
-
"
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@vitest/coverage-v8": "3.2.4",
|
|
38
|
+
"vitest": "3.2.4"
|
|
39
|
+
},
|
|
40
|
+
"gitHead": "2cef8f88aa5316a1789caad2bd7327ca908ccb9f"
|
|
37
41
|
}
|