Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
constructor(reporter: Tr, options: Partial = {}) {
super();
this.reporter = reporter;
this.options = optimal(options, {
footer: string().empty(),
header: string().empty(),
silent: bool(),
});
// Avoid binding listeners while testing
if (process.env.NODE_ENV === 'test') {
return;
}
// Start early so we may capture uncaught/unhandled
this.start();
}
constructor(options: Options, attribute: string, config: Partial = {}) {
super(options, attribute, config, false);
this.config = optimal(
this.config,
{
constant: bool(),
nullable: bool(),
optional: bool(),
type: string('enum').notEmpty(),
valueType: this.createUnionType(),
// `valueType` must be validated before values
values: array(custom(this.validateValue, ''))
.notEmpty()
.required(),
},
{
name: 'EnumDefinition',
unknown: true,
},
loadPackageJSON(): PackageConfig {
const { root } = this.tool.options;
const filePath = path.join(root, 'package.json');
this.debug('Locating package.json in %s', chalk.cyan(root));
if (!fs.existsSync(filePath)) {
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;
}
setMetadata(metadata: Partial): this {
this.metadata = optimal(
metadata,
{
bin: string()
.match(/^[a-z]{1}[a-zA-Z0-9-]+$/u)
.required(),
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'),
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) => {
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(tool: Tool, context: Ctx, options?: PoolExecutorOptions) {
super(tool, context, options);
this.options = optimal(
{ ...options },
{
concurrency: number(os.cpus().length).gte(1),
fifo: bool(true),
timeout: number(0).gte(0),
},
{
name: 'PoolExecutor',
},
);
}
constructor(key: string, title: string, options?: Options) {
super(title, (context, value) => this.execute(context, value));
if (!key || typeof key !== 'string') {
throw new Error('Routine key must be a valid unique string.');
}
this.key = key;
this.options = optimal({ ...options }, this.blueprint(predicates), {
name: this.constructor.name,
});
this.debug = createDebugger(['routine', this.key]);
this.onCommand = new Event('command');
this.onCommandData = new Event('command.data');
}
bootstrap() {
this.options = optimal(
this.options,
{
filter: string().empty(),
},
{
name: 'SyncDotfilesRoutine',
},
);
}