kaven-utils
Advanced tools
Comparing version 5.2.1 to 5.2.2
@@ -8,6 +8,6 @@ #!/usr/bin/env node | ||
* @create: 2018-11-05 14:59:09.639 | ||
* @modify: 2023-12-02 12:29:23.357 | ||
* @version: 5.2.1 | ||
* @times: 188 | ||
* @lines: 378 | ||
* @modify: 2023-12-02 14:03:51.576 | ||
* @version: 5.2.2 | ||
* @times: 190 | ||
* @lines: 362 | ||
* @copyright: Copyright © 2018-2023 Kaven. All Rights Reserved. | ||
@@ -14,0 +14,0 @@ * @description: [description] |
221
bin.js
@@ -9,6 +9,6 @@ #!/usr/bin/env node | ||
* @create: 2018-11-05 14:59:09.639 | ||
* @modify: 2023-12-02 12:29:23.357 | ||
* @version: 5.2.1 | ||
* @times: 188 | ||
* @lines: 378 | ||
* @modify: 2023-12-02 14:03:51.576 | ||
* @version: 5.2.2 | ||
* @times: 190 | ||
* @lines: 362 | ||
* @copyright: Copyright © 2018-2023 Kaven. All Rights Reserved. | ||
@@ -97,22 +97,16 @@ * @description: [description] | ||
for (const item of allFiles) { | ||
try { | ||
// Get file stats to determine if it's a directory or file | ||
const stats = yield (0, index_1.GetFileStats)(item); | ||
// If stats are undefined, continue to the next item | ||
if (stats === undefined) { | ||
continue; | ||
} | ||
// Check if it's a directory and remove it using promises.rmdir | ||
if (stats.isDirectory()) { | ||
yield node_fs_1.promises.rmdir(item); | ||
} | ||
else { | ||
// If it's a file, remove it using promises.unlink | ||
yield node_fs_1.promises.unlink(item); | ||
} | ||
// Get file stats to determine if it's a directory or file | ||
const stats = yield (0, index_1.GetFileStats)(item); | ||
// If stats are undefined, continue to the next item | ||
if (stats === undefined) { | ||
continue; | ||
} | ||
catch (ex) { | ||
// Log a warning if an error occurs during the removal process | ||
index_1.KavenLogger.Default.Warn(ex); | ||
// Check if it's a directory and remove it using promises.rmdir | ||
if (stats.isDirectory()) { | ||
yield node_fs_1.promises.rmdir(item); | ||
} | ||
else { | ||
// If it's a file, remove it using promises.unlink | ||
yield node_fs_1.promises.unlink(item); | ||
} | ||
} | ||
@@ -132,32 +126,26 @@ } | ||
.action((command, otherCommands, options) => __awaiter(void 0, void 0, void 0, function* () { | ||
try { | ||
// Concatenate all commands including the first one | ||
const allCommands = (index_1.IsWin32 && options.win32commands) ? options.win32commands : [command].concat(otherCommands); | ||
const executeOptions = { | ||
decoderEncoding: options.encoding, | ||
spawn: !!options.spawn, | ||
spawnOptions: { | ||
shell: (typeof options.shell === "string" || typeof options.shell === "boolean") ? options.shell : undefined, | ||
}, | ||
execOptions: { | ||
shell: typeof options.shell === "string" ? options.shell : undefined, | ||
}, | ||
}; | ||
// If running sequentially, iterate through and run each command one by one | ||
if (options.sequential) { | ||
for (const c of allCommands) { | ||
yield (0, index_1.Execute)(c, executeOptions); | ||
} | ||
// Concatenate all commands including the first one | ||
const allCommands = (index_1.IsWin32 && options.win32commands) ? options.win32commands : [command].concat(otherCommands); | ||
const executeOptions = { | ||
decoderEncoding: options.encoding, | ||
spawn: !!options.spawn, | ||
spawnOptions: { | ||
shell: (typeof options.shell === "string" || typeof options.shell === "boolean") ? options.shell : undefined, | ||
}, | ||
execOptions: { | ||
shell: typeof options.shell === "string" ? options.shell : undefined, | ||
}, | ||
}; | ||
// If running sequentially, iterate through and run each command one by one | ||
if (options.sequential) { | ||
for (const c of allCommands) { | ||
yield (0, index_1.Execute)(c, executeOptions); | ||
} | ||
else { | ||
// If not running sequentially, execute all commands concurrently | ||
for (const c of allCommands) { | ||
(0, index_1.Execute)(c, executeOptions); | ||
} | ||
} | ||
else { | ||
// If not running sequentially, execute all commands concurrently | ||
for (const c of allCommands) { | ||
(0, index_1.Execute)(c, executeOptions); | ||
} | ||
} | ||
catch (ex) { | ||
// Log an error if an exception occurs during execution | ||
index_1.KavenLogger.Default.Error(ex); | ||
} | ||
})); | ||
@@ -176,37 +164,31 @@ // gen_cert | ||
.action((options) => __awaiter(void 0, void 0, void 0, function* () { | ||
try { | ||
// Disable console logging if verbose mode is not enabled | ||
if (!options.verbose) { | ||
index_1.KavenLogger.Default.EnableConsole = false; | ||
} | ||
// Configure certificate generation options based on command-line inputs | ||
const certOptions = {}; | ||
if (options.dir) { | ||
certOptions.certGenerateDir = options.dir; | ||
} | ||
else { | ||
certOptions.certGenerateDir = "./generated"; | ||
} | ||
if (options.bits) { | ||
certOptions.size = Number(options.bits); | ||
} | ||
if (options.days) { | ||
certOptions.days = Number(options.days); | ||
} | ||
if (options.cn) { | ||
certOptions.serverSubj = { | ||
CN: options.cn, | ||
}; | ||
} | ||
if (options.openssl) { | ||
certOptions.openssl = options.openssl; | ||
} | ||
// Generate the certificate and save the result to a JSON file | ||
const result = yield (0, index_1.GenerateCertificate)(certOptions); | ||
result.Save((0, kaven_basic_1.CombinePath)(certOptions.certGenerateDir, "cert.json")); | ||
// Disable console logging if verbose mode is not enabled | ||
if (!options.verbose) { | ||
index_1.KavenLogger.Default.EnableConsole = false; | ||
} | ||
catch (ex) { | ||
// Log an error if an exception occurs during certificate generation | ||
index_1.KavenLogger.Default.Error(ex); | ||
// Configure certificate generation options based on command-line inputs | ||
const certOptions = {}; | ||
if (options.dir) { | ||
certOptions.certGenerateDir = options.dir; | ||
} | ||
else { | ||
certOptions.certGenerateDir = "./generated"; | ||
} | ||
if (options.bits) { | ||
certOptions.size = Number(options.bits); | ||
} | ||
if (options.days) { | ||
certOptions.days = Number(options.days); | ||
} | ||
if (options.cn) { | ||
certOptions.serverSubj = { | ||
CN: options.cn, | ||
}; | ||
} | ||
if (options.openssl) { | ||
certOptions.openssl = options.openssl; | ||
} | ||
// Generate the certificate and save the result to a JSON file | ||
const result = yield (0, index_1.GenerateCertificate)(certOptions); | ||
result.Save((0, kaven_basic_1.CombinePath)(certOptions.certGenerateDir, "cert.json")); | ||
})); | ||
@@ -255,46 +237,44 @@ // proxy | ||
var _d, _e, _f, _g; | ||
try { | ||
let cwd = process.cwd(); | ||
let config = { | ||
sourceDocumentFileOrDirectory: "./docs", | ||
sourceVersionFile: "./dist/package.json", | ||
targetRootDirectory: "../Kaven-Documents", | ||
targetDirectoryName: (0, node_path_1.basename)(cwd), | ||
}; | ||
if (options.config) { | ||
const configFile = (0, index_1.AppendPathToDirectory)(cwd, options.config); | ||
if ((0, index_1.IsPathExistSync)(configFile)) { | ||
index_1.KavenLogger.Default.Info(`Loading configuration from file: ${configFile}`); | ||
const json = yield (0, index_1.LoadJsonFile)(configFile); | ||
config = Object.assign(config, json); | ||
cwd = (0, node_path_1.dirname)(configFile); | ||
} | ||
let cwd = process.cwd(); | ||
let config = { | ||
sourceDocumentFileOrDirectory: "./docs", | ||
sourceVersionFile: "./dist/package.json", | ||
targetRootDirectory: "../Kaven-Documents", | ||
targetDirectoryName: (0, node_path_1.basename)(cwd), | ||
}; | ||
if (options.config) { | ||
const configFile = (0, index_1.AppendPathToDirectory)(cwd, options.config); | ||
if ((0, index_1.IsPathExistSync)(configFile)) { | ||
index_1.KavenLogger.Default.Info(`Loading configuration from file: ${configFile}`); | ||
const json = yield (0, index_1.LoadJsonFile)(configFile); | ||
config = Object.assign(config, json); | ||
cwd = (0, node_path_1.dirname)(configFile); | ||
} | ||
if (options.variables && options.variables.length > 0) { | ||
config.variables = {}; | ||
for (const variable of options.variables) { | ||
const items = variable.split(":"); | ||
if (items.length === 2) { | ||
config.variables[items[0].trim()] = items[1].trim(); | ||
} | ||
else { | ||
throw new Error(`Config file not exists: ${configFile}`); | ||
} | ||
} | ||
if (options.variables && options.variables.length > 0) { | ||
config.variables = {}; | ||
for (const variable of options.variables) { | ||
const items = variable.split(":"); | ||
if (items.length === 2) { | ||
config.variables[items[0].trim()] = items[1].trim(); | ||
} | ||
} | ||
index_1.KavenLogger.Default.Info(`Current Working Directory: ${cwd}`); | ||
config.sourceDocumentFileOrDirectory = (0, index_1.AppendPathToDirectory)(cwd, config.sourceDocumentFileOrDirectory); | ||
config.sourceVersionFile = (0, index_1.AppendPathToDirectory)(cwd, config.sourceVersionFile); | ||
config.targetRootDirectory = (0, index_1.AppendPathToDirectory)(cwd, config.targetRootDirectory); | ||
if (config.commands) { | ||
for (const command of config.commands) { | ||
if ((_e = (_d = command.options) === null || _d === void 0 ? void 0 : _d.execOptions) === null || _e === void 0 ? void 0 : _e.cwd) { | ||
command.options.execOptions.cwd = (0, index_1.AppendPathToDirectory)(cwd, command.options.execOptions.cwd); | ||
} | ||
} | ||
index_1.KavenLogger.Default.Info(`Current Working Directory: ${cwd}`); | ||
config.sourceDocumentFileOrDirectory = (0, index_1.AppendPathToDirectory)(cwd, config.sourceDocumentFileOrDirectory); | ||
config.sourceVersionFile = (0, index_1.AppendPathToDirectory)(cwd, config.sourceVersionFile); | ||
config.targetRootDirectory = (0, index_1.AppendPathToDirectory)(cwd, config.targetRootDirectory); | ||
if (config.commands) { | ||
for (const command of config.commands) { | ||
if ((_e = (_d = command.options) === null || _d === void 0 ? void 0 : _d.execOptions) === null || _e === void 0 ? void 0 : _e.cwd) { | ||
command.options.execOptions.cwd = (0, index_1.AppendPathToDirectory)(cwd, command.options.execOptions.cwd); | ||
} | ||
} | ||
(_f = config.updateReadmeFile) !== null && _f !== void 0 ? _f : (config.updateReadmeFile = true); | ||
(_g = config.gitCommit) !== null && _g !== void 0 ? _g : (config.gitCommit = true); | ||
yield (0, index_1.ContinuousIntegrationForDocuments)(config); | ||
} | ||
catch (ex) { | ||
index_1.KavenLogger.Default.Error(ex); | ||
} | ||
(_f = config.updateReadmeFile) !== null && _f !== void 0 ? _f : (config.updateReadmeFile = true); | ||
(_g = config.gitCommit) !== null && _g !== void 0 ? _g : (config.gitCommit = true); | ||
yield (0, index_1.ContinuousIntegrationForDocuments)(config); | ||
})); | ||
@@ -334,2 +314,3 @@ // where | ||
index_1.KavenLogger.Default.Error(err); | ||
process.exit(-1); | ||
})); |
{ | ||
"name": "kaven-utils", | ||
"version": "5.2.1", | ||
"version": "5.2.2", | ||
"description": "Utils for Node.js.", | ||
@@ -5,0 +5,0 @@ "main": "index", |
373492
9369