zcb 0.2.4 → 0.2.5
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/README.md +1 -1
- package/dist/cjs/cli.cjs +1 -185
- package/dist/cjs/cli.cjs.map +1 -1
- package/dist/cjs/index.cjs +1 -384
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/esm/cli.mjs +1 -182
- package/dist/esm/cli.mjs.map +1 -1
- package/dist/esm/index.mjs +1 -372
- package/dist/esm/index.mjs.map +1 -1
- package/dist/production.analysis.txt +72 -0
- package/dist/types/cjs/createConfigParser.d.cts +1 -1
- package/dist/types/cjs/createConfigParser.d.cts.map +1 -1
- package/dist/types/cjs/createConfigReader.d.cts +2 -2
- package/dist/types/cjs/createConfigReader.d.cts.map +1 -1
- package/dist/types/cjs/types.d.cts +2 -2
- package/dist/types/cjs/types.d.cts.map +1 -1
- package/dist/types/cjs/utils/arrayHasInvalidDefaults.d.cts +1 -1
- package/dist/types/cjs/utils/arrayHasInvalidDefaults.d.cts.map +1 -1
- package/dist/types/cjs/utils/collateObjectPropertyDefaults.d.cts +2 -2
- package/dist/types/cjs/utils/collateObjectPropertyDefaults.d.cts.map +1 -1
- package/dist/types/cjs/utils/importValidateTransformWriteConfig.d.cts +1 -1
- package/dist/types/cjs/utils/importValidateTransformWriteConfig.d.cts.map +1 -1
- package/dist/types/cjs/utils/isSchemaValid.d.cts +1 -1
- package/dist/types/cjs/utils/isSchemaValid.d.cts.map +1 -1
- package/dist/types/cjs/utils/isValidPropertyDefinition.d.cts +1 -1
- package/dist/types/cjs/utils/isValidPropertyDefinition.d.cts.map +1 -1
- package/dist/types/cjs/utils/jsonStringifyReplacer.d.cts +1 -1
- package/dist/types/cjs/utils/jsonStringifyReplacer.d.cts.map +1 -1
- package/dist/types/cjs/utils/objectPropertyHasDefaults.d.cts +1 -1
- package/dist/types/cjs/utils/objectPropertyHasDefaults.d.cts.map +1 -1
- package/dist/types/cjs/utils/recordHasInvalidDefaults.d.cts +1 -1
- package/dist/types/cjs/utils/recordHasInvalidDefaults.d.cts.map +1 -1
- package/dist/types/cjs/utils/transformWriteConfig.d.cts +1 -1
- package/dist/types/cjs/utils/transformWriteConfig.d.cts.map +1 -1
- package/dist/types/esm/createConfigParser.d.ts +1 -1
- package/dist/types/esm/createConfigParser.d.ts.map +1 -1
- package/dist/types/esm/createConfigReader.d.ts +2 -2
- package/dist/types/esm/createConfigReader.d.ts.map +1 -1
- package/dist/types/esm/types.d.ts +2 -2
- package/dist/types/esm/types.d.ts.map +1 -1
- package/dist/types/esm/utils/arrayHasInvalidDefaults.d.ts +1 -1
- package/dist/types/esm/utils/arrayHasInvalidDefaults.d.ts.map +1 -1
- package/dist/types/esm/utils/collateObjectPropertyDefaults.d.ts +2 -2
- package/dist/types/esm/utils/collateObjectPropertyDefaults.d.ts.map +1 -1
- package/dist/types/esm/utils/importValidateTransformWriteConfig.d.ts +1 -1
- package/dist/types/esm/utils/importValidateTransformWriteConfig.d.ts.map +1 -1
- package/dist/types/esm/utils/isSchemaValid.d.ts +1 -1
- package/dist/types/esm/utils/isSchemaValid.d.ts.map +1 -1
- package/dist/types/esm/utils/isValidPropertyDefinition.d.ts +1 -1
- package/dist/types/esm/utils/isValidPropertyDefinition.d.ts.map +1 -1
- package/dist/types/esm/utils/jsonStringifyReplacer.d.ts +1 -1
- package/dist/types/esm/utils/jsonStringifyReplacer.d.ts.map +1 -1
- package/dist/types/esm/utils/objectPropertyHasDefaults.d.ts +1 -1
- package/dist/types/esm/utils/objectPropertyHasDefaults.d.ts.map +1 -1
- package/dist/types/esm/utils/recordHasInvalidDefaults.d.ts +1 -1
- package/dist/types/esm/utils/recordHasInvalidDefaults.d.ts.map +1 -1
- package/dist/types/esm/utils/transformWriteConfig.d.ts +1 -1
- package/dist/types/esm/utils/transformWriteConfig.d.ts.map +1 -1
- package/dist/types/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +22 -32
- package/src/createConfigParser.ts +1 -1
- package/src/createConfigReader.ts +2 -2
- package/src/types.ts +2 -2
- package/src/utils/arrayHasInvalidDefaults.ts +1 -1
- package/src/utils/collateObjectPropertyDefaults.ts +2 -2
- package/src/utils/importValidateTransformWriteConfig.ts +3 -3
- package/src/utils/isSchemaValid.ts +1 -1
- package/src/utils/isValidPropertyDefinition.ts +1 -1
- package/src/utils/jsonStringifyReplacer.ts +1 -1
- package/src/utils/objectPropertyHasDefaults.ts +1 -1
- package/src/utils/recordHasInvalidDefaults.ts +1 -1
- package/src/utils/transformWriteConfig.ts +1 -1
package/README.md
CHANGED
|
@@ -12,7 +12,7 @@ Use our cli module to build and/or watch a config builder file and transform it
|
|
|
12
12
|
|
|
13
13
|
Import that literally typed config in your components along with `zcb` and create a config reader with scoping abilities, config path autocomplete and return value preview.
|
|
14
14
|
|
|
15
|
-
These three features can be used together in the above workflow or
|
|
15
|
+
These three features can be used together in the above workflow or separately. For example, you can just use the config builder to build a type-safe config for use in your application, or you could handcraft a locales file and use the config reader to read its values.
|
|
16
16
|
|
|
17
17
|
## Installation
|
|
18
18
|
|
package/dist/cjs/cli.cjs
CHANGED
|
@@ -1,186 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var node_fs = require('node:fs');
|
|
4
|
-
var node_path = require('node:path');
|
|
5
|
-
var shelljs = require('shelljs');
|
|
6
|
-
var yargs = require('yargs');
|
|
7
|
-
require('core-js/modules/es.array.push.js');
|
|
8
|
-
var esm = require('fs-extra/esm');
|
|
9
|
-
var Handlebars = require('handlebars');
|
|
10
|
-
var node_url = require('node:url');
|
|
11
|
-
var lodashEs = require('lodash-es');
|
|
12
|
-
|
|
13
|
-
let NonEmumeralProperties = function (NonEmumeralProperties) {
|
|
14
|
-
NonEmumeralProperties["CALLBACKS"] = "__callbacks";
|
|
15
|
-
NonEmumeralProperties["DISABLED"] = "__disabled";
|
|
16
|
-
NonEmumeralProperties["EXPERIMENT"] = "__experiment";
|
|
17
|
-
NonEmumeralProperties["ID"] = "__id";
|
|
18
|
-
NonEmumeralProperties["TYPE"] = "__type";
|
|
19
|
-
NonEmumeralProperties["ZCB"] = "__zcb";
|
|
20
|
-
return NonEmumeralProperties;
|
|
21
|
-
}({});
|
|
22
|
-
let TransformConfigHandlerAction = function (TransformConfigHandlerAction) {
|
|
23
|
-
TransformConfigHandlerAction["DELETE_NODE"] = "deleteNode";
|
|
24
|
-
TransformConfigHandlerAction["SKIP_NODE"] = "skipNode";
|
|
25
|
-
return TransformConfigHandlerAction;
|
|
26
|
-
}({});
|
|
27
|
-
|
|
28
|
-
const removeDisabledSlices = (clone, config) => {
|
|
29
|
-
if (NonEmumeralProperties.DISABLED in config) {
|
|
30
|
-
return {
|
|
31
|
-
action: TransformConfigHandlerAction.DELETE_NODE
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
return {
|
|
35
|
-
value: clone
|
|
36
|
-
};
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
const setupExperiments = callback => async (clone, config) => {
|
|
40
|
-
if (NonEmumeralProperties.EXPERIMENT in config && typeof config.__experiment === 'string') {
|
|
41
|
-
const buckets = await callback(config.__experiment, clone, config);
|
|
42
|
-
clone.__experiment = {
|
|
43
|
-
buckets,
|
|
44
|
-
id: config.__experiment
|
|
45
|
-
};
|
|
46
|
-
return {
|
|
47
|
-
value: clone
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
return {
|
|
51
|
-
value: clone
|
|
52
|
-
};
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
const transformArray = (list, handler) => Promise.all(list.map(entry => {
|
|
56
|
-
if (lodashEs.isPlainObject(entry)) {
|
|
57
|
-
return transformConfig(entry, handler);
|
|
58
|
-
}
|
|
59
|
-
if (Array.isArray(entry)) {
|
|
60
|
-
return transformArray(entry, handler);
|
|
61
|
-
}
|
|
62
|
-
return entry;
|
|
63
|
-
}));
|
|
64
|
-
const transformConfig = async (config, handler = []) => {
|
|
65
|
-
let transform = {};
|
|
66
|
-
const handlers = lodashEs.castArray(handler);
|
|
67
|
-
for (const callback of handlers) {
|
|
68
|
-
const result = await Promise.resolve(callback(transform, config));
|
|
69
|
-
if (result.action === TransformConfigHandlerAction.DELETE_NODE) {
|
|
70
|
-
return {};
|
|
71
|
-
}
|
|
72
|
-
if (result.value) {
|
|
73
|
-
transform = result.value;
|
|
74
|
-
}
|
|
75
|
-
if (result.action === TransformConfigHandlerAction.SKIP_NODE) {
|
|
76
|
-
return transform;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
for (const key in config) {
|
|
80
|
-
const value = config[key];
|
|
81
|
-
if (lodashEs.isPlainObject(value)) {
|
|
82
|
-
transform[key] = await transformConfig(value, handler);
|
|
83
|
-
} else if (Array.isArray(value)) {
|
|
84
|
-
transform[key] = await transformArray(value, handler);
|
|
85
|
-
} else {
|
|
86
|
-
transform[key] = value;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
return transform;
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
const transformWriteConfig = async (config, {
|
|
93
|
-
experimentsCallback,
|
|
94
|
-
outputFile
|
|
95
|
-
}) => {
|
|
96
|
-
const handlers = [removeDisabledSlices];
|
|
97
|
-
if (experimentsCallback) {
|
|
98
|
-
handlers.push(setupExperiments(experimentsCallback));
|
|
99
|
-
}
|
|
100
|
-
const template = Handlebars.compile(node_fs.readFileSync(node_path.resolve(node_path.dirname(node_url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (document.currentScript && document.currentScript.src || new URL('cli.cjs', document.baseURI).href)))), './templates/config.ts.hbs'), {
|
|
101
|
-
encoding: 'utf8'
|
|
102
|
-
}));
|
|
103
|
-
const output = template({
|
|
104
|
-
config: JSON.stringify(await transformConfig(config, handlers), undefined, 2)
|
|
105
|
-
}).replaceAll(/"([A-Za-z][\dA-Za-z]+)":/g, '$1:');
|
|
106
|
-
shelljs.echo(`zcd watch => writing to file: ${outputFile}`);
|
|
107
|
-
shelljs.echo(`zcd watch => content to write:\n${output}\n`);
|
|
108
|
-
esm.outputFileSync(node_path.resolve(process.cwd(), outputFile), output);
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
const importValidateTransformWriteConfig = (inputFile, outputFile, command, experimentCallbackFile) => {
|
|
112
|
-
import(node_path.resolve(process.cwd(), inputFile)).then(({
|
|
113
|
-
default: configBuilder
|
|
114
|
-
}) => {
|
|
115
|
-
if (!configBuilder.$validate()) {
|
|
116
|
-
shelljs.echo(`zcd ${command} => invalid config`);
|
|
117
|
-
shelljs.echo(`zcd ${command} => config values:\n${configBuilder.$toJson()}\n`);
|
|
118
|
-
shelljs.echo(`zcd ${command} => errors:\n${JSON.stringify(configBuilder.$errors(), undefined, 2)}\n`);
|
|
119
|
-
shelljs.exit(1);
|
|
120
|
-
}
|
|
121
|
-
shelljs.echo('zcd ${command} => valid config');
|
|
122
|
-
shelljs.echo(`zcd ${command} => config values:\n${configBuilder.$toJson()}\n`);
|
|
123
|
-
if (experimentCallbackFile) {
|
|
124
|
-
import(node_path.resolve(process.cwd(), experimentCallbackFile)).then(({
|
|
125
|
-
default: experimentsCallback
|
|
126
|
-
}) => {
|
|
127
|
-
void transformWriteConfig(configBuilder.$values(), {
|
|
128
|
-
experimentsCallback,
|
|
129
|
-
outputFile
|
|
130
|
-
});
|
|
131
|
-
}).catch(error => {
|
|
132
|
-
if (error instanceof Error) {
|
|
133
|
-
shelljs.echo(`zcd ${command} => error message: ${error.message}`);
|
|
134
|
-
if (error.stack) {
|
|
135
|
-
shelljs.echo(`zcd ${command} => error stack:\n${error.stack}\n`);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
});
|
|
139
|
-
return;
|
|
140
|
-
}
|
|
141
|
-
void transformWriteConfig(configBuilder.$values(), {
|
|
142
|
-
outputFile
|
|
143
|
-
});
|
|
144
|
-
}).catch(error => {
|
|
145
|
-
if (error instanceof Error) {
|
|
146
|
-
shelljs.echo(`zcd ${command} => error message: ${error.message}`);
|
|
147
|
-
if (error.stack) {
|
|
148
|
-
shelljs.echo(`zcd ${command} => error stack:\n${error.stack}\n`);
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
});
|
|
152
|
-
};
|
|
153
|
-
|
|
154
|
-
let Commands = function (Commands) {
|
|
155
|
-
Commands["BUILD"] = "build";
|
|
156
|
-
Commands["WATCH"] = "watch";
|
|
157
|
-
return Commands;
|
|
158
|
-
}({});
|
|
159
|
-
const generateArguments = cmdYargs => cmdYargs.positional('input-file', {
|
|
160
|
-
demandOption: true,
|
|
161
|
-
desc: 'The relative path to the config builder root file',
|
|
162
|
-
type: 'string'
|
|
163
|
-
}).positional('output-file', {
|
|
164
|
-
demandOption: true,
|
|
165
|
-
desc: 'The relative path to the output config file',
|
|
166
|
-
type: 'string'
|
|
167
|
-
}).option('experiments-callback-file', {
|
|
168
|
-
desc: 'The relative path to the experiment callback file',
|
|
169
|
-
type: 'string'
|
|
170
|
-
});
|
|
171
|
-
const cli = () => {
|
|
172
|
-
yargs.command('watch <input-file> <output-file>', 'Watch a config builder and write config', cmdYargs => generateArguments(cmdYargs), argv => {
|
|
173
|
-
shelljs.echo(`zcd watch => watching file: ${argv['input-file']}`);
|
|
174
|
-
node_fs.watchFile(node_path.resolve(process.cwd(), argv['input-file']), () => {
|
|
175
|
-
shelljs.echo('zcd watch => file change detected');
|
|
176
|
-
importValidateTransformWriteConfig(argv['input-file'], argv['output-file'], Commands.WATCH, argv['experiments-callback-file']);
|
|
177
|
-
});
|
|
178
|
-
}).command('build <input-file> <output-file>', 'Write config from a config builder', cmdYargs => generateArguments(cmdYargs), argv => {
|
|
179
|
-
shelljs.echo(`zcd build => building file: ${argv['input-file']}`);
|
|
180
|
-
importValidateTransformWriteConfig(argv['input-file'], argv['output-file'], Commands.BUILD, argv['experiments-callback-file']);
|
|
181
|
-
}).help().argv;
|
|
182
|
-
};
|
|
183
|
-
|
|
184
|
-
exports.Commands = Commands;
|
|
185
|
-
exports.cli = cli;
|
|
1
|
+
"use strict";var e=require("node:fs"),t=require("node:path"),i=require("shelljs"),r=require("yargs");require("core-js/modules/es.array.push.js");var c,o,n=require("fs-extra/esm"),a=require("handlebars"),s=require("node:url"),l=require("lodash-es");!function(e){e.CALLBACKS="__callbacks",e.DISABLED="__disabled",e.EXPERIMENT="__experiment",e.ID="__id",e.TYPE="__type",e.ZCB="__zcb"}(c||(c={})),function(e){e.DELETE_NODE="deleteNode",e.SKIP_NODE="skipNode"}(o||(o={}));const u=(e,t)=>c.DISABLED in t?{action:o.DELETE_NODE}:{value:e},d=(e,t)=>Promise.all(e.map((e=>l.isPlainObject(e)?p(e,t):Array.isArray(e)?d(e,t):e))),p=async(e,t=[])=>{let i={};const r=l.castArray(t);for(const t of r){const r=await Promise.resolve(t(i,e));if(r.action===o.DELETE_NODE)return{};if(r.value&&(i=r.value),r.action===o.SKIP_NODE)return i}for(const r in e){const c=e[r];l.isPlainObject(c)?i[r]=await p(c,t):Array.isArray(c)?i[r]=await d(c,t):i[r]=c}return i},f=async(r,{experimentsCallback:o,outputFile:l})=>{const d=[u];var f;o&&d.push((f=o,async(e,t)=>{if(c.EXPERIMENT in t&&"string"==typeof t.__experiment){const i=await f(t.__experiment,e,t);return e.__experiment={buckets:i,id:t.__experiment},{value:e}}return{value:e}}));const h=a.compile(e.readFileSync(t.resolve(t.dirname(s.fileURLToPath("undefined"==typeof document?require("url").pathToFileURL(__filename).href:document.currentScript&&document.currentScript.src||new URL("cli.cjs",document.baseURI).href)),"./templates/config.ts.hbs"),{encoding:"utf8"}))({config:JSON.stringify(await p(r,d),void 0,2)}).replaceAll(/"([A-Za-z][\dA-Za-z]+)":/g,"$1:");i.echo(`zcd watch => writing to file: ${l}`),i.echo(`zcd watch => content to write:\n${h}\n`),n.outputFileSync(t.resolve(process.cwd(),l),h)},h=(e,r,c,o)=>{import(t.resolve(process.cwd(),e)).then((({default:e})=>{e.$validate()||(i.echo(`zcd ${c} => invalid config`),i.echo(`zcd ${c} => config values:\n${e.$toJson()}\n`),i.echo(`zcd ${c} => errors:\n${JSON.stringify(e.$errors(),void 0,2)}\n`),i.exit(1)),i.echo("zcd ${command} => valid config"),i.echo(`zcd ${c} => config values:\n${e.$toJson()}\n`),o?import(t.resolve(process.cwd(),o)).then((({default:t})=>{f(e.$values(),{experimentsCallback:t,outputFile:r})})).catch((e=>{e instanceof Error&&(i.echo(`zcd ${c} => error message: ${e.message}`),e.stack&&i.echo(`zcd ${c} => error stack:\n${e.stack}\n`))})):f(e.$values(),{outputFile:r})})).catch((e=>{e instanceof Error&&(i.echo(`zcd ${c} => error message: ${e.message}`),e.stack&&i.echo(`zcd ${c} => error stack:\n${e.stack}\n`))}))};var m;exports.Commands=void 0,(m=exports.Commands||(exports.Commands={})).BUILD="build",m.WATCH="watch";const g=e=>e.positional("input-file",{demandOption:!0,desc:"The relative path to the config builder root file",type:"string"}).positional("output-file",{demandOption:!0,desc:"The relative path to the output config file",type:"string"}).option("experiments-callback-file",{desc:"The relative path to the experiment callback file",type:"string"});exports.cli=()=>{r.command("watch <input-file> <output-file>","Watch a config builder and write config",(e=>g(e)),(r=>{i.echo(`zcd watch => watching file: ${r["input-file"]}`),e.watchFile(t.resolve(process.cwd(),r["input-file"]),(()=>{i.echo("zcd watch => file change detected"),h(r["input-file"],r["output-file"],"watch",r["experiments-callback-file"])}))})).command("build <input-file> <output-file>","Write config from a config builder",(e=>g(e)),(e=>{i.echo(`zcd build => building file: ${e["input-file"]}`),h(e["input-file"],e["output-file"],"build",e["experiments-callback-file"])})).help().argv};
|
|
186
2
|
//# sourceMappingURL=cli.cjs.map
|
package/dist/cjs/cli.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.cjs","sources":["../zod-config-builder/src//types.ts","../zod-config-builder/src//transformers/removeDisabledSlices.ts","../zod-config-builder/src//transformers/setupExperiments.ts","../zod-config-builder/src//utils/transformConfig.ts","../zod-config-builder/src//utils/transformWriteConfig.ts","../zod-config-builder/src//utils/importValidateTransformWriteConfig.ts","../zod-config-builder/src//cli.ts"],"sourcesContent":["import type { List } from 'ts-toolbelt';\nimport type { Includes, Join } from 'type-fest';\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type AnyRecord = Record<string, any>;\n\nexport type Buckets<Config extends AnyRecord> = Record<string, Experiment<Config>>;\n\nexport interface ConfigParserOptions {\n experimentsCallback?: RunExperimentsCallback;\n}\n\nexport interface Experiment<Config extends AnyRecord> {\n action?: TransformConfigHandlerAction;\n value?: Config;\n}\n\nexport enum NonEmumeralProperties {\n CALLBACKS = '__callbacks',\n DISABLED = '__disabled',\n EXPERIMENT = '__experiment',\n ID = '__id',\n TYPE = '__type',\n ZCB = '__zcb',\n}\n\nexport type Path<Config extends object> = Join<Leaves<Config>, '.'>;\n\nexport type RunExperimentsCallback = (id: string) => Promise<string>;\n\nexport type Scope<Config extends object> = Join<Paths<Config>, '.'>;\n\nexport type SetupExperimentsCallback = <Config extends AnyRecord>(\n id: string,\n clone: Config,\n config: Config\n) => Promise<Buckets<Config>>;\n\nexport type TransformConfigHandler = <Config extends AnyRecord>(\n clone: Config,\n config: Config\n) => TransformConfigHandlerReturnType<Config> | Promise<TransformConfigHandlerReturnType<Config>>;\n\nexport type TransformConfigHandlerSync = <Config extends AnyRecord>(\n clone: Config,\n config: Config\n) => TransformConfigHandlerReturnType<Config>;\n\nexport enum TransformConfigHandlerAction {\n DELETE_NODE = 'deleteNode',\n SKIP_NODE = 'skipNode',\n}\n\nexport interface TransformConfigHandlerReturnType<Config extends AnyRecord> {\n action?: TransformConfigHandlerAction;\n value?: Config;\n}\n\nexport interface WriteConfigOptions {\n experimentsCallback?: SetupExperimentsCallback;\n outputFile: string;\n}\n\nexport type Leaves<T, LeafPath extends string[] = []> = T extends string\n ? LeafPath\n : {\n [K in keyof T & string]: Leaves<T[K], [...LeafPath, K]>;\n }[keyof T & string];\n\nexport type Paths<T, LeafPath extends string[] = []> = T extends string\n ? LeafPath\n : {\n [K in keyof T & string]: T[K] extends object ? Paths<T[K], [...LeafPath, K]> : LeafPath;\n }[keyof T & string];\n\nexport type LeavesScopeDiffs<T1 extends readonly string[][], T2 extends string[]> = {\n [K1 in keyof T1]: List.Length<List.Intersect<T1[K1], T2, '<-contains'>> extends 1\n ? List.Length<T1[K1]> extends 1\n ? Includes<T2, T1[K1][0]> extends false\n ? T1[K1]\n : never\n : List.Diff<T1[K1], T2>\n : never;\n}[number];\n","import {\n type AnyRecord,\n NonEmumeralProperties,\n TransformConfigHandlerAction,\n type TransformConfigHandlerSync,\n} from '../types.ts';\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const removeDisabledSlices: TransformConfigHandlerSync = <Config extends AnyRecord>(\n clone: Config,\n config: Config\n) => {\n if (NonEmumeralProperties.DISABLED in config) {\n return {\n action: TransformConfigHandlerAction.DELETE_NODE,\n };\n }\n\n return {\n value: clone,\n };\n};\n","import {\n type AnyRecord,\n NonEmumeralProperties,\n type SetupExperimentsCallback,\n type TransformConfigHandler,\n} from '../types.ts';\n\nexport const setupExperiments =\n (callback: SetupExperimentsCallback): TransformConfigHandler =>\n async <Config extends AnyRecord>(clone: Config, config: Config) => {\n if (NonEmumeralProperties.EXPERIMENT in config && typeof config.__experiment === 'string') {\n const buckets = await callback(config.__experiment, clone, config);\n\n // @ts-expect-error private property\n clone.__experiment = {\n buckets,\n id: config.__experiment,\n };\n\n return {\n value: clone,\n };\n }\n\n return {\n value: clone,\n };\n };\n","import { castArray, isPlainObject } from 'lodash-es';\nimport {\n type AnyRecord,\n type TransformConfigHandler,\n TransformConfigHandlerAction,\n type TransformConfigHandlerSync,\n} from '../types.ts';\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst transformArray = (list: any[], handler: TransformConfigHandler | TransformConfigHandler[]): Promise<any[]> =>\n Promise.all(\n list.map(entry => {\n if (isPlainObject(entry)) {\n return transformConfig(entry, handler);\n }\n\n if (Array.isArray(entry)) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return transformArray(entry, handler);\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return entry;\n })\n );\n\nexport const transformConfig = async <Config extends AnyRecord>(\n config: Config,\n handler: TransformConfigHandler | TransformConfigHandler[] = []\n): Promise<Config> => {\n let transform = {} as Config;\n const handlers = castArray(handler);\n\n for (const callback of handlers) {\n const result = await Promise.resolve(callback(transform, config));\n\n if (result.action === TransformConfigHandlerAction.DELETE_NODE) {\n return {} as Config;\n }\n\n if (result.value) {\n transform = result.value;\n }\n\n if (result.action === TransformConfigHandlerAction.SKIP_NODE) {\n return transform;\n }\n }\n\n for (const key in config) {\n const value = config[key];\n\n if (isPlainObject(value)) {\n transform[key] = await transformConfig(value, handler);\n } else if (Array.isArray(value)) {\n transform[key] = (await transformArray(value, handler)) as Config[Extract<keyof Config, string>];\n } else {\n transform[key] = value;\n }\n }\n\n return transform;\n};\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst transformArraySync = (list: any[], handler: TransformConfigHandlerSync | TransformConfigHandlerSync[]): any[] =>\n list.map(entry => {\n if (isPlainObject(entry)) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return transformConfigSync(entry, handler);\n }\n\n if (Array.isArray(entry)) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return transformArraySync(entry, handler);\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return entry;\n });\n\nexport const transformConfigSync = <Config extends AnyRecord>(\n config: Config,\n handler: TransformConfigHandlerSync | TransformConfigHandlerSync[] = []\n): Config => {\n let transform = {} as Config;\n const handlers = castArray(handler);\n\n for (const callback of handlers) {\n const result = callback(transform, config);\n\n if (result.action === TransformConfigHandlerAction.DELETE_NODE) {\n return {} as Config;\n }\n\n if (result.value) {\n transform = result.value;\n }\n\n if (result.action === TransformConfigHandlerAction.SKIP_NODE) {\n return transform;\n }\n }\n\n for (const key in config) {\n const value = config[key];\n\n if (isPlainObject(value)) {\n transform[key] = transformConfigSync(value, handler);\n } else if (Array.isArray(value)) {\n transform[key] = transformArraySync(value, handler) as Config[Extract<keyof Config, string>];\n } else {\n transform[key] = value;\n }\n }\n\n return transform;\n};\n","import { outputFileSync } from 'fs-extra/esm';\nimport Handlebars from 'handlebars';\nimport { readFileSync } from 'node:fs';\nimport { dirname, resolve } from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport shelljs from 'shelljs';\nimport { removeDisabledSlices } from '../transformers/removeDisabledSlices.ts';\nimport { setupExperiments } from '../transformers/setupExperiments.ts';\nimport type { TransformConfigHandler, WriteConfigOptions } from '../types.ts';\nimport { transformConfig } from './transformConfig.ts';\n\nexport const transformWriteConfig = async <Config extends object>(\n config: Config,\n { experimentsCallback, outputFile }: WriteConfigOptions\n) => {\n const handlers: TransformConfigHandler[] = [removeDisabledSlices];\n\n if (experimentsCallback) {\n handlers.push(setupExperiments(experimentsCallback));\n }\n\n const template = Handlebars.compile(\n readFileSync(resolve(dirname(fileURLToPath(import.meta.url)), './templates/config.ts.hbs'), { encoding: 'utf8' })\n );\n\n const output = template({ config: JSON.stringify(await transformConfig(config, handlers), undefined, 2) }).replaceAll(\n /\"([A-Za-z][\\dA-Za-z]+)\":/g,\n '$1:'\n );\n\n shelljs.echo(`zcd watch => writing to file: ${outputFile}`);\n shelljs.echo(`zcd watch => content to write:\\n${output}\\n`);\n outputFileSync(resolve(process.cwd(), outputFile), output);\n};\n","import { resolve } from 'node:path';\nimport shelljs from 'shelljs';\nimport type { Commands } from '../cli.ts';\nimport type { ConfigBuilder } from '../createConfigBuilder.ts';\nimport type { SetupExperimentsCallback } from '../types.ts';\nimport { transformWriteConfig } from './transformWriteConfig.ts';\n\nexport const importValidateTransformWriteConfig = (\n inputFile: string,\n outputFile: string,\n command: Commands,\n experimentCallbackFile?: string\n) => {\n import(resolve(process.cwd(), inputFile))\n .then(({ default: configBuilder }: { default: ConfigBuilder<object> }) => {\n if (!configBuilder.$validate()) {\n shelljs.echo(`zcd ${command} => invalid config`);\n shelljs.echo(`zcd ${command} => config values:\\n${configBuilder.$toJson()}\\n`);\n shelljs.echo(`zcd ${command} => errors:\\n${JSON.stringify(configBuilder.$errors(), undefined, 2)}\\n`);\n shelljs.exit(1);\n }\n\n shelljs.echo('zcd ${command} => valid config');\n shelljs.echo(`zcd ${command} => config values:\\n${configBuilder.$toJson()}\\n`);\n\n if (experimentCallbackFile) {\n import(resolve(process.cwd(), experimentCallbackFile))\n .then(({ default: experimentsCallback }: { default: SetupExperimentsCallback }) => {\n void transformWriteConfig(configBuilder.$values(), { experimentsCallback, outputFile });\n })\n .catch((error: unknown) => {\n if (error instanceof Error) {\n shelljs.echo(`zcd ${command} => error message: ${error.message}`);\n\n if (error.stack) {\n shelljs.echo(`zcd ${command} => error stack:\\n${error.stack}\\n`);\n }\n }\n });\n\n return;\n }\n\n void transformWriteConfig(configBuilder.$values(), { outputFile });\n })\n .catch((error: unknown) => {\n if (error instanceof Error) {\n shelljs.echo(`zcd ${command} => error message: ${error.message}`);\n\n if (error.stack) {\n shelljs.echo(`zcd ${command} => error stack:\\n${error.stack}\\n`);\n }\n }\n });\n};\n","import { watchFile } from 'node:fs';\nimport { resolve } from 'node:path';\nimport shelljs from 'shelljs';\nimport yargs from 'yargs';\nimport { importValidateTransformWriteConfig } from './utils/importValidateTransformWriteConfig.ts';\n\nexport enum Commands {\n BUILD = 'build',\n WATCH = 'watch',\n}\n\nconst generateArguments = (cmdYargs: yargs.Argv) =>\n cmdYargs\n .positional('input-file', {\n demandOption: true,\n desc: 'The relative path to the config builder root file',\n type: 'string',\n })\n .positional('output-file', {\n demandOption: true,\n desc: 'The relative path to the output config file',\n type: 'string',\n })\n .option('experiments-callback-file', {\n desc: 'The relative path to the experiment callback file',\n type: 'string',\n });\n\nexport const cli = () => {\n yargs\n .command(\n 'watch <input-file> <output-file>',\n 'Watch a config builder and write config',\n cmdYargs => generateArguments(cmdYargs),\n argv => {\n shelljs.echo(`zcd watch => watching file: ${argv['input-file']}`);\n\n watchFile(resolve(process.cwd(), argv['input-file']), () => {\n shelljs.echo('zcd watch => file change detected');\n\n importValidateTransformWriteConfig(\n argv['input-file'],\n argv['output-file'],\n Commands.WATCH,\n argv['experiments-callback-file']\n );\n });\n }\n )\n .command(\n 'build <input-file> <output-file>',\n 'Write config from a config builder',\n cmdYargs => generateArguments(cmdYargs),\n argv => {\n shelljs.echo(`zcd build => building file: ${argv['input-file']}`);\n\n importValidateTransformWriteConfig(\n argv['input-file'],\n argv['output-file'],\n Commands.BUILD,\n argv['experiments-callback-file']\n );\n }\n )\n .help().argv;\n};\n"],"names":["NonEmumeralProperties","TransformConfigHandlerAction","removeDisabledSlices","clone","config","DISABLED","action","DELETE_NODE","value","setupExperiments","callback","EXPERIMENT","__experiment","buckets","id","transformArray","list","handler","Promise","all","map","entry","isPlainObject","transformConfig","Array","isArray","transform","handlers","castArray","result","resolve","SKIP_NODE","key","transformWriteConfig","experimentsCallback","outputFile","push","template","Handlebars","compile","readFileSync","dirname","fileURLToPath","import","encoding","output","JSON","stringify","undefined","replaceAll","shelljs","echo","outputFileSync","process","cwd","importValidateTransformWriteConfig","inputFile","command","experimentCallbackFile","then","default","configBuilder","$validate","$toJson","$errors","exit","$values","catch","error","Error","message","stack","Commands","generateArguments","cmdYargs","positional","demandOption","desc","type","option","cli","yargs","argv","watchFile","WATCH","BUILD","help"],"mappings":";;;;;;;;;;;;AAiBYA,IAAAA,qBAAqB,aAArBA,qBAAqB,EAAA;EAArBA,qBAAqB,CAAA,WAAA,CAAA,GAAA,aAAA,CAAA;EAArBA,qBAAqB,CAAA,UAAA,CAAA,GAAA,YAAA,CAAA;EAArBA,qBAAqB,CAAA,YAAA,CAAA,GAAA,cAAA,CAAA;EAArBA,qBAAqB,CAAA,IAAA,CAAA,GAAA,MAAA,CAAA;EAArBA,qBAAqB,CAAA,MAAA,CAAA,GAAA,QAAA,CAAA;EAArBA,qBAAqB,CAAA,KAAA,CAAA,GAAA,OAAA,CAAA;AAAA,EAAA,OAArBA,qBAAqB,CAAA;AAAA,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AAC,CAAA;AACJ,GACF,CAAC,CACAzB,OAAO,CACN,kCAAkC,EAClC,oCAAoC,EACpCiB,QAAQ,IAAID,iBAAiB,CAACC,QAAQ,CAAC,EACvCQ,IAAI,IAAI;IACNhC,OAAO,CAACC,IAAI,CAAE,CAAA,4BAAA,EAA8B+B,IAAI,CAAC,YAAY,CAAE,CAAA,CAAC,CAAC,CAAA;AAEjE3B,IAAAA,kCAAkC,CAChC2B,IAAI,CAAC,YAAY,CAAC,EAClBA,IAAI,CAAC,aAAa,CAAC,EACnBV,QAAQ,CAACa,KAAK,EACdH,IAAI,CAAC,2BAA2B,CAClC,CAAC,CAAA;AACH,GACF,CAAC,CACAI,IAAI,EAAE,CAACJ,IAAI,CAAA;AAChB;;;;;"}
|
|
1
|
+
{"version":3,"file":"cli.cjs","sources":["../zod-config-builder/src//types.ts","../zod-config-builder/src//transformers/removeDisabledSlices.ts","../zod-config-builder/src//utils/transformConfig.ts","../zod-config-builder/src//utils/transformWriteConfig.ts","../zod-config-builder/src//transformers/setupExperiments.ts","../zod-config-builder/src//utils/importValidateTransformWriteConfig.ts","../zod-config-builder/src//cli.ts"],"sourcesContent":["import { type List } from 'ts-toolbelt';\nimport { type Includes, type Join } from 'type-fest';\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type AnyRecord = Record<string, any>;\n\nexport type Buckets<Config extends AnyRecord> = Record<string, Experiment<Config>>;\n\nexport interface ConfigParserOptions {\n experimentsCallback?: RunExperimentsCallback;\n}\n\nexport interface Experiment<Config extends AnyRecord> {\n action?: TransformConfigHandlerAction;\n value?: Config;\n}\n\nexport enum NonEmumeralProperties {\n CALLBACKS = '__callbacks',\n DISABLED = '__disabled',\n EXPERIMENT = '__experiment',\n ID = '__id',\n TYPE = '__type',\n ZCB = '__zcb',\n}\n\nexport type Path<Config extends object> = Join<Leaves<Config>, '.'>;\n\nexport type RunExperimentsCallback = (id: string) => Promise<string>;\n\nexport type Scope<Config extends object> = Join<Paths<Config>, '.'>;\n\nexport type SetupExperimentsCallback = <Config extends AnyRecord>(\n id: string,\n clone: Config,\n config: Config\n) => Promise<Buckets<Config>>;\n\nexport type TransformConfigHandler = <Config extends AnyRecord>(\n clone: Config,\n config: Config\n) => TransformConfigHandlerReturnType<Config> | Promise<TransformConfigHandlerReturnType<Config>>;\n\nexport type TransformConfigHandlerSync = <Config extends AnyRecord>(\n clone: Config,\n config: Config\n) => TransformConfigHandlerReturnType<Config>;\n\nexport enum TransformConfigHandlerAction {\n DELETE_NODE = 'deleteNode',\n SKIP_NODE = 'skipNode',\n}\n\nexport interface TransformConfigHandlerReturnType<Config extends AnyRecord> {\n action?: TransformConfigHandlerAction;\n value?: Config;\n}\n\nexport interface WriteConfigOptions {\n experimentsCallback?: SetupExperimentsCallback;\n outputFile: string;\n}\n\nexport type Leaves<T, LeafPath extends string[] = []> = T extends string\n ? LeafPath\n : {\n [K in keyof T & string]: Leaves<T[K], [...LeafPath, K]>;\n }[keyof T & string];\n\nexport type Paths<T, LeafPath extends string[] = []> = T extends string\n ? LeafPath\n : {\n [K in keyof T & string]: T[K] extends object ? Paths<T[K], [...LeafPath, K]> : LeafPath;\n }[keyof T & string];\n\nexport type LeavesScopeDiffs<T1 extends readonly string[][], T2 extends string[]> = {\n [K1 in keyof T1]: List.Length<List.Intersect<T1[K1], T2, '<-contains'>> extends 1\n ? List.Length<T1[K1]> extends 1\n ? Includes<T2, T1[K1][0]> extends false\n ? T1[K1]\n : never\n : List.Diff<T1[K1], T2>\n : never;\n}[number];\n","import {\n type AnyRecord,\n NonEmumeralProperties,\n TransformConfigHandlerAction,\n type TransformConfigHandlerSync,\n} from '../types.ts';\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const removeDisabledSlices: TransformConfigHandlerSync = <Config extends AnyRecord>(\n clone: Config,\n config: Config\n) => {\n if (NonEmumeralProperties.DISABLED in config) {\n return {\n action: TransformConfigHandlerAction.DELETE_NODE,\n };\n }\n\n return {\n value: clone,\n };\n};\n","import { castArray, isPlainObject } from 'lodash-es';\nimport {\n type AnyRecord,\n type TransformConfigHandler,\n TransformConfigHandlerAction,\n type TransformConfigHandlerSync,\n} from '../types.ts';\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst transformArray = (list: any[], handler: TransformConfigHandler | TransformConfigHandler[]): Promise<any[]> =>\n Promise.all(\n list.map(entry => {\n if (isPlainObject(entry)) {\n return transformConfig(entry, handler);\n }\n\n if (Array.isArray(entry)) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return transformArray(entry, handler);\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return entry;\n })\n );\n\nexport const transformConfig = async <Config extends AnyRecord>(\n config: Config,\n handler: TransformConfigHandler | TransformConfigHandler[] = []\n): Promise<Config> => {\n let transform = {} as Config;\n const handlers = castArray(handler);\n\n for (const callback of handlers) {\n const result = await Promise.resolve(callback(transform, config));\n\n if (result.action === TransformConfigHandlerAction.DELETE_NODE) {\n return {} as Config;\n }\n\n if (result.value) {\n transform = result.value;\n }\n\n if (result.action === TransformConfigHandlerAction.SKIP_NODE) {\n return transform;\n }\n }\n\n for (const key in config) {\n const value = config[key];\n\n if (isPlainObject(value)) {\n transform[key] = await transformConfig(value, handler);\n } else if (Array.isArray(value)) {\n transform[key] = (await transformArray(value, handler)) as Config[Extract<keyof Config, string>];\n } else {\n transform[key] = value;\n }\n }\n\n return transform;\n};\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst transformArraySync = (list: any[], handler: TransformConfigHandlerSync | TransformConfigHandlerSync[]): any[] =>\n list.map(entry => {\n if (isPlainObject(entry)) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return transformConfigSync(entry, handler);\n }\n\n if (Array.isArray(entry)) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return transformArraySync(entry, handler);\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return entry;\n });\n\nexport const transformConfigSync = <Config extends AnyRecord>(\n config: Config,\n handler: TransformConfigHandlerSync | TransformConfigHandlerSync[] = []\n): Config => {\n let transform = {} as Config;\n const handlers = castArray(handler);\n\n for (const callback of handlers) {\n const result = callback(transform, config);\n\n if (result.action === TransformConfigHandlerAction.DELETE_NODE) {\n return {} as Config;\n }\n\n if (result.value) {\n transform = result.value;\n }\n\n if (result.action === TransformConfigHandlerAction.SKIP_NODE) {\n return transform;\n }\n }\n\n for (const key in config) {\n const value = config[key];\n\n if (isPlainObject(value)) {\n transform[key] = transformConfigSync(value, handler);\n } else if (Array.isArray(value)) {\n transform[key] = transformArraySync(value, handler) as Config[Extract<keyof Config, string>];\n } else {\n transform[key] = value;\n }\n }\n\n return transform;\n};\n","import { outputFileSync } from 'fs-extra/esm';\nimport Handlebars from 'handlebars';\nimport { readFileSync } from 'node:fs';\nimport { dirname, resolve } from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport shelljs from 'shelljs';\nimport { removeDisabledSlices } from '../transformers/removeDisabledSlices.ts';\nimport { setupExperiments } from '../transformers/setupExperiments.ts';\nimport { type TransformConfigHandler, type WriteConfigOptions } from '../types.ts';\nimport { transformConfig } from './transformConfig.ts';\n\nexport const transformWriteConfig = async <Config extends object>(\n config: Config,\n { experimentsCallback, outputFile }: WriteConfigOptions\n) => {\n const handlers: TransformConfigHandler[] = [removeDisabledSlices];\n\n if (experimentsCallback) {\n handlers.push(setupExperiments(experimentsCallback));\n }\n\n const template = Handlebars.compile(\n readFileSync(resolve(dirname(fileURLToPath(import.meta.url)), './templates/config.ts.hbs'), { encoding: 'utf8' })\n );\n\n const output = template({ config: JSON.stringify(await transformConfig(config, handlers), undefined, 2) }).replaceAll(\n /\"([A-Za-z][\\dA-Za-z]+)\":/g,\n '$1:'\n );\n\n shelljs.echo(`zcd watch => writing to file: ${outputFile}`);\n shelljs.echo(`zcd watch => content to write:\\n${output}\\n`);\n outputFileSync(resolve(process.cwd(), outputFile), output);\n};\n","import {\n type AnyRecord,\n NonEmumeralProperties,\n type SetupExperimentsCallback,\n type TransformConfigHandler,\n} from '../types.ts';\n\nexport const setupExperiments =\n (callback: SetupExperimentsCallback): TransformConfigHandler =>\n async <Config extends AnyRecord>(clone: Config, config: Config) => {\n if (NonEmumeralProperties.EXPERIMENT in config && typeof config.__experiment === 'string') {\n const buckets = await callback(config.__experiment, clone, config);\n\n // @ts-expect-error private property\n clone.__experiment = {\n buckets,\n id: config.__experiment,\n };\n\n return {\n value: clone,\n };\n }\n\n return {\n value: clone,\n };\n };\n","import { resolve } from 'node:path';\nimport shelljs from 'shelljs';\nimport { type Commands } from '../cli.ts';\nimport { type ConfigBuilder } from '../createConfigBuilder.ts';\nimport { type SetupExperimentsCallback } from '../types.ts';\nimport { transformWriteConfig } from './transformWriteConfig.ts';\n\nexport const importValidateTransformWriteConfig = (\n inputFile: string,\n outputFile: string,\n command: Commands,\n experimentCallbackFile?: string\n) => {\n import(resolve(process.cwd(), inputFile))\n .then(({ default: configBuilder }: { default: ConfigBuilder<object> }) => {\n if (!configBuilder.$validate()) {\n shelljs.echo(`zcd ${command} => invalid config`);\n shelljs.echo(`zcd ${command} => config values:\\n${configBuilder.$toJson()}\\n`);\n shelljs.echo(`zcd ${command} => errors:\\n${JSON.stringify(configBuilder.$errors(), undefined, 2)}\\n`);\n shelljs.exit(1);\n }\n\n shelljs.echo('zcd ${command} => valid config');\n shelljs.echo(`zcd ${command} => config values:\\n${configBuilder.$toJson()}\\n`);\n\n if (experimentCallbackFile) {\n import(resolve(process.cwd(), experimentCallbackFile))\n .then(({ default: experimentsCallback }: { default: SetupExperimentsCallback }) => {\n void transformWriteConfig(configBuilder.$values(), { experimentsCallback, outputFile });\n })\n .catch((error: unknown) => {\n if (error instanceof Error) {\n shelljs.echo(`zcd ${command} => error message: ${error.message}`);\n\n if (error.stack) {\n shelljs.echo(`zcd ${command} => error stack:\\n${error.stack}\\n`);\n }\n }\n });\n\n return;\n }\n\n void transformWriteConfig(configBuilder.$values(), { outputFile });\n })\n .catch((error: unknown) => {\n if (error instanceof Error) {\n shelljs.echo(`zcd ${command} => error message: ${error.message}`);\n\n if (error.stack) {\n shelljs.echo(`zcd ${command} => error stack:\\n${error.stack}\\n`);\n }\n }\n });\n};\n","import { watchFile } from 'node:fs';\nimport { resolve } from 'node:path';\nimport shelljs from 'shelljs';\nimport yargs from 'yargs';\nimport { importValidateTransformWriteConfig } from './utils/importValidateTransformWriteConfig.ts';\n\nexport enum Commands {\n BUILD = 'build',\n WATCH = 'watch',\n}\n\nconst generateArguments = (cmdYargs: yargs.Argv) =>\n cmdYargs\n .positional('input-file', {\n demandOption: true,\n desc: 'The relative path to the config builder root file',\n type: 'string',\n })\n .positional('output-file', {\n demandOption: true,\n desc: 'The relative path to the output config file',\n type: 'string',\n })\n .option('experiments-callback-file', {\n desc: 'The relative path to the experiment callback file',\n type: 'string',\n });\n\nexport const cli = () => {\n yargs\n .command(\n 'watch <input-file> <output-file>',\n 'Watch a config builder and write config',\n cmdYargs => generateArguments(cmdYargs),\n argv => {\n shelljs.echo(`zcd watch => watching file: ${argv['input-file']}`);\n\n watchFile(resolve(process.cwd(), argv['input-file']), () => {\n shelljs.echo('zcd watch => file change detected');\n\n importValidateTransformWriteConfig(\n argv['input-file'],\n argv['output-file'],\n Commands.WATCH,\n argv['experiments-callback-file']\n );\n });\n }\n )\n .command(\n 'build <input-file> <output-file>',\n 'Write config from a config builder',\n cmdYargs => generateArguments(cmdYargs),\n argv => {\n shelljs.echo(`zcd build => building file: ${argv['input-file']}`);\n\n importValidateTransformWriteConfig(\n argv['input-file'],\n argv['output-file'],\n Commands.BUILD,\n argv['experiments-callback-file']\n );\n }\n )\n .help().argv;\n};\n"],"names":["NonEmumeralProperties","TransformConfigHandlerAction","removeDisabledSlices","clone","config","DISABLED","action","DELETE_NODE","value","transformArray","list","handler","Promise","all","map","entry","isPlainObject","transformConfig","Array","isArray","async","transform","handlers","castArray","callback","result","resolve","SKIP_NODE","key","transformWriteConfig","experimentsCallback","outputFile","push","EXPERIMENT","__experiment","buckets","id","output","Handlebars","compile","readFileSync","dirname","fileURLToPath","document","require","pathToFileURL","__filename","href","currentScript","src","URL","baseURI","encoding","template","JSON","stringify","undefined","replaceAll","shelljs","echo","outputFileSync","process","cwd","importValidateTransformWriteConfig","inputFile","command","experimentCallbackFile","import","then","default","configBuilder","$validate","$toJson","$errors","exit","$values","catch","error","Error","message","stack","Commands","generateArguments","cmdYargs","positional","demandOption","desc","type","option","yargs","argv","watchFile","help"],"mappings":"yPAiBYA,SAAAA,2HAAAA,CAAAA,IAAAA,EAAAA,CAAAA,IA+BAC,SAAAA,qDAAAA,CAAAA,IAAAA,EAAAA,CAAAA,ICxCL,MAAMC,EAAmD,CAC9DC,EACAC,IAEIJ,EAAsBK,YAAYD,EAC7B,CACLE,OAAQL,EAA6BM,aAIlC,CACLC,MAAOL,GCVLM,EAAiB,CAACC,EAAaC,IACnCC,QAAQC,IACNH,EAAKI,KAAIC,GACHC,EAAAA,cAAcD,GACTE,EAAgBF,EAAOJ,GAG5BO,MAAMC,QAAQJ,GAETN,EAAeM,EAAOJ,GAIxBI,KAIAE,EAAkBG,MAC7BhB,EACAO,EAA6D,MAE7D,IAAIU,EAAY,CAAA,EAChB,MAAMC,EAAWC,YAAUZ,GAE3B,IAAK,MAAMa,KAAYF,EAAU,CAC/B,MAAMG,QAAeb,QAAQc,QAAQF,EAASH,EAAWjB,IAEzD,GAAIqB,EAAOnB,SAAWL,EAA6BM,YACjD,MAAO,GAOT,GAJIkB,EAAOjB,QACTa,EAAYI,EAAOjB,OAGjBiB,EAAOnB,SAAWL,EAA6B0B,UACjD,OAAON,CAEX,CAEA,IAAK,MAAMO,KAAOxB,EAAQ,CACxB,MAAMI,EAAQJ,EAAOwB,GAEjBZ,EAAAA,cAAcR,GAChBa,EAAUO,SAAaX,EAAgBT,EAAOG,GACrCO,MAAMC,QAAQX,GACvBa,EAAUO,SAAcnB,EAAeD,EAAOG,GAE9CU,EAAUO,GAAOpB,CAErB,CAEA,OAAOa,CAAAA,EClDI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