@theunwalked/cardigantime 0.0.1
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/.gitcarve/config.yaml +10 -0
- package/.gitcarve/context/content.md +1 -0
- package/LICENSE +65 -0
- package/README.md +2 -0
- package/dist/cardigantime.cjs +40 -0
- package/dist/cardigantime.cjs.map +1 -0
- package/dist/cardigantime.d.ts +9 -0
- package/dist/cardigantime.js +373 -0
- package/dist/cardigantime.js.map +1 -0
- package/dist/configure.cjs +12 -0
- package/dist/configure.cjs.map +1 -0
- package/dist/configure.d.ts +6 -0
- package/dist/configure.js +8 -0
- package/dist/configure.js.map +1 -0
- package/dist/constants.cjs +35 -0
- package/dist/constants.cjs.map +1 -0
- package/dist/constants.d.ts +8 -0
- package/dist/constants.js +27 -0
- package/dist/constants.js.map +1 -0
- package/dist/error/ArgumentError.d.ts +5 -0
- package/dist/read.cjs +69 -0
- package/dist/read.cjs.map +1 -0
- package/dist/read.d.ts +3 -0
- package/dist/read.js +46 -0
- package/dist/read.js.map +1 -0
- package/dist/types.cjs +13 -0
- package/dist/types.cjs.map +1 -0
- package/dist/types.d.ts +40 -0
- package/dist/types.js +9 -0
- package/dist/types.js.map +1 -0
- package/dist/util/storage.cjs +149 -0
- package/dist/util/storage.cjs.map +1 -0
- package/dist/util/storage.d.ts +31 -0
- package/dist/util/storage.js +126 -0
- package/dist/util/storage.js.map +1 -0
- package/dist/validate.cjs +130 -0
- package/dist/validate.cjs.map +1 -0
- package/dist/validate.d.ts +18 -0
- package/dist/validate.js +123 -0
- package/dist/validate.js.map +1 -0
- package/eslint.config.mjs +82 -0
- package/nodemon.json +14 -0
- package/package.json +65 -0
- package/vite.config.ts +98 -0
- package/vitest.config.ts +17 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Cardigantime allows you to configure a command-line tool from a default configuration file.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
Copyright 2025 Semicolon Ambulance
|
|
2
|
+
|
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License.
|
|
5
|
+
You may obtain a copy of the License at
|
|
6
|
+
|
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
|
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
See the License for the specific language governing permissions and
|
|
13
|
+
limitations under the License.
|
|
14
|
+
|
|
15
|
+
Apache License
|
|
16
|
+
Version 2.0, January 2004
|
|
17
|
+
http://www.apache.org/licenses/
|
|
18
|
+
|
|
19
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
20
|
+
|
|
21
|
+
1. Definitions.
|
|
22
|
+
|
|
23
|
+
"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
|
|
24
|
+
|
|
25
|
+
"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
|
|
26
|
+
|
|
27
|
+
"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
|
|
28
|
+
|
|
29
|
+
"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
|
|
30
|
+
|
|
31
|
+
"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
|
|
32
|
+
|
|
33
|
+
"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
|
|
36
|
+
|
|
37
|
+
"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
|
|
38
|
+
|
|
39
|
+
"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
|
|
40
|
+
|
|
41
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
|
|
42
|
+
|
|
43
|
+
2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
|
|
44
|
+
|
|
45
|
+
3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
|
|
46
|
+
|
|
47
|
+
4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
|
|
48
|
+
|
|
49
|
+
You must give any other recipients of the Work or Derivative Works a copy of this License; and
|
|
50
|
+
You must cause any modified files to carry prominent notices stating that You changed the files; and
|
|
51
|
+
You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
|
|
52
|
+
If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
|
|
53
|
+
You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
|
|
54
|
+
|
|
55
|
+
5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
|
|
56
|
+
|
|
57
|
+
6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
|
|
58
|
+
|
|
59
|
+
7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
|
|
60
|
+
|
|
61
|
+
8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
|
|
62
|
+
|
|
63
|
+
9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
|
|
64
|
+
|
|
65
|
+
END OF TERMS AND CONDITIONS
|
package/README.md
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
+
|
|
5
|
+
const configure = require('./configure.cjs');
|
|
6
|
+
const constants = require('./constants.cjs');
|
|
7
|
+
const read = require('./read.cjs');
|
|
8
|
+
const validate = require('./validate.cjs');
|
|
9
|
+
const types = require('./types.cjs');
|
|
10
|
+
|
|
11
|
+
// Make create function generic
|
|
12
|
+
const create = (pOptions)=>{
|
|
13
|
+
const defaults = {
|
|
14
|
+
...constants.DEFAULT_OPTIONS,
|
|
15
|
+
...pOptions.defaults
|
|
16
|
+
};
|
|
17
|
+
const features = pOptions.features || constants.DEFAULT_FEATURES;
|
|
18
|
+
const configShape = pOptions.configShape;
|
|
19
|
+
let logger = pOptions.logger || constants.DEFAULT_LOGGER;
|
|
20
|
+
const options = {
|
|
21
|
+
defaults,
|
|
22
|
+
features,
|
|
23
|
+
configShape,
|
|
24
|
+
logger
|
|
25
|
+
};
|
|
26
|
+
const setLogger = (pLogger)=>{
|
|
27
|
+
logger = pLogger;
|
|
28
|
+
options.logger = pLogger;
|
|
29
|
+
};
|
|
30
|
+
return {
|
|
31
|
+
setLogger,
|
|
32
|
+
configure: (command)=>configure.configure(command, options),
|
|
33
|
+
validate: (config)=>validate.validate(config, options),
|
|
34
|
+
read: (args)=>read.read(args, options)
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
exports.ConfigSchema = types.ConfigSchema;
|
|
39
|
+
exports.create = create;
|
|
40
|
+
//# sourceMappingURL=cardigantime.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cardigantime.cjs","sources":["../src/cardigantime.ts"],"sourcesContent":["import { Command } from 'commander';\nimport { Args, DefaultOptions, Feature, Cardigantime, Logger, Options } from 'types';\nimport { z, ZodObject } from 'zod';\nimport { configure } from './configure';\nimport { DEFAULT_FEATURES, DEFAULT_LOGGER, DEFAULT_OPTIONS } from './constants';\nimport { read } from './read';\nimport { ConfigSchema } from 'types';\nimport { validate } from './validate';\n\nexport * from './types';\n\n// Make create function generic\nexport const create = <T extends z.ZodRawShape>(pOptions: {\n defaults: Pick<DefaultOptions, 'configDirectory'> & Partial<Omit<DefaultOptions, 'configDirectory'>>,\n features?: Feature[],\n configShape: T, // Make configShape mandatory\n logger?: Logger,\n}): Cardigantime<T> => {\n\n\n const defaults: DefaultOptions = { ...DEFAULT_OPTIONS, ...pOptions.defaults } as DefaultOptions;\n const features = pOptions.features || DEFAULT_FEATURES;\n const configShape = pOptions.configShape;\n let logger = pOptions.logger || DEFAULT_LOGGER;\n\n const options: Options<T> = {\n defaults,\n features,\n configShape, // Store the shape\n logger,\n }\n\n const setLogger = (pLogger: Logger) => {\n logger = pLogger;\n options.logger = pLogger;\n }\n\n return {\n setLogger,\n configure: (command: Command) => configure(command, options),\n validate: (config: z.infer<ZodObject<T & typeof ConfigSchema.shape>>) => validate(config, options),\n read: (args: Args) => read(args, options),\n }\n}\n\n\n\n\n\n"],"names":["create","pOptions","defaults","DEFAULT_OPTIONS","features","DEFAULT_FEATURES","configShape","logger","DEFAULT_LOGGER","options","setLogger","pLogger","configure","command","validate","config","read","args"],"mappings":";;;;;;;;;;AAWA;AACO,MAAMA,SAAS,CAA0BC,QAAAA,GAAAA;AAQ5C,IAAA,MAAMC,QAA2B,GAAA;AAAE,QAAA,GAAGC,yBAAe;AAAE,QAAA,GAAGF,SAASC;AAAS,KAAA;IAC5E,MAAME,QAAAA,GAAWH,QAASG,CAAAA,QAAQ,IAAIC,0BAAAA;IACtC,MAAMC,WAAAA,GAAcL,SAASK,WAAW;IACxC,IAAIC,MAAAA,GAASN,QAASM,CAAAA,MAAM,IAAIC,wBAAAA;AAEhC,IAAA,MAAMC,OAAsB,GAAA;AACxBP,QAAAA,QAAAA;AACAE,QAAAA,QAAAA;AACAE,QAAAA,WAAAA;AACAC,QAAAA;AACJ,KAAA;AAEA,IAAA,MAAMG,YAAY,CAACC,OAAAA,GAAAA;QACfJ,MAASI,GAAAA,OAAAA;AACTF,QAAAA,OAAAA,CAAQF,MAAM,GAAGI,OAAAA;AACrB,KAAA;IAEA,OAAO;AACHD,QAAAA,SAAAA;QACAE,SAAW,EAAA,CAACC,OAAqBD,GAAAA,mBAAAA,CAAUC,OAASJ,EAAAA,OAAAA,CAAAA;QACpDK,QAAU,EAAA,CAACC,MAA8DD,GAAAA,iBAAAA,CAASC,MAAQN,EAAAA,OAAAA,CAAAA;QAC1FO,IAAM,EAAA,CAACC,IAAeD,GAAAA,SAAAA,CAAKC,IAAMR,EAAAA,OAAAA;AACrC,KAAA;AACJ;;;;;"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { DefaultOptions, Feature, Cardigantime, Logger } from './types';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
export * from './types';
|
|
4
|
+
export declare const create: <T extends z.ZodRawShape>(pOptions: {
|
|
5
|
+
defaults: Pick<DefaultOptions, "configDirectory"> & Partial<Omit<DefaultOptions, "configDirectory">>;
|
|
6
|
+
features?: Feature[];
|
|
7
|
+
configShape: T;
|
|
8
|
+
logger?: Logger;
|
|
9
|
+
}) => Cardigantime<T>;
|
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
+
|
|
5
|
+
const yaml = require('js-yaml');
|
|
6
|
+
const path = require('path');
|
|
7
|
+
const fs = require('fs');
|
|
8
|
+
const glob = require('glob');
|
|
9
|
+
const crypto = require('crypto');
|
|
10
|
+
const zod = require('zod');
|
|
11
|
+
|
|
12
|
+
function _interopNamespaceDefault(e) {
|
|
13
|
+
const n = Object.create(null, { [Symbol.toStringTag]: { value: 'Module' } });
|
|
14
|
+
if (e) {
|
|
15
|
+
for (const k in e) {
|
|
16
|
+
if (k !== 'default') {
|
|
17
|
+
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
18
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: () => e[k]
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
n.default = e;
|
|
26
|
+
return Object.freeze(n);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const yaml__namespace = /*#__PURE__*/_interopNamespaceDefault(yaml);
|
|
30
|
+
const fs__namespace = /*#__PURE__*/_interopNamespaceDefault(fs);
|
|
31
|
+
|
|
32
|
+
const configure = async (command, options)=>{
|
|
33
|
+
let retCommand = command;
|
|
34
|
+
retCommand = retCommand.option('-c, --config-directory <configDirectory>', 'Config Directory', options.defaults.configDirectory);
|
|
35
|
+
return retCommand;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const DEFAULT_ENCODING = 'utf8';
|
|
39
|
+
const DEFAULT_CONFIG_FILE = 'config.yaml';
|
|
40
|
+
const DEFAULT_OPTIONS = {
|
|
41
|
+
configFile: DEFAULT_CONFIG_FILE,
|
|
42
|
+
isRequired: false,
|
|
43
|
+
encoding: DEFAULT_ENCODING
|
|
44
|
+
};
|
|
45
|
+
const DEFAULT_FEATURES = [
|
|
46
|
+
'config'
|
|
47
|
+
];
|
|
48
|
+
const DEFAULT_LOGGER = {
|
|
49
|
+
// eslint-disable-next-line no-console
|
|
50
|
+
debug: console.debug,
|
|
51
|
+
// eslint-disable-next-line no-console
|
|
52
|
+
info: console.info,
|
|
53
|
+
// eslint-disable-next-line no-console
|
|
54
|
+
warn: console.warn,
|
|
55
|
+
// eslint-disable-next-line no-console
|
|
56
|
+
error: console.error,
|
|
57
|
+
// eslint-disable-next-line no-console
|
|
58
|
+
verbose: console.log,
|
|
59
|
+
// eslint-disable-next-line no-console
|
|
60
|
+
silly: console.log
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
// eslint-disable-next-line no-restricted-imports
|
|
64
|
+
const create$1 = (params)=>{
|
|
65
|
+
// eslint-disable-next-line no-console
|
|
66
|
+
const log = params.log || console.log;
|
|
67
|
+
const exists = async (path)=>{
|
|
68
|
+
try {
|
|
69
|
+
await fs__namespace.promises.stat(path);
|
|
70
|
+
return true;
|
|
71
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
72
|
+
} catch (error) {
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
const isDirectory = async (path)=>{
|
|
77
|
+
const stats = await fs__namespace.promises.stat(path);
|
|
78
|
+
if (!stats.isDirectory()) {
|
|
79
|
+
log(`${path} is not a directory`);
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
return true;
|
|
83
|
+
};
|
|
84
|
+
const isFile = async (path)=>{
|
|
85
|
+
const stats = await fs__namespace.promises.stat(path);
|
|
86
|
+
if (!stats.isFile()) {
|
|
87
|
+
log(`${path} is not a file`);
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
return true;
|
|
91
|
+
};
|
|
92
|
+
const isReadable = async (path)=>{
|
|
93
|
+
try {
|
|
94
|
+
await fs__namespace.promises.access(path, fs__namespace.constants.R_OK);
|
|
95
|
+
} catch (error) {
|
|
96
|
+
log(`${path} is not readable: %s %s`, error.message, error.stack);
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
return true;
|
|
100
|
+
};
|
|
101
|
+
const isWritable = async (path)=>{
|
|
102
|
+
try {
|
|
103
|
+
await fs__namespace.promises.access(path, fs__namespace.constants.W_OK);
|
|
104
|
+
} catch (error) {
|
|
105
|
+
log(`${path} is not writable: %s %s`, error.message, error.stack);
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
return true;
|
|
109
|
+
};
|
|
110
|
+
const isFileReadable = async (path)=>{
|
|
111
|
+
return await exists(path) && await isFile(path) && await isReadable(path);
|
|
112
|
+
};
|
|
113
|
+
const isDirectoryWritable = async (path)=>{
|
|
114
|
+
return await exists(path) && await isDirectory(path) && await isWritable(path);
|
|
115
|
+
};
|
|
116
|
+
const isDirectoryReadable = async (path)=>{
|
|
117
|
+
return await exists(path) && await isDirectory(path) && await isReadable(path);
|
|
118
|
+
};
|
|
119
|
+
const createDirectory = async (path)=>{
|
|
120
|
+
try {
|
|
121
|
+
await fs__namespace.promises.mkdir(path, {
|
|
122
|
+
recursive: true
|
|
123
|
+
});
|
|
124
|
+
} catch (mkdirError) {
|
|
125
|
+
throw new Error(`Failed to create output directory ${path}: ${mkdirError.message} ${mkdirError.stack}`);
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
const readFile = async (path, encoding)=>{
|
|
129
|
+
return await fs__namespace.promises.readFile(path, {
|
|
130
|
+
encoding: encoding
|
|
131
|
+
});
|
|
132
|
+
};
|
|
133
|
+
const writeFile = async (path, data, encoding)=>{
|
|
134
|
+
await fs__namespace.promises.writeFile(path, data, {
|
|
135
|
+
encoding: encoding
|
|
136
|
+
});
|
|
137
|
+
};
|
|
138
|
+
const forEachFileIn = async (directory, callback, options = {
|
|
139
|
+
pattern: '*.*'
|
|
140
|
+
})=>{
|
|
141
|
+
try {
|
|
142
|
+
const files = await glob.glob(options.pattern, {
|
|
143
|
+
cwd: directory,
|
|
144
|
+
nodir: true
|
|
145
|
+
});
|
|
146
|
+
for (const file of files){
|
|
147
|
+
await callback(path.join(directory, file));
|
|
148
|
+
}
|
|
149
|
+
} catch (err) {
|
|
150
|
+
throw new Error(`Failed to glob pattern ${options.pattern} in ${directory}: ${err.message}`);
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
const readStream = async (path)=>{
|
|
154
|
+
return fs__namespace.createReadStream(path);
|
|
155
|
+
};
|
|
156
|
+
const hashFile = async (path, length)=>{
|
|
157
|
+
const file = await readFile(path, 'utf8');
|
|
158
|
+
return crypto.createHash('sha256').update(file).digest('hex').slice(0, length);
|
|
159
|
+
};
|
|
160
|
+
const listFiles = async (directory)=>{
|
|
161
|
+
return await fs__namespace.promises.readdir(directory);
|
|
162
|
+
};
|
|
163
|
+
return {
|
|
164
|
+
exists,
|
|
165
|
+
isDirectory,
|
|
166
|
+
isFile,
|
|
167
|
+
isReadable,
|
|
168
|
+
isWritable,
|
|
169
|
+
isFileReadable,
|
|
170
|
+
isDirectoryWritable,
|
|
171
|
+
isDirectoryReadable,
|
|
172
|
+
createDirectory,
|
|
173
|
+
readFile,
|
|
174
|
+
readStream,
|
|
175
|
+
writeFile,
|
|
176
|
+
forEachFileIn,
|
|
177
|
+
hashFile,
|
|
178
|
+
listFiles
|
|
179
|
+
};
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
function clean(obj) {
|
|
183
|
+
return Object.fromEntries(Object.entries(obj).filter(([_, v])=>v !== undefined));
|
|
184
|
+
}
|
|
185
|
+
const read = async (args, options)=>{
|
|
186
|
+
var _options_defaults;
|
|
187
|
+
const logger = options.logger;
|
|
188
|
+
const storage = create$1({
|
|
189
|
+
log: logger.debug
|
|
190
|
+
});
|
|
191
|
+
const resolvedConfigDir = args.configDirectory || ((_options_defaults = options.defaults) === null || _options_defaults === void 0 ? void 0 : _options_defaults.configDirectory);
|
|
192
|
+
logger.debug(`Resolved config directory: ${resolvedConfigDir}`);
|
|
193
|
+
const configFile = path.join(resolvedConfigDir, options.defaults.configFile);
|
|
194
|
+
logger.debug(`Attempting to load config file for cardigantime: ${configFile}`);
|
|
195
|
+
let rawFileConfig = {};
|
|
196
|
+
try {
|
|
197
|
+
const yamlContent = await storage.readFile(configFile, options.defaults.encoding);
|
|
198
|
+
const parsedYaml = yaml__namespace.load(yamlContent);
|
|
199
|
+
if (parsedYaml !== null && typeof parsedYaml === 'object') {
|
|
200
|
+
rawFileConfig = parsedYaml;
|
|
201
|
+
logger.debug('Loaded Raw File Config for getValuesFromFile: \n\n%s\n\n', JSON.stringify(rawFileConfig, null, 2));
|
|
202
|
+
} else if (parsedYaml !== null) {
|
|
203
|
+
logger.warn(`Ignoring invalid configuration format in ${configFile} for cardigantime. Expected an object, got ${typeof parsedYaml}.`);
|
|
204
|
+
}
|
|
205
|
+
} catch (error) {
|
|
206
|
+
if (error.code === 'ENOENT' || /not found|no such file/i.test(error.message)) {
|
|
207
|
+
logger.debug(`Configuration file not found at ${configFile} for cardigantime. Returning empty object.`);
|
|
208
|
+
} else {
|
|
209
|
+
// Log error but don't throw, just return empty object as per the goal of just *getting* values
|
|
210
|
+
logger.error(`Failed to load or parse configuration from ${configFile} for getValuesFromFile: ${error.message}`);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
const config = clean({
|
|
214
|
+
...rawFileConfig,
|
|
215
|
+
...{
|
|
216
|
+
configDirectory: resolvedConfigDir
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
return config;
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
// Base schema for core options
|
|
223
|
+
const ConfigSchema = zod.z.object({
|
|
224
|
+
configDirectory: zod.z.string()
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
const listZodKeys = (schema, prefix = '')=>{
|
|
228
|
+
// Check if schema has unwrap method (which both ZodOptional and ZodNullable have)
|
|
229
|
+
if (schema._def && (schema._def.typeName === 'ZodOptional' || schema._def.typeName === 'ZodNullable')) {
|
|
230
|
+
// Use type assertion to handle the unwrap method
|
|
231
|
+
const unwrappable = schema;
|
|
232
|
+
return listZodKeys(unwrappable.unwrap(), prefix);
|
|
233
|
+
}
|
|
234
|
+
if (schema._def && schema._def.typeName === 'ZodArray') {
|
|
235
|
+
// Use type assertion to handle the element property
|
|
236
|
+
const arraySchema = schema;
|
|
237
|
+
return listZodKeys(arraySchema.element, prefix);
|
|
238
|
+
}
|
|
239
|
+
if (schema._def && schema._def.typeName === 'ZodObject') {
|
|
240
|
+
// Use type assertion to handle the shape property
|
|
241
|
+
const objectSchema = schema;
|
|
242
|
+
return Object.entries(objectSchema.shape).flatMap(([key, subschema])=>{
|
|
243
|
+
const fullKey = prefix ? `${prefix}.${key}` : key;
|
|
244
|
+
const nested = listZodKeys(subschema, fullKey);
|
|
245
|
+
return nested.length ? nested : fullKey;
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
return [];
|
|
249
|
+
};
|
|
250
|
+
const isPlainObject = (value)=>{
|
|
251
|
+
// Check if it's an object, not null, and not an array.
|
|
252
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
253
|
+
};
|
|
254
|
+
/**
|
|
255
|
+
* Generates a list of all keys within a JavaScript object, using dot notation for nested keys.
|
|
256
|
+
* Mimics the behavior of listZodKeys but operates on plain objects.
|
|
257
|
+
* For arrays, it inspects the first element that is a plain object to determine nested keys.
|
|
258
|
+
* If an array contains no plain objects, or is empty, the key for the array itself is listed.
|
|
259
|
+
*
|
|
260
|
+
* @param obj The object to introspect.
|
|
261
|
+
* @param prefix Internal use for recursion: the prefix for the current nesting level.
|
|
262
|
+
* @returns An array of strings representing all keys in dot notation.
|
|
263
|
+
*/ const listObjectKeys = (obj, prefix = '')=>{
|
|
264
|
+
const keys = new Set(); // Use Set to automatically handle duplicates from array recursion
|
|
265
|
+
for(const key in obj){
|
|
266
|
+
// Ensure it's an own property, not from the prototype chain
|
|
267
|
+
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
268
|
+
const value = obj[key];
|
|
269
|
+
const fullKey = prefix ? `${prefix}.${key}` : key;
|
|
270
|
+
if (Array.isArray(value)) {
|
|
271
|
+
// Find the first element that is a plain object to determine structure
|
|
272
|
+
const firstObjectElement = value.find(isPlainObject);
|
|
273
|
+
if (firstObjectElement) {
|
|
274
|
+
// Recurse into the structure of the first object element found
|
|
275
|
+
const nestedKeys = listObjectKeys(firstObjectElement, fullKey);
|
|
276
|
+
nestedKeys.forEach((k)=>keys.add(k));
|
|
277
|
+
} else {
|
|
278
|
+
// Array is empty or contains no plain objects, list the array key itself
|
|
279
|
+
keys.add(fullKey);
|
|
280
|
+
}
|
|
281
|
+
} else if (isPlainObject(value)) {
|
|
282
|
+
// Recurse into nested plain objects
|
|
283
|
+
const nestedKeys = listObjectKeys(value, fullKey);
|
|
284
|
+
nestedKeys.forEach((k)=>keys.add(k));
|
|
285
|
+
} else {
|
|
286
|
+
// It's a primitive, null, or other non-plain object/array type
|
|
287
|
+
keys.add(fullKey);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
return Array.from(keys); // Convert Set back to Array
|
|
292
|
+
};
|
|
293
|
+
const checkForExtraKeys = (mergedSources, fullSchema, logger)=>{
|
|
294
|
+
const allowedKeys = new Set(listZodKeys(fullSchema));
|
|
295
|
+
const actualKeys = listObjectKeys(mergedSources);
|
|
296
|
+
const extraKeys = actualKeys.filter((key)=>!allowedKeys.has(key));
|
|
297
|
+
if (extraKeys.length > 0) {
|
|
298
|
+
const allowedKeysString = Array.from(allowedKeys).join(', ');
|
|
299
|
+
const extraKeysString = extraKeys.join(', ');
|
|
300
|
+
const errorMessage = `Unknown configuration keys found: ${extraKeysString}. Allowed keys are: ${allowedKeysString}`;
|
|
301
|
+
logger.error(errorMessage);
|
|
302
|
+
throw new Error(`Configuration validation failed: Unknown keys found (${extraKeysString}). Check logs for details.`);
|
|
303
|
+
}
|
|
304
|
+
};
|
|
305
|
+
const validateConfigDirectory = async (configDirectory, isRequired)=>{
|
|
306
|
+
// eslint-disable-next-line no-console
|
|
307
|
+
const storage = create$1({
|
|
308
|
+
log: console.log
|
|
309
|
+
});
|
|
310
|
+
const exists = await storage.exists(configDirectory);
|
|
311
|
+
if (!exists) {
|
|
312
|
+
if (isRequired) {
|
|
313
|
+
throw new Error(`Config directory does not exist and is required: ${configDirectory}`);
|
|
314
|
+
}
|
|
315
|
+
} else if (exists) {
|
|
316
|
+
const isReadable = await storage.isDirectoryReadable(configDirectory);
|
|
317
|
+
if (!isReadable) {
|
|
318
|
+
throw new Error(`Config directory exists but is not readable: ${configDirectory}`);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
};
|
|
322
|
+
const validate = async (config, options)=>{
|
|
323
|
+
const logger = options.logger;
|
|
324
|
+
if (options.features.includes('config') && config.configDirectory) {
|
|
325
|
+
await validateConfigDirectory(config.configDirectory, options.defaults.isRequired);
|
|
326
|
+
}
|
|
327
|
+
// Combine the base schema with the user-provided shape
|
|
328
|
+
const fullSchema = zod.z.object({
|
|
329
|
+
...ConfigSchema.shape,
|
|
330
|
+
...options.configShape
|
|
331
|
+
});
|
|
332
|
+
logger.debug('Full Schema: \n\n%s\n\n', JSON.stringify(listZodKeys(fullSchema), null, 2));
|
|
333
|
+
// Validate the merged sources against the full schema
|
|
334
|
+
const validationResult = fullSchema.safeParse(config);
|
|
335
|
+
// Check for extraneous keys
|
|
336
|
+
checkForExtraKeys(config, fullSchema, logger);
|
|
337
|
+
if (!validationResult.success) {
|
|
338
|
+
logger.error('Configuration validation failed: %s', JSON.stringify(validationResult.error.format(), null, 2));
|
|
339
|
+
throw new Error(`Configuration validation failed. Check logs for details.`);
|
|
340
|
+
}
|
|
341
|
+
return;
|
|
342
|
+
};
|
|
343
|
+
|
|
344
|
+
// Make create function generic
|
|
345
|
+
const create = (pOptions)=>{
|
|
346
|
+
const defaults = {
|
|
347
|
+
...DEFAULT_OPTIONS,
|
|
348
|
+
...pOptions.defaults
|
|
349
|
+
};
|
|
350
|
+
const features = pOptions.features || DEFAULT_FEATURES;
|
|
351
|
+
const configShape = pOptions.configShape;
|
|
352
|
+
let logger = pOptions.logger || DEFAULT_LOGGER;
|
|
353
|
+
const options = {
|
|
354
|
+
defaults,
|
|
355
|
+
features,
|
|
356
|
+
configShape,
|
|
357
|
+
logger
|
|
358
|
+
};
|
|
359
|
+
const setLogger = (pLogger)=>{
|
|
360
|
+
logger = pLogger;
|
|
361
|
+
options.logger = pLogger;
|
|
362
|
+
};
|
|
363
|
+
return {
|
|
364
|
+
setLogger,
|
|
365
|
+
configure: (command)=>configure(command, options),
|
|
366
|
+
validate: (config)=>validate(config, options),
|
|
367
|
+
read: (args)=>read(args, options)
|
|
368
|
+
};
|
|
369
|
+
};
|
|
370
|
+
|
|
371
|
+
exports.ConfigSchema = ConfigSchema;
|
|
372
|
+
exports.create = create;
|
|
373
|
+
//# sourceMappingURL=cardigantime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cardigantime.js","sources":["../src/configure.ts","../src/constants.ts","../src/util/storage.ts","../src/read.ts","../src/types.ts","../src/validate.ts","../src/cardigantime.ts"],"sourcesContent":["import { Command } from \"commander\";\nimport { z } from \"zod\";\nimport { ArgumentError } from \"./error/ArgumentError\";\nimport { Options } from \"./types\";\nexport { ArgumentError };\n\nexport const configure = async <T extends z.ZodRawShape>(command: Command, options: Options<T>): Promise<Command> => {\n let retCommand = command;\n retCommand = retCommand.option('-c, --config-directory <configDirectory>', 'Config Directory', options.defaults.configDirectory)\n return retCommand;\n}\n\n\n\n\n","import { DefaultOptions, Feature, Logger } from \"./types\";\n\nexport const VERSION = '__VERSION__ (__GIT_BRANCH__/__GIT_COMMIT__ __GIT_TAGS__ __GIT_COMMIT_DATE__) __SYSTEM_INFO__';\nexport const PROGRAM_NAME = 'cardigantime';\nexport const DEFAULT_ENCODING = 'utf8';\nexport const DEFAULT_CONFIG_FILE = 'config.yaml';\n\nexport const DEFAULT_OPTIONS: Partial<DefaultOptions> = {\n configFile: DEFAULT_CONFIG_FILE,\n isRequired: false,\n encoding: DEFAULT_ENCODING,\n}\n\nexport const DEFAULT_FEATURES: Feature[] = ['config'];\n\nexport const DEFAULT_LOGGER: Logger = {\n // eslint-disable-next-line no-console\n debug: console.debug,\n // eslint-disable-next-line no-console\n info: console.info,\n // eslint-disable-next-line no-console\n warn: console.warn,\n // eslint-disable-next-line no-console\n error: console.error,\n // eslint-disable-next-line no-console\n verbose: console.log,\n // eslint-disable-next-line no-console\n silly: console.log,\n}\n","// eslint-disable-next-line no-restricted-imports\nimport * as fs from 'fs';\nimport { glob } from 'glob';\nimport path from 'path';\nimport crypto from 'crypto';\n/**\n * This module exists to isolate filesystem operations from the rest of the codebase.\n * This makes testing easier by avoiding direct fs mocking in jest configuration.\n * \n * Additionally, abstracting storage operations allows for future flexibility - \n * this export utility may need to work with storage systems other than the local filesystem\n * (e.g. S3, Google Cloud Storage, etc).\n */\n\nexport interface Utility {\n exists: (path: string) => Promise<boolean>;\n isDirectory: (path: string) => Promise<boolean>;\n isFile: (path: string) => Promise<boolean>;\n isReadable: (path: string) => Promise<boolean>;\n isWritable: (path: string) => Promise<boolean>;\n isFileReadable: (path: string) => Promise<boolean>;\n isDirectoryWritable: (path: string) => Promise<boolean>;\n isDirectoryReadable: (path: string) => Promise<boolean>;\n createDirectory: (path: string) => Promise<void>;\n readFile: (path: string, encoding: string) => Promise<string>;\n readStream: (path: string) => Promise<fs.ReadStream>;\n writeFile: (path: string, data: string | Buffer, encoding: string) => Promise<void>;\n forEachFileIn: (directory: string, callback: (path: string) => Promise<void>, options?: { pattern: string }) => Promise<void>;\n hashFile: (path: string, length: number) => Promise<string>;\n listFiles: (directory: string) => Promise<string[]>;\n}\n\nexport const create = (params: { log?: (message: string, ...args: any[]) => void }): Utility => {\n\n // eslint-disable-next-line no-console\n const log = params.log || console.log;\n\n const exists = async (path: string): Promise<boolean> => {\n try {\n await fs.promises.stat(path);\n return true;\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n } catch (error: any) {\n return false;\n }\n }\n\n const isDirectory = async (path: string): Promise<boolean> => {\n const stats = await fs.promises.stat(path);\n if (!stats.isDirectory()) {\n log(`${path} is not a directory`);\n return false;\n }\n return true;\n }\n\n const isFile = async (path: string): Promise<boolean> => {\n const stats = await fs.promises.stat(path);\n if (!stats.isFile()) {\n log(`${path} is not a file`);\n return false;\n }\n return true;\n }\n\n const isReadable = async (path: string): Promise<boolean> => {\n try {\n await fs.promises.access(path, fs.constants.R_OK);\n } catch (error: any) {\n log(`${path} is not readable: %s %s`, error.message, error.stack);\n return false;\n }\n return true;\n }\n\n const isWritable = async (path: string): Promise<boolean> => {\n try {\n await fs.promises.access(path, fs.constants.W_OK);\n } catch (error: any) {\n log(`${path} is not writable: %s %s`, error.message, error.stack);\n return false;\n }\n return true;\n }\n\n const isFileReadable = async (path: string): Promise<boolean> => {\n return await exists(path) && await isFile(path) && await isReadable(path);\n }\n\n const isDirectoryWritable = async (path: string): Promise<boolean> => {\n return await exists(path) && await isDirectory(path) && await isWritable(path);\n }\n\n const isDirectoryReadable = async (path: string): Promise<boolean> => {\n return await exists(path) && await isDirectory(path) && await isReadable(path);\n }\n\n const createDirectory = async (path: string): Promise<void> => {\n try {\n await fs.promises.mkdir(path, { recursive: true });\n } catch (mkdirError: any) {\n throw new Error(`Failed to create output directory ${path}: ${mkdirError.message} ${mkdirError.stack}`);\n }\n }\n\n const readFile = async (path: string, encoding: string): Promise<string> => {\n return await fs.promises.readFile(path, { encoding: encoding as BufferEncoding });\n }\n\n const writeFile = async (path: string, data: string | Buffer, encoding: string): Promise<void> => {\n await fs.promises.writeFile(path, data, { encoding: encoding as BufferEncoding });\n }\n\n const forEachFileIn = async (directory: string, callback: (file: string) => Promise<void>, options: { pattern: string | string[] } = { pattern: '*.*' }): Promise<void> => {\n try {\n const files = await glob(options.pattern, { cwd: directory, nodir: true });\n for (const file of files) {\n await callback(path.join(directory, file));\n }\n } catch (err: any) {\n throw new Error(`Failed to glob pattern ${options.pattern} in ${directory}: ${err.message}`);\n }\n }\n\n const readStream = async (path: string): Promise<fs.ReadStream> => {\n return fs.createReadStream(path);\n }\n\n const hashFile = async (path: string, length: number): Promise<string> => {\n const file = await readFile(path, 'utf8');\n return crypto.createHash('sha256').update(file).digest('hex').slice(0, length);\n }\n\n const listFiles = async (directory: string): Promise<string[]> => {\n return await fs.promises.readdir(directory);\n }\n\n return {\n exists,\n isDirectory,\n isFile,\n isReadable,\n isWritable,\n isFileReadable,\n isDirectoryWritable,\n isDirectoryReadable,\n createDirectory,\n readFile,\n readStream,\n writeFile,\n forEachFileIn,\n hashFile,\n listFiles,\n };\n}","import * as yaml from 'js-yaml';\nimport path from 'path';\nimport { z, ZodObject } from 'zod';\nimport { Args, ConfigSchema, Options } from './types';\nimport * as Storage from './util/storage';\n\nfunction clean(obj: any) {\n return Object.fromEntries(\n Object.entries(obj).filter(([_, v]) => v !== undefined)\n );\n}\n\nexport const read = async <T extends z.ZodRawShape>(args: Args, options: Options<T>): Promise<z.infer<ZodObject<T & typeof ConfigSchema.shape>>> => {\n const logger = options.logger;\n const storage = Storage.create({ log: logger.debug });\n\n const resolvedConfigDir = args.configDirectory || options.defaults?.configDirectory;\n logger.debug(`Resolved config directory: ${resolvedConfigDir}`);\n\n const configFile = path.join(resolvedConfigDir, options.defaults.configFile);\n logger.debug(`Attempting to load config file for cardigantime: ${configFile}`);\n\n let rawFileConfig: object = {};\n\n try {\n const yamlContent = await storage.readFile(configFile, options.defaults.encoding);\n const parsedYaml = yaml.load(yamlContent);\n if (parsedYaml !== null && typeof parsedYaml === 'object') {\n rawFileConfig = parsedYaml;\n logger.debug('Loaded Raw File Config for getValuesFromFile: \\n\\n%s\\n\\n', JSON.stringify(rawFileConfig, null, 2));\n } else if (parsedYaml !== null) {\n logger.warn(`Ignoring invalid configuration format in ${configFile} for cardigantime. Expected an object, got ${typeof parsedYaml}.`);\n }\n } catch (error: any) {\n if (error.code === 'ENOENT' || /not found|no such file/i.test(error.message)) {\n logger.debug(`Configuration file not found at ${configFile} for cardigantime. Returning empty object.`);\n } else {\n // Log error but don't throw, just return empty object as per the goal of just *getting* values\n logger.error(`Failed to load or parse configuration from ${configFile} for getValuesFromFile: ${error.message}`);\n }\n }\n\n const config: z.infer<ZodObject<T & typeof ConfigSchema.shape>> = clean({\n ...rawFileConfig,\n ...{\n configDirectory: resolvedConfigDir,\n }\n }) as z.infer<ZodObject<T & typeof ConfigSchema.shape>>;\n\n return config;\n}","import { Command } from \"commander\";\nimport { ZodObject } from \"zod\";\n\nimport { z } from \"zod\";\n\nexport type Feature = 'config';\n\nexport interface DefaultOptions {\n configDirectory: string;\n configFile: string;\n isRequired: boolean;\n encoding: string;\n}\n\n// Use ZodRawShape for easier merging later\nexport interface Options<T extends z.ZodRawShape> {\n defaults: DefaultOptions,\n features: Feature[],\n configShape: T; // User-defined configuration shape\n logger: Logger;\n}\n\nexport interface Logger {\n debug: (message: string, ...args: any[]) => void;\n info: (message: string, ...args: any[]) => void;\n warn: (message: string, ...args: any[]) => void;\n error: (message: string, ...args: any[]) => void;\n verbose: (message: string, ...args: any[]) => void;\n silly: (message: string, ...args: any[]) => void;\n}\n\n// Make interface generic\nexport interface Cardigantime<T extends z.ZodRawShape> {\n configure: (command: Command) => Promise<Command>;\n setLogger: (logger: Logger) => void;\n read: (args: Args) => Promise<z.infer<ZodObject<T & typeof ConfigSchema.shape>>>;\n validate: (config: z.infer<ZodObject<T & typeof ConfigSchema.shape>>) => Promise<void>;\n}\n\nexport interface Args {\n [key: string]: any;\n}\n\n// Base schema for core options\nexport const ConfigSchema = z.object({\n configDirectory: z.string(),\n});\n\nexport type Config = z.infer<typeof ConfigSchema>;\n","import { z, ZodObject } from \"zod\";\nimport { ArgumentError } from \"./error/ArgumentError\";\nimport { ConfigSchema, Logger, Options } from \"./types\";\nimport * as Storage from \"./util/storage\";\nexport { ArgumentError };\n\nexport const listZodKeys = (schema: z.ZodTypeAny, prefix = ''): string[] => {\n // Check if schema has unwrap method (which both ZodOptional and ZodNullable have)\n if (schema._def && (schema._def.typeName === 'ZodOptional' || schema._def.typeName === 'ZodNullable')) {\n // Use type assertion to handle the unwrap method\n const unwrappable = schema as z.ZodOptional<any> | z.ZodNullable<any>;\n return listZodKeys(unwrappable.unwrap(), prefix);\n }\n if (schema._def && schema._def.typeName === 'ZodArray') {\n // Use type assertion to handle the element property\n const arraySchema = schema as z.ZodArray<any>;\n return listZodKeys(arraySchema.element, prefix);\n }\n if (schema._def && schema._def.typeName === 'ZodObject') {\n // Use type assertion to handle the shape property\n const objectSchema = schema as z.ZodObject<any>;\n return Object.entries(objectSchema.shape).flatMap(([key, subschema]) => {\n const fullKey = prefix ? `${prefix}.${key}` : key;\n const nested = listZodKeys(subschema as z.ZodTypeAny, fullKey);\n return nested.length ? nested : fullKey;\n });\n }\n return [];\n}\n\nconst isPlainObject = (value: unknown): value is Record<string, unknown> => {\n // Check if it's an object, not null, and not an array.\n return value !== null && typeof value === 'object' && !Array.isArray(value);\n};\n\n/**\n * Generates a list of all keys within a JavaScript object, using dot notation for nested keys.\n * Mimics the behavior of listZodKeys but operates on plain objects.\n * For arrays, it inspects the first element that is a plain object to determine nested keys.\n * If an array contains no plain objects, or is empty, the key for the array itself is listed.\n *\n * @param obj The object to introspect.\n * @param prefix Internal use for recursion: the prefix for the current nesting level.\n * @returns An array of strings representing all keys in dot notation.\n */\nexport const listObjectKeys = (obj: Record<string, unknown>, prefix = ''): string[] => {\n const keys = new Set<string>(); // Use Set to automatically handle duplicates from array recursion\n\n for (const key in obj) {\n // Ensure it's an own property, not from the prototype chain\n if (Object.prototype.hasOwnProperty.call(obj, key)) {\n const value = obj[key];\n const fullKey = prefix ? `${prefix}.${key}` : key;\n\n if (Array.isArray(value)) {\n // Find the first element that is a plain object to determine structure\n const firstObjectElement = value.find(isPlainObject);\n if (firstObjectElement) {\n // Recurse into the structure of the first object element found\n const nestedKeys = listObjectKeys(firstObjectElement, fullKey);\n nestedKeys.forEach(k => keys.add(k));\n } else {\n // Array is empty or contains no plain objects, list the array key itself\n keys.add(fullKey);\n }\n } else if (isPlainObject(value)) {\n // Recurse into nested plain objects\n const nestedKeys = listObjectKeys(value, fullKey);\n nestedKeys.forEach(k => keys.add(k));\n } else {\n // It's a primitive, null, or other non-plain object/array type\n keys.add(fullKey);\n }\n }\n }\n return Array.from(keys); // Convert Set back to Array\n};\n\n\n\nexport const checkForExtraKeys = (mergedSources: object, fullSchema: ZodObject<any>, logger: Logger | typeof console): void => {\n const allowedKeys = new Set(listZodKeys(fullSchema));\n const actualKeys = listObjectKeys(mergedSources as Record<string, unknown>);\n const extraKeys = actualKeys.filter(key => !allowedKeys.has(key));\n\n if (extraKeys.length > 0) {\n const allowedKeysString = Array.from(allowedKeys).join(', ');\n const extraKeysString = extraKeys.join(', ');\n const errorMessage = `Unknown configuration keys found: ${extraKeysString}. Allowed keys are: ${allowedKeysString}`;\n logger.error(errorMessage);\n throw new Error(`Configuration validation failed: Unknown keys found (${extraKeysString}). Check logs for details.`);\n }\n}\n\nconst validateConfigDirectory = async (configDirectory: string, isRequired: boolean): Promise<void> => {\n // eslint-disable-next-line no-console\n const storage = Storage.create({ log: console.log });\n const exists = await storage.exists(configDirectory);\n if (!exists) {\n if (isRequired) {\n throw new Error(`Config directory does not exist and is required: ${configDirectory}`);\n }\n } else if (exists) {\n const isReadable = await storage.isDirectoryReadable(configDirectory);\n if (!isReadable) {\n throw new Error(`Config directory exists but is not readable: ${configDirectory}`);\n }\n }\n}\n\nexport const validate = async <T extends z.ZodRawShape>(config: z.infer<ZodObject<T & typeof ConfigSchema.shape>>, options: Options<T>): Promise<void> => {\n const logger = options.logger;\n\n if (options.features.includes('config') && config.configDirectory) {\n await validateConfigDirectory(config.configDirectory, options.defaults.isRequired);\n }\n\n // Combine the base schema with the user-provided shape\n const fullSchema = z.object({\n ...ConfigSchema.shape,\n ...options.configShape,\n });\n\n logger.debug('Full Schema: \\n\\n%s\\n\\n', JSON.stringify(listZodKeys(fullSchema), null, 2));\n\n // Validate the merged sources against the full schema\n const validationResult = fullSchema.safeParse(config);\n\n // Check for extraneous keys\n checkForExtraKeys(config, fullSchema, logger);\n\n if (!validationResult.success) {\n logger.error('Configuration validation failed: %s', JSON.stringify(validationResult.error.format(), null, 2));\n throw new Error(`Configuration validation failed. Check logs for details.`);\n }\n\n return;\n}\n\n","import { Command } from 'commander';\nimport { Args, DefaultOptions, Feature, Cardigantime, Logger, Options } from 'types';\nimport { z, ZodObject } from 'zod';\nimport { configure } from './configure';\nimport { DEFAULT_FEATURES, DEFAULT_LOGGER, DEFAULT_OPTIONS } from './constants';\nimport { read } from './read';\nimport { ConfigSchema } from 'types';\nimport { validate } from './validate';\n\nexport * from './types';\n\n// Make create function generic\nexport const create = <T extends z.ZodRawShape>(pOptions: {\n defaults: Pick<DefaultOptions, 'configDirectory'> & Partial<Omit<DefaultOptions, 'configDirectory'>>,\n features?: Feature[],\n configShape: T, // Make configShape mandatory\n logger?: Logger,\n}): Cardigantime<T> => {\n\n\n const defaults: DefaultOptions = { ...DEFAULT_OPTIONS, ...pOptions.defaults } as DefaultOptions;\n const features = pOptions.features || DEFAULT_FEATURES;\n const configShape = pOptions.configShape;\n let logger = pOptions.logger || DEFAULT_LOGGER;\n\n const options: Options<T> = {\n defaults,\n features,\n configShape, // Store the shape\n logger,\n }\n\n const setLogger = (pLogger: Logger) => {\n logger = pLogger;\n options.logger = pLogger;\n }\n\n return {\n setLogger,\n configure: (command: Command) => configure(command, options),\n validate: (config: z.infer<ZodObject<T & typeof ConfigSchema.shape>>) => validate(config, options),\n read: (args: Args) => read(args, options),\n }\n}\n\n\n\n\n\n"],"names":["configure","command","options","retCommand","option","defaults","configDirectory","DEFAULT_ENCODING","DEFAULT_CONFIG_FILE","DEFAULT_OPTIONS","configFile","isRequired","encoding","DEFAULT_FEATURES","DEFAULT_LOGGER","debug","console","info","warn","error","verbose","log","silly","create","params","exists","path","fs","promises","stat","isDirectory","stats","isFile","isReadable","access","constants","R_OK","message","stack","isWritable","W_OK","isFileReadable","isDirectoryWritable","isDirectoryReadable","createDirectory","mkdir","recursive","mkdirError","Error","readFile","writeFile","data","forEachFileIn","directory","callback","pattern","files","glob","cwd","nodir","file","join","err","readStream","createReadStream","hashFile","length","crypto","createHash","update","digest","slice","listFiles","readdir","clean","obj","Object","fromEntries","entries","filter","_","v","undefined","read","args","logger","storage","Storage","resolvedConfigDir","rawFileConfig","yamlContent","parsedYaml","yaml","load","JSON","stringify","code","test","config","ConfigSchema","z","object","string","listZodKeys","schema","prefix","_def","typeName","unwrappable","unwrap","arraySchema","element","objectSchema","shape","flatMap","key","subschema","fullKey","nested","isPlainObject","value","Array","isArray","listObjectKeys","keys","Set","prototype","hasOwnProperty","call","firstObjectElement","find","nestedKeys","forEach","k","add","from","checkForExtraKeys","mergedSources","fullSchema","allowedKeys","actualKeys","extraKeys","has","allowedKeysString","extraKeysString","errorMessage","validateConfigDirectory","validate","features","includes","configShape","validationResult","safeParse","success","format","pOptions","setLogger","pLogger"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMO,MAAMA,SAAY,GAAA,OAAgCC,OAAkBC,EAAAA,OAAAA,GAAAA;AACvE,IAAA,IAAIC,UAAaF,GAAAA,OAAAA;IACjBE,UAAaA,GAAAA,UAAAA,CAAWC,MAAM,CAAC,0CAAA,EAA4C,oBAAoBF,OAAQG,CAAAA,QAAQ,CAACC,eAAe,CAAA;IAC/H,OAAOH,UAAAA;AACX,CAAC;;ACNM,MAAMI,mBAAmB,MAAO;AAChC,MAAMC,sBAAsB,aAAc;AAE1C,MA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,MAAM,EAAA,EAAI,IAAM,EAAA,CAAA,CAAA,CAAA;AAC1G,QAAA,MAAM,IAAI1G,KAAAA,CAAM,CAAC,wDAAwD,CAAC,CAAA;AAC9E;AAEA,IAAA;AACJ,CAAC;;AC9HD;AACO,MAAMzB,SAAS,CAA0BoI,QAAAA,GAAAA;AAQ5C,IAAA,MAAMtJ,QAA2B,GAAA;AAAE,QAAA,GAAGI,eAAe;AAAE,QAAA,GAAGkJ,SAAStJ;AAAS,KAAA;IAC5E,MAAM+I,QAAAA,GAAWO,QAASP,CAAAA,QAAQ,IAAIvI,gBAAAA;IACtC,MAAMyI,WAAAA,GAAcK,SAASL,WAAW;IACxC,IAAIjE,MAAAA,GAASsE,QAAStE,CAAAA,MAAM,IAAIvE,cAAAA;AAEhC,IAAA,MAAMZ,OAAsB,GAAA;AACxBG,QAAAA,QAAAA;AACA+I,QAAAA,QAAAA;AACAE,QAAAA,WAAAA;AACAjE,QAAAA;AACJ,KAAA;AAEA,IAAA,MAAMuE,YAAY,CAACC,OAAAA,GAAAA;QACfxE,MAASwE,GAAAA,OAAAA;AACT3J,QAAAA,OAAAA,CAAQmF,MAAM,GAAGwE,OAAAA;AACrB,KAAA;IAEA,OAAO;AACHD,QAAAA,SAAAA;QACA5J,SAAW,EAAA,CAACC,OAAqBD,GAAAA,SAAAA,CAAUC,OAASC,EAAAA,OAAAA,CAAAA;QACpDiJ,QAAU,EAAA,CAACjD,MAA8DiD,GAAAA,QAAAA,CAASjD,MAAQhG,EAAAA,OAAAA,CAAAA;QAC1FiF,IAAM,EAAA,CAACC,IAAeD,GAAAA,IAAAA,CAAKC,IAAMlF,EAAAA,OAAAA;AACrC,KAAA;AACJ;;;;;"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
+
|
|
5
|
+
const configure = async (command, options)=>{
|
|
6
|
+
let retCommand = command;
|
|
7
|
+
retCommand = retCommand.option('-c, --config-directory <configDirectory>', 'Config Directory', options.defaults.configDirectory);
|
|
8
|
+
return retCommand;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
exports.configure = configure;
|
|
12
|
+
//# sourceMappingURL=configure.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"configure.cjs","sources":["../src/configure.ts"],"sourcesContent":["import { Command } from \"commander\";\nimport { z } from \"zod\";\nimport { ArgumentError } from \"./error/ArgumentError\";\nimport { Options } from \"./types\";\nexport { ArgumentError };\n\nexport const configure = async <T extends z.ZodRawShape>(command: Command, options: Options<T>): Promise<Command> => {\n let retCommand = command;\n retCommand = retCommand.option('-c, --config-directory <configDirectory>', 'Config Directory', options.defaults.configDirectory)\n return retCommand;\n}\n\n\n\n\n"],"names":["configure","command","options","retCommand","option","defaults","configDirectory"],"mappings":";;;;AAMO,MAAMA,SAAY,GAAA,OAAgCC,OAAkBC,EAAAA,OAAAA,GAAAA;AACvE,IAAA,IAAIC,UAAaF,GAAAA,OAAAA;IACjBE,UAAaA,GAAAA,UAAAA,CAAWC,MAAM,CAAC,0CAAA,EAA4C,oBAAoBF,OAAQG,CAAAA,QAAQ,CAACC,eAAe,CAAA;IAC/H,OAAOH,UAAAA;AACX;;;;"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { ArgumentError } from './error/ArgumentError';
|
|
4
|
+
import { Options } from './types';
|
|
5
|
+
export { ArgumentError };
|
|
6
|
+
export declare const configure: <T extends z.ZodRawShape>(command: Command, options: Options<T>) => Promise<Command>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
const configure = async (command, options)=>{
|
|
2
|
+
let retCommand = command;
|
|
3
|
+
retCommand = retCommand.option('-c, --config-directory <configDirectory>', 'Config Directory', options.defaults.configDirectory);
|
|
4
|
+
return retCommand;
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export { configure };
|
|
8
|
+
//# sourceMappingURL=configure.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"configure.js","sources":["../src/configure.ts"],"sourcesContent":["import { Command } from \"commander\";\nimport { z } from \"zod\";\nimport { ArgumentError } from \"./error/ArgumentError\";\nimport { Options } from \"./types\";\nexport { ArgumentError };\n\nexport const configure = async <T extends z.ZodRawShape>(command: Command, options: Options<T>): Promise<Command> => {\n let retCommand = command;\n retCommand = retCommand.option('-c, --config-directory <configDirectory>', 'Config Directory', options.defaults.configDirectory)\n return retCommand;\n}\n\n\n\n\n"],"names":["configure","command","options","retCommand","option","defaults","configDirectory"],"mappings":"AAMO,MAAMA,SAAY,GAAA,OAAgCC,OAAkBC,EAAAA,OAAAA,GAAAA;AACvE,IAAA,IAAIC,UAAaF,GAAAA,OAAAA;IACjBE,UAAaA,GAAAA,UAAAA,CAAWC,MAAM,CAAC,0CAAA,EAA4C,oBAAoBF,OAAQG,CAAAA,QAAQ,CAACC,eAAe,CAAA;IAC/H,OAAOH,UAAAA;AACX;;;;"}
|