Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should we archive this project? #223

Open
caub opened this issue Jan 20, 2022 · 4 comments
Open

Should we archive this project? #223

caub opened this issue Jan 20, 2022 · 4 comments

Comments

@caub
Copy link
Contributor

caub commented Jan 20, 2022

It's not so easy to update this project dependencies, without rewriting everything and possibly breaking compabilities (even just node versions) with existing apps. There are issues like #195, #206, #222 discussing this

I'm wondering if it's worth archiving the project, similarly to momentjs project for example

There are alternatives:

For example with prompt-sync, you can achieve the same behavior than prompt like this:

const promptSync = require('prompt-sync')();
const Ajv = require('ajv');
const ajv = new Ajv({ coerceTypes: true, useDefaults: true });

function prompt(schemaProps) {
  const res = {};
  const properties = Object.fromEntries(Object.entries(schemaProps).map(([k, {required, ...v}]) => [k, v]));

  for (const [key, {description = key, default: _default, required}] of Object.entries(schemaProps)) {
    const msg = `${description} ${_default !== undefined ? `(${_default}) ` : ''}`;
    res[key] = promptSync(msg) || undefined;

    while (!ajv.validate({type: 'object', properties, required: required?[key]:[]}, res)) {
      console.error(ajv.errors.filter(o => o.instancePath === '' || o.instancePath === `/${key}`).map(({message, params}) => `> ${message} ${JSON.stringify(params)}`).join('\n'));
      res[key] = promptSync(msg) || undefined;
    }
  }

  return res;
}

const data = prompt({
  name: {type: 'string', minLength: 2, required: true},
  size: {type: 'string', enum: ['xs', 'sm', 'lg']},
  age: {type: 'integer', description: 'How old ru?', minimum: 0, maximum: 150},
  height: {type: 'number', description: 'Height in meters?', minimum: 0, maximum: 2.8, default: 1.8},
})

What are your thoughts?

@ilyashusterman
Copy link

ilyashusterman commented Jan 20, 2022

you are still losing all case scenarios of array items, and object , this is valid only for primtives

@caub
Copy link
Contributor Author

caub commented Jan 20, 2022

@ilyashusterman how do you pass arrays from the REPL?

@caub
Copy link
Contributor Author

caub commented Jan 20, 2022

@ilyashusterman oh right, I didn't even know prompt package supported arrays, I'm fine not supporting them to be honest

@caub
Copy link
Contributor Author

caub commented Feb 1, 2022

I created a simple prompt-ajv package that does it: https://replit.com/@caub/prompt#index.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants