Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
{
appName: string()
.required()
.notEmpty()
.match(APP_NAME_PATTERN),
appPath: string()
.required()
.notEmpty(),
argOptions: object(),
configBlueprint: object(),
configName: string().custom(value => {
if (value && !value.match(CONFIG_NAME_PATTERN)) {
throw new Error('Config file name must be camel case without extension.');
}
}),
footer: string(),
header: string(),
root: string(process.cwd()),
scoped: bool(),
settingsBlueprint: object(),
workspaceRoot: string(),
},
{
name: this.constructor.name,
},
);
this.appPath = Path.resolve(this.options.appPath);
this.rootPath = Path.resolve(this.options.root);
// Set environment variables
env('DEBUG_GLOBAL_NAMESPACE', this.options.appName);
.required()
.notEmpty()
.match(APP_NAME_PATTERN),
appPath: string()
.required()
.notEmpty(),
argOptions: object(),
configBlueprint: object(),
configName: string().custom(value => {
if (value && !value.match(CONFIG_NAME_PATTERN)) {
throw new Error('Config file name must be camel case without extension.');
}
}),
footer: string(),
header: string(),
root: string(process.cwd()),
scoped: bool(),
settingsBlueprint: object(),
workspaceRoot: string(),
},
{
name: this.constructor.name,
},
);
this.appPath = Path.resolve(this.options.appPath);
this.rootPath = Path.resolve(this.options.root);
// Set environment variables
env('DEBUG_GLOBAL_NAMESPACE', this.options.appName);
// Core debugger, logger, and translator for the entire tool
// prettier-ignore
pluginsBlueprint[pluralName] = array(union>([
string().notEmpty(),
shape({ [singularName]: string().notEmpty() }),
instance(contract, true),
], []));
});
const config = optimal(
this.inheritFromArgs(this.parseAndExtend(configPath), args),
{
...configBlueprint,
...pluginsBlueprint,
debug: bool(),
extends: array(string()),
locale: string(),
output: number(2).between(1, 3, true),
// shape() requires a non-empty object
settings: isEmpty(settingsBlueprint) ? object() : shape(settingsBlueprint),
silent: bool(),
theme: string('default').notEmpty(),
},
{
file: configPath instanceof Path ? configPath.name() : '',
name: 'ConfigLoader',
unknown: true,
},
);
return (config as unknown) as T;
}
], []));
});
const config = optimal(
this.inheritFromArgs(this.parseAndExtend(configPath), args),
{
...configBlueprint,
...pluginsBlueprint,
debug: bool(),
extends: array(string()),
locale: string(),
output: number(2).between(1, 3, true),
// shape() requires a non-empty object
settings: isEmptyObject(settingsBlueprint) ? object() : shape(settingsBlueprint),
silent: bool(),
theme: string('default').notEmpty(),
},
{
file: typeof configPath === 'string' ? path.basename(configPath) : '',
name: 'ConfigLoader',
unknown: true,
},
);
return config as T;
}
super();
this.argv = argv;
this.options = optimal(
options,
{
appName: string()
.required()
.notEmpty()
.match(APP_NAME_PATTERN),
appPath: string()
.required()
.notEmpty(),
argOptions: object(),
configBlueprint: object(),
configName: string().custom(value => {
if (value && !value.match(CONFIG_NAME_PATTERN)) {
throw new Error('Config file name must be camel case without extension.');
}
}),
footer: string(),
header: string(),
root: string(process.cwd()),
scoped: bool(),
settingsBlueprint: object(),
workspaceRoot: string(),
},
{
name: this.constructor.name,
},
);
constructor(options: Options, attribute: string, config: Partial = {}) {
super(options, attribute, config, false);
this.config = optimal(
this.config,
{
nullable: bool(),
optional: bool(),
type: string('union').notEmpty(),
valueTypes: array(this.createUnionType())
.notEmpty()
.required(),
},
{
name: 'UnionDefinition',
unknown: true,
},
);
this.valueTypes = this.config.valueTypes.map((type, i) => {
const valueConfig = toConfig(type);
return DefinitionFactory.factory(this.options, `${this.attribute}_${i}`, {
...valueConfig,
nullable: false,
validateConfig() {
const { name } = this.constructor;
this.config = optimal(
this.config,
{
nullable: bool(),
optional: bool(),
type: string(
normalizeType(name.replace('Definition', '').toLowerCase() || 'unknown'),
).notEmpty(),
},
{
name: name || 'Definition',
unknown: true,
},
) as T;
}
}
loadPackageJSON(): PackageConfig {
const rootPath = new Path(this.tool.options.root);
const filePath = rootPath.append('package.json');
this.debug('Locating package.json in %s', color.filePath(rootPath.path()));
if (!filePath.exists()) {
throw new Error(this.tool.msg('errors:packageJsonNotFound'));
}
this.package = optimal(
this.parseFile(filePath),
{
name: string().notEmpty(),
version: string('0.0.0'),
},
{
file: 'package.json',
name: 'ConfigLoader',
unknown: true,
},
);
return this.package;
}
constructor(options: Options) {
this.options = optimal(options, {
defaultNullable: bool(),
defaultOptional: bool(),
disableEslint: bool(),
enums: bool(true),
importPath: string('shapeshifter').notEmpty(),
includeAttributes: bool(),
includeDefinitions: bool(),
includeSchemas: bool(),
indentCharacter: string(' ').notEmpty(),
inferPropTypesShape: bool(),
renderers: array(string()).notEmpty(),
schemaGenerics: bool(),
stripPropTypes: bool(),
suffix: bool(true),
useDefine: bool(),
});
}
configName: string().required(),
configOption: string('--config'),
configStrategy: string(STRATEGY_CREATE).oneOf([
STRATEGY_CREATE,
STRATEGY_REFERENCE,
STRATEGY_COPY,
]),
dependencies: array(string()),
description: string(),
filterOptions: bool(true),
helpOption: string('--help'),
title: string().required(),
useConfigOption: bool(),
versionOption: string('--version'),
watchOptions: array(string()),
workspaceStrategy: string(STRATEGY_REFERENCE).oneOf([STRATEGY_REFERENCE, STRATEGY_COPY]),
},
{
name: this.constructor.name,
},
);
return this;
}
}