#!/usr/bin/env node
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const commander_1 = require("commander");
const fs = tslib_1.__importStar(require("fs"));
const lodash_1 = require("lodash");
const fsh = tslib_1.__importStar(require("../lib/index"));
/**
* Below are the APIs of CLI (Command Line Interface). Some inappropriate titles are used because they are generated by JsDoc.
*
* @namespace CLI
*/
// ls
/**
* @function ls
* @memberof CLI
* @example
Usage: npx fs-hospitality ls [options] <dirPath>
Detecting a text specification.
Options:
-V, --version output the version number
-D, --is-only-dir Exacting directories only
-F, --is-only-file Exacting files only
-S, --excludes-symlink Excluding symbolic-links
-M, --matched-reg-exp <exp> Ex. "\d+\.txt$"
-I, --ignored-reg-exp <exp> Ex. "[_\-.]cache\d+"
-W, --with-file-types Returns file info objects (like fs.Dirent)
-h, --help display help for command
// Ex1. No options
$ npx fs-hospitality ls "D:\Test"
[
'DirFoo-Symlink',
'fileRoot2-Symlink.log',
'fileRoot2.log',
'FILE_ROOT1.TXT',
'DirFoo',
'DirBar',
'DirBar\\fileBar1.txt',
'DirBar\\DirQuux',
'DirBar\\DirQuux\\fileQuux1-Symlink.txt',
'DirBar\\DirQuux\\fileQuux1.txt'
]
*/
commander_1.program
.command('ls <dirPath>')
.version('1.0.0')
.description('Detecting a text specification.')
.option('-D, --is-only-dir', 'Exacting directories only')
.option('-F, --is-only-file', 'Exacting files only')
.option('-S, --excludes-symlink', 'Excluding symbolic-links')
.option('-M, --matched-reg-exp <exp>', 'Ex. "\\.txt$"')
.option('-I, --ignored-reg-exp <exp>', 'Ex. "[_\\-.]cache\\d+"')
.option('-W, --with-file-types', 'Returns file info objects (fs.Dirent)')
.action(async (dirPath, options) => {
const dest = await fsh.readdirRecursively(dirPath, options);
console.dir(dest);
});
// detect-text-spec
/**
* @function detect-text-spec
* @memberof CLI
* @example
npx fs-hospitality detect-text-spec [options] <filePath>
Detecting a text specification.
Options:
-V, --version output the version number
-T, --type <name> "all" | "encoding" | "eol"
-h, --help display help for command
// Ex1.
$ npx fs-hospitality detect-text-spec "D:\Test\src.wsf" --type "encoding"
SJIS
// Ex2.
$ npx fs-hospitality detect-text-spec "D:\Test\src.wsf" --type "eol"
crlf
*/
commander_1.program
.command('detect-text-spec <filePath>')
.version('1.0.0')
.description('Detecting a text specification.')
.option('-T, --type <name>', '"all" | "encoding" | "eol"')
.action((filePath, options) => {
const detectType = (0, lodash_1.get)(options, 'type', 'all');
const data = fs.readFileSync(filePath);
if (detectType === 'encoding' || detectType === 'all') {
console.log(fsh.detectTextEncoding(data));
}
if (detectType === 'eol' || detectType === 'all') {
console.log(fsh.detectTextEol(data));
}
});
// conv-text-enc
/**
* @function conv-text
* @memberof CLI
* @example
Usage: npx fs-hospitality conv-text [options] <filePath> [destPath]
Converting a text encoding.
Options:
-V, --version output the version number
-T, --trim <type> "all" | "start" | "end"
-E, --eol <type> "lf" | "cr" | "crlf" or "unix" | "mac" | "dos"
-B, --bom Add BOM. Only UTFx encoding
-e, --encoding <name> "UTF-16BE", "Shift_JIS", ... "Default: "utf8" (default: "utf8")
-h, --help display help for command
// Ex1.
> npx fs-hospitality conv-text "D:\Test\src.wsf" --trim "all" --eol "dos" --bom
*/
commander_1.program
.command('conv-text <filePath> [destPath]')
.version('1.0.0')
.description('Converting a text encoding.')
.option('-T, --trim <type>', '"all" | "start" | "end"')
.option('-E, --eol <type>', '"lf" | "cr" | "crlf" or "unix" | "mac" | "dos"')
.option('-B, --bom', 'Add BOM. Only UTFx encoding')
.option('-e, --encoding <name>', '"UTF-16BE", "Shift_JIS", ... "Default: "utf8"', 'utf8')
.action((filePath, destPath, options) => {
const trim = (0, lodash_1.get)(options, 'trim', null);
const eol = (0, lodash_1.get)(options, 'eol', null);
const bom = (0, lodash_1.get)(options, 'bom', null);
const encoding = (0, lodash_1.get)(options, 'encoding', null);
const textData = fsh.readAsTextSync(filePath);
let dest = destPath;
if (!dest)
dest = filePath;
fsh.writeAsTextSync(dest, textData, {
trim,
eol,
bom,
encoding,
});
});
commander_1.program.parse(process.argv);
//# sourceMappingURL=index.js.map